First version
[staging/HomeScreen.git] / 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_daynightmodeAdaptor(0),
25     mp_statusbarAdaptor(0),
26     m_secondsTimerId(-1)
27 {
28     // publish dbus day night mode interface
29     mp_daynightmodeAdaptor = new DaynightmodeAdaptor((QObject*)this);
30     // publish statusbar interface
31     mp_statusbarAdaptor = new StatusbarAdaptor((QObject*)this);
32
33     QDBusConnection dbus = QDBusConnection::sessionBus();
34     dbus.registerObject("/StatusBarWidget", this);
35     dbus.registerService("org.agl.mainwindow");
36
37     mp_ui->setupUi(this);
38
39     // callback every second
40     m_secondsTimerId = startTimer(1000);
41 }
42
43 StatusBarWidget::~StatusBarWidget()
44 {
45     delete mp_statusbarAdaptor;
46     delete mp_daynightmodeAdaptor;
47     delete mp_ui;
48 }
49
50 void StatusBarWidget::setDayNightMode(int mode)
51 {
52     switch (mode)
53     {
54     case SystemDayNight::DAYNIGHTMODE_DAY:
55         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_DAY;
56         mp_ui->widget->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_stripes_day.png)"));
57         mp_ui->label_1->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(:/images/transparency.png);"));
58         mp_ui->label_2->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(:/images/transparency.png);"));
59         mp_ui->label_3->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(:/images/transparency.png);"));
60         mp_ui->label_4_Time->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(:/images/transparency.png);"));
61         mp_ui->label_5->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(:/images/transparency.png);"));
62         mp_ui->label_6->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(:/images/transparency.png);"));
63         mp_ui->label_7->setStyleSheet(QString("color: rgb(238, 238, 238); background-image: url(:/images/transparency.png);"));
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(:/images/transparency.png);"));
69         mp_ui->label_2->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(:/images/transparency.png);"));
70         mp_ui->label_3->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(:/images/transparency.png);"));
71         mp_ui->label_4_Time->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(:/images/transparency.png);"));
72         mp_ui->label_5->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(:/images/transparency.png);"));
73         mp_ui->label_6->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(:/images/transparency.png);"));
74         mp_ui->label_7->setStyleSheet(QString("color: rgb(177, 177, 177); background-image: url(:/images/transparency.png);"));
75         break;
76     default:
77         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_UNDEFINED;
78     }
79 }
80
81 void StatusBarWidget::setStatus(int index, const QString &text)
82 {
83     switch (index)
84     {
85     case 1:
86         mp_ui->label_1->setText(text);
87         break;
88     case 2:
89         mp_ui->label_2->setText(text);
90         break;
91     case 3:
92         mp_ui->label_3->setText(text);
93         break;
94     case 4:
95         qDebug("reserved for the time status");
96         break;
97     case 5:
98         mp_ui->label_5->setText(text);
99         break;
100     case 6:
101         mp_ui->label_6->setText(text);
102         break;
103     case 7:
104         mp_ui->label_7->setText(text);
105         break;
106     default:
107         break;
108     }
109 }
110
111 void StatusBarWidget::timerEvent(QTimerEvent *e)
112 {
113     if (e->timerId() == m_secondsTimerId)
114     {
115         mp_ui->label_4_Time->setText(QDateTime::currentDateTime().toString("hh:mm"));
116     }
117 }
118