From: David Faure Date: Fri, 14 Dec 2007 15:53:40 +0000 (+0000) Subject: Moving code around in dolphin fixes DnD support in konqueror :) X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/609ce0929289f3e26eb1898b184c7dafbf7bcac2?ds=inline Moving code around in dolphin fixes DnD support in konqueror :) svn path=/trunk/KDE/kdebase/apps/; revision=748476 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f6da05bb0..50dcec07e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,7 @@ set(dolphinprivate_LIB_SRCS dolphinsortfilterproxymodel.cpp renamedialog.cpp dolphinview.cpp + dolphindropcontroller.cpp ) kde4_add_kcfg_files(dolphinprivate_LIB_SRCS diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 231d86d92..f119f9d92 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -19,25 +19,14 @@ #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 -#include -#include - -#include -#include #include #include -#include #include DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) : diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index 8872dea38..7d29251ea 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -23,13 +23,11 @@ #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 #include #include #include @@ -39,13 +37,10 @@ #include #include -#include #include #include +#include #include -#include -#include -#include DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, DolphinColumnView* columnView, diff --git a/src/dolphindropcontroller.cpp b/src/dolphindropcontroller.cpp new file mode 100644 index 000000000..6e7ec37ba --- /dev/null +++ b/src/dolphindropcontroller.cpp @@ -0,0 +1,125 @@ +/*************************************************************************** + * 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 +#include +#include +#include +#include + +// 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%1", seq)); + + seq = QKeySequence(Qt::ControlModifier).toString(); + seq.chop(1); + QAction* copyAction = popup.addAction(KIcon("edit-copy"), + i18nc("@action:inmenu", + "&Copy Here\t%1", seq)); + + seq = QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString(); + seq.chop(1); + QAction* linkAction = popup.addAction(KIcon("insert-link"), + i18nc("@action:inmenu", + "&Link Here\t%1", 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 index 000000000..0a3c23706 --- /dev/null +++ b/src/dolphindropcontroller.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * 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 +#include +#include + +#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 diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index a45b08dcf..0c888d871 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -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); } diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 13406a6b5..46a80629b 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -20,6 +20,7 @@ ***************************************************************************/ #include "dolphinmainwindow.h" +#include "dolphindropcontroller.h" #include @@ -59,7 +60,6 @@ #include #include #include -#include #include #include #include @@ -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%1", seq)); - - seq = QKeySequence(Qt::ControlModifier).toString(); - seq.chop(1); - QAction* copyAction = popup.addAction(KIcon("edit-copy"), - i18nc("@action:inmenu", - "&Copy Here\t%1", seq)); - - seq = QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString(); - seq.chop(1); - QAction* linkAction = popup.addAction(KIcon("insert-link"), - i18nc("@action:inmenu", - "&Link Here\t%1", 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) diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 53b209642..f757520c3 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -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); diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index e25c2882f..714d4b09f 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -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()); } } diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index dcabe8329..4db66cd4b 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -40,11 +39,13 @@ #include #include #include +#include #include #include #include #include +#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) diff --git a/src/dolphinview.h b/src/dolphinview.h index 3cd7860f1..60e29b4d5 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -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); diff --git a/src/tests/renamedialogtest.cpp b/src/tests/renamedialogtest.cpp index 6404420ff..aeca0a0c4 100644 --- a/src/tests/renamedialogtest.cpp +++ b/src/tests/renamedialogtest.cpp @@ -17,9 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include - #include "renamedialogtest.h" +#include #include QTEST_KDEMAIN(RenameDialogTest, NoGUI) diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp index 37b8c5246..82e2a0507 100644 --- a/src/treeviewsidebarpage.cpp +++ b/src/treeviewsidebarpage.cpp @@ -20,7 +20,6 @@ #include "treeviewsidebarpage.h" #include "dolphinmodel.h" -#include "dolphinmainwindow.h" #include "dolphinsortfilterproxymodel.h" #include "dolphinview.h" #include "dolphinsettings.h"