KWaylandServer

primaryselectionoffer_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 "primaryselectionoffer_v1_interface.h"
7 #include "primaryselectiondevice_v1_interface.h"
8 #include "primaryselectionsource_v1_interface.h"
9 // Qt
10 #include <QPointer>
11 #include <QStringList>
12 // Wayland
13 #include <qwayland-server-wp-primary-selection-unstable-v1.h>
14 // system
15 #include <unistd.h>
16 
17 namespace KWaylandServer
18 {
19 class PrimarySelectionOfferV1InterfacePrivate : public QtWaylandServer::zwp_primary_selection_offer_v1
20 {
21 public:
22  PrimarySelectionOfferV1InterfacePrivate(PrimarySelectionOfferV1Interface *q, AbstractDataSource *source, wl_resource *resource);
23  PrimarySelectionOfferV1Interface *q;
25 
26 protected:
27  void zwp_primary_selection_offer_v1_receive(Resource *resource, const QString &mime_type, int32_t fd) override;
28  void zwp_primary_selection_offer_v1_destroy(Resource *resource) override;
29  void zwp_primary_selection_offer_v1_destroy_resource(Resource *resource) override;
30 };
31 
32 PrimarySelectionOfferV1InterfacePrivate::PrimarySelectionOfferV1InterfacePrivate(PrimarySelectionOfferV1Interface *_q,
33  AbstractDataSource *source,
34  wl_resource *resource)
35  : QtWaylandServer::zwp_primary_selection_offer_v1(resource)
36  , q(_q)
37  , source(source)
38 {
39 }
40 
41 void PrimarySelectionOfferV1InterfacePrivate::zwp_primary_selection_offer_v1_destroy(QtWaylandServer::zwp_primary_selection_offer_v1::Resource *resource)
42 {
43  wl_resource_destroy(resource->handle);
44 }
45 
46 void PrimarySelectionOfferV1InterfacePrivate::zwp_primary_selection_offer_v1_destroy_resource(
47  QtWaylandServer::zwp_primary_selection_offer_v1::Resource *resource)
48 {
49  Q_UNUSED(resource)
50  delete q;
51 }
52 
53 void PrimarySelectionOfferV1InterfacePrivate::zwp_primary_selection_offer_v1_receive(Resource *resource, const QString &mimeType, qint32 fd)
54 {
55  Q_UNUSED(resource)
56  if (!source) {
57  close(fd);
58  return;
59  }
60  source->requestData(mimeType, fd);
61 }
62 
63 PrimarySelectionOfferV1Interface::PrimarySelectionOfferV1Interface(AbstractDataSource *source, wl_resource *resource)
64  : QObject()
65  , d(new PrimarySelectionOfferV1InterfacePrivate(this, source, resource))
66 {
67  Q_ASSERT(source);
68  connect(source, &AbstractDataSource::mimeTypeOffered, this, [this](const QString &mimeType) {
69  d->send_offer(mimeType);
70  });
71 }
72 
73 PrimarySelectionOfferV1Interface::~PrimarySelectionOfferV1Interface() = default;
74 
75 void PrimarySelectionOfferV1Interface::sendAllOffers()
76 {
77  for (const QString &mimeType : d->source->mimeTypes()) {
78  d->send_offer(mimeType);
79  }
80 }
81 
82 wl_resource *PrimarySelectionOfferV1Interface::resource() const
83 {
84  return d->resource()->handle;
85 }
86 
87 }
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:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.