X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/6c19e733673e24684707836fb2c9e0f45d1ac3f9..dec80fb0f940ff4e71032c2d3544f0d60a05c4ce:/src/global.cpp diff --git a/src/global.cpp b/src/global.cpp index d5fbec6bc..c68b2d2d0 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -16,14 +16,17 @@ #include #include #include +#if HAVE_KACTIVITIES +#include +#endif #include -QList Dolphin::validateUris(const QStringList& uriList) +QList Dolphin::validateUris(const QStringList &uriList) { const QString currentDir = QDir::currentPath(); QList urls; - for (const QString& str : uriList) { + for (const QString &str : uriList) { const QUrl url = QUrl::fromUserInput(str, currentDir, QUrl::AssumeLocalFile); if (url.isValid()) { urls.append(url); @@ -57,7 +60,11 @@ void Dolphin::openNewWindow(const QList &urls, QWidget *window, const Open job->start(); } -bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFiles, bool splitView, const QString& preferredService, const QString &activationToken) +bool Dolphin::attachToExistingInstance(const QList &inputUrls, + bool openFiles, + bool splitView, + const QString &preferredService, + const QString &activationToken) { bool attached = false; @@ -71,7 +78,7 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi } int activeWindowIndex = -1; - for (const auto& interface: qAsConst(dolphinInterfaces)) { + for (const auto &interface : qAsConst(dolphinInterfaces)) { ++activeWindowIndex; auto isActiveWindowReply = interface.first->isActiveWindow(); @@ -83,7 +90,7 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi // check to see if any instances already have any of the given URLs or their parents open QList newWindowURLs; - for (const QUrl& url : inputUrls) { + for (const QUrl &url : inputUrls) { bool urlFound = false; const QString urlString = url.toString(); @@ -101,8 +108,7 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi } i = (i + 1) % dolphinInterfaces.size(); - } - while (i != activeWindowIndex); + } while (i != activeWindowIndex); if (!urlFound) { if (GeneralSettings::openExternallyCalledFolderInNewTab()) { @@ -113,13 +119,11 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi } } - for (const auto& interface: qAsConst(dolphinInterfaces)) { + for (const auto &interface : qAsConst(dolphinInterfaces)) { if (interface.second.isEmpty()) { continue; } - auto reply = openFiles ? - interface.first->openFiles(interface.second, splitView) : - interface.first->openDirectories(interface.second, splitView); + auto reply = openFiles ? interface.first->openFiles(interface.second, splitView) : interface.first->openDirectories(interface.second, splitView); reply.waitForFinished(); if (!reply.isError()) { interface.first->activateWindow(activationToken); @@ -137,17 +141,41 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi return attached; } -QVector, QStringList>> Dolphin::dolphinGuiInstances(const QString& preferredService) +QVector, QStringList>> Dolphin::dolphinGuiInstances(const QString &preferredService) { +#if HAVE_KACTIVITIES + static std::once_flag one_consumer; + static KActivities::Consumer *consumer; + std::call_once(one_consumer, []() { + consumer = new KActivities::Consumer(); + // to prevent QGuiApplication::saveStateRequest + const QSignalBlocker blocker(qApp); + // ensures the consumer is ready for query + QEventLoop loop; + QObject::connect(consumer, &KActivities::Consumer::serviceStatusChanged, &loop, &QEventLoop::quit); + loop.exec(); + }); +#endif + QVector, QStringList>> dolphinInterfaces; - if (!preferredService.isEmpty()) { - QSharedPointer preferredInterface( - new OrgKdeDolphinMainWindowInterface(preferredService, - QStringLiteral("/dolphin/Dolphin_1"), - QDBusConnection::sessionBus())); - if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) { - dolphinInterfaces.append(qMakePair(preferredInterface, QStringList())); + const auto tryAppendInterface = [&dolphinInterfaces](const QString &service) { + // Check if instance can handle our URLs + QSharedPointer interface( + new OrgKdeDolphinMainWindowInterface(service, QStringLiteral("/dolphin/Dolphin_1"), QDBusConnection::sessionBus())); + if (interface->isValid() && !interface->lastError().isValid()) { +#if 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())); + } } + }; + + if (!preferredService.isEmpty()) { + tryAppendInterface(preferredService); } // Look for dolphin instances among all available dbus services. @@ -157,16 +185,9 @@ QVector, QStringList>> Do 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 : dbusServices) { + for (const QString &service : dbusServices) { if (service.startsWith(pattern) && !service.endsWith(myPid)) { - // Check if instance can handle our URLs - QSharedPointer interface( - new OrgKdeDolphinMainWindowInterface(service, - QStringLiteral("/dolphin/Dolphin_1"), - QDBusConnection::sessionBus())); - if (interface->isValid() && !interface->lastError().isValid()) { - dolphinInterfaces.append(qMakePair(interface, QStringList())); - } + tryAppendInterface(service); } } @@ -189,17 +210,14 @@ double GlobalConfig::animationDurationFactor() updateAnimationDurationFactor(kdeGlobalsConfig, {"AnimationDurationFactor"}); KConfigWatcher::Ptr configWatcher = KConfigWatcher::create(KSharedConfig::openConfig()); - connect(configWatcher.data(), &KConfigWatcher::configChanged, - &GlobalConfig::updateAnimationDurationFactor); + connect(configWatcher.data(), &KConfigWatcher::configChanged, &GlobalConfig::updateAnimationDurationFactor); return s_animationDurationFactor; } void GlobalConfig::updateAnimationDurationFactor(const KConfigGroup &group, const QByteArrayList &names) { - if (group.name() == QLatin1String("KDE") && - names.contains(QByteArrayLiteral("AnimationDurationFactor"))) { - s_animationDurationFactor = std::max(0.0, - group.readEntry("AnimationDurationFactor", 1.0)); + if (group.name() == QLatin1String("KDE") && names.contains(QByteArrayLiteral("AnimationDurationFactor"))) { + s_animationDurationFactor = std::max(0.0, group.readEntry("AnimationDurationFactor", 1.0)); } }