]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix drag & drop issues with non-local URLs
authorPeter Penz <peter.penz19@gmail.com>
Mon, 30 Jan 2012 11:07:08 +0000 (12:07 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 30 Jan 2012 11:09:21 +0000 (12:09 +0100)
BUG: 292821
BUG: 292355
FIXED-IN: 4.8.1

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

index 3654ed6c969bfb76f41993babc3f9f9182edcc9e..74b751f5adaa9938b5250d0f9f2662b240f10a63 100644 (file)
@@ -1330,7 +1330,7 @@ void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
         const ViewTab& viewTab = m_viewTab[tab];
         const DolphinView* view = viewTab.isPrimaryViewActive ? viewTab.primaryView->view()
                                                               : viewTab.secondaryView->view();
-        DragAndDropHelper::dropUrls(view->rootItem(), event);
+        DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event);
     }
 }
 
index 2ad5bea5cce8fb651c00e70740553d1de0ccc8cc..72c943eb4a77865258b17d4467fdf13b7bcff5bd 100644 (file)
@@ -538,8 +538,7 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url)
 
 void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
 {
-    const KFileItem destItem(KFileItem::Unknown, KFileItem::Unknown, destination);
-    DragAndDropHelper::dropUrls(destItem, event);
+    DragAndDropHelper::dropUrls(KFileItem(), destination, event);
 }
 
 void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
index d9c8f71dcbaf81999933fb51254b369dc1ee602f..1a61f0141b683e4c54848807daceafcdfc52fc80 100644 (file)
@@ -263,11 +263,7 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve
         KFileItemModel* model = fileItemModel();
         KFileItem destItem = model->fileItem(index);
         if (destItem.isNull()) {
-            destItem = model->rootItem();
-            if (destItem.isNull()) {
-                kWarning() << "No destination item available for drop operation.";
-                return;
-            }
+            return;
         }
 
         QDropEvent dropEvent(event->pos().toPoint(),
@@ -276,7 +272,7 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve
                              event->buttons(),
                              event->modifiers());
 
-        DragAndDropHelper::dropUrls(destItem, &dropEvent);
+        DragAndDropHelper::dropUrls(destItem, destItem.url(), &dropEvent);
     }
 }
 
index 6f522fad2ea44d916c3cc985bad43fbabad85d07..902c436cf62e82b05434f431228703453d67c8dc 100644 (file)
@@ -48,8 +48,7 @@ void PlacesPanel::mousePressEvent(QMouseEvent* event)
 void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
 {
     Q_UNUSED(parent);
-    const KFileItem destItem(KFileItem::Unknown, KFileItem::Unknown, dest);
-    DragAndDropHelper::dropUrls(destItem, event);
+    DragAndDropHelper::dropUrls(KFileItem(), dest, event);
 }
 
 void PlacesPanel::emitExtendedUrlChangedSignal(const KUrl& url)
index 539fcaaccebd4dafc2336904fc3868aebc03f441..1e300c5cf25331129eecb2ec9fee969ca6e62594 100644 (file)
@@ -809,13 +809,13 @@ void DolphinView::slotItemUnhovered(int index)
 
 void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
 {
+    KUrl destUrl;
     KFileItem destItem = fileItemModel()->fileItem(index);
     if (destItem.isNull()) {
         destItem = fileItemModel()->rootItem();
-        if (destItem.isNull()) {
-            kWarning() << "No destination item available for drop operation.";
-            return;
-        }
+        destUrl = url();
+    } else {
+        destUrl = destItem.url();
     }
 
     QDropEvent dropEvent(event->pos().toPoint(),
@@ -824,7 +824,7 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
                          event->buttons(),
                          event->modifiers());
 
-    const QString error = DragAndDropHelper::dropUrls(destItem, &dropEvent);
+    const QString error = DragAndDropHelper::dropUrls(destItem, destUrl, &dropEvent);
     if (!error.isEmpty()) {
         emit errorMessage(error);
     }
@@ -959,12 +959,7 @@ bool DolphinView::hasSelection() const
 
 KFileItem DolphinView::rootItem() const
 {
-    KFileItem item = m_dirLister->rootItem();
-    if (item.isNull()) {
-        // The directory has not been loaded yet
-        item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url());
-    }
-    return item;
+    return m_dirLister->rootItem();
 }
 
 void DolphinView::observeCreatedItem(const KUrl& url)
index 91eb4267d84dfe848e89f16b5f6474400e8f5c2a..83673ad723e94e96bac43838a8004ddd6596e2f0 100644 (file)
 #include <QtDBus>
 #include <QDropEvent>
 
-QString DragAndDropHelper::dropUrls(const KFileItem& destItem, QDropEvent* event)
+QString DragAndDropHelper::dropUrls(const KFileItem& destItem, const KUrl& destUrl, QDropEvent* event)
 {
-    Q_ASSERT(!destItem.isNull());
-
-    const KUrl destination = destItem.url();
-    if (!destItem.isWritable()) {
-        return i18nc("@info:status", "Access denied. Could not write to <filename>%1</filename>", destination.pathOrUrl());
+    if (!destItem.isNull() && !destItem.isWritable()) {
+        return i18nc("@info:status", "Access denied. Could not write to <filename>%1</filename>", destUrl.pathOrUrl());
     }
 
     const QMimeData* mimeData = event->mimeData();
@@ -42,17 +39,17 @@ QString DragAndDropHelper::dropUrls(const KFileItem& destItem, QDropEvent* event
         const QString remoteDBusClient = mimeData->data("application/x-kde-dndextract");
         QDBusMessage message = QDBusMessage::createMethodCall(remoteDBusClient, "/DndExtract",
                                                               "org.kde.DndExtract", "extractSelectedFilesTo");
-        message.setArguments(QVariantList() << destination.pathOrUrl());
+        message.setArguments(QVariantList() << destUrl.pathOrUrl());
         QDBusConnection::sessionBus().call(message);
     } else {
         const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
         foreach (const KUrl& url, urls) {
-            if (url == destination) {
+            if (url == destUrl) {
                 return i18nc("@info:status", "A folder cannot be dropped into itself");
             }
         }
 
-        KonqOperations::doDrop(destItem, destination, event, QApplication::activeWindow());
+        KonqOperations::doDrop(destItem, destUrl, event, QApplication::activeWindow());
     }
 
     return QString();
index 1998a85a0e676e6eb8c27048d5136cd8f55c4ada..8838648a05a9d2fdd27276c238e9a5fea99f5fd4 100644 (file)
@@ -38,12 +38,19 @@ public:
      * destination. A context menu with the options
      * 'Move Here', 'Copy Here', 'Link Here' and
      * 'Cancel' is offered to the user.
-     * @param destItem  Item of the destination.
+     * @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.
      * @return          Error message if dropping is not possible. If an empty string
      *                  is returned, the dropping has been successful.
      */
-    static QString dropUrls(const KFileItem& destItem, QDropEvent* event);
+    static QString dropUrls(const KFileItem& destItem,
+                            const KUrl& destUrl,
+                            QDropEvent* event);
 };
 
 #endif