2 * Copyright (C) 2016 The Qt Company Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "statusbarmodel.h"
18 #include "statusbarserver.h"
20 #include <QtDBus/QDBusConnection>
22 class StatusBarModel::Private
25 Private(StatusBarModel *parent);
30 StatusBarServer server;
31 QString iconList[StatusBarServer::SupportedCount];
34 StatusBarModel::Private::Private(StatusBarModel *parent)
37 QDBusConnection dbus = QDBusConnection::sessionBus();
38 dbus.registerObject("/StatusBar", &server);
39 dbus.registerService("org.agl.homescreen");
40 connect(&server, &StatusBarServer::statusIconChanged, [&](int placeholderIndex, const QString &icon) {
41 if (placeholderIndex < 0 || StatusBarServer::SupportedCount <= placeholderIndex) return;
42 if (iconList[placeholderIndex] == icon) return;
43 iconList[placeholderIndex] = icon;
44 emit q->dataChanged(q->index(placeholderIndex), q->index(placeholderIndex));
46 for (int i = 0; i < StatusBarServer::SupportedCount; i++) {
47 iconList[i] = server.getStatusIcon(i);
51 StatusBarModel::StatusBarModel(QObject *parent)
52 : QAbstractListModel(parent)
53 , d(new Private(this))
57 StatusBarModel::~StatusBarModel()
62 int StatusBarModel::rowCount(const QModelIndex &parent) const
67 return StatusBarServer::SupportedCount;
70 QVariant StatusBarModel::data(const QModelIndex &index, int role) const
78 ret = d->iconList[index.row()];
87 QHash<int, QByteArray> StatusBarModel::roleNames() const
89 QHash<int, QByteArray> roles;
90 roles[Qt::DisplayRole] = "icon";