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
9
#
include
"qwaylandinputdevice_p.h"
10
#
include
"qwaylandmimehelper_p.h"
11
#
include
"qwaylandpipewritehelper_p.h"
12
#
include
<
QtCore
/
QFile
>
13
14
#
include
<
QtCore
/
QDebug
>
15
#
if
QT_CONFIG
(
xdg_desktop_portal_file_transfer
)
16
#
include
<
QtGui
/
private
/
qxdgdesktopportalfiletransfer_p
.
h
>
17
#
endif
18
19
#
include
<
algorithm
>
20
#
include
<
unistd
.
h
>
21
#
include
<
signal
.
h
>
22
#
include
<
fcntl
.
h
>
23
24
QT_BEGIN_NAMESPACE
25
using
namespace
std::chrono;
26
27
using
namespace
Qt::StringLiterals;
28
29
namespace
QtWaylandClient
{
30
31
QWaylandDataSource
::
QWaylandDataSource
(
QWaylandDataDeviceManager
*
dataDeviceManager
,
QMimeData
*
mimeData
)
32
:
QtWayland
::
wl_data_source
(
dataDeviceManager
->
create_data_source
())
33
,
m_mime_data
(
mimeData
)
34
{
35
if
(!
mimeData
)
36
return
;
37
const
auto
formats
=
QInternalMimeData
::
formatsHelper
(
mimeData
);
38
for
(
const
QString
&
format
:
formats
) {
39
offer
(
format
);
40
}
41
#
if
QT_CONFIG
(
xdg_desktop_portal_file_transfer
)
42
if
(
mimeData
->
hasUrls
() && !
formats
.
contains
(
QXdgDesktopPortalFileTransfer
::
fileTransferMimeType
())) {
43
const
auto
urls
=
mimeData
->
urls
();
44
if
(
std
::
any_of
(
urls
.
begin
(),
urls
.
end
(),
std
::
mem_fn
(&
QUrl
::
isLocalFile
))) {
45
offer
(
QXdgDesktopPortalFileTransfer
::
fileTransferMimeType
());
46
}
47
}
48
#
endif
49
}
50
51
QWaylandDataSource
::~
QWaylandDataSource
()
52
{
53
destroy
();
54
}
55
56
void
QWaylandDataSource
::
data_source_cancelled
()
57
{
58
Q_EMIT
cancelled
();
59
}
60
61
void
QWaylandDataSource
::
data_source_send
(
const
QString
&
mime_type
,
int32_t
fd
)
62
{
63
QByteArray
content
=
QWaylandMimeHelper
::
getByteArray
(
m_mime_data
,
mime_type
);
64
#
if
QT_CONFIG
(
xdg_desktop_portal_file_transfer
)
65
if
(
content
.
isEmpty
() &&
mime_type
==
QXdgDesktopPortalFileTransfer
::
fileTransferMimeType
()) {
66
QList
<
QUrl
>
urls
=
m_mime_data
->
urls
();
67
urls
.
removeIf
(
std
::
not_fn
(
std
::
mem_fn
(&
QUrl
::
isLocalFile
)));
68
if
(!
urls
.
empty
())
69
content
=
QXdgDesktopPortalFileTransfer
::
exportFiles
(
urls
).
toUtf8
();
70
}
71
#
endif
72
if
(!
content
.
isEmpty
()) {
73
switch
(
QWaylandPipeWriteHelper
::
safeWriteWithTimeout
(
fd
,
content
.
constData
(),
content
.
size
(),
PIPE_BUF
, 5s)) {
74
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Ok
:
75
break
;
76
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Timeout
:
77
qWarning
() <<
"QWaylandDataSource: timeout writing to pipe"
;
78
break
;
79
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Closed
:
80
qWarning
() <<
"QWaylandDataSource: peer closed pipe"
;
81
break
;
82
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Error
:
83
qWarning
() <<
"QWaylandDataSource: write() failed"
;
84
break
;
85
}
86
}
87
close
(
fd
);
88
}
89
90
void
QWaylandDataSource
::
data_source_target
(
const
QString
&
mime_type
)
91
{
92
m_accepted
= !
mime_type
.
isEmpty
();
93
Q_EMIT
dndResponseUpdated
(
m_accepted
,
m_dropAction
);
94
}
95
96
void
QWaylandDataSource
::
data_source_action
(
uint32_t
action
)
97
{
98
Qt
::
DropAction
qtAction
=
Qt
::
IgnoreAction
;
99
100
if
(
action
==
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE
)
101
qtAction
=
Qt
::
MoveAction
;
102
else
if
(
action
==
WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY
)
103
qtAction
=
Qt
::
CopyAction
;
104
105
m_dropAction
=
qtAction
;
106
Q_EMIT
dndResponseUpdated
(
m_accepted
,
m_dropAction
);
107
}
108
109
void
QWaylandDataSource
::
data_source_dnd_finished
()
110
{
111
Q_EMIT
finished
();
112
}
113
114
void
QWaylandDataSource
::
data_source_dnd_drop_performed
()
115
{
116
117
Q_EMIT
dndDropped
(
m_accepted
,
m_dropAction
);
118
}
119
120
}
121
122
QT_END_NAMESPACE
123
124
#
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