2 * Copyright (c) 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.
19 #include <QJsonDocument>
20 #include <QJsonObject>
21 #include <QQuickWindow>
22 //#include <QtQml/QQmlContext>
23 #include <QQmlContext>
24 #include <QtQml/QQmlApplicationEngine>
25 #include "eventhandler.h"
27 void* EventHandler::myThis = 0;
29 const char _drawing_name[] = "drawing_name";
31 EventHandler::EventHandler(QObject *parent) :
40 EventHandler::~EventHandler()
50 void EventHandler::init(int port, const char *token)
53 mp_wm = new QLibWindowmanager();
54 mp_wm->init(port, token);
56 mp_hs = new QLibHomeScreen();
57 mp_hs->init(port, token);
59 mp_hs->set_event_handler(QLibHomeScreen::Event_ShowWindow, [this](json_object *object){
60 this->mp_wm->activateWindow(ROLE_NAME, "normal");
61 HMI_DEBUG(APP_ID, "received showWindow event, end!, line=%d", __LINE__);
64 mp_hs->set_event_handler(QLibHomeScreen::Event_ReplyShowWindow, [this](json_object *object){
65 HMI_DEBUG(APP_ID, "got Event_ReplyShowWindow!\n");
66 const char* msg = json_object_to_json_string(object);
67 emit this->signalOnReplyShowWindow(msg);
70 if (mp_wm->requestSurface(ROLE_NAME) != 0) {
71 HMI_DEBUG(APP_ID, "!!!!LayoutHandler requestSurface Failed!!!!!");
75 // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs
76 mp_wm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [this](json_object *object) {
77 HMI_DEBUG(APP_ID, "Surface got syncDraw!");
78 this->mp_wm->endDraw(ROLE_NAME);
81 mp_wm->set_event_handler(QLibWindowmanager::Event_Visible, [this](json_object *object) {
82 struct json_object *value;
83 json_object_object_get_ex(object, _drawing_name, &value);
84 const char *name = json_object_get_string(value);
86 HMI_DEBUG(APP_ID, "Event_Active kKeyDrawingName = %s", name);
89 mp_wm->set_event_handler(QLibWindowmanager::Event_Invisible, [this](json_object *object) {
90 struct json_object *value;
91 json_object_object_get_ex(object, _drawing_name, &value);
92 const char *name = json_object_get_string(value);
94 HMI_DEBUG(APP_ID, "Event_Inactive kKeyDrawingName = %s", name);
97 HMI_DEBUG(APP_ID, "LayoutHander::init() finished.");
100 void EventHandler::setQuickWindow(QQuickWindow *qw)
103 QObject::connect(mp_qw, SIGNAL(frameSwapped()), mp_wm, SLOT(slotActivateSurface()));
106 void EventHandler::showWindow(QString id, QString json)
109 mp_hs->tapShortcut(id);
111 mp_hs->showWindow(id.toStdString().c_str(), json_tokener_parse(json.toStdString().c_str()));
114 void EventHandler::hideWindow(QString id)
116 mp_hs->hideWindow(id.toStdString().c_str());