┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorElvis Angelaccio <[email protected]>2020-03-16 23:01:54 +0100
committerElvis Angelaccio <[email protected]>2020-03-16 23:01:54 +0100
commitb65c5c3bc2f34e285d24af08248b409a23a2f723 (patch)
treee7dbd64f775c212d76b6acbcf1d66f42f7624298 /src
parent158d12ac37d27023cabf86d165630ec0c9309d4b (diff)
parent869b8d7e303b318d7370309d6caa82a0ba8056bf (diff)
Merge branch 'release/20.04'
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/dbusinterface.cpp14
-rw-r--r--src/dbusinterface.h13
-rw-r--r--src/dolphinmainwindow.cpp4
-rw-r--r--src/global.cpp40
-rw-r--r--src/global.h4
-rw-r--r--src/main.cpp1
7 files changed, 59 insertions, 21 deletions
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/dbusinterface.cpp b/src/dbusinterface.cpp
index fd2d229a2..abdb3a0fe 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 baf804f68..391916d62 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/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 9aff25b26..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 <KRun>
#include <KWindowSystem>
#include <QApplication>
#include <QIcon>
-#include <QDBusInterface>
-#include <QDBusConnectionInterface>
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 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<QPair<QSharedPointer<QDBusInterface>, QStringList>> dolphinInterfaces;
+ QVector<QPair<QSharedPointer<OrgKdeDolphinMainWindowInterface>, QStringList>> dolphinInterfaces;
if (!preferredService.isEmpty()) {
- QSharedPointer<QDBusInterface> preferredInterface(
- new QDBusInterface(preferredService,
- QStringLiteral("/dolphin/Dolphin_1"),
- QString()) // #414402: use empty interface name to prevent QtDBus from caching the interface.
- );
+ QSharedPointer<OrgKdeDolphinMainWindowInterface> 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<QUrl>& inputUrls, bool openFi
for (const QString& service : dbusServices) {
if (service.startsWith(pattern) && !service.endsWith(myPid)) {
// Check if instance can handle our URLs
- QSharedPointer<QDBusInterface> interface(
- new QDBusInterface(service,
- QStringLiteral("/dolphin/Dolphin_1"),
- QStringLiteral("org.kde.dolphin.MainWindow"))
- );
+ QSharedPointer<OrgKdeDolphinMainWindowInterface> 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<QUrl>& inputUrls, bool openFi
for (const QString& url : urls) {
bool urlFound = false;
for (auto& interface: dolphinInterfaces) {
- QDBusReply<bool> 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<QUrl>& 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;
}
diff --git a/src/global.h b/src/global.h
index f203615f1..7ee564581 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<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService = QString());
diff --git a/src/main.cpp b/src/main.cpp
index 2b2674f9d..5932df5ce 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();
}