Port away from KonqOperations::renameV2.

Tested. The if before the connect looks suspicious to me, though.
This commit is contained in:
David Faure 2014-09-04 18:33:04 +02:00
parent 4425c659a0
commit d47557dcd1
2 changed files with 29 additions and 14 deletions

View file

@ -1389,13 +1389,19 @@ void DolphinView::slotDeleteFileFinished(KJob* job)
} }
} }
void DolphinView::slotRenamingFailed(const KUrl& oldUrl, const KUrl& newUrl) void DolphinView::slotRenamingResult(KJob* job)
{ {
const int index = m_model->index(newUrl); if (job->error()) {
if (index >= 0) { KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job);
QHash<QByteArray, QVariant> data; Q_ASSERT(copyJob);
data.insert("text", oldUrl.fileName()); const QUrl newUrl = copyJob->destUrl();
m_model->setData(index, data); const int index = m_model->index(KUrl(newUrl));
if (index >= 0) {
QHash<QByteArray, QVariant> data;
const QUrl oldUrl = copyJob->srcUrls().first();
data.insert("text", oldUrl.fileName());
m_model->setData(index, data);
}
} }
} }
@ -1486,12 +1492,14 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) { if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
const KUrl oldUrl = oldItem.url(); const KUrl oldUrl = oldItem.url();
const KUrl newUrl(url().path(KUrl::AddTrailingSlash) + newName); QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename);
const bool newNameExistsAlready = (m_model->index(newUrl) >= 0); newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));
const bool newNameExistsAlready = (m_model->index(KUrl(newUrl)) >= 0);
if (!newNameExistsAlready) { if (!newNameExistsAlready) {
// Only change the data in the model if no item with the new name // Only change the data in the model if no item with the new name
// is in the model yet. If there is an item with the new name // is in the model yet. If there is an item with the new name
// already, calling KonqOperations::rename() will open a dialog // already, calling KIO::CopyJob will open a dialog
// asking for a new name, and KFileItemModel will update the // asking for a new name, and KFileItemModel will update the
// data when the dir lister signals that the file name has changed. // data when the dir lister signals that the file name has changed.
QHash<QByteArray, QVariant> data; QHash<QByteArray, QVariant> data;
@ -1499,11 +1507,15 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
m_model->setData(index, data); m_model->setData(index, data);
} }
KonqOperations* op = KonqOperations::renameV2(this, oldUrl, newName); KIO::Job * job = KIO::moveAs(oldUrl, newUrl);
if (op && !newNameExistsAlready) { KJobWidgets::setWindow(job, this);
// Only connect the renamingFailed signal if there is no item with the new name KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, QList<QUrl>() << oldUrl, newUrl, job);
job->ui()->setAutoErrorHandlingEnabled(true);
if (!newNameExistsAlready) {
// Only connect the result signal if there is no item with the new name
// in the model yet, see bug 328262. // in the model yet, see bug 328262.
connect(op, &KonqOperations::renamingFailed, this, &DolphinView::slotRenamingFailed); connect(job, &KJob::result, this, &DolphinView::slotRenamingResult);
} }
} }
} }

View file

@ -625,7 +625,10 @@ private slots:
*/ */
void slotTrashFileFinished(KJob* job); void slotTrashFileFinished(KJob* job);
void slotRenamingFailed(const KUrl& oldUrl, const KUrl& newUrl); /**
* Invoked when the rename job is done, for error handling.
*/
void slotRenamingResult(KJob* job);
/** /**
* Invoked when the file item model has started the loading * Invoked when the file item model has started the loading