1 /*
2     This file is part of the KDE libraries
3     SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
4     SPDX-FileCopyrightText: 1999-2008 David Faure <faure@kde.org>
5     SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org>
6 
7     SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef KIO_RENAMEDIALOG_H
11 #define KIO_RENAMEDIALOG_H
12 
13 #include <QDateTime>
14 #include <QDialog>
15 #include <QString>
16 #include <kio/jobuidelegateextension.h>
17 
18 #include "kiowidgets_export.h"
19 #include <kio/global.h>
20 
21 class QScrollArea;
22 class QLabel;
23 class QPixmap;
24 class KFileItem;
25 class KSqueezedTextLabel;
26 
27 namespace KIO
28 {
29 /**
30  * @class KIO::RenameDialog renamedialog.h <KIO/RenameDialog>
31  *
32  * The dialog shown when a CopyJob realizes that a destination file already exists,
33  * and wants to offer the user with the choice to either Rename, Overwrite, Skip;
34  * this dialog is also used when a .part file exists and the user can choose to
35  * Resume a previous download.
36  */
37 class KIOWIDGETS_EXPORT RenameDialog : public QDialog
38 {
39     Q_OBJECT
40 public:
41     /**
42      * Construct a "rename" dialog to let the user know that @p src is about to overwrite @p dest.
43      *
44      * @param parent parent widget (often 0)
45      * @param caption the caption for the dialog box
46      * @param src the url to the file/dir we're trying to copy, as it's part of the text message
47      * @param dest the path to destination file/dir, i.e. the one that already exists
48      * @param options parameters for the dialog (which buttons to show...),
49      * @param sizeSrc size of source file
50      * @param sizeDest size of destination file
51      * @param ctimeSrc creation time of source file
52      * @param ctimeDest creation time of destination file
53      * @param mtimeSrc modification time of source file
54      * @param mtimeDest modification time of destination file
55      */
56     RenameDialog(QWidget *parent,
57                  const QString &caption,
58                  const QUrl &src,
59                  const QUrl &dest,
60                  RenameDialog_Options options,
61                  KIO::filesize_t sizeSrc = KIO::filesize_t(-1),
62                  KIO::filesize_t sizeDest = KIO::filesize_t(-1),
63                  const QDateTime &ctimeSrc = QDateTime(),
64                  const QDateTime &ctimeDest = QDateTime(),
65                  const QDateTime &mtimeSrc = QDateTime(),
66                  const QDateTime &mtimeDest = QDateTime());
67     ~RenameDialog() override;
68 
69     /**
70      * @return the new destination
71      * valid only if RENAME was chosen
72      */
73     QUrl newDestUrl();
74 
75     /**
76      * @return an automatically renamed destination
77      * @since 4.5
78      * valid always
79      */
80     QUrl autoDestUrl() const;
81 
82 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 0)
83     /**
84      * Given a directory path and a filename (which usually exists already),
85      * this function returns a suggested name for a file that doesn't exist
86      * in that directory. The existence is only checked for local urls though.
87      * The suggested file name is of the form "foo 1", "foo 2" etc.
88      * @deprecated Since 5.0. Use KIO::suggestName, since 5.61, use KFileUtils::suggestName from KCoreAddons
89      */
90     KIOWIDGETS_DEPRECATED_VERSION(
91         5,
92         0,
93         "Use KFileUtils::suggestName(const QUrl &, const QString &) from KCoreAddons >= 5.61, or KIO::suggestName(const QUrl &, const QString &)")
94     static QString suggestName(const QUrl &baseURL, const QString &oldName);
95 #endif
96 
97 public Q_SLOTS:
98     void cancelPressed();
99     void renamePressed();
100     void skipPressed();
101     void autoSkipPressed();
102     void overwritePressed();
103     void overwriteAllPressed();
104     void overwriteWhenOlderPressed();
105     void resumePressed();
106     void resumeAllPressed();
107     void suggestNewNamePressed();
108 
109 protected Q_SLOTS:
110     void enableRenameButton(const QString &);
111 private Q_SLOTS:
112     void applyAllPressed();
113     void showSrcIcon(const KFileItem &);
114     void showDestIcon(const KFileItem &);
115     void showSrcPreview(const KFileItem &, const QPixmap &);
116     void showDestPreview(const KFileItem &, const QPixmap &);
117     void resizePanels();
118 
119 private:
120     QScrollArea *createContainerLayout(QWidget *parent, const KFileItem &item, QLabel *preview);
121     class RenameDialogPrivate;
122     RenameDialogPrivate *const d;
123 };
124 
125 }
126 
127 #endif
128