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