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