1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qwaylanddataoffer.h"
43 #include "qwaylanddatadevicemanager.h"
45 #include <QtGui/private/qguiapplication_p.h>
46 #include <qpa/qplatformclipboard.h>
48 #include <QtCore/QDebug>
51 void QWaylandDataOffer::offer_sync_callback(void *data,
52 struct wl_callback *callback,
56 QWaylandDataOffer *mime = static_cast<QWaylandDataOffer *>(data);
57 if (mime->m_receiveSyncCallback == callback) {
58 mime->m_receiveSyncCallback = 0;
59 wl_callback_destroy(callback);
63 const struct wl_callback_listener QWaylandDataOffer::offer_sync_callback_listener = {
64 QWaylandDataOffer::offer_sync_callback
67 void QWaylandDataOffer::offer(void *data,
68 struct wl_data_offer *wl_data_offer,
71 Q_UNUSED(wl_data_offer);
73 QWaylandDataOffer *data_offer = static_cast<QWaylandDataOffer *>(data);
75 if (!data_offer->m_receiveSyncCallback) {
76 data_offer->m_receiveSyncCallback = wl_display_sync(data_offer->m_display->wl_display());
77 wl_callback_add_listener(data_offer->m_receiveSyncCallback, &offer_sync_callback_listener, data_offer);
80 data_offer->m_offered_mime_types.append(QString::fromLocal8Bit(type));
81 // qDebug() << data_offer->m_offered_mime_types;
84 const struct wl_data_offer_listener QWaylandDataOffer::data_offer_listener = {
85 QWaylandDataOffer::offer
88 QWaylandDataOffer::QWaylandDataOffer(QWaylandDisplay *display, struct wl_data_offer *data_offer)
90 , m_receiveSyncCallback(0)
92 m_data_offer = data_offer;
93 wl_data_offer_set_user_data(m_data_offer,this);
94 wl_data_offer_add_listener(m_data_offer,&data_offer_listener,this);
97 QWaylandDataOffer::~QWaylandDataOffer()
99 wl_data_offer_destroy(m_data_offer);
102 bool QWaylandDataOffer::hasFormat_sys(const QString &mimeType) const
104 return m_offered_mime_types.contains(mimeType);
107 QStringList QWaylandDataOffer::formats_sys() const
109 return m_offered_mime_types;
112 QVariant QWaylandDataOffer::retrieveData_sys(const QString &mimeType, QVariant::Type type) const
115 if (m_offered_mime_types.isEmpty())
119 if (pipe(pipefd) == -1) {
120 qWarning("QWaylandMimeData: pipe() failed");
124 QByteArray mimeTypeBa = mimeType.toLatin1();
125 wl_data_offer_receive(m_data_offer,mimeTypeBa.constData(),pipefd[1]);
127 m_display->forceRoundTrip();
133 while ((n = QT_READ(pipefd[0], &buf, sizeof buf)) > 0) {
134 content.append(buf, n);
141 struct wl_data_offer *QWaylandDataOffer::handle() const