Moved icons from resources to data/ fixed bug with segmentation fault when starting...
[mdictionary] / trunk / src / base / gui / SettingsWidget.cpp
index 8f3b218..2d72d99 100644 (file)
@@ -45,6 +45,9 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
     spinBoxesFormLayout->addRow(tr("History size"),
                                 historySizeSpinBox);
 
+    searchResultSizeSpinBox->setMinimum(1);
+    historySizeSpinBox->setMinimum(1);
+
     #ifdef Q_WS_MAEMO_5
         verticalLayout->addSpacing(20);
     #endif
@@ -61,6 +64,9 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
     verticalLayout->addWidget(searchInDictionariesCheckBox);
     verticalLayout->addWidget(searchInBookmarksCheckBox);
 
+
+    settings = 0;
+
     #ifndef Q_WS_MAEMO_5
         setMinimumWidth(250);
         setMaximumWidth(250);
@@ -69,9 +75,9 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
 
 void SettingsWidget::showEvent(QShowEvent *e) {
 
-    settings = guiInterface->settings();
+   settings = guiInterface->settings();
 
-    historySizeSpinBox->setValue(
+   historySizeSpinBox->setValue(
             settings->value("history_size").toInt());
 
     searchResultSizeSpinBox->setValue(
@@ -91,29 +97,36 @@ void SettingsWidget::showEvent(QShowEvent *e) {
 }
 
 void SettingsWidget::hideEvent(QHideEvent *e) {
-    Settings* newSettings = new Settings;
-    newSettings->setValue("history_size",
-                          QString::number(historySizeSpinBox->value()));
-    newSettings->setValue("search_limit",
-                          QString::number(searchResultSizeSpinBox->value()));
-
-    if(searchInDictionariesCheckBox->isChecked())
-        newSettings->setValue("search_dictionaries", "true");
-    else
-        newSettings->setValue("search_dictionaries", "false");
-
-    if(searchInBookmarksCheckBox->isChecked())
-        newSettings->setValue("search_bookmarks", "true");
-    else
-        newSettings->setValue("search_bookmarks", "false");
+    QDialog::hideEvent(e);
 
-    QString key;
-    foreach(key, newSettings->keys()) {
-        if(settings->value(key) != newSettings->value(key)) {
-            guiInterface->setSettings(newSettings);
-            break;
+    if(settings) {
+        Settings* newSettings = new Settings;
+        newSettings->setValue("history_size",
+                              QString::number(historySizeSpinBox->value()));
+        newSettings->setValue("search_limit",
+                              QString::number(
+                                      searchResultSizeSpinBox->value()));
+
+        if(searchInDictionariesCheckBox->isChecked())
+            newSettings->setValue("search_dictionaries", "true");
+        else
+            newSettings->setValue("search_dictionaries", "false");
+
+        if(searchInBookmarksCheckBox->isChecked())
+            newSettings->setValue("search_bookmarks", "true");
+        else
+            newSettings->setValue("search_bookmarks", "false");
+
+        //setting new settings only if their are different that old ones
+        QString key;
+        foreach(key, newSettings->keys()) {
+            if(settings->value(key) != newSettings->value(key)) {
+                guiInterface->setSettings(newSettings);
+                break;
+            }
         }
-    }
 
-    QDialog::hideEvent(e);
+        delete settings;
+        settings = 0;
+    }
 }