]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/global.cpp
Merge branch 'Applications/19.08'
[dolphin.git] / src / global.cpp
index 73e154b3a035985203a05cc0fdd969b2b0b9c314..12f86a2f369ace55f2dc082acdee69a09f6e479c 100644 (file)
@@ -72,17 +72,11 @@ void Dolphin::openNewWindow(const QList<QUrl> &urls, QWidget *window, const Open
 
 bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService)
 {
-    if (KWindowSystem::isPlatformWayland()) {
-        // TODO: once Wayland clients can raise or activate themselves remove this conditional
+    // TODO: once Wayland clients can raise or activate themselves remove check from conditional
+    if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) {
         return false;
     }
 
-    const QStringList services = 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 = QStringLiteral("-") + QString::number(QCoreApplication::applicationPid());
     QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinServices;
     if (!preferredService.isEmpty()) {
         QSharedPointer<QDBusInterface> preferred(
@@ -90,12 +84,17 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
             QStringLiteral("/dolphin/Dolphin_1"),
             QStringLiteral("org.kde.dolphin.MainWindow"))
         );
-        if (preferred->isValid()) {
-            dolphinServices.append(qMakePair(preferred, QStringList() ));
+        if (preferred->isValid() && !preferred->lastError().isValid()) {
+            dolphinServices.append(qMakePair(preferred, QStringList()));
         }
     }
 
     // find all dolphin instances
+    const QStringList services = 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 = QStringLiteral("-") + QString::number(QCoreApplication::applicationPid());
     for (const QString& service : services) {
         if (service.startsWith(pattern) && !service.endsWith(myPid)) {
             // Check if instance can handle our URLs
@@ -104,10 +103,9 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
                 QStringLiteral("/dolphin/Dolphin_1"),
                 QStringLiteral("org.kde.dolphin.MainWindow"))
             );
-            if (!instance->isValid() || instance->lastError().isValid()) {
-                continue;
+            if (instance->isValid() && !instance->lastError().isValid()) {
+                dolphinServices.append(qMakePair(instance, QStringList()));
             }
-            dolphinServices.append(qMakePair(instance, QStringList()));
         }
     }
 
@@ -124,9 +122,9 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
         for (auto& service: dolphinServices) {
             QDBusReply<bool> isUrlOpen = service.first->call(QStringLiteral("isUrlOpen"), url);
             if (isUrlOpen.isValid() && isUrlOpen.value()) {
-                    service.second.append(url);
-                    urlFound = true;
-                    break;
+                service.second.append(url);
+                urlFound = true;
+                break;
             }
         }
         if (!urlFound) {