From 224028d931bf62f257cc6b2c4f7f51a1f42f4bd9 Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Mon, 23 Dec 2019 20:08:41 +0100 Subject: [PATCH] Rename variables to improve readability of Dolphin::attachToExistingInstance Services and interfaces are not the same thing. Also clarify the name of dbus replies. --- src/global.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/global.cpp b/src/global.cpp index 3b81c536ae..9aff25b26d 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -77,39 +77,39 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi return false; } - QVector, QStringList>> dolphinServices; + QVector, QStringList>> dolphinInterfaces; if (!preferredService.isEmpty()) { - QSharedPointer preferred( + QSharedPointer preferredInterface( new QDBusInterface(preferredService, QStringLiteral("/dolphin/Dolphin_1"), QString()) // #414402: use empty interface name to prevent QtDBus from caching the interface. ); - if (preferred->isValid() && !preferred->lastError().isValid()) { - dolphinServices.append(qMakePair(preferred, QStringList())); + if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) { + dolphinInterfaces.append(qMakePair(preferredInterface, QStringList())); } } - // find all dolphin instances - const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + // 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 : services) { + for (const QString& service : dbusServices) { if (service.startsWith(pattern) && !service.endsWith(myPid)) { // Check if instance can handle our URLs - QSharedPointer instance( + QSharedPointer interface( new QDBusInterface(service, QStringLiteral("/dolphin/Dolphin_1"), QStringLiteral("org.kde.dolphin.MainWindow")) ); - if (instance->isValid() && !instance->lastError().isValid()) { - dolphinServices.append(qMakePair(instance, QStringList())); + if (interface->isValid() && !interface->lastError().isValid()) { + dolphinInterfaces.append(qMakePair(interface, QStringList())); } } } - if (dolphinServices.isEmpty()) { + if (dolphinInterfaces.isEmpty()) { return false; } @@ -119,10 +119,10 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi 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); + for (auto& interface: dolphinInterfaces) { + QDBusReply isUrlOpenReply = interface.first->call(QStringLiteral("isUrlOpen"), url); + if (isUrlOpenReply.isValid() && isUrlOpenReply.value()) { + interface.second.append(url); urlFound = true; break; } @@ -131,12 +131,12 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi newUrls.append(url); } } - dolphinServices.front().second << newUrls; + dolphinInterfaces.front().second << newUrls; - for (const auto& service: dolphinServices) { - if (!service.second.isEmpty()) { - service.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), service.second, splitView); - service.first->call(QStringLiteral("activateWindow")); + 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")); } } return true;