1/*
2 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#ifndef WAYLAND_DATAOFFER_H
7#define WAYLAND_DATAOFFER_H
8
9#include <QObject>
10
11#include "KWayland/Client/kwaylandclient_export.h"
12
13#include "datadevicemanager.h"
14
15struct wl_data_offer;
16
17class QMimeType;
18
19namespace KWayland
20{
21namespace Client
22{
23class DataDevice;
24
25/**
26 * @short Wrapper for the wl_data_offer interface.
27 *
28 * This class is a convenient wrapper for the wl_data_offer interface.
29 * The DataOffer gets created by DataDevice.
30 *
31 * @see DataOfferManager
32 **/
33class KWAYLANDCLIENT_EXPORT DataOffer : public QObject
34{
35 Q_OBJECT
36public:
37 ~DataOffer() override;
38
39 /**
40 * Releases the wl_data_offer interface.
41 * After the interface has been released the DataOffer instance is no
42 * longer valid and can be setup with another wl_data_offer interface.
43 **/
44 void release();
45 /**
46 * Destroys the data held by this DataOffer.
47 * This method is supposed to be used when the connection to the Wayland
48 * server goes away. If the connection is not valid anymore, it's not
49 * possible to call release anymore as that calls into the Wayland
50 * connection and the call would fail. This method cleans up the data, so
51 * that the instance can be deleted or set up to a new wl_data_offer interface
52 * once there is a new connection available.
53 *
54 * This method is automatically invoked when the Registry which created this
55 * DataOffer gets destroyed.
56 *
57 * @see release
58 **/
59 void destroy();
60 /**
61 * @returns @c true if managing a wl_data_offer.
62 **/
63 bool isValid() const;
64
65 QList<QMimeType> offeredMimeTypes() const;
66
67 /**
68 * Indicates that the client can accept data of the given @a mimeType.
69 * The @a serial parameter specifies the serial number of the corresponding
70 * dragEntered() event.
71 *
72 * @see DataDevice::dragEntered
73 */
74 void accept(const QMimeType &mimeType, quint32 serial);
75 /**
76 * Indicates that the client can accept data of the given @a mimeType.
77 * The @a serial parameter specifies the serial number of the corresponding
78 * dragEntered() event.
79 *
80 * @see DataDevice::dragEntered
81 */
82 void accept(const QString &mimeType, quint32 serial);
83
84 void receive(const QMimeType &mimeType, qint32 fd);
85 void receive(const QString &mimeType, qint32 fd);
86
87 /**
88 * Notifies the compositor that the drag destination successfully
89 * finished the drag-and-drop operation.
90 *
91 * After this operation it is only allowed to release the DataOffer.
92 *
93 * @since 5.42
94 **/
95 void dragAndDropFinished();
96
97 /**
98 * The actions offered by the DataSource.
99 * @since 5.42
100 * @see sourceDragAndDropActionsChanged
101 **/
102 DataDeviceManager::DnDActions sourceDragAndDropActions() const;
103
104 /**
105 * Sets the @p supported and @p preferred Drag and Drop actions.
106 * @since 5.42
107 **/
108 void setDragAndDropActions(DataDeviceManager::DnDActions supported, DataDeviceManager::DnDAction preferred);
109
110 /**
111 * The currently selected drag and drop action by the compositor.
112 * @see selectedDragAndDropActionChanged
113 * @since 5.42
114 **/
115 DataDeviceManager::DnDAction selectedDragAndDropAction() const;
116
117 operator wl_data_offer *();
118 operator wl_data_offer *() const;
119
120Q_SIGNALS:
121 void mimeTypeOffered(const QString &);
122 /**
123 * Emitted whenever the @link{sourceDragAndDropActions} changed, e.g. on enter or when
124 * the DataSource changes the supported actions.
125 * @see sourceDragAndDropActions
126 * @since 5.42
127 **/
128 void sourceDragAndDropActionsChanged();
129 /**
130 * Emitted whenever the selected drag and drop action changes.
131 * @see selectedDragAndDropAction
132 * @since 5.42
133 **/
134 void selectedDragAndDropActionChanged();
135
136private:
137 friend class DataDevice;
138 explicit DataOffer(DataDevice *parent, wl_data_offer *dataOffer);
139 class Private;
140 QScopedPointer<Private> d;
141};
142
143}
144}
145
146Q_DECLARE_METATYPE(KWayland::Client::DataOffer *)
147
148#endif
149

source code of kwayland/src/client/dataoffer.h