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 void HomescreenHandler::getRunnables(void)
52 struct json_object *json_applist;
56 QDBusPendingReply<QVariantList> reply = applaunch_iface->listApplications(true);
57 reply.waitForFinished();
58 if (reply.isError()) {
59 HMI_ERROR("Launcher","Unable to retrieve application list: %s",
60 reply.error().message().toStdString().c_str());
63 QVariantList applist_variant = reply.value();
64 for (auto &v: applist_variant) {
68 const QDBusArgument &dbus_arg = v.value<QDBusArgument>();
70 dbus_arg.beginStructure();
71 dbus_arg >> app_id >> name >> icon_path;
73 apps << QString("{ \"name\":\"%1\", \"id\":\"%2\", \"icon\":\"%3\" }")
77 dbus_arg.endStructure();
81 applist = QString("[ %1 ]").arg(apps.join(", "));
82 json_applist = json_tokener_parse(applist.toLocal8Bit().data());
84 QString data = json_object_to_json_string(json_applist);
85 HMI_DEBUG("Launcher", "doing an emit initAppList()");
86 emit initAppList(data);
88 HMI_DEBUG("Launcher", "app list is invalid!");