From fa806d48dafec0c47141381740a5d7604293d32d Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Tue, 24 Dec 2019 18:28:26 +0100 Subject: [PATCH] Exclude daemonized processes from Dolphin::attachToExistingInstance() Summary: `dolphin --daemon` does not have the `/dolphin/Dolphin_1` dbus path, because it doesn't have any DolphinMainWindow. Instead of working around this issue (as we did in D21666 and D25510), just exclude these processes from the list of dbus instances checked by `Dolphin::attachToExistingInstance()`. CCBUG: 408244 Test Plan: Same test plan as in D21666 and D25510 Reviewers: #dolphin Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D26213 --- src/dbusinterface.cpp | 14 ++++++++++++-- src/dbusinterface.h | 13 +++++++++++++ src/global.cpp | 2 +- src/global.h | 4 +++- src/main.cpp | 1 + 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/dbusinterface.cpp b/src/dbusinterface.cpp index fd2d229a29..abdb3a0fef 100644 --- a/src/dbusinterface.cpp +++ b/src/dbusinterface.cpp @@ -44,7 +44,7 @@ void DBusInterface::ShowFolders(const QStringList& uriList, const QString& start if (urls.isEmpty()) { return; } - const auto serviceName = QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid()); + const auto serviceName = isDaemon() ? QString() : QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid()); if(!Dolphin::attachToExistingInstance(urls, false, GeneralSettings::splitView(), serviceName)) { Dolphin::openNewWindow(urls); } @@ -57,7 +57,7 @@ void DBusInterface::ShowItems(const QStringList& uriList, const QString& startUp if (urls.isEmpty()) { return; } - const auto serviceName = QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid()); + const auto serviceName = isDaemon() ? QString() : QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid()); if(!Dolphin::attachToExistingInstance(urls, true, GeneralSettings::splitView(), serviceName)) { Dolphin::openNewWindow(urls, nullptr, Dolphin::OpenNewWindowFlag::Select); }; @@ -71,3 +71,13 @@ void DBusInterface::ShowItemProperties(const QStringList& uriList, const QString KPropertiesDialog::showDialog(urls); } } + +void DBusInterface::setAsDaemon() +{ + m_isDaemon = true; +} + +bool DBusInterface::isDaemon() const +{ + return m_isDaemon; +} diff --git a/src/dbusinterface.h b/src/dbusinterface.h index baf804f68a..391916d627 100644 --- a/src/dbusinterface.h +++ b/src/dbusinterface.h @@ -32,6 +32,19 @@ public: Q_SCRIPTABLE void ShowFolders(const QStringList& uriList, const QString& startUpId); Q_SCRIPTABLE void ShowItems(const QStringList& uriList, const QString& startUpId); Q_SCRIPTABLE void ShowItemProperties(const QStringList& uriList, const QString& startUpId); + + /** + * Set whether this interface has been created by dolphin --deamon. + */ + void setAsDaemon(); + + /** + * @return Whether this interface has been created by dolphin --deamon. + */ + bool isDaemon() const; + +private: + bool m_isDaemon = false; }; #endif // DBUSINTERFACE_H diff --git a/src/global.cpp b/src/global.cpp index 9aff25b26d..34ed4e824b 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -82,7 +82,7 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi QSharedPointer preferredInterface( new QDBusInterface(preferredService, QStringLiteral("/dolphin/Dolphin_1"), - QString()) // #414402: use empty interface name to prevent QtDBus from caching the interface. + QStringLiteral("org.kde.dolphin.MainWindow")) ); if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) { dolphinInterfaces.append(qMakePair(preferredInterface, QStringList())); diff --git a/src/global.h b/src/global.h index f203615f1d..7ee564581c 100644 --- a/src/global.h +++ b/src/global.h @@ -45,7 +45,9 @@ namespace Dolphin { /** * Attaches URLs to an existing Dolphin instance if possible. - * Returns true if URLs were successfully attached + * If @p preferredService is a valid dbus service, it will be tried first. + * @p preferredService needs to support the org.kde.dolphin.MainWindow dbus interface with the /dolphin/Dolphin_1 path. + * Returns true if the URLs were successfully attached. */ bool attachToExistingInstance(const QList& inputUrls, bool openFiles, bool splitView, const QString& preferredService = QString()); diff --git a/src/main.cpp b/src/main.cpp index 2b2674f9d9..5932df5ce0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -143,6 +143,7 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv) if (parser.isSet(QStringLiteral("daemon"))) { KDBusService dolphinDBusService; DBusInterface interface; + interface.setAsDaemon(); return app.exec(); }