Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the plugins of the Qt Toolkit. |
7 | ** |
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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qwaylanddatasource_p.h" |
41 | #include "qwaylanddataoffer_p.h" |
42 | #include "qwaylanddatadevicemanager_p.h" |
43 | #include "qwaylandinputdevice_p.h" |
44 | #include "qwaylandmimehelper_p.h" |
45 | |
46 | #include <QtCore/QFile> |
47 | |
48 | #include <QtCore/QDebug> |
49 | |
50 | #include <unistd.h> |
51 | #include <signal.h> |
52 | |
53 | QT_BEGIN_NAMESPACE |
54 | |
55 | namespace QtWaylandClient { |
56 | |
57 | QWaylandDataSource::QWaylandDataSource(QWaylandDataDeviceManager *dataDeviceManager, QMimeData *mimeData) |
58 | : QtWayland::wl_data_source(dataDeviceManager->create_data_source()) |
59 | , m_mime_data(mimeData) |
60 | { |
61 | if (!mimeData) |
62 | return; |
63 | const auto formats = mimeData->formats(); |
64 | for (const QString &format : formats) { |
65 | offer(format); |
66 | } |
67 | } |
68 | |
69 | QWaylandDataSource::~QWaylandDataSource() |
70 | { |
71 | destroy(); |
72 | } |
73 | |
74 | QMimeData * QWaylandDataSource::mimeData() const |
75 | { |
76 | return m_mime_data; |
77 | } |
78 | |
79 | void QWaylandDataSource::data_source_cancelled() |
80 | { |
81 | Q_EMIT cancelled(); |
82 | } |
83 | |
84 | void QWaylandDataSource::data_source_send(const QString &mime_type, int32_t fd) |
85 | { |
86 | QByteArray content = QWaylandMimeHelper::getByteArray(m_mime_data, mime_type); |
87 | if (!content.isEmpty()) { |
88 | // Create a sigpipe handler that does nothing, or clients may be forced to terminate |
89 | // if the pipe is closed in the other end. |
90 | struct sigaction action, oldAction; |
91 | action.sa_handler = SIG_IGN; |
92 | sigemptyset (&action.sa_mask); |
93 | action.sa_flags = 0; |
94 | |
95 | sigaction(SIGPIPE, &action, &oldAction); |
96 | write(fd, content.constData(), content.size()); |
97 | sigaction(SIGPIPE, &oldAction, nullptr); |
98 | } |
99 | close(fd); |
100 | } |
101 | |
102 | void QWaylandDataSource::data_source_target(const QString &mime_type) |
103 | { |
104 | Q_EMIT targetChanged(mime_type); |
105 | } |
106 | |
107 | } |
108 | |
109 | QT_END_NAMESPACE |
110 |
Warning: That file was not part of the compilation database. It may have many parsing errors.