Add sample qml application
[staging/HomeScreen.git] / sample-qml / main.cpp
1 #include <QGuiApplication>
2 #include <QQmlApplicationEngine>
3 #include <unistd.h>
4 #include <vector>
5 #include <QQmlContext>
6 #include <libhomescreen.hpp>    // use libhomescreen
7 #include "calledbyqml.h"
8
9
10 #define FULLSCREEN 1    // assume 1 is "fullscreen"
11
12
13 int main(int argc, char *argv[])
14 {
15     QGuiApplication app(argc, argv);
16
17     /*  use libhomescreen
18         To use libhomescreen, add library path in project file(.pro)
19     */
20     LibHomeScreen *mp_libHomeScreen;
21     mp_libHomeScreen = new LibHomeScreen();
22
23     QQmlApplicationEngine engine;
24     CalledByQml call_hsa;
25     engine.rootContext()->setContextProperty("hsa",&call_hsa);
26
27     int appcategory = 0 ;
28
29     bool enabled = true;
30     enabled = mp_libHomeScreen->renderAppToAreaAllowed(appcategory, FULLSCREEN);
31     if(enabled)
32     {
33         QString target(getenv("AFM_APP_INSTALL_DIR"));
34         qDebug("AFM_APP_INSTALL_DIR is " + target.toLatin1());
35
36         if(NULL == target)
37         {
38             target = ".";
39         }
40
41         QString load_path;
42         load_path = target + "/imports";
43         engine.addImportPath(load_path);
44         load_path = target + "/dummyimports";
45         engine.addImportPath(load_path);
46         load_path = target + "/main.qml";
47
48         engine.load(QUrl(load_path));
49
50         std::vector<int> surfaceIdList;
51         int pid = getpid();
52         //maybe we can't call this function...
53         //surfaceIdList = mp_libHomeScreen->getAllSurfacesOfProcess(pid);
54         if(surfaceIdList.empty())
55         {
56             qDebug("surface list is empty");
57         }
58         else
59         {
60             qDebug("surface list is contained");
61             // it will be implemented as soon as possible
62             //mp_libHomeScreen->renderSurfaceToArea(surfaceIdList.at(0),FULLSCREEN);
63         }
64     }
65     else
66     {
67         qDebug("renderAppToAreaAllowed is denied");
68         delete mp_libHomeScreen;
69         return 0;
70     }
71
72     app.exec();
73     delete mp_libHomeScreen;
74     return 0;
75 }