31 #include <QDBusConnection>
32 #include <QDBusMessage>
33 #include <QDBusPendingCall>
34 #include <QDBusPendingReply>
39 if (!QDBusConnection::sessionBus().isConnected()) {
40 qDebug(
"D-Bus: Could not connect to session bus");
62 qDebug(
"D-Bus: PowerManagementInhibitor: Requesting idle");
66 call = QDBusMessage::createMethodCall(
67 "org.freedesktop.PowerManagement",
68 "/org/freedesktop/PowerManagement/Inhibit",
69 "org.freedesktop.PowerManagement.Inhibit",
72 call = QDBusMessage::createMethodCall(
73 "org.gnome.SessionManager",
74 "/org/gnome/SessionManager",
75 "org.gnome.SessionManager",
82 call.setArguments(
args);
84 QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
85 auto *watcher =
new QDBusPendingCallWatcher(pcall,
this);
96 qDebug(
"D-Bus: PowerManagementInhibitor: Requesting busy");
100 call = QDBusMessage::createMethodCall(
101 "org.freedesktop.PowerManagement",
102 "/org/freedesktop/PowerManagement/Inhibit",
103 "org.freedesktop.PowerManagement.Inhibit",
106 call = QDBusMessage::createMethodCall(
107 "org.gnome.SessionManager",
108 "/org/gnome/SessionManager",
109 "org.gnome.SessionManager",
114 QList<QVariant>
args;
115 args <<
"qBittorrent";
117 args <<
"Active torrents are presented";
119 call.setArguments(
args);
121 QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
122 auto *watcher =
new QDBusPendingCallWatcher(pcall,
this);
129 QDBusPendingReply<> reply = *call;
131 if (reply.isError()) {
132 qDebug(
"D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message()));
137 qDebug(
"D-Bus: PowerManagementInhibitor: Request successful");
143 QDBusPendingReply<uint> reply = *call;
145 if (reply.isError()) {
146 qDebug(
"D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message()));
149 qDebug(
"D-Bus: Falling back to org.gnome.SessionManager");
162 qDebug(
"D-Bus: PowerManagementInhibitor: Request successful, cookie is %d",
m_cookie);
168 qDebug(
"D-Bus: Unexpected reply in state %d",
m_state);
enum State m_intendedState
virtual ~PowerManagementInhibitor()
PowerManagementInhibitor(QObject *parent=nullptr)
void onAsyncReply(QDBusPendingCallWatcher *call)