2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2017, 2018 TOYOTA MOTOR CORPORATION
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "statusbarmodel.h"
19 #include "statusbarserver.h"
21 #include <QtDBus/QDBusConnection>
23 class StatusBarModel::Private
26 Private(StatusBarModel *parent);
31 StatusBarServer server;
32 QString iconList[StatusBarServer::SupportedCount];
35 StatusBarModel::Private::Private(StatusBarModel *parent)
38 QDBusConnection dbus = QDBusConnection::sessionBus();
39 dbus.registerObject("/StatusBar", &server);
40 dbus.registerService("org.agl.homescreen");
41 connect(&server, &StatusBarServer::statusIconChanged, [&](int placeholderIndex, const QString &icon) {
42 if (placeholderIndex < 0 || StatusBarServer::SupportedCount <= placeholderIndex) return;
43 if (iconList[placeholderIndex] == icon) return;
44 iconList[placeholderIndex] = icon;
45 emit q->dataChanged(q->index(placeholderIndex), q->index(placeholderIndex));
47 for (int i = 0; i < StatusBarServer::SupportedCount; i++) {
48 iconList[i] = server.getStatusIcon(i);
52 StatusBarModel::StatusBarModel(QObject *parent)
53 : QAbstractListModel(parent)
54 , d(new Private(this))
58 StatusBarModel::~StatusBarModel()
63 int StatusBarModel::rowCount(const QModelIndex &parent) const
68 // Delete bluetooth because use agl-service-bluetooth.
69 return StatusBarServer::SupportedCount - 1;
72 QVariant StatusBarModel::data(const QModelIndex &index, int role) const
80 if (index.row() == 0){
81 ret = d->iconList[StatusBarServer::StatusWifi];
82 }else if (index.row() == 1){
83 ret = d->iconList[StatusBarServer::StatusCellular];
93 QHash<int, QByteArray> StatusBarModel::roleNames() const
95 QHash<int, QByteArray> roles;
96 roles[Qt::DisplayRole] = "icon";