KGuiAddons

ksystemclipboard.cpp
1/*
2 SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "ksystemclipboard.h"
8#include "kguiaddons_debug.h"
9
10#include "qtclipboard_p.h"
11#include "waylandclipboard_p.h"
12#include "wlrwaylandclipboard_p.h"
13
14#include <QDebug>
15#include <QGuiApplication>
16#include <QMimeData>
17
18KSystemClipboard *KSystemClipboard::instance()
19{
20 if (!qGuiApp || qGuiApp->closingDown()) {
21 return nullptr;
22 }
23 static KSystemClipboard *systemClipboard = nullptr;
24
25#ifdef WITH_WAYLAND
26 static bool s_waylandChecked = false;
27 if (!systemClipboard && qGuiApp->platformName() == QLatin1String("wayland") && !s_waylandChecked) {
28 s_waylandChecked = true;
29
30 if (auto waylandClipboard = WaylandClipboard::create(qApp)) {
31 systemClipboard = waylandClipboard;
32 } else if (auto waylandClipboard = WlrWaylandClipboard::create(qApp)) {
33 systemClipboard = waylandClipboard;
34 } else {
35 qCWarning(KGUIADDONS_LOG) << "Could not init WaylandClipboard, falling back to QtClipboard.";
36 }
37 }
38#endif
39
40 if (!systemClipboard) {
41 systemClipboard = new QtClipboard(qApp);
42 }
43
44 return systemClipboard;
45}
46
48{
49 const QMimeData *data = mimeData(mode);
50 if (data) {
51 return data->text();
52 }
53 return QString();
54}
55
56KSystemClipboard::KSystemClipboard(QObject *parent)
57 : QObject(parent)
58{
59}
60
61#include "moc_ksystemclipboard.cpp"
static KSystemClipboard * instance()
Returns a shared global SystemClipboard instance.
QString text(QClipboard::Mode mode)
Returns the text content of the Clipboard.
virtual const QMimeData * mimeData(QClipboard::Mode mode) const =0
Returns the current mime data received by the clipboard.
QString text() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:15:35 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.