File indexing completed on 2024-05-05 04:01:20
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "fdacpluggedjob.h" 0008 0009 #include <QDBusConnection> 0010 #include <QDBusMessage> 0011 #include <QDBusVariant> 0012 0013 using namespace Solid; 0014 0015 FDAcPluggedJob::FDAcPluggedJob(QObject *parent) 0016 : AbstractAcPluggedJob(parent) 0017 , m_isPlugged(false) 0018 { 0019 } 0020 0021 void FDAcPluggedJob::doStart() 0022 { 0023 QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.UPower"), 0024 QStringLiteral("/org/freedesktop/UPower"), 0025 QStringLiteral("org.freedesktop.DBus.Properties"), 0026 QStringLiteral("Get")); 0027 0028 msg << QStringLiteral("org.freedesktop.UPower"); 0029 msg << QStringLiteral("OnBattery"); 0030 0031 QDBusConnection::systemBus().callWithCallback(msg, this, SLOT(slotDBusReply(QDBusMessage)), SLOT(slotDBusError(QDBusError))); 0032 } 0033 0034 void FDAcPluggedJob::slotDBusReply(const QDBusMessage &msg) 0035 { 0036 Q_ASSERT(!msg.arguments().isEmpty()); 0037 0038 m_isPlugged = !msg.arguments().first().value<QDBusVariant>().variant().toBool(); 0039 emitResult(); 0040 } 0041 0042 void FDAcPluggedJob::slotDBusError(const QDBusError &error) 0043 { 0044 setError(error.type()); 0045 setErrorText(error.message()); 0046 emitResult(); 0047 } 0048 0049 bool FDAcPluggedJob::isPlugged() const 0050 { 0051 return m_isPlugged; 0052 } 0053 0054 #include "moc_fdacpluggedjob.cpp"