]> cloud.milkyroute.net Git - dolphin.git/blob - src/renamedialog.cpp
commited initial version of Dolphin
[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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 KDialogBase(Plain, i18n("Rename Items"),
33 Ok|Cancel, Ok)
34 {
35 setButtonOK(KGuiItem(i18n("Rename"), "apply"));
36
37 Q3VBoxLayout* topLayout = new Q3VBoxLayout(plainPage(), 0, spacingHint());
38 topLayout->setMargin(KDialog::marginHint());
39
40 const int itemCount = items.count();
41 QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:").arg(itemCount),
42 plainPage());
43
44 m_lineEdit = new KLineEdit(plainPage());
45 m_newName = i18n("New name #");
46 assert(itemCount > 1);
47 QString postfix(items[0].prettyURL().section('.',1));
48 if (postfix.length() > 0) {
49 // The first item seems to have a postfix (e. g. 'jpg' or 'txt'). Now
50 // check whether all other items have the same postfix. If this is the
51 // case, add this postfix to the name suggestion.
52 postfix.insert(0, '.');
53 for (int i = 1; i < itemCount; ++i) {
54 if (!items[i].prettyURL().contains(postfix)) {
55 // at least one item does not have the same postfix
56 postfix.truncate(0);
57 break;
58 }
59 }
60 }
61
62 const int selectionLength = m_newName.length();
63 if (postfix.length() > 0) {
64 m_newName.append(postfix);
65 }
66 m_lineEdit->setText(m_newName);
67 m_lineEdit->setSelection(0, selectionLength - 1);
68 m_lineEdit->setFocus();
69
70 QLabel* infoLabel = new QLabel(i18n("(# will be replaced by ascending numbers)"), plainPage());
71
72 topLayout->addWidget(editLabel);
73 topLayout->addWidget(m_lineEdit);
74 topLayout->addWidget(infoLabel);
75 }
76
77 RenameDialog::~RenameDialog()
78 {
79 }
80
81 void RenameDialog::slotOk()
82 {
83 m_newName = m_lineEdit->text();
84 if (m_newName.contains('#') != 1) {
85 m_newName.truncate(0);
86 }
87
88 KDialogBase::slotOk();
89 }
90
91 #include "renamedialog.moc"