Solid

power.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 "power.h"
8#include "acpluggedjob.h"
9#include "inhibition.h"
10#include "inhibitionjob.h"
11#include "powerbackendloader.h"
12#include "requeststatejob.h"
13#include "statesjob.h"
14
15#include "backends/powernotifier.h"
16
17Q_GLOBAL_STATIC(Solid::Power, globalPowerObject)
18
19using namespace Solid;
20
21class Power::Private
22{
23public:
24 PowerNotifier *notifier;
25};
26
27Power *Power::self()
28{
29 return globalPowerObject;
30}
31
32Power::Power(QObject *parent)
33 : QObject(parent)
34 , d(new Private)
35{
36 qRegisterMetaType<Solid::Inhibition::State>("Inhibition::State");
37 d->notifier = PowerBackendLoader::notifier();
38 connect(d->notifier, &PowerNotifier::acPluggedChanged, this, &Power::acPluggedChanged);
39 connect(d->notifier, &PowerNotifier::aboutToSuspend, this, &Power::aboutToSuspend);
40 connect(d->notifier, &PowerNotifier::resumeFromSuspend, this, &Power::resumeFromSuspend);
41}
42
43AcPluggedJob *Power::isAcPlugged(QObject *parent)
44{
45 return new AcPluggedJob(parent);
46}
47
48InhibitionJob *Power::inhibit(Power::InhibitionTypes states, const QString &description, QObject *parent)
49{
50 InhibitionJob *job = new InhibitionJob(parent);
51 job->setInhibitions(states);
52 job->setDescription(description);
53
54 return job;
55}
56
57StatesJob *Power::supportedStates(QObject *parent)
58{
59 return new StatesJob(parent);
60}
61
62RequestStateJob *Power::requestState(Power::InhibitionType state, QObject *parent)
63{
64 auto job = new RequestStateJob(parent);
65 job->setState(state);
66
67 return job;
68}
69
70#include "moc_power.cpp"
Tries to set the device under the state indicated via setState()
Returns the states supported on the device.
Definition statesjob.h:26
The single responsibility of this class is to create arguments valid for logind Inhibit call.
Definition fakebattery.h:16
QObject * parent() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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.