KCoreAddons

kjobuidelegate.cpp
1/*
2 This file is part of the KDE libraries
3
4 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
5 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
6 SPDX-FileCopyrightText: 2006 Kevin Ottens <ervin@kde.org>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#include "kjobuidelegate.h"
12#include "kcoreaddons_debug.h"
13#include "kjob.h"
14
15#include <QDebug>
16
17class KJobUiDelegatePrivate
18{
19public:
20 KJobUiDelegatePrivate(KJobUiDelegate *delegate)
21 : q(delegate)
22 , autoErrorHandling(false)
23 , autoWarningHandling(true)
24 {
25 }
26
27 KJobUiDelegate *const q;
28
29 KJob *job = nullptr;
30 bool autoErrorHandling : 1;
31 bool autoWarningHandling : 1;
32
33 void connectJob(KJob *job);
34 void _k_result();
35};
36
38 : QObject()
39 , d(new KJobUiDelegatePrivate(this))
40{
41 if (flags & AutoErrorHandlingEnabled) {
42 d->autoErrorHandling = true;
43 }
44 if (flags & AutoWarningHandlingEnabled) {
45 d->autoWarningHandling = true;
46 }
47}
48
50
52{
53 if (d->job != nullptr) {
54 qCWarning(KCOREADDONS_DEBUG) << "Trying to attach UI delegate:" << this << "to job" << job //
55 << "but this delegate is already attached to a different job" << d->job;
56 return false;
57 }
58
59 d->job = job;
61
62 return true;
63}
64
66{
67 return d->job;
68}
69
71{
72 if (d->job->error() != KJob::KilledJobError) {
73 qWarning() << d->job->errorString();
74 }
75}
76
78{
79 d->autoErrorHandling = enable;
80}
81
83{
84 return d->autoErrorHandling;
85}
86
88{
89 d->autoWarningHandling = enable;
90}
91
93{
94 return d->autoWarningHandling;
95}
96
97void KJobUiDelegate::slotWarning(KJob *job, const QString &message)
98{
99 Q_UNUSED(job)
100 Q_UNUSED(message)
101}
102
103void KJobUiDelegate::connectJob(KJob *job)
104{
105 connect(job, &KJob::result, this, [this]() {
106 d->_k_result();
107 });
108 connect(job, &KJob::warning, this, &KJobUiDelegate::slotWarning);
109}
110
111void KJobUiDelegatePrivate::_k_result()
112{
113 if (job->error() && autoErrorHandling) {
114 q->showErrorMessage();
115 }
116}
117
118#include "moc_kjobuidelegate.cpp"
The base class for all KJob UI delegate.
bool isAutoErrorHandlingEnabled() const
Returns whether automatic error handling is enabled or disabled.
bool isAutoWarningHandlingEnabled() const
Returns whether automatic warning handling is enabled or disabled.
~KJobUiDelegate() override
Destroys a KJobUiDelegate.
@ AutoErrorHandlingEnabled
Equivalent to setAutoErrorHandlingEnabled(true)
@ AutoWarningHandlingEnabled
Equivalent to setAutoWarningHandlingEnabled(true)
virtual void showErrorMessage()
Display to the user the error given by this job.
KJob * job() const
Retrieves the current job this UI delegate is attached to.
void setAutoErrorHandlingEnabled(bool enable)
Enable or disable the automatic error handling.
KJobUiDelegate(Flags flags={KJobUiDelegate::AutoHandlingDisabled})
Constructs a new KJobUiDelegate with a flags argument.
virtual bool setJob(KJob *job)
Attach this UI delegate to a job.
void setAutoWarningHandlingEnabled(bool enable)
Enable or disable the automatic warning handling.
The base class for all jobs.
Definition kjob.h:74
void result(KJob *job)
Emitted when the job is finished (except when killed with KJob::Quietly).
void warning(KJob *job, const QString &message)
Emitted to display a warning about this job.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setParent(QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 10 2024 11:50:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.