]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Check protocol Class before creating a StatJob
authorAhmad Samir <a.samirh78@gmail.com>
Mon, 14 Sep 2020 14:01:47 +0000 (16:01 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 20 Sep 2020 21:29:23 +0000 (21:29 +0000)
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
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h

index 5aaa9a7e73dd8c1d4b25f7c1d791cca925f8a46a..5c1a08843194070421c6a55668b06785cfa617f9 100644 (file)
@@ -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
index 7c9a687aa14cf29f7a709a7af7217cb5c83da38f..92d673a956b067c7aa881d468bfb0279d9a2c7e4 100644 (file)
@@ -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<QAction> 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()
index 79084ae7dc101df57deeec138469a454e7c2f1ab..c03eb1be07fb56454bd35962e6fb12db25eed7d7 100644 (file)
@@ -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<QAction> preferredSearchTool();