625daec3e09ee5f2676c9e57d92911ba40a6e8d2
[staging/HomeScreen.git] / HomeScreenAppFrameworkBinderTizen / src / homescreenappframeworkbindertizen.cpp
1 /*
2  * Copyright (C) 2016 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 "homescreenappframeworkbindertizen.h"
18
19
20 HomeScreenAppFrameworkBinderTizen::HomeScreenAppFrameworkBinderTizen(QObject *parent) :
21     QObject(parent),
22     mp_appframeworkAdaptor(0)
23 {
24     qDebug("D-Bus: register as org.agl.homescreenappframeworkbinder");
25
26     m_apps.clear();
27
28     // publish app framework interface
29     mp_appframeworkAdaptor = new AppframeworkAdaptor((QObject*)this);
30     QDBusConnection dbus = QDBusConnection::sessionBus();
31     dbus.registerObject("/AppFramework", this);
32     dbus.registerService("org.agl.homescreenappframeworkbinder");
33
34 #ifdef __arm__
35     pkgmgrinfo_pkginfo_get_list(HomeScreenAppFrameworkBinderTizen::pkg_list_cb_static, this);
36     //list_pkgs(this);
37 #endif
38 #ifdef __i386__
39     // for the simulation
40     AppInfo ai;
41     ai.setName("org.test.app1");
42     ai.setDescription("testdesc1");
43     ai.setIconPath("https://www.automotivelinux.org/sites/cpstandard/files/logo.png");
44     m_apps.append(ai);
45     ai.setName("org.test.app2");
46     ai.setDescription("testdesc2");
47     m_apps.append(ai);
48 #endif
49 }
50
51 HomeScreenAppFrameworkBinderTizen::~HomeScreenAppFrameworkBinderTizen()
52 {
53     delete mp_appframeworkAdaptor;
54 }
55
56 QStringList HomeScreenAppFrameworkBinderTizen::getAvailableAppNames()
57 {
58     QStringList result;
59     for (int i = 0; i < m_apps.size(); ++i)
60     {
61         result.append(m_apps.at(i).getName());
62     }
63     qDebug("size: %d", result.size());
64     return result;
65 }
66
67 int HomeScreenAppFrameworkBinderTizen::launchApp(const QString &name)
68 {
69     int pid = -1;
70 #ifdef __arm__
71     qDebug("launchApp name: %s", name.toStdString().c_str());
72     pid = aul_launch_app(name.toStdString().c_str(), 0);
73     qDebug("launchApp pid: %d", pid);
74 #endif
75 #ifdef __i386__
76     qDebug("launchApp name: %s", name.toStdString().c_str());
77     pid = qrand();
78 #endif
79
80     return pid;
81 }
82
83 void HomeScreenAppFrameworkBinderTizen::clearAppList()
84 {
85     m_apps.clear();
86 }
87
88 void HomeScreenAppFrameworkBinderTizen::appendAppName(const char* name)
89 {
90     AppInfo newApp;
91     newApp.setName(QString(name));
92     m_apps.append(newApp);
93 }
94
95 #ifdef __arm__
96 void HomeScreenAppFrameworkBinderTizen::pkg_list_cb_non_static(pkgmgrinfo_pkginfo_h handle)
97 {
98     qDebug("pkg_list_cb_non_static");
99     char *pkgid2 = NULL;
100     pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid2);
101     printf("pkg_list_cb_non_static: %s\n", pkgid2);
102     appendAppName(pkgid2);
103 }
104
105 int HomeScreenAppFrameworkBinderTizen::pkg_list_cb_static(pkgmgrinfo_pkginfo_h handle, void *user_data)
106 {
107     qDebug("pkg_list_cb_static");
108     static_cast<HomeScreenAppFrameworkBinderTizen*>(user_data)->pkg_list_cb_non_static(handle);
109 }
110 #endif