KWayland

datasource.h
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #ifndef WAYLAND_DATASOURCE_H
7 #define WAYLAND_DATASOURCE_H
8 
9 #include "buffer.h"
10 #include "datadevicemanager.h"
11 
12 #include <QObject>
13 
14 #include <KWayland/Client/kwaylandclient_export.h>
15 
16 struct wl_data_source;
17 class QMimeType;
18 
19 namespace KWayland
20 {
21 namespace Client
22 {
23 /**
24  * @short Wrapper for the wl_data_source interface.
25  *
26  * This class is a convenient wrapper for the wl_data_source interface.
27  * To create a DataSource call DataDeviceManager::createDataSource.
28  *
29  * @see DataDeviceManager
30  **/
31 class KWAYLANDCLIENT_EXPORT DataSource : public QObject
32 {
33  Q_OBJECT
34 public:
35  explicit DataSource(QObject *parent = nullptr);
36  ~DataSource() override;
37 
38  /**
39  * Setup this DataSource to manage the @p dataSource.
40  * When using DataDeviceManager::createDataSource there is no need to call this
41  * method.
42  **/
43  void setup(wl_data_source *dataSource);
44  /**
45  * Releases the wl_data_source interface.
46  * After the interface has been released the DataSource instance is no
47  * longer valid and can be setup with another wl_data_source interface.
48  **/
49  void release();
50  /**
51  * Destroys the data held by this DataSource.
52  * This method is supposed to be used when the connection to the Wayland
53  * server goes away. If the connection is not valid anymore, it's not
54  * possible to call release anymore as that calls into the Wayland
55  * connection and the call would fail. This method cleans up the data, so
56  * that the instance can be deleted or set up to a new wl_data_source interface
57  * once there is a new connection available.
58  *
59  * This method is automatically invoked when the Registry which created this
60  * DataSource gets destroyed.
61  *
62  * @see release
63  **/
64  void destroy();
65  /**
66  * @returns @c true if managing a wl_data_source.
67  **/
68  bool isValid() const;
69 
70  void offer(const QString &mimeType);
71  void offer(const QMimeType &mimeType);
72 
73  /**
74  * Sets the actions that the source side client supports for this
75  * operation.
76  *
77  * This request must be made once only, and can only be made on sources
78  * used in drag-and-drop, so it must be performed before
79  * @link{DataDevice::startDrag}. Attempting to use the source other than
80  * for drag-and-drop will raise a protocol error.
81  * @since 5.42
82  **/
83  void setDragAndDropActions(DataDeviceManager::DnDActions actions);
84 
85  /**
86  * The currently selected drag and drop action by the compositor.
87  * @see selectedDragAndDropActionChanged
88  * @since 5.42
89  **/
90  DataDeviceManager::DnDAction selectedDragAndDropAction() const;
91 
92  operator wl_data_source *();
93  operator wl_data_source *() const;
94 
95 Q_SIGNALS:
96  /**
97  * Emitted when a target accepts pointer_focus or motion events. If
98  * a target does not accept any of the offered types, @p mimeType is empty.
99  **/
100  void targetAccepts(const QString &mimeType);
101  /**
102  * Request for data from the client. Send the data as the
103  * specified @p mimeType over the passed file descriptor @p fd, then close
104  * it.
105  **/
106  void sendDataRequested(const QString &mimeType, qint32 fd);
107  /**
108  * This DataSource has been replaced by another DataSource.
109  * The client should clean up and destroy this DataSource.
110  **/
111  void cancelled();
112 
113  /**
114  * The drag-and-drop operation physically finished.
115  *
116  * The user performed the drop action. This signal does not
117  * indicate acceptance, @link{cancelled} may still be
118  * emitted afterwards if the drop destination does not accept any
119  * mime type.
120  *
121  * However, this signal might not be received if the
122  * compositor cancelled the drag-and-drop operation before this
123  * signal could happen.
124  *
125  * Note that the DataSource may still be used in the future and
126  * should not be destroyed here.
127  * @since 5.42
128  **/
129  void dragAndDropPerformed();
130 
131  /**
132  * The drag-and-drop operation concluded.
133  *
134  * The drop destination finished interoperating with this DataSource,
135  * so the client is now free to destroy this DataSource.
136  *
137  * If the action used to perform the operation was "move", the
138  * source can now delete the transferred data.
139  * @since 5.42
140  */
141  void dragAndDropFinished();
142 
143  /**
144  * Emitted whenever the selected drag and drop action changes.
145  * @see selectedDragAndDropAction
146  * @since 5.42
147  **/
148  void selectedDragAndDropActionChanged();
149 
150 private:
151  class Private;
153 };
154 
155 }
156 }
157 
158 #endif
Wrapper for the wl_data_source interface.
Definition: datasource.h:31
DnDAction
Drag and Drop actions supported by DataSource and DataOffer.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 22:53:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.