2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "homescreenhandler.h"
20 #include "hmi-debug.h"
22 void* HomescreenHandler::myThis = 0;
24 HomescreenHandler::HomescreenHandler(QObject *parent) :
31 HomescreenHandler::~HomescreenHandler()
38 void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm, QString myname)
44 mp_hs = new LibHomeScreen();
45 mp_hs->init(port, token);
46 mp_hs->registerCallback(nullptr, HomescreenHandler::onRep_static);
48 mp_hs->set_event_handler(LibHomeScreen::Event_ShowWindow,[this](json_object *object){
49 HMI_DEBUG("Launcher","Surface launcher got Event_ShowWindow\n");
50 mp_qwm->activateWindow(m_myname);
53 mp_hs->set_event_handler(LibHomeScreen::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 QString id = json_object_get_string(obj_data);
65 info << "" << "" << id;
66 emit appListUpdate(info);
68 else if(oper == "install") {
69 struct json_object *obj_icon, *obj_name, *obj_id;
70 if(json_object_object_get_ex(obj_data, "icon", &obj_icon)
71 && json_object_object_get_ex(obj_data, "name", &obj_name)
72 && json_object_object_get_ex(obj_data, "id", &obj_id)) {
73 QString icon = json_object_get_string(obj_icon);
74 QString name = json_object_get_string(obj_name);
75 QString id = json_object_get_string(obj_id);
78 info << icon << name << id;
79 emit appListUpdate(info);
83 HMI_ERROR("Launcher","error operation.\n");
89 void HomescreenHandler::tapShortcut(QString application_id)
91 HMI_DEBUG("Launcher","tapShortcut %s", application_id.toStdString().c_str());
92 struct json_object* j_json = json_object_new_object();
93 struct json_object* value;
94 value = json_object_new_string("normal.full");
95 json_object_object_add(j_json, "area", value);
97 mp_hs->showWindow(application_id.toStdString().c_str(), j_json);
100 void HomescreenHandler::onRep_static(struct json_object* reply_contents)
102 static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents);
105 void HomescreenHandler::onRep(struct json_object* reply_contents)
107 HMI_DEBUG("launcher","HomeScreen onReply %s", json_object_to_json_string(reply_contents));
108 struct json_object *obj_res, *obj_verb;
109 if(json_object_object_get_ex(reply_contents, "response", &obj_res)
110 && json_object_object_get_ex(obj_res, "verb", &obj_verb)
111 && !strcasecmp("getRunnables", json_object_get_string(obj_verb))) {
112 struct json_object *obj_data;
113 if(json_object_object_get_ex(obj_res, "data", &obj_data)) {
114 HMI_DEBUG("launcher","HomescreenHandler emit initAppList");
115 QString data = json_object_to_json_string(obj_data);
116 emit initAppList(data);
121 void HomescreenHandler::getRunnables(void)
123 mp_hs->getRunnables();