Skelleton of StarDict
authorBartosz Szatkowski <bulislaw@linux.com>
Tue, 5 Oct 2010 09:45:06 +0000 (11:45 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Tue, 5 Oct 2010 09:45:06 +0000 (11:45 +0200)
18 files changed:
src/plugins/stardict/StarDialog.cpp [new file with mode: 0644]
src/plugins/stardict/StarDialog.h [new file with mode: 0644]
src/plugins/stardict/StarDict.cpp [new file with mode: 0644]
src/plugins/stardict/StarDict.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/StarDictLoadDialog.h [new file with mode: 0644]
src/plugins/stardict/StarDictSettingsDialog.cpp [new file with mode: 0644]
src/plugins/stardict/StardictLoadDialog.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]

diff --git a/src/plugins/stardict/StarDialog.cpp b/src/plugins/stardict/StarDialog.cpp
new file mode 100644 (file)
index 0000000..e4ca1bf
--- /dev/null
@@ -0,0 +1,268 @@
+/*******************************************************************************
+
+    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 "XdxfDialog.h"
+#include <QDebug>
+
+XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
+                       XdxfDialogType 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 XdxfDialog::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 XdxfDialog::setAccents(bool accents) {
+    _accents = accents;
+}
+
+void XdxfDialog::setGenerateCache(bool generate) {
+    _generateCache = generate;
+
+    if(generate) {
+        _lastAccents = _accents;
+        accentsCheckBox->setChecked(true);
+    }
+    else
+        accentsCheckBox->setChecked(_lastAccents);
+
+    accentsCheckBox->setEnabled(!generate);
+}
+
+void XdxfDialog::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 XdxfDialog::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 XdxfDialog::accept() {
+    if(type == New && _dictionaryFilePath.isEmpty()) {
+        Q_EMIT notify(Notify::Warning, tr("File path is not set"));
+
+        return;
+    }
+
+    saveSettings();
+    QDialog::accept();
+}
+
+Settings* XdxfDialog::getSettings() {
+    return _settings;
+}
+
+#ifdef Q_WS_MAEMO_5
+    void XdxfDialog::showCacheInfo() {
+        Q_EMIT notify(Notify::Warning, cacheToolTip);
+    }
+
+    void XdxfDialog::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..ec50274
--- /dev/null
@@ -0,0 +1,149 @@
+/*******************************************************************************
+
+    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 XDXFDIALOG_H
+#define XDXFDIALOG_H
+
+#include <QDialog>
+#include "../../include/settings.h"
+#include <QtGui>
+#include "xdxfplugin.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 XdxfDialog : 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 XdxfDialogType {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 XdxfDialog(XdxfPlugin* plugin = 0,
+                        XdxfDialogType 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 setGenerateCache(bool);
+    void setAccents(bool);
+
+    #ifdef Q_WS_MAEMO_5
+        //! on maemo shows information about checkboxes
+        void showCacheInfo();
+        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;
+
+    XdxfPlugin* plugin;
+    XdxfDialogType type;
+};
+
+#endif // XDXFDIALOG_H
diff --git a/src/plugins/stardict/StarDict.cpp b/src/plugins/stardict/StarDict.cpp
new file mode 100644 (file)
index 0000000..ee8ee03
--- /dev/null
@@ -0,0 +1,633 @@
+/*******************************************************************************
+
+    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.cpp
+\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
+*/
+
+#include "xdxfplugin.h"
+#include <QDebug>
+#include "../../include/Notify.h"
+
+XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
+                    _langFrom(""), _langTo(""),_name(""), _infoNote("") {
+    _settings = new Settings();
+    _dictDialog = new XdxfDictDialog(this, this);
+
+    connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
+
+
+    _settings->setValue("type","xdxf");
+    _icon = QIcon("/usr/share/mdictionary/xdxf.png");
+    _wordsCount = -1;
+    stopped = false;
+
+    initAccents();
+}
+
+void XdxfPlugin::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);
+}
+
+
+XdxfPlugin::~XdxfPlugin() {
+    delete _settings;
+    delete _dictDialog;
+}
+
+
+QString XdxfPlugin::langFrom() const {   
+    return _langFrom;
+}
+
+
+QString XdxfPlugin::langTo() const {
+    return  _langTo;
+}
+
+
+QString XdxfPlugin::name() const {
+    return  _name;
+}
+
+
+QString XdxfPlugin::type() const {
+    return QString("xdxf");
+}
+
+
+QString XdxfPlugin::infoNote() const {
+    return _infoNote;
+}
+
+
+QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
+    if( word.indexOf("*")==-1 && word.indexOf("?")==-1 &&
+        word.indexOf("_")==-1 && word.indexOf("%")==-1)
+        word+="*";
+
+    if(isCached())
+        return searchWordListCache(word,limit);
+    return searchWordListFile(word, limit);
+}
+
+
+QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
+    QSet<Translation*> translations;
+    QString cacheFilePath = _settings->value("cache_path");
+
+    db.setDatabaseName(cacheFilePath);
+    if(!QFile::exists(cacheFilePath) || !db.open()) {
+        qDebug() << "Database error" << db.lastError().text() << endl;
+        Q_EMIT notify(Notify::Warning, QString(tr("Cache database cannot be "
+                "opened for %1 dictionary. Searching in XDXF file. "
+                "You may want to recache.").arg(name())));
+        _settings->setValue("cached","false");
+        return searchWordListFile(word, limit);
+    }
+    stopped = false;
+    word = word.toLower();
+    word = word.replace("*", "%");
+    word = word.replace("?", "_");
+
+    QSqlQuery cur(db);
+    if(limit !=0)
+        cur.prepare("select word from dict where word like ? or normalized "
+                    "like ? limit ?");
+    else
+        cur.prepare("select word from dict where word like ? or normalized "
+                    "like ?");
+    cur.addBindValue(word);
+    cur.addBindValue(word);
+    if(limit !=0)
+        cur.addBindValue(limit);
+    cur.exec();
+
+    while(cur.next() && (translations.size()<limit || limit==0)) {
+       translations.insert(new TranslationXdxf(
+            cur.value(0).toString(),
+            _dictionaryInfo, this));
+    }
+    db.close();
+    return translations.toList();
+}
+
+
+QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
+    QSet<Translation*> translations;
+    QFile dictionaryFile(_settings->value("path"));
+    word = word.toLower();
+    stopped = false;
+
+    QRegExp regWord(word);
+    regWord.setCaseSensitivity(Qt::CaseInsensitive);
+    regWord.setPatternSyntax(QRegExp::Wildcard);
+
+    /*check xdxf file exist*/
+    if(!QFile::exists(_settings->value("path"))
+                || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        qDebug()<<"Error: could not open file";
+        Q_EMIT notify(Notify::Warning,
+                QString(tr("XDXF file cannot be read for %1").arg(name())));
+        return translations.toList();
+    }
+
+    QXmlStreamReader reader(&dictionaryFile);
+    QString readKey;
+    int i=0;
+
+    /*search words list*/
+    while(!reader.atEnd() && !stopped){
+        reader.readNextStartElement();
+        if(reader.name()=="ar") {
+            while(reader.name()!="k" && !reader.atEnd())
+                reader.readNextStartElement();
+            if(!reader.atEnd())
+                readKey = reader.readElementText();
+            if((regWord.exactMatch(readKey)
+                    || regWord.exactMatch(removeAccents(readKey)))
+                    && (i<limit || limit==0) && !reader.atEnd())  {
+ //               qDebug()<<readKey;
+                translations<<(new TranslationXdxf(readKey.toLower(),
+                               _dictionaryInfo,this));
+                if(translations.size()==limit && limit!=0)
+                    break;
+            }
+        }
+        this->thread()->yieldCurrentThread();
+    }
+    stopped=false;
+    dictionaryFile.close();
+    return translations.toList();
+}
+
+
+QString XdxfPlugin::search(QString key) {
+    if(isCached())
+        return searchCache(key);
+    return searchFile(key);
+}
+
+
+QString XdxfPlugin::searchCache(QString key) {
+    QString result("");
+    QString cacheFilePath = _settings->value("cache_path");
+    db.setDatabaseName(cacheFilePath);
+    key = key.toLower();
+
+    if(!QFile::exists(cacheFilePath) || !db.open()) {
+        qDebug() << "Database error" << db.lastError().text() << endl;
+        Q_EMIT notify(Notify::Warning, QString(tr("Cache database cannot be "
+                "opened for %1 dictionary. Searching in XDXF file. "
+                "You may want to recache.").arg(name())));
+        _settings->setValue("cached","false");
+        return searchFile(key);
+    }
+
+    QSqlQuery cur(db);
+
+    cur.prepare("select translation from dict where word like ?");
+    cur.addBindValue(key);
+    cur.exec();
+    while(cur.next())
+        result += cur.value(0).toString();
+
+    db.close();
+
+    return result;
+
+}
+
+
+QString XdxfPlugin::searchFile(QString key) {
+    QFile dictionaryFile(_settings->value("path"));
+    QString resultString("");
+    key = key.toLower();
+
+    /*check xdxf file exist*/
+    if(!QFile::exists(_settings->value("path"))
+                || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        Q_EMIT notify(Notify::Warning,
+                QString(tr("XDXF file cannot be read for %1").arg(name())));
+        qDebug()<<"Error: could not open file";
+        return "";
+    }
+
+    QXmlStreamReader reader(&dictionaryFile);
+    QString readKey;
+    bool match =false;
+    stopped = false;
+
+    /*search translations for word*/
+    while (!reader.atEnd()&& !stopped) {
+        reader.readNext();
+        if(reader.tokenType() == QXmlStreamReader::StartElement) {
+            if(reader.name()=="k") {
+                readKey = reader.readElementText();
+                if(readKey.toLower()==key.toLower())
+                    match = true;
+            }
+        }
+        if(match) {
+            QString temp("");
+            while(reader.name()!="ar" && !reader.atEnd()) {
+                if(reader.name()!="" && reader.name()!="k") {
+                    if(reader.tokenType()==QXmlStreamReader::EndElement)
+                        temp+="</";
+                    if(reader.tokenType()==QXmlStreamReader::StartElement)
+                        temp+="<";
+                    temp+=reader.name().toString();
+                    if(reader.name().toString()=="c" &&
+                            reader.tokenType()==QXmlStreamReader::StartElement)
+                       temp= temp + " c=\"" + reader.attributes().
+                               value("c").toString() + "\"";
+                    temp+=">";
+                }
+                temp+= reader.text().toString().replace("<","&lt;").
+                        replace(">","&gt;");
+                reader.readNext();
+            }
+            if(temp.at(0)==QChar('\n'))
+                temp.remove(0,1);
+            resultString+="<key>" + readKey +"</key>";
+            resultString+="<t>" + temp + "</t>";
+            match=false;
+        }
+        this->thread()->yieldCurrentThread();
+    }
+    stopped=false;
+    dictionaryFile.close();
+    return resultString;
+}
+
+
+void XdxfPlugin::stop() {
+   //qDebug()<<"stop";
+    stopped=true;
+}
+
+
+DictDialog* XdxfPlugin::dictDialog() {
+     return _dictDialog;
+}
+
+
+CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
+    XdxfPlugin *plugin = new XdxfPlugin();
+
+    connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SIGNAL(notify(Notify::NotifyType,QString)));
+
+    ((XdxfDictDialog*)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 XdxfPlugin::isAvailable() const {
+    return true;
+}
+
+
+Settings* XdxfPlugin::settings() {
+    return _settings;
+}
+
+
+bool XdxfPlugin::isCached() {
+    if(_settings->value("cached") == "true")
+        return true;
+    return false;
+}
+
+
+bool XdxfPlugin::setSettings(const Settings *settings) {
+    if(settings) {
+        bool isPathChange=false;
+        QString oldPath = _settings->value("path");
+        Settings *oldSettings =  new Settings ;
+
+        if(oldPath != settings->value("path")) {
+            if(oldPath!="" && _settings->value("cache_path")!="")
+                clean();
+            isPathChange=true;
+        }
+
+        foreach(QString key, _settings->keys())
+            oldSettings->setValue(key, _settings->value(key));
+
+        foreach(QString key, settings->keys()) {
+           if(key != "generateCache")
+               _settings->setValue(key, settings->value(key));
+        }
+
+        if(!getDictionaryInfo()) {
+            Q_EMIT notify(Notify::Warning,
+                QString(tr("XDXF file is in wrong format")));
+            qDebug()<<"Error: xdxf file is in wrong format";
+            delete _settings;
+            _settings=oldSettings;
+            return false;
+        }
+
+        if(isPathChange) {
+            _wordsCount=0;
+            if(oldPath!="")
+                _settings->setValue("cached","false");
+            if(_settings->value("cached")=="true"
+                    && _settings->value("cache_path")!="") {
+                db_name = _settings->value("type")
+                        + _settings->value("cache_path");
+                db = QSqlDatabase::addDatabase("QSQLITE",db_name);
+            }
+        }
+
+        if((_settings->value("cached") == "false" ||
+            _settings->value("cached").isEmpty()) &&
+            settings->value("generateCache") == "true") {
+            clean();
+            makeCache("");
+        }
+
+        else if (settings->value("generateCache") == "false") {
+            _settings->setValue("cached", "false");
+        }
+    }
+    else
+        return false;
+    Q_EMIT settingsChanged();
+    return true;
+}
+
+
+bool XdxfPlugin::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("XDXF dictionary cannot be read from file")));
+        qDebug()<<"Error: could not open file";
+        return false;
+    }
+
+    bool okFormat=false;
+    QXmlStreamReader reader(&dictionaryFile);
+    reader.readNextStartElement();
+    if(reader.name()=="xdxf") {
+        okFormat=true;
+        if(reader.attributes().hasAttribute("lang_from"))
+            _langFrom = reader.attributes().value("lang_from").toString();
+        if(reader.attributes().hasAttribute("lang_to"))
+            _langTo = reader.attributes().value("lang_to").toString();
+    }
+    reader.readNextStartElement();
+    if(reader.name()=="full_name")
+        _name=reader.readElementText();
+    else
+        qDebug()<<"no full_name";
+    reader.readNextStartElement();
+    if(reader.name()=="description")
+        _infoNote=reader.readElementText();
+    else
+        qDebug()<<"no description";
+
+    _dictionaryInfo= _name + " [" + _langFrom + "-"
+                + _langTo + "]";
+
+    dictionaryFile.close();
+    if(okFormat)
+        return true;
+    return false;
+}
+
+
+QIcon* XdxfPlugin::icon() {
+    return &_icon;
+}
+
+
+int XdxfPlugin::countWords() {
+    if(_wordsCount>0)
+        return _wordsCount;
+    QFile dictionaryFile(_settings->value("path"));
+    if(!QFile::exists(_settings->value("path"))
+                || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        Q_EMIT notify(Notify::Warning,
+                QString(tr("XDXF file cannot be read for %1 dictionary")
+                .arg(name())));
+        qDebug()<<"Error: could not open file";
+        return -1;
+    }
+
+    dictionaryFile.seek(0);
+
+    long wordsCount = 0;
+
+    QString line;
+    while(!dictionaryFile.atEnd()) {
+        line = dictionaryFile.readLine();
+        if(line.contains("<k>")) {
+            wordsCount++;
+        }
+    }
+    _wordsCount = wordsCount;
+    dictionaryFile.close();
+    return wordsCount;
+}
+
+
+bool XdxfPlugin::makeCache(QString) {
+
+    XdxfCachingDialog d(_dictDialog->lastDialogParent());
+
+//    qDebug()<<_dictDialog->lastDialogParent();
+
+    connect(&d, SIGNAL(cancelCaching()),
+            this, SLOT(stop()));
+    connect(this, SIGNAL(updateCachingProgress(int,int)),
+            &d, SLOT(updateCachingProgress(int,int)));
+
+    d.show();
+
+    QCoreApplication::processEvents();
+    QFileInfo dictFileN(_settings->value("path"));
+    QString cachePathN;
+    stopped = false;
+
+    /*create cache file name*/
+    int i=0;
+    do {
+        cachePathN = QDir::homePath() + "/.mdictionary/"
+                                      + dictFileN.completeBaseName()+"."
+                                      +QString::number(i) + ".cache";
+        i++;
+    } while(QFile::exists(cachePathN));
+
+    db_name = _settings->value("type") + cachePathN;
+    db = QSqlDatabase::addDatabase("QSQLITE",db_name);
+
+    /*checke errors (File open and db open)*/
+    QFile dictionaryFile(dictFileN.filePath());
+    if (!QFile::exists(_settings->value("path"))
+                || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        Q_EMIT updateCachingProgress(100, 0);
+        Q_EMIT notify(Notify::Warning,
+                QString(tr("XDXF file cannot be read for %1 dictionary")
+                .arg(name())));
+        return 0;
+    }
+    QXmlStreamReader reader(&dictionaryFile);
+    db.setDatabaseName(cachePathN);
+    if(!db.open()) {
+        qDebug() << "Database error" << db.lastError().text() << endl;
+        Q_EMIT updateCachingProgress(100, 0);
+        Q_EMIT notify(Notify::Warning, QString(tr("Cache database cannot be "
+                "opened for %1 dictionary. Searching in XDXF file. "
+                "You may want to recache.").arg(name())));
+        return false;
+    }
+
+    /*inicial sqlQuery*/
+    QCoreApplication::processEvents();
+    QSqlQuery cur(db);
+    cur.exec("PRAGMA synchronous = 0");
+    cur.exec("drop table dict");
+    QCoreApplication::processEvents();
+    cur.exec("create table dict(word text, normalized text ,translation text)");
+    int counter = 0;
+    cur.exec("BEGIN;");
+
+    QString readKey;
+    bool match = false;
+    QTime timer;
+    timer.start();
+    countWords();
+    int lastProg = -1;
+    _settings->setValue("strip_accents", "true");
+    counter=0;
+
+    /*add all words to db*/
+    while (!reader.atEnd() && !stopped) {
+
+        QCoreApplication::processEvents();
+        reader.readNext();
+        if(reader.tokenType() == QXmlStreamReader::StartElement) {
+            if(reader.name()=="k"){
+                readKey = reader.readElementText();
+                match = true;
+            }
+        }
+        if(match) {
+            QString temp("");
+            while(reader.name()!="ar" && !reader.atEnd()) {
+                if(reader.name()!="" && reader.name()!="k") {
+                    if(reader.tokenType()==QXmlStreamReader::EndElement)
+                        temp+="</";
+                    if(reader.tokenType()==QXmlStreamReader::StartElement)
+                        temp+="<";
+                    temp+=reader.name().toString();
+                    if(reader.name().toString()=="c"
+                        && reader.tokenType()==QXmlStreamReader::StartElement) {
+                        temp= temp + " c=\""
+                                   + reader.attributes().value("c").toString()
+                                   + "\"";
+                    }
+                    temp+=">";
+                }
+                temp+= reader.text().toString().replace("<","&lt;").replace(">"
+                              ,"&gt;");
+                reader.readNext();
+            }
+            if(temp.at(0)==QChar('\n'))
+                temp.remove(0,1);
+            temp="<key>" + readKey + "</key>" + "<t>" + temp+ "</t>";
+            match=false;
+            cur.prepare("insert into dict values(?,?,?)");
+            cur.addBindValue(readKey.toLower());
+            cur.addBindValue(removeAccents(readKey).toLower());
+            cur.addBindValue(temp);
+            cur.exec();
+            counter++;
+            int prog = counter*100/_wordsCount;
+            if(prog % 2 == 0 && lastProg != prog) {
+                Q_EMIT updateCachingProgress(prog,timer.restart());
+                lastProg = prog;
+            }
+        }
+    }
+    cur.exec("END;");
+    cur.exec("select count(*) from dict");
+
+    /*checke errors (wrong number of added words)*/
+    countWords();
+    if(!cur.next() || countWords() != cur.value(0).toInt()) {
+        Q_EMIT updateCachingProgress(100, timer.restart());
+        Q_EMIT notify(Notify::Warning,
+                QString(tr("Database caching error, please try again.")));
+        db.close();
+        _settings->setValue("cache_path", cachePathN);
+        if(stopped)
+            clean();
+        _settings->setValue("cache_path","");
+        return false;
+    }
+
+    _settings->setValue("cache_path", cachePathN);
+    _settings->setValue("cached", "true");
+
+    disconnect(&d, SIGNAL(cancelCaching()),
+            this, SLOT(stop()));
+    disconnect(this, SIGNAL(updateCachingProgress(int,int)),
+            &d, SLOT(updateCachingProgress(int,int)));
+    db.close();
+    return true;
+}
+
+void XdxfPlugin::clean() {
+    if(QFile::exists(_settings->value("cache_path"))) {
+        QFile(_settings->value("cache_path")).remove();
+        QSqlDatabase::removeDatabase(db_name);
+    }
+}
+
+
+Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
diff --git a/src/plugins/stardict/StarDict.h b/src/plugins/stardict/StarDict.h
new file mode 100644 (file)
index 0000000..334a506
--- /dev/null
@@ -0,0 +1,194 @@
+/*******************************************************************************
+
+    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 XDXFPLUGIN_H
+#define XDXFPLUGIN_H
+
+
+#include <QObject>
+#include <QDialog>
+#include <QRegExp>
+#include <QTime>
+#include <QSqlQuery>
+#include <QSqlDatabase>
+#include <QSqlError>
+#include <QFile>
+#include <QXmlStreamReader>
+#include <QtPlugin>
+#include <QHash>
+
+#include "../../include/CommonDictInterface.h"
+#include "../../include/settings.h"
+#include "XdxfDictDialog.h"
+#include "XdxfCachingDialog.h"
+#include "TranslationXdxf.h"
+
+class TranslationXdxf;
+
+class XdxfPlugin : public CommonDictInterface
+{
+    Q_OBJECT
+    Q_INTERFACES(CommonDictInterface)
+public:
+    XdxfPlugin(QObject *parent=0);
+
+    ~XdxfPlugin();
+
+    //! \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();
+
+Q_SIGNALS:
+    //! emitted with percent count of caching progress, and time elapsed from
+    //! last signal emit
+    void updateCachingProgress(int, int);
+
+
+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);
+
+    /*! searches for a translation of a word which is exactly like a key
+        in a database file */
+    QString searchCache(QString key);
+
+    //! scans dictionary file to get information about it
+    bool getDictionaryInfo();
+
+    //! counts the keys in a xdxf file
+    int countWords();
+
+    /*! transforms xdxf files to database files (caching operation)
+        \returns true on success, false on failure */
+    bool makeCache(QString dir);
+
+    //! 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;
+    QSqlDatabase db;
+    QString db_name;
+    //! number of words in a dictionary
+    long _wordsCount;
+    //! indicates if search is stopped
+    volatile bool stopped;
+    Settings *_settings;
+    XdxfDictDialog* _dictDialog;
+    XdxfCachingDialog* cachingDialog;
+};
+
+#endif // XDXFPLUGIN_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..62e1f3d
--- /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 "XdxfDictDialog.h"
+#include "xdxfplugin.h"
+#include "XdxfDialog.h"
+#include <QDebug>
+
+XdxfDictDialog::XdxfDictDialog(XdxfPlugin *plugin, QObject *parent) :
+    DictDialog(parent) {
+    this->plugin = plugin;
+    _lastDialogParent=0;
+}
+
+QWidget* XdxfDictDialog::lastDialogParent() {
+    return _lastDialogParent;
+}
+
+void XdxfDictDialog::setLastDialogParent(QWidget *w) {
+    _lastDialogParent = w;
+}
+
+Settings* XdxfDictDialog::addNewDictionary(QWidget *parent) {
+    XdxfDialog d(0, XdxfDialog::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 XdxfDictDialog::changeSettings(QWidget * parent) {
+    XdxfDialog d(plugin, XdxfDialog::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..50b8ac3
--- /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 XDXFDICTDIALOG_H
+#define XDXFDICTDIALOG_H
+
+#include "../../include/DictDialog.h"
+
+class XdxfPlugin;
+
+
+//! Implementation of DictDialog interface for xdxf plugin
+class XdxfDictDialog : public DictDialog {
+    Q_OBJECT
+public:
+    explicit XdxfDictDialog(XdxfPlugin* 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:
+    XdxfPlugin* plugin;
+    QWidget* _lastDialogParent;
+};
+
+#endif // XDXFDICTDIALOG_H
diff --git a/src/plugins/stardict/StarDictLoadDialog.h b/src/plugins/stardict/StarDictLoadDialog.h
new file mode 100644 (file)
index 0000000..a5161bf
--- /dev/null
@@ -0,0 +1,75 @@
+/*******************************************************************************
+
+    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 XdxfLoadDialog.h
+*/
+//Created by Mateusz Półrola
+
+#ifndef XDXFLOADDIALOG_H
+#define XDXFLOADDIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+#include "../../include/settings.h"
+
+//! Displays dialog which allows user to add new xdxf dictionary
+class XdxfLoadDialog : public QDialog {
+    Q_OBJECT
+public:
+    explicit XdxfLoadDialog(QWidget *parent = 0);
+
+    /*! Displays dialog and returns settings of new dictionary
+        \return Settings object containing new dictionary settings or 0 (NULL) in
+        case user cancels dialog
+    */
+    static Settings* getSettings(QWidget *parent);
+
+    //! Returns dictionary file path chosen by user
+    QString dicitonaryFilePath();
+
+    //! Returns if user wants to cache dictionary
+    bool generateCache();
+
+signals:
+
+public slots:
+
+private Q_SLOTS:
+    void selectFile();
+    void addDictionary();
+    void setGenerateCache(bool);
+    void setAccents(bool);
+
+private:
+    QPushButton* addButton;
+    QPushButton* browseButton;
+    QLabel* browseLabel;
+    QCheckBox* cacheCheckBox;
+    QCheckBox* accentsCheckBox;
+    QVBoxLayout* verticalLayout;
+    QVBoxLayout* browseLayout;
+    QHBoxLayout* cacheLayout;
+    QString _dicitonaryFilePath;
+    bool _generateCache;
+    bool lastAccents;
+
+};
+
+#endif // XDXFLOADDIALOG_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/StardictLoadDialog.cpp b/src/plugins/stardict/StardictLoadDialog.cpp
new file mode 100644 (file)
index 0000000..83f29c3
--- /dev/null
@@ -0,0 +1,153 @@
+/*******************************************************************************
+
+    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 XdxfLoadDialog.cpp
+*/
+//Created by Mateusz Półrola
+
+#include "XdxfLoadDialog.h"
+
+XdxfLoadDialog::XdxfLoadDialog(QWidget *parent) :
+    QDialog(parent) {
+    verticalLayout = new QVBoxLayout;
+    setLayout(verticalLayout);
+
+    setWindowTitle(tr("Add new XDXF dictionary"));
+
+    browseLayout = new QVBoxLayout;
+
+    browseButton =  new QPushButton(tr("Browse"));
+    browseLabel = new QLabel(tr("Dictionary file: not selected"));
+    //browseLabel->setWordWrap(true);
+    browseLabel->setMargin(5);
+
+    browseLayout->addWidget(browseLabel, 0, Qt::AlignLeft);
+    browseLayout->addWidget(browseButton);
+
+    verticalLayout->addLayout(browseLayout);
+
+    cacheLayout = new QHBoxLayout;
+    verticalLayout->addLayout(cacheLayout);
+    accentsCheckBox = new QCheckBox(tr("Strip accents \n(searching takes more "
+                 "time, but spelling don't have to be exact)"));
+    verticalLayout->addWidget(accentsCheckBox);
+
+    cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"),this);
+    cacheCheckBox->setChecked(true);
+    cacheLayout->addWidget(cacheCheckBox);
+
+    addButton = new QPushButton(tr("Add"));
+
+    verticalLayout->addWidget(addButton);
+
+    setModal(true);
+
+    connect(browseButton, SIGNAL(clicked()),
+            this, SLOT(selectFile()));
+
+    connect(addButton, SIGNAL(clicked()),
+            this, SLOT(addDictionary()));
+
+    connect(cacheCheckBox, SIGNAL(toggled(bool)),
+            SLOT(setGenerateCache(bool)));
+
+    connect(accentsCheckBox, SIGNAL(clicked(bool)), SLOT(setAccents(bool)));
+    lastAccents = accentsCheckBox->isChecked();
+    _dicitonaryFilePath = QString();
+}
+
+
+
+void XdxfLoadDialog::setAccents(bool state) {
+    lastAccents = state;
+}
+
+
+
+void XdxfLoadDialog::selectFile() {
+    QString fileName = QFileDialog::getOpenFileName(this,
+                                     tr("Select dictionary file"),
+                                     "",
+                                     tr("XDXF Files (*.xdxf)"),
+                                     0,
+                                     0);
+
+    if (!fileName.isEmpty()) {
+        browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
+        _dicitonaryFilePath = fileName;
+    }repaint(rect());
+    resize(size());
+}
+
+void XdxfLoadDialog::addDictionary() {
+    _generateCache = cacheCheckBox->isChecked();
+    if(!_dicitonaryFilePath.isEmpty()) {
+        accept();
+    }
+    else {
+        reject();
+    }
+}
+
+QString XdxfLoadDialog::dicitonaryFilePath() {
+    return _dicitonaryFilePath;
+}
+
+bool XdxfLoadDialog::generateCache() {
+    return _generateCache;
+}
+
+void XdxfLoadDialog::setGenerateCache(bool generate) {
+    _generateCache = generate;
+
+    if(generate)
+        accentsCheckBox->setChecked(true);
+    else
+        accentsCheckBox->setChecked(lastAccents);
+
+    accentsCheckBox->setEnabled(!generate);
+}
+
+Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
+    XdxfLoadDialog loadDialog(parent);
+    Settings* settings = new Settings;
+
+    if(loadDialog.exec()==QDialog::Accepted) {
+        settings->setValue("path", loadDialog.dicitonaryFilePath());
+        if(loadDialog.generateCache()) {
+            settings->setValue("generateCache", "true");
+        }
+        else {
+            settings->setValue("generateCache", "false");
+        }
+        if(loadDialog.accentsCheckBox->isChecked())
+            settings->setValue("strip_accents", "true");
+        else
+            settings->setValue("strip_accents", "false");
+
+
+        return settings;
+    }
+
+    return 0;
+}
+
+
diff --git a/src/plugins/stardict/TranslationStarDict.cpp b/src/plugins/stardict/TranslationStarDict.cpp
new file mode 100644 (file)
index 0000000..fe228b5
--- /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 "TranslationXdxf.h"
+#include <QDebug>
+
+TranslationXdxf::TranslationXdxf():_key(""),_dictionaryInfo("") {
+    xdxfPlugin=0;
+}
+
+TranslationXdxf::TranslationXdxf(QString _key, QString _dictionaryInfo,
+         XdxfPlugin *xdxfPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
+    this->xdxfPlugin=xdxfPlugin;
+    if(xdxfPlugin)
+        _dictHash = xdxfPlugin->hash();
+    _bookmark=0;
+}
+
+
+QString TranslationXdxf::key() const {
+    return _key;
+}
+
+QString TranslationXdxf::toXml() const { 
+    QString result("");
+    if(!xdxfPlugin)
+        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>" + xdxfPlugin->search(_key) + "</dict>";
+    return result.replace("&","&amp;");
+}
+
+void TranslationXdxf::setKey(QString _key) {
+    this->_key=_key;
+}
+
+void TranslationXdxf::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..e438bbc
--- /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 TRANSLATIONXDXF_H
+#define TRANSLATIONXDXF_H
+
+#include <QString>
+#include "../../include/translation.h"
+#include "xdxfplugin.h"
+
+class TranslationXdxf : public Translation
+{
+public:
+    TranslationXdxf();
+    TranslationXdxf(QString _key,
+                    QString _dictionaryInfo,
+                    XdxfPlugin *xdxfPlugin);
+
+    //! \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;
+    XdxfPlugin *xdxfPlugin;
+    int _dictHash;
+};
+
+#endif // TRANSLATIONXDXF_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..c57a9e9
--- /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 \
+    StarDictDictDialog.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