New xdxf dialog, one which provides methods to add new or change setting of existing...
[mdictionary] / src / plugins / xdxf / xdxfplugin.cpp
index 9335759..533350b 100644 (file)
 
 #include "xdxfplugin.h"
 #include <QDebug>
-#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);
+    _dictDialog = new XdxfDictDialog(this, this);
+
+    connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)),
+            this, SIGNAL(notify(Notify::NotifyType,QString, QWidget*)));
+
     cachingDialog = new XdxfCachingDialog(this);
 
+
+
     _settings->setValue("type","xdxf");
-    _icon = QIcon(":/icons/xdxf.png");
+    _icon = QIcon("/usr/share/mdictionary/xdxf.png");
     _wordsCount = -1;
     stopped = false;
 
@@ -45,6 +51,19 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
     initAccents();
 }
 
+void XdxfPlugin::retranslate() {
+    QString locale = QLocale::system().name();
+
+    QTranslator *translator = new QTranslator(this);
+
+    if(locale == "pl_PL")
+        translator->load(":/translations/dict_xdxf_pl");
+    else
+        translator->load(":/translations/dict_xdxf_en");
+
+    QCoreApplication::installTranslator(translator);
+}
+
 
 XdxfPlugin::~XdxfPlugin() {
     delete _settings;
@@ -310,11 +329,12 @@ DictDialog* XdxfPlugin::dictDialog() {
 
 CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
     XdxfPlugin *plugin = new XdxfPlugin();
-    if(settings && plugin->setSettings(settings))
+    if(settings && plugin->setSettings(settings)) {
         return plugin;
+    }
     else {
         delete plugin;
-        return new XdxfPlugin();
+        return 0;
     }
 }
 
@@ -357,12 +377,17 @@ 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));
@@ -372,6 +397,8 @@ bool XdxfPlugin::setSettings(const Settings *settings) {
             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;
         }
 
@@ -432,11 +459,10 @@ bool XdxfPlugin::getDictionaryInfo() {
     if(reader.name()=="description")
         _infoNote=reader.readElementText();
 
-    QString format = "png";
-    QString initialPath = QDir::currentPath() + "/xdxf." + format;
+    QString initialPath = "/usr/share/mdictionary/xdxf.png";
 
-    _infoNote="path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-"
-                + _langTo + "] ( xdxf )";
+    _infoNote=" path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-"
+                + _langTo + "]";
     dictionaryFile.close();
     if(okFormat)
         return true;
@@ -498,9 +524,6 @@ bool XdxfPlugin::makeCache(QString) {
     db_name = _settings->value("type") + cachePathN;
     db = QSqlDatabase::addDatabase("QSQLITE",db_name);
 
-    qDebug()<<QSqlDatabase::connectionNames().size();
-    foreach(QString name,QSqlDatabase::connectionNames())
-        qDebug()<<name;
     /*checke errors (File open and db open)*/
     QFile dictionaryFile(dictFileN.filePath());
     if (!QFile::exists(_settings->value("path"))
@@ -598,7 +621,7 @@ bool XdxfPlugin::makeCache(QString) {
     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;
     }