GCC Code Coverage Report


Directory: ./
File: src/client/data_control_v1.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 146 177 82.5%
Branches: 34 76 44.7%

Line Branch Exec Source
1 /*
2 SPDX-FileCopyrightText: 2021 Roman Gilg <subdiff@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only
5 */
6 #include "data_control_v1_p.h"
7
8 #include "seat.h"
9 #include "selection_device_p.h"
10 #include "selection_offer_p.h"
11 #include "selection_source_p.h"
12
13 namespace Wrapland::Client
14 {
15
16 3 data_control_manager_v1::data_control_manager_v1(QObject* parent)
17 3 : QObject(parent)
18
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 , d_ptr(new Private)
19 3 {
20 3 }
21
22 6 data_control_manager_v1::~data_control_manager_v1()
23 6 {
24
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 release();
25 6 }
26
27 3 void data_control_manager_v1::release()
28 {
29 3 d_ptr->manager.release();
30 3 }
31
32 8 bool data_control_manager_v1::isValid() const
33 {
34 8 return d_ptr->manager.isValid();
35 }
36
37 3 void data_control_manager_v1::setup(zwlr_data_control_manager_v1* manager)
38 {
39
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(manager);
40
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(!d_ptr->manager.isValid());
41 3 d_ptr->manager.setup(manager);
42 3 }
43
44 EventQueue* data_control_manager_v1::eventQueue()
45 {
46 return d_ptr->queue;
47 }
48
49 6 void data_control_manager_v1::setEventQueue(EventQueue* queue)
50 {
51 3 d_ptr->queue = queue;
52 3 }
53
54 2 data_control_source_v1* data_control_manager_v1::create_source(QObject* parent)
55 {
56
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(isValid());
57
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto* s = new data_control_source_v1(parent);
58 2 auto w = zwlr_data_control_manager_v1_create_data_source(d_ptr->manager);
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (d_ptr->queue) {
60 2 d_ptr->queue->addProxy(w);
61 2 }
62 2 s->setup(w);
63 2 return s;
64 }
65
66 3 data_control_device_v1* data_control_manager_v1::get_device(Seat* seat, QObject* parent)
67 {
68
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(isValid());
69
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(seat);
70
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 auto* device = new data_control_device_v1(parent);
71 3 auto w = zwlr_data_control_manager_v1_get_data_device(d_ptr->manager, *seat);
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (d_ptr->queue) {
73 3 d_ptr->queue->addProxy(w);
74 3 }
75 3 device->setup(w);
76 3 return device;
77 }
78
79 data_control_manager_v1::operator zwlr_data_control_manager_v1*() const
80 {
81 return d_ptr->manager;
82 }
83
84 data_control_manager_v1::operator zwlr_data_control_manager_v1*()
85 {
86 return d_ptr->manager;
87 }
88
89 const zwlr_data_control_device_v1_listener data_control_device_v1::Private::s_listener = {
90 data_offer_callback<Private>,
91 selection_callback<Private>,
92 finished_callback,
93 primary_selection_callback,
94 };
95
96 3 data_control_device_v1::Private::Private(data_control_device_v1* ptr)
97 3 : q(ptr)
98 {
99 3 }
100
101 3 void data_control_device_v1::Private::setup(zwlr_data_control_device_v1* d)
102 {
103
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(d);
104
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(!device.isValid());
105 3 device.setup(d);
106 3 zwlr_data_control_device_v1_add_listener(device, &s_listener, this);
107 3 }
108
109 3 data_control_device_v1::data_control_device_v1(QObject* parent)
110 3 : QObject(parent)
111
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 , d_ptr(new Private(this))
112 3 {
113 3 }
114
115 6 data_control_device_v1::~data_control_device_v1()
116 6 {
117
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 release();
118 6 }
119
120 3 void data_control_device_v1::release()
121 {
122 3 d_ptr->device.release();
123 3 }
124
125 3 bool data_control_device_v1::isValid() const
126 {
127 3 return d_ptr->device.isValid();
128 }
129
130 3 void data_control_device_v1::setup(zwlr_data_control_device_v1* dataDevice)
131 {
132 3 d_ptr->setup(dataDevice);
133 3 }
134
135 void data_control_device_v1::Private::finished_callback(void* data,
136 zwlr_data_control_device_v1* device)
137 {
138 auto priv = reinterpret_cast<data_control_device_v1::Private*>(data);
139 assert(priv->device == device);
140
141 Q_EMIT priv->q->finished();
142 }
143
144 3 void data_control_device_v1::Private::primary_selection_callback(
145 void* data,
146 zwlr_data_control_device_v1* device,
147 zwlr_data_control_offer_v1* id)
148 {
149 3 auto priv = reinterpret_cast<data_control_device_v1::Private*>(data);
150
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 assert(priv->device == device);
151
152
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (!id) {
153 2 priv->primary_selection_offer.reset();
154 2 Q_EMIT priv->q->primary_selection_offered(nullptr);
155 2 return;
156 }
157
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(*priv->lastOffer == id);
159
160 1 priv->primary_selection_offer.reset(priv->lastOffer);
161 1 priv->lastOffer = nullptr;
162
163 1 Q_EMIT priv->q->primary_selection_offered(priv->primary_selection_offer.get());
164 3 }
165
166 2 void data_control_device_v1::set_selection(data_control_source_v1* source)
167 {
168 2 zwlr_data_control_source_v1* wlr_src = nullptr;
169
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (source) {
170 1 wlr_src = *source;
171 1 }
172 2 zwlr_data_control_device_v1_set_selection(d_ptr->device, wlr_src);
173 2 }
174
175 2 void data_control_device_v1::set_primary_selection(data_control_source_v1* source)
176 {
177 2 zwlr_data_control_source_v1* wlr_src = nullptr;
178
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (source) {
179 1 wlr_src = *source;
180 1 }
181 2 zwlr_data_control_device_v1_set_primary_selection(d_ptr->device, wlr_src);
182 2 }
183
184 3 data_control_offer_v1* data_control_device_v1::offered_selection() const
185 {
186 3 return d_ptr->selectionOffer.get();
187 }
188
189 3 data_control_offer_v1* data_control_device_v1::offered_primary_selection() const
190 {
191 3 return d_ptr->primary_selection_offer.get();
192 }
193
194 data_control_device_v1::operator zwlr_data_control_device_v1*()
195 {
196 return d_ptr->device;
197 }
198
199 data_control_device_v1::operator zwlr_data_control_device_v1*() const
200 {
201 return d_ptr->device;
202 }
203
204 const struct zwlr_data_control_offer_v1_listener data_control_offer_v1::Private::s_listener = {
205 offer_callback<Private>,
206 };
207
208 2 data_control_offer_v1::Private::Private(zwlr_data_control_offer_v1* offer, data_control_offer_v1* q)
209 2 : q(q)
210 {
211
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 dataOffer.setup(offer);
212
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 zwlr_data_control_offer_v1_add_listener(offer, &s_listener, this);
213 2 }
214
215 2 data_control_offer_v1::data_control_offer_v1(data_control_device_v1* parent,
216 zwlr_data_control_offer_v1* dataOffer)
217 2 : QObject(parent)
218
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 , d_ptr(new Private(dataOffer, this))
219 2 {
220 2 }
221
222 4 data_control_offer_v1::~data_control_offer_v1()
223 4 {
224
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 release();
225 4 }
226
227 2 void data_control_offer_v1::release()
228 {
229 2 d_ptr->dataOffer.release();
230 2 }
231
232 2 bool data_control_offer_v1::isValid() const
233 {
234 2 return d_ptr->dataOffer.isValid();
235 }
236
237 QList<QMimeType> data_control_offer_v1::offered_mime_types() const
238 {
239 return d_ptr->mimeTypes;
240 }
241
242 void data_control_offer_v1::receive(QMimeType const& mimeType, int32_t fd)
243 {
244 receive(mimeType.name(), fd);
245 }
246
247 void data_control_offer_v1::receive(QString const& mimeType, int32_t fd)
248 {
249 Q_ASSERT(isValid());
250 zwlr_data_control_offer_v1_receive(d_ptr->dataOffer, mimeType.toUtf8().constData(), fd);
251 }
252
253 2 data_control_offer_v1::operator zwlr_data_control_offer_v1*()
254 {
255 2 return d_ptr->dataOffer;
256 }
257
258 data_control_offer_v1::operator zwlr_data_control_offer_v1*() const
259 {
260 return d_ptr->dataOffer;
261 }
262
263 const zwlr_data_control_source_v1_listener data_control_source_v1::Private::s_listener = {
264 send_callback<Private>,
265 cancelled_callback<Private>,
266 };
267
268 2 data_control_source_v1::Private::Private(data_control_source_v1* ptr)
269 2 : q(ptr)
270 {
271 2 }
272
273 2 void data_control_source_v1::Private::setup(zwlr_data_control_source_v1* s)
274 {
275
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(!source.isValid());
276
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(s);
277 2 source.setup(s);
278 2 zwlr_data_control_source_v1_add_listener(s, &s_listener, this);
279 2 }
280
281 2 data_control_source_v1::data_control_source_v1(QObject* parent)
282 2 : QObject(parent)
283
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 , d_ptr(new Private(this))
284 2 {
285 2 }
286
287 4 data_control_source_v1::~data_control_source_v1()
288 4 {
289
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 release();
290 4 }
291
292 2 void data_control_source_v1::release()
293 {
294 2 d_ptr->source.release();
295 2 }
296
297 2 bool data_control_source_v1::isValid() const
298 {
299 2 return d_ptr->source.isValid();
300 }
301
302 2 void data_control_source_v1::setup(zwlr_data_control_source_v1* dataSource)
303 {
304 2 d_ptr->setup(dataSource);
305 2 }
306
307 void data_control_source_v1::offer(QString const& mimeType)
308 {
309 zwlr_data_control_source_v1_offer(d_ptr->source, mimeType.toUtf8().constData());
310 }
311
312 void data_control_source_v1::offer(QMimeType const& mimeType)
313 {
314 if (!mimeType.isValid()) {
315 return;
316 }
317 offer(mimeType.name());
318 }
319
320 data_control_source_v1::operator zwlr_data_control_source_v1*() const
321 {
322 return d_ptr->source;
323 }
324
325 2 data_control_source_v1::operator zwlr_data_control_source_v1*()
326 {
327 2 return d_ptr->source;
328 }
329
330 }
331