Merge branch 'cache'
[mdictionary] / trunk / src / base / gui / SettingsWidget.cpp
index 4cf721d..81bde6e 100644 (file)
@@ -65,16 +65,35 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
     verticalLayout->addWidget(searchInBookmarksCheckBox);
 
 
+    connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
+            SLOT(changed()));
+    connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
+            SLOT(changed()));
+    connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
+            SLOT(changed()));
+    connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
+            SLOT(changed()));
+
+
     settings = 0;
 
     #ifndef Q_WS_MAEMO_5
         setMinimumWidth(250);
         setMaximumWidth(250);
+        footerLayout = new QHBoxLayout(this);
+        closeButton = new QPushButton(tr("Save"));
+        footerLayout->addStretch(0);
+        footerLayout->addWidget(closeButton);
+        verticalLayout->addLayout(footerLayout);
+        connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
     #endif
 }
 
 void SettingsWidget::showEvent(QShowEvent *e) {
 
+   #ifndef Q_WS_MAEMO_5
+       _save = false;
+   #endif
    settings = guiInterface->settings();
 
    historySizeSpinBox->setValue(
@@ -93,13 +112,21 @@ void SettingsWidget::showEvent(QShowEvent *e) {
     else
         searchInDictionariesCheckBox->setChecked(false);
 
+    _changed = false;
     QDialog::showEvent(e);
 }
 
 void SettingsWidget::hideEvent(QHideEvent *e) {
     QDialog::hideEvent(e);
 
-    if(settings) {
+    #ifndef Q_WS_MAEMO_5
+    if(settings && _save) {
+    #else
+    if(settings && _changed &&
+            QMessageBox::question(this, "Save", "Do you want to save changes?",
+             QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+
+    #endif
         Settings* newSettings = new Settings;
         newSettings->setValue("history_size",
                               QString::number(historySizeSpinBox->value()));
@@ -126,7 +153,22 @@ void SettingsWidget::hideEvent(QHideEvent *e) {
             }
         }
 
+    }
+    if(settings) {
         delete settings;
         settings = 0;
     }
+    _changed = false;
+}
+
+
+void SettingsWidget::changed() {
+    _changed = true;
 }
+
+#ifndef Q_WS_MAEMO_5
+    void SettingsWidget::save() {
+        _save = true;
+        hide();
+    }
+#endif