#include "dolphin_generalsettings.h"
#include "draganddrophelper.h"
#include "folderexpander.h"
-#include "kfilepreviewgenerator.h"
#include "selectionmanager.h"
#include "tooltipmanager.h"
#include <kcolorscheme.h>
#include <kdirlister.h>
#include <kfileitem.h>
+#include <kfilepreviewgenerator.h>
#include <kio/previewjob.h>
#include <kiconeffect.h>
#include <kjob.h>
void DolphinColumnWidget::dropEvent(QDropEvent* event)
{
- const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
- if (!urls.isEmpty()) {
- const QModelIndex index = indexAt(event->pos());
- m_view->m_controller->setItemView(this);
- const KFileItem item = m_view->m_controller->itemForIndex(index);
- m_view->m_controller->indicateDroppedUrls(urls,
- url(),
- item);
- event->acceptProposedAction();
- }
+ const QModelIndex index = indexAt(event->pos());
+ m_view->m_controller->setItemView(this);
+ const KFileItem item = m_view->m_controller->itemForIndex(index);
+ m_view->m_controller->indicateDroppedUrls(item, url(), event);
QListView::dropEvent(event);
}
emit activated();
}
-void DolphinController::indicateDroppedUrls(const KUrl::List& urls,
+void DolphinController::indicateDroppedUrls(const KFileItem& destItem,
const KUrl& destPath,
- const KFileItem& destItem)
+ QDropEvent* event)
{
- emit urlsDropped(urls, destPath, destItem);
+ emit urlsDropped(destItem, destPath, event);
}
* Indicates that URLs are dropped above a destination. This method
* should be invoked by the view implementation. The abstract Dolphin view
* will start the corresponding action (copy, move, link).
- * @param urls URLs that are dropped above a destination.
+ * @param destItem Item of the destination (can be null, see KFileItem::isNull()).
* @param destPath Path of the destination.
- * @param destItem Destination item (can be null, see KFileItem::isNull()).
+ * @param event Drop event
*/
- void indicateDroppedUrls(const KUrl::List& urls,
+ void indicateDroppedUrls(const KFileItem& destItem,
const KUrl& destPath,
- const KFileItem& destItem);
+ QDropEvent* event);
/**
* Informs the abstract Dolphin view about a sorting change done inside
void activated();
/**
- * Is emitted if the URLs \a urls have been dropped to the destination
+ * Is emitted if URLs have been dropped to the destination
* path \a destPath. If the URLs have been dropped above an item of
* the destination path, the item is indicated by \a destItem
* (can be null, see KFileItem::isNull()).
*/
- void urlsDropped(const KUrl::List& urls,
+ void urlsDropped(const KFileItem& destItem,
const KUrl& destPath,
- const KFileItem& destItem);
+ QDropEvent* event);
/**
* Is emitted if the sorting has been changed to \a sorting by
void DolphinDetailsView::dropEvent(QDropEvent* event)
{
- const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
- if (!urls.isEmpty()) {
- event->acceptProposedAction();
- const QModelIndex index = indexAt(event->pos());
- KFileItem item;
- if (index.isValid() && (index.column() == DolphinModel::Name)) {
- item = m_controller->itemForIndex(index);
- }
- m_controller->indicateDroppedUrls(urls,
- m_controller->url(),
- item);
+ const QModelIndex index = indexAt(event->pos());
+ KFileItem item;
+ if (index.isValid() && (index.column() == DolphinModel::Name)) {
+ item = m_controller->itemForIndex(index);
}
+ m_controller->indicateDroppedUrls(item, m_controller->url(), event);
QTreeView::dropEvent(event);
}
***************************************************************************/
#include "dolphindropcontroller.h"
+#include <kfileitem.h>
#include <klocale.h>
#include <kicon.h>
#include <QApplication>
#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.
-// NOTE: let's wait for KDirModel::dropEvent first.
-
DolphinDropController::DolphinDropController(QWidget* parentWidget)
: QObject(parentWidget), m_parentWidget(parentWidget)
{
{
}
-void DolphinDropController::dropUrls(const KUrl::List& urls,
- const KUrl& destination)
+void DolphinDropController::dropUrls(const KFileItem& destItem,
+ const KUrl& destPath,
+ QDropEvent* event)
{
- kDebug() << "Source" << urls;
- kDebug() << "Destination:" << destination;
-
- if (destination.protocol() == "trash") {
- KonqOperations::del(m_parentWidget, KonqOperations::TRASH, urls);
- return;
- }
-
- Qt::DropAction action = Qt::CopyAction;
-
- Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
- const bool shiftPressed = modifier & Qt::ShiftModifier;
- const bool controlPressed = modifier & Qt::ControlModifier;
- const bool altPressed = modifier & Qt::AltModifier;
- if ((shiftPressed && controlPressed) || altPressed) {
- action = Qt::LinkAction;
- } else if (controlPressed) {
- action = Qt::CopyAction;
- } else if (shiftPressed) {
- action = Qt::MoveAction;
- } 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("edit-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;
+ 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, m_parentWidget);
} else {
- return;
+ KonqOperations::doDrop(KFileItem(), destination, event, m_parentWidget);
}
}
-
- switch (action) {
- case Qt::MoveAction:
- KonqOperations::copy(m_parentWidget, KonqOperations::MOVE, urls, destination);
- emit doingOperation(KIO::FileUndoManager::Move);
- break;
-
- case Qt::CopyAction:
- KonqOperations::copy(m_parentWidget, KonqOperations::COPY, urls, destination);
- emit doingOperation(KIO::FileUndoManager::Copy);
- break;
-
- case Qt::LinkAction:
- KonqOperations::copy(m_parentWidget, KonqOperations::LINK, urls, destination);
- emit doingOperation(KIO::FileUndoManager::Link);
- break;
-
- default:
- break;
- }
+ // TODO: emit doingOperation, so that the main window gets informed about
+ // about the finished operations
}
#include "dolphindropcontroller.moc"
#define DOLPHINDROPCONTROLLER_H
#include <QObject>
-#include <kurl.h>
#include <kio/fileundomanager.h>
#include "libdolphin_export.h"
+class QDropEvent;
+class KUrl;
+class KFileItem;
+
/**
* @brief Handler for drop events, shared between DolphinView and TreeViewSidebarPage
*/
* 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.
+ * @param destItem Item of the destination (can be null, see KFileItem::isNull()).
+ * @param destPath Path of the destination.
+ * @param event Drop event
*/
- void dropUrls(const KUrl::List& urls,
- const KUrl& destination);
+ void dropUrls(const KFileItem& destItem,
+ const KUrl& destPath,
+ QDropEvent* event);
signals:
/**
#include "dolphinfileplacesview.h"
#include "dolphindropcontroller.h"
+#include <kfileitem.h>
#include <konq_operations.h>
DolphinFilePlacesView::DolphinFilePlacesView(QWidget* parent) :
void DolphinFilePlacesView::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
{
- const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
-
DolphinDropController dropController(parent);
// forward doingOperation signal up to the mainwindow
connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)));
- dropController.dropUrls(urls, dest);
+ dropController.dropUrls(KFileItem(), dest, event);
}
void DolphinFilePlacesView::emitExtendedUrlChangedSignal(const KUrl& url)
void DolphinIconsView::dropEvent(QDropEvent* event)
{
- if (!selectionModel()->isSelected(indexAt(event->pos()))) {
- const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
- if (!urls.isEmpty()) {
- const QModelIndex index = indexAt(event->pos());
- const KFileItem item = m_controller->itemForIndex(index);
- m_controller->indicateDroppedUrls(urls,
- m_controller->url(),
- item);
- event->acceptProposedAction();
- }
- }
+ const QModelIndex index = indexAt(event->pos());
+ const KFileItem item = m_controller->itemForIndex(index);
+ m_controller->indicateDroppedUrls(item, m_controller->url(), event);
KCategorizedView::dropEvent(event);
}
#include <QSplitter>
#include <QDockWidget>
+#include <kdebug.h>
+
DolphinMainWindow::DolphinMainWindow(int id) :
KXmlGuiWindow(0),
m_newMenu(0),
setActiveViewContainer(activeViewContainer);
}
-void DolphinMainWindow::dropUrls(const KUrl::List& urls,
- const KUrl& destination)
+void DolphinMainWindow::dropUrls(const KFileItem& destItem,
+ const KUrl& destPath,
+ QDropEvent* event)
{
DolphinDropController dropController(this);
connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
this, SLOT(slotDoingOperation(KIO::FileUndoManager::CommandType)));
- dropController.dropUrls(urls, destination);
+ dropController.dropUrls(destItem, destPath, event);
}
void DolphinMainWindow::pasteIntoFolder()
this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
this, SLOT(changeSelection(KFileItemList)));
- connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
- this, SLOT(dropUrls(KUrl::List, KUrl)));
+ // TODO: connecting to urlsDropped() fails!
+ connect(treeWidget, SIGNAL(urlsDropped(KFileItem&, KUrl&, QDropEvent*)),
+ this, SLOT(dropUrls(KFileItem&, KUrl&, QDropEvent*)));
// setup "Terminal"
#ifndef Q_OS_WIN
class KNewMenu;
class KTabBar;
class KUrl;
+class QDropEvent;
class QSplitter;
/**
* Handles the dropping of URLs to the given
* destination. This is only called by the TreeViewSidebarPage.
*/
- void dropUrls(const KUrl::List& urls,
- const KUrl& destination);
+ void dropUrls(const KFileItem& destItem,
+ const KUrl& destPath,
+ QDropEvent* event);
/**
* Pastes the clipboard data into the currently selected folder
#include <kcolorscheme.h>
#include <kdirlister.h>
#include <kfileitemdelegate.h>
+#include <kfilepreviewgenerator.h>
#include <kiconeffect.h>
#include <klocale.h>
#include <kio/deletejob.h>
#include "dolphinsettings.h"
#include "dolphin_generalsettings.h"
#include "folderexpander.h"
-#include "kfilepreviewgenerator.h"
#include "renamedialog.h"
#include "tooltipmanager.h"
#include "viewproperties.h"
connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
this, SLOT(openContextMenu(const QPoint&)));
- connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&, const KFileItem&)),
- this, SLOT(dropUrls(const KUrl::List&, const KUrl&, const KFileItem&)));
+ connect(m_controller, SIGNAL(urlsDropped(const KFileItem&, const KUrl&, QDropEvent*)),
+ this, SLOT(dropUrls(const KFileItem&, const KUrl&, QDropEvent*)));
connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
this, SLOT(updateSorting(DolphinView::Sorting)));
connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
m_isContextMenuOpen = false;
}
-void DolphinView::dropUrls(const KUrl::List& urls,
+void DolphinView::dropUrls(const KFileItem& destItem,
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());
- if (sourceDir != destination) {
- DolphinDropController dropController(this);
- // forward doingOperation signal up to the mainwindow
- connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
- this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)));
- dropController.dropUrls(urls, destination);
- }
+ QDropEvent* event)
+{
+ DolphinDropController dropController(this);
+ // forward doingOperation signal up to the mainwindow
+ connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
+ this, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)));
+ dropController.dropUrls(destItem, destPath, event);
}
void DolphinView::updateSorting(DolphinView::Sorting sorting)
void openContextMenu(const QPoint& pos);
/**
- * Drops the URLs \a urls to the destination path \a destPath. If
+ * Drops dragged URLs to the destination path \a destPath. If
* the URLs are dropped above an item inside the destination path,
* the item is indicated by \a destItem.
*/
- void dropUrls(const KUrl::List& urls,
+ void dropUrls(const KFileItem& destItem,
const KUrl& destPath,
- const KFileItem& destItem);
+ QDropEvent* event);
/**
* Updates the view properties of the current URL to the
void SidebarTreeView::dropEvent(QDropEvent* event)
{
- const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
- if (urls.isEmpty()) {
- KTreeView::dropEvent(event);
- } else {
- event->acceptProposedAction();
- const QModelIndex index = indexAt(event->pos());
- if (index.isValid()) {
- emit urlsDropped(urls, index);
- }
+ const QModelIndex index = indexAt(event->pos());
+ if (index.isValid()) {
+ emit urlsDropped(index, event);
}
+ KTreeView::dropEvent(event);
}
#include "sidebartreeview.moc"
signals:
/**
- * Is emitted if the URLs \a urls have been dropped to
+ * Is emitted if the URL have been dropped to
* the index \a index.
*/
- void urlsDropped(const KUrl::List& urls,
- const QModelIndex& index);
+ void urlsDropped(const QModelIndex& index, QDropEvent* event);
protected:
virtual bool event(QEvent* event);
connect(m_treeView, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(updateActiveView(const QModelIndex&)));
- connect(m_treeView, SIGNAL(urlsDropped(const KUrl::List&, const QModelIndex&)),
- this, SLOT(dropUrls(const KUrl::List&, const QModelIndex&)));
+ connect(m_treeView, SIGNAL(urlsDropped(const QModelIndex&, QDropEvent*)),
+ this, SLOT(dropUrls(const QModelIndex&, QDropEvent*)));
connect(m_treeView, SIGNAL(pressed(const QModelIndex&)),
this, SLOT(updateMouseButtons()));
}
}
-void TreeViewSidebarPage::dropUrls(const KUrl::List& urls,
- const QModelIndex& index)
+void TreeViewSidebarPage::dropUrls(const QModelIndex& index, QDropEvent* event)
{
if (index.isValid()) {
const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
Q_ASSERT(!item.isNull());
if (item.isDir()) {
- emit urlsDropped(urls, item.url());
+ emit urlsDropped(item, item.url(), event);
}
}
}
* This signal is emitted whenever a drop action on this widget needs the
* MainWindow's attention.
*/
- void urlsDropped(const KUrl::List& urls, const KUrl& destination);
+ void urlsDropped(const KFileItem& destItem, const KUrl& destPath, QDropEvent* event);
public slots:
/**
void updateActiveView(const QModelIndex& index);
/**
- * Is emitted if the URLs \a urls have been dropped
- * to the index \a index. */
- void dropUrls(const KUrl::List& urls,
- const QModelIndex& index);
+ * Is emitted if URLs have been dropped
+ * to the index \a index.
+ */
+ void dropUrls(const QModelIndex& index, QDropEvent* event);
/**
* Invokes expandToLeafDir() asynchronously (the expanding