From 4fbc5302e7a28dcc5e615a0e1234bf52f120ec7e Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Sun, 10 Jul 2022 15:42:13 +0200 Subject: [PATCH] Fix 'Show Target' for non-local URLs Links are not always local files, e.g. 'remote:/zeroconf' links to 'zeroconf:/' The current code fails there Instead of using QFile API that does not work on non-local URLs use QUrl::resolved to resolve relative links Furthermore, QFile::exists doesn't work for non-local URLs. Instead do a KIO stat to check whether the target exists --- src/dolphinmainwindow.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 4740b66e9..8372a2ac2 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -499,17 +499,20 @@ void DolphinMainWindow::openInNewWindow() void DolphinMainWindow::showTarget() { - const auto link = m_activeViewContainer->view()->selectedItems().at(0); - const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir(); - auto linkDestination = link.linkDest(); - if (QFileInfo(linkDestination).isRelative()) { - linkDestination = linkLocationDir.filePath(linkDestination); - } - if (QFileInfo::exists(linkDestination)) { - KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)}); - } else { - m_activeViewContainer->showMessage(xi18nc("@info", "Could not access %1.", linkDestination), DolphinViewContainer::Warning); - } + const KFileItem link = m_activeViewContainer->view()->selectedItems().at(0); + const QUrl destinationUrl = link.url().resolved(QUrl(link.linkDest())); + + auto job = KIO::statDetails(destinationUrl, KIO::StatJob::SourceSide, KIO::StatNoDetails); + + connect(job, &KJob::finished, this, [this, destinationUrl](KJob *job) { + KIO::StatJob *statJob = static_cast(job); + + if (statJob->error()) { + m_activeViewContainer->showMessage(job->errorString(), DolphinViewContainer::Error); + } else { + KIO::highlightInFileManager({destinationUrl}); + } + }); } void DolphinMainWindow::showEvent(QShowEvent *event) -- 2.47.3