2 * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <QGuiApplication>
18 #include <QCommandLineParser>
19 #include <QtGui/QGuiApplication>
20 #include <QtQml/QQmlApplicationEngine>
21 #include <QtQml/QQmlContext>
22 #include <QtQml/qqml.h>
24 #include "layouthandler.h"
25 #include "homescreencontrolinterface.h"
26 #include "applicationlauncher.h"
27 #include "statusbarmodel.h"
28 #include "applicationmodel.h"
30 #include "afm_user_daemon_proxy.h"
31 #include "mastervolume.h"
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;
41 static inline void cleanup(org::AGL::afm::user *p) {
43 afm_user_daemon_proxy = Q_NULLPTR;
47 void noOutput(QtMsgType, const QMessageLogContext &, const QString &)
53 int main(int argc, char *argv[])
55 QGuiApplication a(argc, argv);
57 QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user",
59 QDBusConnection::sessionBus(),
61 ::afm_user_daemon_proxy = afm_user_daemon_proxy.data();
63 QCoreApplication::setOrganizationDomain("LinuxFoundation");
64 QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
65 QCoreApplication::setApplicationName("HomeScreen");
66 QCoreApplication::setApplicationVersion("0.7.0");
68 QCommandLineParser parser;
69 parser.setApplicationDescription("AGL HomeScreen - see wwww... for more details");
70 parser.addHelpOption();
71 parser.addVersionOption();
72 QCommandLineOption quietOption(QStringList() << "q" << "quiet",
73 QCoreApplication::translate("main", "Be quiet. No outputs."));
74 parser.addOption(quietOption);
77 if (parser.isSet(quietOption))
79 qInstallMessageHandler(noOutput);
82 // Fire up PA client QThread
83 QThread* pat = new QThread;
84 PaClient* client = new PaClient();
85 client->moveToThread(pat);
88 qDBusRegisterMetaType<AppInfo>();
89 qDBusRegisterMetaType<QList<AppInfo> >();
91 qmlRegisterType<ApplicationLauncher>("HomeScreen", 1, 0, "ApplicationLauncher");
92 qmlRegisterType<ApplicationModel>("Home", 1, 0, "ApplicationModel");
93 qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel");
94 qmlRegisterType<MasterVolume>("MasterVolume", 1, 0, "MasterVolume");
96 QQmlApplicationEngine engine;
98 LayoutHandler* layoutHandler = new LayoutHandler();
100 HomeScreenControlInterface* hsci = new HomeScreenControlInterface();
102 QObject::connect(hsci, SIGNAL(newRequestGetSurfaceStatus(int)), layoutHandler, SLOT(requestGetSurfaceStatus(int)));
103 QObject::connect(hsci, SIGNAL(newRequestsToBeVisibleApp(int)), layoutHandler, SLOT(makeMeVisible(int)));
104 QObject::connect(hsci, SIGNAL(newRequestRenderSurfaceToArea(int, int)), layoutHandler, SLOT(requestRenderSurfaceToArea(int,int)));
105 QObject::connect(hsci, SIGNAL(newRequestRenderSurfaceToAreaAllowed(int, int)), layoutHandler, SLOT(requestRenderSurfaceToAreaAllowed(int,int)));
106 QObject::connect(hsci, SIGNAL(newRequestSurfaceIdToFullScreen(int)), layoutHandler, SLOT(requestSurfaceIdToFullScreen(int)));
108 engine.rootContext()->setContextProperty("layoutHandler", layoutHandler);
110 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
112 QList<QObject *> mobjs = engine.rootObjects();
113 MasterVolume *mv = mobjs.first()->findChild<MasterVolume *>("mv");
114 engine.rootContext()->setContextProperty("MasterVolume", mv);
115 QObject::connect(mv, SIGNAL(sliderVolumeChanged(int)), client, SLOT(incDecVolume(int)));
116 QObject::connect(client, SIGNAL(volumeExternallyChanged(int)), mv, SLOT(changeExternalVolume(int)));
118 // Initalize PA client