UI changes to improve usability, French translation update and bump to v0.4
[timedsilencer] / mainwindow.cpp
index 9506049..dc2acd0 100644 (file)
 #include <QVBoxLayout>
 #include <QLabel>
 #include <QSpacerItem>
-#include <QMenuBar>
 #include <QSettings>
+#include <QCheckBox>
+#include <QPushButton>
+#include <QHBoxLayout>
+#include <QCloseEvent>
 
 #include "mainwindow.h"
 #include "alarmd_backend.h"
 
 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
   setCentralWidget(new QWidget());
-  QVBoxLayout *verticalLayout = new QVBoxLayout(centralWidget());
-  QLabel *from_lbl = new QLabel(tr("Use silent profile between"));
+  QHBoxLayout *hori_layout = new QHBoxLayout(centralWidget());
+  QVBoxLayout *verticalLayoutL = new QVBoxLayout();
+  verticalLayoutL->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
+  QLabel *from_lbl = new QLabel(tr("Use the silent profile between"));
   from_lbl->setAlignment(Qt::AlignHCenter);
-  verticalLayout->addWidget(from_lbl);
+  verticalLayoutL->addWidget(from_lbl);
   from_button = new QMaemo5ValueButton();
   from_button->setPickSelector(new QMaemo5TimePickSelector());
-  verticalLayout->addWidget(from_button);
+  verticalLayoutL->addWidget(from_button);
   QLabel *to_lbl = new QLabel(tr("and"));
   to_lbl->setAlignment(Qt::AlignHCenter);
-  verticalLayout->addWidget(to_lbl);
+  verticalLayoutL->addWidget(to_lbl);
   to_button = new QMaemo5ValueButton();
   to_button->setPickSelector(new QMaemo5TimePickSelector());
-  verticalLayout->addWidget(to_button);
-  verticalLayout->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
-  // Menu actions
-  active_action = menuBar()->addAction(tr("Enabled"));
-  active_action->setCheckable(true);
+  verticalLayoutL->addWidget(to_button);
+  // Status
+  verticalLayoutL->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
+  cb_enable = new QCheckBox(tr("Activated"));
+  verticalLayoutL->addWidget(cb_enable);
+  hori_layout->addLayout(verticalLayoutL);
+  QVBoxLayout *verticalLayoutR = new QVBoxLayout;
+  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()));
+  verticalLayoutR->addWidget(done_btn);
+  hori_layout->addLayout(verticalLayoutR);
   // Load settings
   loadSettings();
-  connect(active_action, SIGNAL(triggered(bool)), this, SLOT(enableSilencing(bool)));
+  connect(cb_enable, SIGNAL(toggled(bool)), this, SLOT(enableSilencing(bool)));
   // Auto rotation
   setAttribute(Qt::WA_Maemo5AutoOrientation, true);
 }
 
 MainWindow::~MainWindow() {
-  if(active_action->isChecked()) {
-    QMaemo5InformationBox::information(this, tr("The timed silencer is enabled"), 0);
+  delete from_button;
+  delete to_button;
+  delete cb_enable;
+  delete done_btn;
+}
+
+void MainWindow::closeEvent(QCloseEvent *event) {
+  if(cb_enable->isChecked()) {
+    QMaemo5InformationBox::information(this, tr("The daily profile switching is activated"), 0);
     setProfileEvents();
   } else {
-    QMaemo5InformationBox::information(this, tr("The timed silencer is disabled"), 0);
+    QMaemo5InformationBox::information(this, tr("The daily profile switching is deactivated"), 0);
   }
   saveSettings();
-  delete from_button;
-  delete to_button;
+  event->accept();
 }
 
 void MainWindow::saveSettings() {
   QSettings settings("TimedSilencer", "TimedSilencer");
   settings.setValue("from_time", static_cast<QMaemo5TimePickSelector*>(from_button->pickSelector())->currentTime());
   settings.setValue("to_time", static_cast<QMaemo5TimePickSelector*>(to_button->pickSelector())->currentTime());
-  settings.setValue("enabled", active_action->isChecked());
+  settings.setValue("enabled", cb_enable->isChecked());
 }
 
 void MainWindow::loadSettings() {
@@ -79,16 +98,14 @@ 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);
-  active_action->setChecked(settings.value("enabled", true).toBool());
+  cb_enable->setChecked(settings.value("enabled", true).toBool());
 }
 
 void MainWindow::enableSilencing(bool enabled) {
   if(enabled) {
     setProfileEvents();
-    //QMaemo5InformationBox::information(this, tr("The Timed Silencer is now enabled"), QMaemo5InformationBox::DefaultTimeout);
   } else {
     AlarmdBackend::deleteEvents();
-    //QMaemo5InformationBox::information(this, tr("The Timed Silencer is now disabled"), QMaemo5InformationBox::DefaultTimeout);
   }
 }