af144c52e6e78c68d0c8da8dd93fb51b29e3f908
[staging/HomeScreen.git] / HomeScreen / src / statusbarwidget.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 "statusbarwidget.h"
18 #include "ui_statusbarwidget.h"
19
20 StatusBarWidget::StatusBarWidget(QWidget *parent) :
21     QWidget(parent),
22     mp_ui(new Ui::StatusBarWidget),
23     m_dayNightMode(SystemDayNight::DAYNIGHTMODE_DAY), // TODO: read from system
24     mp_dayNightModeProxy(0),
25     mp_statusbarAdaptor(0),
26     mp_statusbarIconURIs(new QMap<int, QString>)
27 {
28     // this has to be adopted to the system setup
29     mp_dayNightModeProxy = new org::agl::daynightmode("org.agl.homescreen.simulator", //"org.agl.systeminfoprovider"
30                                                       "/",
31                                                       QDBusConnection::sessionBus(),
32                                                       0);
33     QObject::connect(mp_dayNightModeProxy, SIGNAL(dayNightMode(int)), this, SLOT(dayNightModeSlot(int)));
34
35     // publish statusbar interface
36     mp_statusbarAdaptor = new StatusbarAdaptor((QObject*)this);
37
38   QDBusConnection dbus = QDBusConnection::sessionBus();
39     dbus.registerObject("/StatusBar", this);
40     dbus.registerService("org.agl.homescreen");
41
42     mp_ui->setupUi(this);
43 }
44
45 StatusBarWidget::~StatusBarWidget()
46 {
47     delete mp_statusbarAdaptor;
48     delete mp_dayNightModeProxy;
49     delete mp_ui;
50 }
51
52 void StatusBarWidget::dayNightModeSlot(int mode)
53 {
54     switch (mode)
55     {
56     case SystemDayNight::DAYNIGHTMODE_DAY:
57         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_DAY;
58         mp_ui->widget->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_stripes_day.png)"));
59         mp_ui->label_1->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(1) + QString("); background-repeat: no-repeat;"));
60         mp_ui->label_2->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(2) + QString("); background-repeat: no-repeat;"));
61         mp_ui->label_3->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(3) + QString("); background-repeat: no-repeat;"));
62         mp_ui->label_4->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(4) + QString("); background-repeat: no-repeat;"));
63         mp_ui->label_5->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(5) + QString("); background-repeat: no-repeat;"));
64         break;
65     case SystemDayNight::DAYNIGHTMODE_NIGHT:
66         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_NIGHT;
67         mp_ui->widget->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_stripes_night.png)"));
68         mp_ui->label_1->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(1) + QString("); background-repeat: no-repeat;"));
69         mp_ui->label_2->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(2) + QString("); background-repeat: no-repeat;"));
70         mp_ui->label_3->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(3) + QString("); background-repeat: no-repeat;"));
71         mp_ui->label_4->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(4) + QString("); background-repeat: no-repeat;"));
72         mp_ui->label_5->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(5) + QString("); background-repeat: no-repeat;"));
73         break;
74     default:
75         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_UNDEFINED;
76     }
77 }
78
79 QList<int> StatusBarWidget::getAvailablePlaceholders()
80 {
81     QList<int> result;
82
83     // for now, all are available
84     result.append(1);
85     result.append(2);
86     result.append(3);
87     result.append(4);
88     result.append(5);
89
90     return result;
91 }
92
93 QString StatusBarWidget::getStatusIcon(int placeholderIndex)
94 {
95     return mp_statusbarIconURIs->value(placeholderIndex);
96 }
97
98 QString StatusBarWidget::getStatusText(int placeholderIndex)
99 {
100     QString result = "";
101
102     switch (placeholderIndex)
103     {
104     case 1:
105         result = mp_ui->label_1->text();
106         break;
107     case 2:
108         result = mp_ui->label_2->text();
109         break;
110     case 3:
111         result = mp_ui->label_3->text();
112         break;
113     case 4:
114         result = mp_ui->label_4->text();
115         break;
116     case 5:
117         result = mp_ui->label_5->text();
118         break;
119     default:
120         break;
121     }
122
123     return result;
124 }
125
126 void StatusBarWidget::setStatusIcon(int placeholderIndex, const QString &iconURI)
127 {
128     mp_statusbarIconURIs->insert(placeholderIndex, iconURI);
129
130     switch (m_dayNightMode)
131     {
132     case SystemDayNight::DAYNIGHTMODE_DAY:
133         switch (placeholderIndex)
134         {
135         case 1:
136             mp_ui->label_1->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
137             break;
138         case 2:
139             mp_ui->label_2->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
140             break;
141         case 3:
142             mp_ui->label_3->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
143             break;
144         case 4:
145             mp_ui->label_4->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
146             break;
147         case 5:
148             mp_ui->label_5->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
149             break;
150         default:
151             break;
152         }
153         break;
154     case SystemDayNight::DAYNIGHTMODE_NIGHT:
155         switch (placeholderIndex)
156         {
157         case 1:
158             mp_ui->label_1->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
159             break;
160         case 2:
161             mp_ui->label_2->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
162             break;
163         case 3:
164             mp_ui->label_3->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
165             break;
166         case 4:
167             mp_ui->label_4->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
168             break;
169         case 5:
170             mp_ui->label_5->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(") + mp_statusbarIconURIs->value(placeholderIndex) + QString("); background-repeat: no-repeat;"));
171             break;
172         default:
173             break;
174         }
175         break;
176     default:
177         break;
178     }
179 }
180
181 void StatusBarWidget::setStatusText(int placeholderIndex, const QString &text)
182 {
183     switch (placeholderIndex)
184     {
185     case 1:
186         mp_ui->label_1->setText(text);
187         break;
188     case 2:
189         mp_ui->label_2->setText(text);
190         break;
191     case 3:
192         mp_ui->label_3->setText(text);
193         break;
194     case 4:
195         mp_ui->label_4->setText(text);
196         break;
197     case 5:
198         mp_ui->label_5->setText(text);
199         break;
200     default:
201         break;
202     }
203 }
204
205