641c38f0ff6be85e9431270b00d90e6b9ba86333
[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 "usermanagement.h"
30 #include "appinfo.h"
31 #include "afm_user_daemon_proxy.h"
32
33 // XXX: We want this DBus connection to be shared across the different
34 // QML objects, is there another way to do this, a nice way, perhaps?
35 org::AGL::afm::user *afm_user_daemon_proxy;
36
37 namespace {
38
39 struct Cleanup {
40     static inline void cleanup(org::AGL::afm::user *p) {
41         delete p;
42         afm_user_daemon_proxy = Q_NULLPTR;
43     }
44 };
45
46 void noOutput(QtMsgType, const QMessageLogContext &, const QString &)
47 {
48 }
49
50 }
51
52 int main(int argc, char *argv[])
53 {
54     QGuiApplication a(argc, argv);
55
56     QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user",
57                                                                                                "/org/AGL/afm/user",
58                                                                                                QDBusConnection::sessionBus(),
59                                                                                                0));
60     ::afm_user_daemon_proxy = afm_user_daemon_proxy.data();
61
62     QCoreApplication::setOrganizationDomain("LinuxFoundation");
63     QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
64     QCoreApplication::setApplicationName("HomeScreen");
65     QCoreApplication::setApplicationVersion("0.7.0");
66
67     QCommandLineParser parser;
68     parser.setApplicationDescription("AGL HomeScreen - see wwww... for more details");
69     parser.addHelpOption();
70     parser.addVersionOption();
71     QCommandLineOption quietOption(QStringList() << "q" << "quiet",
72         QCoreApplication::translate("main", "Be quiet. No outputs."));
73     parser.addOption(quietOption);
74     parser.process(a);
75
76     if (parser.isSet(quietOption))
77     {
78         qInstallMessageHandler(noOutput);
79     }
80
81     qDBusRegisterMetaType<AppInfo>();
82     qDBusRegisterMetaType<QList<AppInfo> >();
83
84     qmlRegisterType<ApplicationLauncher>("HomeScreen", 1, 0, "ApplicationLauncher");
85     qmlRegisterType<ApplicationModel>("Home", 1, 0, "ApplicationModel");
86     qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel");
87
88     QQmlApplicationEngine engine;
89
90     LayoutHandler* layoutHandler = new LayoutHandler();
91
92     HomeScreenControlInterface* hsci = new HomeScreenControlInterface();
93     QObject::connect(hsci, SIGNAL(newRequestGetSurfaceStatus(int)), layoutHandler, SLOT(requestGetSurfaceStatus(int)));
94     QObject::connect(hsci, SIGNAL(newRequestsToBeVisibleApp(int)), layoutHandler, SLOT(makeMeVisible(int)));
95     QObject::connect(hsci, SIGNAL(newRequestRenderSurfaceToArea(int, int)), layoutHandler, SLOT(requestRenderSurfaceToArea(int,int)));
96     QObject::connect(hsci, SIGNAL(newRequestRenderSurfaceToAreaAllowed(int, int)), layoutHandler, SLOT(requestRenderSurfaceToAreaAllowed(int,int)));
97     QObject::connect(hsci, SIGNAL(newRequestSurfaceIdToFullScreen(int)), layoutHandler, SLOT(requestSurfaceIdToFullScreen(int)));
98
99     engine.rootContext()->setContextProperty("layoutHandler", layoutHandler);
100
101     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
102     UserManagement userManagement(engine.rootObjects().first());
103     Q_UNUSED(userManagement);
104     return a.exec();
105 }