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