1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 5 ** 6 ** This file is part of the Qt Assistant of the Qt Toolkit. 7 ** 8 ** Commercial Usage 9 ** Licensees holding valid Qt Commercial licenses may use this file in 10 ** accordance with the Qt Commercial License Agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and Nokia. 13 ** 14 ** 15 ** GNU General Public License Usage 16 ** Alternatively, this file may be used under the terms of the GNU 17 ** General Public License versions 2.0 or 3.0 as published by the Free 18 ** Software Foundation and appearing in the file LICENSE.GPL included in 19 ** the packaging of this file. Please review the following information 20 ** to ensure GNU General Public Licensing requirements will be met: 21 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and 22 ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special 23 ** exception, Nokia gives you certain additional rights. These rights 24 ** are described in the Nokia Qt GPL Exception version 1.3, included in 25 ** the file GPL_EXCEPTION.txt in this package. 26 ** 27 ** Qt for Windows(R) Licensees 28 ** As a special exception, Nokia, as the sole copyright holder for Qt 29 ** Designer, grants users of the Qt/Eclipse Integration plug-in the 30 ** right for the Qt/Eclipse Integration to link to functionality 31 ** provided by Qt Designer and its related libraries. 32 ** 33 ** If you are unsure which license is appropriate for your use, please 34 ** contact the sales department at qt-sales@nokia.com. 35 ** 36 ****************************************************************************/ 37 38 #ifndef INDEX_H 39 #define INDEX_H 40 41 #include <QStringList> 42 #include <QHash> 43 #include <QDataStream> 44 #include <QObject> 45 #include <QList> 46 #include <QFile> 47 #include <QVector> 48 49 class QTimer; 50 51 QT_BEGIN_NAMESPACE 52 53 struct Document 54 { 55 Document() = default; DocumentDocument56 Document(int d, int f) : docNumber(d), frequency(f) {} 57 bool operator==(const Document & doc) const 58 { 59 return docNumber == doc.docNumber; 60 } 61 bool operator<(const Document & doc) const 62 { 63 return frequency > doc.frequency; 64 } 65 bool operator<=(const Document & doc) const 66 { 67 return frequency >= doc.frequency; 68 } 69 bool operator>(const Document & doc) const 70 { 71 return frequency < doc.frequency; 72 } 73 qint16 docNumber = -1; 74 qint16 frequency = 0; 75 }; 76 77 QDataStream & operator>>(QDataStream & s, Document & l); 78 QDataStream & operator<<(QDataStream & s, const Document & l); 79 80 class HelpIndex : public QObject 81 { 82 Q_OBJECT 83 public: 84 struct Entry 85 { EntryEntry86 Entry(int d) { documents.append(Document(d, 1)); } EntryEntry87 Entry(QVector<Document> l) : documents(l) {} 88 QVector<Document> documents; 89 }; 90 struct PosEntry 91 { PosEntryPosEntry92 PosEntry(int p) { positions.append(p); } 93 QList<uint> positions; 94 }; 95 96 HelpIndex(QString dp, const QString & hp); 97 HelpIndex(QStringList dl, const QString & hp); 98 void writeDict(); 99 void readDict(); 100 void makeIndex(); 101 QStringList query(const QStringList &, const QStringList &, const QStringList &); 102 QString getDocumentTitle(const QString &); 103 void setDictionaryFile(const QString &); 104 void setDocListFile(const QString &); 105 void setDocList(const QStringList &); 106 documentList()107 const QStringList & documentList() const { return docList; }; titlesList()108 const QStringList & titlesList() const { return titleList; }; 109 110 signals: 111 void indexingStart(int); 112 void indexingProgress(int); 113 void indexingEnd(); 114 115 private slots: 116 void setLastWinClosed(); 117 void filterNext(); 118 119 private: 120 void setupDocumentList(); 121 void parseDocument(const QString &, int); 122 void insertInDict(const QString &, int); 123 void writeDocumentList(); 124 void readDocumentList(); 125 QStringList getWildcardTerms(const QString &); 126 QStringList split(const QString &); 127 QVector<Document> setupDummyTerm(const QStringList &); 128 bool searchForPattern(const QStringList &, const QStringList &, const QString &); 129 void buildMiniDict(const QString &); 130 131 QString getCharsetForDocument(QFile *); 132 QStringList docList; 133 QStringList titleList; 134 QHash<QString, Entry *> dict; 135 QHash<QString, PosEntry *> miniDict; 136 uint wordNum = 0; 137 QString docPath; 138 QString dictFile; 139 QString docListFile; 140 bool alreadyHaveDocList; 141 bool lastWindowClosed = false; 142 QHash<QString, QString> documentTitleCache; 143 QTimer * m_pTimer = nullptr; 144 int m_iCurItem = 0; 145 }; 146 147 #endif 148 149 QT_END_NAMESPACE 150