KCoreAddons

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

KDE's Doxygen guidelines are available online.