2 * Copyright (c) 2017, 2018, 2019 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) :
30 HomescreenHandler::~HomescreenHandler()
37 void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm, QString myname)
39 mp_qhs = new QLibHomeScreen();
40 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_OnScreenMessage, [this](json_object *object){
54 const char *display_message = json_object_get_string(
55 json_object_object_get(object, "display_message"));
56 HMI_DEBUG("HomeScreen","set_event_handler Event_OnScreenMessage display_message = %s", display_message);
59 mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowNotification,[this](json_object *object){
60 json_object *p_obj = json_object_object_get(object, "parameter");
61 const char *icon = json_object_get_string(
62 json_object_object_get(p_obj, "icon"));
63 const char *text = json_object_get_string(
64 json_object_object_get(p_obj, "text"));
65 const char *app_id = json_object_get_string(
66 json_object_object_get(p_obj, "caller"));
67 HMI_DEBUG("HomeScreen","Event_ShowNotification icon=%s, text=%s, caller=%s", icon, text, app_id);
68 QFileInfo icon_file(icon);
70 if (icon_file.isFile() && icon_file.exists()) {
71 icon_path = QString(QLatin1String(icon));
73 icon_path = "./images/Utility_Logo_Grey-01.svg";
76 emit showNotification(QString(QLatin1String(app_id)), icon_path, QString(QLatin1String(text)));
79 mp_qhs->set_event_handler(QLibHomeScreen::Event_ShowInformation,[this](json_object *object){
80 json_object *p_obj = json_object_object_get(object, "parameter");
81 const char *info = json_object_get_string(
82 json_object_object_get(p_obj, "info"));
84 emit showInformation(QString(QLatin1String(info)));
88 void HomescreenHandler::tapShortcut(QString application_id)
90 HMI_DEBUG("HomeScreen","tapShortcut %s", application_id.toStdString().c_str());
91 struct json_object* j_json = json_object_new_object();
92 struct json_object* value;
93 value = json_object_new_string("normal.full");
94 json_object_object_add(j_json, "area", value);
96 mp_qhs->showWindow(application_id.toStdString().c_str(), j_json);
99 void HomescreenHandler::onRep_static(struct json_object* reply_contents)
101 static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents);
104 void HomescreenHandler::onEv_static(const string& event, struct json_object* event_contents)
106 static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onEv(event, event_contents);
109 void HomescreenHandler::onRep(struct json_object* reply_contents)
111 const char* str = json_object_to_json_string(reply_contents);
112 HMI_DEBUG("HomeScreen","HomeScreen onReply %s", str);
115 void HomescreenHandler::onEv(const string& event, struct json_object* event_contents)
117 const char* str = json_object_to_json_string(event_contents);
118 HMI_DEBUG("HomeScreen","HomeScreen onEv %s, contents: %s", event.c_str(), str);
120 if (event.compare("homescreen/on_screen_message") == 0) {
121 struct json_object *json_data = json_object_object_get(event_contents, "data");
122 struct json_object *json_display_message = json_object_object_get(json_data, "display_message");
123 const char* display_message = json_object_get_string(json_display_message);
125 HMI_DEBUG("HomeScreen","display_message = %s", display_message);
129 void HomescreenHandler::setQuickWindow(QQuickWindow *qw)
131 mp_qhs->setQuickWindow(qw);