File indexing completed on 2024-04-28 16:55:45

0001 /*
0002  * SPDX-FileCopyrightText: 2017 Red Hat Inc
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  *
0006  * SPDX-FileCopyrightText: 2017 Jan Grulich <jgrulich@redhat.com>
0007  */
0008 
0009 #include "inhibit.h"
0010 #include "inhibit_debug.h"
0011 
0012 #include <QDBusConnection>
0013 #include <QDBusMessage>
0014 #include <QDBusPendingCall>
0015 #include <QDBusPendingCallWatcher>
0016 #include <QDBusPendingReply>
0017 
0018 InhibitPortal::InhibitPortal(QObject *parent)
0019     : QDBusAbstractAdaptor(parent)
0020 {
0021 }
0022 
0023 InhibitPortal::~InhibitPortal()
0024 {
0025 }
0026 
0027 void InhibitPortal::Inhibit(const QDBusObjectPath &handle, const QString &app_id, const QString &window, uint flags, const QVariantMap &options)
0028 {
0029     qCDebug(XdgDesktopPortalKdeInhibit) << "Inhibit called with parameters:";
0030     qCDebug(XdgDesktopPortalKdeInhibit) << "    handle: " << handle.path();
0031     qCDebug(XdgDesktopPortalKdeInhibit) << "    app_id: " << app_id;
0032     qCDebug(XdgDesktopPortalKdeInhibit) << "    window: " << window;
0033     qCDebug(XdgDesktopPortalKdeInhibit) << "    flags: " << flags;
0034     qCDebug(XdgDesktopPortalKdeInhibit) << "    options: " << options;
0035 
0036     QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"),
0037                                                           QStringLiteral("/org/kde/Solid/PowerManagement/PolicyAgent"),
0038                                                           QStringLiteral("org.kde.Solid.PowerManagement.PolicyAgent"),
0039                                                           QStringLiteral("AddInhibition"));
0040     //         interrupt session (1)
0041     message << (uint)1 << app_id << options.value(QStringLiteral("reason")).toString();
0042 
0043     QDBusPendingCall pendingCall = QDBusConnection::sessionBus().asyncCall(message);
0044     QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall);
0045     connect(watcher, &QDBusPendingCallWatcher::finished, [handle, this](QDBusPendingCallWatcher *watcher) {
0046         QDBusPendingReply<uint> reply = *watcher;
0047         if (reply.isError()) {
0048             qCDebug(XdgDesktopPortalKdeInhibit) << "Inhibition error: " << reply.error().message();
0049         } else {
0050             QDBusConnection sessionBus = QDBusConnection::sessionBus();
0051             new Request(handle, this, QStringLiteral("org.freedesktop.impl.portal.Inhibit"), QVariant(reply.value()));
0052         }
0053     });
0054 }