]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Port KRun to OpenUrlJob
authorAhmad Samir <a.samirh78@gmail.com>
Tue, 18 Aug 2020 08:43:58 +0000 (08:43 +0000)
committerDavid Faure <faure@kde.org>
Tue, 18 Aug 2020 08:43:58 +0000 (08:43 +0000)
In DolphinMainWindow, since KRun allows running executables by default, use
setRunExecutables(true) so as not to change the behaviour.

Remove the now redundant slotHandleUrlStatFinished, that whole StatJob
logic is now handled by OpenUrlJob.

Bump KF required version to 5.73, since that's where
OpenUrlJob::setShowOpenOrExecuteDialog was introduced.

CMakeLists.txt
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinviewcontainer.cpp

index f50f25102d0d9409c50ec72b42f2e5a6e1d9efde..5aaa9a7e73dd8c1d4b25f7c1d791cca925f8a46a 100644 (file)
@@ -8,7 +8,7 @@ set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE
 project(Dolphin VERSION ${RELEASE_SERVICE_VERSION})
 
 set(QT_MIN_VERSION "5.11.0")
-set(KF5_MIN_VERSION "5.71.0")
+set(KF5_MIN_VERSION "5.73.0")
 
 # ECM setup
 find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED)
index 5741e89439b9196980760392c5c7e8cd324e3cb4..0aafe3ad674a8d70bcf95cf5e8f40b5c50c9759c 100644 (file)
 #include <KIO/CommandLauncherJob>
 #include <KIO/JobUiDelegate>
 #include <KIO/OpenFileManagerWindowJob>
+#include <KIO/OpenUrlJob>
 #include <KJobWidgets>
 #include <KLocalizedString>
 #include <KMessageBox>
 #include <KNS3/KMoreToolsMenuFactory>
 #include <KProtocolInfo>
 #include <KProtocolManager>
-#include <KRun>
 #include <KShell>
 #include <KStandardAction>
 #include <KStartupInfo>
@@ -114,7 +114,7 @@ DolphinMainWindow::DolphinMainWindow() :
     m_bookmarkHandler(nullptr),
     m_controlButton(nullptr),
     m_updateToolBarTimer(nullptr),
-    m_lastHandleUrlStatJob(nullptr),
+    m_lastHandleUrlOpenJob(nullptr),
     m_terminalPanel(nullptr),
     m_placesPanel(nullptr),
     m_tearDownFromPlacesRequested(false),
@@ -1036,34 +1036,31 @@ void DolphinMainWindow::editSettings()
 
 void DolphinMainWindow::handleUrl(const QUrl& url)
 {
-    delete m_lastHandleUrlStatJob;
-    m_lastHandleUrlStatJob = nullptr;
+    delete m_lastHandleUrlOpenJob;
+    m_lastHandleUrlOpenJob = nullptr;
 
     if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
         activeViewContainer()->setUrl(url);
-    } else if (KProtocolManager::supportsListing(url)) {
-        // stat the URL to see if it is a dir or not
-        m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
-        if (m_lastHandleUrlStatJob->uiDelegate()) {
-            KJobWidgets::setWindow(m_lastHandleUrlStatJob, this);
-        }
-        connect(m_lastHandleUrlStatJob, &KIO::Job::result,
-                this, &DolphinMainWindow::slotHandleUrlStatFinished);
-
-    } else {
-        new KRun(url, this); // Automatically deletes itself after being finished
-    }
-}
-
-void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
-{
-    m_lastHandleUrlStatJob = nullptr;
-    const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
-    const QUrl url = static_cast<KIO::StatJob*>(job)->url();
-    if (entry.isDir()) {
-        activeViewContainer()->setUrl(url);
     } else {
-        new KRun(url, this);  // Automatically deletes itself after being finished
+        m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
+        m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
+        m_lastHandleUrlOpenJob->setRunExecutables(true);
+
+        connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this,
+                [this, url](const QString &mimetype) {
+                    if (mimetype == QLatin1String("inode/directory")) {
+                        // If it's a dir, we'll take it from here
+                        m_lastHandleUrlOpenJob->kill();
+                        m_lastHandleUrlOpenJob = nullptr;
+                        activeViewContainer()->setUrl(url);
+                    }
+        });
+
+        connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() {
+            m_lastHandleUrlOpenJob = nullptr;
+        });
+
+        m_lastHandleUrlOpenJob->start();
     }
 }
 
index 9c36c98b2eda85cdbf6e88eb05f0101d1d9f05af..59e0afa3121ca31153236753d028a530eb007c18 100644 (file)
@@ -54,6 +54,10 @@ class QIcon;
 class PlacesPanel;
 class TerminalPanel;
 
+namespace KIO {
+    class OpenUrlJob;
+}
+
 /**
  * @short Main window for Dolphin.
  *
@@ -432,12 +436,6 @@ private slots:
      */
     void handleUrl(const QUrl& url);
 
-    /**
-     * handleUrl() can trigger a stat job to see if the url can actually
-     * be listed.
-     */
-    void slotHandleUrlStatFinished(KJob* job);
-
     /**
      * Is invoked when the write state of a folder has been changed and
      * enables/disables the "Create New..." menu entry.
@@ -644,7 +642,7 @@ private:
     QToolButton* m_controlButton;
     QTimer* m_updateToolBarTimer;
 
-    KIO::Job* m_lastHandleUrlStatJob;
+    KIO::OpenUrlJob *m_lastHandleUrlOpenJob;
 
     TerminalPanel* m_terminalPanel;
     PlacesPanel* m_placesPanel;
index 4ab34a06a85ef1632c6bdd8ed499489a1e03023b..7809ca7e3fa07f764c932985187efc20d5d4c6ab 100644 (file)
 #include <KFileItemActions>
 #include <KFilePlacesModel>
 #include <KIO/PreviewJob>
+#include <KIO/OpenUrlJob>
+#include <KIO/JobUiDelegate>
 #include <KLocalizedString>
 #include <KMessageWidget>
 #include <KProtocolManager>
-#include <KRun>
 #include <KShell>
 #include <KUrlComboBox>
 #include <KUrlNavigator>
@@ -645,8 +646,10 @@ void DolphinViewContainer::slotItemActivated(const KFileItem& item)
         return;
     }
 
-    KRun *run = new KRun(item.targetUrl(), this);
-    run->setShowScriptExecutionPrompt(true);
+    KIO::OpenUrlJob *job = new KIO::OpenUrlJob(item.targetUrl());
+    job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
+    job->setShowOpenOrExecuteDialog(true);
+    job->start();
 }
 
 void DolphinViewContainer::slotItemsActivated(const KFileItemList& items)