Added saving to configs new dictionaries and active/inactive state
authorBartosz Szatkowski <bulislaw@linux.com>
Tue, 10 Aug 2010 08:34:31 +0000 (10:34 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Tue, 10 Aug 2010 08:34:31 +0000 (10:34 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.cpp

index 29fc0ab..66181d2 100644 (file)
@@ -150,18 +150,25 @@ void Backbone::search(QStringList words) {
 
 
 
- void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
-     foreach(CommonDictInterface* dict, _dicts.keys())
-         if(activeDicts.contains(dict))
-             _dicts[dict] = 1;
-         else
-             _dicts[dict] = 0;
+void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
+    foreach(CommonDictInterface* dict, _dicts.keys())
+        if(activeDicts.contains(dict))
+            _dicts[dict] = 1;
+        else
+            _dicts[dict] = 0;
+    dictUpdated();
  }
 
 
 
+void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
+    addInternalDictionary(dict,active);
+    dictUpdated();
+}
+
+
 
- void Backbone::addDictionary(CommonDictInterface* dict, bool active) {
+ void Backbone::addInternalDictionary(CommonDictInterface* dict, bool active) {
      dict->setHash(_dicts.size()+1);
      _dicts[dict] = active;
      connect(dict, SIGNAL(settingsChanged()), this, SLOT(dictUpdated()));
@@ -255,6 +262,7 @@ void Backbone::loadPrefs() {
     QDir confDir(_configPath);
     if(!confDir.exists())
         qDebug() << "Configuration file dosn't exists (" << _configPath << ")";
+        return;
     QSettings set(_configPath + "/mdictionary.config", QSettings::IniFormat);
     _pluginPath = set.value("general/plugin_path", _pluginPath).toString();
     _historyLen = set.value("general/history_length", 10).toInt();
@@ -267,8 +275,8 @@ void Backbone::loadDicts() {
     QDir confDir(_configPath);
     if(!confDir.exists())
         qDebug() << confDir.mkpath(_configPath);
+
     QSettings set(_configPath + "/mdictionary.config", QSettings::IniFormat);
-    _pluginPath = set.value("general/path", _pluginPath).toString();
     QStringList dicts = set.childGroups();
     foreach(QString dict, dicts) {
         if(!dict.contains("dictionary_"))
@@ -286,13 +294,13 @@ void Backbone::loadDicts() {
         QStringList items = set.childKeys();
         foreach(QString item, items)
             plugSet->setValue(item, set.value(item, "").toString());
-        addDictionary(plug->getNew(plugSet), set.value("active",1).toBool());
+        bool active = set.value("active",1).toBool();
         set.endGroup();
+        addInternalDictionary(plug->getNew(plugSet), active);
     }
 }
 
 void Backbone::dictUpdated() {
-    qDebug() << "UPDATE";
     QDir confDir(_configPath);
     if(!confDir.exists())
         qDebug() << confDir.mkpath(_configPath);
@@ -303,13 +311,14 @@ void Backbone::dictUpdated() {
 
 void Backbone::saveState(QSettings* set, Settings* plugSet, bool active
                          , uint hash) {
+    if(!set || !plugSet)
+        return;
     QString section;
-    section.append("dictionary_%1").arg(hash);
+    section.append(QString("dictionary_%1").arg(hash));
     QList<QString> keys = plugSet->keys();
     foreach(QString key, keys)
         set->setValue(section + "/" + key, plugSet->value(key));
     set->setValue(section + "/active", active);
-
 }
 
 //saving dictionaries state
index 9159318..fee6e60 100644 (file)
@@ -94,6 +94,7 @@ public Q_SLOTS:
 
     /*! adds new dictionary and activate it
       \param dict dictionary to be added
+      \param active decides whether searches are perfomed in given dictionaries
       */
     void addDictionary(CommonDictInterface* dict, bool active = 1);
 
@@ -149,6 +150,7 @@ private:
     void loadDicts();
     void saveState(QSettings*, Settings*, bool, uint);
     CommonDictInterface* plugin(QString type); //< search for given type plugin
+    void addInternalDictionary(CommonDictInterface*, bool);
     //void writeConfig(QString key, QString value);
 
 };
index c8d882e..723e770 100644 (file)
@@ -102,6 +102,8 @@ Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
 
     if(settingsDialog.exec()==QDialog::Accepted) {
         Settings* settings = new Settings;
+        foreach(QString key, plugin->settings()->keys())
+            settings->setValue(key, plugin->settings()->value(key));
         settings->setValue("path", settingsDialog.dicitonaryFilePath());
         plugin->setSettings(settings);
         return NULL;