Use async call in closeNotification

This commit is contained in:
Loren Burkholder 2021-01-20 16:09:25 -05:00
parent ac36e92447
commit 1479743e70
1 changed files with 18 additions and 18 deletions

View File

@ -75,19 +75,17 @@ NotificationsManager::postNotification(const QString &roomid,
static QDBusInterface notifyApp("org.freedesktop.Notifications", static QDBusInterface notifyApp("org.freedesktop.Notifications",
"/org/freedesktop/Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications"); "org.freedesktop.Notifications");
auto call = notifyApp.asyncCallWithArgumentList("Notify", argumentList); auto call = notifyApp.asyncCallWithArgumentList("Notify", argumentList);
auto watcher = new QDBusPendingCall{QDBusPendingReply{call}}; auto watcher = new QDBusPendingCallWatcher{QDBusPendingCall{QDBusPendingReply{call}}};
connect(watcher, connect(
&QDBusPendingCallWatcher::finished, watcher, &QDBusPendingCallWatcher::finished, this, [watcher, this, &roomid, &eventid]() {
this, if (watcher->reply().type() == QDBusMessage::ErrorMessage)
[watcher, this, &roomid, &eventid]() { qDebug() << "D-Bus Error:" << watcher->reply().errorMessage();
if (watcher->reply().type() == QDBusMessage::ErrorMessage) else
qDebug() << "D-Bus Error:" << watcher.reply().errorMessage(); notificationIds[watcher->reply().arguments().first().toUInt()] =
else roomEventId{roomid, eventid};
notificationIds[watcher->reply().arguments().first().toUInt()] = delete watcher;
roomEventId{roomid, eventid}; });
delete watcher;
});
} }
void void
@ -99,11 +97,13 @@ NotificationsManager::closeNotification(uint id)
static QDBusInterface closeCall("org.freedesktop.Notifications", static QDBusInterface closeCall("org.freedesktop.Notifications",
"/org/freedesktop/Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications"); "org.freedesktop.Notifications");
QDBusMessage reply = auto call = closeCall.asyncCallWithArgumentList("CloseNotification", argumentList);
closeCall.callWithArgumentList(QDBus::AutoDetect, "CloseNotification", argumentList); auto watcher = new QDBusPendingCallWatcher{QDBusPendingCall{QDBusPendingReply{call}}};
if (reply.type() == QDBusMessage::ErrorMessage) { connect(watcher, &QDBusPendingCallWatcher::finished, this, [watcher, this]() {
qDebug() << "D-Bus Error:" << reply.errorMessage(); if (watcher->reply().type() == QDBusMessage::ErrorMessage) {
} qDebug() << "D-Bus Error:" << watcher->reply().errorMessage();
};
});
} }
void void