1 | // Copyright (C) 2017 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qwldatasource_p.h" |
5 | #include "qwldataoffer_p.h" |
6 | #include "qwldatadevice_p.h" |
7 | #include "qwldatadevicemanager_p.h" |
8 | #include <QtWaylandCompositor/private/qwaylandutils_p.h> |
9 | |
10 | #include <unistd.h> |
11 | #include <QtWaylandCompositor/private/wayland-wayland-server-protocol.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | namespace QtWayland { |
16 | |
17 | DataSource::DataSource(struct wl_client *client, uint32_t id, uint32_t time) |
18 | : QtWaylandServer::wl_data_source(client, id, 1) |
19 | , m_time(time) |
20 | { |
21 | } |
22 | |
23 | DataSource::~DataSource() |
24 | { |
25 | if (m_manager) |
26 | m_manager->sourceDestroyed(source: this); |
27 | if (m_device) |
28 | m_device->sourceDestroyed(source: this); |
29 | } |
30 | |
31 | uint32_t DataSource::time() const |
32 | { |
33 | return m_time; |
34 | } |
35 | |
36 | QList<QString> DataSource::mimeTypes() const |
37 | { |
38 | return m_mimeTypes; |
39 | } |
40 | |
41 | void DataSource::accept(const QString &mimeType) |
42 | { |
43 | send_target(mimeType); |
44 | } |
45 | |
46 | void DataSource::send(const QString &mimeType, int fd) |
47 | { |
48 | send_send(mimeType, fd); |
49 | close(fd: fd); |
50 | } |
51 | |
52 | void DataSource::cancel() |
53 | { |
54 | send_cancelled(); |
55 | } |
56 | |
57 | void DataSource::setManager(DataDeviceManager *mgr) |
58 | { |
59 | m_manager = mgr; |
60 | } |
61 | |
62 | void DataSource::setDevice(DataDevice *device) |
63 | { |
64 | m_device = device; |
65 | } |
66 | |
67 | DataSource *DataSource::fromResource(struct ::wl_resource *resource) |
68 | { |
69 | return QtWayland::fromResource<DataSource *>(resource); |
70 | } |
71 | |
72 | void DataSource::data_source_offer(Resource *, const QString &mime_type) |
73 | { |
74 | m_mimeTypes.append(t: mime_type); |
75 | } |
76 | |
77 | void DataSource::data_source_destroy(Resource *resource) |
78 | { |
79 | wl_resource_destroy(resource->handle); |
80 | } |
81 | |
82 | void DataSource::data_source_destroy_resource(QtWaylandServer::wl_data_source::Resource *resource) |
83 | { |
84 | Q_UNUSED(resource); |
85 | delete this; |
86 | } |
87 | |
88 | } |
89 | |
90 | QT_END_NAMESPACE |
91 |