/* * SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #ifndef DBUSHELPERS_H #define DBUSHELPERS_H #include #include #include template Q_REQUIRED_RESULT T blockOnReply(QDBusPendingReply reply) { reply.waitForFinished(); if (reply.isError()) { QTextStream(stderr) << i18n("error: ") << reply.error().message() << Qt::endl; exit(1); } return reply.value(); } void blockOnReply(QDBusPendingReply reply) { reply.waitForFinished(); if (reply.isError()) { QTextStream(stderr) << i18n("error: ") << reply.error().message() << Qt::endl; exit(1); } } template static void setWhenAvailable(const QDBusPendingReply &pending, W func, QObject *parent) { QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, parent); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, parent, [func](QDBusPendingCallWatcher *watcher) { watcher->deleteLater(); QDBusPendingReply reply = *watcher; func(reply.value()); }); } #endif