1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
#ifndef SEARCHENGINE_H
#define SEARCHENGINE_H
#include <qobject.h>
#include <qptrlist.h>
#include <qstring.h>
#include <kpixmap.h>
#include <kio/job.h>
#include "docentrytraverser.h"
class QWidget;
class KProcess;
class KConfig;
class KHTMLPart;
namespace KHC {
class Formatter;
class SearchEngine;
class View;
class SearchHandler;
class SearchTraverser : public QObject, public DocEntryTraverser
{
Q_OBJECT
public:
SearchTraverser( SearchEngine *engine, int level );
~SearchTraverser();
void process( DocEntry * );
void startProcess( DocEntry * );
DocEntryTraverser *createChild( DocEntry * );
DocEntryTraverser *parentTraverser();
void deleteTraverser();
void finishTraversal();
protected:
void connectHandler( SearchHandler *handler );
void disconnectHandler( SearchHandler *handler );
protected slots:
void showSearchResult( SearchHandler *, DocEntry *, const QString &result );
void showSearchError( SearchHandler *, DocEntry *, const QString &error );
private:
const int mMaxLevel;
SearchEngine *mEngine;
int mLevel;
DocEntry *mEntry;
QString mJobData;
QString mResult;
QMap<SearchHandler *, int> mConnectCount;
};
class SearchEngine : public QObject
{
Q_OBJECT
public:
enum Operation { And, Or };
SearchEngine( View * );
~SearchEngine();
bool initSearchHandlers();
bool search( QString words, QString method = "and", int matches = 5,
QString scope = "" );
Formatter *formatter() const;
View *view() const;
QString substituteSearchQuery( const QString &query );
static QString substituteSearchQuery( const QString &query,
const QString &identifier, const QStringList &words, int maxResults,
Operation operation, const QString &lang );
void finishSearch();
/**
Append error message to error log.
*/
void logError( DocEntry *entry, const QString &msg );
/**
Return error log.
*/
QString errorLog() const;
bool isRunning() const;
SearchHandler *handler( const QString &documentType ) const;
QStringList words() const;
int maxResults() const;
Operation operation() const;
bool canSearch( DocEntry * );
bool needsIndex( DocEntry * );
signals:
void searchFinished();
protected slots:
void searchStdout(KProcess *proc, char *buffer, int buflen);
void searchStderr(KProcess *proc, char *buffer, int buflen);
void searchExited(KProcess *proc);
protected:
void processSearchQueue();
private:
KProcess *mProc;
bool mSearchRunning;
QString mSearchResult;
QString mStderr;
View *mView;
QString mWords;
int mMatches;
QString mMethod;
QString mLang;
QString mScope;
QStringList mWordList;
int mMaxResults;
Operation mOperation;
DocEntryTraverser *mRootTraverser;
QMap<QString, SearchHandler *> mHandlers;
};
}
#endif
// vim:ts=2:sw=2:et
|