KWaylandServer

datacontroloffer_v1_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 David Edmundson <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "datacontroloffer_v1_interface.h"
7 #include "datacontroldevice_v1_interface.h"
8 #include "datacontrolsource_v1_interface.h"
9 // Qt
10 #include <QPointer>
11 #include <QStringList>
12 // Wayland
13 #include <qwayland-server-wlr-data-control-unstable-v1.h>
14 // system
15 #include <unistd.h>
16 
17 namespace KWaylandServer
18 {
19 class DataControlOfferV1InterfacePrivate : public QtWaylandServer::zwlr_data_control_offer_v1
20 {
21 public:
22  DataControlOfferV1InterfacePrivate(DataControlOfferV1Interface *q, AbstractDataSource *source, wl_resource *resource);
23 
24  DataControlOfferV1Interface *q;
26 
27 protected:
28  void zwlr_data_control_offer_v1_receive(Resource *resource, const QString &mime_type, int32_t fd) override;
29  void zwlr_data_control_offer_v1_destroy(Resource *resource) override;
30  void zwlr_data_control_offer_v1_destroy_resource(Resource *resource) override;
31 };
32 
33 DataControlOfferV1InterfacePrivate::DataControlOfferV1InterfacePrivate(DataControlOfferV1Interface *_q, AbstractDataSource *source, wl_resource *resource)
34  : QtWaylandServer::zwlr_data_control_offer_v1(resource)
35  , q(_q)
36  , source(source)
37 {
38 }
39 
40 void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_destroy(QtWaylandServer::zwlr_data_control_offer_v1::Resource *resource)
41 {
42  wl_resource_destroy(resource->handle);
43 }
44 
45 void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_destroy_resource(QtWaylandServer::zwlr_data_control_offer_v1::Resource *resource)
46 {
47  Q_UNUSED(resource)
48  delete q;
49 }
50 
51 void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_receive(Resource *resource, const QString &mimeType, qint32 fd)
52 {
53  Q_UNUSED(resource)
54  if (!source) {
55  close(fd);
56  return;
57  }
58  source->requestData(mimeType, fd);
59 }
60 
61 DataControlOfferV1Interface::DataControlOfferV1Interface(AbstractDataSource *source, wl_resource *resource)
62  : QObject()
63  , d(new DataControlOfferV1InterfacePrivate(this, source, resource))
64 {
65  Q_ASSERT(source);
66  connect(source, &AbstractDataSource::mimeTypeOffered, this, [this](const QString &mimeType) {
67  d->send_offer(mimeType);
68  });
69 }
70 
71 DataControlOfferV1Interface::~DataControlOfferV1Interface() = default;
72 
73 void DataControlOfferV1Interface::sendAllOffers()
74 {
75  Q_ASSERT(d->source);
76  for (const QString &mimeType : d->source->mimeTypes()) {
77  d->send_offer(mimeType);
78  }
79 }
80 
81 wl_resource *DataControlOfferV1Interface::resource() const
82 {
83  return d->resource()->handle;
84 }
85 
86 }
const QList< QKeySequence > & close()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:08:27 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.