| 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 | |
| 18 | KSystemClipboard *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 | |
| 47 | QString KSystemClipboard::text(QClipboard::Mode mode) |
| 48 | { |
| 49 | const QMimeData *data = mimeData(mode); |
| 50 | if (data) { |
| 51 | return data->text(); |
| 52 | } |
| 53 | return QString(); |
| 54 | } |
| 55 | |
| 56 | KSystemClipboard::KSystemClipboard(QObject *parent) |
| 57 | : QObject(parent) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | #include "moc_ksystemclipboard.cpp" |
| 62 |
