Resolve conflict after pull
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Fri, 13 Aug 2010 09:25:50 +0000 (11:25 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Fri, 13 Aug 2010 09:25:50 +0000 (11:25 +0200)
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.cpp
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.h
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

index 75c425d..1d88298 100644 (file)
@@ -56,12 +56,17 @@ XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
     cacheLayout = new QHBoxLayout;
     verticalLayout->addLayout(cacheLayout);
 
-    cacheButton = new QPushButton(tr("Cache"));
-    if(plugin->settings()->value("Cached") == "true") {
-        cacheButton->setEnabled(false);
+    cacheCheckBox = new QCheckBox(tr("Cached"));
+    if(plugin->settings()->value("cached") == "true") {
+        cacheCheckBox->setChecked(true);
+        _generateCache = true;
+    }
+    else {
+        cacheCheckBox->setChecked(false);
+        _generateCache = false;
     }
 
-    cacheLayout->addWidget(cacheButton);
+    cacheLayout->addWidget(cacheCheckBox);
 
     saveButton = new QPushButton(tr("Save settings"));
 
@@ -75,9 +80,20 @@ XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
     connect(saveButton, SIGNAL(clicked()),
             this, SLOT(accept()));
 
+    connect(cacheCheckBox, SIGNAL(toggled(bool)),
+            SLOT(setGenerateCache(bool)));
+
     _dicitonaryFilePath = plugin->settings()->value("path");
 }
 
+void XdxfSettingsDialog::setGenerateCache(bool generate) {
+    _generateCache = generate;
+}
+
+bool XdxfSettingsDialog::generateCache() {
+    return _generateCache;
+}
+
 void XdxfSettingsDialog::selectFile() {
     QString fileName = QFileDialog::getOpenFileName(this,
                                      tr("Select dictionary file"),
@@ -105,6 +121,13 @@ Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
         foreach(QString key, plugin->settings()->keys())
             settings->setValue(key, plugin->settings()->value(key));
         settings->setValue("path", settingsDialog.dicitonaryFilePath());
+
+        if(settingsDialog.generateCache()) {
+            settings->setValue("cached", "true");
+        }
+        else {
+            settings->setValue("cached", "false");
+        }
         plugin->setSettings(settings);
         return NULL;
     }
index 4eda7a1..25671eb 100644 (file)
@@ -41,17 +41,18 @@ public:
     QString dicitonaryFilePath();
 
     //! Returns if user want to cache dictionary
-   // bool generateCache();
+    bool generateCache();
 
 private Q_SLOTS:
     void selectFile();
+    void setGenerateCache(bool);
 
 private:
     QLabel* infoLabel;
     QPushButton* saveButton;
     QPushButton* browseButton;
     QLabel* browseLabel;
-    QPushButton* cacheButton;
+    QCheckBox* cacheCheckBox;
     QVBoxLayout* verticalLayout;
     QHBoxLayout* browseLayout;
     QHBoxLayout* cacheLayout;
index fdce4aa..48e3857 100644 (file)
@@ -211,7 +211,7 @@ DictDialog* XdxfPlugin::dictDialog() {
 void XdxfPlugin::setPath(QString path){
     this->path=path;
     _settings->setValue("path",path);
-    getDictionaryInfo();
+    //getDictionaryInfo();
 }
 
 
@@ -219,14 +219,18 @@ CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
     XdxfPlugin *plugin = new XdxfPlugin();
     if(settings){
         plugin->setPath(settings->value("path"));
+
         QStringList list = settings->keys();
         foreach(QString key, list)
             plugin->settings()->setValue(key, settings->value(key));
-        //if(plugin->settings()->value("cached") != "true")
+        
+//if(plugin->settings()->value("cached") != "true")
         plugin->db_name = plugin->_settings->value("type")
                + plugin->_settings->value("path");
         plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
         plugin->makeCache("");
+        plugin->getDictionaryInfo();
+        
     }
     return  plugin;
 }
@@ -255,8 +259,20 @@ bool XdxfPlugin::isCached()
 }
 
 void XdxfPlugin::setSettings(Settings *settings) {
-    _settings = settings;
-    setPath(_settings->value("path"));
+
+    QString oldPath = _settings->value("path");
+    if(oldPath != settings->value("path")) {
+        setPath(settings->value("path"));
+    }
+
+    if(_settings->value("cached") == "false" &&
+       settings->value("cached") == "true") {
+        makeCache("");
+    }
+    else {
+        _settings->setValue("cached", settings->value("cached"));
+    }
+
     emit settingsChanged();
 }
 
@@ -335,6 +351,7 @@ int XdxfPlugin::countWords() {
 
 bool XdxfPlugin::makeCache(QString dir) {
     cachingDialog->setVisible(true);
+    QCoreApplication::processEvents();
     QFileInfo dictFileN(_settings->value("path"));
     QString cachePathN;
     cachePathN = QDir::homePath() + "/.mdictionary/"
@@ -357,10 +374,12 @@ bool XdxfPlugin::makeCache(QString dir) {
         qDebug() << "Database error" << endl;
         return false;
     }
+    QCoreApplication::processEvents();
     QSqlQuery cur(db);
     cur.exec("PRAGMA synchronous = 0");
     cur.exec("drop table dict");
     cur.exec("create table dict(word text ,transl text)");
+    QCoreApplication::processEvents();
     int counter = 0;
     cur.exec("BEGIN;");
 
@@ -409,15 +428,19 @@ bool XdxfPlugin::makeCache(QString dir) {
         }
     }
 
-    cachingDialog->setVisible(false);
 
     qDebug()<<counter;
     cur.exec("END;");
     cur.exec("select count(*) from dict");
+
+    countWords();
+    cachingDialog->setVisible(false);
+
     if(!cur.next() || countWords() != cur.value(0).toInt())
         return false;
     _settings->setValue("cache_path", cachePathN);
     _settings->setValue("cached", "true");
+
     return true;
 }