d47d43f5a6ad7775e6a4e5c2c37b06edd4b0f4d0
[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 "../../include/CommonDictInterface.h"
41 #include "../../include/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 settings
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 current plugin settings
87     Settings* settings();
88
89     //! returns words count in dictionary
90     long wordsCount();
91
92     //! Sets new settings
93     bool setSettings(const Settings*);
94
95     //! returns plugin icon
96     QIcon* icon();
97
98     /*! plugin should delete any files (eg. cache) that have been created and are ready
99         to be deleted
100         */
101     void clean();
102
103
104
105 public Q_SLOTS:
106     /*! performs search in dictionary
107       \param  word word to search in dictionary
108       \param limit limit on number of results
109
110       After finishing search it has to emit
111       \see CommonDictInterface:finalTranslation  finalTranslation
112     */
113     QList<Translation*> searchWordList(QString word, int limit=0);
114
115     //! stop current operation
116     void stop();
117
118     //! loads translations for each plugin only once
119     void retranslate();
120
121 Q_SIGNALS:
122     //! emitted with percent count of caching progress, and time elapsed from
123     //! last signal emit
124     void updateCachingProgress(int, int);
125
126
127 private:
128
129     /*! returns true or false depending on whether the dictionary is cached
130         or not, not implemented yet
131      */
132     bool isCached();
133     /*! searches for a list of words similar to a word in a database file
134     \param word key compared with keys in a database
135     \param limit limits the number of translations in returned list,
136            0 means unlimited
137     \returns list of translations
138     */
139     QList<Translation*> searchWordListCache(QString word, int limit=0);
140
141     /*! searches for a list of words similar to a word in a xdxf file
142     \param word key compared with keys in a xdxf file
143     \param limit limits the number of translations in returned list,
144            0 means unlimited
145     \returns list of translations
146     */
147     QList<Translation*> searchWordListFile(QString word, int limit=0);
148
149     /*! searches for a translation of a word which is exactly like a key
150         in xdxf file */
151     QString searchFile(QString key);
152
153     /*! searches for a translation of a word which is exactly like a key
154         in database file */
155     QString searchCache(QString key);
156
157     //! scans dictionary file to get information about it
158     bool getDictionaryInfo();
159
160     //! counts the keys in xdxf file
161     int countWords();
162
163     /*! transforms xdxf files to database files (caching operation)
164         \returns true on success, false on failure */
165     bool makeCache(QString dir);
166
167     //! language from which we translate
168     QString _langFrom;
169     //! language to which we translate
170     QString _langTo;
171     //! name of a dictionary
172     QString _name;
173     //! information about dictionary
174     QString _infoNote;
175
176     QString _dictionaryInfo;
177
178     //! unique number of a dictionary assigned to it by backbone
179     uint _hash;
180     //! icon displayed during translations and when the dictionary is chosen
181     QIcon _icon;
182     QSqlDatabase db;
183     QString db_name;
184     //! number of words in dictionary
185     long _wordsCount;
186     //! indicates if search is stopped
187     volatile bool stopped;
188     Settings *_settings;
189     XdxfDictDialog* _dictDialog;
190     XdxfCachingDialog* cachingDialog;
191 };
192
193 #endif // XDXFPLUGIN_H
194
195