refact: refact LaunchApp's implementation
Signed-off-by: ComixHe <heyuming@deepin.org> Signed-off-by: black-desk <me@black-desk.cn>
This commit is contained in:
parent
2fa74e40e5
commit
e3bfb1cc7a
@ -26,7 +26,7 @@ public:
|
|||||||
JobManager.interface(),
|
JobManager.interface(),
|
||||||
u8"JobNew",
|
u8"JobNew",
|
||||||
this,
|
this,
|
||||||
SLOT(onJobNew(QDBusObjectPath, QDBusObjectPath)))) {
|
SLOT(jobNewForward(QDBusObjectPath, QDBusObjectPath)))) {
|
||||||
qFatal() << "connect JobNew failed.";
|
qFatal() << "connect JobNew failed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,35 +35,63 @@ public:
|
|||||||
JobManager.interface(),
|
JobManager.interface(),
|
||||||
u8"JobRemoved",
|
u8"JobRemoved",
|
||||||
this,
|
this,
|
||||||
SLOT(onJobRemoved(QDBusObjectPath, QString, QVariantList)))) {
|
SLOT(jobRemovedForward(QDBusObjectPath, QString, QVariantList)))) {
|
||||||
qFatal() << "connect JobNew failed.";
|
qFatal() << "connect JobNew failed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(this, &Demo::applicationLaunched, [](QList<QString> 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<QString> apps;
|
||||||
|
for (const auto &app : result) {
|
||||||
|
apps.append(app.value<QString>());
|
||||||
|
}
|
||||||
|
emit applicationLaunched(apps);
|
||||||
|
});
|
||||||
|
|
||||||
|
auto reply =
|
||||||
|
ApplicationManager.callWithArgumentList(QDBus::Block, "Launch", {appId, QString{""}, QStringList{}, QVariantMap{}});
|
||||||
|
|
||||||
|
if (reply.type() == QDBusMessage::ReplyMessage) {
|
||||||
|
myJob = reply.arguments().first().value<QDBusObjectPath>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should be QList<QDBusObjectPath>
|
|
||||||
void launchApp(const QString &appId)
|
|
||||||
{
|
|
||||||
auto msg =
|
|
||||||
ApplicationManager.callWithArgumentList(QDBus::Block, "Launch", {appId, QString{""}, QStringList{}, QVariantMap{}});
|
|
||||||
qInfo() << "reply message:" << msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void onJobNew(QDBusObjectPath job, QDBusObjectPath source)
|
void jobNewForward(QDBusObjectPath job, QDBusObjectPath source)
|
||||||
{
|
{
|
||||||
qInfo() << "Job New ["
|
qInfo() << "Job New ["
|
||||||
<< "Job Path:" << job.path() << source.path() << "add this job].";
|
<< "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 ["
|
qInfo() << "Job Removed ["
|
||||||
<< "Job Path:" << job.path() << "Job Status:" << status << "result:" << result;
|
<< "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<QString> apps);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDBusInterface ApplicationManager;
|
QDBusInterface ApplicationManager;
|
||||||
QDBusInterface JobManager;
|
QDBusInterface JobManager;
|
||||||
|
QDBusObjectPath myJob;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
Loading…
Reference in New Issue
Block a user