]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Merge branch 'master' into frameworks
[dolphin.git] / src / views / dolphinview.cpp
index ce8e08210fffbf39f8cb05a8f4ee38f5df0b5dc1..e7034984e9da6001c4e20c9f2c84ffd93a1b795a 100644 (file)
 #include <kitemviews/kitemlistselectionmanager.h>
 #include <kitemviews/kitemlistview.h>
 #include <kitemviews/kitemlistcontroller.h>
+#include <KIO/CopyJob>
 #include <KIO/DeleteJob>
 #include <KIO/JobUiDelegate>
 #include <KIO/NetAccess>
 #include <KIO/PreviewJob>
+#include <KIO/Paste>
 #include <KJob>
 #include <KMenu>
 #include <KGlobal>
 #include <KMessageBox>
 #include <KJobWidgets>
-#include <konq_fileitemcapabilities.h>
 #include <konq_operations.h>
-#include <konqmimedata.h>
 #include <KToggleAction>
 #include <KUrl>
 
@@ -674,22 +674,26 @@ void DolphinView::renameSelectedItems()
 void DolphinView::trashSelectedItems()
 {
     const KUrl::List list = simplifiedSelectedUrls();
-    KonqOperations::del(this, KonqOperations::TRASH, list);
+    KIO::JobUiDelegate uiDelegate;
+    uiDelegate.setWindow(window());
+    if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) {
+        KIO::Job* job = KIO::trash(list);
+        KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, KUrl("trash:/"), job);
+        KJobWidgets::setWindow(job, this);
+        connect(job, &KIO::Job::result,
+                this, &DolphinView::slotTrashFileFinished);
+    }
 }
 
 void DolphinView::deleteSelectedItems()
 {
     const KUrl::List list = simplifiedSelectedUrls();
-    const bool del = KonqOperations::askDeleteConfirmation(list,
-                     KonqOperations::DEL,
-                     KonqOperations::DEFAULT_CONFIRMATION,
-                     this);
 
-    if (del) {
+    KIO::JobUiDelegate uiDelegate;
+    uiDelegate.setWindow(window());
+    if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) {
         KIO::Job* job = KIO::del(list);
-        if (job->ui()) {
-            KJobWidgets::setWindow(job, this);
-        }
+        KJobWidgets::setWindow(job, this);
         connect(job, &KIO::Job::result,
                 this, &DolphinView::slotDeleteFileFinished);
     }
@@ -698,7 +702,7 @@ void DolphinView::deleteSelectedItems()
 void DolphinView::cutSelectedItems()
 {
     QMimeData* mimeData = selectionMimeData();
-    KonqMimeData::addIsCutSelection(mimeData, true);
+    KIO::setClipboardDataCut(mimeData, true);
     QApplication::clipboard()->setMimeData(mimeData);
 }
 
@@ -1172,6 +1176,14 @@ bool DolphinView::itemsExpandable() const
 
 void DolphinView::restoreState(QDataStream& stream)
 {
+    // Read the version number of the view state and check if the version is supported.
+    quint32 version = 0;
+    stream >> version;
+    if (version != 1) {
+        // The version of the view state isn't supported, we can't restore it.
+        return;
+    }
+
     // Restore the current item that had the keyboard focus
     stream >> m_currentItemUrl;
 
@@ -1186,6 +1198,8 @@ void DolphinView::restoreState(QDataStream& stream)
 
 void DolphinView::saveState(QDataStream& stream)
 {
+    stream << quint32(1); // View state version
+
     // Save the current item that has the keyboard focus
     const int currentIndex = m_container->controller()->selectionManager()->currentItem();
     if (currentIndex != -1) {
@@ -1294,11 +1308,11 @@ void DolphinView::updateViewState()
                 m_view->scrollToItem(currentIndex);
                 m_scrollToCurrentItem = false;
             }
-
-            m_currentItemUrl = KUrl();
         } else {
             selectionManager->setCurrentItem(0);
         }
+
+        m_currentItemUrl = KUrl();
     }
 
     if (!m_restoredContentsPosition.isNull()) {
@@ -1358,6 +1372,15 @@ void DolphinView::calculateItemCount(int& fileCount,
     }
 }
 
+void DolphinView::slotTrashFileFinished(KJob* job)
+{
+    if (job->error() == 0) {
+        emit operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
+    } else if (job->error() != KIO::ERR_USER_CANCELED) {
+        emit errorMessage(job->errorString());
+    }
+}
+
 void DolphinView::slotDeleteFileFinished(KJob* job)
 {
     if (job->error() == 0) {