]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[RenameDialog] Fix crash when renaming single items
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Thu, 5 Apr 2018 20:33:34 +0000 (22:33 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Thu, 5 Apr 2018 21:15:50 +0000 (23:15 +0200)
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

index 44c0a5a7beb98323650cfd2a1a4a74decd85c19e..e49f56e2de6266b0ae92f445c7792c27f3fdfe52 100644 (file)
@@ -155,22 +155,29 @@ void RenameDialog::slotAccepted()
         widget = this;
     }
 
+    const QList<QUrl> 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<KIO::BatchRenameJob*>(job), &KIO::BatchRenameJob::fileRenamed, this, &RenameDialog::slotFileRenamed);
     }
 
-    const QList<QUrl> 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);