2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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 "shortcutappmodel.h"
18 #include "hmi-debug.h"
19 #include <QJsonDocument>
20 #include <QJsonObject>
21 #include <QJsonParseError>
23 #define SHORTCUTKEY_PATH "/var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json"
25 class ShortcutAppModel::Private
30 QList<RegisterApp> data;
33 ShortcutAppModel::Private::Private()
38 ShortcutAppModel::ShortcutAppModel(QObject *parent)
39 : QAbstractListModel(parent)
46 ShortcutAppModel::~ShortcutAppModel()
50 void ShortcutAppModel::init()
53 for(int i = 0; i < 3; i++) {
54 temp.id = "video@0.1";
56 temp.icon = getIconPath(temp.id);
57 if (temp.icon == "") {
66 int ShortcutAppModel::rowCount(const QModelIndex &parent) const
71 return this->d->data.count();
74 QVariant ShortcutAppModel::data(const QModelIndex &index, int role) const
81 case Qt::DecorationRole:
82 ret = this->d->data[index.row()].icon;
85 ret = this->d->data[index.row()].name;
88 ret = this->d->data[index.row()].id;
97 QHash<int, QByteArray> ShortcutAppModel::roleNames() const
99 QHash<int, QByteArray> roles;
100 roles[Qt::DecorationRole] = "icon";
101 roles[Qt::DisplayRole] = "name";
102 roles[Qt::UserRole] = "id";
106 void ShortcutAppModel::shortcutUpdate(QStringList shortcut_list)
108 HMI_DEBUG("Launcher", "ShortcutAppModel::shortcutUpdate id1=%s", shortcut_list.at(1).toStdString().c_str());
110 for(int i = 0; i < d->data.size(); i++) {
111 temp.id = shortcut_list.at(2 * i);
112 temp.name = shortcut_list.at(2 * i + 1);
113 temp.icon = getIconPath(temp.id);
114 if (temp.icon == "") {
117 temp.isBlank = false;
119 d->data.replace(i, temp);
121 emit updateShortcut();
124 QString ShortcutAppModel::getId(int index) const
126 return d->data.at(index).id;
129 QString ShortcutAppModel::getName(int index) const
131 return d->data.at(index).name;
134 QString ShortcutAppModel::getIcon(int index) const
136 return d->data.at(index).icon;
139 bool ShortcutAppModel::isBlank(int index) const
141 return d->data.at(index).isBlank;
144 QString ShortcutAppModel::getIconPath(QString id)
146 QString name = id.section('@', 0, 0);
147 QString version = id.section('@', 1, 1);
148 QString boardIconPath = "/var/local/lib/afm/applications/" + name + "/" + version + "/icon.svg";
149 QString appIconPath = ":/images/TopShortcut/" + name + ".svg";
150 if (QFile::exists(boardIconPath)) {
151 return "file://" + boardIconPath;
152 } else if (QFile::exists(appIconPath)) {
153 return appIconPath.section('/', 1, -1);
158 void ShortcutAppModel::setAppQueuePoint(QString id, QString name)
161 app.icon = getIconPath(app.id);
162 if (app.icon == "") {