Separate translations for each plugin
[mdictionary] / src / plugins / xdxf / 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
23 /*! \file xdxfplugin.h
24 */
25 #ifndef XDXFPLUGIN_H
26 #define XDXFPLUGIN_H
27
28
29 #include <QObject>
30 #include <QDialog>
31 #include <QRegExp>
32 #include <QTime>
33 #include <QSqlQuery>
34 #include <QSqlDatabase>
35 #include <QSqlError>
36 #include <QFile>
37 #include <QXmlStreamReader>
38 #include <QtPlugin>
39
40 #include "../../common/CommonDictInterface.h"
41 #include "../../common/settings.h"
42 #include "XdxfDictDialog.h"
43 #include "XdxfCachingDialog.h"
44 #include "TranslationXdxf.h"
45
46 class TranslationXdxf;
47
48 class XdxfPlugin : public CommonDictInterface
49 {
50     Q_OBJECT
51     Q_INTERFACES(CommonDictInterface)
52 public:
53     XdxfPlugin(QObject *parent=0);
54
55     ~XdxfPlugin();
56
57     //! returns source language code iso 639-2
58     QString langFrom() const;
59
60     //! returns destination language code iso 639-2
61     QString langTo() const;
62
63     //! returns dictionary name (like "old English" or so)
64     QString name() const;
65
66     //! returns dictionary type (xdxf, google translate, etc)
67     QString type() const;
68
69     //! returns information about dictionary in html (name, authors, etc)
70     QString infoNote() const;
71
72     /*! returns DictDialog object that creates dialogs
73         for adding new dictionary and changing plugin things
74       */
75     DictDialog* dictDialog();
76
77     //! returns new, clean copy of plugin with settings set as in Settings*
78     CommonDictInterface* getNew(const Settings*) const;
79
80     //! returns whether plugin can start searching
81     bool isAvailable() const;
82
83     //! returns a description of a word given by a QString
84     QString search(QString key);
85
86     //! returns a unique hash for a dictionary
87     uint hash() const;
88
89     //! sets unique value (unique for every dictionary, not plugin)
90     void setHash(uint);
91
92     //! returns current plugin settings
93     Settings* settings();
94
95     //! returns words count in dictionary
96     long wordsCount();
97
98     //! Sets new settings
99     bool setSettings(const Settings*);
100
101     //! returns plugin icon
102     QIcon* icon();
103
104     /*! plugin should delete any files (eg. cache) that have been created and are ready
105         to be deleted
106         */
107     void clean();
108
109
110
111 public Q_SLOTS:
112     /*! performs search in dictionary
113       \param  word word to search in dictionary
114       \param limit limit on number of results
115
116       After finishing search it has to emit
117       \see CommonDictInterface:finalTranslation  finalTranslation
118     */
119     QList<Translation*> searchWordList(QString word, int limit=0);
120
121     //! stop current operation
122     void stop();
123
124     void retranslate();
125
126
127
128 Q_SIGNALS:
129     //! emitted with percent count of caching progress, and time elapsed from
130     //! last signal emit
131     void updateCachingProgress(int, int);
132
133
134
135 private:
136 /*! returns true or false depending on whether the dictionary is cached
137     or not, not implemented yet
138  */
139     bool isCached();
140
141 //! sets the path to dictionary file and adds it to settings
142  //   void setPath(QString);
143
144     QList<Translation*> searchWordListCache(QString word, int limit=0);
145
146     QList<Translation*> searchWordListFile(QString word, int limit=0);
147
148     QString searchFile(QString key);
149
150     QString searchCache(QString key);
151
152     //! scans dictionary file to get information about it
153     bool getDictionaryInfo();
154
155     int countWords();
156
157     bool makeCache(QString dir);
158
159     //! language from which we translate
160     QString _langFrom;
161     //! language to which we translate
162     QString _langTo;
163     //! name of a dictionary
164     QString _name;
165     //! information about dictionary
166     QString _infoNote;
167     //! path to dictionary file
168  //   QString path;
169     uint _hash;
170     QIcon _icon;
171     QSqlDatabase db;
172     QString db_name;
173     //! number of words in dictionary
174     long _wordsCount;
175     volatile bool stopped;
176     Settings *_settings;
177     XdxfDictDialog* _dictDialog;
178     XdxfCachingDialog* cachingDialog;
179 };
180
181 #endif // XDXFPLUGIN_H
182
183