X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/27e3907a3daf9a63d05c00a0ff746de6cfdf2bdf..9c7e196bddd692032245c8f068495f318434169d:/src/global.cpp diff --git a/src/global.cpp b/src/global.cpp index e7ff67d77..3b81c536a 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -70,31 +70,31 @@ void Dolphin::openNewWindow(const QList &urls, QWidget *window, const Open ); } -bool Dolphin::attachToExistingInstance(const QList& urls, bool openFiles, bool splitView, const QString& preferredService) +bool Dolphin::attachToExistingInstance(const QList& 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, QStringList>> dolphinServices; if (!preferredService.isEmpty()) { QSharedPointer preferred( new QDBusInterface(preferredService, QStringLiteral("/dolphin/Dolphin_1"), - QStringLiteral("org.kde.dolphin.MainWindow")) + QString()) // #414402: use empty interface name to prevent QtDBus from caching the interface. ); - 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 = QLatin1Char('-') + 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& 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& 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 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) {