Merge pull request #6515 from nextcloud/work/ervin/socketapi-use-ksystemclipboard-when-available

[socketapi] Replace QClipboard with KSystemClipboard when available
This commit is contained in:
Matthieu Gallien 2024-03-07 08:51:22 +01:00 committed by GitHub
commit ffffc89414
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View file

@ -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

View file

@ -67,7 +67,6 @@
#include <QJsonObject>
#include <QWidget>
#include <QClipboard>
#include <QDesktopServices>
#include <QProcess>
@ -77,6 +76,12 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
#ifdef HAVE_KGUIADDONS
#include <QMimeData>
#include <KSystemClipboard>
#else
#include <QClipboard>
#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 *)