1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
3 David Faure <faure@kde.org>
4 Copyright (C) 2006 Kevin Ottens <ervin@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KJOBUIDELEGATE_H
23#define KJOBUIDELEGATE_H
24
25#include <kdecore_export.h>
26#include <QtCore/QObject>
27
28class KJob;
29
30/**
31 * The base class for all KJob UI delegate.
32 *
33 * A UI delegate is responsible for the events of a
34 * job and provides a UI for them (an error message
35 * box or warning etc.).
36 *
37 * @see KJob
38 */
39class KDECORE_EXPORT KJobUiDelegate : public QObject
40{
41 Q_OBJECT
42
43public:
44 /**
45 * Constructs a new KJobUiDelegate.
46 */
47 KJobUiDelegate();
48
49 /**
50 * Destroys a KJobUiDelegate.
51 */
52 virtual ~KJobUiDelegate();
53
54private:
55 /**
56 * Attach this UI delegate to a job. Once attached it'll track the job events.
57 *
58 * @return true if the job we're correctly attached to the job, false otherwise.
59 */
60 bool setJob( KJob *job );
61
62protected:
63 /**
64 * Retrieves the current job this UI delegate is attached to.
65 *
66 * @return current job this UI delegate is attached to, or 0 if
67 * this UI delegate is not tracking any job
68 */
69 KJob *job();
70
71 friend class KJob;
72
73public:
74 /**
75 * Display a dialog box to inform the user of the error given by
76 * this job.
77 * Only call if error is not 0, and only in the slot connected
78 * to result.
79 */
80 virtual void showErrorMessage();
81
82 /**
83 * Enable or disable the automatic error handling. When automatic
84 * error handling is enabled and an error occurs, then showErrorDialog()
85 * is called, right before the emission of the result signal.
86 *
87 * The default is false.
88 *
89 * See also isAutoErrorHandlingEnabled , showErrorDialog
90 *
91 * @param enable enable or disable automatic error handling
92 * @see isAutoErrorHandlingEnabled()
93 */
94 void setAutoErrorHandlingEnabled( bool enable );
95
96 /**
97 * Returns whether automatic error handling is enabled or disabled.
98 * See also setAutoErrorHandlingEnabled .
99 * @return true if automatic error handling is enabled
100 * @see setAutoErrorHandlingEnabled()
101 */
102 bool isAutoErrorHandlingEnabled() const;
103
104 /**
105 * Enable or disable the automatic warning handling. When automatic
106 * warning handling is enabled and an error occurs, then a message box
107 * is displayed with the warning message
108 *
109 * The default is true.
110 *
111 * See also isAutoWarningHandlingEnabled , showErrorDialog
112 *
113 * @param enable enable or disable automatic warning handling
114 * @see isAutoWarningHandlingEnabled()
115 */
116 void setAutoWarningHandlingEnabled( bool enable );
117
118 /**
119 * Returns whether automatic warning handling is enabled or disabled.
120 * See also setAutoWarningHandlingEnabled .
121 * @return true if automatic warning handling is enabled
122 * @see setAutoWarningHandlingEnabled()
123 */
124 bool isAutoWarningHandlingEnabled() const;
125
126protected Q_SLOTS:
127 virtual void slotWarning(KJob *job, const QString &plain, const QString &rich);
128
129private:
130 void connectJob(KJob *job);
131
132 Q_PRIVATE_SLOT(d, void _k_result(KJob*))
133
134 class Private;
135 Private * const d;
136};
137
138#endif // KJOBUIDELEGATE_H
139