From: Kai Uwe Broulik Date: Mon, 7 Feb 2022 12:10:53 +0000 (+0100) Subject: [Places Panel] Reject drops on unwritable locations X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/df79f5b47723e485395cec30645acbe0e2bafba9 [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. --- 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 #include #include +#include #include #include +#include #include #include @@ -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(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();