]> cloud.milkyroute.net Git - dolphin.git/blob - src/renamedialog.cpp
Cleanup of URL drop handling (simplified code, modifier keys work again). After furth...
[dolphin.git] / src / renamedialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "renamedialog.h"
22 #include <klocale.h>
23 #include <qlabel.h>
24 #include <qlayout.h>
25 #include <q3vbox.h>
26 //Added by qt3to4:
27 #include <Q3VBoxLayout>
28 #include <assert.h>
29 #include <klineedit.h>
30
31 RenameDialog::RenameDialog(const KUrl::List& items) :
32 KDialog()
33 {
34 setCaption(i18n("Rename Items"));
35 setButtons(Ok|Cancel);
36 setDefaultButton(Ok);
37
38 setButtonGuiItem(Ok, KGuiItem(i18n("Rename"), "apply"));
39
40 QWidget *page = new QWidget(this);
41 setMainWidget(page);
42
43 Q3VBoxLayout* topLayout = new Q3VBoxLayout(page, 0, spacingHint());
44 topLayout->setMargin(KDialog::marginHint());
45
46 const int itemCount = items.count();
47 QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:",itemCount),
48 page);
49
50 m_lineEdit = new KLineEdit(page);
51 m_newName = i18n("New name #");
52 assert(itemCount > 1);
53 QString postfix(items[0].prettyUrl().section('.',1));
54 if (postfix.length() > 0) {
55 // The first item seems to have a postfix (e. g. 'jpg' or 'txt'). Now
56 // check whether all other items have the same postfix. If this is the
57 // case, add this postfix to the name suggestion.
58 postfix.insert(0, '.');
59 for (int i = 1; i < itemCount; ++i) {
60 if (!items[i].prettyUrl().contains(postfix)) {
61 // at least one item does not have the same postfix
62 postfix.truncate(0);
63 break;
64 }
65 }
66 }
67
68 const int selectionLength = m_newName.length();
69 if (postfix.length() > 0) {
70 m_newName.append(postfix);
71 }
72 m_lineEdit->setText(m_newName);
73 m_lineEdit->setSelection(0, selectionLength - 1);
74 m_lineEdit->setFocus();
75
76 QLabel* infoLabel = new QLabel(i18n("(# will be replaced by ascending numbers)"), page);
77
78 topLayout->addWidget(editLabel);
79 topLayout->addWidget(m_lineEdit);
80 topLayout->addWidget(infoLabel);
81 }
82
83 RenameDialog::~RenameDialog()
84 {
85 }
86
87 void RenameDialog::slotButtonClicked(int button)
88 {
89 if (button==Ok) {
90 m_newName = m_lineEdit->text();
91 if (m_newName.contains('#') != 1) {
92 m_newName.truncate(0);
93 }
94 }
95
96 KDialog::slotButtonClicked(button);
97 }
98
99 #include "renamedialog.moc"