]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Port away from KonqOperations::rename
authorDavid Faure <faure@kde.org>
Thu, 4 Sep 2014 16:14:43 +0000 (18:14 +0200)
committerDavid Faure <faure@kde.org>
Mon, 22 Sep 2014 20:37:44 +0000 (22:37 +0200)
It's a bit more code, but this way if you want e.g. custom error handling
you know what to change :)

src/panels/folders/folderspanel.cpp

index 1f7d007ca5a43312fb9cfebd96350c833f003764..674f04c0d68974a053e41d0774cbf3379282c53e 100644 (file)
 #include <kitemviews/kfileitemmodel.h>
 
 #include <KFileItem>
-#include <konq_operations.h>
+#include <KJobWidgets>
+#include <KJobUiDelegate>
+#include <KIO/CopyJob>
+#include <KIO/FileUndoManager>
 
 #include <QApplication>
 #include <QBoxLayout>
@@ -250,7 +253,14 @@ void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, co
         const KFileItem item = m_model->fileItem(index);
         const QString newName = value.toString();
         if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
-            KonqOperations::rename(this, item.url(), newName);
+            const QUrl oldUrl = item.url();
+            QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename);
+            newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));
+
+            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);
         }
     }
 }