From fa806d48dafec0c47141381740a5d7604293d32d Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Tue, 24 Dec 2019 18:28:26 +0100 Subject: 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/global.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/global.cpp') diff --git a/src/global.cpp b/src/global.cpp index 9aff25b26..34ed4e824 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())); -- cgit v1.3 From 869b8d7e303b318d7370309d6caa82a0ba8056bf Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Mon, 23 Dec 2019 11:06:54 +0100 Subject: Switch to generated MainWindow dbus interface Summary: This allows compile-time checks for the main window dbus methods. Test Plan: Same test plan as in D21691, D21666 and D25510. Reviewers: #dolphin Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D26214 --- src/CMakeLists.txt | 4 ++++ src/dolphinmainwindow.cpp | 4 ++++ src/global.cpp | 40 ++++++++++++++++++++++------------------ 3 files changed, 30 insertions(+), 18 deletions(-) (limited to 'src/global.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e8d623d2f..02a43a209 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -269,6 +269,10 @@ kconfig_add_kcfg_files(dolphinstatic_SRCS GENERATE_MOC qt5_add_resources(dolphinstatic_SRCS dolphin.qrc) +qt5_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/dolphinmainwindow.h org.kde.DolphinMainWindow.xml) +qt5_add_dbus_adaptor(dolphinstatic_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.DolphinMainWindow.xml dolphinmainwindow.h DolphinMainWindow) +qt5_add_dbus_interface(dolphinstatic_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.DolphinMainWindow.xml dolphinmainwindowinterface) + add_library(dolphinstatic STATIC ${dolphinstatic_SRCS}) target_include_directories(dolphinstatic SYSTEM PRIVATE ${PHONON_INCLUDES}) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 399901688..f88bc3f44 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -21,6 +21,7 @@ #include "dolphinmainwindow.h" +#include "dolphinmainwindowadaptor.h" #include "config-terminal.h" #include "global.h" #include "dolphinbookmarkhandler.h" @@ -118,6 +119,9 @@ DolphinMainWindow::DolphinMainWindow() : m_forwardAction(nullptr) { Q_INIT_RESOURCE(dolphin); + + new MainWindowAdaptor(this); + #ifndef Q_OS_WIN setWindowFlags(Qt::WindowContextHelpButtonHint); #endif diff --git a/src/global.cpp b/src/global.cpp index 34ed4e824..5236fa4d1 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -21,14 +21,13 @@ #include "dolphin_generalsettings.h" #include "dolphindebug.h" +#include "dolphinmainwindowinterface.h" #include #include #include #include -#include -#include QList Dolphin::validateUris(const QStringList& uriList) { @@ -72,18 +71,19 @@ void Dolphin::openNewWindow(const QList &urls, QWidget *window, const Open bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFiles, bool splitView, const QString& preferredService) { + bool attached = false; + // TODO: once Wayland clients can raise or activate themselves remove check from conditional if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) { return false; } - QVector, QStringList>> dolphinInterfaces; + QVector, QStringList>> dolphinInterfaces; if (!preferredService.isEmpty()) { - QSharedPointer preferredInterface( - new QDBusInterface(preferredService, - QStringLiteral("/dolphin/Dolphin_1"), - QStringLiteral("org.kde.dolphin.MainWindow")) - ); + QSharedPointer preferredInterface( + new OrgKdeDolphinMainWindowInterface(preferredService, + QStringLiteral("/dolphin/Dolphin_1"), + QDBusConnection::sessionBus())); if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) { dolphinInterfaces.append(qMakePair(preferredInterface, QStringList())); } @@ -98,11 +98,10 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi for (const QString& service : dbusServices) { if (service.startsWith(pattern) && !service.endsWith(myPid)) { // Check if instance can handle our URLs - QSharedPointer interface( - new QDBusInterface(service, - QStringLiteral("/dolphin/Dolphin_1"), - QStringLiteral("org.kde.dolphin.MainWindow")) - ); + QSharedPointer interface( + new OrgKdeDolphinMainWindowInterface(service, + QStringLiteral("/dolphin/Dolphin_1"), + QDBusConnection::sessionBus())); if (interface->isValid() && !interface->lastError().isValid()) { dolphinInterfaces.append(qMakePair(interface, QStringList())); } @@ -120,8 +119,9 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi for (const QString& url : urls) { bool urlFound = false; for (auto& interface: dolphinInterfaces) { - QDBusReply isUrlOpenReply = interface.first->call(QStringLiteral("isUrlOpen"), url); - if (isUrlOpenReply.isValid() && isUrlOpenReply.value()) { + auto isUrlOpenReply = interface.first->isUrlOpen(url); + isUrlOpenReply.waitForFinished(); + if (!isUrlOpenReply.isError() && isUrlOpenReply.value()) { interface.second.append(url); urlFound = true; break; @@ -135,9 +135,13 @@ bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFi for (const auto& interface: dolphinInterfaces) { if (!interface.second.isEmpty()) { - interface.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), interface.second, splitView); - interface.first->call(QStringLiteral("activateWindow")); + auto reply = openFiles ? interface.first->openFiles(interface.second, splitView) : interface.first->openDirectories(interface.second, splitView); + reply.waitForFinished(); + if (!reply.isError()) { + interface.first->activateWindow(); + attached = true; + } } } - return true; + return attached; } -- cgit v1.3