X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b2defa2f98468fcb9491ef7c3b96e340bb6bfa92..9df6ef77aadbd2c142bc666d3c998d9ece47f7fe:/src/views/draganddrophelper.cpp diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index 2953233d0..7b9949df4 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -52,15 +52,43 @@ KIO::DropJob *DragAndDropHelper::dropUrls(const QUrl &destUrl, QDropEvent *event return nullptr; } - // Drop into a directory or a desktop-file - KIO::DropJob *job = KIO::drop(event, destUrl); - KJobWidgets::setWindow(job, window); - return job; + // TODO: remove this check once Qt is fixed so that it doesn't emit a QDropEvent on Wayland + // when we called QDragMoveEvent::ignore() + // https://codereview.qt-project.org/c/qt/qtwayland/+/541750 + KFileItem item(destUrl); + // KFileItem(QUrl) only stat local URLs, so we always allow dropping on non-local URLs + if (!item.isLocalFile() || supportsDropping(item)) { + // Drop into a directory or a desktop-file + KIO::DropJob *job = KIO::drop(event, destUrl); + KJobWidgets::setWindow(job, window); + return job; + } } return nullptr; } +bool DragAndDropHelper::supportsDropping(const KFileItem &destItem) +{ + return (destItem.isDir() && destItem.isWritable()) || destItem.isDesktopFile(); +} + +void DragAndDropHelper::updateDropAction(QDropEvent *event, const QUrl &destUrl) +{ + if (urlListMatchesUrl(event->mimeData()->urls(), destUrl)) { + event->setDropAction(Qt::IgnoreAction); + event->ignore(); + } + KFileItem item(destUrl); + if (!item.isLocalFile() || supportsDropping(item)) { + event->setDropAction(event->proposedAction()); + event->accept(); + } else { + event->setDropAction(Qt::IgnoreAction); + event->ignore(); + } +} + void DragAndDropHelper::clearUrlListMatchesUrlCache() { DragAndDropHelper::m_urlListMatchesUrlCache.clear();