From 312da848bcd62c165ccd1b7c0dde8d45a75c0c2e Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 6 Mar 2024 18:17:55 +0100 Subject: [PATCH 1/2] [gui] Add KGuiAddons as an optional dependency This will be needed to replace QClipboard in some places. Signed-off-by: Kevin Ottens --- src/gui/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 097e4df79..a921ea1a6 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,6 +1,7 @@ project(gui) find_package(Qt5 REQUIRED COMPONENTS Widgets Svg Qml Quick QuickControls2 QuickWidgets Xml Network) find_package(KF5Archive REQUIRED) +find_package(KF5GuiAddons) if(QUICK_COMPILER) find_package(Qt5QuickCompiler) @@ -563,6 +564,14 @@ target_link_libraries(nextcloudCore KF5::Archive ) +if(KF5GuiAddons_FOUND) + target_link_libraries(nextcloudCore + PUBLIC + KF5::GuiAddons + ) + add_definitions(-DHAVE_KGUIADDONS) +endif() + add_subdirectory(socketapi) # skip unity inclusion for files which cause problems with a CMake unity build From 526ab056d67b2f3220365e709b6f753d0dcb0979 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 6 Mar 2024 20:35:12 +0100 Subject: [PATCH 2/2] [socketapi] Replace QClipboard with KSystemClipboard when available This is necessary in Wayland sessions for the clipboard related actions of the socketapi to work. Indeed, QClipboard does its job only if we got a window with the focus in such session. In the case of the socketapi, it is generally the file manager asking the desktop client to put something in the clipboard. At this point in time no window of the client have the focus, so nothing gets added to the clipboard. KSystemClipboard on the other hand, uses the wlr data control protocol under wayland sessions ensuring something ends up in the clipboard as expected. When not in a wayland session it falls back to QClipboard so no behavior is lost. Signed-off-by: Kevin Ottens --- src/gui/socketapi/socketapi.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index 91219f974..69cd4127f 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -67,7 +67,6 @@ #include #include -#include #include #include @@ -77,6 +76,12 @@ #include #endif +#ifdef HAVE_KGUIADDONS +#include +#include +#else +#include +#endif // This is the version that is returned when the client asks for the VERSION. // The first number should be changed if there is an incompatible change that breaks old clients. @@ -194,6 +199,17 @@ static QString buildMessage(const QString &verb, const QString &path, const QStr } return msg; } + +void setClipboardText(const QString &text) +{ +#ifdef HAVE_KGUIADDONS + auto mimeData = new QMimeData(); + mimeData->setText(text); + KSystemClipboard::instance()->setMimeData(mimeData, QClipboard::Clipboard); +#else + QApplication::clipboard()->setText(text); +#endif +} } namespace OCC { @@ -902,7 +918,7 @@ void SocketApi::command_COPY_PUBLIC_LINK(const QString &localFile, SocketListene #ifdef Q_OS_WIN void SocketApi::command_COPYASPATH(const QString &localFile, SocketListener *) { - QApplication::clipboard()->setText(localFile); + setClipboardText(localFile); } void SocketApi::command_OPENNEWWINDOW(const QString &localFile, SocketListener *) @@ -995,7 +1011,7 @@ void SocketApi::command_MAKE_ONLINE_ONLY(const QString &filesArg, SocketListener void SocketApi::copyUrlToClipboard(const QString &link) { - QApplication::clipboard()->setText(link); + setClipboardText(link); } void SocketApi::command_RESOLVE_CONFLICT(const QString &localFile, SocketListener *)