diff --git a/src/dbusinterface.h b/src/dbusinterface.h --- a/src/dbusinterface.h +++ b/src/dbusinterface.h @@ -32,6 +32,19 @@ 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/dbusinterface.cpp b/src/dbusinterface.cpp --- a/src/dbusinterface.cpp +++ b/src/dbusinterface.cpp @@ -44,7 +44,7 @@ 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 @@ 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 @@ KPropertiesDialog::showDialog(urls); } } + +void DBusInterface::setAsDaemon() +{ + m_isDaemon = true; +} + +bool DBusInterface::isDaemon() const +{ + return m_isDaemon; +} diff --git a/src/global.h b/src/global.h --- a/src/global.h +++ b/src/global.h @@ -45,7 +45,9 @@ /** * 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/global.cpp b/src/global.cpp --- a/src/global.cpp +++ b/src/global.cpp @@ -82,7 +82,7 @@ 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/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -143,6 +143,7 @@ if (parser.isSet(QStringLiteral("daemon"))) { KDBusService dolphinDBusService; DBusInterface interface; + interface.setAsDaemon(); return app.exec(); }