Merge branch 'http' into stardict
authorMarcin Kazmierczak <marcin.kazmierczak@comarch.pl>
Tue, 5 Oct 2010 12:10:49 +0000 (14:10 +0200)
committerMarcin Kazmierczak <marcin.kazmierczak@comarch.pl>
Tue, 5 Oct 2010 12:10:49 +0000 (14:10 +0200)
25 files changed:
mdictionary.pri
src/plugins/plugins.pri
src/plugins/stardict/StarDialog.cpp [new file with mode: 0644]
src/plugins/stardict/StarDialog.h [new file with mode: 0644]
src/plugins/stardict/StarDict.qrc [new file with mode: 0644]
src/plugins/stardict/StarDictDialog.cpp [new file with mode: 0644]
src/plugins/stardict/StarDictDialog.h [new file with mode: 0644]
src/plugins/stardict/StarDictPlugin.cpp [new file with mode: 0644]
src/plugins/stardict/StarDictPlugin.h [new file with mode: 0644]
src/plugins/stardict/StarDictSettingsDialog.cpp [new file with mode: 0644]
src/plugins/stardict/TranslationStarDict.cpp [new file with mode: 0644]
src/plugins/stardict/TranslationStarDict.h [new file with mode: 0644]
src/plugins/stardict/en_US.ts [new file with mode: 0644]
src/plugins/stardict/pl_PL.ts [new file with mode: 0644]
src/plugins/stardict/stardict.pro [new file with mode: 0644]
src/plugins/stardict/translations/en_US.qm [new file with mode: 0644]
src/plugins/stardict/translations/pl_PL.qm [new file with mode: 0644]
src/plugins/stardict/xdxf.png [new file with mode: 0644]
src/plugins/xdxf/HttpDownloader.cpp
src/plugins/xdxf/HttpDownloader.h
src/plugins/xdxf/XdxfDialog.cpp
src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp
src/plugins/xdxf/XdxfDictDownloadProgressDialog.h
src/plugins/xdxf/XdxfDictDownloader.cpp
src/plugins/xdxf/XdxfDictDownloader.h

index 3a5aeeb..ab81e07 100644 (file)
@@ -8,7 +8,7 @@ CONFIG += \
 CONFIG -= debug
 
 isEmpty(ENABLED_SRC):ENABLED_SRC = "mdictionary plugins desktopWidget"
-isEmpty(ENABLED_PLUGINS):ENABLED_PLUGINS = "xdxf google"
+isEmpty(ENABLED_PLUGINS):ENABLED_PLUGINS = "xdxf google stardict"
 
 isEmpty(INSTALL_PREFIX):INSTALL_PREFIX=/usr
 isEmpty(BIN_DIR):BIN_DIR=$$INSTALL_PREFIX/bin
index ba1bf3d..df3baf9 100644 (file)
@@ -1 +1 @@
-ENABLED_PLUGINS = xdxf google
+ENABLED_PLUGINS = xdxf google stardict
diff --git a/src/plugins/stardict/StarDialog.cpp b/src/plugins/stardict/StarDialog.cpp
new file mode 100644 (file)
index 0000000..3874fba
--- /dev/null
@@ -0,0 +1,252 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "StarDialog.h"
+#include <QDebug>
+
+StarDialog::StarDialog(StarDictPlugin *plugin,
+                       StarDialogType type,
+                       QWidget *parent) :
+    QDialog(parent) {
+    this->plugin = plugin;
+    this->type = type;
+
+
+    cacheToolTip = tr("Optimize for quicker searches (may take some time)");
+    accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)");
+
+    initializeUI();
+
+    connect(cacheCheckBox, SIGNAL(toggled(bool)),
+            this, SLOT(setGenerateCache(bool)));
+
+    connect(accentsCheckBox, SIGNAL(toggled(bool)),
+            this, SLOT(setAccents(bool)));
+
+    #ifdef Q_WS_MAEMO_5
+        connect(accentsInfoToolButton, SIGNAL(clicked()),
+                 this, SLOT(showAccentsInfo()));
+
+        connect(cacheInfoToolButton, SIGNAL(clicked()),
+                 this, SLOT(showCacheInfo()));
+    #endif
+
+    if(type == New) {
+        connect(browseButton, SIGNAL(clicked()),
+                this, SLOT(selectFile()));
+    }
+
+    connect(confirmButton, SIGNAL(clicked()),
+            this, SLOT(accept()));
+
+}
+
+
+void StarDialog::initializeUI() {
+    mainVerticalLayout = new QVBoxLayout;
+    widget = new QWidget;
+    widget->setLayout(mainVerticalLayout);
+
+    infoLabel = new QLabel;
+    infoLabel->setWordWrap(true);
+
+    if(type == New) {
+        setWindowTitle(tr("Add new XDXF dictionary"));
+
+        browseLayout = new QHBoxLayout;
+        browseButton = new QPushButton(tr("Browse"));
+        infoLabel->setText(tr("Dictionary file: not selected"));
+
+        browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
+        browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
+
+        mainVerticalLayout->addLayout(browseLayout);
+    }
+    else {
+        setWindowTitle(tr("XDXF Settings"));
+
+        infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
+                       tr("From: ") + plugin->langFrom() + "\n" +
+                       tr("To: ") + plugin->langTo() + "\n" +
+                       tr("Description: ") + plugin->name() + "\n" +
+                       plugin->infoNote());
+        mainVerticalLayout->addWidget(infoLabel);
+    }
+
+    accentsLayout = new QHBoxLayout;
+    accentsCheckBox = new QCheckBox(tr("Strip accents"));
+    accentsCheckBox->setToolTip(accentsToolTip);
+    accentsLayout->addWidget(accentsCheckBox); 
+    #ifdef Q_WS_MAEMO_5
+        accentsInfoToolButton = new QToolButton;
+        accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
+        accentsLayout->addWidget(accentsInfoToolButton);
+    #endif
+
+    cacheLayout = new QHBoxLayout;
+    cacheCheckBox = new QCheckBox(tr("Optimize"));
+    cacheCheckBox->setToolTip(cacheToolTip);
+    cacheLayout->addWidget(cacheCheckBox);
+    #ifdef Q_WS_MAEMO_5
+        cacheInfoToolButton = new QToolButton;
+        cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
+        cacheLayout->addWidget(cacheInfoToolButton);
+    #endif
+
+    mainVerticalLayout->addLayout(cacheLayout);
+    mainVerticalLayout->addLayout(accentsLayout);
+
+
+    //load old setting if exists
+    if(!plugin) {
+        cacheCheckBox->setChecked(true);
+        accentsCheckBox->setChecked(true);
+        accentsCheckBox->setEnabled(false);
+        _generateCache = true;
+        _accents = true;
+        _dictionaryFilePath = "";
+    }
+    else if(plugin && plugin->settings()->value("cached") == "true") {
+        cacheCheckBox->setChecked(true);
+        accentsCheckBox->setChecked(true);
+        accentsCheckBox->setEnabled(false);
+        _generateCache = true;
+        _accents = true;
+    }
+    else {
+        cacheCheckBox->setChecked(false);
+        _generateCache = false;
+
+        if(plugin->settings()->value("strip_accents") == "true") {
+            accentsCheckBox->setChecked(true);
+            _accents = true;
+        }
+        else {
+            accentsCheckBox->setChecked(false);
+            _accents = false;
+        }
+    }
+
+    confirmButton = new QPushButton;
+    mainVerticalLayout->addWidget(confirmButton);
+    if(type == New) {
+        confirmButton->setText(tr("Add"));
+    }
+    else {
+        confirmButton->setText(tr("Save settings"));
+    }
+
+    scrollArea = new QScrollArea;
+    scrollArea->setWidget(widget);
+    scrollArea->setWidgetResizable(true);
+    #ifdef Q_WS_MAEMO_5
+        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    #else
+        if(type==New) {
+            infoLabel->setMinimumWidth(200);
+            setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
+            setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
+            scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+        }
+    #endif
+
+    layout = new QHBoxLayout;
+    layout->addWidget(scrollArea);
+    setLayout(layout);
+
+    #ifndef Q_WS_MAEMO_5
+        setMinimumSize(400,200);
+    #else
+        setMinimumHeight(350);
+    #endif
+
+    scrollArea->setLineWidth(0);
+    scrollArea->setMidLineWidth(0);
+    scrollArea->setFrameStyle(QFrame::NoFrame);
+
+
+}
+
+
+void StarDialog::setAccents(bool accents) {
+    _accents = accents;
+}
+
+
+void StarDialog::selectFile() {
+    QString fileName = QFileDialog::getOpenFileName(this,
+                                     tr("Select dictionary file"),
+                                     _dictionaryFilePath,
+                                     tr("XDXF Files (*.xdxf)"),
+                                     NULL,
+                                     NULL);
+
+    if (!fileName.isEmpty()) {
+        infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
+        _dictionaryFilePath = fileName;
+        updateGeometry();
+    }
+}
+
+void StarDialog::saveSettings() {
+    _settings = new Settings;
+    if(plugin) {
+        foreach(QString key, plugin->settings()->keys())
+            _settings->setValue(key, plugin->settings()->value(key));
+    }
+    else {
+        _settings->setValue("path", _dictionaryFilePath);
+    }
+
+    if(_generateCache)
+        _settings->setValue("generateCache", "true");
+    else
+        _settings->setValue("generateCache", "false");
+
+    if(_accents)
+        _settings->setValue("strip_accents", "true");
+    else
+        _settings->setValue("strip_accents", "false");
+}
+
+void StarDialog::accept() {
+    if(type == New && _dictionaryFilePath.isEmpty()) {
+        Q_EMIT notify(Notify::Warning, tr("File path is not set"));
+
+        return;
+    }
+
+    saveSettings();
+    QDialog::accept();
+}
+
+Settings* StarDialog::getSettings() {
+    return _settings;
+}
+
+#ifdef Q_WS_MAEMO_5
+    void StarDialog::showAccentsInfo() {
+        Q_EMIT notify(Notify::Warning, accentsToolTip);
+    }
+#endif
+
diff --git a/src/plugins/stardict/StarDialog.h b/src/plugins/stardict/StarDialog.h
new file mode 100644 (file)
index 0000000..85a08cc
--- /dev/null
@@ -0,0 +1,147 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+    \file XdxfDialog.cpp
+    \author Mateusz Półrola <mateusz.polrola@gmail.com>
+*/
+
+#ifndef STARDIALOG_H
+#define STARDIALOG_H
+
+#include <QDialog>
+#include "../../include/settings.h"
+#include <QtGui>
+#include "StarDictPlugin.h"
+
+
+//! Implementation of xdxf plugin's dialogs.
+/*!
+    This class can create dialogs for adding a new dictionary or changing settings
+     of an existing one, based on dialog type passed to contructor.
+    When adding a new dictionary dialog contains a button to browse file system and
+    select a dictionary file. When changing settings dialog displays basic
+    information about dictionary i. e. name, languages and license info.
+    In both types of dialogs there are comboboxes with "cache" and "remove accents"
+     options. On maemo right next to comboboxes are tool buttons which allow to
+     see more information about these options, on desktop the same information is
+     displayed as a tool tip.
+    All contents of a dialog are in a scroll area.
+*/
+class StarDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    /*!
+      Describes type of dialog. New means that dialog contains widgets to browse
+        file system and select dictionary file. Change means that dialog displays
+     information about dictionary.
+      In both types dialog provides widgets to create or delete cache and remove
+     or keep accents.
+    */
+    enum StarDialogType {New, Change};
+
+    //! Constructor
+    /*!
+        Creates new xdxf dialog
+        \param plugin if created dialog is of type Change it must be set to
+            point to plugin whose settings will be changed
+        \param type describes type of created dialog
+        \param parent parent widget of created dialog
+    */
+    explicit StarDialog(StarDictPlugin* plugin = 0,
+                        StarDialogType type = New,
+                        QWidget* parent = 0);
+
+    //! \returns settings of plugin
+    /*!
+        After acceptance of dialog this method returns plugin's settings based on
+         user's choices in dialog.
+    */
+    Settings* getSettings();
+
+Q_SIGNALS:
+    //! Requests to show notification
+    void notify(Notify::NotifyType, QString);
+
+public Q_SLOTS:
+    //! Reimplemented accept method, to check if all necessary fields in
+    //! dialog are correct e. g. dictionary file path
+    //! and saves new settings
+    void accept();
+
+private Q_SLOTS:
+    //! displays dialog to browse and select file
+    void selectFile();
+    void setAccents(bool);
+
+    #ifdef Q_WS_MAEMO_5
+        //! on maemo shows information about checkboxes
+        void showAccentsInfo();
+    #endif
+
+
+private:
+    void initializeUI();
+
+    //! saves new settings after acceptance of dialog
+    void saveSettings();
+
+    QLabel* infoLabel;
+    QPushButton* browseButton;
+    QHBoxLayout* browseLayout;
+
+
+    QCheckBox* cacheCheckBox;
+    QCheckBox* accentsCheckBox;
+    QHBoxLayout* cacheLayout;
+    QHBoxLayout* accentsLayout;
+
+    QString cacheToolTip;
+    QString accentsToolTip;
+
+    #ifdef Q_WS_MAEMO_5
+        QToolButton* cacheInfoToolButton;
+        QToolButton* accentsInfoToolButton;
+    #endif
+
+
+    QPushButton* confirmButton;
+
+    QString _dictionaryFilePath;
+
+    QScrollArea* scrollArea;
+
+    QWidget* widget;
+    QHBoxLayout* layout;
+
+    QVBoxLayout* mainVerticalLayout;
+    bool _generateCache;
+    bool _accents;
+    bool _lastAccents;
+
+    Settings* _settings;
+
+    StarDictPlugin* plugin;
+    StarDialogType type;
+};
+
+#endif // STARDIALOG_H
diff --git a/src/plugins/stardict/StarDict.qrc b/src/plugins/stardict/StarDict.qrc
new file mode 100644 (file)
index 0000000..0642344
--- /dev/null
@@ -0,0 +1,6 @@
+<RCC>
+    <qresource prefix="/xdxf">
+        <file>translations/pl_PL.qm</file>
+        <file>translations/en_US.qm</file>
+    </qresource>
+</RCC>
diff --git a/src/plugins/stardict/StarDictDialog.cpp b/src/plugins/stardict/StarDictDialog.cpp
new file mode 100644 (file)
index 0000000..d6dd535
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file XdxfDictDialog.cpp
+*/
+//Created by Mateusz Półrola
+
+#include "StarDictDialog.h"
+#include "StarDictPlugin.h"
+#include "StarDialog.h"
+#include <QDebug>
+
+StarDictDialog::StarDictDialog(StarDictPlugin *plugin, QObject *parent) :
+    DictDialog(parent) {
+    this->plugin = plugin;
+    _lastDialogParent=0;
+}
+
+QWidget* StarDictDialog::lastDialogParent() {
+    return _lastDialogParent;
+}
+
+void StarDictDialog::setLastDialogParent(QWidget *w) {
+    _lastDialogParent = w;
+}
+
+Settings* StarDictDialog::addNewDictionary(QWidget *parent) {
+    StarDialog d(0, StarDialog::New, parent);
+
+    setLastDialogParent(parent);
+
+    connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
+
+    if(d.exec() == QDialog::Accepted) {
+        return d.getSettings();
+    }
+    return 0;
+}
+
+void StarDictDialog::changeSettings(QWidget * parent) {
+    StarDialog d(plugin, StarDialog::Change, parent);
+
+    setLastDialogParent(parent);
+
+    connect(&d, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
+
+    if(d.exec() == QDialog::Accepted) {
+        plugin->setSettings(d.getSettings());
+    }
+}
diff --git a/src/plugins/stardict/StarDictDialog.h b/src/plugins/stardict/StarDictDialog.h
new file mode 100644 (file)
index 0000000..f4a33e1
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+/*! \file XdxfDictDialog.h
+*/
+//Created by Mateusz Półrola
+
+#ifndef STARDICTDIALOG_H
+#define STARDICTDIALOG_H
+
+#include "../../include/DictDialog.h"
+
+class StarDictPlugin;
+
+
+//! Implementation of DictDialog interface for xdxf plugin
+class StarDictDialog : public DictDialog {
+    Q_OBJECT
+public:
+    explicit StarDictDialog(StarDictPlugin* plugin, QObject *parent = 0);
+    /*!
+      Shows "add new xdxf dictionary" dialog and returns settings of a new dict
+      \param parent parent widget on which dialog will be displayed
+      */
+    Settings* addNewDictionary(QWidget *parent);
+
+    /*!
+      Shows settings dialog and saves new settings in plugin
+      \param parent parent widget on which dialog will be displayed
+      */
+    void changeSettings(QWidget *parent);
+
+    QWidget* lastDialogParent();
+
+    void setLastDialogParent(QWidget*);
+
+private:
+    StarDictPlugin* plugin;
+    QWidget* _lastDialogParent;
+};
+
+#endif // STARDICTDIALOG_H
diff --git a/src/plugins/stardict/StarDictPlugin.cpp b/src/plugins/stardict/StarDictPlugin.cpp
new file mode 100644 (file)
index 0000000..9879e12
--- /dev/null
@@ -0,0 +1,195 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file stardictplugin.cpp
+*/
+
+#include "StarDictPlugin.h"
+#include <QDebug>
+#include "../../include/Notify.h"
+#include <QTranslator>
+#include <QCoreApplication>
+#include <QThread>
+
+StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
+                    _langFrom(""), _langTo(""),_name(""), _infoNote("") {
+    _settings = new Settings();
+    _dictDialog = new StarDictDialog(this, this);
+
+    connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
+
+
+    _settings->setValue("type","stardict");
+    _icon = QIcon("/usr/share/mdictionary/xdxf.png");
+    _wordsCount = -1;
+    stopped = false;
+
+    initAccents();
+}
+
+void StarDictPlugin::retranslate() {
+    QString locale = QLocale::system().name();
+
+    QTranslator *translator = new QTranslator(this);
+
+    if(!translator->load(":/xdxf/translations/" + locale)) {
+        translator->load(":/xdxf/translations/en_US");
+    }
+    QCoreApplication::installTranslator(translator);
+}
+
+
+StarDictPlugin::~StarDictPlugin() {
+    delete _settings;
+    delete _dictDialog;
+}
+
+
+QString StarDictPlugin::langFrom() const {
+    return _langFrom;
+}
+
+
+QString StarDictPlugin::langTo() const {
+    return  _langTo;
+}
+
+
+QString StarDictPlugin::name() const {
+    return  _name;
+}
+
+
+QString StarDictPlugin::type() const {
+    return QString("stardict");
+}
+
+
+QString StarDictPlugin::infoNote() const {
+    return _infoNote;
+}
+
+
+QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
+    QSet<Translation*> translations;
+    return translations.toList();
+}
+
+
+
+QString StarDictPlugin::search(QString key) {
+    return "";
+}
+
+
+
+void StarDictPlugin::stop() {
+    stopped=true;
+}
+
+
+DictDialog* StarDictPlugin::dictDialog() {
+     return _dictDialog;
+}
+
+
+CommonDictInterface* StarDictPlugin::getNew(const Settings *settings) const {
+    StarDictPlugin *plugin = new StarDictPlugin();
+
+    connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
+
+    ((StarDictDialog*)plugin->dictDialog())->setLastDialogParent(_dictDialog->lastDialogParent());
+
+
+
+    if(settings && plugin->setSettings(settings)) {
+
+        disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+                this, SIGNAL(notify(Notify::NotifyType,QString)));
+        return plugin;
+    }
+    else {
+        disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+                this, SIGNAL(notify(Notify::NotifyType,QString)));
+        delete plugin;
+        return 0;
+    }
+}
+
+
+bool StarDictPlugin::isAvailable() const {
+    return true;
+}
+
+
+Settings* StarDictPlugin::settings() {
+    return _settings;
+}
+
+
+bool StarDictPlugin::isCached() {
+    return false;
+}
+
+
+bool StarDictPlugin::setSettings(const Settings *settings) {
+    if(settings) {
+
+    } else
+        return false;
+    Q_EMIT settingsChanged();
+    return true;
+}
+
+
+bool StarDictPlugin::getDictionaryInfo() {
+    QFile dictionaryFile(_settings->value("path"));
+    if(!QFile::exists(_settings->value("path"))
+                || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+       Q_EMIT notify(Notify::Warning,
+               QString(tr("StarDict dictionary cannot be read from file")));
+        qDebug()<<"Error: could not open the file";
+        return false;
+    }
+
+    return false;
+}
+
+
+QIcon* StarDictPlugin::icon() {
+    return &_icon;
+}
+
+
+int StarDictPlugin::countWords() {
+    return 0;
+}
+
+
+
+void StarDictPlugin::clean() {
+
+}
+
+
+Q_EXPORT_PLUGIN2(stardict, StarDictPlugin)
diff --git a/src/plugins/stardict/StarDictPlugin.h b/src/plugins/stardict/StarDictPlugin.h
new file mode 100644 (file)
index 0000000..f371153
--- /dev/null
@@ -0,0 +1,180 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+
+/*! \file xdxfplugin.h
+*/
+#ifndef STARDICTPLUGIN_H
+#define STARDICTPLUGIN_H
+
+
+#include <QObject>
+#include <QDialog>
+#include <QRegExp>
+#include <QTime>
+#include <QSqlQuery>
+#include <QSqlDatabase>
+#include <QSqlError>
+#include <QFile>
+#include <QXmlStreamReader>
+#include <QtPlugin>
+#include <QHash>
+#include <QIcon>
+
+#include "../../include/CommonDictInterface.h"
+#include "../../include/settings.h"
+#include "StarDictDialog.h"
+#include "TranslationStarDict.h"
+
+class TranslationXdxf;
+
+class StarDictPlugin : public CommonDictInterface
+{
+    Q_OBJECT
+    Q_INTERFACES(CommonDictInterface)
+public:
+    StarDictPlugin(QObject *parent=0);
+
+    ~StarDictPlugin();
+
+    //! \returns source language code iso 639-2
+    QString langFrom() const;
+
+    //! \returns destination language code iso 639-2
+    QString langTo() const;
+
+    //! \returns dictionary name (like "old English" or so)
+    QString name() const;
+
+    //! \returns dictionary type (xdxf, google translate, etc)
+    QString type() const;
+
+    //! returns information about dictionary in xml (name, authors, etc)
+    QString infoNote() const;
+
+    /*! \returns DictDialog object that creates dialogs
+        for adding a new dictionary and changing plugin settings
+      */
+    DictDialog* dictDialog();
+
+    //! \returns new, clean copy of plugin with settings set as in Settings*
+    CommonDictInterface* getNew(const Settings*) const;
+
+    //! \returns whether plugin can start searching
+    bool isAvailable() const;
+
+    //! \returns a description of a word given by a QString
+    QString search(QString key);
+
+    //! \returns current plugin settings
+    Settings* settings();
+
+    //! \returns words count in a dictionary
+    long wordsCount();
+
+    //! Sets new settings
+    bool setSettings(const Settings*);
+
+    //! \returns plugin icon
+    QIcon* icon();
+
+    /*! plugin should delete any files (eg. cache) that have been created and are ready
+        to be deleted
+        */
+    void clean();
+
+
+
+public Q_SLOTS:
+    /*! performs search in a dictionary
+      \param  word word to search for in a dictionary
+      \param limit limit on number of results
+
+      After finishing search it has to emit
+      \see CommonDictInterface:finalTranslation  finalTranslation
+    */
+    QList<Translation*> searchWordList(QString word, int limit=0);
+
+    //! stops current operation
+    void stop();
+
+    //! loads translations for each plugin only once
+    void retranslate();
+
+
+private:
+
+    /*! \returns true or false depending on whether the dictionary is cached
+        or not
+     */
+    bool isCached();
+    /*! searches for a list of words similar to a word in a database file
+    \param word key compared with keys in a database
+    \param limit limits the number of translations in returned list,
+           0 means unlimited
+    \returns list of translations
+    */
+    QList<Translation*> searchWordListCache(QString word, int limit=0);
+
+    /*! searches for a list of words similar to a word in a xdxf file
+    \param word key compared with keys in a xdxf file
+    \param limit limits the number of translations in returned list,
+           0 means unlimited
+    \returns list of translations
+    */
+    QList<Translation*> searchWordListFile(QString word, int limit=0);
+
+    /*! searches for a translation of a word which is exactly like a key
+        in a xdxf file */
+    QString searchFile(QString key);
+
+    //! scans dictionary file to get information about it
+    bool getDictionaryInfo();
+
+    //! counts the keys in a xdxf file
+    int countWords();
+
+
+    //! language from which we translate
+    QString _langFrom;
+    //! language to which we translate
+    QString _langTo;
+    //! name of a dictionary
+    QString _name;
+    //! information about dictionary
+    QString _infoNote;
+
+    QString _dictionaryInfo;
+
+    //! icon displayed during translations and when a dictionary is chosen
+    QIcon _icon;
+
+    //! number of words in a dictionary
+    long _wordsCount;
+    //! indicates if search is stopped
+    volatile bool stopped;
+    Settings *_settings;
+    StarDictDialog* _dictDialog;
+};
+
+#endif // XDXFPLUGIN_H
+
+
diff --git a/src/plugins/stardict/StarDictSettingsDialog.cpp b/src/plugins/stardict/StarDictSettingsDialog.cpp
new file mode 100644 (file)
index 0000000..f9b4206
--- /dev/null
@@ -0,0 +1,175 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file XdxfSettingsDialog.cpp
+*/
+//Created by Mateusz Półrola
+
+#include "XdxfSettingsDialog.h"
+#include <QDebug>
+
+XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
+    QDialog(parent)
+{
+    this->plugin = plugin;
+    verticalLayout = new QVBoxLayout();
+       setLayout(verticalLayout);
+
+    setWindowTitle(tr("XDXF Settings"));
+
+
+    infoLabel = new QLabel(this);
+
+    infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
+                   tr("From: ") + plugin->langFrom() + "\n" +
+                   tr("To: ") + plugin->langTo() + "\n" +
+                   tr("Description: ") + plugin->name());
+
+    verticalLayout->addWidget(infoLabel);
+
+    browseLayout = new QHBoxLayout();
+    verticalLayout->addLayout(browseLayout);
+
+    browseButton =  new QPushButton(tr("Browse"));
+    browseLabel = new QLabel(tr("Dictionary file: ") +
+                             plugin->settings()->value("path"));
+
+    browseLayout->addWidget(browseLabel);
+    browseLayout->addWidget(browseButton,0, Qt::AlignRight);
+
+
+    cacheLayout = new QHBoxLayout();
+    verticalLayout->insertLayout(-1,cacheLayout,0);
+    accentsCheckBox = new QCheckBox(tr("Strip accents \n(searching takes more time, "
+                 "but spelling don't have to be exact)"));
+    verticalLayout->addWidget(accentsCheckBox);
+
+    if(plugin->settings()->value("strip_accents") == "true")
+        accentsCheckBox->setChecked(true);
+    else
+        accentsCheckBox->setChecked(false);
+
+    cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"),this);
+    if(plugin->settings()->value("cached") == "true") {
+        cacheCheckBox->setChecked(true);
+        accentsCheckBox->setChecked(true);
+        accentsCheckBox->setEnabled(false);
+        _generateCache = true;
+    }
+    else {
+        cacheCheckBox->setChecked(false);
+        _generateCache = false;
+    }
+
+    cacheLayout->addWidget(cacheCheckBox);
+
+    saveButton = new QPushButton(tr("Save settings"));
+
+    verticalLayout->addWidget(saveButton);
+
+    setModal(true);
+
+    connect(browseButton, SIGNAL(clicked()),
+            this, SLOT(selectFile()));
+
+    connect(saveButton, SIGNAL(clicked()),
+            this, SLOT(accept()));
+
+    connect(cacheCheckBox, SIGNAL(toggled(bool)),
+            SLOT(setGenerateCache(bool)));
+
+    connect(accentsCheckBox, SIGNAL(clicked(bool)), SLOT(setAccents(bool)));
+
+
+    _dicitonaryFilePath = plugin->settings()->value("path");
+    lastAccents = accentsCheckBox->isChecked();
+}
+
+
+void XdxfSettingsDialog::setAccents(bool state) {
+    lastAccents = state;
+}
+
+
+void XdxfSettingsDialog::setGenerateCache(bool generate) {
+    _generateCache = generate;
+
+    if(generate)
+        accentsCheckBox->setChecked(true);
+    else
+        accentsCheckBox->setChecked(lastAccents);
+
+    accentsCheckBox->setEnabled(!generate);
+}
+
+bool XdxfSettingsDialog::generateCache() {
+    return _generateCache;
+}
+
+void XdxfSettingsDialog::selectFile() {
+    QString fileName = QFileDialog::getOpenFileName(this,
+                                     tr("Select dictionary file"),
+                                     "",
+                                     tr("XDXF Files (*.xdxf)"),
+                                     0,
+                                     0);
+    if (!fileName.isEmpty()) {
+        browseLabel->setText(tr("Dictionary file: ") + fileName);
+        _dicitonaryFilePath = fileName;
+    }    
+}
+
+QString XdxfSettingsDialog::dicitonaryFilePath() {
+    return _dicitonaryFilePath;
+}
+
+Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
+                                          QWidget *parent) {
+    XdxfSettingsDialog settingsDialog(plugin, parent);
+
+
+    if(settingsDialog.exec()==QDialog::Accepted) {
+        Settings* settings = new Settings;
+        foreach(QString key, plugin->settings()->keys())
+            settings->setValue(key, plugin->settings()->value(key));
+        settings->setValue("path", settingsDialog.dicitonaryFilePath());
+
+        if(settingsDialog.generateCache()) {
+            settings->setValue("generateCache", "true");
+        }
+        else {
+            settings->setValue("generateCache", "false");
+        }
+
+        if(settingsDialog.accentsCheckBox->isChecked())
+            settings->setValue("strip_accents", "true");
+        else
+            settings->setValue("strip_accents", "false");
+
+        plugin->setSettings(settings);
+        delete settings;
+        return 0;
+    }
+
+    return 0;
+}
+
+
diff --git a/src/plugins/stardict/TranslationStarDict.cpp b/src/plugins/stardict/TranslationStarDict.cpp
new file mode 100644 (file)
index 0000000..942b21e
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+/*! \file TranslationXdxf.cpp
+    \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
+*/
+
+
+#include "TranslationStarDict.h"
+#include <QDebug>
+
+TranslationStarDict::TranslationStarDict():_key(""),_dictionaryInfo("") {
+    starDictPlugin=0;
+}
+
+TranslationStarDict::TranslationStarDict(QString _key, QString _dictionaryInfo,
+         StarDictPlugin *starDictPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
+    this->starDictPlugin=starDictPlugin;
+    if(starDictPlugin)
+        _dictHash = starDictPlugin->hash();
+    _bookmark=0;
+}
+
+
+QString TranslationStarDict::key() const {
+    return _key;
+}
+
+QString TranslationStarDict::toXml() const {
+    QString result("");
+    if(!starDictPlugin)
+        return result;
+
+    result=result + "<dict> <info path=\"/usr/share/mdictionary/xdxf.png\" ";
+    if(isBookmark())
+        result+= " bookmark=\"true\" > \n";
+    else
+        result+= " bookmark=\"false\" > \n";
+    result+= _dictionaryInfo + "</info>" + starDictPlugin->search(_key) + "</dict>";
+    return result.replace("&","&amp;");
+}
+
+void TranslationStarDict::setKey(QString _key) {
+    this->_key=_key;
+}
+
+void TranslationStarDict::setDictionaryInfo(QString _dictionaryInfo) {
+    this->_dictionaryInfo=_dictionaryInfo;
+}
+
diff --git a/src/plugins/stardict/TranslationStarDict.h b/src/plugins/stardict/TranslationStarDict.h
new file mode 100644 (file)
index 0000000..6a18cf8
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+/*! \file TranslationXdxf.h
+*/
+#ifndef TRANSLATIONSTARDICT_H
+#define TRANSLATIONSTARDICT_H
+
+#include <QString>
+#include "../../include/translation.h"
+#include "StarDictPlugin.h"
+
+class TranslationStarDict : public Translation
+{
+public:
+    TranslationStarDict();
+    TranslationStarDict(QString _key,
+                    QString _dictionaryInfo,
+                    StarDictPlugin *starDictPlugin);
+
+    //! \return word to be translated
+    QString key() const;
+
+    //! \return parsed raw format into xml
+    QString toXml() const;
+
+    /*! sets the word for which we want to find a translation
+        \param word for which we want to find a translation */
+    void setKey(QString);
+
+    //! sets information about dictionary
+    void setDictionaryInfo(QString);
+
+    //! \return whether given translation is taken from bookmarks
+    int isBookmark() const {
+        return _bookmark;
+   }
+
+    //! returns corresponding dict object
+    uint dict() const {return _dictHash;}
+
+private:
+    QString _key;
+    QString _dictionaryInfo;
+    StarDictPlugin *starDictPlugin;
+    int _dictHash;
+};
+
+#endif // TRANSLATIONSTARDICT_H
+
diff --git a/src/plugins/stardict/en_US.ts b/src/plugins/stardict/en_US.ts
new file mode 100644 (file)
index 0000000..64c07a0
--- /dev/null
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.0" language="en_US">
+<context>
+    <name>XdxfCachingDialog</name>
+    <message>
+        <location filename="XdxfCachingDialog.cpp" line="35"/>
+        <location filename="XdxfCachingDialog.cpp" line="49"/>
+        <source>Caching dictionary, please wait</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfCachingDialog.cpp" line="41"/>
+        <source>Cancel</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfCachingDialog.cpp" line="79"/>
+        <source>Estimated time left: </source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message numerus="yes">
+        <location filename="XdxfCachingDialog.cpp" line="80"/>
+        <source>%n second(s)</source>
+        <translation>
+            <numerusform>%n second</numerusform>
+            <numerusform>%n seconds</numerusform>
+        </translation>
+    </message>
+</context>
+<context>
+    <name>XdxfDialog</name>
+    <message>
+        <location filename="XdxfDialog.cpp" line="35"/>
+        <source>Optimize for quicker searches (may take some time)</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="36"/>
+        <source>Strip accents (searching takes more time, but spelling doesn&apos;t have to be exact)</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="74"/>
+        <source>Add new XDXF dictionary</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="77"/>
+        <source>Browse</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="78"/>
+        <source>Dictionary file: not selected</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="86"/>
+        <source>XDXF Settings</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="88"/>
+        <source>Plugin: </source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="89"/>
+        <source>From: </source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="90"/>
+        <source>To: </source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="91"/>
+        <source>Description: </source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="97"/>
+        <source>Strip accents</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="107"/>
+        <source>Optimize</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="153"/>
+        <source>Add</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="156"/>
+        <source>Save settings</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="210"/>
+        <source>Select dictionary file</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="212"/>
+        <source>XDXF Files (*.xdxf)</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="217"/>
+        <source>Dictionary file: %1</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="246"/>
+        <source>File path is not set</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
+    <name>XdxfPlugin</name>
+    <message>
+        <location filename="xdxfplugin.cpp" line="108"/>
+        <location filename="xdxfplugin.cpp" line="206"/>
+        <location filename="xdxfplugin.cpp" line="523"/>
+        <source>Cache database cannot be opened for %1 dictionary. Searching in XDXF file. You may want to recache.</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="157"/>
+        <location filename="xdxfplugin.cpp" line="237"/>
+        <source>XDXF file cannot be read for %1</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="365"/>
+        <source>XDXF file is in wrong format</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="407"/>
+        <source>XDXF dictionary cannot be read from file</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="455"/>
+        <location filename="xdxfplugin.cpp" line="514"/>
+        <source>XDXF file cannot be read for %1 dictionary</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="605"/>
+        <source>Database caching error, please try again.</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+</TS>
diff --git a/src/plugins/stardict/pl_PL.ts b/src/plugins/stardict/pl_PL.ts
new file mode 100644 (file)
index 0000000..9800a1c
--- /dev/null
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.0" language="pl_PL">
+<context>
+    <name>XdxfCachingDialog</name>
+    <message>
+        <location filename="XdxfCachingDialog.cpp" line="35"/>
+        <location filename="XdxfCachingDialog.cpp" line="49"/>
+        <source>Caching dictionary, please wait</source>
+        <translation>Optymalizacja słownika, proszę czekać</translation>
+    </message>
+    <message>
+        <location filename="XdxfCachingDialog.cpp" line="41"/>
+        <source>Cancel</source>
+        <translation>Anuluj</translation>
+    </message>
+    <message>
+        <location filename="XdxfCachingDialog.cpp" line="79"/>
+        <source>Estimated time left: </source>
+        <translation>Pozostały czas: </translation>
+    </message>
+    <message numerus="yes">
+        <location filename="XdxfCachingDialog.cpp" line="80"/>
+        <source>%n second(s)</source>
+        <translation>
+            <numerusform>%n sekunda</numerusform>
+            <numerusform>%n sekundy</numerusform>
+            <numerusform>%n sekund</numerusform>
+        </translation>
+    </message>
+</context>
+<context>
+    <name>XdxfDialog</name>
+    <message>
+        <location filename="XdxfDialog.cpp" line="35"/>
+        <source>Optimize for quicker searches (may take some time)</source>
+        <translation>Optymalizuj dla szybszego wyszukiwania (może zająć trochę czasu)</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="36"/>
+        <source>Strip accents (searching takes more time, but spelling doesn&apos;t have to be exact)</source>
+        <translation>Usuń akcenty (wyszukiwanie trwa dłużej, ale szukane słowo nie musi być wpisane dokładnie)</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="74"/>
+        <source>Add new XDXF dictionary</source>
+        <translation>Dodaj nowy słownik XDXF</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="77"/>
+        <source>Browse</source>
+        <translation>Przeglądaj</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="78"/>
+        <source>Dictionary file: not selected</source>
+        <translation>Plik ze słownikiem nie został wybrany</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="86"/>
+        <source>XDXF Settings</source>
+        <translation>Ustawienia XDXF</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="88"/>
+        <source>Plugin: </source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="89"/>
+        <source>From: </source>
+        <translation>Z: </translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="90"/>
+        <source>To: </source>
+        <translation>Na: </translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="91"/>
+        <source>Description: </source>
+        <translation>Opis: </translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="97"/>
+        <source>Strip accents</source>
+        <translation>Usuń akcenty</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="107"/>
+        <source>Optimize</source>
+        <translation>Optymalizuj</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="153"/>
+        <source>Add</source>
+        <translation>Dodaj</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="156"/>
+        <source>Save settings</source>
+        <translation>Zapisz ustawienia</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="210"/>
+        <source>Select dictionary file</source>
+        <translation>Wybierz plik ze słownikiem</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="212"/>
+        <source>XDXF Files (*.xdxf)</source>
+        <translation>Pliki XDXF (*.xdxf)</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="217"/>
+        <source>Dictionary file: %1</source>
+        <translation>Plik ze słownikiem: %1</translation>
+    </message>
+    <message>
+        <location filename="XdxfDialog.cpp" line="246"/>
+        <source>File path is not set</source>
+        <translation>Ścieżka do pliku nie jest ustawiona</translation>
+    </message>
+</context>
+<context>
+    <name>XdxfPlugin</name>
+    <message>
+        <location filename="xdxfplugin.cpp" line="108"/>
+        <location filename="xdxfplugin.cpp" line="206"/>
+        <location filename="xdxfplugin.cpp" line="523"/>
+        <source>Cache database cannot be opened for %1 dictionary. Searching in XDXF file. You may want to recache.</source>
+        <translation>Nie można otworzyć bazy danych dla słownika %1. Szukanie w pliku XDXF. Możesz spróbować ponownie włączyć optymalizację.</translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="157"/>
+        <location filename="xdxfplugin.cpp" line="237"/>
+        <source>XDXF file cannot be read for %1</source>
+        <translation>Nie można odczytać pliku XDXF dla %1</translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="365"/>
+        <source>XDXF file is in wrong format</source>
+        <translation>Niewłaściwy format pliku XDXF</translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="407"/>
+        <source>XDXF dictionary cannot be read from file</source>
+        <translation>Nie można odczytać słownika XDXF z pliku</translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="455"/>
+        <location filename="xdxfplugin.cpp" line="514"/>
+        <source>XDXF file cannot be read for %1 dictionary</source>
+        <translation>Nie mozna odczytać pliku XDXF dla słownika %1</translation>
+    </message>
+    <message>
+        <location filename="xdxfplugin.cpp" line="605"/>
+        <source>Database caching error, please try again.</source>
+        <translation>Błąd optymalizacji, proszę spróbować ponownie.</translation>
+    </message>
+</context>
+</TS>
diff --git a/src/plugins/stardict/stardict.pro b/src/plugins/stardict/stardict.pro
new file mode 100644 (file)
index 0000000..e12c77b
--- /dev/null
@@ -0,0 +1,45 @@
+TARGET = stardict
+
+include(../plugin.pri)
+
+QT = core \
+    gui \
+    xml \
+    sql
+
+maemo5:QT += maemo5
+
+SOURCES +=  \
+    StarDictPlugin.cpp \
+    TranslationStarDict.cpp \
+    StarDictDialog.cpp \
+    StarDialog.cpp
+
+
+HEADERS += \
+    StarDictPlugin.h \
+    TranslationStarDict.h \
+    ../../include/DictDialog.h \
+    StarDictDialog.h \
+    ../../include/translation.h \
+    ../../include/settings.h \
+    ../../include/CommonDictInterface.h \
+    StarDialog.h
+
+RESOURCES += \
+    StarDict.qrc
+
+TRANSLATIONS += pl_PL.ts \
+                en_US.ts
+    
+unix {
+  INSTALLS += plugin-icon
+
+
+
+  plugin-icon.path = $$DATA_DIR
+  plugin-icon.files += xdxf.png
+}
+
+check.commands = echo 'No check here'
+QMAKE_EXTRA_TARGETS += check
diff --git a/src/plugins/stardict/translations/en_US.qm b/src/plugins/stardict/translations/en_US.qm
new file mode 100644 (file)
index 0000000..900f716
Binary files /dev/null and b/src/plugins/stardict/translations/en_US.qm differ
diff --git a/src/plugins/stardict/translations/pl_PL.qm b/src/plugins/stardict/translations/pl_PL.qm
new file mode 100644 (file)
index 0000000..07a9e30
Binary files /dev/null and b/src/plugins/stardict/translations/pl_PL.qm differ
diff --git a/src/plugins/stardict/xdxf.png b/src/plugins/stardict/xdxf.png
new file mode 100644 (file)
index 0000000..3d87cf4
Binary files /dev/null and b/src/plugins/stardict/xdxf.png differ
index e693c92..54f8273 100644 (file)
@@ -46,12 +46,16 @@ void HttpDownloader::download(QUrl url, QString file) {
     // Following line is crucial becouse sourceforge wont redirect correctly
     //    if no user-agent is supplied
     request.setRawHeader("User-Agent", "Wget/1.12 (linux-gnu)");
-    manager->get(request);
+    currentReply = manager->get(request);
+    connect(currentReply, SIGNAL(downloadProgress(qint64,qint64)),
+               this, SIGNAL(progress(qint64,qint64)));
 
 }
 
 void HttpDownloader::downloadFinished(QNetworkReply *reply) {
 
+    disconnect(reply, SIGNAL(downloadProgress(qint64,qint64)),
+               this, SIGNAL(progress(qint64,qint64)));
     if(reply->error() != QNetworkReply::NoError) {
         Q_EMIT error(reply->errorString());
         return;
@@ -65,7 +69,9 @@ void HttpDownloader::downloadFinished(QNetworkReply *reply) {
        QNetworkRequest req;
        req.setRawHeader("User-Agent", "Wget/1.12 (linux-gnu)");
        req.setUrl(r);
-       manager->get(req);
+       currentReply = manager->get(req);
+       connect(currentReply, SIGNAL(downloadProgress(qint64,qint64)),
+                  this, SIGNAL(progress(qint64,qint64)));
     }
     else {
         QFile resultFile(destFile);
index ec6ac27..76f27d1 100644 (file)
@@ -49,11 +49,13 @@ private Q_SLOTS:
 Q_SIGNALS:
     void finished();
     void error(QString);
+    void progress(qint64,qint64);
 
 private:
     QHttp *http;
     QNetworkAccessManager *manager;
     QString destFile;
+    QNetworkReply* currentReply;
 
 
 };
index cdabb31..b92206f 100644 (file)
@@ -244,7 +244,6 @@ void XdxfDialog::selectFile() {
 }
 
 void XdxfDialog::downloadFile() {
-   qDebug()<<"a";
    XdxfPlugin::dictDownloader.download(this);
 }
 
index 2e95783..9d730bf 100644 (file)
@@ -57,6 +57,10 @@ XdxfDictDownloadProgressDialog::XdxfDictDownloadProgressDialog(QWidget*parent):
     #endif
 }
 
+void XdxfDictDownloadProgressDialog::show() {
+    downloadProgressBar->setMaximum(0);
+    QDialog::show();
+}
 
 void XdxfDictDownloadProgressDialog::setText(QString text) {
     setWindowTitle(text);
@@ -65,6 +69,13 @@ void XdxfDictDownloadProgressDialog::setText(QString text) {
     #endif
 }
 
+void XdxfDictDownloadProgressDialog::updateProgress(float progress) {
+    if(downloadProgressBar->maximum() == 0) {
+        downloadProgressBar->setMaximum(100);
+    }
+    downloadProgressBar->setValue(progress*100);
+}
+
 void XdxfDictDownloadProgressDialog::reject() {
     #ifndef Q_WS_MAEMO_5
         Q_EMIT cancelDownloading();
index bce23c0..9238901 100644 (file)
@@ -46,10 +46,15 @@ public Q_SLOTS:
     //! Set text which will be displayed to user as info about current download
     void setText(QString);
 
+    void updateProgress(float progress);
+
+    void show();
+
 Q_SIGNALS:
     //! signal emitted when user cancels downloading of a dictionary
     void cancelDownloading();
 
+
 private:
     QLabel* downloadLabel;
     QProgressBar* downloadProgressBar;
index 4cdb4eb..6ae05a6 100644 (file)
@@ -52,6 +52,9 @@ XdxfDictDownloader::XdxfDictDownloader(QObject *parent) :
     connect(&http, SIGNAL(finished()), this, SLOT(processFinished()));
     connect(&http, SIGNAL(error(QString)),
             this, SLOT(downloadingError(QString)));
+    connect(&http, SIGNAL(progress(qint64,qint64)),
+            this, SLOT(updateDownloadProgress(qint64,qint64)));
+
 }
 
 void XdxfDictDownloader::download(QWidget *parent) {
@@ -64,6 +67,9 @@ void XdxfDictDownloader::download(QWidget *parent) {
 
     connect(progressDialog, SIGNAL(cancelDownloading()),
             this, SLOT(breakDownloading()));
+    connect(this, SIGNAL(downloadProgress(float)),
+            progressDialog, SLOT(updateProgress(float)));
+
     progressDialog->setText(tr("Downloading dictionaries list"));
     progressDialog->show();
 }
@@ -72,6 +78,10 @@ QString XdxfDictDownloader::downloadedFile() {
     return _downloadedFile;
 }
 
+void XdxfDictDownloader::updateDownloadProgress(qint64 downloaded,
+                                                qint64 total)   {
+    Q_EMIT downloadProgress(float(downloaded) / float(total));
+}
 
 void XdxfDictDownloader::downloadingError(QString error) {
     breakDownloading();
index 2f7dd98..6d14407 100644 (file)
@@ -64,6 +64,8 @@ Q_SIGNALS:
     //! emitted to inform user about errors and warnings
     void notify(Notify::NotifyType, QString);
 
+    void downloadProgress(float);
+
 private Q_SLOTS:
     //! obtained list of dictionaries from website
     void dictListReceived(QNetworkReply*);
@@ -76,6 +78,8 @@ private Q_SLOTS:
 
     void downloadingError(QString);
 
+    void updateDownloadProgress(qint64, qint64);
+
 private:
     //! dict is downloaded and unpacked
     void downloadComplete();