Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[socketapi] Replace QClipboard with KSystemClipboard when available #6515

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/socketapi/socketapi.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/socketapi/socketapi.cpp

File src/gui/socketapi/socketapi.cpp does not conform to Custom style guidelines. (lines 80)
* Copyright (C) by Dominik Schmidt <[email protected]>
* Copyright (C) by Klaas Freitag <[email protected]>
* Copyright (C) by Roeland Jago Douma <[email protected]>
Expand Down 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 @@
}
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 @@
#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::copyUrlToClipboard(const QString &link)
{
QApplication::clipboard()->setText(link);
setClipboardText(link);
}

void SocketApi::command_RESOLVE_CONFLICT(const QString &localFile, SocketListener *)
Expand Down
Loading