File indexing completed on 2024-12-01 09:52:49

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
0004     SPDX-FileCopyrightText: 2000-2013 David Faure <faure@kde.org>
0005     SPDX-FileCopyrightText: 2006 Kevin Ottens <ervin@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef KIO_JOBUIDELEGATEEXTENSION_H
0011 #define KIO_JOBUIDELEGATEEXTENSION_H
0012 
0013 #include "kiocore_export.h"
0014 #include <QDateTime>
0015 #include <kio/global.h>
0016 
0017 class KJob;
0018 namespace KIO
0019 {
0020 class Job;
0021 class ClipboardUpdater;
0022 
0023 /**
0024  * @see RenameDialog_Options
0025  * @since 5.0
0026  */
0027 enum RenameDialog_Option {
0028     RenameDialog_Overwrite = 1, ///< We have an existing destination, show details about it and offer to overwrite it.
0029     RenameDialog_OverwriteItself = 2, ///< Warn that the current operation would overwrite a file with itself, which is not allowed.
0030     RenameDialog_Skip = 4, ///< Offer a "Skip" button, to skip other files too. Requires RenameDialog_MultipleItems.
0031     RenameDialog_MultipleItems =
0032         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.
0033     RenameDialog_Resume = 16, ///< Offer a "Resume" button (plus "Resume All" if RenameDialog_MultipleItems).
0034     RenameDialog_NoRename = 64, ///< Don't offer a "Rename" button.
0035 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 78)
0036     RenameDialog_IsDirectory KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 78, "Use RenameDialog_DestIsDirectory.") =
0037         128, ///< @deprecated since 5.78, use RenameDialog_DestIsDirectory instead.
0038 #endif
0039     RenameDialog_DestIsDirectory = 128, ///< The destination is a directory, the dialog updates labels and tooltips accordingly. @since 5.78
0040     RenameDialog_SourceIsDirectory = 256, ///< The source is a directory, the dialog updates labels and tooltips accordingly. @since 5.78
0041 };
0042 /**
0043  * Stores a combination of #RenameDialog_Option values.
0044  */
0045 Q_DECLARE_FLAGS(RenameDialog_Options, RenameDialog_Option)
0046 Q_DECLARE_OPERATORS_FOR_FLAGS(RenameDialog_Options)
0047 
0048 // For compat
0049 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 0)
0050 /**
0051  * @deprecated since 5.0, use the RenameDialog_Option enum values
0052  */
0053 enum {
0054     M_OVERWRITE KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use RenameDialog_Overwrite.") = RenameDialog_Overwrite,
0055     M_OVERWRITE_ITSELF KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use RenameDialog_OverwriteItself.") = RenameDialog_OverwriteItself,
0056     M_SKIP KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use RenameDialog_Skip.") = RenameDialog_Skip,
0057     M_MULTI KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use RenameDialog_MultipleItems.") = RenameDialog_MultipleItems,
0058     M_RESUME KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use RenameDialog_Resume.") = RenameDialog_Resume,
0059     M_NORENAME KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use RenameDialog_NoRename.") = RenameDialog_NoRename,
0060     M_ISDIR KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use RenameDialog_IsDirectory.") = RenameDialog_IsDirectory,
0061 };
0062 /**
0063  * @deprecated since 5.0, use RenameDialog_Options
0064  */
0065 KIOCORE_DEPRECATED_VERSION(5, 0, "Use KIO::RenameDialog_Options")
0066 typedef RenameDialog_Options RenameDialog_Mode;
0067 #endif
0068 
0069 /**
0070  * @see SkipDialog_Options
0071  * @since 5.0
0072  */
0073 enum SkipDialog_Option {
0074     /**
0075      * Set if the current operation concerns multiple files, so it makes sense
0076      * to offer buttons that apply the user's choice to all files/folders.
0077      */
0078     SkipDialog_MultipleItems = 8,
0079     /**
0080      * Set if the current operation involves copying files/folders with certain
0081      * characters in their names that are not supported by the destination
0082      * filesystem (e.g.\ VFAT and NTFS disallow "*" in file/folder names).
0083      *
0084      * This will make the SkipDialog show a "Replace" button that can be used
0085      * to instruct the underlying job to replace any problematic character with
0086      * an underscore "_".
0087      *
0088      * @since 5.86
0089      */
0090     SkipDialog_Replace_Invalid_Chars = 16,
0091 
0092     /**
0093      * Set if the current operation @e cannot be retried.
0094      *
0095      * For example if there is an issue that involves the destination filesystem
0096      * support, e.g. VFAT and ExFat don't support symlinks, then retrying doesn't
0097      * make sense.
0098      *
0099      * @since 5.88
0100      */
0101     SkipDialog_Hide_Retry = 32,
0102 };
0103 /**
0104  * Stores a combination of #SkipDialog_Option values.
0105  */
0106 Q_DECLARE_FLAGS(SkipDialog_Options, SkipDialog_Option)
0107 Q_DECLARE_OPERATORS_FOR_FLAGS(SkipDialog_Options)
0108 
0109 /**
0110  * The result of a rename or skip dialog
0111  */
0112 enum RenameDialog_Result {
0113     Result_Cancel = 0,
0114     Result_Rename = 1,
0115     Result_Skip = 2,
0116     Result_AutoSkip = 3,
0117     Result_Overwrite = 4,
0118     Result_OverwriteAll = 5,
0119     Result_Resume = 6,
0120     Result_ResumeAll = 7,
0121     Result_AutoRename = 8,
0122     Result_Retry = 9,
0123     /**
0124      * Can be returned only when multiple files are passed, Option overwrite is passed
0125      * And files modification times are valid
0126      * @since 5.77
0127      */
0128     Result_OverwriteWhenOlder = 10,
0129     /**
0130      * Can be returned if the user selects to replace any character disallowed
0131      * by the destination filesystem with an underscore "_".
0132      *
0133      * See @ref SkipDialog_Option::SkipDialog_Replace_Invalid_Chars
0134      *
0135      * @since 5.86
0136      */
0137     Result_ReplaceInvalidChars = 11,
0138     /**
0139      * The same as @c Result_ReplaceInvalidChars, but the user selected to
0140      * automatically replace any invalid character, without being asked about
0141      * every file/folder.
0142      *
0143      * @since 5.86
0144      */
0145     Result_ReplaceAllInvalidChars = 12,
0146 
0147 // @deprecated since 5.0, use the undeprecated enum values
0148 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 0)
0149     R_CANCEL KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Cancel.") = Result_Cancel,
0150     R_RENAME KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Rename.") = Result_Rename,
0151     R_SKIP KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Skip.") = Result_Skip,
0152     R_AUTO_SKIP KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_AutoSkip.") = Result_AutoSkip,
0153     R_OVERWRITE KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Overwrite.") = Result_Overwrite,
0154     R_OVERWRITE_ALL KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_OverwriteAll.") = Result_OverwriteAll,
0155     R_RESUME KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Resume.") = Result_Resume,
0156     R_RESUME_ALL KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_ResumeAll.") = Result_ResumeAll,
0157     R_AUTO_RENAME KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_AutoRename.") = Result_AutoRename,
0158     R_RETRY KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Retry.") = Result_Retry,
0159 
0160     S_CANCEL KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Cancel.") = Result_Cancel,
0161     S_SKIP KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Skip.") = Result_Skip,
0162     S_AUTO_SKIP KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_AutoSkip.") = Result_AutoSkip,
0163     S_RETRY KIOCORE_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 5, 0, "Use Result_Retry.") = Result_Retry,
0164 #endif
0165 };
0166 typedef RenameDialog_Result SkipDialog_Result;
0167 
0168 /**
0169  * @class KIO::JobUiDelegateExtension jobuidelegateextension.h <KIO/JobUiDelegateExtension>
0170  *
0171  * An abstract class defining interaction with users from KIO jobs:
0172  * \li asking what to do in case of a conflict while copying/moving files or directories
0173  * \li asking what to do in case of an error while copying/moving files or directories
0174  * \li asking for confirmation before deleting files or directories
0175  * \li popping up message boxes when the worker requests it
0176  * @since 5.0
0177  */
0178 class KIOCORE_EXPORT JobUiDelegateExtension
0179 {
0180 protected:
0181     /**
0182      * Constructor
0183      */
0184     JobUiDelegateExtension();
0185 
0186     /**
0187      * Destructor
0188      */
0189     virtual ~JobUiDelegateExtension();
0190 
0191 public:
0192     /**
0193      * \relates KIO::RenameDialog
0194      * Construct a modal, parent-less "rename" dialog, and return
0195      * a result code, as well as the new dest. Much easier to use than the
0196      * class RenameDialog directly.
0197      *
0198      * @param title the title for the dialog box
0199      * @param src the URL of the file/dir we're trying to copy, as it's part of the text message
0200      * @param dest the URL of the destination file/dir, i.e. the one that already exists
0201      * @param options parameters for the dialog (which buttons to show...)
0202      * @param newDest the new destination path, valid if R_RENAME was returned.
0203      * @param sizeSrc size of source file
0204      * @param sizeDest size of destination file
0205      * @param ctimeSrc creation time of source file
0206      * @param ctimeDest creation time of destination file
0207      * @param mtimeSrc modification time of source file
0208      * @param mtimeDest modification time of destination file
0209      * @return the result
0210      */
0211     virtual KIO::RenameDialog_Result askFileRename(KJob *job,
0212                                                    const QString &title,
0213                                                    const QUrl &src,
0214                                                    const QUrl &dest,
0215                                                    KIO::RenameDialog_Options options,
0216                                                    QString &newDest,
0217                                                    KIO::filesize_t sizeSrc = KIO::filesize_t(-1),
0218                                                    KIO::filesize_t sizeDest = KIO::filesize_t(-1),
0219                                                    const QDateTime &ctimeSrc = QDateTime(),
0220                                                    const QDateTime &ctimeDest = QDateTime(),
0221                                                    const QDateTime &mtimeSrc = QDateTime(),
0222                                                    const QDateTime &mtimeDest = QDateTime()) = 0;
0223 
0224     /**
0225      * @internal
0226      * See skipdialog.h
0227      */
0228     virtual KIO::SkipDialog_Result askSkip(KJob *job, KIO::SkipDialog_Options options, const QString &error_text) = 0;
0229 
0230     /**
0231      * The type of deletion: real deletion, moving the files to the trash
0232      * or emptying the trash
0233      * Used by askDeleteConfirmation.
0234      */
0235     enum DeletionType { Delete, Trash, EmptyTrash };
0236     /**
0237      * ForceConfirmation: always ask the user for confirmation
0238      * DefaultConfirmation: don't ask the user if he/she said "don't ask again".
0239      *
0240      * Used by askDeleteConfirmation.
0241      */
0242     enum ConfirmationType { DefaultConfirmation, ForceConfirmation };
0243     /**
0244      * Ask for confirmation before deleting/trashing @p urls.
0245      *
0246      * Note that this method is not called automatically by KIO jobs. It's the application's
0247      * responsibility to ask the user for confirmation before calling KIO::del() or KIO::trash().
0248      *
0249      * @param urls the urls about to be deleted/trashed
0250      * @param deletionType the type of deletion (Delete for real deletion, Trash otherwise)
0251      * @param confirmationType see ConfirmationType. Normally set to DefaultConfirmation.
0252      * Note: the window passed to setWindow is used as the parent for the message box.
0253      * @return true if confirmed
0254      */
0255     virtual bool askDeleteConfirmation(const QList<QUrl> &urls, DeletionType deletionType, ConfirmationType confirmationType) = 0;
0256 
0257     /**
0258      * Message box types.
0259      *
0260      * Should be kept in sync with WorkerBase::MessageBoxType.
0261      *
0262      * @since 4.11
0263      */
0264     enum MessageBoxType {
0265         QuestionTwoActions = 1, ///< @since 5.100
0266         WarningTwoActions = 2, ///< @since 5.100
0267         WarningContinueCancel = 3,
0268         WarningTwoActionsCancel = 4, ///< @since 5.100
0269         Information = 5,
0270         SSLMessageBox = 6,
0271         // In KMessageBox::DialogType; Sorry = 7, Error = 8, QuestionTwoActionsCancel = 9
0272         WarningContinueCancelDetailed = 10,
0273 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 100)
0274         QuestionYesNo ///< @deprecated Since 5.100, use QuestionTwoActions.
0275             KIOCORE_ENUMERATOR_DEPRECATED_VERSION(5, 100, "Use QuestionTwoActions.") = QuestionTwoActions,
0276         WarningYesNo ///< @deprecated Since 5.100, use WarningTwoActions.
0277             KIOCORE_ENUMERATOR_DEPRECATED_VERSION(5, 100, "Use WarningTwoActions.") = WarningTwoActions,
0278         WarningYesNoCancel ///< @deprecated Since 5.100, use WarningTwoActionsCancel.
0279             KIOCORE_ENUMERATOR_DEPRECATED_VERSION(5, 100, "Use WarningTwoActionsCancel.") = WarningTwoActionsCancel,
0280 #endif
0281     };
0282 
0283     /**
0284      * This function allows for the delegation user prompts from the KIO workers.
0285      *
0286      * @param type the desired type of message box.
0287      * @param text the message shown to the user.
0288      * @param title the title of the message dialog box.
0289      * @param primaryActionText the text for the primary action.
0290      * @param secondaryActionText the text for the secondary action.
0291      * @param primaryActionIconName the icon shown on the primary action.
0292      * @param secondaryActionIconName the icon shown on the secondary action.
0293      * @param dontAskAgainName the name used to store result from 'Do not ask again' checkbox.
0294      * @param sslMetaData SSL information used by the SSLMessageBox.
0295      */
0296     virtual int requestMessageBox(MessageBoxType type,
0297                                   const QString &text,
0298                                   const QString &title,
0299                                   const QString &primaryActionText,
0300                                   const QString &secondaryActionText,
0301                                   const QString &primaryActionIconName = QString(),
0302                                   const QString &secondaryActionIconName = QString(),
0303                                   const QString &dontAskAgainName = QString(),
0304                                   const KIO::MetaData &sslMetaData = KIO::MetaData()) = 0;
0305 
0306     enum ClipboardUpdaterMode {
0307         UpdateContent,
0308         OverwriteContent,
0309         RemoveContent,
0310     };
0311 
0312     /**
0313      * Creates a clipboard updater as a child of the given job.
0314      */
0315     virtual ClipboardUpdater *createClipboardUpdater(Job *job, ClipboardUpdaterMode mode);
0316     /**
0317      * Update URL in clipboard, if present
0318      */
0319     virtual void updateUrlInClipboard(const QUrl &src, const QUrl &dest);
0320 
0321     // TODO KF6: add virtual_hook
0322 
0323 private:
0324     class Private;
0325     Private *const d;
0326 };
0327 
0328 /**
0329  * Returns the default job UI delegate extension to be used by all KIO jobs (in which HideProgressInfo is not set)
0330  * Can return nullptr, if no kio GUI library is loaded.
0331  * @since 5.0
0332  */
0333 KIOCORE_EXPORT JobUiDelegateExtension *defaultJobUiDelegateExtension();
0334 
0335 /**
0336  * Internal. Allows the KIO widgets library to register its widget-based job UI delegate extension
0337  * automatically.
0338  * @since 5.0
0339  */
0340 KIOCORE_EXPORT void setDefaultJobUiDelegateExtension(JobUiDelegateExtension *extension);
0341 
0342 } // namespace KIO
0343 
0344 #endif