┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2014-09-04 18:33:04 +0200
committerDavid Faure <[email protected]>2014-09-22 22:37:44 +0200
commitd47557dcd17a028596c4e0e7b0aabc5db4847bed (patch)
tree18fd975bf0c943759ef93d6fa629a409a30248be /src/views
parent4425c659a001887d82664b41c0e4222e21beddbc (diff)
Port away from KonqOperations::renameV2.
Tested. The if before the connect looks suspicious to me, though.
Diffstat (limited to 'src/views')
-rw-r--r--src/views/dolphinview.cpp38
-rw-r--r--src/views/dolphinview.h5
2 files changed, 29 insertions, 14 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 17465eaa9..2eb16fe2d 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -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 (index >= 0) {
- QHash<QByteArray, QVariant> data;
- data.insert("text", oldUrl.fileName());
- m_model->setData(index, data);
+ if (job->error()) {
+ KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job);
+ Q_ASSERT(copyJob);
+ const QUrl newUrl = copyJob->destUrl();
+ 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("..")) {
const KUrl oldUrl = oldItem.url();
- const KUrl newUrl(url().path(KUrl::AddTrailingSlash) + newName);
- const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
+ QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename);
+ newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));
+
+ const bool newNameExistsAlready = (m_model->index(KUrl(newUrl)) >= 0);
if (!newNameExistsAlready) {
// 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
- // 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
// data when the dir lister signals that the file name has changed.
QHash<QByteArray, QVariant> data;
@@ -1499,11 +1507,15 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
m_model->setData(index, data);
}
- KonqOperations* op = KonqOperations::renameV2(this, oldUrl, newName);
- if (op && !newNameExistsAlready) {
- // Only connect the renamingFailed signal if there is no item with the new name
+ KIO::Job * job = KIO::moveAs(oldUrl, newUrl);
+ KJobWidgets::setWindow(job, this);
+ 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.
- connect(op, &KonqOperations::renamingFailed, this, &DolphinView::slotRenamingFailed);
+ connect(job, &KJob::result, this, &DolphinView::slotRenamingResult);
}
}
}
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index 688699096..1c5ecd57e 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -625,7 +625,10 @@ private slots:
*/
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