Clean and order documentation in source files. Source ready to beta 2 release
[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     \file xdxfplugin.h
23     \brief Implementation of xdxf plugin's main class.
24
25     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
26 */
27
28 #ifndef XDXFPLUGIN_H
29 #define XDXFPLUGIN_H
30
31 #include <QObject>
32 #include <QDialog>
33 #include <QRegExp>
34 #include <QTime>
35 #include <QSqlQuery>
36 #include <QSqlDatabase>
37 #include <QSqlError>
38 #include <QFile>
39 #include <QXmlStreamReader>
40 #include <QtPlugin>
41 #include <QHash>
42
43 #include "../../include/CommonDictInterface.h"
44 #include "../../include/settings.h"
45 #include "XdxfDictDialog.h"
46 #include "XdxfCachingDialog.h"
47 #include "TranslationXdxf.h"
48 #include "XdxfDictDownloader.h"
49
50 class TranslationXdxf;
51
52 class XdxfPlugin : public CommonDictInterface
53 {
54     Q_OBJECT
55     Q_INTERFACES(CommonDictInterface)
56 public:
57     XdxfPlugin(QObject *parent=0);
58     ~XdxfPlugin();
59
60     //! \returns source language code iso 639-2
61     QString langFrom() const;
62
63     //! \returns destination language code iso 639-2
64     QString langTo() const;
65
66     //! \returns dictionary name (like "old English" or so)
67     QString name() const;
68
69     //! \returns dictionary type (xdxf, google translate, etc)
70     QString type() const;
71
72     //! \returns information about dictionary in xml (name, authors, etc)
73     QString infoNote() const;
74
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     /*!
103         plugin should delete any files (eg. cache) that have been created and are ready
104         to be deleted
105     */
106     void clean();
107
108     static XdxfDictDownloader dictDownloader;
109
110 public Q_SLOTS:
111     /*!
112         performs search in a dictionary
113         \param  word word to search for in a 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     //! stops current operation
122     void stop();
123
124     //! loads translations for each plugin only once
125     void retranslate();
126
127 Q_SIGNALS:
128     //! emitted with percent count of caching progress, and time elapsed from
129     //! last signal emit
130     void updateCachingProgress(int, int);
131
132 private:
133     /*!
134         \returns true or false depending on whether the dictionary is cached
135         or not
136     */
137     bool isCached();
138     /*!
139         searches for a list of words similar to a word in a database file
140         \param word key compared with keys in a database
141         \param limit limits the number of translations in returned list,
142         0 means unlimited
143         \returns list of translations
144     */
145     QList<Translation*> searchWordListCache(QString word, int limit=0);
146
147     /*!
148         searches for a list of words similar to a word in a xdxf file
149         \param word key compared with keys in a xdxf file
150         \param limit limits the number of translations in returned list,
151         0 means unlimited
152         \returns list of translations
153     */
154     QList<Translation*> searchWordListFile(QString word, int limit=0);
155
156     /*!
157         searches for a translation of a word which is exactly like a key
158         in a xdxf file
159     */
160     QString searchFile(QString key);
161
162     /*!
163         searches for a translation of a word which is exactly like a key
164         in a database file
165     */
166     QString searchCache(QString key);
167
168     //! scans dictionary file to get information about it
169     bool getDictionaryInfo();
170
171     //! counts the keys in a xdxf file
172     int countWords();
173
174     /*!
175         transforms xdxf files to database files (caching operation)
176         \returns true on success, false on failure
177     */
178     bool makeCache(QString dir);
179
180     static bool dictDownloaderInitialized;
181
182     QString _langFrom;
183     QString _langTo;
184     QString _name;
185     QString _infoNote;
186     QString _dictionaryInfo;
187     QIcon _icon;
188     QSqlDatabase db;
189     QString db_name;
190     long _wordsCount;
191     volatile bool stopped;
192     Settings *_settings;
193     XdxfDictDialog* _dictDialog;
194     XdxfCachingDialog* cachingDialog;
195 };
196
197 #endif // XDXFPLUGIN_H
198
199