X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=app%2Fmain.cpp;h=4c406e61fc78bd0a25eedade5a2f386aa891dfb4;hb=refs%2Fheads%2Fsandbox%2Fknimitz%2Fhmi-framework-to-latest;hp=5ad9577a0a9a4fca45e2e4978369ae13eeee658b;hpb=0f9e9e41961a896ad2dc2bb05fcd7f5d9ee9e26b;p=apps%2Fmediaplayer.git diff --git a/app/main.cpp b/app/main.cpp index 5ad9577..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,60 +26,25 @@ #include #include -#ifdef HAVE_LIBHOMESCREEN +#include +#include "qlibwindowmanager.h" +#include "qlibsoundmanager.h" #include -#endif -#include "playlistwithmetadata.h" - -#ifndef HAVE_LIGHTMEDIASCANNER -QVariantList readMusicFile(const QString &path) -{ - QVariantList ret; - QDir dir(path); - for (const auto &entry : dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) { - QFileInfo fileInfo(dir.absoluteFilePath(entry)); - if (fileInfo.isDir()) { - ret.append(readMusicFile(fileInfo.absoluteFilePath())); - } else if (fileInfo.isFile()) { - ret.append(QUrl::fromLocalFile(fileInfo.absoluteFilePath())); - } - } - return ret; -} -#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"); - qmlRegisterType("MediaPlayer", 1, 0, "PlaylistWithMetadata"); - QQmlApplicationEngine engine; QQmlContext *context = engine.rootContext(); -#ifndef HAVE_LIGHTMEDIASCANNER - QVariantList mediaFiles; - QString music; - - for (const auto &music : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) { - mediaFiles.append(readMusicFile(music)); - } - - context->setContextProperty("mediaFiles", mediaFiles); -#endif - QCommandLineParser parser; parser.addPositionalArgument("port", app.translate("main", "port for binding")); parser.addPositionalArgument("secret", app.translate("main", "secret for binding")); @@ -99,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(); }