Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
[mdictionary] / trunk / src / plugins / xdxf / src / xdxfplugin.cpp
index 50e9567..a59363b 100644 (file)
 
 XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
                     _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
-                    _type("xdxf"), _infoNote(tr("")) {
+                    _type(tr("xdxf")), _infoNote(tr("")) {
     _wordsCount = -1;
     _settings = new Settings();
     _dictDialog = new XdxfDictDialog(this);
-    cachingDialog = new XdxfCachingDialog();
+    cachingDialog = new XdxfCachingDialog(this);
+
 
     connect(cachingDialog, SIGNAL(cancelCaching()),
             this, SLOT(stop()));
-
     connect(this, SIGNAL(updateCachingProgress(int,int)),
             cachingDialog, SLOT(updateCachingProgress(int,int)));
 
@@ -50,12 +50,11 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
 }
 
 
-
 XdxfPlugin::~XdxfPlugin() {
     delete _settings;
+    delete cachingDialog;
 }
 
-
 QString XdxfPlugin::langFrom() const {   
     return _langFrom;
 }
@@ -137,7 +136,6 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
 
 QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
     QTime time;
-    time.start();
     QSet<Translation*> translations;
     QFile dictionaryFile(path);
 
@@ -187,7 +185,6 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
     }
     stopped=false;
     dictionaryFile.close();
-    qDebug() << time.elapsed();
     return translations.toList();
 }
 
@@ -291,6 +288,8 @@ DictDialog* XdxfPlugin::dictDialog() {
 }
 
 void XdxfPlugin::setPath(QString path){
+    if(this->path!=path && this->path!="" && _settings->value("cache_path")!="");
+        clean();
     this->path=path;
     _settings->setValue("path",path);
     //getDictionaryInfo();
@@ -352,28 +351,29 @@ bool XdxfPlugin::isCached() {
 
 
 void XdxfPlugin::setSettings(Settings *settings) {
+    if(settings)
+    {
+        QString oldPath = _settings->value("path");
+        if(oldPath != settings->value("path")) {
+            setPath(settings->value("path"));
+        }
 
-    QString oldPath = _settings->value("path");
-    if(oldPath != settings->value("path")) {
-        setPath(settings->value("path"));
-    }
+       foreach(QString key, settings->keys())
+           if(key != "generateCache")
+               _settings->setValue(key, settings->value(key));
 
-   foreach(QString key, settings->keys())
-       if(key != "generateCache")
-           _settings->setValue(key, settings->value(key));
+        if((_settings->value("cached") == "false" ||
+                _settings->value("cached").isEmpty()) &&
+                settings->value("generateCache") == "true") {
+            makeCache("");
+        }
+        else if (settings->value("generateCache") != "true") {
+           _settings->setValue("cached", "false");
+        }
 
-    if((_settings->value("cached") == "false" ||
-            _settings->value("cached").isEmpty()) &&
-            settings->value("generateCache") == "true") {
-        makeCache("");
-    }
-    else if (settings->value("generateCache") != "true") {
-       _settings->setValue("cached", "false");
+        getDictionaryInfo();
+        delete settings;
     }
-
-
-    delete settings;
-
     Q_EMIT settingsChanged();
 }
 
@@ -445,7 +445,7 @@ int XdxfPlugin::countWords() {
     return wordsCount;
 }
 
-bool XdxfPlugin::makeCache(QString dir) {
+bool XdxfPlugin::makeCache(QString) {
     cachingDialog->setVisible(true);
     QCoreApplication::processEvents();
     stopped = false;
@@ -456,7 +456,6 @@ bool XdxfPlugin::makeCache(QString dir) {
 
     QFile dictionaryFile(dictFileN.filePath());
 
-
     if (!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
         Q_EMIT updateCachingProgress(100, 0);
         Q_EMIT notify(Notify::Warning,