mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Rename variables to improve readability of Dolphin::attachToExistingInstance
Services and interfaces are not the same thing. Also clarify the name of dbus replies.
This commit is contained in:
parent
151a17e048
commit
224028d931
|
@ -77,39 +77,39 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinServices;
|
QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinInterfaces;
|
||||||
if (!preferredService.isEmpty()) {
|
if (!preferredService.isEmpty()) {
|
||||||
QSharedPointer<QDBusInterface> preferred(
|
QSharedPointer<QDBusInterface> preferredInterface(
|
||||||
new QDBusInterface(preferredService,
|
new QDBusInterface(preferredService,
|
||||||
QStringLiteral("/dolphin/Dolphin_1"),
|
QStringLiteral("/dolphin/Dolphin_1"),
|
||||||
QString()) // #414402: use empty interface name to prevent QtDBus from caching the interface.
|
QString()) // #414402: use empty interface name to prevent QtDBus from caching the interface.
|
||||||
);
|
);
|
||||||
if (preferred->isValid() && !preferred->lastError().isValid()) {
|
if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) {
|
||||||
dolphinServices.append(qMakePair(preferred, QStringList()));
|
dolphinInterfaces.append(qMakePair(preferredInterface, QStringList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find all dolphin instances
|
// Look for dolphin instances among all available dbus services.
|
||||||
const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
|
const QStringList dbusServices = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
|
||||||
// Don't match the service without trailing "-" (unique instance)
|
// Don't match the service without trailing "-" (unique instance)
|
||||||
const QString pattern = QStringLiteral("org.kde.dolphin-");
|
const QString pattern = QStringLiteral("org.kde.dolphin-");
|
||||||
// Don't match the pid without leading "-"
|
// Don't match the pid without leading "-"
|
||||||
const QString myPid = QLatin1Char('-') + QString::number(QCoreApplication::applicationPid());
|
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)) {
|
if (service.startsWith(pattern) && !service.endsWith(myPid)) {
|
||||||
// Check if instance can handle our URLs
|
// Check if instance can handle our URLs
|
||||||
QSharedPointer<QDBusInterface> instance(
|
QSharedPointer<QDBusInterface> interface(
|
||||||
new QDBusInterface(service,
|
new QDBusInterface(service,
|
||||||
QStringLiteral("/dolphin/Dolphin_1"),
|
QStringLiteral("/dolphin/Dolphin_1"),
|
||||||
QStringLiteral("org.kde.dolphin.MainWindow"))
|
QStringLiteral("org.kde.dolphin.MainWindow"))
|
||||||
);
|
);
|
||||||
if (instance->isValid() && !instance->lastError().isValid()) {
|
if (interface->isValid() && !interface->lastError().isValid()) {
|
||||||
dolphinServices.append(qMakePair(instance, QStringList()));
|
dolphinInterfaces.append(qMakePair(interface, QStringList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dolphinServices.isEmpty()) {
|
if (dolphinInterfaces.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,10 +119,10 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
|
||||||
const auto urls = QUrl::toStringList(inputUrls);
|
const auto urls = QUrl::toStringList(inputUrls);
|
||||||
for (const QString& url : urls) {
|
for (const QString& url : urls) {
|
||||||
bool urlFound = false;
|
bool urlFound = false;
|
||||||
for (auto& service: dolphinServices) {
|
for (auto& interface: dolphinInterfaces) {
|
||||||
QDBusReply<bool> isUrlOpen = service.first->call(QStringLiteral("isUrlOpen"), url);
|
QDBusReply<bool> isUrlOpenReply = interface.first->call(QStringLiteral("isUrlOpen"), url);
|
||||||
if (isUrlOpen.isValid() && isUrlOpen.value()) {
|
if (isUrlOpenReply.isValid() && isUrlOpenReply.value()) {
|
||||||
service.second.append(url);
|
interface.second.append(url);
|
||||||
urlFound = true;
|
urlFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -131,12 +131,12 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
|
||||||
newUrls.append(url);
|
newUrls.append(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dolphinServices.front().second << newUrls;
|
dolphinInterfaces.front().second << newUrls;
|
||||||
|
|
||||||
for (const auto& service: dolphinServices) {
|
for (const auto& interface: dolphinInterfaces) {
|
||||||
if (!service.second.isEmpty()) {
|
if (!interface.second.isEmpty()) {
|
||||||
service.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), service.second, splitView);
|
interface.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), interface.second, splitView);
|
||||||
service.first->call(QStringLiteral("activateWindow"));
|
interface.first->call(QStringLiteral("activateWindow"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue