From 30349ef1bdcae0ed80f47c168d46c15020b927d3 Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Thu, 5 Apr 2018 22:33:34 +0200 Subject: [PATCH] [RenameDialog] Fix crash when renaming single items Summary: `m_spinBox` is initialized only when renaming multiple items. This commit restores the single-item rename logic which was wrongly removed by commit c5eb4e31161ccf422. BUG: 392743 FIXED-IN: 18.03.90 Test Plan: Disable inline renaming and try to rename single or multiple items (and also to undo the jobs). Subscribers: #dolphin Differential Revision: https://phabricator.kde.org/D11972 --- src/views/renamedialog.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/views/renamedialog.cpp b/src/views/renamedialog.cpp index 44c0a5a7be..e49f56e2de 100644 --- a/src/views/renamedialog.cpp +++ b/src/views/renamedialog.cpp @@ -155,22 +155,29 @@ void RenameDialog::slotAccepted() widget = this; } + const QList srcList = m_items.urlList(); + const QString newName = m_lineEdit->text(); KIO::FileUndoManager::CommandType cmdType; + KIO::Job *job = nullptr; if (m_renameOneItem) { Q_ASSERT(m_items.count() == 1); cmdType = KIO::FileUndoManager::Rename; + const QUrl oldUrl = m_items.constFirst().url(); + QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename); + newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); + m_renamedItems << newUrl; + job = KIO::moveAs(oldUrl, newUrl, KIO::HideProgressInfo); } else { cmdType = KIO::FileUndoManager::BatchRename; + job = KIO::batchRename(srcList, newName, m_spinBox->value(), QLatin1Char('#')); + connect(qobject_cast(job), &KIO::BatchRenameJob::fileRenamed, this, &RenameDialog::slotFileRenamed); } - const QList srcList = m_items.urlList(); - KIO::BatchRenameJob* job = KIO::batchRename(srcList, m_lineEdit->text(), m_spinBox->value(), QLatin1Char('#')); KJobWidgets::setWindow(job, widget); const QUrl parentUrl = srcList.first().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash); KIO::FileUndoManager::self()->recordJob(cmdType, srcList, parentUrl, job); - connect(job, &KIO::BatchRenameJob::fileRenamed, this, &RenameDialog::slotFileRenamed); - connect(job, &KIO::BatchRenameJob::result, this, &RenameDialog::slotResult); + connect(job, &KJob::result, this, &RenameDialog::slotResult); job->uiDelegate()->setAutoErrorHandlingEnabled(true);