6 #include "dataoffer_interface_p.h" 7 #include "datadevice_interface.h" 8 #include "datasource_interface.h" 10 #include <QStringList> 12 #include <wayland-server.h> 22 const struct wl_data_offer_interface DataOfferInterface::Private::s_interface = {
25 resourceDestroyedCallback,
31 DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource)
32 : Resource::Private(q, nullptr, parentResource, &wl_data_offer_interface, &s_interface)
34 , dataDevice(parentInterface)
39 DataOfferInterface::Private::~Private() =
default;
41 void DataOfferInterface::Private::acceptCallback(wl_client *client, wl_resource *resource, uint32_t serial,
const char *mimeType)
45 auto p = cast<Private>(resource);
52 void DataOfferInterface::Private::receiveCallback(wl_client *client, wl_resource *resource,
const char *mimeType, int32_t fd)
55 cast<Private>(resource)->receive(
QString::fromUtf8(mimeType), fd);
58 void DataOfferInterface::Private::receive(const
QString &mimeType, qint32 fd)
64 source->requestData(mimeType, fd);
67 void DataOfferInterface::Private::finishCallback(wl_client *client, wl_resource *resource)
70 auto p = cast<Private>(resource);
74 p->source->dndFinished();
78 void DataOfferInterface::Private::setActionsCallback(wl_client *client, wl_resource *resource, uint32_t dnd_actions, uint32_t preferred_action)
82 DataDeviceManagerInterface::DnDActions supportedActions;
83 if (dnd_actions & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY) {
84 supportedActions |= DataDeviceManagerInterface::DnDAction::Copy;
86 if (dnd_actions & WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE) {
87 supportedActions |= DataDeviceManagerInterface::DnDAction::Move;
89 if (dnd_actions & WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK) {
90 supportedActions |= DataDeviceManagerInterface::DnDAction::Ask;
93 if (dnd_actions & ~(WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY | WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE | WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK)) {
94 wl_resource_post_error(resource, WL_DATA_OFFER_ERROR_INVALID_ACTION_MASK,
"Invalid action mask");
97 if (preferred_action != WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY &&
98 preferred_action != WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE &&
99 preferred_action != WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK &&
100 preferred_action != WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE) {
101 wl_resource_post_error(resource, WL_DATA_OFFER_ERROR_INVALID_ACTION,
"Invalid preferred action");
105 DataDeviceManagerInterface::DnDAction preferredAction = DataDeviceManagerInterface::DnDAction::None;
106 if (preferred_action == WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY) {
107 preferredAction = DataDeviceManagerInterface::DnDAction::Copy;
108 }
else if (preferred_action == WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE) {
109 preferredAction = DataDeviceManagerInterface::DnDAction::Move;
110 }
else if (preferred_action == WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK) {
111 preferredAction = DataDeviceManagerInterface::DnDAction::Ask;
114 auto p = cast<Private>(resource);
115 p->supportedDnDActions = supportedActions;
116 p->preferredDnDAction = preferredAction;
117 Q_EMIT p->q_func()->dragAndDropActionsChanged();
120 void DataOfferInterface::Private::sendSourceActions()
125 if (wl_resource_get_version(resource) < WL_DATA_OFFER_SOURCE_ACTIONS_SINCE_VERSION) {
128 uint32_t wlActions = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
129 const auto actions = source->supportedDragAndDropActions();
130 if (actions.testFlag(DataDeviceManagerInterface::DnDAction::Copy)) {
131 wlActions |= WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
133 if (actions.testFlag(DataDeviceManagerInterface::DnDAction::Move)) {
134 wlActions |= WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE;
136 if (actions.testFlag(DataDeviceManagerInterface::DnDAction::Ask)) {
137 wlActions |= WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK;
139 wl_data_offer_send_source_actions(resource, wlActions);
142 DataOfferInterface::DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface, wl_resource *parentResource)
143 : Resource(new Private(source, parentInterface, this, parentResource))
146 connect(source, &DataSourceInterface::mimeTypeOffered,
this,
147 [
this](
const QString &mimeType) {
163 DataOfferInterface::~DataOfferInterface() =
default;
165 void DataOfferInterface::sendAllOffers()
168 for (
const QString &mimeType : d->source->mimeTypes()) {
173 DataOfferInterface::Private *DataOfferInterface::d_func()
const 175 return reinterpret_cast<DataOfferInterface::Private*
>(d.
data());
181 return d->supportedDnDActions;
187 return d->preferredDnDAction;
193 if (wl_resource_get_version(d->resource) < WL_DATA_OFFER_ACTION_SINCE_VERSION) {
196 uint32_t wlAction = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
197 if (action == DataDeviceManagerInterface::DnDAction::Copy) {
198 wlAction = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
199 }
else if (action == DataDeviceManagerInterface::DnDAction::Move ) {
200 wlAction = WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE;
201 }
else if (action == DataDeviceManagerInterface::DnDAction::Ask) {
202 wlAction = WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK;
204 wl_data_offer_send_action(d->resource, wlAction);
const QList< QKeySequence > & close()
QString fromUtf8(const char *str, int size)
const char * constData() const const
DnDAction
Drag and Drop actions supported by the DataSourceInterface.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void destroyed(QObject *obj)
QByteArray toUtf8() const const