File indexing completed on 2024-12-01 12:36:43

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
0004     SPDX-FileCopyrightText: 1999-2008 David Faure <faure@kde.org>
0005     SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef KIO_RENAMEDIALOG_H
0011 #define KIO_RENAMEDIALOG_H
0012 
0013 #include <QDateTime>
0014 #include <QDialog>
0015 #include <QString>
0016 #include <kio/jobuidelegateextension.h>
0017 
0018 #include "kiowidgets_export.h"
0019 #include <kio/global.h>
0020 
0021 #include <memory>
0022 
0023 class QScrollArea;
0024 class QLabel;
0025 class QPixmap;
0026 class KFileItem;
0027 class KSqueezedTextLabel;
0028 
0029 namespace KIO
0030 {
0031 /**
0032  * @class KIO::RenameDialog renamedialog.h <KIO/RenameDialog>
0033  *
0034  * The dialog shown when a CopyJob realizes that a destination file already exists,
0035  * and wants to offer the user with the choice to either Rename, Overwrite, Skip;
0036  * this dialog is also used when a .part file exists and the user can choose to
0037  * Resume a previous download.
0038  */
0039 class KIOWIDGETS_EXPORT RenameDialog : public QDialog
0040 {
0041     Q_OBJECT
0042 public:
0043     /**
0044      * Construct a "rename" dialog to let the user know that @p src is about to overwrite @p dest.
0045      *
0046      * @param parent parent widget (often 0)
0047      * @param title the title for the dialog box
0048      * @param src the url to the file/dir we're trying to copy, as it's part of the text message
0049      * @param dest the path to destination file/dir, i.e. the one that already exists
0050      * @param options parameters for the dialog (which buttons to show...),
0051      * @param sizeSrc size of source file
0052      * @param sizeDest size of destination file
0053      * @param ctimeSrc creation time of source file
0054      * @param ctimeDest creation time of destination file
0055      * @param mtimeSrc modification time of source file
0056      * @param mtimeDest modification time of destination file
0057      */
0058     RenameDialog(QWidget *parent,
0059                  const QString &title,
0060                  const QUrl &src,
0061                  const QUrl &dest,
0062                  RenameDialog_Options options,
0063                  KIO::filesize_t sizeSrc = KIO::filesize_t(-1),
0064                  KIO::filesize_t sizeDest = KIO::filesize_t(-1),
0065                  const QDateTime &ctimeSrc = QDateTime(),
0066                  const QDateTime &ctimeDest = QDateTime(),
0067                  const QDateTime &mtimeSrc = QDateTime(),
0068                  const QDateTime &mtimeDest = QDateTime());
0069     ~RenameDialog() override;
0070 
0071     /**
0072      * @return the new destination
0073      * valid only if RENAME was chosen
0074      */
0075     QUrl newDestUrl();
0076 
0077     /**
0078      * @return an automatically renamed destination
0079      * @since 4.5
0080      * valid always
0081      */
0082     QUrl autoDestUrl() const;
0083 
0084 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 0)
0085     /**
0086      * Given a directory path and a filename (which usually exists already),
0087      * this function returns a suggested name for a file that doesn't exist
0088      * in that directory. The existence is only checked for local urls though.
0089      * The suggested file name is of the form "foo 1", "foo 2" etc.
0090      * @deprecated Since 5.0. Use KIO::suggestName, since 5.61, use KFileUtils::suggestName from KCoreAddons
0091      */
0092     KIOWIDGETS_DEPRECATED_VERSION(
0093         5,
0094         0,
0095         "Use KFileUtils::suggestName(const QUrl &, const QString &) from KCoreAddons >= 5.61, or KIO::suggestName(const QUrl &, const QString &)")
0096     static QString suggestName(const QUrl &baseURL, const QString &oldName);
0097 #endif
0098 
0099 public Q_SLOTS:
0100     void cancelPressed();
0101     void renamePressed();
0102     void skipPressed();
0103     void autoSkipPressed();
0104     void overwritePressed();
0105     void overwriteAllPressed();
0106     void overwriteWhenOlderPressed();
0107     void resumePressed();
0108     void resumeAllPressed();
0109     void suggestNewNamePressed();
0110 
0111 protected Q_SLOTS:
0112     void enableRenameButton(const QString &);
0113 private Q_SLOTS:
0114     KIOWIDGETS_NO_EXPORT void applyAllPressed();
0115     KIOWIDGETS_NO_EXPORT void showSrcIcon(const KFileItem &);
0116     KIOWIDGETS_NO_EXPORT void showDestIcon(const KFileItem &);
0117     KIOWIDGETS_NO_EXPORT void showSrcPreview(const KFileItem &, const QPixmap &);
0118     KIOWIDGETS_NO_EXPORT void showDestPreview(const KFileItem &, const QPixmap &);
0119     KIOWIDGETS_NO_EXPORT void resizePanels();
0120 
0121 private:
0122     KIOWIDGETS_NO_EXPORT QScrollArea *createContainerLayout(QWidget *parent, const KFileItem &item, QLabel *preview);
0123 
0124     class RenameDialogPrivate;
0125     std::unique_ptr<RenameDialogPrivate> const d;
0126 };
0127 
0128 }
0129 
0130 #endif