1 | |
2 | /* |
3 | This file is part of KHelpCenter. |
4 | |
5 | Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org> |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #ifndef KHC_SEARCHHANDLER_H |
23 | #define KHC_SEARCHHANDLER_H |
24 | |
25 | #include "searchengine.h" |
26 | |
27 | #include <QObject> |
28 | |
29 | #include <KProcess> |
30 | |
31 | class KConfigGroup; |
32 | namespace KIO { |
33 | class Job; |
34 | } |
35 | |
36 | namespace KHC { |
37 | |
38 | class SearchJob : public QObject { |
39 | Q_OBJECT |
40 | public: |
41 | SearchJob(DocEntry *entry); |
42 | ~SearchJob(); |
43 | |
44 | bool startLocal(const QString &cmdString); |
45 | bool startRemote(const QString &url); |
46 | |
47 | Q_SIGNALS: |
48 | void searchFinished( SearchJob *, DocEntry *, const QString & ); |
49 | void searchError( SearchJob *, DocEntry *, const QString & ); |
50 | |
51 | protected Q_SLOTS: |
52 | void searchExited( int exitCode, QProcess::ExitStatus ); |
53 | void slotJobResult( KJob *job ); |
54 | void slotJobData( KIO::Job *, const QByteArray &data ); |
55 | |
56 | protected: |
57 | DocEntry *mEntry; |
58 | KProcess *mProcess; |
59 | KIO::Job *mKioJob; |
60 | QString mCmd; |
61 | QString mResult; |
62 | QString mError; |
63 | }; |
64 | |
65 | class SearchHandler : public QObject |
66 | { |
67 | Q_OBJECT |
68 | public: |
69 | static SearchHandler *initFromFile( const QString &filename ); |
70 | |
71 | virtual ~SearchHandler(); |
72 | |
73 | virtual void search( DocEntry *, const QStringList &words, |
74 | int maxResults = 10, |
75 | SearchEngine::Operation operation = SearchEngine::And ) = 0; |
76 | |
77 | virtual QString indexCommand( const QString &identifier ) = 0; |
78 | |
79 | QStringList documentTypes() const; |
80 | |
81 | virtual bool checkPaths(QString* error) const = 0; |
82 | |
83 | Q_SIGNALS: |
84 | void searchFinished( SearchHandler *, DocEntry *, const QString & ); |
85 | void searchError( SearchHandler *, DocEntry *, const QString & ); |
86 | |
87 | protected: |
88 | SearchHandler( const KConfigGroup &cg ); |
89 | |
90 | QString mLang; |
91 | QStringList mDocumentTypes; |
92 | }; |
93 | |
94 | class ExternalProcessSearchHandler : public SearchHandler |
95 | { |
96 | Q_OBJECT |
97 | public: |
98 | ExternalProcessSearchHandler( const KConfigGroup &cg ); |
99 | |
100 | void search( DocEntry *, const QStringList &words, |
101 | int maxResults = 10, |
102 | SearchEngine::Operation operation = SearchEngine::And ); |
103 | |
104 | QString indexCommand( const QString &identifier ); |
105 | |
106 | bool checkPaths(QString* error) const; |
107 | |
108 | private: |
109 | bool checkBinary( const QString &cmd ) const; |
110 | |
111 | private slots: |
112 | void slotSearchFinished( SearchJob *, DocEntry *, const QString & ); |
113 | void slotSearchError( SearchJob *, DocEntry *, const QString & ); |
114 | |
115 | private: |
116 | QString mSearchCommand; |
117 | QString mSearchUrl; |
118 | QString mSearchBinary; |
119 | QString mIndexCommand; |
120 | QString mTryExec; |
121 | }; |
122 | |
123 | } |
124 | |
125 | #endif //KHC_SEARCHHANDLER_H |
126 | |