2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
4 * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include "nativeappmodel.h"
20 #include <QtDBus/QDBusInterface>
21 #include <QtDBus/QDBusReply>
22 #include "afm_user_daemon_proxy.h"
23 #include "httpclient.h"
25 #include "hmi-debug.h"
27 extern org::AGL::afm::user* afm_user_daemon_proxy;
29 class NativeAppModel::Private {
38 NativeAppModel::Private::Private() {
42 void NativeAppModel::Private::getApps() {
43 QString apps = afm_user_daemon_proxy->runnables(QStringLiteral(""));
44 QJsonDocument japps = QJsonDocument::fromJson(apps.toUtf8());
45 for (auto const& app : japps.array()) {
46 QJsonObject const& jso = app.toObject();
51 this->data.append(appinfo);
55 NativeAppModel::NativeAppModel(QObject* parent)
56 : QAbstractListModel(parent), d(new Private()) {
57 connect(afm_user_daemon_proxy, &org::AGL::afm::user::changed, this,
58 &NativeAppModel::appChanged);
61 NativeAppModel::~NativeAppModel() {
65 int NativeAppModel::rowCount(const QModelIndex& parent) const {
69 return this->d->data.count();
72 QVariant NativeAppModel::data(const QModelIndex& index, int role) const {
79 ret = this->d->data[index.row()].iconPath();
82 ret = this->d->data[index.row()].name();
85 ret = this->d->data[index.row()].id();
88 ret = this->d->data[index.row()].version();
91 ret = this->d->data[index.row()].description();
94 ret = this->d->data[index.row()].shortname();
97 ret = this->d->data[index.row()].author();
106 QHash<int, QByteArray> NativeAppModel::roleNames() const {
107 QHash<int, QByteArray> roles;
108 roles[IconRole] = "icon";
109 roles[NameRole] = "name";
110 roles[IdRole] = "id";
111 roles[VersionRole] = "version";
112 roles[DescriptionRole] = "description";
113 roles[ShortNameRole] = "shortname";
114 roles[AuthorRole] = "author";
118 QString NativeAppModel::id(int i) const {
119 return data(index(i), IdRole).toString();
122 QString NativeAppModel::name(int i) const {
123 return data(index(i), NameRole).toString();
126 void NativeAppModel::appChanged(const QString& info) {
130 int NativeAppModel::launch(const QString& application) {
132 HMI_DEBUG("launch", "ApplicationLauncher launch %s.",
133 application.toStdString().c_str());
135 result = afm_user_daemon_proxy->start(application).value().toInt();
136 HMI_DEBUG("launch", "ApplicationLauncher pid: %d.", result);
141 void NativeAppModel::uninstall(int index) {
142 const QString& id = this->d->data[index].id();
143 QString result = afm_user_daemon_proxy->uninstall(id);
144 if (result == "null") {
145 beginRemoveRows(QModelIndex(), index, index);
146 this->d->data.removeAt(index);
151 void NativeAppModel::refresh() {
153 this->d->data.clear();
156 emit applistChanged(this->d->data);