add getTranslationFor function for 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
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
102 public slots:
103     /*! performs search in dictionary
104       \param  word word to search in dictionary
105       \param limit limit on number of results
106
107       After finishing search it has to emit
108       \see CommonDictInterface:finalTranslation  finalTranslation
109     */
110     QList<Translation*> searchWordList(QString word, int limit=0);
111
112     //! stop current operation
113     void stop();
114
115     void done();
116     void started(int);
117
118 private:
119     void initLanguages();
120     QMap<QString, QString> languages;
121
122     //! language from which we translate
123     QString _langFrom;
124     //! language to which we translate
125     QString _langTo;
126     //! name of a dictionary
127     QString _name;
128     //! type of a dictionary
129     QString _type;
130     //! information about dictionary
131     QString _infoNote;
132     //! path to dictionary file
133     QString path;
134     uint _hash;
135     QIcon _icon;
136     Settings *_settings;
137     bool stopped;
138     volatile bool wait;
139     QHttp *http;
140     GoogleDictDialog *_dictDialog;
141 };
142
143 #endif // GOOGLEPLUGIN_H
144
145