File indexing completed on 2024-04-14 05:43:43
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Dimitris Kardarakos <dimkard@posteo.net> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "solidwakeupbackend.h" 0008 #include <QDBusInterface> 0009 #include <QDBusConnection> 0010 #include <QDBusReply> 0011 #include <QDebug> 0012 #include <QDateTime> 0013 0014 SolidWakeupBackend::SolidWakeupBackend(QObject *parent) : WakeupBackend {parent} 0015 { 0016 m_interface = new QDBusInterface {QStringLiteral("org.kde.Solid.PowerManagement"), QStringLiteral("/org/kde/Solid/PowerManagement"), QStringLiteral("org.kde.Solid.PowerManagement"), QDBusConnection::sessionBus(), this}; 0017 } 0018 0019 void SolidWakeupBackend::clearWakeup(const QVariant &scheduledWakeup) 0020 { 0021 m_interface->call(QStringLiteral("clearWakeup"), scheduledWakeup.toInt()); 0022 } 0023 0024 QVariant SolidWakeupBackend::scheduleWakeup(const QVariantMap &callbackInfo, const quint64 wakeupAt) 0025 { 0026 auto scheduledAt = QDateTime::fromSecsSinceEpoch(wakeupAt); 0027 0028 qDebug() << "SolidWakeupBackend::scheduleWakeup at" << scheduledAt.toString("dd.MM.yyyy hh:mm:ss") << "tz " << scheduledAt.timeZoneAbbreviation() << " epoch" << wakeupAt; 0029 0030 if (m_interface->isValid()) { 0031 QDBusReply<uint> reply = m_interface->call(QStringLiteral("scheduleWakeup"), callbackInfo["dbus-service"].toString(), QDBusObjectPath {callbackInfo["dbus-path"].toString()}, wakeupAt); 0032 return reply.value(); 0033 } 0034 0035 return 0; 0036 } 0037 0038 bool SolidWakeupBackend::isWakeupBackend() const 0039 { 0040 auto callMessage = QDBusMessage::createMethodCall(m_interface->service(), m_interface->path(), QStringLiteral("org.freedesktop.DBus.Introspectable"), QStringLiteral("Introspect")); 0041 QDBusReply<QString> result = QDBusConnection::sessionBus().call(callMessage); 0042 0043 if (result.isValid() && result.value().indexOf(QStringLiteral("scheduleWakeup")) >= 0) { 0044 return true; 0045 } 0046 0047 return false; 0048 }