Solid

fdpowernotifier.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
3 SPDX-FileCopyrightText: 2014 Lukáš Tinkl <ltinkl@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "fdpowernotifier.h"
9
10#include <QDBusConnection>
11#include <QDebug>
12
13Solid::FDPowerNotifier::FDPowerNotifier(QObject *parent)
14 : PowerNotifier(parent)
15{
16 auto conn = QDBusConnection::systemBus();
17 conn.connect(QStringLiteral("org.freedesktop.UPower"),
18 QStringLiteral("/org/freedesktop/UPower"),
19 QStringLiteral("org.freedesktop.DBus.Properties"),
20 QStringLiteral("PropertiesChanged"),
21 this,
22 SLOT(upowerPropertiesChanged(QString, QVariantMap, QStringList)));
23
24 conn.connect(QStringLiteral("org.freedesktop.login1"),
25 QStringLiteral("/org/freedesktop/login1"),
26 QStringLiteral("org.freedesktop.login1.Manager"),
27 QStringLiteral("PrepareForSleep"),
28 this,
29 SLOT(login1Resuming(bool)));
30}
31
32void Solid::FDPowerNotifier::upowerPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidated)
33{
34 if (interface != QStringLiteral("org.freedesktop.UPower")) {
35 return;
36 }
37
38 if (changedProperties.contains(QStringLiteral("OnBattery"))) {
39 Q_EMIT acPluggedChanged(!changedProperties.value(QStringLiteral("OnBattery")).toBool());
40 }
41
42 // Just for debug purposes
43 if (!invalidated.isEmpty()) {
44 qDebug() << "Invalidated" << invalidated;
45 }
46}
47
48void Solid::FDPowerNotifier::login1Resuming(bool active)
49{
50 if (active) {
51 Q_EMIT aboutToSuspend();
52 } else {
53 Q_EMIT resumeFromSuspend();
54 }
55}
56
57#include "moc_fdpowernotifier.cpp"
QDBusConnection systemBus()
bool isEmpty() const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:56:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.