blob: b730f38bdbdc94ccc057c9ba69894302ad06c451 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include "sleepnotifier.hpp"
#include <QtDBus/qdbusconnection.h>
#include <QtDBus/qdbuserror.h>
namespace caelestia::internal {
SleepNotifier::SleepNotifier(QObject* parent)
: QObject(parent) {
auto bus = QDBusConnection::systemBus();
if (!bus.isConnected()) {
qWarning() << "SleepNotifier::SleepNotifier: failed to connect to system bus:" << bus.lastError().message();
return;
}
const bool ok = bus.connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager",
"PrepareForSleep", this, SLOT(handlePrepareForSleep(bool)));
if (!ok) {
qWarning() << "SleepNotifier::SleepNotifier: failed to connect to dbus:" << bus.lastError().message();
}
}
void SleepNotifier::handlePrepareForSleep(bool sleep) {
if (sleep) {
emit aboutToSleep();
} else {
emit resumed();
}
}
} // namespace caelestia::internal
|