mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-23 12:55:44 +03:00
[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 <ervin@kde.org>
This commit is contained in:
parent
312da848bc
commit
526ab056d6
1 changed files with 19 additions and 3 deletions
|
@ -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 *)
|
||||
|
|
Loading…
Reference in a new issue