9879e1220786ef2fec012e51b06a4834e032d212
[mdictionary] / src / plugins / stardict / StarDictPlugin.cpp
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 stardictplugin.cpp
23 */
24
25 #include "StarDictPlugin.h"
26 #include <QDebug>
27 #include "../../include/Notify.h"
28 #include <QTranslator>
29 #include <QCoreApplication>
30 #include <QThread>
31
32 StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
33                     _langFrom(""), _langTo(""),_name(""), _infoNote("") {
34     _settings = new Settings();
35     _dictDialog = new StarDictDialog(this, this);
36
37     connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString)),
38             this, SIGNAL(notify(Notify::NotifyType,QString)));
39
40
41     _settings->setValue("type","stardict");
42     _icon = QIcon("/usr/share/mdictionary/xdxf.png");
43     _wordsCount = -1;
44     stopped = false;
45
46     initAccents();
47 }
48
49 void StarDictPlugin::retranslate() {
50     QString locale = QLocale::system().name();
51
52     QTranslator *translator = new QTranslator(this);
53
54     if(!translator->load(":/xdxf/translations/" + locale)) {
55         translator->load(":/xdxf/translations/en_US");
56     }
57     QCoreApplication::installTranslator(translator);
58 }
59
60
61 StarDictPlugin::~StarDictPlugin() {
62     delete _settings;
63     delete _dictDialog;
64 }
65
66
67 QString StarDictPlugin::langFrom() const {
68     return _langFrom;
69 }
70
71
72 QString StarDictPlugin::langTo() const {
73     return  _langTo;
74 }
75
76
77 QString StarDictPlugin::name() const {
78     return  _name;
79 }
80
81
82 QString StarDictPlugin::type() const {
83     return QString("stardict");
84 }
85
86
87 QString StarDictPlugin::infoNote() const {
88     return _infoNote;
89 }
90
91
92 QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
93     QSet<Translation*> translations;
94     return translations.toList();
95 }
96
97
98
99 QString StarDictPlugin::search(QString key) {
100     return "";
101 }
102
103
104
105 void StarDictPlugin::stop() {
106     stopped=true;
107 }
108
109
110 DictDialog* StarDictPlugin::dictDialog() {
111      return _dictDialog;
112 }
113
114
115 CommonDictInterface* StarDictPlugin::getNew(const Settings *settings) const {
116     StarDictPlugin *plugin = new StarDictPlugin();
117
118     connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
119             this, SIGNAL(notify(Notify::NotifyType,QString)));
120
121     ((StarDictDialog*)plugin->dictDialog())->setLastDialogParent(_dictDialog->lastDialogParent());
122
123
124
125     if(settings && plugin->setSettings(settings)) {
126
127         disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
128                 this, SIGNAL(notify(Notify::NotifyType,QString)));
129         return plugin;
130     }
131     else {
132         disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
133                 this, SIGNAL(notify(Notify::NotifyType,QString)));
134         delete plugin;
135         return 0;
136     }
137 }
138
139
140 bool StarDictPlugin::isAvailable() const {
141     return true;
142 }
143
144
145 Settings* StarDictPlugin::settings() {
146     return _settings;
147 }
148
149
150 bool StarDictPlugin::isCached() {
151     return false;
152 }
153
154
155 bool StarDictPlugin::setSettings(const Settings *settings) {
156     if(settings) {
157
158     } else
159         return false;
160     Q_EMIT settingsChanged();
161     return true;
162 }
163
164
165 bool StarDictPlugin::getDictionaryInfo() {
166     QFile dictionaryFile(_settings->value("path"));
167     if(!QFile::exists(_settings->value("path"))
168                 || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
169        Q_EMIT notify(Notify::Warning,
170                QString(tr("StarDict dictionary cannot be read from file")));
171         qDebug()<<"Error: could not open the file";
172         return false;
173     }
174
175     return false;
176 }
177
178
179 QIcon* StarDictPlugin::icon() {
180     return &_icon;
181 }
182
183
184 int StarDictPlugin::countWords() {
185     return 0;
186 }
187
188
189
190 void StarDictPlugin::clean() {
191
192 }
193
194
195 Q_EXPORT_PLUGIN2(stardict, StarDictPlugin)