┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKai Uwe Broulik <[email protected]>2022-02-07 13:10:53 +0100
committerKai Uwe Broulik <[email protected]>2022-03-04 18:25:38 +0000
commitdf79f5b47723e485395cec30645acbe0e2bafba9 (patch)
treee644b7921b988487432769bc636a8d18a0a51d9b /src
parentb6e03e05f4b63dc86c763f73ec863137ea59d2f0 (diff)
[Places Panel] Reject drops on unwritable locations
Indicate that you cannot drop here. Avoids a "Cannot drop file" or "not supported" error when dropping files ontop of a search or timeline URL. It is done in Dolphin rather than the library as there we cannot assume what a consumer might be doing with the drop.
Diffstat (limited to 'src')
-rw-r--r--src/panels/places/placespanel.cpp32
-rw-r--r--src/panels/places/placespanel.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp
index 81056fb9c..38dc4dc3a 100644
--- a/src/panels/places/placespanel.cpp
+++ b/src/panels/places/placespanel.cpp
@@ -23,9 +23,11 @@
#include <KIO/Job>
#include <KListOpenFilesJob>
#include <KLocalizedString>
+#include <KProtocolManager>
#include <QIcon>
#include <QMenu>
+#include <QMimeData>
#include <QShowEvent>
#include <QTimer>
@@ -127,6 +129,36 @@ void PlacesPanel::showEvent(QShowEvent* event)
KFilePlacesView::showEvent(event);
}
+static bool isInternalDrag(const QMimeData *mimeData)
+{
+ const auto formats = mimeData->formats();
+ for (const auto &format : formats) {
+ // from KFilePlacesModel::_k_internalMimetype
+ if (format.startsWith(QLatin1String("application/x-kfileplacesmodel-"))) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void PlacesPanel::dragMoveEvent(QDragMoveEvent *event)
+{
+ const QModelIndex index = indexAt(event->pos());
+ if (index.isValid()) {
+ auto *placesModel = static_cast<KFilePlacesModel *>(model());
+
+ // Reject drag ontop of a non-writable protocol
+ // We don't know whether we're dropping inbetween or ontop of a place
+ // so still allow internal drag events so that re-arranging still works.
+ const QUrl url = placesModel->url(index);
+ if (url.isValid() && !isInternalDrag(event->mimeData()) && !KProtocolManager::supportsWriting(url)) {
+ event->setDropAction(Qt::IgnoreAction);
+ }
+ }
+
+ KFilePlacesView::dragMoveEvent(event);
+}
+
void PlacesPanel::slotConfigureTrash()
{
const QUrl url = currentIndex().data(KFilePlacesModel::UrlRole).toUrl();
diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h
index 97be1f735..6c37301ad 100644
--- a/src/panels/places/placespanel.h
+++ b/src/panels/places/placespanel.h
@@ -54,6 +54,7 @@ Q_SIGNALS:
protected:
void showEvent(QShowEvent* event) override;
+ void dragMoveEvent(QDragMoveEvent *event) override;
private Q_SLOTS:
void slotConfigureTrash();