Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylanddatasource.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qwaylanddatasource_p.h"
6
#
include
"qwaylanddataoffer_p.h"
7
#
include
"qwaylanddatadevicemanager_p.h"
8
#
include
"qwaylandinputdevice_p.h"
9
#
include
"qwaylandmimehelper_p.h"
10
#
include
"qwaylandpipewritehelper_p.h"
11
12
#
include
<
QtCore
/
QFile
>
13
14
#
include
<
QtCore
/
QDebug
>
15
16
#
include
<
unistd
.
h
>
17
#
include
<
signal
.
h
>
18
#
include
<
fcntl
.
h
>
19
20
QT_BEGIN_NAMESPACE
21
using
namespace
std::chrono;
22
23
namespace
QtWaylandClient
{
24
25
QWaylandDataSource
::
QWaylandDataSource
(
QWaylandDataDeviceManager
*
dataDeviceManager
,
QMimeData
*
mimeData
)
26
:
QtWayland
::
wl_data_source
(
dataDeviceManager
->
create_data_source
())
27
,
m_mime_data
(
mimeData
)
28
{
29
if
(!
mimeData
)
30
return
;
31
const
auto
formats
=
QInternalMimeData
::
formatsHelper
(
mimeData
);
32
for
(
const
QString
&
format
:
formats
) {
33
offer
(
format
);
34
}
35
}
36
37
QWaylandDataSource
::~
QWaylandDataSource
()
38
{
39
destroy
();
40
}
41
42
void
QWaylandDataSource
::
data_source_cancelled
()
43
{
44
Q_EMIT
cancelled
();
45
}
46
47
void
QWaylandDataSource
::
data_source_send
(
const
QString
&
mime_type
,
int32_t
fd
)
48
{
49
QByteArray
content
=
QWaylandMimeHelper
::
getByteArray
(
m_mime_data
,
mime_type
);
50
if
(!
content
.
isEmpty
()) {
51
switch
(
QWaylandPipeWriteHelper
::
safeWriteWithTimeout
(
fd
,
content
.
constData
(),
content
.
size
(),
PIPE_BUF
, 5s)) {
52
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Ok
:
53
break
;
54
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Timeout
:
55
qWarning
() <<
"QWaylandDataSource: timeout writing to pipe"
;
56
break
;
57
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Closed
:
58
qWarning
() <<
"QWaylandDataSource: peer closed pipe"
;
59
break
;
60
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Error
:
61
qWarning
() <<
"QWaylandDataSource: write() failed"
;
62
break
;
63
}
64
}
65
close
(
fd
);
66
}
67
68
void
QWaylandDataSource
::
data_source_target
(
const
QString
&
mime_type
)
69
{
70
m_accepted
= !
mime_type
.
isEmpty
();
71
Q_EMIT
dndResponseUpdated
(
m_accepted
,
m_dropAction
);
72
}
73
74
void
QWaylandDataSource
::
data_source_action
(
uint32_t
action
)
75
{
76
Qt
::
DropAction
qtAction
=
Qt
::
IgnoreAction
;
77
78
if
(
action
==
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE
)
79
qtAction
=
Qt
::
MoveAction
;
80
else
if
(
action
==
WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY
)
81
qtAction
=
Qt
::
CopyAction
;
82
83
m_dropAction
=
qtAction
;
84
Q_EMIT
dndResponseUpdated
(
m_accepted
,
m_dropAction
);
85
}
86
87
void
QWaylandDataSource
::
data_source_dnd_finished
()
88
{
89
Q_EMIT
finished
();
90
}
91
92
void
QWaylandDataSource
::
data_source_dnd_drop_performed
()
93
{
94
95
Q_EMIT
dndDropped
(
m_accepted
,
m_dropAction
);
96
}
97
98
}
99
100
QT_END_NAMESPACE
101
102
#
include
"moc_qwaylanddatasource_p.cpp"
QtWaylandClient
Definition
qwaylandclientextension.h:16
qtbase
src
plugins
platforms
wayland
qwaylanddatasource.cpp
Generated on
for Qt by
1.16.1