File indexing completed on 2024-10-13 03:42:25

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 "fakeUpower.h"
0008 
0009 #include <QDBusConnection>
0010 #include <QDBusPendingCall>
0011 #include <qdbusmessage.h>
0012 
0013 FakeUpower::FakeUpower(QObject *parent)
0014     : QObject(parent)
0015     , m_onBattery(false)
0016 {
0017 }
0018 
0019 QString FakeUpower::daemonVersion() const
0020 {
0021     return "POP";
0022 }
0023 
0024 QString FakeUpower::GetCriticalAction()
0025 {
0026     return "AAAA";
0027 }
0028 
0029 QDBusObjectPath FakeUpower::GetDisplayDevice()
0030 {
0031     return QDBusObjectPath("AA");
0032 }
0033 
0034 bool FakeUpower::isDocked() const
0035 {
0036     return true;
0037 }
0038 
0039 bool FakeUpower::lidIsClosed() const
0040 {
0041     return false;
0042 }
0043 
0044 bool FakeUpower::lidIsPresent() const
0045 {
0046     return true;
0047 }
0048 
0049 bool FakeUpower::onBattery() const
0050 {
0051     return m_onBattery;
0052 }
0053 
0054 void FakeUpower::setOnBattery(bool onBattery)
0055 {
0056     m_onBattery = onBattery;
0057 
0058     emitPropertiesChanged(QStringLiteral("OnBattery"), m_onBattery);
0059 }
0060 
0061 void FakeUpower::emitPropertiesChanged(const QString &name, const QVariant &value)
0062 {
0063     auto msg = QDBusMessage::createSignal(QStringLiteral("/org/freedesktop/UPower"),
0064                                           QStringLiteral("org.freedesktop.DBus.Properties"),
0065                                           QStringLiteral("PropertiesChanged"));
0066 
0067     QVariantMap map;
0068     map.insert(name, value);
0069     QList<QVariant> args;
0070     args << QString("org.freedesktop.UPower");
0071     args << map;
0072     args << QStringList();
0073 
0074     msg.setArguments(args);
0075 
0076     QDBusConnection::systemBus().asyncCall(msg);
0077 }
0078 
0079 QList<QDBusObjectPath> FakeUpower::EnumerateDevices()
0080 {
0081     QList<QDBusObjectPath> list;
0082     return list;
0083 }
0084 
0085 #include "moc_fakeUpower.cpp"