2020-05-12 11:26:57 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2020-05-28 07:25:56 +00:00
|
|
|
#include "datacontroloffer_v1_interface.h"
|
|
|
|
#include "datacontroldevice_v1_interface.h"
|
|
|
|
#include "datacontrolsource_v1_interface.h"
|
2020-05-12 11:26:57 +00:00
|
|
|
// Qt
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QPointer>
|
|
|
|
// Wayland
|
|
|
|
#include <qwayland-server-wlr-data-control-unstable-v1.h>
|
|
|
|
// system
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
namespace KWaylandServer
|
|
|
|
{
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
class DataControlOfferV1InterfacePrivate : public QtWaylandServer::zwlr_data_control_offer_v1
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlOfferV1InterfacePrivate(DataControlOfferV1Interface *q, AbstractDataSource *source, wl_resource *resource);
|
2020-05-28 07:21:32 +00:00
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlOfferV1Interface *q;
|
2020-05-12 11:26:57 +00:00
|
|
|
QPointer<AbstractDataSource> source;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void zwlr_data_control_offer_v1_receive(Resource *resource, const QString &mime_type, int32_t fd) override;
|
|
|
|
void zwlr_data_control_offer_v1_destroy(Resource *resource) override;
|
|
|
|
void zwlr_data_control_offer_v1_destroy_resource(Resource *resource) override;
|
|
|
|
};
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlOfferV1InterfacePrivate::DataControlOfferV1InterfacePrivate(DataControlOfferV1Interface *_q, AbstractDataSource *source, wl_resource *resource)
|
2020-05-12 11:26:57 +00:00
|
|
|
: QtWaylandServer::zwlr_data_control_offer_v1(resource)
|
|
|
|
, q(_q)
|
|
|
|
, source(source)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_destroy(QtWaylandServer::zwlr_data_control_offer_v1::Resource *resource)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
wl_resource_destroy(resource->handle);
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_destroy_resource(QtWaylandServer::zwlr_data_control_offer_v1::Resource *resource)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
delete q;
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlOfferV1InterfacePrivate::zwlr_data_control_offer_v1_receive(Resource *resource, const QString &mimeType, qint32 fd)
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
if (!source) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
source->requestData(mimeType, fd);
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlOfferV1Interface::DataControlOfferV1Interface(AbstractDataSource *source, wl_resource *resource)
|
2020-05-12 11:26:57 +00:00
|
|
|
: QObject()
|
2020-05-28 07:25:56 +00:00
|
|
|
, d(new DataControlOfferV1InterfacePrivate(this, source, resource))
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(source);
|
|
|
|
connect(source, &AbstractDataSource::mimeTypeOffered, this,
|
|
|
|
[this](const QString &mimeType) {
|
|
|
|
d->send_offer(mimeType);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
DataControlOfferV1Interface::~DataControlOfferV1Interface() = default;
|
2020-05-12 11:26:57 +00:00
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
void DataControlOfferV1Interface::sendAllOffers()
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(d->source);
|
|
|
|
for (const QString &mimeType : d->source->mimeTypes()) {
|
|
|
|
d->send_offer(mimeType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 07:25:56 +00:00
|
|
|
wl_resource *DataControlOfferV1Interface::resource() const
|
2020-05-12 11:26:57 +00:00
|
|
|
{
|
|
|
|
return d->resource()->handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|