]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/global.cpp
Fix clazy-range-loop warning
[dolphin.git] / src / global.cpp
index 5236fa4d102a9086367bfa61d62dd9eaafff3331..6a702cf43bacf08cd981b1f90f0012a19f1d3400 100644 (file)
@@ -23,7 +23,9 @@
 #include "dolphindebug.h"
 #include "dolphinmainwindowinterface.h"
 
 #include "dolphindebug.h"
 #include "dolphinmainwindowinterface.h"
 
-#include <KRun>
+#include <KDialogJobUiDelegate>
+#include <KIO/ApplicationLauncherJob>
+#include <KService>
 #include <KWindowSystem>
 
 #include <QApplication>
 #include <KWindowSystem>
 
 #include <QApplication>
@@ -60,13 +62,11 @@ void Dolphin::openNewWindow(const QList<QUrl> &urls, QWidget *window, const Open
     if (!urls.isEmpty()) {
         command.append(QLatin1String(" %U"));
     }
     if (!urls.isEmpty()) {
         command.append(QLatin1String(" %U"));
     }
-    KRun::run(
-        command,
-        urls,
-        window,
-        QApplication::applicationDisplayName(),
-        QApplication::windowIcon().name()
-    );
+    KService::Ptr service(new KService(QApplication::applicationDisplayName(), command, QApplication::windowIcon().name()));
+    auto *job = new KIO::ApplicationLauncherJob(service, window);
+    job->setUrls(urls);
+    job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, window));
+    job->start();
 }
 
 bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService)
 }
 
 bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService)
@@ -78,36 +78,7 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
         return false;
     }
 
         return false;
     }
 
-    QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinInterfaces;
-    if (!preferredService.isEmpty()) {
-        QSharedPointer<OrgKdeDolphinMainWindowInterface> preferredInterface(
-            new OrgKdeDolphinMainWindowInterface(preferredService,
-                QStringLiteral("/dolphin/Dolphin_1"),
-                QDBusConnection::sessionBus()));
-        if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) {
-            dolphinInterfaces.append(qMakePair(preferredInterface, QStringList()));
-        }
-    }
-
-    // Look for dolphin instances among all available dbus services.
-    const QStringList dbusServices = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
-    // Don't match the service without trailing "-" (unique instance)
-    const QString pattern = QStringLiteral("org.kde.dolphin-");
-    // Don't match the pid without leading "-"
-    const QString myPid = QLatin1Char('-') + QString::number(QCoreApplication::applicationPid());
-    for (const QString& service : dbusServices) {
-        if (service.startsWith(pattern) && !service.endsWith(myPid)) {
-            // Check if instance can handle our URLs
-            QSharedPointer<OrgKdeDolphinMainWindowInterface> interface(
-                        new OrgKdeDolphinMainWindowInterface(service,
-                            QStringLiteral("/dolphin/Dolphin_1"),
-                            QDBusConnection::sessionBus()));
-            if (interface->isValid() && !interface->lastError().isValid()) {
-                dolphinInterfaces.append(qMakePair(interface, QStringList()));
-            }
-        }
-    }
-
+    auto dolphinInterfaces = dolphinGuiInstances(preferredService);
     if (dolphinInterfaces.isEmpty()) {
         return false;
     }
     if (dolphinInterfaces.isEmpty()) {
         return false;
     }
@@ -133,7 +104,7 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
     }
     dolphinInterfaces.front().second << newUrls;
 
     }
     dolphinInterfaces.front().second << newUrls;
 
-    for (const auto& interface: dolphinInterfaces) {
+    for (const auto& interface: qAsConst(dolphinInterfaces)) {
         if (!interface.second.isEmpty()) {
             auto reply = openFiles ? interface.first->openFiles(interface.second, splitView) : interface.first->openDirectories(interface.second, splitView);
             reply.waitForFinished();
         if (!interface.second.isEmpty()) {
             auto reply = openFiles ? interface.first->openFiles(interface.second, splitView) : interface.first->openDirectories(interface.second, splitView);
             reply.waitForFinished();
@@ -145,3 +116,38 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
     }
     return attached;
 }
     }
     return attached;
 }
+
+QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> Dolphin::dolphinGuiInstances(const QString& preferredService)
+{
+    QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinInterfaces;
+    if (!preferredService.isEmpty()) {
+        QSharedPointer<OrgKdeDolphinMainWindowInterface> preferredInterface(
+            new OrgKdeDolphinMainWindowInterface(preferredService,
+                QStringLiteral("/dolphin/Dolphin_1"),
+                QDBusConnection::sessionBus()));
+        if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) {
+            dolphinInterfaces.append(qMakePair(preferredInterface, QStringList()));
+        }
+    }
+
+    // Look for dolphin instances among all available dbus services.
+    const QStringList dbusServices = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
+    // Don't match the service without trailing "-" (unique instance)
+    const QString pattern = QStringLiteral("org.kde.dolphin-");
+    // Don't match the pid without leading "-"
+    const QString myPid = QLatin1Char('-') + QString::number(QCoreApplication::applicationPid());
+    for (const QString& service : dbusServices) {
+        if (service.startsWith(pattern) && !service.endsWith(myPid)) {
+            // Check if instance can handle our URLs
+            QSharedPointer<OrgKdeDolphinMainWindowInterface> interface(
+                        new OrgKdeDolphinMainWindowInterface(service,
+                            QStringLiteral("/dolphin/Dolphin_1"),
+                            QDBusConnection::sessionBus()));
+            if (interface->isValid() && !interface->lastError().isValid()) {
+                dolphinInterfaces.append(qMakePair(interface, QStringList()));
+            }
+        }
+    }
+
+    return dolphinInterfaces;
+}