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 // disable apps which don't work with the compositor right now
58 QStringList notShow = {
65 for (auto const &app : japps.array()) {
66 QJsonObject const &jso = app.toObject();
67 auto const name = jso["name"].toString();
68 auto const id = jso["id"].toString();
69 if (notShow.contains(id)) continue;
70 auto const icon = get_icon_name(jso);
71 this->data.append(AppInfo(icon, name, id));
72 qDebug() << "name:" << name << "icon:" << icon << "id:" << id;
76 ApplicationModel::ApplicationModel(QObject *parent)
77 : QAbstractListModel(parent)
82 ApplicationModel::~ApplicationModel()
87 int ApplicationModel::rowCount(const QModelIndex &parent) const
92 return this->d->data.count();
95 QVariant ApplicationModel::data(const QModelIndex &index, int role) const
102 case Qt::DecorationRole:
103 ret = this->d->data[index.row()].iconPath();
105 case Qt::DisplayRole:
106 ret = this->d->data[index.row()].name();
109 ret = this->d->data[index.row()].id();
118 QHash<int, QByteArray> ApplicationModel::roleNames() const
120 QHash<int, QByteArray> roles;
121 roles[Qt::DecorationRole] = "icon";
122 roles[Qt::DisplayRole] = "name";
123 roles[Qt::UserRole] = "id";
127 QString ApplicationModel::id(int i) const
129 return data(index(i), Qt::UserRole).toString();
132 void ApplicationModel::move(int from, int to)
135 if (to < 0 || to > rowCount()) return;
137 if (!beginMoveRows(parent, from, from, parent, to + 1)) {
138 qDebug() << from << to << false;
141 d->data.move(from, to);
143 } else if (from > to) {
144 if (!beginMoveRows(parent, from, from, parent, to)) {
145 qDebug() << from << to << false;
148 d->data.move(from, to);
151 qDebug() << from << to << false;