File: renamefile.cpp

package info (click to toggle)
kget 4%3A16.08.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,440 kB
  • ctags: 4,323
  • sloc: cpp: 37,020; xml: 341; python: 290; perl: 41; sh: 11; makefile: 4
file content (67 lines) | stat: -rw-r--r-- 2,637 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/***************************************************************************
*   Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>                     *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
***************************************************************************/

#include "renamefile.h"
#include "core/filemodel.h"

#include <QtCore/QFile>

#include <KLocale>

RenameFile::RenameFile(FileModel *model, const QModelIndex &index, QWidget *parent, Qt::WFlags flags)
  : KDialog(parent, flags),
    m_model(model),
    m_index(index)
{
    setCaption(i18n("Rename File"));
    showButtonSeparator(true);
    QWidget *widget = new QWidget(this);
    ui.setupUi(widget);
    setMainWidget(widget);

    const QString originalName = m_model->data(m_index, Qt::DisplayRole).toString();
    m_dest = m_model->getUrl(m_index).upUrl();

    ui.label->setText(i18n("Rename %1 to:", originalName));
    ui.name->setText(originalName);

    setButtonText(KDialog::Ok, i18n("&Rename"));
    enableButtonOk(false);

    connect(ui.name, SIGNAL(textEdited(QString)), this, SLOT(updateButton()));
    connect(this, SIGNAL(okClicked()), this, SLOT(rename()));
}

void RenameFile::updateButton()
{
    const QString newName = ui.name->text();
    KUrl dest = m_dest;
    dest.addPath(newName);

    const bool enabled = !newName.isEmpty() && !QFile::exists(dest.pathOrUrl());
    enableButtonOk(enabled);
}

void RenameFile::rename()
{
    const QString newName = ui.name->text();
    m_model->rename(m_index, newName);
}

#include "renamefile.moc"