From d54380147e9155c0c6dfba98d59c15abac060296 Mon Sep 17 00:00:00 2001 From: Bartosz Szatkowski Date: Tue, 5 Oct 2010 11:45:06 +0200 Subject: [PATCH] Skelleton of StarDict --- src/plugins/stardict/StarDialog.cpp | 268 ++++++++++ src/plugins/stardict/StarDialog.h | 149 ++++++ src/plugins/stardict/StarDict.cpp | 633 +++++++++++++++++++++++ src/plugins/stardict/StarDict.h | 194 +++++++ src/plugins/stardict/StarDict.qrc | 6 + src/plugins/stardict/StarDictDialog.cpp | 70 +++ src/plugins/stardict/StarDictDialog.h | 59 +++ src/plugins/stardict/StarDictLoadDialog.h | 75 +++ src/plugins/stardict/StarDictSettingsDialog.cpp | 175 +++++++ src/plugins/stardict/StardictLoadDialog.cpp | 153 ++++++ src/plugins/stardict/TranslationStarDict.cpp | 67 +++ src/plugins/stardict/TranslationStarDict.h | 67 +++ src/plugins/stardict/en_US.ts | 161 ++++++ src/plugins/stardict/pl_PL.ts | 162 ++++++ src/plugins/stardict/stardict.pro | 45 ++ src/plugins/stardict/translations/en_US.qm | Bin 0 -> 134 bytes src/plugins/stardict/translations/pl_PL.qm | Bin 0 -> 3426 bytes src/plugins/stardict/xdxf.png | Bin 0 -> 2047 bytes 18 files changed, 2284 insertions(+) create mode 100644 src/plugins/stardict/StarDialog.cpp create mode 100644 src/plugins/stardict/StarDialog.h create mode 100644 src/plugins/stardict/StarDict.cpp create mode 100644 src/plugins/stardict/StarDict.h create mode 100644 src/plugins/stardict/StarDict.qrc create mode 100644 src/plugins/stardict/StarDictDialog.cpp create mode 100644 src/plugins/stardict/StarDictDialog.h create mode 100644 src/plugins/stardict/StarDictLoadDialog.h create mode 100644 src/plugins/stardict/StarDictSettingsDialog.cpp create mode 100644 src/plugins/stardict/StardictLoadDialog.cpp create mode 100644 src/plugins/stardict/TranslationStarDict.cpp create mode 100644 src/plugins/stardict/TranslationStarDict.h create mode 100644 src/plugins/stardict/en_US.ts create mode 100644 src/plugins/stardict/pl_PL.ts create mode 100644 src/plugins/stardict/stardict.pro create mode 100644 src/plugins/stardict/translations/en_US.qm create mode 100644 src/plugins/stardict/translations/pl_PL.qm create mode 100644 src/plugins/stardict/xdxf.png diff --git a/src/plugins/stardict/StarDialog.cpp b/src/plugins/stardict/StarDialog.cpp new file mode 100644 index 0000000..e4ca1bf --- /dev/null +++ b/src/plugins/stardict/StarDialog.cpp @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//Created by Mateusz Półrola + +#include "XdxfDialog.h" +#include + +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 index 0000000..ec50274 --- /dev/null +++ b/src/plugins/stardict/StarDialog.h @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! + \file XdxfDialog.cpp + \author Mateusz Półrola +*/ + +#ifndef XDXFDIALOG_H +#define XDXFDIALOG_H + +#include +#include "../../include/settings.h" +#include +#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 index 0000000..ee8ee03 --- /dev/null +++ b/src/plugins/stardict/StarDict.cpp @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file xdxfplugin.cpp +\author Jakub Jaszczynski +*/ + +#include "xdxfplugin.h" +#include +#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 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 XdxfPlugin::searchWordListCache(QString word, int limit) { + QSet 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() XdxfPlugin::searchWordListFile(QString word, int limit) { + QSet 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))) + && (ithread()->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+=""; + } + temp+= reader.text().toString().replace("<","<"). + replace(">",">"); + reader.readNext(); + } + if(temp.at(0)==QChar('\n')) + temp.remove(0,1); + resultString+="" + readKey +""; + resultString+="" + temp + ""; + 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("")) { + 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+=""; + } + temp+= reader.text().toString().replace("<","<").replace(">" + ,">"); + reader.readNext(); + } + if(temp.at(0)==QChar('\n')) + temp.remove(0,1); + temp="" + readKey + "" + "" + temp+ ""; + 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 index 0000000..334a506 --- /dev/null +++ b/src/plugins/stardict/StarDict.h @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + + +/*! \file xdxfplugin.h +*/ +#ifndef XDXFPLUGIN_H +#define XDXFPLUGIN_H + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 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 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 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 index 0000000..0642344 --- /dev/null +++ b/src/plugins/stardict/StarDict.qrc @@ -0,0 +1,6 @@ + + + translations/pl_PL.qm + translations/en_US.qm + + diff --git a/src/plugins/stardict/StarDictDialog.cpp b/src/plugins/stardict/StarDictDialog.cpp new file mode 100644 index 0000000..62e1f3d --- /dev/null +++ b/src/plugins/stardict/StarDictDialog.cpp @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file XdxfDictDialog.cpp +*/ +//Created by Mateusz Półrola + +#include "XdxfDictDialog.h" +#include "xdxfplugin.h" +#include "XdxfDialog.h" +#include + +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 index 0000000..50b8ac3 --- /dev/null +++ b/src/plugins/stardict/StarDictDialog.h @@ -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 . + + 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 index 0000000..a5161bf --- /dev/null +++ b/src/plugins/stardict/StarDictLoadDialog.h @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ +/*! \file XdxfLoadDialog.h +*/ +//Created by Mateusz Półrola + +#ifndef XDXFLOADDIALOG_H +#define XDXFLOADDIALOG_H + +#include +#include +#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 index 0000000..f9b4206 --- /dev/null +++ b/src/plugins/stardict/StarDictSettingsDialog.cpp @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file XdxfSettingsDialog.cpp +*/ +//Created by Mateusz Półrola + +#include "XdxfSettingsDialog.h" +#include + +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 index 0000000..83f29c3 --- /dev/null +++ b/src/plugins/stardict/StardictLoadDialog.cpp @@ -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 . + + 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 index 0000000..fe228b5 --- /dev/null +++ b/src/plugins/stardict/TranslationStarDict.cpp @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ +/*! \file TranslationXdxf.cpp + \author Jakub Jaszczynski +*/ + + +#include "TranslationXdxf.h" +#include + +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 + " \n"; + else + result+= " bookmark=\"false\" > \n"; + result+= _dictionaryInfo + "" + xdxfPlugin->search(_key) + ""; + return result.replace("&","&"); +} + +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 index 0000000..e438bbc --- /dev/null +++ b/src/plugins/stardict/TranslationStarDict.h @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ +/*! \file TranslationXdxf.h +*/ +#ifndef TRANSLATIONXDXF_H +#define TRANSLATIONXDXF_H + +#include +#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 index 0000000..64c07a0 --- /dev/null +++ b/src/plugins/stardict/en_US.ts @@ -0,0 +1,161 @@ + + + + + XdxfCachingDialog + + + + Caching dictionary, please wait + + + + + Cancel + + + + + Estimated time left: + + + + + %n second(s) + + %n second + %n seconds + + + + + XdxfDialog + + + Optimize for quicker searches (may take some time) + + + + + Strip accents (searching takes more time, but spelling doesn't have to be exact) + + + + + Add new XDXF dictionary + + + + + Browse + + + + + Dictionary file: not selected + + + + + XDXF Settings + + + + + Plugin: + + + + + From: + + + + + To: + + + + + Description: + + + + + Strip accents + + + + + Optimize + + + + + Add + + + + + Save settings + + + + + Select dictionary file + + + + + XDXF Files (*.xdxf) + + + + + Dictionary file: %1 + + + + + File path is not set + + + + + XdxfPlugin + + + + + Cache database cannot be opened for %1 dictionary. Searching in XDXF file. You may want to recache. + + + + + + XDXF file cannot be read for %1 + + + + + XDXF file is in wrong format + + + + + XDXF dictionary cannot be read from file + + + + + + XDXF file cannot be read for %1 dictionary + + + + + Database caching error, please try again. + + + + diff --git a/src/plugins/stardict/pl_PL.ts b/src/plugins/stardict/pl_PL.ts new file mode 100644 index 0000000..9800a1c --- /dev/null +++ b/src/plugins/stardict/pl_PL.ts @@ -0,0 +1,162 @@ + + + + + XdxfCachingDialog + + + + Caching dictionary, please wait + Optymalizacja słownika, proszę czekać + + + + Cancel + Anuluj + + + + Estimated time left: + Pozostały czas: + + + + %n second(s) + + %n sekunda + %n sekundy + %n sekund + + + + + XdxfDialog + + + Optimize for quicker searches (may take some time) + Optymalizuj dla szybszego wyszukiwania (może zająć trochę czasu) + + + + Strip accents (searching takes more time, but spelling doesn't have to be exact) + Usuń akcenty (wyszukiwanie trwa dłużej, ale szukane słowo nie musi być wpisane dokładnie) + + + + Add new XDXF dictionary + Dodaj nowy słownik XDXF + + + + Browse + Przeglądaj + + + + Dictionary file: not selected + Plik ze słownikiem nie został wybrany + + + + XDXF Settings + Ustawienia XDXF + + + + Plugin: + + + + + From: + Z: + + + + To: + Na: + + + + Description: + Opis: + + + + Strip accents + Usuń akcenty + + + + Optimize + Optymalizuj + + + + Add + Dodaj + + + + Save settings + Zapisz ustawienia + + + + Select dictionary file + Wybierz plik ze słownikiem + + + + XDXF Files (*.xdxf) + Pliki XDXF (*.xdxf) + + + + Dictionary file: %1 + Plik ze słownikiem: %1 + + + + File path is not set + Ścieżka do pliku nie jest ustawiona + + + + XdxfPlugin + + + + + Cache database cannot be opened for %1 dictionary. Searching in XDXF file. You may want to recache. + Nie można otworzyć bazy danych dla słownika %1. Szukanie w pliku XDXF. Możesz spróbować ponownie włączyć optymalizację. + + + + + XDXF file cannot be read for %1 + Nie można odczytać pliku XDXF dla %1 + + + + XDXF file is in wrong format + Niewłaściwy format pliku XDXF + + + + XDXF dictionary cannot be read from file + Nie można odczytać słownika XDXF z pliku + + + + + XDXF file cannot be read for %1 dictionary + Nie mozna odczytać pliku XDXF dla słownika %1 + + + + Database caching error, please try again. + Błąd optymalizacji, proszę spróbować ponownie. + + + diff --git a/src/plugins/stardict/stardict.pro b/src/plugins/stardict/stardict.pro new file mode 100644 index 0000000..c57a9e9 --- /dev/null +++ b/src/plugins/stardict/stardict.pro @@ -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 index 0000000000000000000000000000000000000000..900f71678adc36c355111d16b61fba965160a91d GIT binary patch literal 134 zcmcE7ks@*G{hX<16=n7(EZlq7iGhKEgJ+4@OCZgV3B<9?KthN?l_8HofuWcol_8lS zAIMGt35#F~GZb?GB^cO%m`62Fp*S@;KQBe2Sd$$nAQ+KSk>;G3oROKA?vk09lb_Dm K0TgCpWCQ?znH|Ic literal 0 HcmV?d00001 diff --git a/src/plugins/stardict/translations/pl_PL.qm b/src/plugins/stardict/translations/pl_PL.qm new file mode 100644 index 0000000000000000000000000000000000000000..07a9e30fd960f95c6ebf63425d31042196ca9086 GIT binary patch literal 3426 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 literal 0 HcmV?d00001 -- 1.7.9.5