kde-frameworks/kio: DnD: support possibleActions() coming from the drop event

KDE-bug: https://bugs.kde.org/show_bug.cgi?id=505247

Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
This commit is contained in:
Andreas Sturmlechner
2025-08-10 20:07:04 +02:00
parent d959236c54
commit c27a4705d2
2 changed files with 165 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
From c313833da92c68e5208723ec09fff69a2c930729 Mon Sep 17 00:00:00 2001
From: Marco Martin <notmart@gmail.com>
Date: Sun, 27 Jul 2025 17:01:37 +0200
Subject: [PATCH] DnD: support possibleActions() coming from the drop event
respect the possible actions that the clients sent and
enable only those (still checking if the url can be copied or can be moved)
just always allow a link as before, as the link action is not supported by
the wayland protocol
BUG:505247
---
autotests/dropjobtest.cpp | 3 ++-
src/widgets/dropjob.cpp | 13 ++++++-------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/autotests/dropjobtest.cpp b/autotests/dropjobtest.cpp
index 2c2ca702b6..1372e6b4fb 100644
--- a/autotests/dropjobtest.cpp
+++ b/autotests/dropjobtest.cpp
@@ -435,7 +435,7 @@ private Q_SLOTS:
// When dropping the source file onto the directory
QUrl destUrl = QUrl::fromLocalFile(dest);
- QDropEvent dropEvent(QPoint(10, 10), Qt::CopyAction /*unused*/, &m_mimeData, Qt::LeftButton, Qt::NoModifier);
+ QDropEvent dropEvent(QPoint(10, 10), Qt::CopyAction | Qt::MoveAction, &m_mimeData, Qt::LeftButton, Qt::NoModifier);
KIO::DropJob *job = KIO::drop(&dropEvent, destUrl, KIO::HideProgressInfo);
JobSpy jobSpy(job);
qRegisterMetaType<KFileItemListProperties>();
@@ -447,6 +447,7 @@ private Q_SLOTS:
QVERIFY(spyShow.wait());
QTRY_VERIFY(findPopup());
QMenu *popup = findPopup();
+
QCOMPARE(int(popupDropActions(popup)), int(offeredActions));
// And when selecting action number <triggerActionNumber>
diff --git a/src/widgets/dropjob.cpp b/src/widgets/dropjob.cpp
index 70c6fb0d9b..c7416bd353 100644
--- a/src/widgets/dropjob.cpp
+++ b/src/widgets/dropjob.cpp
@@ -88,6 +88,7 @@ public:
, m_mimeData(dropEvent->mimeData()) // Extract everything from the dropevent, since it will be deleted before the job starts
, m_urls(KUrlMimeData::urlsFromMimeData(m_mimeData, KUrlMimeData::PreferLocalUrls, &m_metaData))
, m_dropAction(dropEvent->dropAction())
+ , m_possibleActions(dropEvent->possibleActions())
, m_relativePos(dropEvent->position().toPoint())
, m_keyboardModifiers(dropEvent->modifiers())
, m_hasArkFormat(m_mimeData->hasFormat(s_applicationSlashXDashKDEDashArkDashDnDExtractDashService)
@@ -519,21 +520,19 @@ void DropJobPrivate::handleCopyToDirectory()
}
m_itemProps.setItems(fileItems);
- m_possibleActions = Qt::LinkAction;
+ m_possibleActions |= Qt::LinkAction;
const bool sReading = m_itemProps.supportsReading();
// For http URLs, even though technically the protocol supports deleting,
// this never makes sense for a drag operation.
const bool sDeleting = m_allSourcesAreHttpUrls ? false : m_itemProps.supportsDeleting();
const bool sMoving = m_itemProps.supportsMoving();
- if (sReading) {
- m_possibleActions |= Qt::CopyAction;
+ if (!sReading) {
+ m_possibleActions &= ~Qt::CopyAction;
}
- if (sMoving || (sReading && sDeleting)) {
- if (!equalDestination) {
- m_possibleActions |= Qt::MoveAction;
- }
+ if (!(sMoving || (sReading && sDeleting)) || equalDestination) {
+ m_possibleActions &= ~Qt::MoveAction;
}
const bool trashing = m_destUrl.scheme() == QLatin1String("trash");
--
GitLab

View File

@@ -0,0 +1,85 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
ECM_DESIGNERPLUGIN="true"
ECM_HANDBOOK="optional"
ECM_HANDBOOK_DIR="docs"
ECM_TEST="forceoptional"
QTMIN=6.7.2
inherit ecm frameworks.kde.org xdg
DESCRIPTION="Framework providing transparent file and data management"
LICENSE="LGPL-2+"
KEYWORDS="~amd64 ~arm64 ~loong ~ppc64 ~riscv ~x86"
IUSE="acl +kwallet wayland X"
# tests hang
RESTRICT="test"
# slot op: Uses Qt6::GuiPrivate for qtx11extras_p.h
COMMON_DEPEND="
>=dev-qt/qtbase-${QTMIN}:6[dbus,gui,network,ssl,widgets,X?]
>=dev-qt/qtdeclarative-${QTMIN}:6
=kde-frameworks/kauth-${KDE_CATV}*:6
=kde-frameworks/kbookmarks-${KDE_CATV}*:6
=kde-frameworks/kcodecs-${KDE_CATV}*:6
=kde-frameworks/kcolorscheme-${KDE_CATV}*:6
=kde-frameworks/kcompletion-${KDE_CATV}*:6
=kde-frameworks/kconfig-${KDE_CATV}*:6
=kde-frameworks/kcoreaddons-${KDE_CATV}*:6
=kde-frameworks/kcrash-${KDE_CATV}*:6
=kde-frameworks/kdbusaddons-${KDE_CATV}*:6
=kde-frameworks/kguiaddons-${KDE_CATV}*:6
=kde-frameworks/ki18n-${KDE_CATV}*:6
=kde-frameworks/kiconthemes-${KDE_CATV}*:6
=kde-frameworks/kitemviews-${KDE_CATV}*:6
=kde-frameworks/kjobwidgets-${KDE_CATV}*:6
=kde-frameworks/knotifications-${KDE_CATV}*:6
=kde-frameworks/kservice-${KDE_CATV}*:6
=kde-frameworks/ktextwidgets-${KDE_CATV}*:6
=kde-frameworks/kwidgetsaddons-${KDE_CATV}*:6
=kde-frameworks/kwindowsystem-${KDE_CATV}*:6[wayland?,X?]
=kde-frameworks/solid-${KDE_CATV}*:6
acl? (
sys-apps/attr
virtual/acl
)
handbook? (
dev-libs/libxml2:=
dev-libs/libxslt
=kde-frameworks/karchive-${KDE_CATV}*:6
=kde-frameworks/kdoctools-${KDE_CATV}*:6
)
kwallet? ( =kde-frameworks/kwallet-${KDE_CATV}*:6 )
X? ( >=dev-qt/qtbase-${QTMIN}:6=[gui] )
"
DEPEND="${COMMON_DEPEND}
>=dev-qt/qtbase-${QTMIN}:6[concurrent]
"
RDEPEND="${COMMON_DEPEND}
>=dev-qt/qtbase-${QTMIN}:6[libproxy]
sys-power/switcheroo-control
"
# bug 944812: File Properties is accessible from KFileWidget (KIO); this
# provides access to keditfiletype binary via KWidgetsAddons (Tier1)
# Typical KIO revdeps (dolphin, krusader et al.) can rely on this dep
PDEPEND="
>=kde-frameworks/kded-${KDE_CATV}:6
kde-plasma/keditfiletype
"
PATCHES=( "${FILESDIR}/${P}-dnd-support-possibleActions.patch" ) # KDE-bug 505247
src_configure() {
local mycmakeargs=(
$(cmake_use_find_package acl ACL)
$(cmake_use_find_package kwallet KF6Wallet)
-DWITH_WAYLAND=$(usex wayland)
-DWITH_X11=$(usex X)
)
ecm_src_configure
}