delete sleep 1sec
[apps/launcher.git] / launcher / src / main.cpp
index 50f1303..1d324b2 100644 (file)
 #include <QtQml/QQmlContext>
 #include <QtQml/qqml.h>
 #include <QQuickWindow>
+#include <QThread>
 
 #include <qlibwindowmanager.h>
 #include "applicationlauncher.h"
 #include "applicationmodel.h"
 #include "appinfo.h"
 #include "afm_user_daemon_proxy.h"
-#include "qlibhomescreen.h"
+#include "homescreenhandler.h"
+#include "shortcutappmodel.h"
 #include "hmi-debug.h"
 
 // XXX: We want this DBus connection to be shared across the different
@@ -87,18 +89,21 @@ int main(int argc, char *argv[])
 
     // import C++ class to QML
     qmlRegisterType<ApplicationModel>("AppModel", 1, 0, "ApplicationModel");
+    qmlRegisterType<ShortcutAppModel>("ShortcutAppModel", 1, 0, "ShortcutAppModel");
 
     // DBus
     qDBusRegisterMetaType<AppInfo>();
     qDBusRegisterMetaType<QList<AppInfo> >();
 
-    QLibHomeScreen* homescreenHandler = new QLibHomeScreen();
     ApplicationLauncher *launcher = new ApplicationLauncher();
     QLibWindowmanager* layoutHandler = new QLibWindowmanager();
+    ShortcutAppModel* shortcutAppModel = new ShortcutAppModel();
     if(layoutHandler->init(port,token) != 0){
         exit(EXIT_FAILURE);
     }
 
+//    AGLScreenInfo screenInfo(layoutHandler->get_scale_factor());
+
     if (layoutHandler->requestSurface(myname) != 0) {
         exit(EXIT_FAILURE);
     }
@@ -118,20 +123,9 @@ int main(int argc, char *argv[])
         HMI_DEBUG("launch", "surface %s Event_Invisible", label);
     });
 
-    homescreenHandler->init(port, token.toStdString().c_str());
-
-    homescreenHandler->set_event_handler(QLibHomeScreen::Event_TapShortcut, [layoutHandler, myname](json_object *object){
-        json_object *appnameJ = nullptr;
-        if(json_object_object_get_ex(object, "application_name", &appnameJ))
-        {
-            const char *appname = json_object_get_string(appnameJ);
-            if(myname == appname)
-            {
-                qDebug("Surface %s got tapShortcut\n", appname);
-                layoutHandler->activateSurface(myname);
-            }
-        }
-    });
+    HomescreenHandler* homescreenHandler = new HomescreenHandler();
+    QObject::connect(homescreenHandler, SIGNAL(updateShortcutList(QStringList)), shortcutAppModel, SLOT(shortcutUpdate(QStringList)));
+    homescreenHandler->init(port, token.toStdString().c_str(), layoutHandler, myname);
 
     QUrl bindingAddress;
     bindingAddress.setScheme(QStringLiteral("ws"));
@@ -145,14 +139,17 @@ int main(int argc, char *argv[])
 
     // mail.qml loading
     QQmlApplicationEngine engine;
-    engine.rootContext()->setContextProperty("layoutHandler", layoutHandler);
-    engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler);
-    engine.rootContext()->setContextProperty("launcher", launcher);
+    engine.rootContext()->setContextProperty(QStringLiteral("layoutHandler"), layoutHandler);
+    engine.rootContext()->setContextProperty(QStringLiteral("homescreenHandler"), homescreenHandler);
+    engine.rootContext()->setContextProperty(QStringLiteral("launcher"), launcher);
+//    engine.rootContext()->setContextProperty(QStringLiteral("screenInfo"), &screenInfo);
+    engine.rootContext()->setContextProperty(QStringLiteral("shortcutAppModel"), shortcutAppModel);
     engine.load(QUrl(QStringLiteral("qrc:/Launcher.qml")));
+    homescreenHandler->getRunnables();
 
     QObject *root = engine.rootObjects().first();
     QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
-    QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface()));
+    homescreenHandler->setQuickWindow(window);
 
     return a.exec();
 }