From c313833da92c68e5208723ec09fff69a2c930729 Mon Sep 17 00:00:00 2001 From: Marco Martin 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(); @@ -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 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