]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Dolphin: port from KonqOperations::doDrop to the new KIO::DropJob
authorDavid Faure <faure@kde.org>
Fri, 26 Dec 2014 07:57:42 +0000 (08:57 +0100)
committerDavid Faure <faure@kde.org>
Mon, 5 Jan 2015 08:07:10 +0000 (09:07 +0100)
REVIEW: 121678

src/dolphintabwidget.cpp
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h
src/panels/folders/folderspanel.cpp
src/panels/places/placespanel.cpp
src/views/dolphinview.cpp
src/views/dolphinview.h
src/views/draganddrophelper.cpp
src/views/draganddrophelper.h

index a0c9b9d8198269bcf9c560106332cdf0dd9b45a7..5b26359e6298f4b4209ddd60d0e1640943dd0586 100644 (file)
@@ -23,7 +23,6 @@
 #include "dolphintabpage.h"
 #include "dolphinviewcontainer.h"
 #include "dolphin_generalsettings.h"
-#include "views/draganddrophelper.h"
 
 #include <QApplication>
 #include <KConfigGroup>
@@ -286,13 +285,8 @@ void DolphinTabWidget::openNewActivatedTab(int index)
 void DolphinTabWidget::tabDropEvent(int index, QDropEvent* event)
 {
     if (index >= 0) {
-        const DolphinView* view = tabPageAt(index)->activeViewContainer()->view();
-
-        QString error;
-        DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event, error);
-        if (!error.isEmpty()) {
-            currentTabPage()->activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
-        }
+        DolphinView* view = tabPageAt(index)->activeViewContainer()->view();
+        view->dropUrls(view->url(), event);
     }
 }
 
index 3954a12e6638c2abc7ab57c669e1dc1680b073a6..8fea3ba9d0bb8389d89724b9f0cd74605c0286fe 100644 (file)
 #include <KFileItemActions>
 #include <KFilePlacesModel>
 #include <KLocalizedString>
-#include <KIO/NetAccess>
 #include <KIO/PreviewJob>
 #include <KMessageWidget>
-#include <konq_operations.h>
 #include <KShell>
 #include <QUrl>
 #include <KUrlComboBox>
@@ -45,7 +43,6 @@
 #include "filterbar/filterbar.h"
 #include "search/dolphinsearchbox.h"
 #include "statusbar/dolphinstatusbar.h"
-#include "views/draganddrophelper.h"
 #include "views/viewmodecontroller.h"
 #include "views/viewproperties.h"
 
@@ -60,9 +57,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
     m_statusBar(0),
     m_statusBarTimer(0),
     m_statusBarTimestamp(),
-    m_autoGrabFocus(true),
-    m_dropDestination(),
-    m_dropEvent(0)
+    m_autoGrabFocus(true)
 #ifdef KActivities_FOUND
     , m_activityResourceInstance(0)
 #endif
@@ -74,8 +69,6 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
     m_topLayout->setMargin(0);
 
     m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this);
-    connect(m_urlNavigator, &KUrlNavigator::urlsDropped,
-            this, &DolphinViewContainer::dropUrls);
     connect(m_urlNavigator, &KUrlNavigator::activated,
             this, &DolphinViewContainer::activate);
     connect(m_urlNavigator->editor(), &KUrlComboBox::completionModeChanged,
@@ -147,6 +140,8 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
             this, &DolphinViewContainer::slotHistoryChanged);
     connect(m_urlNavigator, &KUrlNavigator::returnPressed,
             this, &DolphinViewContainer::slotReturnPressed);
+    connect(m_urlNavigator, &KUrlNavigator::urlsDropped,
+            m_view, &DolphinView::dropUrls);
 
     // Initialize status bar
     m_statusBar = new DolphinStatusBar(this);
@@ -612,41 +607,6 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url)
     }
 }
 
-void DolphinViewContainer::dropUrls(const QUrl& destination, QDropEvent* event)
-{
-    m_dropDestination = destination;
-
-    const QMimeData* mimeData = event->mimeData();
-    QMimeData* mimeDataCopy = new QMimeData;
-    foreach (const QString& format, mimeData->formats()) {
-        mimeDataCopy->setData(format, mimeData->data(format));
-    }
-
-    m_dropEvent.reset(new QDropEvent(event->pos(),
-                                     event->possibleActions(),
-                                     mimeDataCopy,
-                                     event->mouseButtons(),
-                                     event->keyboardModifiers()));
-
-    QTimer::singleShot(0, this, SLOT(dropUrlsDelayed()));
-}
-
-void DolphinViewContainer::dropUrlsDelayed()
-{
-    if (m_dropEvent.isNull()) {
-        return;
-    }
-
-    QString error;
-    DragAndDropHelper::dropUrls(KFileItem(), m_dropDestination, m_dropEvent.data(), error);
-    if (!error.isEmpty()) {
-        showMessage(error, Error);
-    }
-
-    delete m_dropEvent->mimeData();
-    m_dropEvent.reset();
-}
-
 void DolphinViewContainer::redirect(const QUrl& oldUrl, const QUrl& newUrl)
 {
     Q_UNUSED(oldUrl);
index bd4141db5a2d56e6a605247eaba4da3291664645..62f91100e9e5d457edd6f4d927c87610335834d7 100644 (file)
@@ -257,24 +257,6 @@ private slots:
      */
     void slotUrlNavigatorLocationChanged(const QUrl& url);
 
-    /**
-     * Is connected with the URL navigator and drops the URLs
-     * above the destination \a destination.
-     *
-     * Creates a copy of \a event and invokes \a dropUrlsDelayed with a
-     * queued connection.
-     */
-    void dropUrls(const QUrl& destination, QDropEvent* event);
-
-    /**
-     * Is invoked with a queued connection by \a dropUrls to prevent that the
-     * drop actions are executed in the URL navigator menu's nested event loop,
-     * which might cause a crash. Simply using a queued connection from the URL
-     * navigator to \a dropUrls would not work because the \a event pointer
-     * would be dangling then.
-     */
-    void dropUrlsDelayed();
-
     /**
      * Is invoked when a redirection is done and changes the
      * URL of the URL navigator to \a newUrl without triggering
@@ -341,9 +323,6 @@ private:
     QElapsedTimer m_statusBarTimestamp;  // Time in ms since last update
     bool m_autoGrabFocus;
 
-    QUrl m_dropDestination;
-    QScopedPointer<QDropEvent> m_dropEvent;
-
 #ifdef KF5Activities_FOUND
 private:
     KActivities::ResourceInstance * m_activityResourceInstance;
index f56f5a1391831666555ac31c359ac02ba794998a..b83e950e5c2020ef2f9a804b9a68a850034c1828 100644 (file)
@@ -36,6 +36,7 @@
 #include <KJobWidgets>
 #include <KJobUiDelegate>
 #include <KIO/CopyJob>
+#include <KIO/DropJob>
 #include <KIO/FileUndoManager>
 
 #include <QApplication>
@@ -239,10 +240,9 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve
                              event->buttons(),
                              event->modifiers());
 
-        QString error;
-        DragAndDropHelper::dropUrls(destItem, destItem.url(), &dropEvent, error);
-        if (!error.isEmpty()) {
-            emit errorMessage(error);
+        KIO::DropJob *job = DragAndDropHelper::dropUrls(destItem.url(), &dropEvent, this);
+        if (job) {
+            connect(job, &KIO::DropJob::result, this, [this](KJob *job) { if (job->error()) emit errorMessage(job->errorString()); });
         }
     }
 }
index b04191f1c73fa42b8e9d1f18f698c2e6a4a4ee02..631b6b69df82e52844907f9535f7a882271021d0 100644 (file)
@@ -30,6 +30,7 @@
 #include <KDirNotify>
 #include <QIcon>
 #include <KIO/Job>
+#include <KIO/DropJob>
 #include <KIO/EmptyTrashJob>
 #include <KIO/JobUiDelegate>
 #include <KJobWidgets>
@@ -375,11 +376,7 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
                          event->buttons(),
                          event->modifiers());
 
-    QString error;
-    DragAndDropHelper::dropUrls(KFileItem(), destUrl, &dropEvent, error);
-    if (!error.isEmpty()) {
-        emit errorMessage(error);
-    }
+    slotUrlsDropped(destUrl, &dropEvent, this);
 }
 
 void PlacesPanel::slotItemDropEventStorageSetupDone(int index, bool success)
@@ -390,12 +387,7 @@ void PlacesPanel::slotItemDropEventStorageSetupDone(int index, bool success)
     if ((index == m_itemDropEventIndex) && m_itemDropEvent && m_itemDropEventMimeData) {
         if (success) {
             QUrl destUrl = m_model->placesItem(index)->url();
-
-            QString error;
-            DragAndDropHelper::dropUrls(KFileItem(), destUrl, m_itemDropEvent, error);
-            if (!error.isEmpty()) {
-                emit errorMessage(error);
-            }
+            slotUrlsDropped(destUrl, m_itemDropEvent, this);
         }
 
         delete m_itemDropEventMimeData;
@@ -414,13 +406,10 @@ void PlacesPanel::slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent*
 
 void PlacesPanel::slotUrlsDropped(const QUrl& dest, QDropEvent* event, QWidget* parent)
 {
-    Q_UNUSED(parent);
-    QString error;
-    DragAndDropHelper::dropUrls(KFileItem(), dest, event, error);
-    if (!error.isEmpty()) {
-        emit errorMessage(error);
+    KIO::DropJob *job = DragAndDropHelper::dropUrls(dest, event, parent);
+    if (job) {
+        connect(job, &KIO::DropJob::result, this, [this](KJob *job) { if (job->error()) emit errorMessage(job->errorString()); });
     }
-
 }
 
 void PlacesPanel::slotTrashUpdated(KJob* job)
index cb25c6555ab2a4f3af67a762262f7868aaab687a..32e182ce7c15bf1518b7e928cfff99188e7605af 100644 (file)
 #include <KIO/JobUiDelegate>
 #include <KIO/NetAccess>
 #include <KIO/PreviewJob>
+#include <KIO/DropJob>
 #include <KIO/PasteJob>
 #include <KIO/Paste>
 #include <KJob>
 #include <QMenu>
 #include <KMessageBox>
 #include <KJobWidgets>
-#include <konq_operations.h>
 #include <QUrl>
 
 #include "dolphinnewfilemenuobserver.h"
@@ -1039,22 +1039,22 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
                          event->mimeData(),
                          event->buttons(),
                          event->modifiers());
+    dropUrls(destUrl, &dropEvent);
 
-    QString error;
-    KonqOperations* job = DragAndDropHelper::dropUrls(destItem, destUrl, &dropEvent, error);
-    if (!error.isEmpty()) {
-        emit infoMessage(error);
-    }
+    setActive(true);
+}
+
+void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent)
+{
+    KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, this);
 
     if (job && destUrl == url()) {
         // Mark the dropped urls as selected.
         m_clearSelectionBeforeSelectingNewItems = true;
         m_markFirstNewlySelectedItemAsCurrent = true;
-        connect(job, &KonqOperations::itemCreated, this, &DolphinView::slotItemCreated);
-        //connect(job, &KIO::InteractiveDropJob::result, this, &DolphinView::slotPasteJobResult);
+        connect(job, &KIO::DropJob::itemCreated, this, &DolphinView::slotItemCreated);
+        connect(job, &KIO::DropJob::result, this, &DolphinView::slotPasteJobResult);
     }
-
-    setActive(true);
 }
 
 void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
@@ -1096,8 +1096,11 @@ void DolphinView::slotItemCreated(const QUrl& url)
     m_selectedUrls << url;
 }
 
-void DolphinView::slotPasteJobResult(KJob *)
+void DolphinView::slotPasteJobResult(KJob *job)
 {
+    if (job->error()) {
+        emit errorMessage(job->errorString());
+    }
     if (!m_selectedUrls.isEmpty()) {
         m_selectedUrls << KDirModel::simplifiedUrlList(m_selectedUrls);
     }
index c054c311a360971d29ea796070dec9f3924ab1d9..aa4492bc35fbc8b37b0fc82291a2545017bcc706 100644 (file)
@@ -362,6 +362,11 @@ public slots:
      */
     void pasteIntoFolder();
 
+    /**
+     * Handles a drop of @p dropEvent onto @p destUrl
+     */
+    void dropUrls(const QUrl &destUrl, QDropEvent *dropEvent);
+
     void stopLoading();
 
     /** Activates the view if the item list container gets focus. */
index a09faa345179fbb016b67289c550650a56639614..f740fd5202008e891513c80674615cfa0c14b620 100644 (file)
 
 #include "draganddrophelper.h"
 
-#include <KFileItem>
-#include <KLocalizedString>
-#include <konq_operations.h>
 #include <QUrl>
-#include <QApplication>
-#include <QtDBus>
+#include <QDBusMessage>
+#include <QDBusConnection>
 #include <QDropEvent>
+#include <QMimeData>
+
+#include <KFileItem>
+#include <KLocalizedString>
 #include <KUrlMimeData>
+#include <KIO/DropJob>
+#include <KJobWidgets>
 
-KonqOperations* DragAndDropHelper::dropUrls(const KFileItem& destItem, const QUrl& destUrl, QDropEvent* event, QString& error)
+KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event, QWidget* window)
 {
-    error.clear();
-
-    if (!destItem.isNull() && !destItem.isWritable()) {
-        error = xi18nc("@info:status", "Access denied. Could not write to <filename>%1</filename>",
-                       destUrl.toDisplayString(QUrl::PreferLocalFile));
-        return 0;
-    }
-
     const QMimeData* mimeData = event->mimeData();
     if (mimeData->hasFormat("application/x-kde-ark-dndextract-service") &&
         mimeData->hasFormat("application/x-kde-ark-dndextract-path")) {
@@ -49,19 +44,11 @@ KonqOperations* DragAndDropHelper::dropUrls(const KFileItem& destItem, const QUr
                                                               "org.kde.ark.DndExtract", "extractSelectedFilesTo");
         message.setArguments({destUrl.toDisplayString(QUrl::PreferLocalFile)});
         QDBusConnection::sessionBus().call(message);
-    } else if (!destItem.isNull() && (destItem.isDir() || destItem.isDesktopFile())) {
-        // Drop into a directory or a desktop-file
-        const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData);
-        foreach (const QUrl& url, urls) {
-            if (url == destUrl) {
-                error = i18nc("@info:status", "A folder cannot be dropped into itself");
-                return 0;
-            }
-        }
-
-        return KonqOperations::doDrop(destItem, destUrl, event, QApplication::activeWindow(), QList<QAction*>());
     } else {
-        return KonqOperations::doDrop(KFileItem(), destUrl, event, QApplication::activeWindow(), QList<QAction*>());
+        // Drop into a directory or a desktop-file
+        KIO::DropJob *job = KIO::drop(event, destUrl);
+        KJobWidgets::setWindow(job, window);
+        return job;
     }
 
     return 0;
index c4ae974b50ab5e0af5eb9dc749d383a8bdadb2fa..85268eb4f85aa5eb09a7a3683295ceb0dbe1ea26 100644 (file)
 
 #include <QString>
 
-class KFileItem;
 class QUrl;
 class QDropEvent;
-class KonqOperations;
+class QWidget;
+namespace KIO { class DropJob; }
 
 class LIBDOLPHINPRIVATE_EXPORT DragAndDropHelper
 {
@@ -39,22 +39,15 @@ public:
      * offered to the user. The drag destination must represent a directory or
      * a desktop-file, otherwise the dropping gets ignored.
      *
-     * @param destItem  Item of the destination. Can be 0 (KFileItem::isNull()) if
-     *                  no file-item is available for the destination. In this case
-     *                  destUrl is used as fallback. For performance reasons it is
-     *                  recommended to pass a file-item if available.
      * @param destUrl   URL of the item destination. Is used only if destItem::isNull()
      *                  is true.
      * @param event     Drop event.
-     * @param error     Error message intended to be shown for users if dropping is not
-     *                  possible. If an empty string is returned, the dropping has been
-     *                  successful.
-     * @return          KonqOperations pointer
+     * @param window    Associated widget.
+     * @return          KIO::DropJob pointer
      */
-    static KonqOperations* dropUrls(const KFileItem& destItem,
-                                    const QUrl& destUrl,
-                                    QDropEvent* event,
-                                    QString& error);
+    static KIO::DropJob* dropUrls(const QUrl& destUrl,
+                                  QDropEvent* event,
+                                  QWidget *window);
 };
 
 #endif