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.
19 #include "homescreenhandler.h"
21 #include "hmi-debug.h"
23 void* HomescreenHandler::myThis = 0;
25 HomescreenHandler::HomescreenHandler(QObject *parent) :
32 HomescreenHandler::~HomescreenHandler()
39 void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm, QString myname)
45 mp_hs = new LibHomeScreen();
46 mp_hs->init(port, token);
47 mp_hs->registerCallback(nullptr, HomescreenHandler::onRep_static);
49 mp_hs->set_event_handler(LibHomeScreen::Event_ShowWindow,[this](json_object *object){
50 HMI_DEBUG("Launcher","Surface launcher got Event_ShowWindow\n");
51 mp_qwm->activateWindow(m_myname);
54 mp_hs->set_event_handler(LibHomeScreen::Event_AppListChanged,[this](json_object *object){
55 HMI_DEBUG("Launcher","laucher: appListChanged [%s]\n", json_object_to_json_string(object));
57 struct json_object *obj_param, *obj_oper, *obj_data;
58 if(json_object_object_get_ex(object, "parameter", &obj_param)
59 && json_object_object_get_ex(obj_param, "operation", &obj_oper)
60 && json_object_object_get_ex(obj_param, "data", &obj_data)) {
61 QString oper = json_object_get_string(obj_oper);
62 if(oper == "uninstall") {
63 /* { "application_id": "launcher",
64 * "type": "application-list-changed",
66 * "operation": "uninstall",
67 * "data": "onstestapp@0.1"
70 QString id = json_object_get_string(obj_data);
73 info << "" << "" << id;
74 emit appListUpdate(info);
76 else if(oper == "install") {
77 /* { "application_id": "launcher",
78 * "type": "application-list-changed",
80 * "operation": "install",
82 * "description":"This is a demo onstestapp application",
83 * "name": "onstestapp",
85 * "id": "onstestapp@0.1",
91 * "icon": "\/var\/local\/lib\/afm\/applications\/onstestapp\/0.1\/icon.svg",
96 struct json_object *obj_icon, *obj_name, *obj_id;
97 if(json_object_object_get_ex(obj_data, "icon", &obj_icon)
98 && json_object_object_get_ex(obj_data, "name", &obj_name)
99 && json_object_object_get_ex(obj_data, "id", &obj_id)) {
100 QString icon = json_object_get_string(obj_icon);
101 QString name = json_object_get_string(obj_name);
102 QString id = json_object_get_string(obj_id);
105 info << icon << name << id;
106 emit appListUpdate(info);
110 HMI_ERROR("Launcher","error operation.\n");
116 void HomescreenHandler::tapShortcut(QString application_id)
118 HMI_DEBUG("Launcher","tapShortcut %s", application_id.toStdString().c_str());
119 struct json_object* j_json = json_object_new_object();
120 struct json_object* value;
121 value = json_object_new_string("normal.full");
122 json_object_object_add(j_json, "area", value);
124 mp_hs->showWindow(application_id.toStdString().c_str(), j_json);
127 void HomescreenHandler::onRep_static(struct json_object* reply_contents)
129 static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents);
132 void HomescreenHandler::onRep(struct json_object* reply_contents)
134 HMI_DEBUG("launcher","HomeScreen onReply %s", json_object_to_json_string(reply_contents));
135 struct json_object *obj_res, *obj_verb;
136 if(json_object_object_get_ex(reply_contents, "response", &obj_res)
137 && json_object_object_get_ex(obj_res, "verb", &obj_verb)
138 && !strcasecmp("getRunnables", json_object_get_string(obj_verb))) {
139 struct json_object *obj_data;
140 if(json_object_object_get_ex(obj_res, "data", &obj_data)) {
141 HMI_DEBUG("launcher","HomescreenHandler emit initAppList");
142 QString data = json_object_to_json_string(obj_data);
143 emit initAppList(data);
148 void HomescreenHandler::getRunnables(void)
150 mp_hs->getRunnables();