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) :
31 HomescreenHandler::~HomescreenHandler()
38 void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm, QString myname)
44 mp_qhs = new QLibHomeScreen();
45 mp_qhs->init(port, token);
46 mp_qhs->registerCallback(nullptr, HomescreenHandler::onRep_static);
48 mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowWindow,[this](json_object *object){
49 HMI_DEBUG("Launcher","Surface launcher got Event_ShowWindow\n");
50 mp_qwm->activateWindow(m_myname);
53 mp_qhs->set_event_handler(QLibHomeScreen::Event_AppListChanged,[this](json_object *object){
54 HMI_DEBUG("Launcher","laucher: appListChanged [%s]\n", json_object_to_json_string(object));
56 struct json_object *obj_param, *obj_oper, *obj_data;
57 if(json_object_object_get_ex(object, "parameter", &obj_param)
58 && json_object_object_get_ex(obj_param, "operation", &obj_oper)
59 && json_object_object_get_ex(obj_param, "data", &obj_data)) {
60 QString oper = json_object_get_string(obj_oper);
61 if(oper == "uninstall") {
62 /* { "application_id": "launcher",
63 * "type": "application-list-changed",
65 * "operation": "uninstall",
66 * "data": "onstestapp@0.1"
69 QString id = json_object_get_string(obj_data);
72 info << "" << "" << id;
73 emit appListUpdate(info);
75 else if(oper == "install") {
76 /* { "application_id": "launcher",
77 * "type": "application-list-changed",
79 * "operation": "install",
81 * "description":"This is a demo onstestapp application",
82 * "name": "onstestapp",
84 * "id": "onstestapp@0.1",
90 * "icon": "\/var\/local\/lib\/afm\/applications\/onstestapp\/0.1\/icon.svg",
95 struct json_object *obj_icon, *obj_name, *obj_id;
96 if(json_object_object_get_ex(obj_data, "icon", &obj_icon)
97 && json_object_object_get_ex(obj_data, "name", &obj_name)
98 && json_object_object_get_ex(obj_data, "id", &obj_id)) {
99 QString icon = json_object_get_string(obj_icon);
100 QString name = json_object_get_string(obj_name);
101 QString id = json_object_get_string(obj_id);
104 info << icon << name << id;
105 emit appListUpdate(info);
109 HMI_ERROR("Launcher","error operation.\n");
115 void HomescreenHandler::tapShortcut(QString application_id)
117 HMI_DEBUG("Launcher","tapShortcut %s", application_id.toStdString().c_str());
118 struct json_object* j_json = json_object_new_object();
119 struct json_object* value;
120 value = json_object_new_string("normal.full");
121 json_object_object_add(j_json, "area", value);
123 mp_qhs->showWindow(application_id.toStdString().c_str(), j_json);
126 void HomescreenHandler::onRep_static(struct json_object* reply_contents)
128 static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents);
131 void HomescreenHandler::onRep(struct json_object* reply_contents)
133 HMI_DEBUG("launcher","HomeScreen onReply %s", json_object_to_json_string(reply_contents));
134 struct json_object *obj_res, *obj_verb;
135 if(json_object_object_get_ex(reply_contents, "response", &obj_res)
136 && json_object_object_get_ex(obj_res, "verb", &obj_verb)
137 && !strcasecmp("getRunnables", json_object_get_string(obj_verb))) {
138 struct json_object *obj_data;
139 if(json_object_object_get_ex(obj_res, "data", &obj_data)) {
140 HMI_DEBUG("launcher","HomescreenHandler emit initAppList");
141 QString data = json_object_to_json_string(obj_data);
142 emit initAppList(data);
147 void HomescreenHandler::getRunnables(void)
149 mp_qhs->getRunnables();
152 void HomescreenHandler::setQuickWindow(QQuickWindow *qw)
154 mp_qhs->setQuickWindow(qw);