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