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>
26 #include <QPushButton>
27 #include <QHBoxLayout>
28 #include <QCloseEvent>
30 #include "mainwindow.h"
31 #include "alarmd_backend.h"
32 #include "dbus_backend.h"
34 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
35 setCentralWidget(new QWidget());
36 QHBoxLayout *hori_layout = new QHBoxLayout(centralWidget());
37 QVBoxLayout *verticalLayoutL = new QVBoxLayout();
38 verticalLayoutL->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
39 QLabel *from_lbl = new QLabel(tr("Use the silent profile between"));
40 from_lbl->setAlignment(Qt::AlignHCenter);
41 verticalLayoutL->addWidget(from_lbl);
42 from_button = new QMaemo5ValueButton();
43 from_button->setPickSelector(new QMaemo5TimePickSelector());
44 verticalLayoutL->addWidget(from_button);
45 QLabel *to_lbl = new QLabel(tr("and"));
46 to_lbl->setAlignment(Qt::AlignHCenter);
47 verticalLayoutL->addWidget(to_lbl);
48 to_button = new QMaemo5ValueButton();
49 to_button->setPickSelector(new QMaemo5TimePickSelector());
50 verticalLayoutL->addWidget(to_button);
52 verticalLayoutL->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
53 cb_enable = new QCheckBox(tr("Activated"));
54 verticalLayoutL->addWidget(cb_enable);
55 hori_layout->addLayout(verticalLayoutL);
56 QVBoxLayout *verticalLayoutR = new QVBoxLayout;
57 verticalLayoutR->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
58 done_btn = new QPushButton(tr("Save"));
59 done_btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
60 connect(done_btn, SIGNAL(clicked()), this, SLOT(close()));
61 verticalLayoutR->addWidget(done_btn);
62 hori_layout->addLayout(verticalLayoutR);
65 connect(cb_enable, SIGNAL(toggled(bool)), this, SLOT(enableSilencing(bool)));
67 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
70 MainWindow::~MainWindow() {
77 void MainWindow::closeEvent(QCloseEvent *event) {
78 if(cb_enable->isChecked()) {
79 QMaemo5InformationBox::information(this, tr("The daily profile switching is activated"), 0);
82 QMaemo5InformationBox::information(this, tr("The daily profile switching is deactivated"), 0);
88 void MainWindow::saveSettings() {
89 QSettings settings("TimedSilencer", "TimedSilencer");
90 settings.setValue("from_time", static_cast<QMaemo5TimePickSelector*>(from_button->pickSelector())->currentTime());
91 settings.setValue("to_time", static_cast<QMaemo5TimePickSelector*>(to_button->pickSelector())->currentTime());
92 settings.setValue("enabled", cb_enable->isChecked());
95 void MainWindow::loadSettings() {
96 QSettings settings("TimedSilencer", "TimedSilencer");
97 QTime from_time = settings.value("from_time", QTime(22, 0)).toTime();
98 static_cast<QMaemo5TimePickSelector*>(from_button->pickSelector())->setCurrentTime(from_time);
99 QTime to_time = settings.value("to_time", QTime(8, 0)).toTime();
100 static_cast<QMaemo5TimePickSelector*>(to_button->pickSelector())->setCurrentTime(to_time);
101 cb_enable->setChecked(settings.value("enabled", true).toBool());
104 void MainWindow::enableSilencing(bool enabled) {
108 AlarmdBackend::deleteEvents();
112 void MainWindow::setProfileEvents() {
113 // Set profile events in Alarmd
114 QTime from_time = static_cast<QMaemo5TimePickSelector*>(from_button->pickSelector())->currentTime();
115 qDebug("From time: %s", qPrintable(from_time.toString()));
116 AlarmdBackend::setProfileEvent(SILENT, from_time);
117 QTime to_time = static_cast<QMaemo5TimePickSelector*>(to_button->pickSelector())->currentTime();
118 AlarmdBackend::setProfileEvent(GENERAL, to_time);
119 qDebug("To time: %s", qPrintable(to_time.toString()));
120 // Update current profile
121 bool in_silent_mode = false;
122 QTime ctime = QTime::currentTime();
123 if(from_time < to_time) {
124 in_silent_mode = (ctime > from_time && ctime < to_time);
126 // to_time is the next day
127 in_silent_mode = (ctime > from_time || (ctime < from_time && ctime < to_time));
130 DBusBackend::setProfile(SILENT);
132 DBusBackend::setProfile(GENERAL);*/