From: Mateusz Półrola Date: Tue, 5 Oct 2010 09:57:11 +0000 (+0200) Subject: Fixed file names X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=22a63ba66bc0763dc553d99d5bbd3c107d7e620d;p=mdictionary Fixed file names --- diff --git a/mdictionary.pri b/mdictionary.pri index 3a5aeeb..ab81e07 100644 --- a/mdictionary.pri +++ b/mdictionary.pri @@ -8,7 +8,7 @@ CONFIG += \ CONFIG -= debug isEmpty(ENABLED_SRC):ENABLED_SRC = "mdictionary plugins desktopWidget" -isEmpty(ENABLED_PLUGINS):ENABLED_PLUGINS = "xdxf google" +isEmpty(ENABLED_PLUGINS):ENABLED_PLUGINS = "xdxf google stardict" isEmpty(INSTALL_PREFIX):INSTALL_PREFIX=/usr isEmpty(BIN_DIR):BIN_DIR=$$INSTALL_PREFIX/bin diff --git a/src/plugins/plugins.pri b/src/plugins/plugins.pri index ba1bf3d..df3baf9 100644 --- a/src/plugins/plugins.pri +++ b/src/plugins/plugins.pri @@ -1 +1 @@ -ENABLED_PLUGINS = xdxf google +ENABLED_PLUGINS = xdxf google stardict diff --git a/src/plugins/stardict/StarDict.cpp b/src/plugins/stardict/StarDict.cpp deleted file mode 100644 index ee8ee03..0000000 --- a/src/plugins/stardict/StarDict.cpp +++ /dev/null @@ -1,633 +0,0 @@ -/******************************************************************************* - - 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 deleted file mode 100644 index 334a506..0000000 --- a/src/plugins/stardict/StarDict.h +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - - 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/StarDictLoadDialog.h b/src/plugins/stardict/StarDictLoadDialog.h deleted file mode 100644 index a5161bf..0000000 --- a/src/plugins/stardict/StarDictLoadDialog.h +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - - 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/StarDictPlugin.cpp b/src/plugins/stardict/StarDictPlugin.cpp new file mode 100644 index 0000000..ee8ee03 --- /dev/null +++ b/src/plugins/stardict/StarDictPlugin.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/StarDictPlugin.h b/src/plugins/stardict/StarDictPlugin.h new file mode 100644 index 0000000..334a506 --- /dev/null +++ b/src/plugins/stardict/StarDictPlugin.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/StardictLoadDialog.cpp b/src/plugins/stardict/StardictLoadDialog.cpp deleted file mode 100644 index 83f29c3..0000000 --- a/src/plugins/stardict/StardictLoadDialog.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - - 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/stardict.pro b/src/plugins/stardict/stardict.pro index c57a9e9..e12c77b 100644 --- a/src/plugins/stardict/stardict.pro +++ b/src/plugins/stardict/stardict.pro @@ -20,7 +20,7 @@ HEADERS += \ StarDictPlugin.h \ TranslationStarDict.h \ ../../include/DictDialog.h \ - StarDictDictDialog.h \ + StarDictDialog.h \ ../../include/translation.h \ ../../include/settings.h \ ../../include/CommonDictInterface.h \