change comment's and fix bug (xslt transform)
[mdictionary] / src / plugins / google / 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     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
24 */
25
26 #ifndef GOOGLEPLUGIN_H
27 #define GOOGLEPLUGIN_H
28
29
30 #include <QObject>
31 #include <QDialog>
32 #include <QtPlugin>
33 #include <QIcon>
34 #include <QtNetwork>
35
36 #include "../../include/CommonDictInterface.h"
37 #include "../../include/settings.h"
38 #include "../../include/DictDialog.h"
39 #include "TranslationGoogle.h"
40 #include "GoogleDictDialog.h"
41
42 class GoogleDictDialog;
43
44 class GooglePlugin : public CommonDictInterface
45 {
46     Q_OBJECT
47     Q_INTERFACES(CommonDictInterface)
48 public:
49     GooglePlugin(QObject *parent=0);
50     ~GooglePlugin();
51
52     //! \returns source language code iso 639-2
53     QString langFrom() const;
54
55     //! \returns destination language code iso 639-2
56     QString langTo() const;
57
58     //! \returns dictionary name (like "old English" or so)
59     QString name() const;
60
61     //! \returns dictionary type (xdxf, google translate, etc)
62     QString type() const;
63
64     //! returns information about dictionary (name, authors, etc)
65     QString infoNote() const;
66
67     //! sets the language to which the translation is done
68     void setLangTo(QString langTo);
69
70     //! sets the language from which the translation is done
71     void setLangFrom(QString langFrom);
72
73     /*!
74         \returns DictDialog object that creates dialogs
75         for adding new dictionaries and changing plugin things
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     //! sets if connection with Internet is possible
86     void setConnectionAccept(QString connectionAcepted);
87
88     //! \returns the value of "connection_accepted" from settings
89     bool isConnectionAccept() const;
90
91     //! \returns a description of a word given by a QString
92     QString search(QString key);
93
94     //! \returns current plugin settings
95     Settings* settings();
96
97     //! Sets new settings
98     void setSettings(const Settings*);
99
100     //! \returns plugin icon
101     QIcon* icon();
102
103     //! \returns empty translation object (to be fetched later) for a given key
104     Translation* getTranslationFor(QString key);
105
106     //! initializes the list of available languages in Google translator
107     static void initLanguages();
108
109     static QMap<QString, QString> languages;
110
111 public slots:
112     /*! performs search in a dictionary
113       \param  word word to search for in a dictionary
114       \param limit limit on number of results
115
116       After finishing search it has to emit
117       \see CommonDictInterface:finalTranslation  finalTranslation
118     */
119     QList<Translation*> searchWordList(QString word, int limit=0);
120
121     //! stops current operation
122     void stop();
123
124     //! function called after the request from Google is returned
125     void done();
126
127     //! transforms Google format to String with translation
128     QString jsonParse(QString result);
129
130     //! sets information about dictionary
131     void getDictionaryInfo();
132
133     //! loads translations for each plugin only once
134     void retranslate();
135 protected:
136     static bool noNetworkErrorShowed;
137
138 private:
139     //! name of a dictionary
140     QString _name;
141     //! type of a dictionary
142     QString _type;
143     //! information about dictionary
144     QString _infoNote;
145
146     //! icon displayed during translations and when a dictionary is chosen
147     QIcon _icon;
148     Settings *_settings;
149     //! indicates if search is stopped
150     bool stopped;
151     bool _connectionAccept;
152     //! indicates if response from Google appeared
153     volatile bool wait;
154     QHttp *http;
155     GoogleDictDialog *_dictDialog;
156     QThread *threa;
157 };
158
159 #endif // GOOGLEPLUGIN_H
160
161