Solid

fdacpluggedjob.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "fdacpluggedjob.h"
8
9#include <QDBusConnection>
10#include <QDBusMessage>
11#include <QDBusVariant>
12
13using namespace Solid;
14
15FDAcPluggedJob::FDAcPluggedJob(QObject *parent)
16 : AbstractAcPluggedJob(parent)
17 , m_isPlugged(false)
18{
19}
20
21void FDAcPluggedJob::doStart()
22{
23 QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.UPower"),
24 QStringLiteral("/org/freedesktop/UPower"),
25 QStringLiteral("org.freedesktop.DBus.Properties"),
26 QStringLiteral("Get"));
27
28 msg << QStringLiteral("org.freedesktop.UPower");
29 msg << QStringLiteral("OnBattery");
30
31 QDBusConnection::systemBus().callWithCallback(msg, this, SLOT(slotDBusReply(QDBusMessage)), SLOT(slotDBusError(QDBusError)));
32}
33
34void FDAcPluggedJob::slotDBusReply(const QDBusMessage &msg)
35{
36 Q_ASSERT(!msg.arguments().isEmpty());
37
38 m_isPlugged = !msg.arguments().first().value<QDBusVariant>().variant().toBool();
39 emitResult();
40}
41
42void FDAcPluggedJob::slotDBusError(const QDBusError &error)
43{
44 setError(error.type());
45 setErrorText(error.message());
46 emitResult();
47}
48
49bool FDAcPluggedJob::isPlugged() const
50{
51 return m_isPlugged;
52}
53
54#include "moc_fdacpluggedjob.cpp"
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition job.cpp:36
void setErrorText(const QString &errorText)
Sets the error text.
Definition job.cpp:62
void setError(int errorCode)
Sets the error code.
Definition job.cpp:57
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
The single responsibility of this class is to create arguments valid for logind Inhibit call.
Definition fakebattery.h:16
bool callWithCallback(const QDBusMessage &message, QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout) const const
QDBusConnection systemBus()
QList< QVariant > arguments() const const
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.