- 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(
- new QDBusInterface(preferredService,
- QStringLiteral("/dolphin/Dolphin_1"),
- QStringLiteral("org.kde.dolphin.MainWindow"))
- );
- if (preferred->isValid()) {
- dolphinServices.append(qMakePair(preferred, QStringList() ));
- }
- }
-
- // find all dolphin instances
- for (const QString& service : services) {
- if (service.startsWith(pattern) && !service.endsWith(myPid)) {
- // Check if instance can handle our URLs
- QSharedPointer<QDBusInterface> instance(
- new QDBusInterface(service,
- QStringLiteral("/dolphin/Dolphin_1"),
- QStringLiteral("org.kde.dolphin.MainWindow"))
- );
- if (!instance->isValid() || instance->lastError().isValid()) {
- continue;
- }
- dolphinServices.append(qMakePair(instance, QStringList()));
- }
- }
-
- if (dolphinServices.isEmpty()) {