ecbe8e417e2490ef69de002da5bd806258f84e2a
[apps/homescreen.git] / homescreen / src / homescreencontrolinterface.cpp
1 /*
2  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
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 "afm_user_daemon_proxy.h"
18 #include "homescreencontrolinterface.h"
19
20 extern org::AGL::afm::user *afm_user_daemon_proxy;
21
22 HomeScreenControlInterface::HomeScreenControlInterface(QObject *parent) :
23     QObject(parent),
24     mp_homeScreenAdaptor(0)
25 {
26     // publish dbus homescreen interface
27     mp_homeScreenAdaptor = new HomescreenAdaptor((QObject*)this);
28
29     QDBusConnection dbus = QDBusConnection::sessionBus();
30     dbus.registerObject("/HomeScreen", this);
31     dbus.registerService("org.agl.homescreen");
32 }
33
34 QList<int> HomeScreenControlInterface::getAllSurfacesOfProcess(int pid)
35 {
36     qDebug("getAllSurfacesOfProcess %d", pid);
37     return newRequestGetAllSurfacesOfProcess(pid);
38 }
39
40 int HomeScreenControlInterface::getSurfaceStatus(int surfaceId)
41 {
42     qDebug("getSurfaceStatus %d", surfaceId);
43     return newRequestGetSurfaceStatus(surfaceId);
44 }
45
46 void HomeScreenControlInterface::hardKeyPressed(int key)
47 {
48     int pid = -1;
49
50     switch (key)
51     {
52     case InputEvent::HARDKEY_NAV:
53         qDebug("hardKeyPressed NAV key pressed!");
54         pid = afm_user_daemon_proxy->start("navigation@0.1").value().toInt();
55         qDebug("pid: %d", pid);
56         emit newRequestsToBeVisibleApp(pid);
57         break;
58     case InputEvent::HARDKEY_MEDIA:
59         qDebug("hardKeyPressed MEDIA key pressed!");
60         pid = afm_user_daemon_proxy->start("media@0.1").value().toInt();
61         qDebug("pid: %d", pid);
62         emit newRequestsToBeVisibleApp(pid);
63         break;
64     default:
65         qDebug("hardKeyPressed %d", key);
66         break;
67     }
68 }
69
70 void HomeScreenControlInterface::renderSurfaceToArea(int surfaceId, int layoutArea)
71 {
72     qDebug("renderSurfaceToArea %d %d", surfaceId, layoutArea);
73     emit newRequestRenderSurfaceToArea(surfaceId, layoutArea);
74 }
75
76 bool HomeScreenControlInterface::renderAppToAreaAllowed(int appCategory, int layoutArea)
77 {
78     qDebug("renderAppToAreaAllowed %d %d", appCategory, layoutArea);
79     return true; //TODO: ask policy manager
80 }
81
82 void HomeScreenControlInterface::requestSurfaceIdToFullScreen(int surfaceId)
83 {
84     qDebug("requestSurfaceIdToFullScreen %d", surfaceId);
85     emit newRequestSurfaceIdToFullScreen(surfaceId);
86 }