diff options
author | wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com> | 2019-05-30 11:19:55 +0800 |
---|---|---|
committer | wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com> | 2019-05-30 11:19:55 +0800 |
commit | b17dc9b509243d72cb6448dcf5be5b8f91c52502 (patch) | |
tree | 37d837ee3a8b345e299c392deda9f7046842f356 /launcher/src | |
parent | 60b3b65ebaf8e0ef209df0abd6f25a1e385d5733 (diff) |
update
Change-Id: Ic603b7cb155254f9b4166cf9902bbc7b519798da
Diffstat (limited to 'launcher/src')
-rw-r--r-- | launcher/src/applicationmodel.cpp | 114 | ||||
-rw-r--r-- | launcher/src/applicationmodel.h | 5 | ||||
-rw-r--r-- | launcher/src/homescreenhandler.cpp | 221 | ||||
-rw-r--r-- | launcher/src/homescreenhandler.h | 62 | ||||
-rw-r--r-- | launcher/src/main.cpp | 36 | ||||
-rw-r--r-- | launcher/src/shortcutappmodel.cpp | 169 | ||||
-rw-r--r-- | launcher/src/shortcutappmodel.h | 53 |
7 files changed, 61 insertions, 599 deletions
diff --git a/launcher/src/applicationmodel.cpp b/launcher/src/applicationmodel.cpp index 261e43e..31e80d9 100644 --- a/launcher/src/applicationmodel.cpp +++ b/launcher/src/applicationmodel.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2016 The Qt Company Ltd. * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH - * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION + * Copyright (c) 2018 TOYOTA MOTOR CORPORATION * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,11 +32,9 @@ class ApplicationModel::Private { public: Private(); + void loadAppInfo(); - void addApp(QString icon, QString name, QString id); - void removeApp(QString id); - - QList<AppInfo> data; + QList<AppInfo> data, data_temp; }; namespace { @@ -44,8 +42,8 @@ namespace { { QString icon = i["name"].toString().toLower(); - if ( !QFile::exists(QString(":/images/%1_active.svg").arg(icon)) || - !QFile::exists(QString(":/images/%1_inactive.svg").arg(icon)) ) + if ( !QFile::exists(QString(":/images/%1_active.png").arg(icon)) || + !QFile::exists(QString(":/images/%1_inactive.png").arg(icon)) ) { icon = "blank"; } @@ -55,40 +53,47 @@ namespace { ApplicationModel::Private::Private() { -} - -void ApplicationModel::Private::addApp(QString icon, QString name, QString id) -{ - HMI_DEBUG("addApp","name: %s icon: %s id: %s.", name.toStdString().c_str(), icon.toStdString().c_str(), id.toStdString().c_str()); - for(int i = 0; i < this->data.size(); ++i) { - if(this->data[i].id() == id) - return; + loadAppInfo(); + int times = 22 / this->data_temp.size(); + if(22 % this->data_temp.size() > 0) { + ++times; } - - QString _icon = name.toLower(); - if ( !QFile::exists(QString(":/images/%1_active.svg").arg(_icon)) || - !QFile::exists(QString(":/images/%1_inactive.svg").arg(_icon)) ) - { - _icon = "blank"; - } - - int pos = 0; - for (pos = 0; pos < this->data.size(); ++pos) { - if (QString::compare(this->data.at(pos).name(), name, Qt::CaseInsensitive) > 0) - break; + while(times > 0) { + for(auto i = 0; i < this->data_temp.size(); ++i) { + this->data.append(this->data_temp.at(i)); + } + --times; } - this->data.insert(pos, AppInfo(_icon, name, id)); } -void ApplicationModel::Private::removeApp(QString id) +void ApplicationModel::Private::loadAppInfo() { - HMI_DEBUG("removeApp","id: %s.",id.toStdString().c_str()); - for (int i = 0; i < this->data.size(); ++i) { - if (this->data.at(i).id() == id) { - this->data.removeAt(i); - break; - } + QString apps = afm_user_daemon_proxy->runnables(QStringLiteral("")); + QJsonDocument japps = QJsonDocument::fromJson(apps.toUtf8()); + int appCount = 0; + int tachometerIndex = 0; + for (auto const &app : japps.array()) { + QJsonObject const &jso = app.toObject(); + auto const name = jso["name"].toString(); + auto const id = jso["id"].toString(); + auto const icon = get_icon_name(jso); + + // Hide HomeScreen icon itself + if (name != "launcher" && + name != "homescreen" && + name != "HomeScreen" && + !name.contains("OnScreen", Qt::CaseInsensitive)) { + this->data_temp.append(AppInfo(icon, name, id)); + } + if (name == "tachometer") { + HMI_DEBUG("launcher", "tachometer index:%d", tachometerIndex); + tachometerIndex = appCount - 1; + } + appCount++; + + HMI_DEBUG("launcher","name: %s icon: %s id: %s.", name.toStdString().c_str(), icon.toStdString().c_str(), id.toStdString().c_str()); } + this->data_temp.swap(tachometerIndex, 4); } ApplicationModel::ApplicationModel(QObject *parent) @@ -147,12 +152,6 @@ QString ApplicationModel::id(int i) const return data(index(i), Qt::UserRole).toString(); } -QString ApplicationModel::appid(int i) const -{ - QString id = data(index(i), Qt::UserRole).toString(); - return id.split("@")[0]; -} - QString ApplicationModel::name(int i) const { return data(index(i), Qt::DisplayRole).toString(); @@ -180,36 +179,3 @@ void ApplicationModel::move(int from, int to) HMI_NOTICE("launcher","from : %d, to : %d. false.", from, to); } } - -void ApplicationModel::updateApplist(QStringList info) -{ - QString icon = info.at(0); - QString name = info.at(1); - QString id = info.at(2); - - beginResetModel(); - if(icon == "") { // uninstall - d->removeApp(id); - } - else { - // new app - d->addApp(icon, name, id); - } - endResetModel(); -} - -void ApplicationModel::initAppList(QString data) -{ - HMI_DEBUG("launcher","init application list."); - beginResetModel(); - QJsonDocument japps = QJsonDocument::fromJson(data.toUtf8()); - for (auto const &app : japps.array()) { - QJsonObject const &jso = app.toObject(); - auto const name = jso["name"].toString(); - auto const id = jso["id"].toString(); - auto const icon = get_icon_name(jso); - - d->addApp(icon, name, id); - } - endResetModel(); -} diff --git a/launcher/src/applicationmodel.h b/launcher/src/applicationmodel.h index 780e575..8398b62 100644 --- a/launcher/src/applicationmodel.h +++ b/launcher/src/applicationmodel.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2016 The Qt Company Ltd. - * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION + * Copyright (c) 2018 TOYOTA MOTOR CORPORATION * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,12 +31,9 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QHash<int, QByteArray> roleNames() const override; - Q_INVOKABLE QString appid(int index) const; Q_INVOKABLE QString id(int index) const; Q_INVOKABLE QString name(int index) const; Q_INVOKABLE void move(int from, int to); - Q_INVOKABLE void initAppList(QString data); - Q_INVOKABLE void updateApplist(QStringList info); private: class Private; diff --git a/launcher/src/homescreenhandler.cpp b/launcher/src/homescreenhandler.cpp deleted file mode 100644 index 2da71c8..0000000 --- a/launcher/src/homescreenhandler.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2017 TOYOTA MOTOR CORPORATION - * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <QFileInfo> -#include "homescreenhandler.h" -#include <functional> -#include <QProcess> -#include <dirent.h> -#include <stdio.h> -#include "hmi-debug.h" -#include "afm_user_daemon_proxy.h" - -extern org::AGL::afm::user *afm_user_daemon_proxy; - -#define BUF_SIZE 1024 -void* HomescreenHandler::myThis = 0; - -HomescreenHandler::HomescreenHandler(QObject *parent) : - QObject(parent), - mp_qhs(NULL) -{ -} - -HomescreenHandler::~HomescreenHandler() -{ - if (mp_qhs != NULL) { - delete mp_qhs; - } -} - -void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm, QString myname) -{ - myThis = this; - mp_qwm = qwm; - m_myname = myname; - - mp_qhs = new QLibHomeScreen(); - mp_qhs->init(port, token); - mp_qhs->registerCallback(nullptr, HomescreenHandler::onRep_static); - - mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowWindow,[this](json_object *object){ - HMI_DEBUG("Launcher","Surface launcher got Event_ShowWindow\n"); - mp_qwm->activateWindow(m_myname); - }); - - mp_qhs->set_event_handler(QLibHomeScreen::Event_AppListChanged,[this](json_object *object){ - HMI_DEBUG("Launcher","laucher: appListChanged [%s]\n", json_object_to_json_string(object)); - - struct json_object *obj_param, *obj_oper, *obj_data; - if(json_object_object_get_ex(object, "parameter", &obj_param) - && json_object_object_get_ex(obj_param, "operation", &obj_oper) - && json_object_object_get_ex(obj_param, "data", &obj_data)) { - QString oper = json_object_get_string(obj_oper); - if(oper == "uninstall") { - /* { "application_id": "launcher", - * "type": "application-list-changed", - * "parameter":{ - * "operation": "uninstall", - * "data": "onstestapp@0.1" - * } - * } */ - QString id = json_object_get_string(obj_data); - QStringList info; - // icon, name, id - info << "" << "" << id; - emit appListUpdate(info); - } - else if(oper == "install") { - /* { "application_id": "launcher", - * "type": "application-list-changed", - * "parameter": { - * "operation": "install", - * "data": { - * "description":"This is a demo onstestapp application", - * "name": "onstestapp", - * "shortname": "", - * "id": "onstestapp@0.1", - * "version": "0.1", - * "author": "Qt", - * "author-email": "", - * "width": "", - * "height": "", - * "icon": "\/var\/local\/lib\/afm\/applications\/onstestapp\/0.1\/icon.svg", - * "http-port": 31022 - * } - * } - * } */ - struct json_object *obj_icon, *obj_name, *obj_id; - if(json_object_object_get_ex(obj_data, "icon", &obj_icon) - && json_object_object_get_ex(obj_data, "name", &obj_name) - && json_object_object_get_ex(obj_data, "id", &obj_id)) { - QString icon = json_object_get_string(obj_icon); - QString name = json_object_get_string(obj_name); - QString id = json_object_get_string(obj_id); - QStringList info; - // icon, name, id - info << icon << name << id; - emit appListUpdate(info); - } - } - else { - HMI_ERROR("Launcher","error operation.\n"); - } - } - }); - - mp_qhs->set_event_handler(QLibHomeScreen::Event_UpdateShortcut,[this](json_object *object){ - HMI_DEBUG("Launcher","Surface launcher got Event_UpdateShortcut\n"); - json_object *obj_p = json_object_object_get(object, "parameter"); - json_object *obj_array = json_object_object_get(obj_p, "shortcut"); - QStringList shortcut_list; - for(int i = 0; i < 3; i++) - { - shortcut_list << QString(QLatin1String(json_object_get_string(json_object_object_get(json_object_array_get_idx(obj_array, i), "shortcut_id")))); - shortcut_list << QString(QLatin1String(json_object_get_string(json_object_object_get(json_object_array_get_idx(obj_array, i), "shortcut_name")))); - } - HMI_DEBUG("Launcher","SEvent_UpdateShortcut id1 = %s", shortcut_list.at(2).toStdString().c_str()); - emit updateShortcutList(shortcut_list); - }); -} - -void HomescreenHandler::tapShortcut(QString application_id) -{ - HMI_DEBUG("Launcher","tapShortcut %s", application_id.toStdString().c_str()); - struct json_object* j_json = json_object_new_object(); - struct json_object* value; - value = json_object_new_string("normal.full"); - json_object_object_add(j_json, "area", value); - - mp_qhs->showWindow(application_id.toStdString().c_str(), j_json); -} - -void HomescreenHandler::onRep_static(struct json_object* reply_contents) -{ - static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents); -} - -void HomescreenHandler::onRep(struct json_object* reply_contents) -{ - HMI_DEBUG("launcher","HomeScreen onReply %s", json_object_to_json_string(reply_contents)); - struct json_object *obj_res, *obj_verb; - if(json_object_object_get_ex(reply_contents, "response", &obj_res) - && json_object_object_get_ex(obj_res, "verb", &obj_verb) - && !strcasecmp("getRunnables", json_object_get_string(obj_verb))) { - struct json_object *obj_data; - if(json_object_object_get_ex(obj_res, "data", &obj_data)) { - HMI_DEBUG("launcher","HomescreenHandler emit initAppList"); - QString data = json_object_to_json_string(obj_data); - emit initAppList(data); - } - } -} - -void HomescreenHandler::hideWindow(QString application_id) -{ - mp_qhs->hideWindow(application_id.section('@', 0, 0).toStdString().c_str()); -} - -void HomescreenHandler::registerShortcut(QString shortcut_id, QString shortcut_name, QString position) -{ -// struct json_object* j_obj = json_object_new_object(); -// struct json_object* val_id = json_object_new_string(shortcut_id.toStdString().c_str()); -// struct json_object* val_name = json_object_new_string(shortcut_name.toStdString().c_str()); -// struct json_object* val_position = json_object_new_string(position.toStdString().c_str()); -// json_object_object_add(j_obj, "shortcut_id", val_id); -// json_object_object_add(j_obj, "shortcut_name", val_name); -// json_object_object_add(j_obj, "position", val_position); - - mp_qhs->registerShortcut(shortcut_id, shortcut_name, position); -} - -int HomescreenHandler::uninstallApplication(QString application_id) -{ - int result = -1; - HMI_DEBUG("launcher","Application uninstall %s.", application_id.toStdString().c_str()); - - result = afm_user_daemon_proxy->uninstall(application_id).value().toInt(); - HMI_DEBUG("launcher","ApplicationUninstall pid: %d.", result); - -// QProcess *process = new QProcess(); -// QString command = "/usr/bin/pkill " + application_id.section('@', 0, 0); -// HMI_DEBUG("launcher", "command is %s", command.toStdString().c_str()); -// process->start(command); - - return result; -} - -void HomescreenHandler::sendAppToMeter(QString application_id) -{ - HMI_DEBUG("Launcher","sendAppToMeter %s", application_id.toStdString().c_str()); - struct json_object* j_json = json_object_new_object(); - struct json_object* value; - value = json_object_new_string("master.split.sub"); - json_object_object_add(j_json, "area", value); - - mp_qhs->showWindow(application_id.section('@', 0, 0).toStdString().c_str(), j_json); -} - -void HomescreenHandler::getRunnables(void) -{ - mp_qhs->getRunnables(); -} - -void HomescreenHandler::setQuickWindow(QQuickWindow *qw) -{ - mp_qhs->setQuickWindow(qw); -} diff --git a/launcher/src/homescreenhandler.h b/launcher/src/homescreenhandler.h deleted file mode 100644 index e612331..0000000 --- a/launcher/src/homescreenhandler.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2017 TOYOTA MOTOR CORPORATION - * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HOMESCREENHANDLER_H -#define HOMESCREENHANDLER_H - -#include <QObject> -#include <QQuickWindow> -#include <qlibhomescreen.h> -#include <string> -#include <qlibwindowmanager.h> - -using namespace std; - -class HomescreenHandler : public QObject -{ - Q_OBJECT -public: - explicit HomescreenHandler(QObject *parent = 0); - ~HomescreenHandler(); - - void init(int port, const char* token, QLibWindowmanager *qwm, QString myname); - - Q_INVOKABLE void tapShortcut(QString application_id); - Q_INVOKABLE void getRunnables(void); - Q_INVOKABLE void hideWindow(QString application_id); - Q_INVOKABLE void registerShortcut(QString shortcut_id, QString shortcut_name, QString position); - Q_INVOKABLE int uninstallApplication(QString application_id); - Q_INVOKABLE void sendAppToMeter(QString application_id); - - void onRep(struct json_object* reply_contents); - - static void* myThis; - static void onRep_static(struct json_object* reply_contents); - void setQuickWindow(QQuickWindow *qw); - -signals: - void initAppList(QString data); - void appListUpdate(QStringList info); - void updateShortcutList(QStringList shortcut_list); - -private: - QLibHomeScreen *mp_qhs; - QLibWindowmanager *mp_qwm; - QString m_myname; -}; - -#endif // HOMESCREENHANDLER_H diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index 1d324b2..5fed90a 100644 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -29,8 +29,7 @@ #include "applicationmodel.h" #include "appinfo.h" #include "afm_user_daemon_proxy.h" -#include "homescreenhandler.h" -#include "shortcutappmodel.h" +#include "qlibhomescreen.h" #include "hmi-debug.h" // XXX: We want this DBus connection to be shared across the different @@ -89,21 +88,18 @@ int main(int argc, char *argv[]) // import C++ class to QML qmlRegisterType<ApplicationModel>("AppModel", 1, 0, "ApplicationModel"); - qmlRegisterType<ShortcutAppModel>("ShortcutAppModel", 1, 0, "ShortcutAppModel"); // DBus qDBusRegisterMetaType<AppInfo>(); qDBusRegisterMetaType<QList<AppInfo> >(); + QLibHomeScreen* homescreenHandler = new QLibHomeScreen(); ApplicationLauncher *launcher = new ApplicationLauncher(); QLibWindowmanager* layoutHandler = new QLibWindowmanager(); - ShortcutAppModel* shortcutAppModel = new ShortcutAppModel(); if(layoutHandler->init(port,token) != 0){ exit(EXIT_FAILURE); } -// AGLScreenInfo screenInfo(layoutHandler->get_scale_factor()); - if (layoutHandler->requestSurface(myname) != 0) { exit(EXIT_FAILURE); } @@ -123,10 +119,6 @@ int main(int argc, char *argv[]) HMI_DEBUG("launch", "surface %s Event_Invisible", label); }); - HomescreenHandler* homescreenHandler = new HomescreenHandler(); - QObject::connect(homescreenHandler, SIGNAL(updateShortcutList(QStringList)), shortcutAppModel, SLOT(shortcutUpdate(QStringList))); - homescreenHandler->init(port, token.toStdString().c_str(), layoutHandler, myname); - QUrl bindingAddress; bindingAddress.setScheme(QStringLiteral("ws")); bindingAddress.setHost(QStringLiteral("localhost")); @@ -137,16 +129,28 @@ int main(int argc, char *argv[]) query.addQueryItem(QStringLiteral("token"), token); bindingAddress.setQuery(query); + const QByteArray hack_delay = qgetenv("HMI_LAUNCHER_STARTUP_DELAY"); + int delay_time = 1; + + if (!hack_delay.isEmpty()) { + delay_time = (QString::fromLocal8Bit(hack_delay)).toInt(); + } + + QThread::sleep(delay_time); + qDebug("Sleep %d sec to resolve race condtion between HomeScreen and Launcher", delay_time); + // mail.qml loading QQmlApplicationEngine engine; - engine.rootContext()->setContextProperty(QStringLiteral("layoutHandler"), layoutHandler); - engine.rootContext()->setContextProperty(QStringLiteral("homescreenHandler"), homescreenHandler); - engine.rootContext()->setContextProperty(QStringLiteral("launcher"), launcher); -// engine.rootContext()->setContextProperty(QStringLiteral("screenInfo"), &screenInfo); - engine.rootContext()->setContextProperty(QStringLiteral("shortcutAppModel"), shortcutAppModel); + engine.rootContext()->setContextProperty("layoutHandler", layoutHandler); + engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler); + engine.rootContext()->setContextProperty("launcher", launcher); engine.load(QUrl(QStringLiteral("qrc:/Launcher.qml"))); - homescreenHandler->getRunnables(); + homescreenHandler->init(port, token.toStdString().c_str()); + + homescreenHandler->set_event_handler(QLibHomeScreen::Event_TapShortcut, [layoutHandler, myname](json_object *object){ + layoutHandler->activateSurface(myname); + }); QObject *root = engine.rootObjects().first(); QQuickWindow *window = qobject_cast<QQuickWindow *>(root); homescreenHandler->setQuickWindow(window); diff --git a/launcher/src/shortcutappmodel.cpp b/launcher/src/shortcutappmodel.cpp deleted file mode 100644 index 0fd76b6..0000000 --- a/launcher/src/shortcutappmodel.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2017 TOYOTA MOTOR CORPORATION - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "shortcutappmodel.h" -#include "hmi-debug.h" -#include <QJsonDocument> -#include <QJsonObject> -#include <QJsonParseError> - -#define SHORTCUTKEY_PATH "/var/local/lib/afm/applications/homescreen/0.1/etc/registeredApp.json" - -class ShortcutAppModel::Private -{ -public: - Private(); - - QList<RegisterApp> data; -}; - -ShortcutAppModel::Private::Private() -{ -} - - -ShortcutAppModel::ShortcutAppModel(QObject *parent) - : QAbstractListModel(parent) - , d(new Private()) -{ - init(); -// getAppQueue(); -} - -ShortcutAppModel::~ShortcutAppModel() -{ - delete this->d; -} -void ShortcutAppModel::init() -{ - RegisterApp temp; - for(int i = 0; i < 3; i++) { - temp.id = "video@0.1"; - temp.name = "video"; - temp.icon = getIconPath(temp.id); - if (temp.icon == "") { - temp.isBlank = true; - } else { - temp.isBlank = false; - } - d->data.append(temp); - } -} - -int ShortcutAppModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return 0; - - return this->d->data.count(); -} - -QVariant ShortcutAppModel::data(const QModelIndex &index, int role) const -{ - QVariant ret; - if (!index.isValid()) - return ret; - - switch (role) { - case Qt::DecorationRole: - ret = this->d->data[index.row()].icon; - break; - case Qt::DisplayRole: - ret = this->d->data[index.row()].name; - break; - case Qt::UserRole: - ret = this->d->data[index.row()].id; - break; - default: - break; - } - - return ret; -} - -QHash<int, QByteArray> ShortcutAppModel::roleNames() const -{ - QHash<int, QByteArray> roles; - roles[Qt::DecorationRole] = "icon"; - roles[Qt::DisplayRole] = "name"; - roles[Qt::UserRole] = "id"; - return roles; -} - -void ShortcutAppModel::shortcutUpdate(QStringList shortcut_list) -{ - HMI_DEBUG("Launcher", "ShortcutAppModel::shortcutUpdate id1=%s", shortcut_list.at(1).toStdString().c_str()); - RegisterApp temp; - for(int i = 0; i < d->data.size(); i++) { - temp.id = shortcut_list.at(2 * i); - temp.name = shortcut_list.at(2 * i + 1); - temp.icon = getIconPath(temp.id); - if (temp.icon == "") { - temp.isBlank = true; - } else { - temp.isBlank = false; - } - d->data.replace(i, temp); - } - emit updateShortcut(); -} - -QString ShortcutAppModel::getId(int index) const -{ - return d->data.at(index).id; -} - -QString ShortcutAppModel::getName(int index) const -{ - return d->data.at(index).name; -} - -QString ShortcutAppModel::getIcon(int index) const -{ - return d->data.at(index).icon; -} - -bool ShortcutAppModel::isBlank(int index) const -{ - return d->data.at(index).isBlank; -} - -QString ShortcutAppModel::getIconPath(QString id) -{ - QString name = id.section('@', 0, 0); - QString version = id.section('@', 1, 1); - QString boardIconPath = "/var/local/lib/afm/applications/" + name + "/" + version + "/icon.svg"; - QString appIconPath = ":/images/TopShortcut/" + name + ".svg"; - if (QFile::exists(boardIconPath)) { - return "file://" + boardIconPath; - } else if (QFile::exists(appIconPath)) { - return appIconPath.section('/', 1, -1); - } - return ""; -} - -void ShortcutAppModel::setAppQueuePoint(QString id, QString name) -{ - app.id = id; - app.icon = getIconPath(app.id); - if (app.icon == "") { - app.isBlank = true; - } else { - app.isBlank = false; - } - app.name = name; - d->data.append(app); -} diff --git a/launcher/src/shortcutappmodel.h b/launcher/src/shortcutappmodel.h deleted file mode 100644 index e11e121..0000000 --- a/launcher/src/shortcutappmodel.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef SHORTCUTAPPMODEL_H -#define SHORTCUTAPPMODEL_H - -#include <QtCore/QAbstractListModel> -#include <QXmlStreamReader> -#include <QXmlStreamWriter> -#include <QFile> -#include <QProcess> -#include <QThread> - -struct RegisterApp { - QString id; - QString name; - QString icon; - bool isBlank; -}; - -class ShortcutAppModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit ShortcutAppModel(QObject *parent = nullptr); - ~ShortcutAppModel(); - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QHash<int, QByteArray> roleNames() const override; - - Q_INVOKABLE QString getId(int index) const; - Q_INVOKABLE QString getName(int index) const; - Q_INVOKABLE QString getIcon(int index) const; - Q_INVOKABLE bool isBlank(int index) const; - -public slots: - void shortcutUpdate(QStringList shortcut_list); - -signals: - void updateShortcut(); - -private: - void init(); - void getAppQueue(); - void setAppQueuePoint(QString id, QString name); - QString getIconPath(QString id); - - class Private; - Private *d; - RegisterApp app; - -}; - -#endif // SHORTCUTAPPMODEL_H |