KCoreAddons

kjobuidelegate.h
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 #ifndef KJOBUIDELEGATE_H
12 #define KJOBUIDELEGATE_H
13 
14 #include <QObject>
15 #include <kcoreaddons_export.h>
16 #include <memory>
17 
18 class KJob;
19 
20 /**
21  * @class KJobUiDelegate kjobuidelegate.h KJobUiDelegate
22  *
23  * The base class for all KJob UI delegate.
24  *
25  * A UI delegate is responsible for the events of a
26  * job and provides a UI for them (an error message
27  * box or warning etc.).
28  *
29  * @see KJob
30  */
31 class KCOREADDONS_EXPORT KJobUiDelegate : public QObject
32 {
33  Q_OBJECT
34 
35 public:
36  /**
37  * Flags for the constructor, to enable automatic handling of errors and/or warnings
38  * @see Flags
39  * @since 5.70
40  */
41  enum Flag {
42  AutoHandlingDisabled = 0, ///< No automatic handling (default)
43  AutoErrorHandlingEnabled = 1, ///< Equivalent to setAutoErrorHandlingEnabled(true)
44  AutoWarningHandlingEnabled = 2, ///< Equivalent to setAutoWarningHandlingEnabled(true)
45  AutoHandlingEnabled = AutoErrorHandlingEnabled | AutoWarningHandlingEnabled, ///< Enables both error and warning handling
46  };
47  /**
48  * Stores a combination of #Flag values.
49  */
50  Q_DECLARE_FLAGS(Flags, Flag)
51 
52  /**
53  * Constructs a new KJobUiDelegate.
54  */
56 
57  /**
58  * Constructs a new KJobUiDelegate with a flags argument.
59  * @param flags allows to enable automatic error/warning handling
60  * @since 5.70
61  */
62  explicit KJobUiDelegate(Flags flags); // KF6 TODO merge with default constructor, using AutoHandlingDisabled as default value
63 
64  /**
65  * Destroys a KJobUiDelegate.
66  */
67  ~KJobUiDelegate() override;
68 
69 protected:
70  /**
71  * Attach this UI delegate to a job. Once attached it'll track the job events.
72  *
73  * @return true if the job we're correctly attached to the job, false otherwise.
74  */
75  virtual bool setJob(KJob *job);
76 
77 protected:
78  /**
79  * Retrieves the current job this UI delegate is attached to.
80  *
81  * @return current job this UI delegate is attached to, or @c nullptr if
82  * this UI delegate is not tracking any job
83  */
84  KJob *job() const;
85 
86  friend class KJob;
87 
88 public:
89  /**
90  * Display to the user the error given by this job.
91  * The default implementation uses qWarning(). Subclasses
92  * reimplement this to use something more user-visible such
93  * as a message box.
94  *
95  * Only call this method if error is not 0, and only in the
96  * slot connected to result.
97  */
98  virtual void showErrorMessage();
99 
100  /**
101  * Enable or disable the automatic error handling. When automatic
102  * error handling is enabled and an error occurs, then showErrorDialog()
103  * is called, right before the emission of the result signal.
104  *
105  * The default is false.
106  *
107  * See also isAutoErrorHandlingEnabled , showErrorDialog
108  *
109  * @param enable enable or disable automatic error handling
110  * @see isAutoErrorHandlingEnabled()
111  */
112  void setAutoErrorHandlingEnabled(bool enable);
113 
114  /**
115  * Returns whether automatic error handling is enabled or disabled.
116  * See also setAutoErrorHandlingEnabled .
117  * @return true if automatic error handling is enabled
118  * @see setAutoErrorHandlingEnabled()
119  */
120  bool isAutoErrorHandlingEnabled() const;
121 
122  /**
123  * Enable or disable the automatic warning handling. When automatic
124  * warning handling is enabled and an error occurs, then a message box
125  * is displayed with the warning message
126  *
127  * The default is true.
128  *
129  * See also isAutoWarningHandlingEnabled , showErrorDialog
130  *
131  * @param enable enable or disable automatic warning handling
132  * @see isAutoWarningHandlingEnabled()
133  */
134  void setAutoWarningHandlingEnabled(bool enable);
135 
136  /**
137  * Returns whether automatic warning handling is enabled or disabled.
138  * See also setAutoWarningHandlingEnabled .
139  * @return true if automatic warning handling is enabled
140  * @see setAutoWarningHandlingEnabled()
141  */
142  bool isAutoWarningHandlingEnabled() const;
143 
144 protected Q_SLOTS:
145  virtual void slotWarning(KJob *job, const QString &plain, const QString &rich);
146 
147 private:
148  void connectJob(KJob *job);
149 
150 private:
151  std::unique_ptr<class KJobUiDelegatePrivate> const d;
152 };
153 
154 Q_DECLARE_OPERATORS_FOR_FLAGS(KJobUiDelegate::Flags)
155 
156 #endif // KJOBUIDELEGATE_H
Flag
Flags for the constructor, to enable automatic handling of errors and/or warnings.
The base class for all KJob UI delegate.
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 Sat Apr 10 2021 23:01:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.