add googleSettingsDialog
[mdictionary] / trunk / src / plugins / google / src / GooglePlugin.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 GooglePlugin.h
24 */
25 #ifndef GOOGLEPLUGIN_H
26 #define GOOGLEPLUGIN_H
27
28
29 #include <QObject>
30 #include <QDialog>
31 #include <QtPlugin>
32 #include <QIcon>
33 #include <QtNetwork>
34
35 #include "../../../includes/CommonDictInterface.h"
36 #include "../../../includes/settings.h"
37 #include "../../../includes/DictDialog.h"
38 #include "TranslationGoogle.h"
39 #include "GoogleDictDialog.h"
40
41 class GoogleDictDialog;
42
43 class GooglePlugin : public CommonDictInterface
44 {
45     Q_OBJECT
46     Q_INTERFACES(CommonDictInterface)
47 public:
48     GooglePlugin(QObject *parent=0);
49     ~GooglePlugin();
50
51     //! returns source language code iso 639-2
52     QString langFrom() const;
53
54     //! returns destination language code iso 639-2
55     QString langTo() const;
56
57     //! returns dictionary name (like "old english" or so)
58     QString name() const;
59
60     //! returns dictionary type (xdxf, google translate, etc)
61     QString type() const;
62
63     //! returns information about dictionary in html (name, authors, etc)
64     QString infoNote() const;
65
66     void setLangTo(QString langTo);
67
68     void setLangFrom(QString langFrom);
69
70     /*! returns DictDialog object that creates dialogs
71         for adding new dictionary and change plugin tings
72       */
73     DictDialog* dictDialog();
74
75     //! returns new, clean copy of plugin with setting set as in Settings*
76     CommonDictInterface* getNew(const Settings*) const;
77
78     //! returns whether plugin can start searching
79     bool isAvailable() const;
80
81     //! returns a description of a word given by a QString
82     QString search(QString key);
83
84     //! returns a unique hash for a dictionary
85     uint hash() const;
86
87     //! set unique value (unique for every dictionary not plugin)
88     void setHash(uint);
89
90     //! returns current plugin settings
91     Settings* settings();
92
93     //! Sets new settings
94     void setSettings(Settings*);
95
96     //! returns plugin icon
97     QIcon* icon();
98
99     Translation* getTranslationFor(QString key);
100
101     static QMap<QString, QString> initLanguages();
102
103 public 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     void done();
117
118 private:
119     QString jsonParse(QString result);
120     void getDictionaryInfo();
121
122     QMap<QString, QString> languages;
123     //! language from which we translate
124     QString _langFrom;
125     //! language to which we translate
126     QString _langTo;
127     //! name of a dictionary
128     QString _name;
129     //! type of a dictionary
130     QString _type;
131     //! information about dictionary
132     QString _infoNote;
133     //! path to dictionary file
134     QString path;
135     uint _hash;
136     QIcon _icon;
137     Settings *_settings;
138     bool stopped;
139     volatile bool wait;
140     QHttp *http;
141     GoogleDictDialog *_dictDialog;
142 };
143
144 #endif // GOOGLEPLUGIN_H
145
146