6f7d9cb59b7b98725df52c800b96ef984207a205
[staging/HomeScreen.git] / HomeScreen / src / popupwidget.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 "popupwidget.h"
18 #include "ui_popupwidget.h"
19 #include <include/daynightmode.hpp>
20
21 PopupWidget::PopupWidget(QWidget *parent) :
22     QWidget(parent),
23     mp_ui(new Ui::PopupWidget),
24     mp_popupAdaptor(0),
25     m_sendComboBoxChoice(false)
26 {
27     // publish dbus popup interface
28     mp_popupAdaptor = new PopupAdaptor((QObject*)this);
29     QDBusConnection dbus = QDBusConnection::sessionBus();
30     dbus.registerObject("/Popup", this);
31     dbus.registerService("org.agl.homescreen");
32
33     // no window decoration
34     setWindowFlags(Qt::FramelessWindowHint);
35
36     mp_ui->setupUi(this);
37
38     this->close();
39 }
40
41 PopupWidget::~PopupWidget()
42 {
43     delete mp_popupAdaptor;
44     delete mp_ui;
45 }
46
47 void PopupWidget::updateColorScheme()
48 {
49     QSettings settings;
50     QSettings settings_cs(QApplication::applicationDirPath() +
51                           "/colorschemes/" +
52                           settings.value("systemsettings/colorscheme", "default").toString() +
53                           "/" +
54                           QString::number(settings.value("systemsettings/proximityobjectdetected", false).toBool()) +
55                           "/" +
56                           QString::number(settings.value("systemsettings/daynightmode", SystemDayNight::DAYNIGHTMODE_DAY).toInt()) +
57                           ".ini",
58                           QSettings::IniFormat);
59
60     mp_ui->widget_popup->setStyleSheet(settings_cs.value(QString("PopupWidget/widget_popup_css")).toString());
61     mp_ui->label_text->setStyleSheet(settings_cs.value(QString("PopupWidget/label_text_css")).toString());
62 }
63
64 void PopupWidget::showPopup(int /*type*/, const QString &text)
65 {
66     m_sendComboBoxChoice = false;
67     mp_ui->comboBox_choice->hide();
68     this->show();
69     this->raise();
70     mp_ui->label_text->setText(text);
71 }
72
73 void PopupWidget::showPopupComboBox(const QString &text, const QStringList &choices)
74 {
75     mp_ui->comboBox_choice->clear();
76     m_sendComboBoxChoice = true;
77     mp_ui->comboBox_choice->addItems(choices);
78     mp_ui->comboBox_choice->show();
79     this->show();
80     this->raise();
81     mp_ui->label_text->setText(text);
82 }
83
84 void PopupWidget::on_pushButton_OK_clicked()
85 {
86     if (m_sendComboBoxChoice)
87     {
88         comboBoxResult(mp_ui->comboBox_choice->currentText());
89         m_sendComboBoxChoice = false;
90     }
91     this->close();
92 }