2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
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 "applicationmodel.h"
21 #include <QtCore/QDebug>
23 #include <QtDBus/QDBusInterface>
24 #include <QtDBus/QDBusReply>
26 class ApplicationModel::Private
29 Private(ApplicationModel *parent);
39 // This is a disgrace, shouldn't we be having a defined way to know which icon (if it is not given by the getAvailableApps() reply)?
40 QString get_icon_name(AppInfo const &i)
42 QString icon = i.iconPath().isEmpty() ? i.id().split("@").front() : i.iconPath();
43 if (icon == "hvac" || icon == "poi") {
44 icon = icon.toUpper();
45 } else if (icon == "mediaplayer") {
48 icon[0] = icon[0].toUpper();
54 ApplicationModel::Private::Private(ApplicationModel *parent)
56 , proxy(QStringLiteral("org.agl.homescreenappframeworkbinder"), QStringLiteral("/AppFramework"), QStringLiteral("org.agl.appframework"), QDBusConnection::sessionBus())
58 QDBusReply<QList<AppInfo>> reply = proxy.call("getAvailableApps");
59 if (reply.isValid()) {
60 // FIXME: Is the order from dbus the one we want to use?!
61 for (auto const &i: reply.value()) {
62 auto const name = i.name().split(" ").front().toUpper();
63 auto const icon = get_icon_name(i);
64 data.append(AppInfo(icon, name, i.id()));
67 qDebug() << "getAvailableApps() reply is INVALID!";
71 ApplicationModel::ApplicationModel(QObject *parent)
72 : QAbstractListModel(parent)
73 , d(new Private(this))
77 ApplicationModel::~ApplicationModel()
82 int ApplicationModel::rowCount(const QModelIndex &parent) const
87 return d->data.count();
90 QVariant ApplicationModel::data(const QModelIndex &index, int role) const
97 case Qt::DecorationRole:
98 ret = d->data[index.row()].iconPath();
100 case Qt::DisplayRole:
101 ret = d->data[index.row()].name();
104 ret = d->data[index.row()].id();
113 QHash<int, QByteArray> ApplicationModel::roleNames() const
115 QHash<int, QByteArray> roles;
116 roles[Qt::DecorationRole] = "icon";
117 roles[Qt::DisplayRole] = "name";
118 roles[Qt::UserRole] = "id";