X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e9bd295b3cce63048b141d1fdba844091419a973..3bf471e0:/src/panels/places/placespanel.cpp 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();