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 *******************************************************************************/
22 /*! \file stardictplugin.cpp
25 #include "StarDictPlugin.h"
27 #include "../../include/Notify.h"
28 #include <QTranslator>
29 #include <QCoreApplication>
32 StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
33 _langFrom(""), _langTo(""),_name(""), _infoNote("") {
34 _settings = new Settings();
35 _dictDialog = new StarDictDialog(this, this);
37 connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString)),
38 this, SIGNAL(notify(Notify::NotifyType,QString)));
41 _settings->setValue("type","stardict");
42 _icon = QIcon("/usr/share/mdictionary/xdxf.png");
49 void StarDictPlugin::retranslate() {
50 QString locale = QLocale::system().name();
52 QTranslator *translator = new QTranslator(this);
54 if(!translator->load(":/xdxf/translations/" + locale)) {
55 translator->load(":/xdxf/translations/en_US");
57 QCoreApplication::installTranslator(translator);
61 StarDictPlugin::~StarDictPlugin() {
67 QString StarDictPlugin::langFrom() const {
72 QString StarDictPlugin::langTo() const {
77 QString StarDictPlugin::name() const {
82 QString StarDictPlugin::type() const {
83 return QString("stardict");
87 QString StarDictPlugin::infoNote() const {
92 QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
93 QSet<Translation*> translations;
94 return translations.toList();
99 QString StarDictPlugin::search(QString key) {
105 void StarDictPlugin::stop() {
110 DictDialog* StarDictPlugin::dictDialog() {
115 CommonDictInterface* StarDictPlugin::getNew(const Settings *settings) const {
116 StarDictPlugin *plugin = new StarDictPlugin();
118 connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
119 this, SIGNAL(notify(Notify::NotifyType,QString)));
121 ((StarDictDialog*)plugin->dictDialog())->setLastDialogParent(_dictDialog->lastDialogParent());
125 if(settings && plugin->setSettings(settings)) {
127 disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
128 this, SIGNAL(notify(Notify::NotifyType,QString)));
132 disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
133 this, SIGNAL(notify(Notify::NotifyType,QString)));
140 bool StarDictPlugin::isAvailable() const {
145 Settings* StarDictPlugin::settings() {
150 bool StarDictPlugin::isCached() {
155 bool StarDictPlugin::setSettings(const Settings *settings) {
160 Q_EMIT settingsChanged();
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";
179 QIcon* StarDictPlugin::icon() {
184 int StarDictPlugin::countWords() {
190 void StarDictPlugin::clean() {
195 Q_EXPORT_PLUGIN2(stardict, StarDictPlugin)