Merge branch 'cache' of ssh://drop.maemo.org/git/mdictionary into cache
[mdictionary] / trunk / src / plugins / xdxf / src / xdxfplugin.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 #ifndef XDXFPLUGIN_H
23 #define XDXFPLUGIN_H
24
25 #include "../../../includes/CommonDictInterface.h"
26 #include <QObject>
27 #include <QDialog>
28 #include <QRegExp>
29 #include <QTime>
30 #include <QSqlQuery>
31 #include <QSqlDatabase>
32 #include <QSqlError>
33 #include "XdxfDictDialog.h"
34 #include "XdxfCachingDialog.h"
35
36 class TranslationXdxf;
37
38 class XdxfPlugin : public CommonDictInterface
39 {
40     Q_OBJECT
41     Q_INTERFACES(CommonDictInterface)
42 public:
43     XdxfPlugin(QObject *parent=0);
44
45     //! returns source language code iso 639-2
46     QString langFrom() const;
47
48     //! returns destination language code iso 639-2
49     QString langTo() const;
50
51     //! returns dictionary name (like "old english" or so)
52     QString name() const;
53
54     //! returns dictionary type (xdxf, google translate, etc)
55     QString type() const;
56
57     //! returns information about dictionary in html (name, authors, etc)
58     QString infoNote() const;
59
60     /*! returns DictDialog object that creates dialogs
61         for adding new dictionary and change plugin settings
62       */
63     DictDialog* dictDialog();
64
65
66     //! returns new, clean copy of plugin with setting set as in Settings*
67     CommonDictInterface* getNew(const Settings*) const;
68
69     //! returns whether plugin can start searching
70     bool isAvailable() const;
71
72     //! returns a description of a word given by a QString
73     QString search(QString key);
74
75     //! returns a unique hash for a dictionary
76     uint hash() const;
77
78     //! set unique value (unique for every dictionary not plugin)
79     void setHash(uint);
80
81     //! returns current plugin settings
82     Settings* settings();
83
84     //! returns words count in dictionary
85     long wordsCount();
86
87     //! Sets new settings
88     void setSettings(Settings*);
89
90     //! returns plugin icon
91     virtual QIcon* icon();
92
93 public Q_SLOTS:
94     /*! performs search in dictionary
95       \param  word word to search in dictionary
96       \param limit limit on number of results
97
98       After finishing search it has to emit
99       \see CommonDictInterface:finalTranslation  finalTranslation
100     */
101     QList<Translation*> searchWordList(QString word, int limit=0);
102
103     //! stop current operation
104     void stop();
105
106 Q_SIGNALS:
107     //! emited with percent count of caching progress
108     void updateCachingProgress(int);
109
110
111 protected:
112     QString removeAccents(QString);
113
114 private:
115 /*! returns true or false depending on whether the dictionary is cached
116     or not, not implemented yet
117  */
118     bool isCached();
119
120 //! sets the path to dictionary file and adds it to settings
121     void setPath(QString);
122
123     QList<Translation*> searchWordListCache(QString word, int limit=0);
124     QList<Translation*> searchWordListFile(QString word, int limit=0);
125     QString searchFile(QString key);
126     QString searchCache(QString key);
127     int countWords();
128     bool makeCache(QString dir);
129
130     //! language from which we translate
131     QString _langFrom;
132     //! language to which we translate
133     QString _langTo;
134     //! name of a dictionary
135     QString _name;
136     //! type of a dictionary
137     QString _type;
138     //! information about dictionary
139     QString _infoNote;
140     QDialog *_loadDialog;
141     QDialog *_settingsDialog;
142     //! path to dictionary file
143     QString path;
144     uint _hash;
145     QIcon _icon;
146     QSqlDatabase db;
147     QString db_name;
148
149     //! number of words in dicrionary
150     long _wordsCount;
151
152     //! scan dictionary file to get information about it
153     void getDictionaryInfo();
154
155     volatile bool stopped;
156     Settings *_settings;
157     XdxfDictDialog* _dictDialog;
158     XdxfCachingDialog* cachingDialog;
159 };
160
161 #endif // XDXFPLUGIN_H
162
163