Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qhaikuclipboard.cpp
Go to the documentation of this file.
1
// Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias Koenig <tobias.koenig@kdab.com>
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
if
!
defined
(
QT_NO_CLIPBOARD
)
5
6
#
include
"qhaikuclipboard.h"
7
8
#
include
<
QMimeData
>
9
#
include
<
QThread
>
10
11
#
include
<
Clipboard
.
h
>
12
13
using
namespace
Qt::StringLiterals;
14
15
QHaikuClipboard::QHaikuClipboard()
16
: m_systemMimeData(
nullptr
)
17
, m_userMimeData(
nullptr
)
18
{
19
if
(be_clipboard)
20
be_clipboard->StartWatching(BMessenger(
this
));
21
}
22
23
QHaikuClipboard::~QHaikuClipboard()
24
{
25
if
(be_clipboard)
26
be_clipboard->StopWatching(BMessenger(
this
));
27
28
delete
m_userMimeData;
29
delete
m_systemMimeData;
30
}
31
32
QMimeData *QHaikuClipboard::mimeData(QClipboard::Mode mode)
33
{
34
if
(mode != QClipboard::Clipboard)
35
return
0;
36
37
if
(m_userMimeData)
38
return
m_userMimeData;
39
40
if
(!be_clipboard->Lock())
41
return
0;
42
43
if
(!m_systemMimeData)
44
m_systemMimeData =
new
QMimeData();
45
else
46
m_systemMimeData->clear();
47
48
const
BMessage *clipboard = be_clipboard->Data();
49
if
(clipboard) {
50
char
*name =
nullptr
;
51
uint32 type = 0;
52
int32 count = 0;
53
54
for
(
int
i = 0; clipboard->GetInfo(B_MIME_TYPE, i, &name, &type, &count) == B_OK; i++) {
55
const
void
*data =
nullptr
;
56
int32 dataLen = 0;
57
58
const
status_t status = clipboard->FindData(name, B_MIME_TYPE, &data, &dataLen);
59
if
(dataLen && (status == B_OK)) {
60
const
QLatin1StringView format(name);
61
if
(format ==
"text/plain"_L1
) {
62
m_systemMimeData->setText(QString::fromLocal8Bit(
reinterpret_cast
<
const
char
*>(data), dataLen));
63
}
else
if
(format ==
"text/html"_L1
) {
64
m_systemMimeData->setHtml(QString::fromLocal8Bit(
reinterpret_cast
<
const
char
*>(data), dataLen));
65
}
else
{
66
m_systemMimeData->setData(format, QByteArray(
reinterpret_cast
<
const
char
*>(data), dataLen));
67
}
68
}
69
}
70
}
71
72
be_clipboard->Unlock();
73
74
return
m_systemMimeData;
75
}
76
77
void
QHaikuClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode)
78
{
79
if
(mode != QClipboard::Clipboard)
80
return
;
81
82
if
(mimeData) {
83
if
(m_systemMimeData == mimeData)
84
return
;
85
86
if
(m_userMimeData == mimeData)
87
return
;
88
}
89
90
if
(!be_clipboard->Lock())
91
return
;
92
93
be_clipboard->Clear();
94
if
(mimeData) {
95
BMessage *clipboard = be_clipboard->Data();
96
if
(clipboard) {
97
const
QStringList formats = mimeData->formats();
98
Q_FOREACH (
const
QString &format, formats) {
99
const
QByteArray data = mimeData->data(format).data();
100
clipboard->AddData(format.toUtf8(), B_MIME_TYPE, data, data.count());
101
}
102
}
103
}
104
105
if
(be_clipboard->Commit() != B_OK)
106
qWarning(
"Unable to store mime data on clipboard"
);
107
108
be_clipboard->Unlock();
109
110
m_userMimeData = mimeData;
111
112
emitChanged(QClipboard::Clipboard);
113
}
114
115
bool
QHaikuClipboard::supportsMode(QClipboard::Mode mode)
const
116
{
117
return
(mode == QClipboard::Clipboard);
118
}
119
120
bool
QHaikuClipboard::ownsMode(QClipboard::Mode mode)
const
121
{
122
Q_UNUSED(mode);
123
124
return
false
;
125
}
126
127
void
QHaikuClipboard::MessageReceived(BMessage* message)
128
{
129
if
(message->what == B_CLIPBOARD_CHANGED) {
130
delete
m_userMimeData;
131
m_userMimeData =
nullptr
;
132
133
emitChanged(QClipboard::Clipboard);
134
}
135
136
BHandler::MessageReceived(message);
137
}
138
139
#
endif
qtbase
src
plugins
platforms
haiku
qhaikuclipboard.cpp
Generated on
for Qt by
1.18.0