File indexing completed on 2024-12-22 05:09:20

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #ifndef WAYLAND_DATASOURCE_H
0007 #define WAYLAND_DATASOURCE_H
0008 
0009 #include "buffer.h"
0010 #include "datadevicemanager.h"
0011 
0012 #include <QObject>
0013 
0014 #include "KWayland/Client/kwaylandclient_export.h"
0015 
0016 struct wl_data_source;
0017 class QMimeType;
0018 
0019 namespace KWayland
0020 {
0021 namespace Client
0022 {
0023 /**
0024  * @short Wrapper for the wl_data_source interface.
0025  *
0026  * This class is a convenient wrapper for the wl_data_source interface.
0027  * To create a DataSource call DataDeviceManager::createDataSource.
0028  *
0029  * @see DataDeviceManager
0030  **/
0031 class KWAYLANDCLIENT_EXPORT DataSource : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035     explicit DataSource(QObject *parent = nullptr);
0036     ~DataSource() override;
0037 
0038     /**
0039      * Setup this DataSource to manage the @p dataSource.
0040      * When using DataDeviceManager::createDataSource there is no need to call this
0041      * method.
0042      **/
0043     void setup(wl_data_source *dataSource);
0044     /**
0045      * Releases the wl_data_source interface.
0046      * After the interface has been released the DataSource instance is no
0047      * longer valid and can be setup with another wl_data_source interface.
0048      **/
0049     void release();
0050     /**
0051      * Destroys the data held by this DataSource.
0052      * This method is supposed to be used when the connection to the Wayland
0053      * server goes away. If the connection is not valid anymore, it's not
0054      * possible to call release anymore as that calls into the Wayland
0055      * connection and the call would fail. This method cleans up the data, so
0056      * that the instance can be deleted or set up to a new wl_data_source interface
0057      * once there is a new connection available.
0058      *
0059      * This method is automatically invoked when the Registry which created this
0060      * DataSource gets destroyed.
0061      *
0062      * @see release
0063      **/
0064     void destroy();
0065     /**
0066      * @returns @c true if managing a wl_data_source.
0067      **/
0068     bool isValid() const;
0069 
0070     void offer(const QString &mimeType);
0071     void offer(const QMimeType &mimeType);
0072 
0073     /**
0074      * Sets the actions that the source side client supports for this
0075      * operation.
0076      *
0077      * This request must be made once only, and can only be made on sources
0078      * used in drag-and-drop, so it must be performed before
0079      * @link{DataDevice::startDrag}. Attempting to use the source other than
0080      * for drag-and-drop will raise a protocol error.
0081      * @since 5.42
0082      **/
0083     void setDragAndDropActions(DataDeviceManager::DnDActions actions);
0084 
0085     /**
0086      * The currently selected drag and drop action by the compositor.
0087      * @see selectedDragAndDropActionChanged
0088      * @since 5.42
0089      **/
0090     DataDeviceManager::DnDAction selectedDragAndDropAction() const;
0091 
0092     operator wl_data_source *();
0093     operator wl_data_source *() const;
0094 
0095 Q_SIGNALS:
0096     /**
0097      * Emitted when a target accepts pointer_focus or motion events. If
0098      * a target does not accept any of the offered types, @p mimeType is empty.
0099      **/
0100     void targetAccepts(const QString &mimeType);
0101     /**
0102      * Request for data from the client. Send the data as the
0103      * specified @p mimeType over the passed file descriptor @p fd, then close
0104      * it.
0105      **/
0106     void sendDataRequested(const QString &mimeType, qint32 fd);
0107     /**
0108      * This DataSource has been replaced by another DataSource.
0109      * The client should clean up and destroy this DataSource.
0110      **/
0111     void cancelled();
0112 
0113     /**
0114      * The drag-and-drop operation physically finished.
0115      *
0116      * The user performed the drop action. This signal does not
0117      * indicate acceptance, @link{cancelled} may still be
0118      * emitted afterwards if the drop destination does not accept any
0119      * mime type.
0120      *
0121      * However, this signal might not be received if the
0122      * compositor cancelled the drag-and-drop operation before this
0123      * signal could happen.
0124      *
0125      * Note that the DataSource may still be used in the future and
0126      * should not be destroyed here.
0127      * @since 5.42
0128      **/
0129     void dragAndDropPerformed();
0130 
0131     /**
0132      * The drag-and-drop operation concluded.
0133      *
0134      * The drop destination finished interoperating with this DataSource,
0135      * so the client is now free to destroy this DataSource.
0136      *
0137      * If the action used to perform the operation was "move", the
0138      * source can now delete the transferred data.
0139      * @since 5.42
0140      */
0141     void dragAndDropFinished();
0142 
0143     /**
0144      * Emitted whenever the selected drag and drop action changes.
0145      * @see selectedDragAndDropAction
0146      * @since 5.42
0147      **/
0148     void selectedDragAndDropActionChanged();
0149 
0150 private:
0151     class Private;
0152     QScopedPointer<Private> d;
0153 };
0154 
0155 }
0156 }
0157 
0158 #endif