Solid

inhibitionjob.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 "inhibitionjob.h"
8#include "backends/abstractinhibitionjob.h"
9#include "inhibitionjob_p.h"
10#include "powerbackendloader.h"
11
12#include "inhibition.h"
13
14#include <QDebug>
15#include <qglobal.h>
16
17using namespace Solid;
18
19InhibitionJobPrivate::InhibitionJobPrivate()
20 : inhibitions(Power::None)
21 , inhibition(nullptr)
22 , backendJob(nullptr)
23{
24}
25
26InhibitionJob::InhibitionJob(QObject *parent)
27 : Job(*new InhibitionJobPrivate(), parent)
28{
29}
30
31Inhibition *InhibitionJob::inhibition() const
32{
33 Q_ASSERT_X(d_func()->inhibition, "addInhibitionJob", "::inhibition() called before result() has been emitted");
34
35 if (d_func()->inhibition) {
36 return d_func()->inhibition;
37 }
38
39 qWarning() << "result() has not been emitted yet, job not finished";
40 return nullptr;
41}
42
43void InhibitionJob::doStart()
44{
45 Q_D(InhibitionJob);
46
47 if (!d->inhibitions) {
48 setError(InvalidInhibitions);
49 emitResult();
50 return;
51 }
52 if (d->description.isEmpty()) {
53 setError(EmptyDescription);
54 emitResult();
55 return;
56 }
57
58 d->backendJob = PowerBackendLoader::addInhibitionJob(d->inhibitions, d->description);
59 connect(d->backendJob, &AbstractInhibitionJob::result, [this, d]() {
60 d_func()->inhibition = d->backendJob->inhibition();
61 emitResult();
62 });
63
64 d->backendJob->start();
65}
66
67void InhibitionJob::setInhibitions(Power::InhibitionTypes inhibitions)
68{
69 Q_D(InhibitionJob);
70 d->inhibitions = inhibitions;
71}
72
73Power::InhibitionTypes InhibitionJob::inhibitions() const
74{
75 return d_func()->inhibitions;
76}
77
78void InhibitionJob::setDescription(const QString &description)
79{
80 Q_D(InhibitionJob);
81 d->description = description;
82}
83
84QString InhibitionJob::description() const
85{
86 return d_func()->description;
87}
88
89#include "moc_inhibitionjob.cpp"
Holds an inhibition.
Definition inhibition.h:27
This class represents an asynchronous job performed by Solid, it is usually not used directly but ins...
Definition job.h:37
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition job.cpp:36
void setError(int errorCode)
Sets the error code.
Definition job.cpp:57
The single responsibility of this class is to create arguments valid for logind Inhibit call.
Definition fakebattery.h:16
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
Q_D(Todo)
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.