Commit df79f5b4 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[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.
parent b6e03e05
Pipeline #145162 passed with stage
in 2 minutes and 17 seconds
......@@ -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();
......
......@@ -54,6 +54,7 @@ Q_SIGNALS:
protected:
void showEvent(QShowEvent* event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
private Q_SLOTS:
void slotConfigureTrash();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment