Commit 0d0b9583 authored by Emmanuel Pescosta's avatar Emmanuel Pescosta
Browse files

Fix Bug 319119 - Dolphin doesn't notice when renaming failed

Change the data in the model before the real renaming is done by KonqOperations::rename(),
but when the rename operation fails, revert the data changes in the model.

BUG: 319119
REVIEW: 110922
parent ba336575
......@@ -1363,6 +1363,16 @@ void DolphinView::slotDeleteFileFinished(KJob* job)
}
}
void DolphinView::slotRenamingFailed(const KUrl& oldUrl, const KUrl& newUrl)
{
const int index = m_model->index(newUrl);
if (index >= 0) {
QHash<QByteArray, QVariant> data;
data.insert("text", oldUrl.fileName());
m_model->setData(index, data);
}
}
void DolphinView::slotDirectoryLoadingStarted()
{
// Disable the writestate temporary until it can be determined in a fast way
......@@ -1454,7 +1464,10 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
m_model->setData(index, data);
}
KonqOperations::rename(this, oldUrl, newName);
KonqOperations* op = KonqOperations::renameV2(this, oldUrl, newName);
if (op) {
connect(op, SIGNAL(renamingFailed(KUrl,KUrl)), SLOT(slotRenamingFailed(KUrl,KUrl)));
}
}
}
}
......
......@@ -632,6 +632,8 @@ private slots:
*/
void slotDeleteFileFinished(KJob* job);
void slotRenamingFailed(const KUrl& oldUrl, const KUrl& newUrl);
/**
* Invoked when the file item model has started the loading
* of the directory specified by DolphinView::url().
......
......@@ -750,16 +750,21 @@ static QString translatePath( QString path ) // krazy:exclude=passbyvalue
}
void KonqOperations::rename( QWidget * parent, const KUrl & oldurl, const KUrl& newurl )
{
renameV2(parent, oldurl, newurl);
}
KonqOperations *KonqOperations::renameV2( QWidget * parent, const KUrl & oldurl, const KUrl& newurl )
{
kDebug(1203) << "oldurl=" << oldurl << " newurl=" << newurl;
if ( oldurl == newurl )
return;
return 0;
KUrl::List lst;
lst.append(oldurl);
KIO::Job * job = KIO::moveAs( oldurl, newurl, oldurl.isLocalFile() ? KIO::HideProgressInfo : KIO::DefaultFlags );
KonqOperations * op = new KonqOperations( parent );
op->setOperation( job, MOVE, newurl );
op->setOperation( job, RENAME, newurl );
KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Rename, lst, newurl, job );
// if moving the desktop then update config file and emit
if ( oldurl.isLocalFile() && oldurl.toLocalFile( KUrl::AddTrailingSlash ) == KGlobalSettings::desktopPath() )
......@@ -772,6 +777,8 @@ void KonqOperations::rename( QWidget * parent, const KUrl & oldurl, const KUrl&
g.writeEntry( "XDG_DESKTOP_DIR", QString("\"" + translatePath( newurl.path() ) + "\"") );
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_PATHS);
}
return op;
}
void KonqOperations::setOperation( KIO::Job * job, Operation method, const KUrl & dest )
......@@ -840,15 +847,16 @@ void KonqOperations::slotStatResult( KJob * job )
void KonqOperations::slotResult(KJob *job)
{
bool jobFailed = false;
if (job && job->error()) {
static_cast<KIO::Job*>(job)->ui()->showErrorMessage();
job = 0; // The job failed, so set it to 0. All further job related codepaths become disabled
jobFailed = true;
}
switch (m_method) {
case PUT: {
KIO::SimpleJob *simpleJob = qobject_cast<KIO::SimpleJob*>(job);
if (simpleJob) {
if (simpleJob && !jobFailed) {
m_createdUrls << simpleJob->url();
}
}
......@@ -858,6 +866,15 @@ void KonqOperations::slotResult(KJob *job)
// Update konq windows opened on trash:/
org::kde::KDirNotify::emitFilesAdded("trash:/"); // yeah, files were removed, but we don't know which ones...
break;
case RENAME: {
KIO::CopyJob *renameJob = qobject_cast<KIO::CopyJob*>(job);
if (renameJob && jobFailed) {
const KUrl oldUrl = renameJob->srcUrls().first();
const KUrl newUrl = renameJob->destUrl();
emit renamingFailed(oldUrl, newUrl);
}
}
break;
default:
break;
}
......@@ -872,11 +889,16 @@ void KonqOperations::slotResult(KJob *job)
}
void KonqOperations::rename( QWidget * parent, const KUrl & oldurl, const QString & name )
{
renameV2(parent, oldurl, name);
}
KonqOperations *KonqOperations::renameV2( QWidget * parent, const KUrl & oldurl, const QString & name )
{
KUrl newurl( oldurl );
newurl.setPath( oldurl.directory( KUrl::AppendTrailingSlash ) + name );
kDebug(1203) << "KonqOperations::rename("<<name<<") called. newurl=" << newurl;
rename( parent, oldurl, newurl );
return renameV2( parent, oldurl, newurl );
}
// Duplicated in libkfile's KDirOperator
......
......@@ -53,7 +53,7 @@ public:
*/
static void editMimeType( const QString & mimeType, QWidget* parent );
enum Operation { TRASH, DEL, COPY, MOVE, LINK, EMPTYTRASH, STAT, MKDIR, RESTORE, UNKNOWN, PUT };
enum Operation { TRASH, DEL, COPY, MOVE, LINK, EMPTYTRASH, STAT, MKDIR, RESTORE, UNKNOWN, PUT, RENAME };
/**
* Delete the @p selectedUrls if possible.
*
......@@ -188,6 +188,19 @@ public:
*/
static void rename( QWidget * parent, const KUrl & oldurl, const QString & name );
/**
* Do a renaming.
* @param parent the parent widget, passed to KonqOperations ctor
* @param oldurl the current url of the file to be renamed
* @param name the new name for the file. Shouldn't include '/'.
*
* @return The KonqOperations object
* @since 4.11
*
* @todo TODO KDE 5.0 - Merge rename and renameV2
*/
static KonqOperations *renameV2( QWidget * parent, const KUrl & oldurl, const QString & name );
/**
* Do a renaming.
* @param parent the parent widget, passed to KonqOperations ctor
......@@ -198,6 +211,21 @@ public:
*/
static void rename( QWidget * parent, const KUrl & oldurl, const KUrl & newurl );
/**
* Do a renaming.
* @param parent the parent widget, passed to KonqOperations ctor
* @param oldurl the current url of the file to be renamed
* @param newurl the new url for the file
* Use this version if the other one wouldn't work :) (e.g. because name could
* be a relative path, including a '/').
*
* @return The KonqOperations object
* @since 4.11
*
* @todo TODO KDE 5.0 - Merge rename and renameV2
*/
static KonqOperations *renameV2( QWidget * parent, const KUrl & oldurl, const KUrl & newurl );
enum ConfirmationType { DEFAULT_CONFIRMATION, SKIP_CONFIRMATION, FORCE_CONFIRMATION };
/**
* Ask for confirmation before deleting/trashing @p selectedUrls.
......@@ -229,6 +257,7 @@ Q_SIGNALS:
void statFinished( const KFileItem & item );
void aboutToCreate(const QPoint &pos, const QList<KIO::CopyInfo> &files);
void aboutToCreate(const KUrl::List &urls);
void renamingFailed(const KUrl &oldUrl, const KUrl &newUrl);
private:
QWidget* parentWidget() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment