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