File indexing completed on 2024-05-12 05:32:18

0001 /*
0002     SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kwin_export.h"
0010 
0011 #include "clientconnection.h"
0012 #include "datadevicemanager.h"
0013 
0014 struct wl_client;
0015 
0016 namespace KWin
0017 {
0018 /**
0019  * @brief The AbstractDataSource class abstracts the data that
0020  * can be transferred to another client.
0021  *
0022  * It loosely maps to DataDeviceInterface
0023  */
0024 
0025 // Anything related to selections are pure virtual, content relating
0026 // to drag and drop has a default implementation
0027 
0028 class KWIN_EXPORT AbstractDataSource : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032     virtual bool isAccepted() const
0033     {
0034         return false;
0035     }
0036 
0037     virtual void accept(const QString &mimeType)
0038     {
0039     };
0040     virtual void requestData(const QString &mimeType, qint32 fd) = 0;
0041     virtual void cancel() = 0;
0042 
0043     virtual QStringList mimeTypes() const = 0;
0044 
0045     /**
0046      * @returns The Drag and Drop actions supported by this DataSourceInterface.
0047      */
0048     virtual DataDeviceManagerInterface::DnDActions supportedDragAndDropActions() const
0049     {
0050         return {};
0051     };
0052     virtual DataDeviceManagerInterface::DnDAction selectedDndAction() const
0053     {
0054         return DataDeviceManagerInterface::DnDAction::None;
0055     }
0056     /**
0057      * The user performed the drop action during a drag and drop operation.
0058      */
0059     virtual void dropPerformed(){};
0060     /**
0061      * The drop destination finished interoperating with this data source.
0062      */
0063     virtual void dndFinished(){};
0064     /**
0065      * This event indicates the @p action selected by the compositor after matching the
0066      * source/destination side actions. Only one action (or none) will be offered here.
0067      */
0068     virtual void dndAction(DataDeviceManagerInterface::DnDAction action)
0069     {
0070     };
0071 
0072     /**
0073      *  Called when a user stops clicking but it is not accepted by a client.
0074      */
0075     virtual void dndCancelled()
0076     {
0077     }
0078 
0079     virtual wl_client *client() const
0080     {
0081         return nullptr;
0082     };
0083 
0084 Q_SIGNALS:
0085     void aboutToBeDestroyed();
0086 
0087     void mimeTypeOffered(const QString &);
0088     void supportedDragAndDropActionsChanged();
0089 
0090 protected:
0091     explicit AbstractDataSource(QObject *parent = nullptr);
0092 };
0093 
0094 }