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
13#include <QDebug>
14#include <QGuiApplication>
15#include <QMimeData>
16
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
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"
This class mimics QClipboard but unlike QClipboard it will continue to get updates even when our wind...
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-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.