diff --git a/examples/launchApp/main.cpp b/examples/launchApp/main.cpp index b59f56b..64ab0eb 100644 --- a/examples/launchApp/main.cpp +++ b/examples/launchApp/main.cpp @@ -26,7 +26,7 @@ public: JobManager.interface(), u8"JobNew", this, - SLOT(onJobNew(QDBusObjectPath, QDBusObjectPath)))) { + SLOT(jobNewForward(QDBusObjectPath, QDBusObjectPath)))) { qFatal() << "connect JobNew failed."; } @@ -35,35 +35,63 @@ public: JobManager.interface(), u8"JobRemoved", this, - SLOT(onJobRemoved(QDBusObjectPath, QString, QVariantList)))) { + SLOT(jobRemovedForward(QDBusObjectPath, QString, QVariantList)))) { qFatal() << "connect JobNew failed."; } + + connect(this, &Demo::applicationLaunched, [](QList apps) { + qInfo() << "application launched:"; + for (const auto &app : apps) { + qInfo() << app; + }; + }); + } + + void launchApp(const QString &appId) + { + connect(this, &Demo::amJobRemoved, [this](QDBusObjectPath job, QString status, QVariantList result) { + if (myJob == job) { + qInfo() << "my job" << status << result; + } + QList apps; + for (const auto &app : result) { + apps.append(app.value()); + } + emit applicationLaunched(apps); + }); + + auto reply = + ApplicationManager.callWithArgumentList(QDBus::Block, "Launch", {appId, QString{""}, QStringList{}, QVariantMap{}}); + + if (reply.type() == QDBusMessage::ReplyMessage) { + myJob = reply.arguments().first().value(); + } } - // TODO: should be QList - void launchApp(const QString &appId) - { - auto msg = - ApplicationManager.callWithArgumentList(QDBus::Block, "Launch", {appId, QString{""}, QStringList{}, QVariantMap{}}); - qInfo() << "reply message:" << msg; - } - public Q_SLOTS: - void onJobNew(QDBusObjectPath job, QDBusObjectPath source) + void jobNewForward(QDBusObjectPath job, QDBusObjectPath source) { qInfo() << "Job New [" << "Job Path:" << job.path() << source.path() << "add this job]."; + emit amJobNew(job, source); } - void onJobRemoved(QDBusObjectPath job, QString status, QVariantList result) + void jobRemovedForward(QDBusObjectPath job, QString status, QVariantList result) { qInfo() << "Job Removed [" << "Job Path:" << job.path() << "Job Status:" << status << "result:" << result; + emit amJobRemoved(job, status, result); } +Q_SIGNALS: + void amJobNew(QDBusObjectPath job, QDBusObjectPath source); + void amJobRemoved(QDBusObjectPath job, QString status, QVariantList result); + void applicationLaunched(QList apps); + private: QDBusInterface ApplicationManager; QDBusInterface JobManager; + QDBusObjectPath myJob; }; int main(int argc, char *argv[])