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
13#include <QDebug>
14#include <QGuiApplication>
15#include <QMimeData>
16
17KSystemClipboard *KSystemClipboard::instance()
18{
19 if (!qGuiApp || qGuiApp->closingDown()) {
20 return nullptr;
21 }
22 static KSystemClipboard *systemClipboard = nullptr;
23
24#ifdef WITH_WAYLAND
25 static bool s_waylandChecked = false;
26 if (!systemClipboard && qGuiApp->platformName() == QLatin1String("wayland") && !s_waylandChecked) {
27 WaylandClipboard *waylandClipboard = new WaylandClipboard(qApp);
28 s_waylandChecked = true;
29
30 if (waylandClipboard->isValid()) {
31 systemClipboard = waylandClipboard;
32 } else {
33 delete waylandClipboard;
34 qCWarning(KGUIADDONS_LOG) << "Could not init WaylandClipboard, falling back to QtClipboard.";
35 }
36 }
37#endif
38
39 if (!systemClipboard) {
40 systemClipboard = new QtClipboard(qApp);
41 }
42
43 return systemClipboard;
44}
45
46QString KSystemClipboard::text(QClipboard::Mode mode)
47{
48 const QMimeData *data = mimeData(mode);
49 if (data) {
50 return data->text();
51 }
52 return QString();
53}
54
55KSystemClipboard::KSystemClipboard(QObject *parent)
56 : QObject(parent)
57{
58}
59
60#include "moc_ksystemclipboard.cpp"
61

source code of kguiaddons/src/systemclipboard/ksystemclipboard.cpp