1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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