993a204f6625adc5f20c0120119451e13cd4fd0d
[apps/mediaplayer.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 <unistd.h>
19
20 int QLibWindowmanager::init(int port, char const *token) {
21     return this->wm->init(port, token);
22 }
23
24 int QLibWindowmanager::requestSurface(const char *label) {
25     applabel = label;
26     json_object *obj = json_object_new_object();
27     json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label));
28     return this->wm->requestSurface(obj);
29 }
30
31 int QLibWindowmanager::activateSurface(const char *label) {
32     json_object *obj = json_object_new_object();
33     json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label));
34     json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full"));
35     return this->wm->activateSurface(obj);
36 }
37
38 int QLibWindowmanager::deactivateSurface(const char *label) {
39     json_object *obj = json_object_new_object();
40     json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label));
41     return this->wm->deactivateSurface(obj);
42 }
43
44 int QLibWindowmanager::endDraw(const char *label) {
45     json_object *obj = json_object_new_object();
46     json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label));
47     return this->wm->endDraw(obj); 
48     }
49
50 void QLibWindowmanager::set_event_handler(enum QEventType et,
51                                   handler_fun f) {
52     LibWindowmanager::EventType wet = (LibWindowmanager::EventType)et;
53     return this->wm->set_event_handler(wet, std::move(f));
54 }
55
56 void QLibWindowmanager::slotActivateSurface(){
57     if(!isActive){
58         qDebug("Let's snow mediaplayer");;
59         isActive = true;
60         this->activateSurface(applabel.c_str());
61     }
62 }
63
64 /*void QLibWindowmanager::setVisible(bool visible){
65     isVisible = visible;
66 }*/
67
68 QLibWindowmanager::QLibWindowmanager(QObject *parent) 
69     :QObject(parent) , isActive(false)
70 {
71     wm = new LibWindowmanager();
72 }
73
74 QLibWindowmanager::~QLibWindowmanager() { }