]> cloud.milkyroute.net Git - dolphin.git/blob - src/renamedialog.h
516411b3c0c8e5594093d4f7b754b2dcaf29bb29
[dolphin.git] / src / renamedialog.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19 #ifndef RENAMEDIALOG_H
20 #define RENAMEDIALOG_H
21
22 #include "libdolphin_export.h"
23
24 #include <kdialog.h>
25 #include <kurl.h>
26
27
28 class KFileItem;
29 class KLineEdit;
30
31 /**
32 * @brief Dialog for renaming a variable number of files.
33 *
34 * The renaming is not done by the dialog, the invoker
35 * must do this itself:
36 * \code
37 * RenameDialog dialog(...);
38 * if (dialog.exec() == QDialog::Accepted) {
39 * const QString& newName = dialog.newName();
40 * if (newName.isEmpty()) {
41 * // an invalid name has been chosen, use
42 * // dialog.errorString() to tell the user about this
43 * }
44 * else {
45 * // rename items corresponding to the new name
46 * }
47 * }
48 * \endcode
49 */
50 class LIBDOLPHINPRIVATE_EXPORT RenameDialog : public KDialog
51 {
52 Q_OBJECT
53
54 public:
55 explicit RenameDialog(const QList<KFileItem>& items);
56 virtual ~RenameDialog();
57
58 /**
59 * Returns the new name of the items. If more than one
60 * item should be renamed, then it is assured that the # character
61 * is part of the returned string. If the returned string is empty,
62 * then RenameDialog::errorString() should be used to show the reason
63 * of having an empty string (e. g. if the # character has
64 * been deleted by the user, although more then one item should be
65 * renamed).
66 */
67 const QString& newName() const
68 {
69 return m_newName;
70 }
71
72 /**
73 * Returns the error string, if Dialog::newName() returned an empty string.
74 */
75 const QString& errorString() const
76 {
77 return m_errorString;
78 }
79
80 protected slots:
81 virtual void slotButtonClicked(int button);
82
83 private:
84 /**
85 * Returns the extension string for a filename, which contains all
86 * file extensions. Version numbers like in "cmake-2.4.5" don't count
87 * as file extension. If the version numbers follow after a valid extension, they
88 * are part of the extension string.
89 *
90 * Examples (name -> extension string):
91 * "Image.gif" -> ".gif"
92 * "package.tar.gz" -> ".tar.gz"
93 * "cmake-2.4.5" -> ""
94 * "Image.1.12.gif" -> ".gif"
95 * "Image.tar.1.12.gz" -> ".tar.1.12.gz"
96 */
97 static QString extensionString(const QString& name);
98
99 private:
100 bool m_renameOneItem;
101 KLineEdit* m_lineEdit;
102 QString m_newName;
103 QString m_errorString;
104
105 friend class RenameDialogTest; // allow access for unit testing
106 };
107
108 #endif