]> cloud.milkyroute.net Git - dolphin.git/blob - src/renamedialog.h
Adapt Dolphin Nepomuk support to namespace changes.
[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 KLineEdit;
29
30 /**
31 * @brief Dialog for renaming a variable number of files.
32 *
33 * The renaming is not done by the dialog, the invoker
34 * must do this itself:
35 * \code
36 * RenameDialog dialog(...);
37 * if (dialog.exec() == QDialog::Accepted) {
38 * const QString& newName = dialog.newName();
39 * if (newName.isEmpty()) {
40 * // an invalid name has been chosen, use
41 * // dialog.errorString() to tell the user about this
42 * }
43 * else {
44 * // rename items corresponding to the new name
45 * }
46 * }
47 * \endcode
48 */
49 class LIBDOLPHINPRIVATE_EXPORT RenameDialog : public KDialog
50 {
51 Q_OBJECT
52
53 public:
54 explicit RenameDialog(const KUrl::List& items);
55 virtual ~RenameDialog();
56
57 /**
58 * Returns the new name of the items. If more than one
59 * item should be renamed, then it is assured that the # character
60 * is part of the returned string. If the returned string is empty,
61 * then RenameDialog::errorString() should be used to show the reason
62 * of having an empty string (e. g. if the # character has
63 * been deleted by the user, although more then one item should be
64 * renamed).
65 */
66 const QString& newName() const
67 {
68 return m_newName;
69 }
70
71 /**
72 * Returns the error string, if Dialog::newName() returned an empty string.
73 */
74 const QString& errorString() const
75 {
76 return m_errorString;
77 }
78
79 protected slots:
80 virtual void slotButtonClicked(int button);
81
82 private:
83 /**
84 * Returns the extension string for a filename, which contains all
85 * file extensions. Version numbers like in "cmake-2.4.5" don't count
86 * as file extension. If the version numbers follow after a valid extension, they
87 * are part of the extension string.
88 *
89 * Examples (name -> extension string):
90 * "Image.gif" -> ".gif"
91 * "package.tar.gz" -> ".tar.gz"
92 * "cmake-2.4.5" -> ""
93 * "Image.1.12.gif" -> ".gif"
94 * "Image.tar.1.12.gz" -> ".tar.1.12.gz"
95 */
96 static QString extensionString(const QString& name);
97
98 private:
99 bool m_renameOneItem;
100 KLineEdit* m_lineEdit;
101 QString m_newName;
102 QString m_errorString;
103
104 friend class RenameDialogTest; // allow access for unit testing
105 };
106
107 #endif