homescreen: remove unused DBus code artifacts
[apps/homescreen.git] / homescreen / src / main.cpp
index 63edd54..b92ff60 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ * Copyright (c) 2017, 2018 TOYOTA MOTOR CORPORATION
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
 
 #include <QGuiApplication>
 #include <QCommandLineParser>
+#include <QtCore/QUrlQuery>
 #include <QtGui/QGuiApplication>
 #include <QtQml/QQmlApplicationEngine>
 #include <QtQml/QQmlContext>
 
 #include <qlibwindowmanager.h>
 #include <weather.h>
+#include <bluetooth.h>
 #include "applicationlauncher.h"
 #include "statusbarmodel.h"
-#include "afm_user_daemon_proxy.h"
 #include "mastervolume.h"
 #include "homescreenhandler.h"
 #include "hmi-debug.h"
-
-// XXX: We want this DBus connection to be shared across the different
-// QML objects, is there another way to do this, a nice way, perhaps?
-org::AGL::afm::user *afm_user_daemon_proxy;
-
-namespace {
-
-struct Cleanup {
-    static inline void cleanup(org::AGL::afm::user *p) {
-        delete p;
-        afm_user_daemon_proxy = Q_NULLPTR;
-    }
-};
-
-void noOutput(QtMsgType, const QMessageLogContext &, const QString &)
-{
-}
-
-}
+#include "chromecontroller.h"
 
 int main(int argc, char *argv[])
 {
     QGuiApplication a(argc, argv);
 
-    // use launch process
-    QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user",
-                                                                                               "/org/AGL/afm/user",
-                                                                                               QDBusConnection::sessionBus(),
-                                                                                               0));
-    ::afm_user_daemon_proxy = afm_user_daemon_proxy.data();
-
     QCoreApplication::setOrganizationDomain("LinuxFoundation");
     QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
     QCoreApplication::setApplicationName("HomeScreen");
@@ -74,9 +50,10 @@ int main(int argc, char *argv[])
     parser.addVersionOption();
     parser.process(a);
     QStringList positionalArguments = parser.positionalArguments();
-    
+
     int port = 1700;
     QString token = "wm";
+    QString graphic_role = "homescreen"; // defined in layers.json in Window Manager
 
     if (positionalArguments.length() == 2) {
         port = positionalArguments.takeFirst().toInt();
@@ -89,6 +66,8 @@ int main(int argc, char *argv[])
     // qmlRegisterType<ApplicationLauncher>("HomeScreen", 1, 0, "ApplicationLauncher");
     qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel");
     qmlRegisterType<MasterVolume>("MasterVolume", 1, 0, "MasterVolume");
+    qmlRegisterUncreatableType<ChromeController>("SpeechChrome", 1, 0, "SpeechChromeController",
+                                                 QLatin1String("SpeechChromeController is uncreatable."));
 
     ApplicationLauncher *launcher = new ApplicationLauncher();
     QLibWindowmanager* layoutHandler = new QLibWindowmanager();
@@ -96,12 +75,14 @@ int main(int argc, char *argv[])
         exit(EXIT_FAILURE);
     }
 
-    if (layoutHandler->requestSurface(QString("HomeScreen")) != 0) {
+    AGLScreenInfo screenInfo(layoutHandler->get_scale_factor());
+
+    if (layoutHandler->requestSurface(graphic_role) != 0) {
         exit(EXIT_FAILURE);
     }
 
-    layoutHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [layoutHandler](json_object *object) {
-        layoutHandler->endDraw(QString("HomeScreen"));
+    layoutHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [layoutHandler, &graphic_role](json_object *object) {
+        layoutHandler->endDraw(graphic_role);
     });
 
     layoutHandler->set_event_handler(QLibWindowmanager::Event_ScreenUpdated, [layoutHandler, launcher](json_object *object) {
@@ -130,18 +111,23 @@ int main(int argc, char *argv[])
 
     // mail.qml loading
     QQmlApplicationEngine engine;
+    engine.rootContext()->setContextProperty("bindingAddress", bindingAddress);
     engine.rootContext()->setContextProperty("layoutHandler", layoutHandler);
     engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler);
     engine.rootContext()->setContextProperty("launcher", launcher);
     engine.rootContext()->setContextProperty("weather", new Weather(bindingAddress));
+    engine.rootContext()->setContextProperty("bluetooth", new Bluetooth(bindingAddress, engine.rootContext()));
+    engine.rootContext()->setContextProperty("speechChromeController", new ChromeController(bindingAddress, &engine));
+    engine.rootContext()->setContextProperty("screenInfo", &screenInfo);
     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
 
     QObject *root = engine.rootObjects().first();
     QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
     QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface()));
 
-    // start homescreen appplications
-    launcher->launch("launcher@0.1");   //Launcher
+    QList<QObject *> sobjs = engine.rootObjects();
+    StatusBarModel *statusBar = sobjs.first()->findChild<StatusBarModel *>("statusBar");
+    statusBar->init(bindingAddress, engine.rootContext());
 
     return a.exec();
 }