X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=app%2Fmain.cpp;h=4c406e61fc78bd0a25eedade5a2f386aa891dfb4;hb=61a5af3ee61d017dd3c9dd2c23a41fbfde37fb6b;hp=c3e0fb0429108c4b380e1a0054440b1b38d8e324;hpb=92e613114ff5212fa7e5c2a226e32b6e252c9a9c;p=apps%2Fmediaplayer.git diff --git a/app/main.cpp b/app/main.cpp index c3e0fb0..4c406e6 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,5 +1,6 @@ /* * 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. @@ -25,21 +26,18 @@ #include #include -#ifdef HAVE_LIBHOMESCREEN +#include +#include "qlibwindowmanager.h" +#include "qlibsoundmanager.h" #include -#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"); @@ -67,9 +65,59 @@ int main(int argc, char *argv[]) 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(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(); }