Added save confirm for general settings
authorBartosz Szatkowski <bulislaw@linux.com>
Mon, 23 Aug 2010 09:25:40 +0000 (11:25 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Mon, 23 Aug 2010 09:25:40 +0000 (11:25 +0200)
trunk/src/base/gui/SettingsWidget.cpp
trunk/src/base/gui/SettingsWidget.h

index 2d72d99..7bd7d77 100644 (file)
@@ -70,11 +70,20 @@ SettingsWidget::SettingsWidget(GUIInterface *parent) :
     #ifndef Q_WS_MAEMO_5
         setMinimumWidth(250);
         setMaximumWidth(250);
+        footerLayout = new QHBoxLayout(this);
+        closeButton = new QPushButton(tr("Ok"));
+        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(
@@ -99,7 +108,14 @@ void SettingsWidget::showEvent(QShowEvent *e) {
 void SettingsWidget::hideEvent(QHideEvent *e) {
     QDialog::hideEvent(e);
 
-    if(settings) {
+    #ifndef Q_WS_MAEMO_5
+    if(settings && _save) {
+    #else
+    if(settings &&
+            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 +142,17 @@ void SettingsWidget::hideEvent(QHideEvent *e) {
             }
         }
 
+    }
+    if(settings) {
         delete settings;
         settings = 0;
     }
 }
+
+
+#ifndef Q_WS_MAEMO_5
+    void SettingsWidget::save() {
+        _save = true;
+        hide();
+    }
+#endif
index f7ed38d..3f56d10 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <QWidget>
 #include <QtGui>
+#include <QPushButton>
 #include "../../includes/GUIInterface.h"
 #include "../../includes/settings.h"
 
@@ -67,6 +68,15 @@ private:
 
     GUIInterface* guiInterface;
     Settings* settings;
+    #ifndef Q_WS_MAEMO_5
+        QPushButton* closeButton;
+        QHBoxLayout* footerLayout;
+        bool _save;
+
+        public Q_SLOTS:
+            void save();
+    #endif
+
 };
 
 #endif // SETTINGSWIDGET_H