919bea0fe635d6315f7651c5ebcc2a269001c108
[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/daynightmode", SystemDayNight::DAYNIGHTMODE_DAY).toInt()) +
55                           ".ini",
56                           QSettings::IniFormat);
57
58     mp_ui->widget_Popup->setStyleSheet(settings_cs.value(QString("PopupWidget/widget_Popup")).toString());
59     mp_ui->label_Text->setStyleSheet(settings_cs.value(QString("PopupWidget/label_Text")).toString());
60 }
61
62 void PopupWidget::showPopup(int /*type*/, const QString &text)
63 {
64     m_sendComboBoxChoice = false;
65     mp_ui->comboBox->hide();
66     this->show();
67     this->raise();
68     mp_ui->label_Text->setText(text);
69 }
70
71 void PopupWidget::showPopupComboBox(const QString &text, const QStringList &choices)
72 {
73     m_sendComboBoxChoice = true;
74     mp_ui->comboBox->addItems(choices);
75     mp_ui->comboBox->show();
76     this->show();
77     this->raise();
78     mp_ui->label_Text->setText(text);
79 }
80
81 void PopupWidget::on_pushButton_OK_clicked()
82 {
83     if (m_sendComboBoxChoice)
84     {
85         comboBoxResult(mp_ui->comboBox->currentText());
86         m_sendComboBoxChoice = false;
87     }
88     this->close();
89 }