1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
4 SPDX-FileCopyrightText: 2000-2013 David Faure <faure@kde.org>
5 SPDX-FileCopyrightText: 2006 Kevin Ottens <ervin@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef KIO_JOBUIDELEGATEEXTENSION_H
11#define KIO_JOBUIDELEGATEEXTENSION_H
12
13#include "kiocore_export.h"
14#include <QDateTime>
15#include <kio/global.h>
16
17class KJob;
18namespace KIO
19{
20class Job;
21class ClipboardUpdater;
22
23/**
24 * @see RenameDialog_Options
25 * @since 5.0
26 */
27enum RenameDialog_Option {
28 RenameDialog_Overwrite = 1, ///< We have an existing destination, show details about it and offer to overwrite it.
29 RenameDialog_OverwriteItself = 2, ///< Warn that the current operation would overwrite a file with itself, which is not allowed.
30 RenameDialog_Skip = 4, ///< Offer a "Skip" button, to skip other files too. Requires RenameDialog_MultipleItems.
31 RenameDialog_MultipleItems =
32 8, ///< Set if the current operation concerns multiple files, so it makes sense to offer buttons that apply the user's choice to all files/folders.
33 RenameDialog_Resume = 16, ///< Offer a "Resume" button (plus "Resume All" if RenameDialog_MultipleItems).
34 RenameDialog_NoRename = 64, ///< Don't offer a "Rename" button.
35 RenameDialog_DestIsDirectory = 128, ///< The destination is a directory, the dialog updates labels and tooltips accordingly. @since 5.78
36 RenameDialog_SourceIsDirectory = 256, ///< The source is a directory, the dialog updates labels and tooltips accordingly. @since 5.78
37};
38/**
39 * Stores a combination of #RenameDialog_Option values.
40 */
41Q_DECLARE_FLAGS(RenameDialog_Options, RenameDialog_Option)
42Q_DECLARE_OPERATORS_FOR_FLAGS(RenameDialog_Options)
43
44/**
45 * @see SkipDialog_Options
46 * @since 5.0
47 */
48enum SkipDialog_Option {
49 /**
50 * Set if the current operation concerns multiple files, so it makes sense
51 * to offer buttons that apply the user's choice to all files/folders.
52 */
53 SkipDialog_MultipleItems = 8,
54 /**
55 * Set if the current operation involves copying files/folders with certain
56 * characters in their names that are not supported by the destination
57 * filesystem (e.g.\ VFAT and NTFS disallow "*" in file/folder names).
58 *
59 * This will make the SkipDialog show a "Replace" button that can be used
60 * to instruct the underlying job to replace any problematic character with
61 * an underscore "_".
62 *
63 * @since 5.86
64 */
65 SkipDialog_Replace_Invalid_Chars = 16,
66
67 /**
68 * Set if the current operation @e cannot be retried.
69 *
70 * For example if there is an issue that involves the destination filesystem
71 * support, e.g. VFAT and ExFat don't support symlinks, then retrying doesn't
72 * make sense.
73 *
74 * @since 5.88
75 */
76 SkipDialog_Hide_Retry = 32,
77};
78/**
79 * Stores a combination of #SkipDialog_Option values.
80 */
81Q_DECLARE_FLAGS(SkipDialog_Options, SkipDialog_Option)
82Q_DECLARE_OPERATORS_FOR_FLAGS(SkipDialog_Options)
83
84/**
85 * The result of a rename or skip dialog
86 */
87enum RenameDialog_Result {
88 Result_Cancel = 0,
89 Result_Rename = 1,
90 Result_Skip = 2,
91 Result_AutoSkip = 3,
92 Result_Overwrite = 4,
93 Result_OverwriteAll = 5,
94 Result_Resume = 6,
95 Result_ResumeAll = 7,
96 Result_AutoRename = 8,
97 Result_Retry = 9,
98 /**
99 * Can be returned only when multiple files are passed, Option overwrite is passed
100 * And files modification times are valid
101 * @since 5.77
102 */
103 Result_OverwriteWhenOlder = 10,
104 /**
105 * Can be returned if the user selects to replace any character disallowed
106 * by the destination filesystem with an underscore "_".
107 *
108 * See @ref SkipDialog_Option::SkipDialog_Replace_Invalid_Chars
109 *
110 * @since 5.86
111 */
112 Result_ReplaceInvalidChars = 11,
113 /**
114 * The same as @c Result_ReplaceInvalidChars, but the user selected to
115 * automatically replace any invalid character, without being asked about
116 * every file/folder.
117 *
118 * @since 5.86
119 */
120 Result_ReplaceAllInvalidChars = 12,
121};
122typedef RenameDialog_Result SkipDialog_Result;
123
124/**
125 * @class KIO::JobUiDelegateExtension jobuidelegateextension.h <KIO/JobUiDelegateExtension>
126 *
127 * An abstract class defining interaction with users from KIO jobs:
128 * \li asking for confirmation before deleting files or directories
129 * @since 5.0
130 */
131class KIOCORE_EXPORT JobUiDelegateExtension
132{
133protected:
134 /**
135 * Constructor
136 */
137 JobUiDelegateExtension();
138
139 /**
140 * Destructor
141 */
142 virtual ~JobUiDelegateExtension();
143
144public:
145 /**
146 * The type of deletion: real deletion, moving the files to the trash
147 * or emptying the trash
148 * Used by askDeleteConfirmation.
149 */
150 enum DeletionType { Delete, Trash, EmptyTrash };
151 /**
152 * ForceConfirmation: always ask the user for confirmation
153 * DefaultConfirmation: don't ask the user if he/she said "don't ask again".
154 *
155 * Used by askDeleteConfirmation.
156 */
157 enum ConfirmationType { DefaultConfirmation, ForceConfirmation };
158 /**
159 * Ask for confirmation before deleting/trashing @p urls.
160 *
161 * Note that this method is not called automatically by KIO jobs. It's the application's
162 * responsibility to ask the user for confirmation before calling KIO::del() or KIO::trash().
163 *
164 * @param urls the urls about to be deleted/trashed
165 * @param deletionType the type of deletion (Delete for real deletion, Trash otherwise)
166 * @param confirmationType see ConfirmationType. Normally set to DefaultConfirmation.
167 * Note: the window passed to setWindow is used as the parent for the message box.
168 * @return true if confirmed
169 */
170 virtual bool askDeleteConfirmation(const QList<QUrl> &urls, DeletionType deletionType, ConfirmationType confirmationType) = 0;
171
172 enum ClipboardUpdaterMode {
173 UpdateContent,
174 OverwriteContent,
175 RemoveContent,
176 };
177
178 /**
179 * Creates a clipboard updater as a child of the given job.
180 */
181 virtual ClipboardUpdater *createClipboardUpdater(Job *job, ClipboardUpdaterMode mode);
182 /**
183 * Update URL in clipboard, if present
184 */
185 virtual void updateUrlInClipboard(const QUrl &src, const QUrl &dest);
186
187 // TODO KF6: add virtual_hook
188
189private:
190 class Private;
191 Private *const d;
192};
193
194/**
195 * Returns the default job UI delegate extension to be used by all KIO jobs (in which HideProgressInfo is not set)
196 * Can return nullptr, if no kio GUI library is loaded.
197 * @since 5.0
198 */
199KIOCORE_EXPORT JobUiDelegateExtension *defaultJobUiDelegateExtension();
200
201/**
202 * Internal. Allows the KIO widgets library to register its widget-based job UI delegate extension
203 * automatically.
204 * @since 5.0
205 */
206KIOCORE_EXPORT void setDefaultJobUiDelegateExtension(JobUiDelegateExtension *extension);
207
208} // namespace KIO
209
210#endif
211

source code of kio/src/core/jobuidelegateextension.h