summaryrefslogtreecommitdiffstats
path: root/khelpcenter/searchengine.h
blob: 2863b904f60794a5c5b20789f01f0ebfc49a3fe0 (plain)
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 <tqobject.h>
#include <tqptrlist.h>
#include <tqstring.h>

#include <kpixmap.h>
#include <tdeio/job.h>

#include "docentrytraverser.h"

class TQWidget;
class TDEProcess;
class TDEConfig;
class KHTMLPart;

namespace KHC {

class Formatter;
class SearchEngine;
class View;
class SearchHandler;

class SearchTraverser : public TQObject, 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 TQString &result );
    void showSearchError( SearchHandler *, DocEntry *, const TQString &error );

  private:
    const int mMaxLevel;
  
    SearchEngine *mEngine;
    int mLevel;

    DocEntry *mEntry;
    TQString mJobData;
    
    TQString mResult;
    
    TQMap<SearchHandler *, int> mConnectCount;
};


class SearchEngine : public TQObject
{
    Q_OBJECT
  public:
    enum Operation { And, Or };

    SearchEngine( View * );
    ~SearchEngine();

    bool initSearchHandlers();

    bool search( TQString words, TQString method = "and", int matches = 5,
                 TQString scope = "" );

    Formatter *formatter() const; 
    View *view() const;

    TQString substituteSearchQuery( const TQString &query );

    static TQString substituteSearchQuery( const TQString &query,
      const TQString &identifier, const TQStringList &words, int maxResults,
      Operation operation, const TQString &lang );

    void finishSearch();

    /**
      Append error message to error log.
    */
    void logError( DocEntry *entry, const TQString &msg );

    /**
      Return error log.
    */
    TQString errorLog() const;

    bool isRunning() const;

    SearchHandler *handler( const TQString &documentType ) const;

    TQStringList words() const;
    int maxResults() const;
    Operation operation() const;

    bool canSearch( DocEntry * );
    bool needsIndex( DocEntry * );

  signals:
    void searchFinished();

  protected slots:
    void searchStdout(TDEProcess *proc, char *buffer, int buflen);
    void searchStderr(TDEProcess *proc, char *buffer, int buflen);
    void searchExited(TDEProcess *proc);

  protected:
    void processSearchQueue();
    
  private:
    TDEProcess *mProc;
    bool mSearchRunning;
    TQString mSearchResult;

    TQString mStderr;

    View *mView;
    
    TQString mWords;
    int mMatches;
    TQString mMethod;
    TQString mLang;
    TQString mScope;

    TQStringList mWordList;
    int mMaxResults;
    Operation mOperation;
    
    DocEntryTraverser *mRootTraverser;

    TQMap<TQString, SearchHandler *> mHandlers;
};

}

#endif
// vim:ts=2:sw=2:et