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