First version
[staging/HomeScreen.git] / src / systemsettingssimulator.cpp
1 /*
2  * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "systemsettingssimulator.h"
18 #include "ui_systemsettingssimulator.h"
19 #include "include/daynightmode.h"
20 #include <QSettings>
21
22 SystemSettingsSimulator::SystemSettingsSimulator(QWidget *parent) :
23     QDialog(parent),
24     mp_ui(new Ui::SystemSettingsSimulator),
25     mp_dBusDayNightMode(0)
26 {
27     mp_ui->setupUi(this);
28
29     // connect to the dBus interface provided by the main window
30     mp_dBusDayNightMode = new org::agl::daynightmode("org.agl.mainwindow",
31                                               "/MainWindow",
32                                               QDBusConnection::sessionBus(),
33                                               0);
34
35     QSettings settings;
36     this->restoreGeometry(settings.value("systemsettingssimulator/geometry").toByteArray());
37     mp_ui->radioButton_DayMode->setChecked(settings.value("systemsettingssimulator/daymode", true).toBool()); // if nothing is stored, use "true"
38     mp_ui->radioButton_NightMode->setChecked(settings.value("systemsettingssimulator/nightmode", false).toBool()); // if nothing is stored, use "false"
39 }
40
41 SystemSettingsSimulator::~SystemSettingsSimulator()
42 {
43     QSettings settings;
44     settings.setValue("systemsettingssimulator/geometry", saveGeometry());
45     settings.setValue("systemsettingssimulator/daymode", mp_ui->radioButton_DayMode->isChecked());
46     settings.setValue("systemsettingssimulator/nightmode", mp_ui->radioButton_NightMode->isChecked());
47
48     if (0 == mp_dBusDayNightMode)
49     {
50         delete mp_dBusDayNightMode;
51     }
52     delete mp_ui;
53 }
54
55 void SystemSettingsSimulator::on_pushButton_Exit_clicked()
56 {
57     QApplication::exit();
58 }
59
60 void SystemSettingsSimulator::on_radioButton_DayMode_toggled(bool checked)
61 {
62     if (checked)
63     {
64         mp_dBusDayNightMode->setDayNightMode(SystemDayNight::DAYNIGHTMODE_DAY);
65     }
66 }
67
68 void SystemSettingsSimulator::on_radioButton_NightMode_toggled(bool checked)
69 {
70     if (checked)
71     {
72         mp_dBusDayNightMode->setDayNightMode(SystemDayNight::DAYNIGHTMODE_NIGHT);
73     }
74 }