Skip to content

Commit

Permalink
Merge pull request #6515 from nextcloud/work/ervin/socketapi-use-ksys…
Browse files Browse the repository at this point in the history
…temclipboard-when-available

[socketapi] Replace QClipboard with KSystemClipboard when available
  • Loading branch information
mgallien authored Mar 7, 2024
2 parents 0e301e7 + 526ab05 commit ffffc89
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
22 changes: 19 additions & 3 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
#include <QJsonObject>
#include <QWidget>

#include <QClipboard>
#include <QDesktopServices>

#include <QProcess>
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 *)
Expand Down Expand Up @@ -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 *)
Expand Down

0 comments on commit ffffc89

Please sign in to comment.