1 /********************************************************************
2 Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
3 
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11 
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library.  If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #ifndef WAYLAND_DATAOFFER_H
21 #define WAYLAND_DATAOFFER_H
22 
23 #include <QObject>
24 // STD
25 #include <memory>
26 
27 #include <Wrapland/Client/wraplandclient_export.h>
28 
29 #include "datadevicemanager.h"
30 
31 struct wl_data_offer;
32 
33 class QMimeType;
34 
35 namespace Wrapland
36 {
37 namespace Client
38 {
39 class DataDevice;
40 
41 /**
42  * @short Wrapper for the wl_data_offer interface.
43  *
44  * This class is a convenient wrapper for the wl_data_offer interface.
45  * The DataOffer gets created by DataDevice.
46  *
47  * @see DataOfferManager
48  **/
49 class WRAPLANDCLIENT_EXPORT DataOffer : public QObject
50 {
51     Q_OBJECT
52 public:
53     explicit DataOffer(DataDevice* parent, wl_data_offer* dataOffer);
54     virtual ~DataOffer();
55 
56     /**
57      * Releases the wl_data_offer interface.
58      * After the interface has been released the DataOffer instance is no
59      * longer valid and can be setup with another wl_data_offer interface.
60      **/
61     void release();
62 
63     /**
64      * @returns @c true if managing a wl_data_offer.
65      **/
66     bool isValid() const;
67 
68     QList<QMimeType> offeredMimeTypes() const;
69 
70     void receive(const QMimeType& mimeType, qint32 fd);
71     void receive(const QString& mimeType, qint32 fd);
72 
73     /**
74      * Notifies the compositor that the drag destination successfully
75      * finished the drag-and-drop operation.
76      *
77      * After this operation it is only allowed to release the DataOffer.
78      *
79      * @since 0.0.542
80      **/
81     void dragAndDropFinished();
82 
83     /**
84      * The actions offered by the DataSource.
85      * @since 0.0.542
86      * @see sourceDragAndDropActionsChanged
87      **/
88     DataDeviceManager::DnDActions sourceDragAndDropActions() const;
89 
90     /**
91      * Sets the @p supported and @p preferred Drag and Drop actions.
92      * @since 0.0.542
93      **/
94     void setDragAndDropActions(DataDeviceManager::DnDActions supported,
95                                DataDeviceManager::DnDAction preferred);
96 
97     /**
98      * The currently selected drag and drop action by the compositor.
99      * @see selectedDragAndDropActionChanged
100      * @since 0.0.542
101      **/
102     DataDeviceManager::DnDAction selectedDragAndDropAction() const;
103 
104     operator wl_data_offer*();
105     operator wl_data_offer*() const;
106 
107 Q_SIGNALS:
108     void mimeTypeOffered(const QString&);
109     /**
110      * Emitted whenever the @link{sourceDragAndDropActions} changed, e.g. on enter or when
111      * the DataSource changes the supported actions.
112      * @see sourceDragAndDropActions
113      * @since 0.0.542
114      **/
115     void sourceDragAndDropActionsChanged();
116     /**
117      * Emitted whenever the selected drag and drop action changes.
118      * @see selectedDragAndDropAction
119      * @since 0.0.542
120      **/
121     void selectedDragAndDropActionChanged();
122 
123 private:
124     class Private;
125     std::unique_ptr<Private> d;
126 };
127 
128 }
129 }
130 
131 Q_DECLARE_METATYPE(Wrapland::Client::DataOffer*)
132 
133 #endif
134