[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 c5eb4e3116.

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
This commit is contained in:
Elvis Angelaccio 2018-04-05 22:33:34 +02:00
parent 386a862de4
commit 30349ef1bd

View 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);