1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the plugins of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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 <QtGui/QPlatformClipboard>
48 #include <QtCore/QDebug>
51 void QWaylandDataOffer::offer_sync_callback(void *data,
52 struct wl_callback *wl_callback,
57 QWaylandDataOffer *mime = static_cast<QWaylandDataOffer *>(data);
58 mime->m_receiving_offers = false;
59 wl_callback_destroy(wl_callback);
62 const struct wl_callback_listener QWaylandDataOffer::offer_sync_callback_listener = {
63 QWaylandDataOffer::offer_sync_callback
66 void QWaylandDataOffer::offer(void *data,
67 struct wl_data_offer *wl_data_offer,
70 Q_UNUSED(wl_data_offer);
72 QWaylandDataOffer *data_offer = static_cast<QWaylandDataOffer *>(data);
74 if (!data_offer->m_receiving_offers) {
75 struct wl_callback *callback = wl_display_sync(data_offer->m_display->wl_display());
76 wl_callback_add_listener(callback,&offer_sync_callback_listener,data_offer);
77 data_offer->m_receiving_offers = true;
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_receiving_offers(false)
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