1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qwldataoffer_p.h"
5
6#include "qwldatadevice_p.h"
7#include "qwldatasource_p.h"
8
9#include <unistd.h>
10
11QT_BEGIN_NAMESPACE
12
13namespace QtWayland
14{
15
16DataOffer::DataOffer(DataSource *dataSource, QtWaylandServer::wl_data_device::Resource *target)
17 : QtWaylandServer::wl_data_offer(target->client(), 0, 1)
18 , m_dataSource(dataSource)
19{
20 // FIXME: connect to dataSource and reset m_dataSource on destroy
21 target->data_device_object->send_data_offer(target->handle, resource()->handle);
22 const auto mimeTypes = dataSource->mimeTypes();
23 for (const QString &mimeType : mimeTypes) {
24 send_offer(mimeType);
25 }
26}
27
28DataOffer::~DataOffer()
29{
30}
31
32void DataOffer::data_offer_accept(Resource *resource, uint32_t serial, const QString &mimeType)
33{
34 Q_UNUSED(resource);
35 Q_UNUSED(serial);
36 if (m_dataSource)
37 m_dataSource->accept(mimeType);
38}
39
40void DataOffer::data_offer_receive(Resource *resource, const QString &mimeType, int32_t fd)
41{
42 Q_UNUSED(resource);
43 if (m_dataSource)
44 m_dataSource->send(mimeType, fd);
45 else
46 close(fd: fd);
47}
48
49void DataOffer::data_offer_destroy(Resource *resource)
50{
51 wl_resource_destroy(resource->handle);
52}
53
54void DataOffer::data_offer_destroy_resource(Resource *)
55{
56 delete this;
57}
58
59}
60
61QT_END_NAMESPACE
62

source code of qtwayland/src/compositor/wayland_wrapper/qwldataoffer.cpp