]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/renamedialog.h
Disables the rename button if no name or an identical name has been specified.
[dolphin.git] / src / views / 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 class KFileItem;
28 class KFileItemList;
29 class KLineEdit;
30
31 #include <QString>
32
33 /**
34 * @brief Dialog for renaming a variable number of files.
35 *
36 * The renaming is not done by the dialog, the invoker
37 * must do this itself:
38 * \code
39 * RenameDialog dialog(...);
40 * if (dialog.exec() == QDialog::Accepted) {
41 * const QString& newName = dialog.newName();
42 * if (newName.isEmpty()) {
43 * // an invalid name has been chosen, use
44 * // dialog.errorString() to tell the user about this
45 * }
46 * else {
47 * // rename items corresponding to the new name
48 * }
49 * }
50 * \endcode
51 */
52 class LIBDOLPHINPRIVATE_EXPORT RenameDialog : public KDialog
53 {
54 Q_OBJECT
55
56 public:
57 explicit RenameDialog(QWidget *parent, const KFileItemList& items);
58 virtual ~RenameDialog();
59
60 /**
61 * Returns the new name of the items. If more than one
62 * item should be renamed, then it is assured that the # character
63 * is part of the returned string. If the returned string is empty,
64 * then RenameDialog::errorString() should be used to show the reason
65 * of having an empty string (e. g. if the # character has
66 * been deleted by the user, although more than one item should be
67 * renamed).
68 */
69 QString newName() const;
70
71 /**
72 * Returns the error string, if Dialog::newName() returned an empty string.
73 */
74 QString errorString() const;
75
76 protected slots:
77 virtual void slotButtonClicked(int button);
78
79 private slots:
80 void slotTextChanged(const QString &newName);
81
82 private:
83 bool m_renameOneItem;
84 KLineEdit* m_lineEdit;
85 QString m_newName;
86 QString m_errorString;
87
88 friend class RenameDialogTest; // allow access for unit testing
89 };
90
91 inline QString RenameDialog::newName() const
92 {
93 return m_newName;
94 }
95
96 inline QString RenameDialog::errorString() const
97 {
98 return m_errorString;
99 }
100
101 #endif