]> cloud.milkyroute.net Git - dolphin.git/commitdiff
* Move code from DolphinDropController to DragAndDropHelper.
authorPeter Penz <peter.penz19@gmail.com>
Fri, 24 Oct 2008 22:19:23 +0000 (22:19 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 24 Oct 2008 22:19:23 +0000 (22:19 +0000)
* Move code which checks whether the dragging of a MIME type is supported to DragAndDropHelper. This allows adding an improved support for dropping compressed files from Ark to Dolphin later...

CCMAIL: haraldhv@stud.ntnu.no

svn path=/trunk/KDE/kdebase/apps/; revision=875611

13 files changed:
src/CMakeLists.txt
src/dolphincolumnwidget.cpp
src/dolphindetailsview.cpp
src/dolphindropcontroller.cpp [deleted file]
src/dolphindropcontroller.h [deleted file]
src/dolphinfileplacesview.cpp
src/dolphiniconsview.cpp
src/dolphinmainwindow.cpp
src/dolphinview.cpp
src/dolphinviewcontainer.cpp
src/draganddrophelper.cpp
src/draganddrophelper.h
src/treeviewsidebarpage.cpp

index e2f5a97bf7bbe79396acbd8e135475aa110c008b..0e330d65b38229b8d19ee481eb2c46b1ba6d559b 100644 (file)
@@ -25,7 +25,6 @@ set(dolphinprivate_LIB_SRCS
     dolphiniconsview.cpp
     dolphincolumnview.cpp
     dolphincolumnwidget.cpp
-    dolphindropcontroller.cpp
     dolphinfileitemdelegate.cpp
     dolphinmodel.cpp
     dolphinsettings.cpp
index 7f93638403e62a6556db9d3de51f3b29fc61395a..7b889068b86ef719e71f5b688a9c29dcd9200bee 100644 (file)
@@ -294,7 +294,7 @@ void DolphinColumnWidget::startDrag(Qt::DropActions supportedActions)
 
 void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
 {
-    if (event->mimeData()->hasUrls()) {
+    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
         event->acceptProposedAction();
     }
 }
@@ -323,7 +323,7 @@ void DolphinColumnWidget::dragMoveEvent(QDragMoveEvent* event)
     }
     setDirtyRegion(m_dropRect);
 
-    if (event->mimeData()->hasUrls()) {
+    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
         // accept url drops, independently from the destination item
         event->acceptProposedAction();
     }
index 501108c012419b27a3591b9de15e86608a9460a7..e6ce1a8ed484d6970a6f76da593f6d18399f468c 100644 (file)
@@ -312,7 +312,7 @@ void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
 
 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
 {
-    if (event->mimeData()->hasUrls()) {
+    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
         event->acceptProposedAction();
     }
 
@@ -345,7 +345,7 @@ void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
         setDirtyRegion(m_dropRect);
     }
 
-    if (event->mimeData()->hasUrls()) {
+    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
         // accept url drops, independently from the destination item
         event->acceptProposedAction();
     }
diff --git a/src/dolphindropcontroller.cpp b/src/dolphindropcontroller.cpp
deleted file mode 100644 (file)
index 40fccf0..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
- *   Copyright (C) 2007 by David Faure <faure@kde.org>                     *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
- ***************************************************************************/
-
-#include "dolphindropcontroller.h"
-#include <kfileitem.h>
-#include <konq_operations.h>
-
-void DolphinDropController::dropUrls(const KFileItem& destItem,
-                                     const KUrl& destPath,
-                                     QDropEvent* event,
-                                     QWidget* widget)
-{
-    const bool dropToItem = !destItem.isNull() && (destItem.isDir() || destItem.isDesktopFile());
-    const KUrl destination = dropToItem ? destItem.url() : destPath;
-                             
-    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
-    const KUrl sourceDir = KUrl(urls.first().directory());
-    if (sourceDir != destination) {
-        if (dropToItem) {
-            KonqOperations::doDrop(destItem, destination, event, widget);
-        } else {
-            KonqOperations::doDrop(KFileItem(), destination, event, widget);
-        }
-    }
-}
\ No newline at end of file
diff --git a/src/dolphindropcontroller.h b/src/dolphindropcontroller.h
deleted file mode 100644 (file)
index f4e7c84..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2007 by David Faure <faure@kde.org>                     *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
- ***************************************************************************/
-
-#ifndef DOLPHINDROPCONTROLLER_H
-#define DOLPHINDROPCONTROLLER_H
-
-#include "libdolphin_export.h"
-
-class QDropEvent;
-class QWidget;
-class KUrl;
-class KFileItem;
-
-/**
- * @brief Handler for drop events, shared between DolphinView and TreeViewSidebarPage
- */
-class LIBDOLPHINPRIVATE_EXPORT DolphinDropController
-{
-public:
-    /**
-     * Handles the dropping of URLs to the given
-     * 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 (can be null, see KFileItem::isNull()).
-     * @param destPath  Path of the destination.
-     * @param event     Drop event.
-     * @param widget    Source widget where the dragging has been started.
-     */
-    static void dropUrls(const KFileItem& destItem,
-                         const KUrl& destPath,
-                         QDropEvent* event,
-                         QWidget* widget);
-};
-
-#endif // DOLPHINDROPCONTROLLER_H
index c6626e010a5796db0281c17ab017ef0305563e3f..c36820ef53f32e8ded13847a122a83b2e687be87 100644 (file)
@@ -18,7 +18,7 @@
  ***************************************************************************/
 
 #include "dolphinfileplacesview.h"
-#include "dolphindropcontroller.h"
+#include "draganddrophelper.h"
 #include <kfileitem.h>
 #include <konq_operations.h>
 
@@ -45,7 +45,7 @@ void DolphinFilePlacesView::mousePressEvent(QMouseEvent* event)
 
 void DolphinFilePlacesView::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
 {
-    DolphinDropController::dropUrls(KFileItem(), dest, event, parent);
+    DragAndDropHelper::dropUrls(KFileItem(), dest, event, parent);
 }
 
 void DolphinFilePlacesView::emitExtendedUrlChangedSignal(const KUrl& url)
index 83379e279c85985df839fc0fc02009bfd0226db3..e5578df328d4b6ed3299f946d5284ea6be2540cf 100644 (file)
@@ -214,7 +214,7 @@ void DolphinIconsView::startDrag(Qt::DropActions supportedActions)
 
 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 {
-    if (event->mimeData()->hasUrls()) {
+    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
         event->acceptProposedAction();
     }
 }
@@ -242,7 +242,7 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
             m_dropRect.setSize(QSize()); // set as invalid
         }
     }
-    if (event->mimeData()->hasUrls()) {
+    if (DragAndDropHelper::isMimeDataSupported(event->mimeData())) {
         // accept url drops, independently from the destination item
         event->acceptProposedAction();
     }
index 618676935b9d2bd517c7ac4297aee21ace2a9bd6..edff432a4f65a72886d5e99f3779c9f63923385d 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "dolphinmainwindow.h"
 #include "dolphinviewactionhandler.h"
-#include "dolphindropcontroller.h"
 
 #include <config-nepomuk.h>
 
index 9e454ea711f326fdd2276d477057f4c2c6d12292..cd9b67bb7725a1e4857c79f3f47e4c8167c426a2 100644 (file)
@@ -47,7 +47,6 @@
 #include <ktoggleaction.h>
 #include <kurl.h>
 
-#include "dolphindropcontroller.h"
 #include "dolphinmodel.h"
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
@@ -58,6 +57,7 @@
 #include "dolphiniconsview.h"
 #include "dolphinsettings.h"
 #include "dolphin_generalsettings.h"
+#include "draganddrophelper.h"
 #include "folderexpander.h"
 #include "renamedialog.h"
 #include "tooltipmanager.h"
@@ -871,7 +871,7 @@ void DolphinView::dropUrls(const KFileItem& destItem,
                            const KUrl& destPath,
                            QDropEvent* event)
 {
-    DolphinDropController::dropUrls(destItem, destPath, event, this);
+    DragAndDropHelper::dropUrls(destItem, destPath, event, this);
 }
 
 void DolphinView::updateSorting(DolphinView::Sorting sorting)
index 3c1445fa5a07f356eaf89ebbe984dddf8f6ee5d2..ad79d6bb1132aa4083ba82394506827d2bee3b54 100644 (file)
@@ -46,7 +46,6 @@
 #include "dolphinmodel.h"
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
-#include "dolphindropcontroller.h"
 #include "dolphinstatusbar.h"
 #include "dolphinmainwindow.h"
 #include "dolphindirlister.h"
@@ -54,6 +53,7 @@
 #include "dolphindetailsview.h"
 #include "dolphiniconsview.h"
 #include "dolphincontextmenu.h"
+#include "draganddrophelper.h"
 #include "filterbar.h"
 #include "kurlnavigator.h"
 #include "viewproperties.h"
@@ -369,7 +369,7 @@ void DolphinViewContainer::saveRootUrl(const KUrl& url)
 
 void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
 {
-    DolphinDropController::dropUrls(KFileItem(), destination, event, this);
+    DragAndDropHelper::dropUrls(KFileItem(), destination, event, this);
 }
 
 void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
index 6d8854d2d5d8aa8090afbeb09224ca4956667650..6e3fff2fc607516b6d48af77dc8dab6d5e3cd91e 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
  *   Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at>                  *
- *                                                                         *
+ *   Copyright (C) 2007 by David Faure <faure@kde.org>                     *                                                                      *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
 #include "dolphincontroller.h"
 
 #include <kdirmodel.h>
+#include <kfileitem.h>
 #include <kicon.h>
+#include <konq_operations.h>
 
 #include <QAbstractItemView>
 #include <QAbstractProxyModel>
 #include <QDrag>
 
+bool DragAndDropHelper::isMimeDataSupported(const QMimeData* mimeData)
+{
+    return mimeData->hasUrls() || mimeData->hasFormat("application/x-kde-dndextract");
+}
+
 void DragAndDropHelper::startDrag(QAbstractItemView* itemView,
                                   Qt::DropActions supportedActions,
                                   DolphinController* controller)
@@ -60,3 +67,22 @@ void DragAndDropHelper::startDrag(QAbstractItemView* itemView,
         drag->exec(supportedActions, Qt::IgnoreAction);
     }
 }
+
+void DragAndDropHelper::dropUrls(const KFileItem& destItem,
+                                 const KUrl& destPath,
+                                 QDropEvent* event,
+                                 QWidget* widget)
+{
+    const bool dropToItem = !destItem.isNull() && (destItem.isDir() || destItem.isDesktopFile());
+    const KUrl destination = dropToItem ? destItem.url() : destPath;
+                             
+    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+    const KUrl sourceDir = KUrl(urls.first().directory());
+    if (sourceDir != destination) {
+        if (dropToItem) {
+            KonqOperations::doDrop(destItem, destination, event, widget);
+        } else {
+            KonqOperations::doDrop(KFileItem(), destination, event, widget);
+        }
+    }
+}
index 64e347e9c5ed7f14dc318b88d1e84f55eb8c1a90..920ff5135d06fe7f81091ad6dd6545ca222abb69 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
  *   Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at>                  *
- *                                                                         *
+ *   Copyright (C) 2007 by David Faure <faure@kde.org>                     *                                                                       *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
 #include <QtCore/Qt>
 
 class DolphinController;
+class KFileItem;
+class KUrl;
+class QDropEvent;
+class QMimeData;
 class QAbstractItemView;
 class QBrush;
 class QRect;
@@ -39,12 +43,33 @@ class DragAndDropHelper
 {
 
 public:
+    /**
+     * Returns true, if Dolphin supports the dragging of
+     * the given mime data.
+     */
+    static bool isMimeDataSupported(const QMimeData* mimeData);
+    
     /**
      * Creates a drag object for the view \a itemView for all selected items.
      */
     static void startDrag(QAbstractItemView* itemView,
                           Qt::DropActions supportedActions,
                           DolphinController* controller = 0);
+                          
+    /**
+     * Handles the dropping of URLs to the given
+     * 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 (can be null, see KFileItem::isNull()).
+     * @param destPath  Path of the destination.
+     * @param event     Drop event.
+     * @param widget    Source widget where the dragging has been started.
+     */
+    static void dropUrls(const KFileItem& destItem,
+                         const KUrl& destPath,
+                         QDropEvent* event,
+                         QWidget* widget);
 };
 
 #endif
index 4e591a127fca182a5c8c2f6dc5fd6eea83e62659..32779ffce8eb6ffd4a6b23c9d57f467149bc943b 100644 (file)
 
 #include "treeviewsidebarpage.h"
 
-#include "dolphindropcontroller.h"
 #include "dolphinmodel.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinview.h"
 #include "dolphinsettings.h"
 #include "dolphin_folderspanelsettings.h"
 #include "dolphin_generalsettings.h"
+#include "draganddrophelper.h"
 #include "folderexpander.h"
 #include "renamedialog.h"
 #include "sidebartreeview.h"
@@ -207,7 +207,7 @@ void TreeViewSidebarPage::dropUrls(const QModelIndex& index, QDropEvent* event)
         KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
         Q_ASSERT(!item.isNull());
         if (item.isDir()) {
-            DolphinDropController::dropUrls(item, item.url(), event, this);
+            DragAndDropHelper::dropUrls(item, item.url(), event, this);
         }
     }
 }