From 9b83378c087a87cef537ba751b7713aff8bed84c Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 14 Sep 2020 16:01:47 +0200 Subject: [PATCH] Check protocol Class before creating a StatJob StatJob::mostLocalUrl only works with ":local" protocols, adjust the code accordingly. Make the code async. Remove activeContainerLocalPath() method as it isn't needed anymore. Drive-by change: minimum required version of Qt should be 5.12 because that's what KF >= 5.73 already requires. --- CMakeLists.txt | 2 +- src/dolphinmainwindow.cpp | 38 +++++++++++++++++++++++++------------- src/dolphinmainwindow.h | 6 ------ 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aaa9a7e7..5c1a08843 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set (RELEASE_SERVICE_VERSION_MICRO "70") set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}") project(Dolphin VERSION ${RELEASE_SERVICE_VERSION}) -set(QT_MIN_VERSION "5.11.0") +set(QT_MIN_VERSION "5.12.0") set(KF5_MIN_VERSION "5.73.0") # ECM setup diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 7c9a687aa..92d673a95 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -943,18 +943,6 @@ void DolphinMainWindow::toggleShowMenuBar() } } -QString DolphinMainWindow::activeContainerLocalPath() -{ - KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url()); - KJobWidgets::setWindow(statJob, this); - statJob->exec(); - QUrl url = statJob->mostLocalUrl(); - if (url.isLocalFile()) { - return url.toLocalFile(); - } - return QDir::homePath(); -} - QPointer DolphinMainWindow::preferredSearchTool() { m_searchTools.clear(); @@ -1001,7 +989,31 @@ void DolphinMainWindow::openPreferredSearchTool() void DolphinMainWindow::openTerminal() { - KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath()); + const QUrl url = m_activeViewContainer->url(); + + if (url.isLocalFile()) { + KToolInvocation::invokeTerminal(QString(), url.toLocalFile()); + return; + } + + // Not a local file, with protocol Class ":local", try stat'ing + if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) { + KIO::StatJob *job = KIO::mostLocalUrl(url); + KJobWidgets::setWindow(job, this); + connect(job, &KJob::result, this, [job]() { + QUrl statUrl; + if (!job->error()) { + statUrl = job->mostLocalUrl(); + } + + KToolInvocation::invokeTerminal(QString(), statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath()); + }); + + return; + } + + // Nothing worked, just use $HOME + KToolInvocation::invokeTerminal(QString(), QDir::homePath()); } void DolphinMainWindow::editSettings() diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 79084ae7d..c03eb1be0 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -592,12 +592,6 @@ private: /** Adds "What's This?" texts to many widgets and StandardActions. */ void setupWhatsThis(); - /** - * Returns the KIO::StatJob::mostLocalUrl() for the active container URL - * if it's a local file. Otherwise returns the user's home path. - */ - QString activeContainerLocalPath(); - /** Returns preferred search tool as configured in "More Search Tools" menu. */ QPointer preferredSearchTool(); -- 2.47.3