PoC: Qt Compositor-ized homescreen
[apps/homescreen.git] / homescreen / src / main.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 <QGuiApplication>
18 #include <QCommandLineParser>
19 #include <QtGui/QGuiApplication>
20 #include <QtQml/QQmlApplicationEngine>
21 #include <QtQml/QQmlContext>
22 #include <QtQml/qqml.h>
23
24 #include "layouthandler.h"
25 #include "homescreencontrolinterface.h"
26 #include "applicationlauncher.h"
27 #include "statusbarmodel.h"
28 #include "applicationmodel.h"
29 #include "appinfo.h"
30 #include "afm_user_daemon_proxy.h"
31 #include "mastervolume.h"
32 #include "paclient.h"
33
34 // XXX: We want this DBus connection to be shared across the different
35 // QML objects, is there another way to do this, a nice way, perhaps?
36 org::AGL::afm::user *afm_user_daemon_proxy;
37
38 namespace {
39
40 struct Cleanup {
41     static inline void cleanup(org::AGL::afm::user *p) {
42         delete p;
43         afm_user_daemon_proxy = Q_NULLPTR;
44     }
45 };
46
47 void noOutput(QtMsgType, const QMessageLogContext &, const QString &)
48 {
49 }
50
51 }
52
53 int main(int argc, char *argv[])
54 {
55     qputenv("QT_QPA_PLATFORM", "eglfs");
56     qputenv("QT_QPA_EGLFS_INTEGRATION","eglfs_kms");
57     qputenv("QT_QPA_EGLFS_KMS_CONFIG","/home/root/kmsconfig");
58
59     QGuiApplication app(argc, argv);
60
61     QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user",
62                                                                                                "/org/AGL/afm/user",
63                                                                                                QDBusConnection::sessionBus(),
64                                                                                                0));
65     ::afm_user_daemon_proxy = afm_user_daemon_proxy.data();
66
67     QCoreApplication::setOrganizationDomain("LinuxFoundation");
68     QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
69     QCoreApplication::setApplicationName("HomeScreen");
70     QCoreApplication::setApplicationVersion("0.7.0");
71
72     QCommandLineParser parser;
73     parser.setApplicationDescription("AGL HomeScreen - see wwww... for more details");
74     parser.addHelpOption();
75     parser.addVersionOption();
76     QCommandLineOption quietOption(QStringList() << "q" << "quiet",
77         QCoreApplication::translate("main", "Be quiet. No outputs."));
78     parser.addOption(quietOption);
79     parser.process(app);
80
81     if (parser.isSet(quietOption))
82     {
83         qInstallMessageHandler(noOutput);
84     }
85
86     // Fire up PA client QThread
87     QThread* pat = new QThread;
88     PaClient* client = new PaClient();
89     client->moveToThread(pat);
90     pat->start();
91
92     qDBusRegisterMetaType<AppInfo>();
93     qDBusRegisterMetaType<QList<AppInfo> >();
94
95     qmlRegisterType<ApplicationLauncher>("HomeScreen", 1, 0, "ApplicationLauncher");
96     qmlRegisterType<ApplicationModel>("Home", 1, 0, "ApplicationModel");
97     qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel");
98     qmlRegisterType<MasterVolume>("MasterVolume", 1, 0, "MasterVolume");
99
100     QQmlApplicationEngine engine;
101
102     LayoutHandler* layoutHandler = new LayoutHandler();
103
104     HomeScreenControlInterface* hsci = new HomeScreenControlInterface();
105
106     QObject::connect(hsci, SIGNAL(newRequestGetSurfaceStatus(int)), layoutHandler, SLOT(requestGetSurfaceStatus(int)));
107     QObject::connect(hsci, SIGNAL(newRequestsToBeVisibleApp(int)), layoutHandler, SLOT(makeMeVisible(int)));
108     QObject::connect(hsci, SIGNAL(newRequestRenderSurfaceToArea(int, int)), layoutHandler, SLOT(requestRenderSurfaceToArea(int,int)));
109     QObject::connect(hsci, SIGNAL(newRequestRenderSurfaceToAreaAllowed(int, int)), layoutHandler, SLOT(requestRenderSurfaceToAreaAllowed(int,int)));
110     QObject::connect(hsci, SIGNAL(newRequestSurfaceIdToFullScreen(int)), layoutHandler, SLOT(requestSurfaceIdToFullScreen(int)));
111
112     engine.rootContext()->setContextProperty("layoutHandler", layoutHandler);
113
114     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
115
116     QList<QObject *> mobjs = engine.rootObjects();
117     MasterVolume *mv = mobjs.first()->findChild<MasterVolume *>("mv");
118     engine.rootContext()->setContextProperty("MasterVolume", mv);
119     QObject::connect(mv, SIGNAL(sliderVolumeChanged(int)), client, SLOT(incDecVolume(int)));
120     QObject::connect(client, SIGNAL(volumeExternallyChanged(int)), mv, SLOT(changeExternalVolume(int)));
121
122     // Initalize PA client
123     client->init();
124
125     QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit);
126     return app.exec();
127 }