Solid

job.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 "job.h"
8#include "job_p.h"
9
10#include <QEventLoop>
11
12using namespace Solid;
13JobPrivate::JobPrivate()
14{
15 eventLoop = nullptr;
17}
18
19Job::Job(QObject *parent)
20 : QObject(parent)
21 , d_ptr(new JobPrivate)
22{
23 d_ptr->q_ptr = this;
24}
25
26Job::~Job()
27{
28 delete d_ptr;
29}
30
32{
34}
35
37{
38 Q_D(Job);
39 if (d->eventLoop) {
40 d->eventLoop->quit();
41 }
42
43 Q_EMIT result(this);
45}
46
47int Job::error() const
48{
49 return d_func()->error;
50}
51
52QString Job::errorText() const
53{
54 return d_func()->errorText;
55}
56
57void Job::setError(int errorCode)
58{
59 d_func()->error = errorCode;
60}
61
62void Job::setErrorText(const QString &errorText)
63{
64 d_func()->errorText = errorText;
65}
66
68{
69 Q_D(Job);
70
71 Q_ASSERT(!d->eventLoop);
72
73 QEventLoop loop(this);
74 d->eventLoop = &loop;
75
76 start();
77 d->eventLoop->exec(QEventLoop::ExcludeUserInputEvents);
78
79 return (d->error == NoError);
80}
81
82Job::Job(JobPrivate &dd, QObject *parent)
83 : QObject(parent)
84 , d_ptr(&dd)
85{
86}
87
88#include "moc_job.cpp"
This class represents an asynchronous job performed by Solid, it is usually not used directly but ins...
Definition job.h:37
void start()
Starts the job asynchronously.
Definition job.cpp:31
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition job.cpp:36
@ NoError
Indicates there is no error.
Definition job.h:48
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
bool exec()
Executes the job synchronously.
Definition job.cpp:67
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 invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
Q_EMITQ_EMIT
void deleteLater()
QueuedConnection
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.