From 7d60594111ebc075bbd60d3e8d1fcdcdb0f3c139 Mon Sep 17 00:00:00 2001 From: Eike Hein Date: Thu, 10 Mar 2016 02:54:59 +0900 Subject: [PATCH] Handle KIO URLs which proxy for local URLs in Icon applet. Dragging an app link .desktop file from Folder View showing desktop:/ from Folder View (but not Dolphin) to desktop/panel, spawning an Icon, was broken because: - KDirModel::metaData adds the UDS_LOCAL_PATH (local file) url as text/uri-list to the drag MIME data, but also the original desktop:/ URL as a second special MIME format for KDE URLs, using KUrlMimeData - Dolphin only does the first part, using a partial code copy from KDirModel - ContainmentInterface::processMimeData uses KUrlMimeData with default options to decode the drag MIME data - the default option is PreferKdeURLs, so it retrieves the desktop:/ URL from the FV drag but not the Dolphin drag (since it lacks it) - Thus the Icon applet is handed a desktop:/ URL in the FV case, which the code - not using KIO - isn't written to handle This patch adds an async KIO::StatJob to the Icon code when QURL::isLocalFile is fast to try and resolve an URL to a more local one the rest of the code can handle. Rewriting more of the Icon code to use KIO /would/ have been nice, however it ultimately ends up using KDesktopFile which can't handle non-local files, so at some point resolving to the proxied-for path would happen anyway. BUG:356548 --- applets/icon/plugin/icon_p.cpp | 18 ++++++++++++++++++ applets/icon/plugin/icon_p.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/applets/icon/plugin/icon_p.cpp b/applets/icon/plugin/icon_p.cpp index e3dbf788c..f09f61cce 100644 --- a/applets/icon/plugin/icon_p.cpp +++ b/applets/icon/plugin/icon_p.cpp @@ -38,6 +38,7 @@ #include #include +#include #include IconPrivate::IconPrivate() { @@ -47,6 +48,23 @@ IconPrivate::~IconPrivate() { } void IconPrivate::setUrl(const QUrl &url) +{ + if (url.isLocalFile()) { + setUrlInternal(url); + } else { + KIO::StatJob *statJob = KIO::mostLocalUrl(url, KIO::HideProgressInfo); + + connect(statJob, &KJob::result, [=](KJob *job) { + if (!job->error()) { + setUrlInternal(static_cast(job)->mostLocalUrl()); + } + }); + + statJob->start(); + } +} + +void IconPrivate::setUrlInternal(const QUrl &url) { m_url = url; diff --git a/applets/icon/plugin/icon_p.h b/applets/icon/plugin/icon_p.h index 5341330f4..1628dd99c 100644 --- a/applets/icon/plugin/icon_p.h +++ b/applets/icon/plugin/icon_p.h @@ -59,6 +59,8 @@ Q_SIGNALS: void jumpListActionsChanged(const QVariantList &jumpListActions); private: + void setUrlInternal(const QUrl &url); + QUrl m_url; QString m_name; QString m_icon;