]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Moving code around in dolphin fixes DnD support in konqueror :)
authorDavid Faure <faure@kde.org>
Fri, 14 Dec 2007 15:53:40 +0000 (15:53 +0000)
committerDavid Faure <faure@kde.org>
Fri, 14 Dec 2007 15:53:40 +0000 (15:53 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=748476

13 files changed:
src/CMakeLists.txt
src/dolphincolumnview.cpp
src/dolphincolumnwidget.cpp
src/dolphindropcontroller.cpp [new file with mode: 0644]
src/dolphindropcontroller.h [new file with mode: 0644]
src/dolphiniconsview.cpp
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinpart.cpp
src/dolphinview.cpp
src/dolphinview.h
src/tests/renamedialogtest.cpp
src/treeviewsidebarpage.cpp

index f6da05bb0ce89b134e8574a3b84f0891ff8ab423..50dcec07ecc565c17f2cbffe20e2d8d45e60da9d 100644 (file)
@@ -22,6 +22,7 @@ set(dolphinprivate_LIB_SRCS
     dolphinsortfilterproxymodel.cpp
     renamedialog.cpp
     dolphinview.cpp
+    dolphindropcontroller.cpp
     )
 
 kde4_add_kcfg_files(dolphinprivate_LIB_SRCS
index 231d86d92f8da006511ed64b3d47102779671b82..f119f9d92a2c087a0ef42bfea4948e004a103598 100644 (file)
 
 #include "dolphincolumnview.h"
 
-#include "dolphinmodel.h"
 #include "dolphincolumnwidget.h"
 #include "dolphincontroller.h"
-#include "dolphindirlister.h"
-#include "dolphinmodel.h"
-#include "dolphinsortfilterproxymodel.h"
 #include "dolphinsettings.h"
 
 #include "dolphin_columnmodesettings.h"
 
-#include <kcolorutils.h>
-#include <kcolorscheme.h>
-#include <kdirlister.h>
-
-#include <QAbstractProxyModel>
-#include <QApplication>
 #include <QPoint>
 #include <QScrollBar>
-#include <QTimer>
 #include <QTimeLine>
 
 DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) :
index 8872dea3842bfda7e7db284805a0db89c48bf1a9..7d29251ea62057abdaa79ef15521ea76cedc7420 100644 (file)
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
 #include "dolphindirlister.h"
-#include "dolphinmodel.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinsettings.h"
 #include "dolphin_columnmodesettings.h"
 #include "draganddrophelper.h"
 
-#include <kcolorutils.h>
 #include <kcolorscheme.h>
 #include <kdirlister.h>
 #include <kfileitem.h>
 #include <kmimetyperesolver.h>
 #include <konqmimedata.h>
 
-#include <QAbstractProxyModel>
 #include <QApplication>
 #include <QClipboard>
+#include <QPainter>
 #include <QPoint>
-#include <QScrollBar>
-#include <QTimer>
-#include <QTimeLine>
 
 DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
                                          DolphinColumnView* columnView,
diff --git a/src/dolphindropcontroller.cpp b/src/dolphindropcontroller.cpp
new file mode 100644 (file)
index 0000000..6e7ec37
--- /dev/null
@@ -0,0 +1,125 @@
+/***************************************************************************
+ *   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 <klocale.h>
+#include <kicon.h>
+#include <QApplication>
+#include <kdebug.h>
+#include <kmenu.h>
+#include <konq_operations.h>
+
+// TODO replace with KonqOperations::doDrop [or move doDrop code into this class]
+// Note that this means changing the DolphinDropController controller usage
+// to "create with new and let it autodelete" instead of on stack, since doDrop is async.
+
+DolphinDropController::DolphinDropController(QWidget* parentWidget)
+    : QObject(parentWidget), m_parentWidget(parentWidget)
+{
+}
+
+DolphinDropController::~DolphinDropController()
+{
+}
+
+void DolphinDropController::dropUrls(const KUrl::List& urls,
+                                     const KUrl& destination)
+{
+    kDebug() << "Source" << urls;
+    kDebug() << "Destination:" << destination;
+
+    Qt::DropAction action = Qt::CopyAction;
+
+    Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
+    const bool shiftPressed   = modifier & Qt::ShiftModifier;
+    const bool controlPressed = modifier & Qt::ControlModifier;
+    if (shiftPressed && controlPressed) {
+        // shortcut for 'Link Here' is used
+        action = Qt::LinkAction;
+    } else if (shiftPressed) {
+        // shortcut for 'Move Here' is used
+        action = Qt::MoveAction;
+    } else if (controlPressed) {
+        // shortcut for 'Copy Here' is used
+        action = Qt::CopyAction;
+    } else {
+        // open a context menu which offers the following actions:
+        // - Move Here
+        // - Copy Here
+        // - Link Here
+        // - Cancel
+
+        KMenu popup(m_parentWidget);
+
+        QString seq = QKeySequence(Qt::ShiftModifier).toString();
+        seq.chop(1); // chop superfluous '+'
+        QAction* moveAction = popup.addAction(KIcon("go-jump"),
+                                              i18nc("@action:inmenu",
+                                                    "&Move Here\t<shortcut>%1</shortcut>", seq));
+
+        seq = QKeySequence(Qt::ControlModifier).toString();
+        seq.chop(1);
+        QAction* copyAction = popup.addAction(KIcon("edit-copy"),
+                                              i18nc("@action:inmenu",
+                                                    "&Copy Here\t<shortcut>%1</shortcut>", seq));
+
+        seq = QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString();
+        seq.chop(1);
+        QAction* linkAction = popup.addAction(KIcon("insert-link"),
+                                              i18nc("@action:inmenu",
+                                                    "&Link Here\t<shortcut>%1</shortcut>", seq));
+
+        popup.addSeparator();
+        popup.addAction(KIcon("process-stop"), i18nc("@action:inmenu", "Cancel"));
+
+        QAction* activatedAction = popup.exec(QCursor::pos());
+        if (activatedAction == moveAction) {
+            action = Qt::MoveAction;
+        } else if (activatedAction == copyAction) {
+            action = Qt::CopyAction;
+        } else if (activatedAction == linkAction) {
+            action = Qt::LinkAction;
+        } else {
+            return;
+        }
+    }
+
+    switch (action) {
+    case Qt::MoveAction:
+        KonqOperations::copy(m_parentWidget, KonqOperations::MOVE, urls, destination);
+        emit doingOperation(KonqFileUndoManager::MOVE);
+        break;
+
+    case Qt::CopyAction:
+        KonqOperations::copy(m_parentWidget, KonqOperations::COPY, urls, destination);
+        emit doingOperation(KonqFileUndoManager::COPY);
+        break;
+
+    case Qt::LinkAction:
+        KonqOperations::copy(m_parentWidget, KonqOperations::LINK, urls, destination);
+        emit doingOperation(KonqFileUndoManager::LINK);
+        break;
+
+    default:
+        break;
+    }
+}
+
+#include "dolphindropcontroller.moc"
diff --git a/src/dolphindropcontroller.h b/src/dolphindropcontroller.h
new file mode 100644 (file)
index 0000000..0a3c237
--- /dev/null
@@ -0,0 +1,64 @@
+/***************************************************************************
+ *   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 <QObject>
+#include <kurl.h>
+#include <konq_fileundomanager.h>
+
+#include "libdolphin_export.h"
+
+/**
+ * @brief Handler for drop events, shared between DolphinView and TreeViewSidebarPage
+ */
+class LIBDOLPHINPRIVATE_EXPORT DolphinDropController : public QObject
+{
+    Q_OBJECT
+public:
+    explicit DolphinDropController(QWidget* parentWidget);
+    virtual ~DolphinDropController();
+
+    /**
+     * 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 urls        List of URLs which have been
+     *                    dropped.
+     * @param destination Destination URL, where the
+     *                    list or URLs should be moved,
+     *                    copied or linked to.
+     */
+    void dropUrls(const KUrl::List& urls,
+                  const KUrl& destination);
+
+signals:
+    /**
+     * Is emitted when renaming, copying, moving, linking etc.
+     * Used for feedback in the mainwindow.
+     */
+    void doingOperation(KonqFileUndoManager::CommandType type);
+
+private:
+    QWidget* m_parentWidget;
+};
+
+#endif // DOLPHINDROPCONTROLLER_H
index a45b08dcf9886b27d7235c07900798ebca0468c6..0c888d8714ca9f566828d8414eabb596cba294aa 100644 (file)
@@ -225,12 +225,20 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
     setDirtyRegion(m_dropRect);
 
     m_dropRect.setSize(QSize()); // set as invalid
+    bool destIsDir = false;
     if (index.isValid()) {
         const KFileItem item = itemForIndex(index);
         if (!item.isNull() && item.isDir()) {
             m_dropRect = visualRect(index);
+            destIsDir = true;
         }
+    } else { // dropping on viewport
+        destIsDir = true;
     }
+    if (destIsDir && event->mimeData()->hasUrls()) {
+        event->acceptProposedAction();
+    }
+
     setDirtyRegion(m_dropRect);
 }
 
index 13406a6b5224d5b7f08d9a4eb2eca3a82882ff59..46a80629b6bc1a416dffee7a3e1a33b7f9f8d2f9 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "dolphinmainwindow.h"
+#include "dolphindropcontroller.h"
 
 #include <config-nepomuk.h>
 
@@ -59,7 +60,6 @@
 #include <kmenubar.h>
 #include <kmessagebox.h>
 #include <konqmimedata.h>
-#include <konq_operations.h>
 #include <kpropertiesdialog.h>
 #include <kprotocolinfo.h>
 #include <ktoggleaction.h>
@@ -150,84 +150,10 @@ void DolphinMainWindow::refreshViews()
 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
                                  const KUrl& destination)
 {
-    kDebug() << "Source" << urls;
-    kDebug() << "Destination:" << destination;
-
-    Qt::DropAction action = Qt::CopyAction;
-
-    Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
-    const bool shiftPressed   = modifier & Qt::ShiftModifier;
-    const bool controlPressed = modifier & Qt::ControlModifier;
-    if (shiftPressed && controlPressed) {
-        // shortcut for 'Link Here' is used
-        action = Qt::LinkAction;
-    } else if (shiftPressed) {
-        // shortcut for 'Move Here' is used
-        action = Qt::MoveAction;
-    } else if (controlPressed) {
-        // shortcut for 'Copy Here' is used
-        action = Qt::CopyAction;
-    } else {
-        // open a context menu which offers the following actions:
-        // - Move Here
-        // - Copy Here
-        // - Link Here
-        // - Cancel
-
-        KMenu popup(this);
-
-        QString seq = QKeySequence(Qt::ShiftModifier).toString();
-        seq.chop(1); // chop superfluous '+'
-        QAction* moveAction = popup.addAction(KIcon("go-jump"),
-                                              i18nc("@action:inmenu",
-                                                    "&Move Here\t<shortcut>%1</shortcut>", seq));
-
-        seq = QKeySequence(Qt::ControlModifier).toString();
-        seq.chop(1);
-        QAction* copyAction = popup.addAction(KIcon("edit-copy"),
-                                              i18nc("@action:inmenu",
-                                                    "&Copy Here\t<shortcut>%1</shortcut>", seq));
-
-        seq = QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString();
-        seq.chop(1);
-        QAction* linkAction = popup.addAction(KIcon("insert-link"),
-                                              i18nc("@action:inmenu",
-                                                    "&Link Here\t<shortcut>%1</shortcut>", seq));
-
-        popup.addSeparator();
-        popup.addAction(KIcon("process-stop"), i18nc("@action:inmenu", "Cancel"));
-
-        QAction* activatedAction = popup.exec(QCursor::pos());
-        if (activatedAction == moveAction) {
-            action = Qt::MoveAction;
-        } else if (activatedAction == copyAction) {
-            action = Qt::CopyAction;
-        } else if (activatedAction == linkAction) {
-            action = Qt::LinkAction;
-        } else {
-            return;
-        }
-    }
-
-    switch (action) {
-    case Qt::MoveAction:
-        KonqOperations::copy(this, KonqOperations::MOVE, urls, destination);
-        m_undoCommandTypes.append(KonqFileUndoManager::MOVE);
-        break;
-
-    case Qt::CopyAction:
-        KonqOperations::copy(this, KonqOperations::COPY, urls, destination);
-        m_undoCommandTypes.append(KonqFileUndoManager::COPY);
-        break;
-
-    case Qt::LinkAction:
-        KonqOperations::copy(this, KonqOperations::LINK, urls, destination);
-        m_undoCommandTypes.append(KonqFileUndoManager::LINK);
-        break;
-
-    default:
-        break;
-    }
+    DolphinDropController dropController(this);
+    connect(&dropController, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
+            this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType)));
+    dropController.dropUrls(urls, destination);
 }
 
 void DolphinMainWindow::changeUrl(const KUrl& url)
index 53b20964282e83f923ef7eb0715c6c16e8d2c7d5..f757520c371a7e10ee3daa0311e7d45a8922a220 100644 (file)
@@ -102,14 +102,7 @@ public:
 public slots:
     /**
      * 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 urls        List of URLs which have been
-     *                    dropped.
-     * @param destination Destination URL, where the
-     *                    list or URLs should be moved,
-     *                    copied or linked to.
+     * destination. This is only called by the TreeViewSidebarPage.
      */
     void dropUrls(const KUrl::List& urls,
                   const KUrl& destination);
index e25c2882f1faeb1c5220ead728a544bf773255b0..714d4b09f5d46aa2b85fb95d60d864416d20be70 100644 (file)
@@ -102,12 +102,8 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi
     // TODO sort_by_* actions
     // TODO show_*_info actions
 
-    // TODO connect to urlsDropped
-
     // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
     // (sort of spacial navigation)
-
-    // TODO MMB-click should do something like KonqDirPart::mmbClicked
 }
 
 DolphinPart::~DolphinPart()
@@ -144,7 +140,6 @@ void DolphinPart::createActions()
 
 void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
 {
-    // Yes, DolphinMainWindow has very similar code :/
     const bool hasSelection = !selection.isEmpty();
     if (!hasSelection) {
         stateChanged("has_no_selection");
@@ -232,20 +227,23 @@ void DolphinPart::slotRequestItemInfo(const KFileItem& item)
 
 void DolphinPart::slotItemTriggered(const KFileItem& item)
 {
-    qDebug() << QApplication::mouseButtons();
+    // MMB click support.
+    // TODO: this doesn't work, mouseButtons() is always 0.
+    // Issue N176832 for the missing QAIV signal; task 177399
+    kDebug() << QApplication::mouseButtons();
     if (QApplication::mouseButtons() & Qt::MidButton) {
-        qDebug() << "MMB!!" << item.mimetype();
+        kDebug() << "MMB!!" << item.mimetype();
         if (item.mimeTypePtr()->is("inode/directory")) {
             KParts::OpenUrlArguments args;
             args.setMimeType( item.mimetype() );
             emit m_extension->createNewWindow( item.url(), args );
         } else {
-            qDebug() << "run()";
+            kDebug() << "run()";
             item.run();
         }
     } else {
         // Left button. [Right button goes to slotOpenContextMenu before triggered can be emitted]
-        qDebug() << "LMB";
+        kDebug() << "LMB";
         emit m_extension->openUrlRequest(item.url());
     }
 }
index dcabe8329ebd0f8096f4c09a4ec7f5f26528df0d..4db66cd4bb4ce07921c93ba38a6f5f4b71c4401d 100644 (file)
@@ -29,7 +29,6 @@
 #include <QBoxLayout>
 #include <QTimer>
 #include <QScrollBar>
-#include <QClipboard>
 
 #include <kcolorscheme.h>
 #include <kdirlister.h>
 #include <kio/netaccess.h>
 #include <kio/previewjob.h>
 #include <kjob.h>
+#include <kmenu.h>
 #include <kmimetyperesolver.h>
 #include <konqmimedata.h>
 #include <konq_operations.h>
 #include <kurl.h>
 
+#include "dolphindropcontroller.h"
 #include "dolphinmodel.h"
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
@@ -751,6 +752,7 @@ void DolphinView::dropUrls(const KUrl::List& urls,
                            const KUrl& destPath,
                            const KFileItem& destItem)
 {
+    Q_ASSERT(!urls.isEmpty());
     const KUrl& destination = !destItem.isNull() && destItem.isDir() ?
                               destItem.url() : destPath;
     const KUrl sourceDir = KUrl(urls.first().directory());
@@ -762,7 +764,11 @@ void DolphinView::dropUrls(const KUrl::List& urls,
 void DolphinView::dropUrls(const KUrl::List& urls,
                            const KUrl& destination)
 {
-    emit urlsDropped(urls, destination);
+    DolphinDropController dropController(this);
+    // forward doingOperation signal up to the mainwindow
+    connect(&dropController, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
+            this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)));
+    dropController.dropUrls(urls, destination);
 }
 
 void DolphinView::updateSorting(DolphinView::Sorting sorting)
index 3cd7860f1d83b0c576b01659c8ed97aaa451f62f..60e29b4d5a8d702bdef99da8f75e5cb90b3e7136 100644 (file)
@@ -476,14 +476,6 @@ signals:
      */
     void requestContextMenu(const KFileItem& item, const KUrl& url);
 
-    /**
-     * Is emitted if the URLs \a are dropped to the destination URL
-     * \a destination. No operation is done within the DolphinView, the
-     * receiver of the signal has to take care about the corresponding
-     * operation.
-     */
-    void urlsDropped(const KUrl::List& urls, const KUrl& destination);
-
     /**
      * Is emitted if an information message with the content \a msg
      * should be shown.
@@ -566,8 +558,8 @@ private slots:
                   const KFileItem& destItem);
 
     /**
-     * Drops the URLs \a urls at the
-     * destination \a destination.
+     * Handles the dropping of URLs to the given destination.
+     * @see DolphinDropController
      */
     void dropUrls(const KUrl::List& urls,
                   const KUrl& destination);
@@ -585,7 +577,7 @@ private slots:
 
     /**
      * Updates the view properties of the current URL to the
-     * additional informations given by \a info.
+     * additional information given by \a info.
      */
     void updateAdditionalInfo(const KFileItemDelegate::InformationList& info);
 
index 6404420ffaf9a03656a807d2ccab313a962ea2a6..aeca0a0c4efd5196aa3035bf323237a784b5db57 100644 (file)
@@ -17,9 +17,8 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
-#include <qtest_kde.h>
-
 #include "renamedialogtest.h"
+#include <qtest_kde.h>
 #include <renamedialog.h>
 
 QTEST_KDEMAIN(RenameDialogTest, NoGUI)
index 37b8c5246e95d86482310d54eaa060c68ac004e3..82e2a0507f43f882561ee9d61749628e32c896eb 100644 (file)
@@ -20,7 +20,6 @@
 #include "treeviewsidebarpage.h"
 
 #include "dolphinmodel.h"
-#include "dolphinmainwindow.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinview.h"
 #include "dolphinsettings.h"