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