From: Peter Penz Date: Fri, 24 Oct 2008 22:19:23 +0000 (+0000) Subject: * Move code from DolphinDropController to DragAndDropHelper. X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/e7bd514a39f0b07ddfec85f5f7b391e16af7d279 * Move code from DolphinDropController to DragAndDropHelper. * 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 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2f5a97bf..0e330d65b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,7 +25,6 @@ set(dolphinprivate_LIB_SRCS dolphiniconsview.cpp dolphincolumnview.cpp dolphincolumnwidget.cpp - dolphindropcontroller.cpp dolphinfileitemdelegate.cpp dolphinmodel.cpp dolphinsettings.cpp diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index 7f9363840..7b889068b 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -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(); } diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 501108c01..e6ce1a8ed 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -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 index 40fccf0d2..000000000 --- a/src/dolphindropcontroller.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * Copyright (C) 2007 by David Faure * - * * - * 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 -#include - -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 index f4e7c84c2..000000000 --- a/src/dolphindropcontroller.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by David Faure * - * * - * 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 diff --git a/src/dolphinfileplacesview.cpp b/src/dolphinfileplacesview.cpp index c6626e010..c36820ef5 100644 --- a/src/dolphinfileplacesview.cpp +++ b/src/dolphinfileplacesview.cpp @@ -18,7 +18,7 @@ ***************************************************************************/ #include "dolphinfileplacesview.h" -#include "dolphindropcontroller.h" +#include "draganddrophelper.h" #include #include @@ -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) diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 83379e279..e5578df32 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -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(); } diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 618676935..edff432a4 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -21,7 +21,6 @@ #include "dolphinmainwindow.h" #include "dolphinviewactionhandler.h" -#include "dolphindropcontroller.h" #include diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 9e454ea71..cd9b67bb7 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -47,7 +47,6 @@ #include #include -#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) diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 3c1445fa5..ad79d6bb1 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -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) diff --git a/src/draganddrophelper.cpp b/src/draganddrophelper.cpp index 6d8854d2d..6e3fff2fc 100644 --- a/src/draganddrophelper.cpp +++ b/src/draganddrophelper.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2007 by Peter Penz * - * * + * Copyright (C) 2007 by David Faure * * * * 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 * @@ -22,12 +22,19 @@ #include "dolphincontroller.h" #include +#include #include +#include #include #include #include +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); + } + } +} diff --git a/src/draganddrophelper.h b/src/draganddrophelper.h index 64e347e9c..920ff5135 100644 --- a/src/draganddrophelper.h +++ b/src/draganddrophelper.h @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2007 by Peter Penz * - * * + * Copyright (C) 2007 by David Faure * * * * 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 * @@ -23,6 +23,10 @@ #include 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 diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp index 4e591a127..32779ffce 100644 --- a/src/treeviewsidebarpage.cpp +++ b/src/treeviewsidebarpage.cpp @@ -19,13 +19,13 @@ #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); } } }