homescreen/: Plug-in the launcher in the applicationlauncher
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 21 Jan 2020 21:55:01 +0000 (23:55 +0200)
committerMarius Vlad <marius.vlad@collabora.com>
Wed, 22 Jan 2020 10:24:03 +0000 (12:24 +0200)
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I12d17bfb130362fbe0381884d294f03fafc8833e

homescreen/src/applicationlauncher.cpp
homescreen/src/applicationlauncher.h
homescreen/src/main.cpp

index 5a1e2d6..bb9f646 100644 (file)
 
 #include "applicationlauncher.h"
 
-#include "afm_user_daemon_proxy.h"
-
 #include "hmi-debug.h"
 
-extern org::AGL::afm::user *afm_user_daemon_proxy;
-
-ApplicationLauncher::ApplicationLauncher(QObject *parent)
+ApplicationLauncher::ApplicationLauncher(const QString &conn_str, QObject *parent)
     : QObject(parent)
     , m_launching(false)
     , m_timeout(new QTimer(this))
@@ -43,6 +39,12 @@ ApplicationLauncher::ApplicationLauncher(QObject *parent)
     connect(this, &ApplicationLauncher::currentChanged, [&]() {
         setLaunching(false);
     });
+
+    m_launching = false;
+    m_launcher = new Launcher(conn_str, parent);
+
+    if (m_launcher->setup_pws_connection() != 0)
+           HMI_DEBUG("HomeScreen","ApplicationLauncher failed to set-up connection to afm-system-daemon");
 }
 
 int ApplicationLauncher::launch(const QString &application)
@@ -50,7 +52,9 @@ int ApplicationLauncher::launch(const QString &application)
     int result = -1;
     HMI_DEBUG("HomeScreen","ApplicationLauncher launch %s.", application.toStdString().c_str());
 
-    result = afm_user_daemon_proxy->start(application).value().toInt();
+    if (m_launcher->connection_is_set())
+           result = m_launcher->start(application);
+
     HMI_DEBUG("HomeScreen","ApplicationLauncher pid: %d.", result);
 
     if (result > 1) {
index dfa5846..e6ac183 100644 (file)
 #ifndef APPLICATIONLAUNCHER_H
 #define APPLICATIONLAUNCHER_H
 
+#include <QTimer>
 #include <QtCore/QObject>
 
+#include "launcher.h"
+
 class QTimer;
 
 class ApplicationLauncher : public QObject
@@ -29,7 +32,7 @@ class ApplicationLauncher : public QObject
     Q_PROPERTY(bool launching READ isLaunching NOTIFY launchingChanged)
     Q_PROPERTY(QString current READ current WRITE setCurrent NOTIFY currentChanged)
 public:
-    explicit ApplicationLauncher(QObject *parent = NULL);
+    explicit ApplicationLauncher(const QString &afm_conn_str, QObject *parent = NULL);
 
     bool isLaunching() const;
     QString current() const;
@@ -50,6 +53,7 @@ private:
     bool m_launching;
     QString m_current;
     QTimer *m_timeout;
+    Launcher *m_launcher;
 };
 
 #endif // APPLICATIONLAUNCHER_H
index 901799c..fb207f2 100644 (file)
@@ -24,6 +24,8 @@
 #include <QtQml/qqml.h>
 #include <QQuickWindow>
 #include <QScreen>
+#include <QUrlQuery>
+#include <QTimer>
 #include <qpa/qplatformnativeinterface.h>
 
 #include <cstdlib>
 #include <bluetooth.h>
 #include "applicationlauncher.h"
 #include "statusbarmodel.h"
-#include "afm_user_daemon_proxy.h"
 #include "mastervolume.h"
 #include "shell.h"
 #include "hmi-debug.h"
 
 #include "wayland-agl-shell-client-protocol.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;
-    }
-};
-
-}
+#define CONNECT_STR    "unix:/run/platform/apis/ws/afm-main"
 
 static void global_add(void *data, struct wl_registry *reg, uint32_t name,
                        const char *interface, uint32_t)
@@ -109,13 +97,6 @@ int main(int argc, char *argv[])
     }
     std::shared_ptr<struct agl_shell> shell{agl_shell, agl_shell_destroy};
 
-    // 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");
@@ -145,7 +126,7 @@ int main(int argc, char *argv[])
     qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel");
     qmlRegisterType<MasterVolume>("MasterVolume", 1, 0, "MasterVolume");
 
-    ApplicationLauncher *launcher = new ApplicationLauncher();
+    ApplicationLauncher *launcher = new ApplicationLauncher(CONNECT_STR, &a);
 
     QUrl bindingAddress;
     bindingAddress.setScheme(QStringLiteral("ws"));
@@ -157,31 +138,6 @@ int main(int argc, char *argv[])
     query.addQueryItem(QStringLiteral("token"), token);
     bindingAddress.setQuery(query);
 
-#if 0
-    // mail.qml loading
-    QQmlApplicationEngine engine;
-    engine.rootContext()->setContextProperty("bindingAddress", bindingAddress);
-    engine.rootContext()->setContextProperty("launcher", launcher);
-    engine.rootContext()->setContextProperty("weather", new Weather(bindingAddress));
-    engine.rootContext()->setContextProperty("bluetooth", new Bluetooth(bindingAddress, engine.rootContext()));
-    //engine.rootContext()->setContextProperty("screenInfo", &screenInfo);
-    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
-    engine.load(QUrl(QStringLiteral("qrc:/background.qml")));
-
-    auto root_objects = engine.rootObjects();
-    printf("num root objects: %d\n", root_objects.length());
-    QObject *root = engine.rootObjects().first();
-    QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
-
-    for (auto o : root_objects) {
-        qDebug() << o->dynamicPropertyNames();
-    }
-
-    QList<QObject *> sobjs = engine.rootObjects();
-    StatusBarModel *statusBar = sobjs.first()->findChild<StatusBarModel *>("statusBar");
-    statusBar->init(bindingAddress, engine.rootContext());
-#endif
-
     QQmlEngine engine;
     QQmlContext *context = engine.rootContext();
     context->setContextProperty("bindingAddress", bindingAddress);