1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QWAYLANDDATAOFFER_H |
5 | #define QWAYLANDDATAOFFER_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/qhash.h> |
19 | #include <QtCore/qstring.h> |
20 | |
21 | #include <QtGui/private/qinternalmimedata_p.h> |
22 | |
23 | #include <QtWaylandClient/private/qtwaylandclientglobal_p.h> |
24 | #include <QtWaylandClient/private/qwayland-wayland.h> |
25 | |
26 | QT_REQUIRE_CONFIG(wayland_datadevice); |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | namespace QtWaylandClient { |
31 | |
32 | class QWaylandDisplay; |
33 | class QWaylandMimeData; |
34 | |
35 | class QWaylandAbstractDataOffer |
36 | { |
37 | public: |
38 | virtual void startReceiving(const QString &mimeType, int fd) = 0; |
39 | virtual QMimeData *mimeData() = 0; |
40 | |
41 | virtual ~QWaylandAbstractDataOffer() = default; |
42 | }; |
43 | |
44 | class Q_WAYLANDCLIENT_EXPORT QWaylandDataOffer |
45 | : public QtWayland::wl_data_offer // needs to be the first because we do static casts from the user pointer to the wrapper |
46 | , public QWaylandAbstractDataOffer |
47 | { |
48 | public: |
49 | explicit QWaylandDataOffer(QWaylandDisplay *display, struct ::wl_data_offer *offer); |
50 | ~QWaylandDataOffer() override; |
51 | QMimeData *mimeData() override; |
52 | Qt::DropActions supportedActions() const; |
53 | |
54 | QString firstFormat() const; |
55 | |
56 | void startReceiving(const QString &mimeType, int fd) override; |
57 | |
58 | protected: |
59 | void data_offer_offer(const QString &mime_type) override; |
60 | void data_offer_source_actions(uint32_t source_actions) override; |
61 | void data_offer_action(uint32_t dnd_action) override; |
62 | |
63 | private: |
64 | QWaylandDisplay *m_display = nullptr; |
65 | QScopedPointer<QWaylandMimeData> m_mimeData; |
66 | Qt::DropActions m_supportedActions; |
67 | }; |
68 | |
69 | |
70 | class QWaylandMimeData : public QInternalMimeData { |
71 | public: |
72 | explicit QWaylandMimeData(QWaylandAbstractDataOffer *dataOffer); |
73 | ~QWaylandMimeData() override; |
74 | |
75 | void appendFormat(const QString &mimeType); |
76 | |
77 | protected: |
78 | bool hasFormat_sys(const QString &mimeType) const override; |
79 | QStringList formats_sys() const override; |
80 | QVariant retrieveData_sys(const QString &mimeType, QMetaType type) const override; |
81 | |
82 | private: |
83 | int readData(int fd, QByteArray &data) const; |
84 | |
85 | QWaylandAbstractDataOffer *m_dataOffer = nullptr; |
86 | mutable QStringList m_types; |
87 | mutable QHash<QString, QByteArray> m_data; |
88 | }; |
89 | |
90 | } // namespace QtWaylandClient |
91 | |
92 | QT_END_NAMESPACE |
93 | #endif |
94 | |