diff options
| author | Kai Uwe Broulik <[email protected]> | 2022-02-07 13:10:53 +0100 |
|---|---|---|
| committer | Kai Uwe Broulik <[email protected]> | 2022-03-04 18:25:38 +0000 |
| commit | df79f5b47723e485395cec30645acbe0e2bafba9 (patch) | |
| tree | e644b7921b988487432769bc636a8d18a0a51d9b /src/panels/places/placespanel.cpp | |
| parent | b6e03e05f4b63dc86c763f73ec863137ea59d2f0 (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/panels/places/placespanel.cpp')
| -rw-r--r-- | src/panels/places/placespanel.cpp | 32 |
1 files changed, 32 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(); |
