File indexing completed on 2024-12-01 09:53:35

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
0004     SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
0005     SPDX-FileCopyrightText: 2006 Kevin Ottens <ervin@kde.org>
0006     SPDX-FileCopyrightText: 2013 Dawit Alemayehu <adawit@kde.org>
0007     SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0008 
0009     SPDX-License-Identifier: LGPL-2.0-or-later
0010 */
0011 
0012 #ifndef KIO_JOBUIDELEGATE_H
0013 #define KIO_JOBUIDELEGATE_H
0014 
0015 #include <KDialogJobUiDelegate>
0016 #include <kio/askuseractioninterface.h>
0017 #include <kio/global.h>
0018 #include <kio/jobuidelegateextension.h>
0019 #include <kio/renamedialog.h>
0020 #include <kio/skipdialog.h>
0021 
0022 class KJob;
0023 class KDirOperator;
0024 class KIOWidgetJobUiDelegateFactory;
0025 
0026 namespace KIO
0027 {
0028 class JobUiDelegatePrivate;
0029 
0030 class FileUndoManager;
0031 
0032 class Job;
0033 
0034 /**
0035  * @class KIO::JobUiDelegate jobuidelegate.h <KIO/JobUiDelegate>
0036  *
0037  * A UI delegate tuned to be used with KIO Jobs.
0038  */
0039 class KIOWIDGETS_EXPORT JobUiDelegate : public KDialogJobUiDelegate, public JobUiDelegateExtension
0040 {
0041     Q_OBJECT
0042     // Allow the factory to construct. Everyone else needs to go through the factory or derive!
0043     friend class ::KIOWidgetJobUiDelegateFactory;
0044     // KIO internals don't need to derive either
0045     friend class KIO::FileUndoManager;
0046 
0047 public:
0048 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 98)
0049     /**
0050      * Constructs a new KIO Job UI delegate.
0051      * @deprecated Since 5.98, use KIO::createDefaultJobUiDelegate or versioned constructor instead
0052      */
0053     KIOWIDGETS_DEPRECATED_VERSION(5, 98, "use KIO::createDefaultJobUiDelegate or versioned constructor instead")
0054     JobUiDelegate();
0055 #endif
0056 
0057 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 98)
0058     /**
0059      * Constructs a new KIO Job UI Delegate.
0060      * @param flags allows to enable automatic error/warning handling
0061      * @param window the window associated with this delegate, see setWindow.
0062      * @since 5.70,
0063      * @deprecated Since 5.98, use KIO::createDefaultJobUiDelegate or versioned constructor instead
0064      */
0065     KIOWIDGETS_DEPRECATED_VERSION(5, 98, "use KIO::createDefaultJobUiDelegate or versioned constructor instead")
0066     explicit JobUiDelegate(KJobUiDelegate::Flags flags, QWidget *window);
0067 #endif
0068 
0069 protected:
0070     friend class ::KDirOperator;
0071 
0072     enum class Version {
0073         V2,
0074     };
0075 
0076     /**
0077      * Constructs a new KIO Job UI delegate.
0078      * @param version does nothing purely here to disambiguate this constructor from the deprecated older constructors.
0079      * @param flags allows to enable automatic error/warning handling
0080      * @param window the window associated with this delegate, see setWindow.
0081      * @param ifaces Interface instances such as OpenWithHandlerInterface to replace the default interfaces
0082      * @since 5.98
0083      */
0084     explicit JobUiDelegate(Version version, KJobUiDelegate::Flags flags = AutoHandlingDisabled, QWidget *window = nullptr, const QList<QObject *> &ifaces = {});
0085 
0086 public:
0087     /**
0088      * Destroys the KIO Job UI delegate.
0089      */
0090     ~JobUiDelegate() override;
0091 
0092 public:
0093     /**
0094      * Associate this job with a window given by @p window.
0095      * @param window the window to associate to
0096      * @see window()
0097      */
0098     void setWindow(QWidget *window) override;
0099 
0100     /**
0101      * Unregister the given window from kded.
0102      * This is normally done automatically when the window is destroyed.
0103      *
0104      * This method is useful for instance when keeping a hidden window
0105      * around to make it faster to reuse later.
0106      * @since 5.2
0107      */
0108     static void unregisterWindow(QWidget *window);
0109 
0110     /**
0111      * \relates KIO::RenameDialog
0112      * Construct a modal, parent-less "rename" dialog, and return
0113      * a result code, as well as the new dest. Much easier to use than the
0114      * class RenameDialog directly.
0115      *
0116      * @param title the title for the dialog box
0117      * @param src the URL of the file/dir we're trying to copy, as it's part of the text message
0118      * @param dest the URL of the destination file/dir, i.e. the one that already exists
0119      * @param options parameters for the dialog (which buttons to show...)
0120      * @param newDestPath the new destination path, valid if R_RENAME was returned.
0121      * @param sizeSrc size of source file
0122      * @param sizeDest size of destination file
0123      * @param ctimeSrc creation time of source file
0124      * @param ctimeDest creation time of destination file
0125      * @param mtimeSrc modification time of source file
0126      * @param mtimeDest modification time of destination file
0127      * @return the result
0128      */
0129     RenameDialog_Result askFileRename(KJob *job,
0130                                       const QString &title,
0131                                       const QUrl &src,
0132                                       const QUrl &dest,
0133                                       KIO::RenameDialog_Options options,
0134                                       QString &newDest,
0135                                       KIO::filesize_t sizeSrc = KIO::filesize_t(-1),
0136                                       KIO::filesize_t sizeDest = KIO::filesize_t(-1),
0137                                       const QDateTime &ctimeSrc = QDateTime(),
0138                                       const QDateTime &ctimeDest = QDateTime(),
0139                                       const QDateTime &mtimeSrc = QDateTime(),
0140                                       const QDateTime &mtimeDest = QDateTime()) override;
0141 
0142     /**
0143      * @internal
0144      * See skipdialog.h
0145      */
0146     SkipDialog_Result askSkip(KJob *job, KIO::SkipDialog_Options options, const QString &error_text) override;
0147 
0148     /**
0149      * Ask for confirmation before deleting/trashing @p urls.
0150      *
0151      * Note that this method is not called automatically by KIO jobs. It's the application's
0152      * responsibility to ask the user for confirmation before calling KIO::del() or KIO::trash().
0153      *
0154      * @param urls the urls about to be deleted/trashed
0155      * @param deletionType the type of deletion (Delete for real deletion, Trash otherwise)
0156      * @param confirmation see ConfirmationType. Normally set to DefaultConfirmation.
0157      * Note: the window passed to setWindow is used as the parent for the message box.
0158      * @return true if confirmed
0159      */
0160     bool askDeleteConfirmation(const QList<QUrl> &urls, DeletionType deletionType, ConfirmationType confirmationType) override;
0161 
0162     /**
0163      * This function allows for the delegation user prompts from the KIO workers.
0164      *
0165      * @param type the desired type of message box.
0166      * @param text the message shown to the user.
0167      * @param title the title of the message dialog box.
0168      * @param primaryActionText the text for the primary action button.
0169      * @param secondaryActionText the text for the secondary action button.
0170      * @param primaryActionIconName the icon shown on the primary action button.
0171      * @param secondaryActionIconName the icon shown on the secondary action button.
0172      * @param dontAskAgainName the name used to store result from 'Do not ask again' checkbox.
0173      * @param metaData SSL information used by the SSLMessageBox. Since 5.66 this is also used for privilege operation details.
0174      *
0175      * @since 4.11
0176      *
0177      * @internal
0178      */
0179     // KF6 TODO Add a QString parameter for "details" and keep in sync with API in SlaveBase, SlaveInterface, and JobUiDelegateExtension.
0180     int requestMessageBox(MessageBoxType type,
0181                           const QString &text,
0182                           const QString &title,
0183                           const QString &primaryActionText,
0184                           const QString &secondaryActionText,
0185                           const QString &primaryActionIconName = QString(),
0186                           const QString &secondaryActionIconName = QString(),
0187                           const QString &dontAskAgainName = QString(),
0188                           const KIO::MetaData &metaData = KIO::MetaData()) override;
0189 
0190     /**
0191      * Creates a clipboard updater
0192      */
0193     ClipboardUpdater *createClipboardUpdater(Job *job, ClipboardUpdaterMode mode) override;
0194     /**
0195      * Update URL in clipboard, if present
0196      */
0197     void updateUrlInClipboard(const QUrl &src, const QUrl &dest) override;
0198 
0199 private:
0200     std::unique_ptr<JobUiDelegatePrivate> const d;
0201 };
0202 }
0203 
0204 #endif