X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fplugins%2Fxdxf%2Fxdxfplugin.cpp;h=aad8274f27bf0c72cff3d14962c5d319e424ad51;hb=14cb9cc957bcdc9c39af54ba168c6816a1910a2d;hp=884ae7d9bbc730c677bc4fcc75b5794a4b2200da;hpb=b2edd0bdef4d55ca9c19d70885e36f384bcbceb6;p=mdictionary diff --git a/src/plugins/xdxf/xdxfplugin.cpp b/src/plugins/xdxf/xdxfplugin.cpp index 884ae7d..aad8274 100644 --- a/src/plugins/xdxf/xdxfplugin.cpp +++ b/src/plugins/xdxf/xdxfplugin.cpp @@ -25,30 +25,39 @@ #include "xdxfplugin.h" #include -#include "../../common/Notify.h" +#include "../../include/Notify.h" XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent), _langFrom(""), _langTo(""),_name(""), _infoNote("") { _settings = new Settings(); - _dictDialog = new XdxfDictDialog(this); - cachingDialog = new XdxfCachingDialog(this); + _dictDialog = new XdxfDictDialog(this, this); + + connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString)), + this, SIGNAL(notify(Notify::NotifyType,QString))); + _settings->setValue("type","xdxf"); - _icon = QIcon(":/icons/xdxf.png"); + _icon = QIcon("/usr/share/mdictionary/xdxf.png"); _wordsCount = -1; stopped = false; - connect(cachingDialog, SIGNAL(cancelCaching()), - this, SLOT(stop())); - connect(this, SIGNAL(updateCachingProgress(int,int)), - cachingDialog, SLOT(updateCachingProgress(int,int))); 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 cachingDialog; delete _dictDialog; } @@ -74,7 +83,7 @@ QString XdxfPlugin::type() const { QString XdxfPlugin::infoNote() const { - return _infoNote; + return _infoNote; } @@ -133,7 +142,7 @@ QList XdxfPlugin::searchWordListCache(QString word, int limit) { if(ok) { /*add key word to list*/ translations.insert(new TranslationXdxf( cur.value(0).toString().toLower(), - _infoNote, this)); + _dictionaryInfo, this)); i++; } } @@ -184,7 +193,7 @@ QList XdxfPlugin::searchWordListFile(QString word, int limit) { } if(ok) { /*add key word to list*/ translations<<(new TranslationXdxf(readKey.toLower(), - _infoNote,this)); + _dictionaryInfo,this)); i++; } if(i>=limit && limit!=0) @@ -310,9 +319,23 @@ DictDialog* XdxfPlugin::dictDialog() { CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const { XdxfPlugin *plugin = new XdxfPlugin(); - if(settings && plugin->setSettings(settings)) + + 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; } @@ -324,24 +347,7 @@ bool XdxfPlugin::isAvailable() const { } -void XdxfPlugin::setHash(uint _hash) { - this->_hash=_hash; -} - - -uint XdxfPlugin::hash() const { - return _hash; -} - - Settings* XdxfPlugin::settings() { -/* - Settings *returnSettings=new Settings; - QStringList list = _settings->keys(); - foreach(QString key, list) - returnSettings->setValue(key,_settings->value(key)); - return returnSettings; -*/ return _settings; } @@ -435,15 +441,17 @@ bool XdxfPlugin::getDictionaryInfo() { 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"; - QString format = "png"; - QString initialPath = QDir::currentPath() + "/xdxf." + format; + _dictionaryInfo= _name + " [" + _langFrom + "-" + + _langTo + "]"; - _infoNote="path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-" - + _langTo + "] ( xdxf )"; dictionaryFile.close(); if(okFormat) return true; @@ -487,7 +495,19 @@ int XdxfPlugin::countWords() { bool XdxfPlugin::makeCache(QString) { - cachingDialog->setVisible(true); + + 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; @@ -505,9 +525,6 @@ bool XdxfPlugin::makeCache(QString) { db_name = _settings->value("type") + cachePathN; db = QSqlDatabase::addDatabase("QSQLITE",db_name); - qDebug()<value("path")) @@ -550,6 +567,7 @@ bool XdxfPlugin::makeCache(QString) { /*add all words to db*/ while (!reader.atEnd() && !stopped) { + QCoreApplication::processEvents(); reader.readNext(); if(reader.tokenType() == QXmlStreamReader::StartElement) { @@ -590,7 +608,7 @@ bool XdxfPlugin::makeCache(QString) { cur.exec(); counter++; int prog = counter*100/_wordsCount; - if(prog % 5 == 0 && lastProg != prog) { + if(prog % 2 == 0 && lastProg != prog) { Q_EMIT updateCachingProgress(prog,timer.restart()); lastProg = prog; } @@ -598,14 +616,13 @@ bool XdxfPlugin::makeCache(QString) { } cur.exec("END;"); cur.exec("select count(*) from dict"); - cachingDialog->setVisible(false); /*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 againg."))); + QString(tr("Database caching error, please try again."))); db.close(); return false; } @@ -613,6 +630,13 @@ bool XdxfPlugin::makeCache(QString) { _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; }