1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 2000 Stephan Kulow <coolo@kde.org> |
3 | 1999 - 2008 David Faure <faure@kde.org> |
4 | 2001 Holger Freyther <freyther@kde.org> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #ifndef KIO_RENAMEDIALOG_H |
23 | #define KIO_RENAMEDIALOG_H |
24 | |
25 | #include <ksqueezedtextlabel.h> |
26 | #include <kurl.h> |
27 | #include <QtGui/QDialog> |
28 | #include <QtCore/QString> |
29 | #include <sys/types.h> |
30 | |
31 | #include <kio/global.h> |
32 | |
33 | class QScrollArea; |
34 | class QLabel; |
35 | class QPixmap; |
36 | class KFileItem; |
37 | |
38 | namespace KIO |
39 | { |
40 | |
41 | // KDE5: get rid of M_OVERWRITE_ITSELF, trigger it internally if src==dest |
42 | // KDE5: get rid of M_SINGLE. If not multi, then single ;) |
43 | // KDE5: use QFlags to get rid of all the casting! |
44 | /** |
45 | * M_OVERWRITE: We have an existing dest, show details about it and offer to overwrite it. |
46 | * M_OVERWRITE_ITSELF: Warn that the current operation would overwrite a file with itself, |
47 | * which is not allowed. |
48 | * M_SKIP: Offer a "Skip" button, to skip other files too. Requires M_MULTI. |
49 | * M_SINGLE: Deprecated and unused, please ignore. |
50 | * M_MULTI: 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 | * M_RESUME: Offer a "Resume" button (plus "Resume All" if M_MULTI) |
53 | * M_NORENAME: Don't offer a "Rename" button |
54 | * M_ISDIR: The dest is a directory, so label the "overwrite" button something like "merge" instead. |
55 | */ |
56 | enum RenameDialog_Mode { M_OVERWRITE = 1, M_OVERWRITE_ITSELF = 2, M_SKIP = 4, M_SINGLE = 8, M_MULTI = 16, M_RESUME = 32, M_NORENAME = 64, M_ISDIR = 128 }; |
57 | |
58 | /** |
59 | * The result of open_RenameDialog(). |
60 | */ |
61 | enum RenameDialog_Result {R_RESUME = 6, R_RESUME_ALL = 7, R_OVERWRITE = 4, R_OVERWRITE_ALL = 5, R_SKIP = 2, R_AUTO_SKIP = 3, R_RENAME = 1, R_AUTO_RENAME = 8, R_CANCEL = 0}; |
62 | |
63 | |
64 | /** |
65 | * The dialog shown when a CopyJob realizes that a destination file already exists, |
66 | * and wants to offer the user with the choice to either Rename, Overwrite, Skip; |
67 | * this dialog is also used when a .part file exists and the user can choose to |
68 | * Resume a previous download. |
69 | */ |
70 | class KIO_EXPORT RenameDialog : public QDialog |
71 | { |
72 | Q_OBJECT |
73 | public: |
74 | /** |
75 | * Construct a "rename" dialog to let the user know that @p src is about to overwrite @p dest. |
76 | * |
77 | * @param parent parent widget (often 0) |
78 | * @param caption the caption for the dialog box |
79 | * @param src the url to the file/dir we're trying to copy, as it's part of the text message |
80 | * @param dest the path to destination file/dir, i.e. the one that already exists |
81 | * @param mode parameters for the dialog (which buttons to show...), |
82 | * @param sizeSrc size of source file |
83 | * @param sizeDest size of destination file |
84 | * @param ctimeSrc creation time of source file |
85 | * @param ctimeDest creation time of destination file |
86 | * @param mtimeSrc modification time of source file |
87 | * @param mtimeDest modification time of destination file |
88 | * @see RenameDialog_Mode |
89 | */ |
90 | RenameDialog(QWidget *parent, const QString & caption, |
91 | const KUrl & src, const KUrl & dest, |
92 | RenameDialog_Mode mode, |
93 | KIO::filesize_t sizeSrc = KIO::filesize_t(-1), |
94 | KIO::filesize_t sizeDest = KIO::filesize_t(-1), |
95 | time_t ctimeSrc = time_t(-1), |
96 | time_t ctimeDest = time_t(-1), |
97 | time_t mtimeSrc = time_t(-1), |
98 | time_t mtimeDest = time_t(-1)); |
99 | ~RenameDialog(); |
100 | |
101 | /** |
102 | * @return the new destination |
103 | * valid only if RENAME was chosen |
104 | */ |
105 | KUrl newDestUrl(); |
106 | |
107 | |
108 | /** |
109 | * @return an automatically renamed destination |
110 | * @since 4.5 |
111 | * valid always |
112 | */ |
113 | KUrl autoDestUrl() const; |
114 | |
115 | /** |
116 | * Given a directory path and a filename (which usually exists already), |
117 | * this function returns a suggested name for a file that doesn't exist |
118 | * in that directory. The existence is only checked for local urls though. |
119 | * The suggested file name is of the form "foo 1", "foo 2" etc. |
120 | */ |
121 | static QString suggestName(const KUrl& baseURL, const QString& oldName); |
122 | |
123 | public Q_SLOTS: |
124 | void cancelPressed(); |
125 | void renamePressed(); |
126 | void skipPressed(); |
127 | void autoSkipPressed(); |
128 | void overwritePressed(); |
129 | void overwriteAllPressed(); |
130 | void resumePressed(); |
131 | void resumeAllPressed(); |
132 | void suggestNewNamePressed(); |
133 | |
134 | protected Q_SLOTS: |
135 | void enableRenameButton(const QString &); |
136 | private Q_SLOTS: |
137 | void applyAllPressed(); |
138 | void showSrcIcon(const KFileItem &); |
139 | void showDestIcon(const KFileItem &); |
140 | void showSrcPreview(const KFileItem &, const QPixmap &); |
141 | void showDestPreview(const KFileItem &, const QPixmap &); |
142 | void resizePanels(); |
143 | |
144 | private: |
145 | QScrollArea* createContainerLayout(QWidget* parent, const KFileItem& item, QLabel* preview); |
146 | QLabel* createLabel(QWidget* parent, const QString& text, const bool containerTitle); |
147 | KSqueezedTextLabel* createSqueezedLabel(QWidget* parent, const QString& text); |
148 | class RenameDialogPrivate; |
149 | RenameDialogPrivate* const d; |
150 | }; |
151 | |
152 | } |
153 | |
154 | #endif |
155 | |