summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabeldict/modules/dbsearchengine2/KDBSearchEngine2.h
blob: 29615e9e798f101a31f98519dd04631b7d7fb771 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* ****************************************************************************
   
DBSE2  
Andrea Rizzi

**************************************************************************** */

#ifndef DBSEARCH_ENGINE2_H
#define DBSEARCH_ENGINE2_H

#include <searchengine.h>
#include <tqdialog.h>

#include "database.h"
#include "dbse2_factory.h"
#include "preferenceswidget.h"
#include "dbscan.h"
#include "sourcedialog.h"

//#include "DBSESettings.h"

class KDBSearchEngine2 : public SearchEngine
{
    Q_OBJECT
  
    
    public:
    
    KDBSearchEngine2(TQObject *parent=0, const char *name=0);
    virtual ~KDBSearchEngine2();
    
    //init if needed.
    bool init();
    
    /** @return true, if a search is currently active */
    bool isSearching() const {return searching;}
    
    void stopSearch()  { if(di) di->stop();}
    
    
    
    /** @returns true, if it was initialized correctly */
    bool isReady() const {return iAmReady; }
    

    void saveSettings(KConfigBase *config);
    void readSettings(KConfigBase *config);


    TQString translate(const TQString text);

    TQString fuzzyTranslation(const TQString text, int &score);
    TQString searchTranslation(const TQString, int &score );

    /**
     * Finds all messages belonging to package package. If nothing is found,
     * the list is empty.
     * @param package The name of the file, something like "kbabel.po"
     * @param resultList Will contain the found messages afterwards
     * @param error If an error occured, this should contain a description
     *
     * @return true, if successfull
     */
    bool messagesForPackage(const TQString& package
			    , TQValueList<Message>& resultList, TQString& error);

    /** 
     * @returns true, if the searchresults are given as rich text
     * the default implementation returns false
     */ 
    bool usesRichTextResults(){return true;}
    
    /** @returns true, if the the entries in the database can be edited */
    bool isEditable(){return false;}
    
    /** 
     * @returns a widget which lets the user setup all preferences of this
     * search engine. The returned widget should not be bigger than
     * 400x400. If you need more space, you maybe want to use
     * a tabbed widget.
     * @param parent the parent of the returned widget
     */
    virtual PrefWidget* preferencesWidget(TQWidget *parent);
    
    /** @returns information about this SearchEngine */
    virtual const TDEAboutData *about() const;
    
    /** @returns the i18n name of this search engine */
    TQString name() const {return i18n("DB SearchEngine II");}
    
    /** @returns a untranslated name of this engine */
    TQString id() const {return "dbse2";}
    
    /** @returns the last error message */
    TQString lastError() {return lasterror;}
    
    
    /**
     * sets the engine to always ask the preferences dialog for settings
     * if is existing before starting the search.
     */
    virtual void setAutoUpdateOptions(bool activate)
    {
	autoupdate=activate;
    }
    
    
    
    public slots:	
	
	void receiveResult(QueryResult r);
    
    /**
     * starts a search for string s in the original text
     * @returns false, if an error occured. Use @ref lastError
     * to get the last error message
     */
    bool startSearch(TQString s);
    
    /**
     * starts a search for string s in the translated text
     * @returns false, if an error occured. Use @ref lastError
     * to get the last error message
     */
    bool startSearchInTranslation(TQString s);
    
    
    /** stops a search */
    //  virtual void stopSearch() ;
    
    
    /**
     * This method allows a search engine to use different settings depending
     * on the edited file. The default implementation does nothing.
     * @param file The edited file with path
     */
    //    virtual void setEditedFile(TQString file);
    
    /**
     * This method allows a search engine to use different settings depending
     * on the edited package. The default implementation does nothing.
     * @param package The name of the package, that is currently translated.
     */
    //    virtual void setEditedPackage(TQString package);
    
    /**
     * This method allows a search engine to use different settings depending
     * on the language code. The default implementation does nothing.
     * @param lang The current language code (e.g. de).
     */	
    //    virtual void setLanguageCode(TQString lang);
    //    virtual void setLanguage(TQString languageCode, TQString languageName);
    
    
    
    /**
     * This method is called, if something has been changed in the
     * current file. See @ref setEditedFile if you want to know the file
     * name
     * @param orig the original string
     * @param translation the translated string  
     */
    
    void stringChanged( TQString orig, TQString translated
			, TQString description);
    
    //void scan();
    
    void  setLastError(TQString er);
    
    //Slots for preference dialog
  //  void  scanSource(TQString sourceName);
    void  scanNowPressed();
    void  scanAllPressed();
    void  editSource();
    void  removeSource();
    void  addSource();
    
	
    private:
    DataBaseInterface *di;
    bool searching;
    bool iAmReady;
    bool autoupdate;
    TQString lasterror;
    KDB2PreferencesWidget *pw;
    
    //PrefWidg -> DBSE
    void updateSettings();
    //DBSE -> PrefWidg
    void    setSettings();
    
    DBSESettings settings;
    TQString dbDirectory;
    bool autoAdd,useSentence,useGlossary,useExact;
    bool useDivide,useAlpha,useWordByWord,useDynamic;
    uint numberOfResult;
    TQMap<TQString,MessagesSource> sources;
    
};


#endif // SEARCH_ENGINE2_H