- // check to see if any instances already have any of the given URLs open
- for (const QString& url : QUrl::toStringList(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;
- }
- }
- if (!urlFound) {
- newUrls.append(url);
+QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> Dolphin::dolphinGuiInstances(const QString &preferredService)
+{
+#ifdef HAVE_KACTIVITIES
+ static std::once_flag one_consumer;
+ static KActivities::Consumer *consumer;
+ std::call_once(one_consumer, []() {
+ consumer = new KActivities::Consumer();
+ // ensures the consumer is ready for query
+ QEventLoop loop;
+ QObject::connect(consumer, &KActivities::Consumer::serviceStatusChanged, &loop, &QEventLoop::quit);
+ loop.exec();
+ });
+#endif
+
+ QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinInterfaces;
+ const auto tryAppendInterface = [&dolphinInterfaces](const QString &service) {
+ // Check if instance can handle our URLs
+ QSharedPointer<OrgKdeDolphinMainWindowInterface> interface(
+ new OrgKdeDolphinMainWindowInterface(service, QStringLiteral("/dolphin/Dolphin_1"), QDBusConnection::sessionBus()));
+ if (interface->isValid() && !interface->lastError().isValid()) {
+#ifdef HAVE_KACTIVITIES
+ const auto currentActivity = consumer->currentActivity();
+ if (currentActivity.isEmpty() || currentActivity == QStringLiteral("00000000-0000-0000-0000-000000000000")
+ || interface->isOnActivity(consumer->currentActivity()))
+#endif
+ if (interface->isOnCurrentDesktop()) {
+ dolphinInterfaces.append(qMakePair(interface, QStringList()));
+ }