File indexing completed on 2024-04-28 04:00:49
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org> 0003 SPDX-FileCopyrightText: 2014 Lukáš Tinkl <ltinkl@redhat.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "fdpowernotifier.h" 0009 0010 #include <QDBusConnection> 0011 #include <QDebug> 0012 0013 Solid::FDPowerNotifier::FDPowerNotifier(QObject *parent) 0014 : PowerNotifier(parent) 0015 { 0016 auto conn = QDBusConnection::systemBus(); 0017 conn.connect(QStringLiteral("org.freedesktop.UPower"), 0018 QStringLiteral("/org/freedesktop/UPower"), 0019 QStringLiteral("org.freedesktop.DBus.Properties"), 0020 QStringLiteral("PropertiesChanged"), 0021 this, 0022 SLOT(upowerPropertiesChanged(QString, QVariantMap, QStringList))); 0023 0024 conn.connect(QStringLiteral("org.freedesktop.login1"), 0025 QStringLiteral("/org/freedesktop/login1"), 0026 QStringLiteral("org.freedesktop.login1.Manager"), 0027 QStringLiteral("PrepareForSleep"), 0028 this, 0029 SLOT(login1Resuming(bool))); 0030 } 0031 0032 void Solid::FDPowerNotifier::upowerPropertiesChanged(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidated) 0033 { 0034 if (interface != QStringLiteral("org.freedesktop.UPower")) { 0035 return; 0036 } 0037 0038 if (changedProperties.contains(QStringLiteral("OnBattery"))) { 0039 Q_EMIT acPluggedChanged(!changedProperties.value(QStringLiteral("OnBattery")).toBool()); 0040 } 0041 0042 // Just for debug purposes 0043 if (!invalidated.isEmpty()) { 0044 qDebug() << "Invalidated" << invalidated; 0045 } 0046 } 0047 0048 void Solid::FDPowerNotifier::login1Resuming(bool active) 0049 { 0050 if (active) { 0051 Q_EMIT aboutToSuspend(); 0052 } else { 0053 Q_EMIT resumeFromSuspend(); 0054 } 0055 } 0056 0057 #include "moc_fdpowernotifier.cpp"