2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3 * Copyright (c) 2018,2019 TOYOTA MOTOR CORPORATION
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 <QDBusMessage>
19 #include <QDBusConnection>
20 #include "homescreenhandler.h"
21 #include "hmi-debug.h"
25 #define APPLAUNCH_DBUS_IFACE "org.automotivelinux.AppLaunch"
26 #define APPLAUNCH_DBUS_OBJECT "/org/automotivelinux/AppLaunch"
28 HomescreenHandler::HomescreenHandler(QObject *parent) : QObject(parent)
30 applaunch_iface = new org::automotivelinux::AppLaunch(APPLAUNCH_DBUS_IFACE, APPLAUNCH_DBUS_OBJECT, QDBusConnection::sessionBus(), this);
33 HomescreenHandler::~HomescreenHandler()
37 void HomescreenHandler::tapShortcut(QString application_id)
39 HMI_DEBUG("Launcher","tapShortcut %s", application_id.toStdString().c_str());
41 QDBusPendingReply<> reply = applaunch_iface->start(application_id);
42 reply.waitForFinished();
43 if (reply.isError()) {
44 HMI_ERROR("Launcher","Unable to start application '%s': %s",
45 application_id.toStdString().c_str(),
46 reply.error().message().toStdString().c_str());
50 int HomescreenHandler::getRunnablesCount(void)
54 QDBusPendingReply<QVariantList> reply = applaunch_iface->listApplications(true);
55 reply.waitForFinished();
57 if (reply.isError()) {
58 HMI_ERROR("Launcher","Unable to retrieve application list: %s",
59 reply.error().message().toStdString().c_str());
62 QVariantList applist_variant = reply.value();
63 for (auto &v: applist_variant)
70 void HomescreenHandler::getRunnables(void)
72 struct json_object *json_applist;
76 QDBusPendingReply<QVariantList> reply = applaunch_iface->listApplications(true);
77 reply.waitForFinished();
78 if (reply.isError()) {
79 HMI_ERROR("Launcher","Unable to retrieve application list: %s",
80 reply.error().message().toStdString().c_str());
83 QVariantList applist_variant = reply.value();
84 for (auto &v: applist_variant) {
88 const QDBusArgument &dbus_arg = v.value<QDBusArgument>();
90 dbus_arg.beginStructure();
91 dbus_arg >> app_id >> name >> icon_path;
93 apps << QString("{ \"name\":\"%1\", \"id\":\"%2\", \"icon\":\"%3\" }")
97 dbus_arg.endStructure();
101 applist = QString("[ %1 ]").arg(apps.join(", "));
102 json_applist = json_tokener_parse(applist.toLocal8Bit().data());
104 QString data = json_object_to_json_string(json_applist);
105 HMI_DEBUG("Launcher", "doing an emit initAppList()");
106 emit initAppList(data);
108 HMI_DEBUG("Launcher", "app list is invalid!");