]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/global.cpp
Port KRun::run usage to run another Dolphin process, to ApplicationLauncherJob
[dolphin.git] / src / global.cpp
index 9aff25b26d6fc36ea984ff508ac4e23c87473b4a..19f43e06b04c5dcac9bfad6e755c579b57da4f55 100644 (file)
 
 #include "dolphin_generalsettings.h"
 #include "dolphindebug.h"
+#include "dolphinmainwindowinterface.h"
 
-#include <KRun>
+#include <KDialogJobUiDelegate>
+#include <KIO/ApplicationLauncherJob>
+#include <KService>
 #include <KWindowSystem>
 
 #include <QApplication>
 #include <QIcon>
-#include <QDBusInterface>
-#include <QDBusConnectionInterface>
 
 QList<QUrl> Dolphin::validateUris(const QStringList& uriList)
 {
@@ -61,29 +62,28 @@ void Dolphin::openNewWindow(const QList<QUrl> &urls, QWidget *window, const Open
     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 attached = false;
+
     // TODO: once Wayland clients can raise or activate themselves remove check from conditional
     if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) {
         return false;
     }
 
-    QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinInterfaces;
+    QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinInterfaces;
     if (!preferredService.isEmpty()) {
-        QSharedPointer<QDBusInterface> preferredInterface(
-            new QDBusInterface(preferredService,
-            QStringLiteral("/dolphin/Dolphin_1"),
-            QString()) // #414402: use empty interface name to prevent QtDBus from caching the interface.
-        );
+        QSharedPointer<OrgKdeDolphinMainWindowInterface> preferredInterface(
+            new OrgKdeDolphinMainWindowInterface(preferredService,
+                QStringLiteral("/dolphin/Dolphin_1"),
+                QDBusConnection::sessionBus()));
         if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) {
             dolphinInterfaces.append(qMakePair(preferredInterface, QStringList()));
         }
@@ -98,11 +98,10 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
     for (const QString& service : dbusServices) {
         if (service.startsWith(pattern) && !service.endsWith(myPid)) {
             // Check if instance can handle our URLs
-            QSharedPointer<QDBusInterface> interface(
-                new QDBusInterface(service,
-                QStringLiteral("/dolphin/Dolphin_1"),
-                QStringLiteral("org.kde.dolphin.MainWindow"))
-            );
+            QSharedPointer<OrgKdeDolphinMainWindowInterface> interface(
+                        new OrgKdeDolphinMainWindowInterface(service,
+                            QStringLiteral("/dolphin/Dolphin_1"),
+                            QDBusConnection::sessionBus()));
             if (interface->isValid() && !interface->lastError().isValid()) {
                 dolphinInterfaces.append(qMakePair(interface, QStringList()));
             }
@@ -120,8 +119,9 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
     for (const QString& url : urls) {
         bool urlFound = false;
         for (auto& interface: dolphinInterfaces) {
-            QDBusReply<bool> isUrlOpenReply = interface.first->call(QStringLiteral("isUrlOpen"), url);
-            if (isUrlOpenReply.isValid() && isUrlOpenReply.value()) {
+            auto isUrlOpenReply = interface.first->isUrlOpen(url);
+            isUrlOpenReply.waitForFinished();
+            if (!isUrlOpenReply.isError() && isUrlOpenReply.value()) {
                 interface.second.append(url);
                 urlFound = true;
                 break;
@@ -135,9 +135,13 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
 
     for (const auto& interface: dolphinInterfaces) {
         if (!interface.second.isEmpty()) {
-            interface.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), interface.second, splitView);
-            interface.first->call(QStringLiteral("activateWindow"));
+            auto reply = openFiles ? interface.first->openFiles(interface.second, splitView) : interface.first->openDirectories(interface.second, splitView);
+            reply.waitForFinished();
+            if (!reply.isError()) {
+                interface.first->activateWindow();
+                attached = true;
+            }
         }
     }
-    return true;
+    return attached;
 }