/*
* Copyright (C) 2016 The Qt Company Ltd.
+ * Copyright (C) 2016, 2017 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.
#include <QtQml/qqml.h>
#include <QtQuickControls2/QQuickStyle>
-#ifdef HAVE_LIBHOMESCREEN
+#include <QQuickWindow>
+#include "qlibwindowmanager.h"
+#include "qlibsoundmanager.h"
#include <libhomescreen.hpp>
-#endif
+
+static LibHomeScreen* hs;
+static QLibWindowmanager* qwm;
+static QLibSoundmanager* smw;
+static std::string myname = std::string("MediaPlayer");
int main(int argc, char *argv[])
{
-#ifdef HAVE_LIBHOMESCREEN
- LibHomeScreen libHomeScreen;
-
- if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
- qWarning() << "renderAppToAreaAllowed is denied";
- return -1;
- }
-#endif
-
QGuiApplication app(argc, argv);
QQuickStyle::setStyle("AGL");
query.addQueryItem(QStringLiteral("token"), secret);
bindingAddress.setQuery(query);
context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
+
+ std::string token = secret.toStdString();
+
+ hs = new LibHomeScreen();
+ qwm = new QLibWindowmanager();
+ smw = new QLibSoundmanager();
+
+ // WindowManager
+ if(qwm->init(port,secret) != 0){
+ exit(EXIT_FAILURE);
+ }
+ if (qwm->requestSurface(myname.c_str()) != 0) {
+ exit(EXIT_FAILURE);
+ }
+ qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm](json_object *object) {
+ fprintf(stderr, "Surface got syncDraw!\n");
+ qwm->endDraw(myname.c_str());
+ });
+ qwm->set_event_handler(QLibWindowmanager::Event_FlushDraw, [&engine, smw](json_object *object) {
+ fprintf(stderr, "Surface got flushDraw!\n");
+ QObject *root = engine.rootObjects().first();
+ int sourceID = root->property("sourceID").toInt();
+ smw->connect(sourceID, "default");
+ });
+
+ // HomeScreen
+ hs->init(port, token.c_str());
+ hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm](json_object *object){
+ const char *appname = json_object_get_string(
+ json_object_object_get(object, "application_name"));
+ if(myname == appname)
+ {
+ qDebug("Surface %s got tapShortcut\n", appname);
+ qwm->activateSurface(myname.c_str());
+ }
+ });
+
+ // SoundManager, event handler is set inside smw
+ smw->init(port, secret);
+
+ engine.rootContext()->setContextProperty("smw",smw);
+
}
engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));
+ QObject *root = engine.rootObjects().first();
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
+ QObject::connect(window, SIGNAL(frameSwapped()),
+ qwm, SLOT(slotActivateSurface())); // This should be disconnected, but when...
+ QObject::connect(smw, SIGNAL(reply(QVariant)),
+ root, SLOT(slotReply(QVariant)));
+ QObject::connect(smw, SIGNAL(event(QVariant, QVariant)),
+ root, SLOT(slotEvent(QVariant, QVariant)));
return app.exec();
}