Work on the parsing of .ifo file
[mdictionary] / src / plugins / stardict / StarDictPlugin.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 STARDICTPLUGIN_H
26 #define STARDICTPLUGIN_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 #include <QHash>
40 #include <QIcon>
41
42 #include "../../include/CommonDictInterface.h"
43 #include "../../include/settings.h"
44 #include "StarDictDialog.h"
45 #include "TranslationStarDict.h"
46 #include "StarDictSettings.h"
47
48 class TranslationXdxf;
49
50 class StarDictPlugin : public CommonDictInterface
51 {
52     Q_OBJECT
53     Q_INTERFACES(CommonDictInterface)
54 public:
55     StarDictPlugin(QObject *parent=0);
56
57     ~StarDictPlugin();
58
59     //! \returns source language code iso 639-2
60     QString langFrom() const;
61
62     //! \returns destination language code iso 639-2
63     QString langTo() const;
64
65     //! \returns dictionary name (like "old English" or so)
66     QString name() const;
67
68     //! \returns dictionary type (xdxf, google translate, etc)
69     QString type() const;
70
71     //! returns information about dictionary in xml (name, authors, etc)
72     QString infoNote() const;
73
74     /*! \returns DictDialog object that creates dialogs
75         for adding a new dictionary and changing plugin settings
76       */
77     DictDialog* dictDialog();
78
79     //! \returns new, clean copy of plugin with settings set as in Settings*
80     CommonDictInterface* getNew(const Settings*) const;
81
82     //! \returns whether plugin can start searching
83     bool isAvailable() const;
84
85     //! \returns a description of a word given by a QString
86     QString search(QString key);
87
88     //! \returns current plugin settings
89     Settings* settings();
90
91     //! \returns words count in a dictionary
92     long wordsCount();
93
94     //! Sets new settings
95     bool setSettings(const Settings*);
96
97     //! \return object containing data parsed from .ifo file
98     StarDictSettings* parseIfoFile();
99
100     //! \returns plugin icon
101     QIcon* icon();
102
103     /*! plugin should delete any files (eg. cache) that have been created and are ready
104         to be deleted
105         */
106     void clean();
107
108
109
110 public Q_SLOTS:
111     /*! performs search in a dictionary
112       \param  word word to search for in a dictionary
113       \param limit limit on number of results
114
115       After finishing search it has to emit
116       \see CommonDictInterface:finalTranslation  finalTranslation
117     */
118     QList<Translation*> searchWordList(QString word, int limit=0);
119
120     //! stops current operation
121     void stop();
122
123     //! loads translations for each plugin only once
124     void retranslate();
125
126
127 private:
128
129     /*! \returns true or false depending on whether the dictionary is cached
130         or not
131      */
132     bool isCached();
133     /*! searches for a list of words similar to a word in a database file
134     \param word key compared with keys in a database
135     \param limit limits the number of translations in returned list,
136            0 means unlimited
137     \returns list of translations
138     */
139     QList<Translation*> searchWordListCache(QString word, int limit=0);
140
141     /*! searches for a list of words similar to a word in a xdxf file
142     \param word key compared with keys in a xdxf file
143     \param limit limits the number of translations in returned list,
144            0 means unlimited
145     \returns list of translations
146     */
147     QList<Translation*> searchWordListFile(QString word, int limit=0);
148
149     /*! searches for a translation of a word which is exactly like a key
150         in a xdxf file */
151     QString searchFile(QString key);
152
153     //! scans dictionary file to get information about it
154     bool getDictionaryInfo();
155
156     //! counts the keys in a xdxf file
157     int countWords();
158
159
160     //! language from which we translate
161     QString _langFrom;
162     //! language to which we translate
163     QString _langTo;
164     //! name of a dictionary
165     QString _name;
166     //! information about dictionary
167     QString _infoNote;
168
169     QString _dictionaryInfo;
170
171     //! icon displayed during translations and when a dictionary is chosen
172     QIcon _icon;
173
174     //! number of words in a dictionary
175     long _wordsCount;
176     //! indicates if search is stopped
177     volatile bool stopped;
178     Settings *_settings;
179     StarDictDialog* _dictDialog;
180     StarDictSettings* _ifoFileSettings;
181 };
182
183 #endif // XDXFPLUGIN_H
184
185