KVIrc  4.9.2
DeveloperAPIs
HelpIndex.h
Go to the documentation of this file.
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(int d, int f) : docNumber(d), frequency(f) {}
56  Document() : docNumber(-1), frequency(0) {}
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;
74  qint16 frequency;
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  {
86  Entry(int d) { documents.append(Document(d, 1)); }
87  Entry(QVector<Document> l) : documents(l) {}
88  QVector<Document> documents;
89  };
90  struct PosEntry
91  {
92  PosEntry(int p) { positions.append(p); }
93  QList<uint> positions;
94  };
95 
96  HelpIndex(const QString & dp, const QString & hp);
97  HelpIndex(const 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 
107  const QStringList & documentList() { return docList; };
108  const QStringList & titlesList() { 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  QString getCharsetForDocument(QFile *);
131  QStringList docList;
132  QStringList titleList;
133  QHash<QString, Entry *> dict;
134  QHash<QString, PosEntry *> miniDict;
135  uint wordNum;
136  QString docPath;
140  QHash<QString, QString> documentTitleCache;
141  QTimer * m_pTimer;
143 };
144 
145 #endif
146 
147 QT_END_NAMESPACE
QHash< QString, QString > documentTitleCache
Definition: HelpIndex.h:140
Document()
Definition: HelpIndex.h:56
bool lastWindowClosed
Definition: HelpIndex.h:139
QStringList split(const QString &)
Definition: HelpIndex.cpp:504
QString docListFile
Definition: HelpIndex.h:137
#define f
Definition: detector.cpp:70
QString dictFile
Definition: HelpIndex.h:137
Document(int d, int f)
Definition: HelpIndex.h:55
void insertInDict(const QString &, int)
Definition: HelpIndex.cpp:171
void setDocListFile(const QString &)
Definition: HelpIndex.cpp:116
#define l
Definition: detector.cpp:76
QHash< QString, Entry * > dict
Definition: HelpIndex.h:133
bool searchForPattern(const QStringList &, const QStringList &, const QString &)
Definition: HelpIndex.cpp:569
uint wordNum
Definition: HelpIndex.h:135
qint16 docNumber
Definition: HelpIndex.h:73
QString getCharsetForDocument(QFile *)
Definition: HelpIndex.cpp:192
bool alreadyHaveDocList
Definition: HelpIndex.h:138
void makeIndex()
Definition: HelpIndex.cpp:126
QStringList docList
Definition: HelpIndex.h:131
QHash< QString, PosEntry * > miniDict
Definition: HelpIndex.h:134
bool operator>(const Document &doc) const
Definition: HelpIndex.h:69
void writeDocumentList()
Definition: HelpIndex.cpp:297
void readDict()
Definition: HelpIndex.cpp:312
PosEntry(int p)
Definition: HelpIndex.h:92
QVector< Document > setupDummyTerm(const QStringList &)
Definition: HelpIndex.cpp:531
void indexingEnd()
void setDictionaryFile(const QString &)
Definition: HelpIndex.cpp:111
char s d
Definition: KviIrcNumericCodes.h:391
char s char s s
Definition: KviIrcNumericCodes.h:391
QList< uint > positions
Definition: HelpIndex.h:93
QDataStream & operator<<(QDataStream &s, const Document &l)
Definition: HelpIndex.cpp:72
bool operator<=(const Document &doc) const
Definition: HelpIndex.h:65
void buildMiniDict(const QString &)
Definition: HelpIndex.cpp:562
void writeDict()
Definition: HelpIndex.cpp:280
QString docPath
Definition: HelpIndex.h:136
void indexingProgress(int)
bool operator<(const Document &doc) const
Definition: HelpIndex.h:61
void readDocumentList()
Definition: HelpIndex.cpp:335
Definition: HelpIndex.h:90
Definition: HelpIndex.h:53
qint16 frequency
Definition: HelpIndex.h:74
void filterNext()
Definition: HelpIndex.cpp:138
QDataStream & operator>>(QDataStream &s, Document &l)
Definition: HelpIndex.cpp:65
void indexingStart(int)
void setLastWinClosed()
Definition: HelpIndex.cpp:106
Definition: HelpIndex.h:80
QStringList titleList
Definition: HelpIndex.h:132
Entry(int d)
Definition: HelpIndex.h:86
int m_iCurItem
Definition: HelpIndex.h:142
QString getDocumentTitle(const QString &)
Definition: HelpIndex.cpp:417
void setDocList(const QStringList &)
Definition: HelpIndex.cpp:121
Definition: HelpIndex.h:84
QVector< Document > documents
Definition: HelpIndex.h:88
const QStringList & titlesList()
Definition: HelpIndex.h:108
const QStringList & documentList()
Definition: HelpIndex.h:107
HelpIndex(const QString &dp, const QString &hp)
Definition: HelpIndex.cpp:79
void setupDocumentList()
Definition: HelpIndex.cpp:154
QTimer * m_pTimer
Definition: HelpIndex.h:141
#define p
Definition: detector.cpp:80
Entry(QVector< Document > l)
Definition: HelpIndex.h:87
QStringList query(const QStringList &, const QStringList &, const QStringList &)
Definition: HelpIndex.cpp:349
bool operator==(const Document &doc) const
Definition: HelpIndex.h:57
QStringList getWildcardTerms(const QString &)
Definition: HelpIndex.cpp:452
void parseDocument(const QString &, int)
Definition: HelpIndex.cpp:217