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
This commit is contained in:
Elvis Angelaccio 2019-12-23 11:06:54 +01:00
parent fa806d48da
commit 869b8d7e30
3 changed files with 30 additions and 18 deletions

View file

@ -269,6 +269,10 @@ kconfig_add_kcfg_files(dolphinstatic_SRCS GENERATE_MOC
qt5_add_resources(dolphinstatic_SRCS dolphin.qrc) 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}) add_library(dolphinstatic STATIC ${dolphinstatic_SRCS})
target_include_directories(dolphinstatic SYSTEM PRIVATE ${PHONON_INCLUDES}) target_include_directories(dolphinstatic SYSTEM PRIVATE ${PHONON_INCLUDES})

View file

@ -21,6 +21,7 @@
#include "dolphinmainwindow.h" #include "dolphinmainwindow.h"
#include "dolphinmainwindowadaptor.h"
#include "config-terminal.h" #include "config-terminal.h"
#include "global.h" #include "global.h"
#include "dolphinbookmarkhandler.h" #include "dolphinbookmarkhandler.h"
@ -118,6 +119,9 @@ DolphinMainWindow::DolphinMainWindow() :
m_forwardAction(nullptr) m_forwardAction(nullptr)
{ {
Q_INIT_RESOURCE(dolphin); Q_INIT_RESOURCE(dolphin);
new MainWindowAdaptor(this);
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
setWindowFlags(Qt::WindowContextHelpButtonHint); setWindowFlags(Qt::WindowContextHelpButtonHint);
#endif #endif

View file

@ -21,14 +21,13 @@
#include "dolphin_generalsettings.h" #include "dolphin_generalsettings.h"
#include "dolphindebug.h" #include "dolphindebug.h"
#include "dolphinmainwindowinterface.h"
#include <KRun> #include <KRun>
#include <KWindowSystem> #include <KWindowSystem>
#include <QApplication> #include <QApplication>
#include <QIcon> #include <QIcon>
#include <QDBusInterface>
#include <QDBusConnectionInterface>
QList<QUrl> Dolphin::validateUris(const QStringList& uriList) QList<QUrl> Dolphin::validateUris(const QStringList& uriList)
{ {
@ -72,18 +71,19 @@ void Dolphin::openNewWindow(const QList<QUrl> &urls, QWidget *window, const Open
bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService) bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService)
{ {
bool attached = false;
// TODO: once Wayland clients can raise or activate themselves remove check from conditional // TODO: once Wayland clients can raise or activate themselves remove check from conditional
if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) { if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) {
return false; return false;
} }
QVector<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinInterfaces; QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinInterfaces;
if (!preferredService.isEmpty()) { if (!preferredService.isEmpty()) {
QSharedPointer<QDBusInterface> preferredInterface( QSharedPointer<OrgKdeDolphinMainWindowInterface> preferredInterface(
new QDBusInterface(preferredService, new OrgKdeDolphinMainWindowInterface(preferredService,
QStringLiteral("/dolphin/Dolphin_1"), QStringLiteral("/dolphin/Dolphin_1"),
QStringLiteral("org.kde.dolphin.MainWindow")) QDBusConnection::sessionBus()));
);
if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) { if (preferredInterface->isValid() && !preferredInterface->lastError().isValid()) {
dolphinInterfaces.append(qMakePair(preferredInterface, QStringList())); dolphinInterfaces.append(qMakePair(preferredInterface, QStringList()));
} }
@ -98,11 +98,10 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
for (const QString& service : dbusServices) { for (const QString& service : dbusServices) {
if (service.startsWith(pattern) && !service.endsWith(myPid)) { if (service.startsWith(pattern) && !service.endsWith(myPid)) {
// Check if instance can handle our URLs // Check if instance can handle our URLs
QSharedPointer<QDBusInterface> interface( QSharedPointer<OrgKdeDolphinMainWindowInterface> interface(
new QDBusInterface(service, new OrgKdeDolphinMainWindowInterface(service,
QStringLiteral("/dolphin/Dolphin_1"), QStringLiteral("/dolphin/Dolphin_1"),
QStringLiteral("org.kde.dolphin.MainWindow")) QDBusConnection::sessionBus()));
);
if (interface->isValid() && !interface->lastError().isValid()) { if (interface->isValid() && !interface->lastError().isValid()) {
dolphinInterfaces.append(qMakePair(interface, QStringList())); dolphinInterfaces.append(qMakePair(interface, QStringList()));
} }
@ -120,8 +119,9 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
for (const QString& url : urls) { for (const QString& url : urls) {
bool urlFound = false; bool urlFound = false;
for (auto& interface: dolphinInterfaces) { for (auto& interface: dolphinInterfaces) {
QDBusReply<bool> isUrlOpenReply = interface.first->call(QStringLiteral("isUrlOpen"), url); auto isUrlOpenReply = interface.first->isUrlOpen(url);
if (isUrlOpenReply.isValid() && isUrlOpenReply.value()) { isUrlOpenReply.waitForFinished();
if (!isUrlOpenReply.isError() && isUrlOpenReply.value()) {
interface.second.append(url); interface.second.append(url);
urlFound = true; urlFound = true;
break; break;
@ -135,9 +135,13 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
for (const auto& interface: dolphinInterfaces) { for (const auto& interface: dolphinInterfaces) {
if (!interface.second.isEmpty()) { if (!interface.second.isEmpty()) {
interface.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), interface.second, splitView); auto reply = openFiles ? interface.first->openFiles(interface.second, splitView) : interface.first->openDirectories(interface.second, splitView);
interface.first->call(QStringLiteral("activateWindow")); reply.waitForFinished();
if (!reply.isError()) {
interface.first->activateWindow();
attached = true;
}
} }
} }
return true; return attached;
} }