Porting to new HMI Framework
[apps/hvac.git] / app / qlibwindowmanager.cpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "qlibwindowmanager.h"
18 #include <QDebug>
19 #include <unistd.h>
20
21 int QLibWindowmanager::init(int port, const QString &token) {
22     std::string ctoken = token.toStdString();
23     return this->wm->init(port, ctoken.c_str());
24 }
25
26 int QLibWindowmanager::requestSurface(json_object *label) {
27     applabel = json_object_get_string(label);
28
29     json_object *obj = json_object_new_object();
30     json_object_object_add(obj, wm->kKeyDrawingName, label);
31     return this->wm->requestSurface(obj);
32 }
33
34 int QLibWindowmanager::activateSurface(json_object *label) {
35     qDebug() << "activateSurface applabel: " << applabel.c_str();
36     json_object *obj = json_object_new_object();
37     qDebug() << "DrawingName: " << wm->kKeyDrawingName;
38     json_object_object_add(obj, wm->kKeyDrawingName, label);
39     qDebug() << "DrawingArea: " << wm->kKeyDrawingArea;
40     json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full"));
41     qDebug() << "obj pointer: " << obj;
42     qDebug() << "activateSurface end obj: " << json_object_get_string(obj);
43
44     return this->wm->activateSurface(obj);
45 }
46
47 int QLibWindowmanager::deactivateSurface(json_object *label) {
48     json_object *obj = json_object_new_object();
49     json_object_object_add(obj, wm->kKeyDrawingName, label);
50     return this->wm->deactivateSurface(obj);
51 }
52
53 int QLibWindowmanager::endDraw(json_object *label) {
54     json_object *obj = json_object_new_object();
55     qDebug() << "endDraw label: " << json_object_get_string(label);
56     json_object_object_add(obj, wm->kKeyDrawingName, label);
57     return this->wm->endDraw(obj);
58     }
59
60 void QLibWindowmanager::set_event_handler(enum QEventType et,
61  handler_fun f) {
62     LibWindowmanager::EventType wet = (LibWindowmanager::EventType)et;
63     return this->wm->set_event_handler(wet, std::move(f));
64 }
65
66 void QLibWindowmanager::slotActivateSurface(){
67     if(!isActive){
68         qDebug("Let's show HVAC");
69         isActive = true;
70         qDebug() << "slotActivateSurface applabel: " << applabel.c_str();
71         this->activateSurface(json_object_new_string(applabel.c_str()));
72     }
73 }
74
75 QLibWindowmanager::QLibWindowmanager(QObject *parent)
76     :QObject(parent), isActive(false)
77 {
78     wm = new LibWindowmanager();
79 }
80
81 QLibWindowmanager::~QLibWindowmanager() { }