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