modify display/hide onscreen sequence
[apps/onscreenapp.git] / sample / app / eventhandler.cpp
index b88bda4..34e7e3e 100644 (file)
 #include <QJsonDocument>
 #include <QJsonObject>
 #include <QQuickWindow>
-#include <QtQml/QQmlContext>
+//#include <QtQml/QQmlContext>
+#include <QQmlContext>
+#include <QtQml/QQmlApplicationEngine>
 #include "eventhandler.h"
 
 void* EventHandler::myThis = 0;
 
+const char _drawing_name[] = "drawing_name";
+
 EventHandler::EventHandler(QObject *parent) :
     QObject(parent),
     mp_hs(NULL),
@@ -52,8 +56,8 @@ void EventHandler::init(int port, const char *token)
     mp_hs = new QLibHomeScreen();
     mp_hs->init(port, token);
 
-    mp_hs->set_event_handler(QLibHomeScreen::Event_TapShortcut, [this](json_object *object){
-        this->mp_wm->activateWindow(ROLE_NAME);
+    mp_hs->set_event_handler(QLibHomeScreen::Event_ShowWindow, [this](json_object *object){
+        this->mp_wm->activateWindow(ROLE_NAME, "normal");
         HMI_DEBUG(APP_ID, "received showWindow event, end!, line=%d", __LINE__);
     });
 
@@ -76,7 +80,7 @@ void EventHandler::init(int port, const char *token)
 
     mp_wm->set_event_handler(QLibWindowmanager::Event_Visible, [this](json_object *object) {
         struct json_object *value;
-        json_object_object_get_ex(object, "drawing_name", &value);
+        json_object_object_get_ex(object, _drawing_name, &value);
         const char *name = json_object_get_string(value);
 
         HMI_DEBUG(APP_ID, "Event_Active kKeyDrawingName = %s", name);
@@ -84,7 +88,7 @@ void EventHandler::init(int port, const char *token)
 
     mp_wm->set_event_handler(QLibWindowmanager::Event_Invisible, [this](json_object *object) {
         struct json_object *value;
-        json_object_object_get_ex(object, "drawing_name", &value);
+        json_object_object_get_ex(object, _drawing_name, &value);
         const char *name = json_object_get_string(value);
 
         HMI_DEBUG(APP_ID, "Event_Inactive kKeyDrawingName = %s", name);
@@ -106,3 +110,8 @@ void EventHandler::showWindow(QString id, QString json)
     else
         mp_hs->showWindow(id.toStdString().c_str(), json_tokener_parse(json.toStdString().c_str()));
 }
+
+void EventHandler::hideWindow(QString id)
+{
+    mp_hs->hideWindow(id.toStdString().c_str());
+}