2 * This file is part of TimedSilencer.
4 * TimedSilencer is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * TimedSilencer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with TimedSilencer. If not, see <http://www.gnu.org/licenses/>.
18 #include <QMaemo5ValueButton>
19 #include <QMaemo5TimePickSelector>
20 #include <QMaemo5InformationBox>
21 #include <QVBoxLayout>
23 #include <QSpacerItem>
27 #include "mainwindow.h"
28 #include "alarmd_backend.h"
29 #include "dbus_backend.h"
31 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
32 setCentralWidget(new QWidget());
33 QVBoxLayout *verticalLayout = new QVBoxLayout(centralWidget());
34 QLabel *from_lbl = new QLabel(tr("Use silent profile between"));
35 from_lbl->setAlignment(Qt::AlignHCenter);
36 verticalLayout->addWidget(from_lbl);
37 from_button = new QMaemo5ValueButton();
38 from_button->setPickSelector(new QMaemo5TimePickSelector());
39 verticalLayout->addWidget(from_button);
40 QLabel *to_lbl = new QLabel(tr("and"));
41 to_lbl->setAlignment(Qt::AlignHCenter);
42 verticalLayout->addWidget(to_lbl);
43 to_button = new QMaemo5ValueButton();
44 to_button->setPickSelector(new QMaemo5TimePickSelector());
45 verticalLayout->addWidget(to_button);
46 verticalLayout->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
48 active_action = menuBar()->addAction(tr("Enabled"));
49 active_action->setCheckable(true);
52 connect(active_action, SIGNAL(triggered(bool)), this, SLOT(enableSilencing(bool)));
54 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
57 MainWindow::~MainWindow() {
58 if(active_action->isChecked()) {
59 QMaemo5InformationBox::information(this, tr("The timed silencer is enabled"), 0);
62 QMaemo5InformationBox::information(this, tr("The timed silencer is disabled"), 0);
69 void MainWindow::saveSettings() {
70 QSettings settings("TimedSilencer", "TimedSilencer");
71 settings.setValue("from_time", static_cast<QMaemo5TimePickSelector*>(from_button->pickSelector())->currentTime());
72 settings.setValue("to_time", static_cast<QMaemo5TimePickSelector*>(to_button->pickSelector())->currentTime());
73 settings.setValue("enabled", active_action->isChecked());
76 void MainWindow::loadSettings() {
77 QSettings settings("TimedSilencer", "TimedSilencer");
78 QTime from_time = settings.value("from_time", QTime(22, 0)).toTime();
79 static_cast<QMaemo5TimePickSelector*>(from_button->pickSelector())->setCurrentTime(from_time);
80 QTime to_time = settings.value("to_time", QTime(8, 0)).toTime();
81 static_cast<QMaemo5TimePickSelector*>(to_button->pickSelector())->setCurrentTime(to_time);
82 active_action->setChecked(settings.value("enabled", true).toBool());
85 void MainWindow::enableSilencing(bool enabled) {
88 //QMaemo5InformationBox::information(this, tr("The Timed Silencer is now enabled"), QMaemo5InformationBox::DefaultTimeout);
90 AlarmdBackend::deleteEvents();
91 //QMaemo5InformationBox::information(this, tr("The Timed Silencer is now disabled"), QMaemo5InformationBox::DefaultTimeout);
95 void MainWindow::setProfileEvents() {
96 // Set profile events in Alarmd
97 QTime from_time = static_cast<QMaemo5TimePickSelector*>(from_button->pickSelector())->currentTime();
98 qDebug("From time: %s", qPrintable(from_time.toString()));
99 AlarmdBackend::setProfileEvent(SILENT, from_time);
100 QTime to_time = static_cast<QMaemo5TimePickSelector*>(to_button->pickSelector())->currentTime();
101 AlarmdBackend::setProfileEvent(GENERAL, to_time);
102 qDebug("To time: %s", qPrintable(to_time.toString()));
103 // Update current profile
104 bool in_silent_mode = false;
105 QTime ctime = QTime::currentTime();
106 if(from_time < to_time) {
107 in_silent_mode = (ctime > from_time && ctime < to_time);
109 // to_time is the next day
110 in_silent_mode = (ctime > from_time || (ctime < from_time && ctime < to_time));
113 DBusBackend::setProfile(SILENT);
115 DBusBackend::setProfile(GENERAL);*/