]>
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
) :
34 setCaption(i18n("Rename Items"));
35 setButtons(Ok
|Cancel
);
38 setButtonGuiItem(Ok
, KGuiItem(i18n("Rename"), "apply"));
40 QWidget
*page
= new QWidget(this);
43 Q3VBoxLayout
* topLayout
= new Q3VBoxLayout(page
, 0, spacingHint());
44 topLayout
->setMargin(KDialog::marginHint());
46 const int itemCount
= items
.count();
47 QLabel
* editLabel
= new QLabel(i18n("Rename the %1 selected items to:",itemCount
),
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
68 const int selectionLength
= m_newName
.length();
69 if (postfix
.length() > 0) {
70 m_newName
.append(postfix
);
72 m_lineEdit
->setText(m_newName
);
73 m_lineEdit
->setSelection(0, selectionLength
- 1);
74 m_lineEdit
->setFocus();
76 QLabel
* infoLabel
= new QLabel(i18n("(# will be replaced by ascending numbers)"), page
);
78 topLayout
->addWidget(editLabel
);
79 topLayout
->addWidget(m_lineEdit
);
80 topLayout
->addWidget(infoLabel
);
83 RenameDialog::~RenameDialog()
87 void RenameDialog::slotButtonClicked(int button
)
90 m_newName
= m_lineEdit
->text();
91 if (m_newName
.contains('#') != 1) {
92 m_newName
.truncate(0);
96 KDialog::slotButtonClicked(button
);
99 #include "renamedialog.moc"