]>
cloud.milkyroute.net Git - dolphin.git/blob - src/renamedialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
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. *
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. *
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 ***************************************************************************/
21 #include "renamedialog.h"
27 #include <Q3VBoxLayout>
29 #include <klineedit.h>
31 RenameDialog::RenameDialog(const KUrl::List
& items
) :
32 KDialogBase(Plain
, i18n("Rename Items"),
35 setButtonOK(KGuiItem(i18n("Rename"), "apply"));
37 Q3VBoxLayout
* topLayout
= new Q3VBoxLayout(plainPage(), 0, spacingHint());
38 topLayout
->setMargin(KDialog::marginHint());
40 const int itemCount
= items
.count();
41 QLabel
* editLabel
= new QLabel(i18n("Rename the %1 selected items to:").arg(itemCount
),
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
62 const int selectionLength
= m_newName
.length();
63 if (postfix
.length() > 0) {
64 m_newName
.append(postfix
);
66 m_lineEdit
->setText(m_newName
);
67 m_lineEdit
->setSelection(0, selectionLength
- 1);
68 m_lineEdit
->setFocus();
70 QLabel
* infoLabel
= new QLabel(i18n("(# will be replaced by ascending numbers)"), plainPage());
72 topLayout
->addWidget(editLabel
);
73 topLayout
->addWidget(m_lineEdit
);
74 topLayout
->addWidget(infoLabel
);
77 RenameDialog::~RenameDialog()
81 void RenameDialog::slotOk()
83 m_newName
= m_lineEdit
->text();
84 if (m_newName
.contains('#') != 1) {
85 m_newName
.truncate(0);
88 KDialogBase::slotOk();
91 #include "renamedialog.moc"