2 * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "mainwindow.h"
18 #include "ui_mainwindow.h"
20 MainWindow::MainWindow(QWidget *parent) :
22 mp_ui(new Ui::MainWindow),
23 mp_dBusDayNightModeAdaptor(0),
24 mp_dBusStatusBarProxy(0),
26 mp_dBusProximityProxy(0),
27 mp_dBusHomeScreenProxy(0)
32 QDBusConnection dbus = QDBusConnection::sessionBus();
34 // publish dbus day night mode interface
35 mp_dBusDayNightModeAdaptor = new DaynightmodeAdaptor((QObject*)this);
37 dbus.registerService("org.agl.homescreen.simulator");
38 dbus.registerObject("/", this);
40 mp_dBusStatusBarProxy = new org::agl::statusbar("org.agl.homescreen",
42 QDBusConnection::sessionBus(),
44 mp_dBusPopupProxy = new org::agl::popup("org.agl.homescreen",
46 QDBusConnection::sessionBus(),
48 mp_dBusProximityProxy = new org::agl::proximity("org.agl.homescreen",
50 QDBusConnection::sessionBus(),
52 mp_dBusHomeScreenProxy = new org::agl::homescreen("org.agl.homescreen",
54 QDBusConnection::sessionBus(),
58 this->move(settings.value("homescreensimulator/pos").toPoint());
59 mp_ui->radioButton_DayMode->setChecked(settings.value("homescreensimulator/daymode", true).toBool()); // if nothing is stored, use "true"
60 mp_ui->radioButton_NightMode->setChecked(settings.value("homescreensimulator/nightmode", false).toBool()); // if nothing is stored, use "false"
63 MainWindow::~MainWindow()
66 settings.setValue("homescreensimulator/pos", this->pos());
67 settings.setValue("homescreensimulator/daymode", mp_ui->radioButton_DayMode->isChecked());
68 settings.setValue("homescreensimulator/nightmode", mp_ui->radioButton_NightMode->isChecked());
70 delete mp_dBusHomeScreenProxy;
71 delete mp_dBusProximityProxy;
72 delete mp_dBusPopupProxy;
73 delete mp_dBusStatusBarProxy;
75 if (0 == mp_dBusDayNightModeAdaptor)
77 delete mp_dBusDayNightModeAdaptor;
82 void MainWindow::on_radioButton_DayMode_toggled(bool checked)
86 emit(dayNightMode(SystemDayNight::DAYNIGHTMODE_DAY));
90 void MainWindow::on_radioButton_NightMode_toggled(bool checked)
94 emit(dayNightMode(SystemDayNight::DAYNIGHTMODE_NIGHT));
98 void MainWindow::on_pushButton_Update_clicked()
100 QList<int> availablePlaceholders = mp_dBusStatusBarProxy->getAvailablePlaceholders();
101 mp_ui->tableWidget_Status->verticalHeader()->setVisible(false);
102 mp_ui->tableWidget_Status->clear();
103 mp_ui->tableWidget_Status->setRowCount(availablePlaceholders.size());
104 mp_ui->tableWidget_Status->setColumnCount(3);
106 QList<QString> horizontalHeaderLabels;
107 horizontalHeaderLabels.append("Placeholder #");
108 horizontalHeaderLabels.append("Text");
109 horizontalHeaderLabels.append("iconURI");
110 mp_ui->tableWidget_Status->setHorizontalHeaderLabels(horizontalHeaderLabels);
112 // disable trigger for the update
113 mp_ui->tableWidget_Status->blockSignals(true);
115 for (int i = 0; i < availablePlaceholders.size(); ++i)
117 mp_ui->tableWidget_Status->setItem(i, 0, new QTableWidgetItem(QString::number(availablePlaceholders[i])));
118 mp_ui->tableWidget_Status->item(i, 0)->setFlags(Qt::ItemIsSelectable);
119 mp_ui->tableWidget_Status->setItem(i, 1, new QTableWidgetItem(mp_dBusStatusBarProxy->getStatusText(availablePlaceholders[i])));
120 mp_ui->tableWidget_Status->setItem(i, 2, new QTableWidgetItem(mp_dBusStatusBarProxy->getStatusIcon(availablePlaceholders[i])));
123 // enable trigger again
124 mp_ui->tableWidget_Status->blockSignals(false);
127 void MainWindow::on_pushButton_Exit_clicked()
129 QApplication::exit();
132 void MainWindow::on_tableWidget_Status_cellChanged(int row, int column)
137 mp_dBusStatusBarProxy->setStatusText(mp_ui->tableWidget_Status->item(row, 0)->text().toInt(), mp_ui->tableWidget_Status->item(row, 1)->text());
143 mp_dBusStatusBarProxy->setStatusIcon(mp_ui->tableWidget_Status->item(row, 0)->text().toInt(), mp_ui->tableWidget_Status->item(row, 2)->text());
147 void MainWindow::on_pushButton_Send_clicked()
149 mp_dBusPopupProxy->showPopup(0, mp_ui->plainTextEdit_Popup->toPlainText());
152 void MainWindow::on_pushButton_IconExample_clicked()
154 on_pushButton_Update_clicked();
156 // THIS IS JUST AN EXAMPLE!!! It only works, because the alias for the pic is defined in the
157 // Home Screen app resources...
158 mp_ui->tableWidget_Status->setItem(0, 2, new QTableWidgetItem(":/icons/home_day.png"));
161 void MainWindow::on_pushButton_PopupExample_clicked()
163 mp_dBusPopupProxy->showPopup(0, "Hello Popup!\nNice to see you!");
166 void MainWindow::on_pushButton_comboBoxExample_clicked()
169 choices.append("Item1");
170 choices.append("Item2");
171 choices.append("Item3");
172 choices.append("Item4");
173 mp_dBusPopupProxy->showPopupComboBox("Make your choice!", choices);
176 void MainWindow::on_checkBox_ObjectDetected_clicked()
178 mp_dBusProximityProxy->setObjectDetected(Qt::Checked == mp_ui->checkBox_ObjectDetected->checkState());