Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
[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     void 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
125
126 Q_SIGNALS:
127     //! emitted with percent count of caching progress, and time elapsed from
128     //! last signal emit
129     void updateCachingProgress(int, int);
130
131
132
133 private:
134 /*! returns true or false depending on whether the dictionary is cached
135     or not, not implemented yet
136  */
137     bool isCached();
138
139 //! sets the path to dictionary file and adds it to settings
140  //   void setPath(QString);
141
142     QList<Translation*> searchWordListCache(QString word, int limit=0);
143
144     QList<Translation*> searchWordListFile(QString word, int limit=0);
145
146     QString searchFile(QString key);
147
148     QString searchCache(QString key);
149     //! scans dictionary file to get information about it
150     void getDictionaryInfo();
151
152     int countWords();
153
154     bool makeCache(QString dir);
155
156     //! language from which we translate
157     QString _langFrom;
158     //! language to which we translate
159     QString _langTo;
160     //! name of a dictionary
161     QString _name;
162     //! information about dictionary
163     QString _infoNote;
164     //! path to dictionary file
165  //   QString path;
166     uint _hash;
167     QIcon _icon;
168     QSqlDatabase db;
169     QString db_name;
170     //! number of words in dictionary
171     long _wordsCount;
172     volatile bool stopped;
173     Settings *_settings;
174     XdxfDictDialog* _dictDialog;
175     XdxfCachingDialog* cachingDialog;
176
177 };
178
179 #endif // XDXFPLUGIN_H
180
181