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 #include "afm_user_daemon_proxy.h"
28 extern org::AGL::afm::user *afm_user_daemon_proxy;
30 class ApplicationModel::Private
39 QString get_icon_name(QJsonObject const &i)
41 QString icon = i["id"].toString().split("@").front();
42 if (icon == "hvac" || icon == "poi") {
43 icon = icon.toUpper();
44 } else if (icon == "mediaplayer") {
47 icon[0] = icon[0].toUpper();
53 ApplicationModel::Private::Private()
55 QString apps = afm_user_daemon_proxy->runnables(QStringLiteral(""));
56 QJsonDocument japps = QJsonDocument::fromJson(apps.toUtf8());
57 for (auto const &app : japps.array()) {
58 QJsonObject const &jso = app.toObject();
59 auto const name = jso["name"].toString();
60 auto const id = jso["id"].toString();
61 auto const icon = get_icon_name(jso);
62 this->data.append(AppInfo(icon, name, id));
63 qDebug() << "name:" << name << "icon:" << icon << "id:" << id;
67 ApplicationModel::ApplicationModel(QObject *parent)
68 : QAbstractListModel(parent)
73 ApplicationModel::~ApplicationModel()
78 int ApplicationModel::rowCount(const QModelIndex &parent) const
83 return this->d->data.count();
86 QVariant ApplicationModel::data(const QModelIndex &index, int role) const
93 case Qt::DecorationRole:
94 ret = this->d->data[index.row()].iconPath();
97 ret = this->d->data[index.row()].name();
100 ret = this->d->data[index.row()].id();
109 QHash<int, QByteArray> ApplicationModel::roleNames() const
111 QHash<int, QByteArray> roles;
112 roles[Qt::DecorationRole] = "icon";
113 roles[Qt::DisplayRole] = "name";
114 roles[Qt::UserRole] = "id";