Using the Tizen application manager to receive information about installed apps and...
[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.homescreenappframeworkbindertizen");
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.homescreenappframeworkbindertizen");
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 #endif
78
79     return pid;
80 }
81
82 void HomeScreenAppFrameworkBinderTizen::clearAppList()
83 {
84     m_apps.clear();
85 }
86
87 void HomeScreenAppFrameworkBinderTizen::appendAppName(const char* name)
88 {
89     AppInfo newApp;
90     newApp.setName(QString(name));
91     m_apps.append(newApp);
92 }
93
94 #ifdef __arm__
95 void HomeScreenAppFrameworkBinderTizen::pkg_list_cb_non_static(pkgmgrinfo_pkginfo_h handle)
96 {
97     qDebug("pkg_list_cb_non_static");
98     char *pkgid2 = NULL;
99     pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid2);
100     printf("pkg_list_cb_non_static: %s\n", pkgid2);
101     appendAppName(pkgid2);
102 }
103
104 int HomeScreenAppFrameworkBinderTizen::pkg_list_cb_static(pkgmgrinfo_pkginfo_h handle, void *user_data)
105 {
106     qDebug("pkg_list_cb_static");
107     static_cast<HomeScreenAppFrameworkBinderTizen*>(user_data)->pkg_list_cb_non_static(handle);
108 }
109 #endif