1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
23 \brief Implementation of google plugin's main class.
25 \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
28 #ifndef GOOGLEPLUGIN_H
29 #define GOOGLEPLUGIN_H
38 #include "../../include/CommonDictInterface.h"
39 #include "../../include/settings.h"
40 #include "../../include/DictDialog.h"
41 #include "TranslationGoogle.h"
42 #include "GoogleDictDialog.h"
44 class GoogleDictDialog;
46 class GooglePlugin : public CommonDictInterface
49 Q_INTERFACES(CommonDictInterface)
51 GooglePlugin(QObject *parent=0);
54 //! \returns source language code iso 639-2
55 QString langFrom() const;
57 //! \returns destination language code iso 639-2
58 QString langTo() const;
60 //! \returns dictionary name (like "old English" or so)
63 //! \returns dictionary type (xdxf, google translate, etc)
66 //! returns information about dictionary (name, authors, etc)
67 QString infoNote() const;
69 //! sets the language to which the translation is done
70 void setLangTo(QString langTo);
72 //! sets the language from which the translation is done
73 void setLangFrom(QString langFrom);
76 \returns DictDialog object that creates dialogs
77 for adding new dictionaries and changing plugin things
79 DictDialog* dictDialog();
81 //! \returns new, clean copy of plugin with settings set as in Settings*
82 CommonDictInterface* getNew(const Settings*) const;
84 //! \returns whether plugin can start searching
85 bool isAvailable() const;
87 //! sets if connection with Internet is possible
88 void setConnectionAccept(QString connectionAcepted);
90 //! \returns the value of "connection_accepted" from settings
91 bool isConnectionAccept() const;
93 //! \returns a description of a word given by a QString
94 QString search(QString key);
96 //! \returns current plugin settings
100 void setSettings(const Settings*);
102 //! \returns plugin icon
105 //! \returns plugin icon's resource path
108 //! \returns empty translation object (to be fetched later) for a given key
109 Translation* getTranslationFor(QString key);
111 //! initializes the list of available languages in Google translator
112 static void initLanguages();
114 static QMap<QString, QString> languages;
117 /*! performs search in a dictionary
118 \param word word to search for in a dictionary
119 \param limit limit on number of results
121 After finishing search it has to emit
122 \see CommonDictInterface:finalTranslation finalTranslation
124 QList<Translation*> searchWordList(QString word, int limit=0);
126 //! stops current operation
129 //! function called after the request from Google is returned
132 //! transforms Google format to String with translation
133 QString jsonParse(QString result);
135 //! sets information about dictionary
136 void getDictionaryInfo();
138 //! loads translations for each plugin only once
141 static bool noNetworkErrorShowed;
144 //! name of a dictionary
146 //! type of a dictionary
148 //! information about dictionary
151 //! icon displayed during translations and when a dictionary is chosen
156 //! indicates if search is stopped
158 bool _connectionAccept;
159 //! indicates if response from Google appeared
162 GoogleDictDialog *_dictDialog;
166 #endif // GOOGLEPLUGIN_H