First integration of new HMI design
[staging/HomeScreen.git] / HomeScreen / src2 / statusbarserver.cpp
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "statusbarserver.h"
19 #include "statusbar_adaptor.h"
20
21 class StatusBarServer::Private
22 {
23 public:
24     Private(StatusBarServer *parent);
25     QString texts[SupportedCount];
26     QString icons[SupportedCount];
27     StatusbarAdaptor adaptor;
28 };
29
30 StatusBarServer::Private::Private(StatusBarServer *parent)
31     : adaptor(parent)
32 {
33     icons[0] = QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png");
34     icons[1] = QStringLiteral("qrc:/images/Status/HMI_Status_Bluetooth_Inactive-01.png");
35     icons[2] = QStringLiteral("qrc:/images/Status/HMI_Status_Signal_NoBars-01.png");
36 }
37
38 StatusBarServer::StatusBarServer(QObject *parent)
39     : QObject(parent)
40     , d(new Private(this))
41 {
42 }
43
44 StatusBarServer::~StatusBarServer()
45 {
46     delete d;
47 }
48
49 QList<int> StatusBarServer::getAvailablePlaceholders() const
50 {
51     QList<int> ret;
52     for (int i = 0; i < SupportedCount; ++i) {
53         ret.append(i);
54     }
55     return ret;
56 }
57
58 QString StatusBarServer::getStatusIcon(int placeholderIndex) const
59 {
60     QString ret;
61     if (-1 < placeholderIndex && placeholderIndex < SupportedCount)
62         ret = d->icons[placeholderIndex];
63     return ret;
64 }
65
66 void StatusBarServer::setStatusIcon(int placeholderIndex, const QString &icon)
67 {
68     if (-1 < placeholderIndex && placeholderIndex < SupportedCount) {
69         if (d->icons[placeholderIndex] == icon) return;
70         d->icons[placeholderIndex] = icon;
71         emit statusIconChanged(placeholderIndex, icon);
72     }
73 }
74
75 QString StatusBarServer::getStatusText(int placeholderIndex) const
76 {
77     QString ret;
78     if (-1 < placeholderIndex && placeholderIndex < SupportedCount) {
79         ret = d->texts[placeholderIndex];
80     }
81     return ret;
82 }
83
84 void StatusBarServer::setStatusText(int placeholderIndex, const QString &text)
85 {
86     if (-1 < placeholderIndex && placeholderIndex < SupportedCount) {
87         if (d->texts[placeholderIndex] == text) return;
88         d->texts[placeholderIndex] = text;
89         emit statusTextChanged(placeholderIndex, text);
90     }
91 }