]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix crash when dropping URLs on the URL navigator's drop down menus
authorFrank Reininghaus <frank78ac@googlemail.com>
Tue, 2 Jul 2013 17:27:06 +0000 (19:27 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Tue, 2 Jul 2013 17:27:06 +0000 (19:27 +0200)
The problem was that the files were copied/moved inside the nested event
loop of the drag, which caused problems if the "File exists" dialog was
shown.

The solution is to make the copy/move operation delayed, such that it is
executed in the main event loop.

Note that dropping files on these menus does apparently not work at the
moment when using the Oxygen style (see bug 310016).

BUG: 192139
BUG: 256338
BUG: 293220
BUG: 309076
FIXED-IN: 4.11.0
REVIEW: 111273

src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h

index 71dc5fd7b50808731992cf1f0d7a3679497ea863..1e9e79ae7a8d800e980baeb8afee3db3bae2c151 100644 (file)
@@ -68,7 +68,9 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
     m_statusBar(0),
     m_statusBarTimer(0),
     m_statusBarTimestamp(),
-    m_autoGrabFocus(true)
+    m_autoGrabFocus(true),
+    m_dropDestination(),
+    m_dropEvent(0)
 #ifdef KActivities_FOUND
     , m_activityResourceInstance(0)
 #endif
@@ -597,11 +599,37 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url)
 
 void DolphinViewContainer::dropUrls(const KUrl& 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(), destination, event, 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 KUrl& oldUrl, const KUrl& newUrl)
index bc58531a2700d6e50a1c32a4afccb77472255eff..e5597ccc6196e78613ccb01de1bd376bc5eef295 100644 (file)
@@ -261,9 +261,21 @@ private slots:
     /**
      * 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 KUrl& 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
@@ -330,6 +342,9 @@ private:
     QElapsedTimer m_statusBarTimestamp;  // Time in ms since last update
     bool m_autoGrabFocus;
 
+    KUrl m_dropDestination;
+    QScopedPointer<QDropEvent> m_dropEvent;
+
 #ifdef KActivities_FOUND
 private:
     KActivities::ResourceInstance * m_activityResourceInstance;