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 
14 class Q_DECL_HIDDEN KJobUiDelegate::Private
15 {
16 public:
17  Private(KJobUiDelegate *delegate)
18  : q(delegate), job(nullptr),
19  autoErrorHandling(false),
20  autoWarningHandling(true) { }
21 
22  KJobUiDelegate *const q;
23 
24  KJob *job;
25  bool autoErrorHandling : 1;
26  bool autoWarningHandling : 1;
27 
28  void connectJob(KJob *job);
29  void _k_result();
30 };
31 
33  : QObject(), d(new Private(this))
34 {
35 }
36 
38  : QObject(), d(new Private(this))
39 {
40  if (flags & AutoErrorHandlingEnabled) {
41  d->autoErrorHandling = true;
42  }
43  if (flags & AutoWarningHandlingEnabled) {
44  d->autoWarningHandling = true;
45  }
46 }
47 
49 {
50  delete d;
51 }
52 
54 {
55  if (d->job != nullptr) {
56  return false;
57  }
58 
59  d->job = job;
60  setParent(job);
61 
62  return true;
63 }
64 
66 {
67  return d->job;
68 }
69 
71 {
72 }
73 
75 {
76  d->autoErrorHandling = enable;
77 }
78 
80 {
81  return d->autoErrorHandling;
82 }
83 
85 {
86  d->autoWarningHandling = enable;
87 }
88 
90 {
91  return d->autoWarningHandling;
92 }
93 
94 void KJobUiDelegate::slotWarning(KJob *job, const QString &plain,
95  const QString &rich)
96 {
97  Q_UNUSED(job)
98  Q_UNUSED(plain)
99  Q_UNUSED(rich)
100 }
101 
102 void KJobUiDelegate::connectJob(KJob *job)
103 {
104  connect(job, &KJob::result, this, [this](){ d->_k_result();} );
105  connect(job, &KJob::warning, this, &KJobUiDelegate::slotWarning);
106 }
107 
108 void KJobUiDelegate::Private::_k_result()
109 {
110  if (job->error() && autoErrorHandling) {
111  q->showErrorMessage();
112  }
113 }
114 
115 #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 a dialog box to inform the user of 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:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:01:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.