• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • ui
renamefile.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
19 
20 #include "renamefile.h"
21 #include "core/filemodel.h"
22 
23 #include <QtCore/QFile>
24 
25 #include <KLocale>
26 
27 RenameFile::RenameFile(FileModel *model, const QModelIndex &index, QWidget *parent, Qt::WFlags flags)
28  : KDialog(parent, flags),
29  m_model(model),
30  m_index(index)
31 {
32  setCaption(i18n("Rename File"));
33  showButtonSeparator(true);
34  QWidget *widget = new QWidget(this);
35  ui.setupUi(widget);
36  setMainWidget(widget);
37 
38  const QString originalName = m_model->data(m_index, Qt::DisplayRole).toString();
39  m_dest = m_model->getUrl(m_index).upUrl();
40 
41  ui.label->setText(i18n("Rename %1 to:", originalName));
42  ui.name->setText(originalName);
43 
44  setButtonText(KDialog::Ok, i18n("&Rename"));
45  enableButtonOk(false);
46 
47  connect(ui.name, SIGNAL(textEdited(QString)), this, SLOT(updateButton()));
48  connect(this, SIGNAL(okClicked()), this, SLOT(rename()));
49 }
50 
51 void RenameFile::updateButton()
52 {
53  const QString newName = ui.name->text();
54  KUrl dest = m_dest;
55  dest.addPath(newName);
56 
57  const bool enabled = !newName.isEmpty() && !QFile::exists(dest.pathOrUrl());
58  enableButtonOk(enabled);
59 }
60 
61 void RenameFile::rename()
62 {
63  const QString newName = ui.name->text();
64  m_model->rename(m_index, newName);
65 }
66 
67 #include "renamefile.moc"
QWidget
KDialog
FileModel
This model represents the files that are being downloaded.
Definition: filemodel.h:101
renamefile.h
FileModel::rename
void rename(const QModelIndex &file, const QString &newName)
Definition: filemodel.cpp:649
FileModel::data
QVariant data(const QModelIndex &index, int role) const
Definition: filemodel.cpp:344
RenameFile::RenameFile
RenameFile(FileModel *model, const QModelIndex &index, QWidget *parent=0, Qt::WFlags flags=0)
Definition: renamefile.cpp:27
FileModel::getUrl
KUrl getUrl(const QModelIndex &index)
The url on the filesystem (no check if the file exists yet!) of index, it can be a folder or file...
Definition: filemodel.cpp:544
filemodel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal