]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Exclude daemonized processes from Dolphin::attachToExistingInstance()
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Tue, 24 Dec 2019 17:28:26 +0000 (18:28 +0100)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Mon, 16 Mar 2020 21:38:40 +0000 (22:38 +0100)
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
src/dbusinterface.h
src/global.cpp
src/global.h
src/main.cpp

index fd2d229a29b91257720be8934b1d89daa840e886..abdb3a0fefdee27308bc64788755790e28c91e30 100644 (file)
@@ -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;
+}
index baf804f68af111a70dfdcbf1fa489670c057b22a..391916d6271998150ed9566aa27bc12eeec6b708 100644 (file)
@@ -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
index 9aff25b26d6fc36ea984ff508ac4e23c87473b4a..34ed4e824b971cd0a4177b4788bddd893f06b20e 100644 (file)
@@ -82,7 +82,7 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
         QSharedPointer<QDBusInterface> 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()));
index f203615f1d82bd985f87e21ce803e388fefc11b5..7ee564581c6b7b1ff14e71610489ec7e0d8817db 100644 (file)
@@ -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<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService = QString());
 
index 2b2674f9d97dceb34f9e8f8ae24f3be40cd61da4..5932df5ce0b66426e99ecc5d2f622e1cc4bb70bb 100644 (file)
@@ -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();
     }