Make sure settings are only saved when the "Save" button is pressed and the daily...
[timedsilencer] / mainwindow.cpp
index dc2acd0..e4ed214 100644 (file)
@@ -57,12 +57,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
   verticalLayoutR->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
   done_btn = new QPushButton(tr("Save"));
   done_btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
-  connect(done_btn, SIGNAL(clicked()), this, SLOT(close()));
+  connect(done_btn, SIGNAL(clicked()), this, SLOT(saveAndClose()));
   verticalLayoutR->addWidget(done_btn);
   hori_layout->addLayout(verticalLayoutR);
   // Load settings
   loadSettings();
-  connect(cb_enable, SIGNAL(toggled(bool)), this, SLOT(enableSilencing(bool)));
   // Auto rotation
   setAttribute(Qt::WA_Maemo5AutoOrientation, true);
 }
@@ -74,15 +73,18 @@ MainWindow::~MainWindow() {
   delete done_btn;
 }
 
-void MainWindow::closeEvent(QCloseEvent *event) {
+void MainWindow::saveAndClose() {
+  // Save the settings and set the events
   if(cb_enable->isChecked()) {
-    QMaemo5InformationBox::information(this, tr("The daily profile switching is activated"), 0);
     setProfileEvents();
+    QMaemo5InformationBox::information(this, tr("The daily profile switching is activated"), 0);
   } else {
+    AlarmdBackend::deleteEvents();
     QMaemo5InformationBox::information(this, tr("The daily profile switching is deactivated"), 0);
   }
   saveSettings();
-  event->accept();
+  // Close the window
+  close();
 }
 
 void MainWindow::saveSettings() {
@@ -98,15 +100,7 @@ void MainWindow::loadSettings() {
   static_cast<QMaemo5TimePickSelector*>(from_button->pickSelector())->setCurrentTime(from_time);
   QTime to_time = settings.value("to_time", QTime(8, 0)).toTime();
   static_cast<QMaemo5TimePickSelector*>(to_button->pickSelector())->setCurrentTime(to_time);
-  cb_enable->setChecked(settings.value("enabled", true).toBool());
-}
-
-void MainWindow::enableSilencing(bool enabled) {
-  if(enabled) {
-    setProfileEvents();
-  } else {
-    AlarmdBackend::deleteEvents();
-  }
+  cb_enable->setChecked(settings.value("enabled", false).toBool());
 }
 
 void MainWindow::setProfileEvents() {