7ad69f7a0de3ec1f1e3886ac6b160fc7dcb4ddba
[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     json_object *obj = json_object_new_object();
36     json_object_object_add(obj, wm->kKeyDrawingName, label);
37     json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full"));
38
39     return this->wm->activateSurface(obj);
40 }
41
42 int QLibWindowmanager::deactivateSurface(json_object *label) {
43     json_object *obj = json_object_new_object();
44     json_object_object_add(obj, wm->kKeyDrawingName, label);
45     return this->wm->deactivateSurface(obj);
46 }
47
48 int QLibWindowmanager::endDraw(json_object *label) {
49     json_object *obj = json_object_new_object();
50     json_object_object_add(obj, wm->kKeyDrawingName, label);
51     return this->wm->endDraw(obj);
52     }
53
54 void QLibWindowmanager::set_event_handler(enum QEventType et,
55  handler_fun f) {
56     LibWindowmanager::EventType wet = (LibWindowmanager::EventType)et;
57     return this->wm->set_event_handler(wet, std::move(f));
58 }
59
60 void QLibWindowmanager::slotActivateSurface(){
61     if(!isActive){
62         qDebug("Let's show HVAC");
63         isActive = true;
64         this->activateSurface(json_object_new_string(applabel.c_str()));
65     }
66 }
67
68 QLibWindowmanager::QLibWindowmanager(QObject *parent)
69     :QObject(parent), isActive(false)
70 {
71     wm = new LibWindowmanager();
72 }
73
74 QLibWindowmanager::~QLibWindowmanager() { }