]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/global.cpp
Match style of if() condition used above
[dolphin.git] / src / global.cpp
index e7ff67d776578cfa88368e1177b99b1e94c77b91..12f86a2f369ace55f2dc082acdee69a09f6e479c 100644 (file)
@@ -70,18 +70,13 @@ void Dolphin::openNewWindow(const QList<QUrl> &urls, QWidget *window, const Open
     );
 }
 
-bool Dolphin::attachToExistingInstance(const QList<QUrl>& urls, bool openFiles, bool splitView, const QString& preferredService)
+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-");
-    const QString myPid = QString::number(QCoreApplication::applicationPid());
     QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinServices;
     if (!preferredService.isEmpty()) {
         QSharedPointer<QDBusInterface> preferred(
@@ -89,12 +84,17 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& urls, bool openFiles,
             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
@@ -103,10 +103,9 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& urls, bool openFiles,
                 QStringLiteral("/dolphin/Dolphin_1"),
                 QStringLiteral("org.kde.dolphin.MainWindow"))
             );
-            if (!instance->isValid()) {
-                continue;
+            if (instance->isValid() && !instance->lastError().isValid()) {
+                dolphinServices.append(qMakePair(instance, QStringList()));
             }
-            dolphinServices.append(qMakePair(instance, QStringList()));
         }
     }
 
@@ -117,14 +116,15 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& urls, bool openFiles,
     QStringList newUrls;
 
     // check to see if any instances already have any of the given URLs open
-    for (const QString& url : QUrl::toStringList(urls)) {
+    const auto urls = QUrl::toStringList(inputUrls);
+    for (const QString& url : urls) {
         bool urlFound = false;
         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) {