2014-11-04 14:10:22 +00:00
|
|
|
/********************************************************************
|
|
|
|
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) version 3, or any
|
|
|
|
later version accepted by the membership of KDE e.V. (or its
|
|
|
|
successor approved by the membership of KDE e.V.), which shall
|
|
|
|
act as a proxy defined in Section 6 of version 3 of the license.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "datasource_interface.h"
|
2014-11-14 08:45:02 +00:00
|
|
|
#include "datadevicemanager_interface.h"
|
|
|
|
#include "resource_p.h"
|
2014-11-04 14:10:22 +00:00
|
|
|
// Qt
|
|
|
|
#include <QStringList>
|
|
|
|
// Wayland
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
|
|
|
namespace KWayland
|
|
|
|
{
|
|
|
|
namespace Server
|
|
|
|
{
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
class DataSourceInterface::Private : public Resource::Private
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-11-14 08:45:02 +00:00
|
|
|
Private(DataSourceInterface *q, DataDeviceManagerInterface *parent);
|
2014-11-04 14:10:22 +00:00
|
|
|
~Private();
|
2014-11-14 08:45:02 +00:00
|
|
|
void create(wl_client *client, quint32 version, quint32 id) override;
|
2014-11-04 14:10:22 +00:00
|
|
|
|
|
|
|
QStringList mimeTypes;
|
|
|
|
|
|
|
|
private:
|
2014-11-14 09:55:06 +00:00
|
|
|
DataSourceInterface *q_func() {
|
|
|
|
return reinterpret_cast<DataSourceInterface *>(q);
|
|
|
|
}
|
2014-11-04 14:10:22 +00:00
|
|
|
void offer(const QString &mimeType);
|
|
|
|
|
|
|
|
static void offerCallback(wl_client *client, wl_resource *resource, const char *mimeType);
|
|
|
|
static void destroyCallack(wl_client *client, wl_resource *resource);
|
|
|
|
|
|
|
|
const static struct wl_data_source_interface s_interface;
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct wl_data_source_interface DataSourceInterface::Private::s_interface = {
|
|
|
|
offerCallback,
|
|
|
|
destroyCallack
|
|
|
|
};
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
DataSourceInterface::Private::Private(DataSourceInterface *q, DataDeviceManagerInterface *parent)
|
2014-11-14 09:55:06 +00:00
|
|
|
: Resource::Private(q, parent)
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
DataSourceInterface::Private::~Private() = default;
|
2014-11-04 14:10:22 +00:00
|
|
|
|
|
|
|
void DataSourceInterface::Private::destroyCallack(wl_client *client, wl_resource *resource)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
2014-11-14 09:55:06 +00:00
|
|
|
cast<Private>(resource)->q_func()->deleteLater();
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::Private::offerCallback(wl_client *client, wl_resource *resource, const char *mimeType)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
2014-11-14 09:20:43 +00:00
|
|
|
cast<Private>(resource)->offer(QString::fromUtf8(mimeType));
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::Private::offer(const QString &mimeType)
|
|
|
|
{
|
|
|
|
mimeTypes << mimeType;
|
2014-11-14 09:55:06 +00:00
|
|
|
Q_Q(DataSourceInterface);
|
2014-11-04 14:10:22 +00:00
|
|
|
emit q->mimeTypeOffered(mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::Private::create(wl_client *client, quint32 version, quint32 id)
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_ASSERT(!resource);
|
|
|
|
resource = wl_resource_create(client, &wl_data_source_interface, version, id);
|
|
|
|
if (!resource) {
|
2014-11-04 14:10:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-11-14 08:45:02 +00:00
|
|
|
wl_resource_set_implementation(resource, &s_interface, this, unbind);
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent)
|
2014-11-14 08:45:02 +00:00
|
|
|
: Resource(new Private(this, parent))
|
2014-11-04 14:10:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DataSourceInterface::~DataSourceInterface() = default;
|
|
|
|
|
|
|
|
void DataSourceInterface::accept(const QString &mimeType)
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-04 14:10:22 +00:00
|
|
|
// TODO: does this require a sanity check on the possible mimeType?
|
2014-11-14 08:45:02 +00:00
|
|
|
wl_data_source_send_target(d->resource, mimeType.isEmpty() ? nullptr : mimeType.toUtf8().constData());
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::requestData(const QString &mimeType, qint32 fd)
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-04 14:10:22 +00:00
|
|
|
// TODO: does this require a sanity check on the possible mimeType?
|
2014-11-14 08:45:02 +00:00
|
|
|
wl_data_source_send_send(d->resource, mimeType.toUtf8().constData(), int32_t(fd));
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataSourceInterface::cancel()
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
|
|
|
wl_data_source_send_cancelled(d->resource);
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList DataSourceInterface::mimeTypes() const
|
|
|
|
{
|
2014-11-14 08:45:02 +00:00
|
|
|
Q_D();
|
2014-11-04 14:10:22 +00:00
|
|
|
return d->mimeTypes;
|
|
|
|
}
|
|
|
|
|
2014-11-05 14:22:15 +00:00
|
|
|
DataSourceInterface *DataSourceInterface::get(wl_resource *native)
|
|
|
|
{
|
2014-11-14 14:13:06 +00:00
|
|
|
return Private::get<DataSourceInterface>(native);
|
2014-11-05 14:22:15 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 08:45:02 +00:00
|
|
|
DataSourceInterface::Private *DataSourceInterface::d_func() const
|
|
|
|
{
|
|
|
|
return reinterpret_cast<DataSourceInterface::Private*>(d.data());
|
|
|
|
}
|
|
|
|
|
2014-11-05 14:22:15 +00:00
|
|
|
}
|
2014-11-04 14:10:22 +00:00
|
|
|
}
|