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