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
qqnxclipboard.cpp
Go to the documentation of this file.
1// Copyright (C) 2011 - 2012 Research In Motion
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
5
6#if !defined(QT_NO_CLIPBOARD)
7
9
10#include <QtGui/QColor>
11
12#include <QtCore/QDebug>
13#include <QtCore/QMimeData>
14#include <QtCore/QStringList>
15#include <QtCore/QUrl>
16
17#include <clipboard/clipboard.h>
18#include <errno.h>
19
21
22Q_LOGGING_CATEGORY(lcQpaClipboard, "qt.qpa.clipboard");
23
24// null terminated array
25static const char *typeList[] = {"text/html", "text/plain", "image/png", "image/jpeg", "application/x-color", 0};
26
27static QByteArray readClipboardBuff(const char *type)
28{
29 char *pbuffer;
30 if (is_clipboard_format_present(type) == 0) {
31 int size = get_clipboard_data(type, &pbuffer);
32 if (size != -1 && pbuffer) {
33 const QByteArray result = QByteArray(pbuffer, size);
34 free(pbuffer);
35 return result;
36 }
37 }
38
39 return QByteArray();
40}
41
43{
45public:
47 : QMimeData(),
50 {
52
53 for (int i = 0; typeList[i] != 0; ++i) {
55 }
56 }
57
59 {
60 delete m_userMimeData;
61 }
62
67
69 {
71 qCDebug(lcQpaClipboard) << "mimetype=" << mimetype << "result=" << result;
72 return result;
73 }
74
76 {
78
81 result << format;
82 }
83
84 qCDebug(lcQpaClipboard) << "result=" << result;
85 return result;
86 }
87
89 {
90 delete m_userMimeData;
92
93 // system clipboard API doesn't allow detection of changes by other applications
94 // simulate an owner change through delayed invocation
95 // basically transfer ownership of data to the system clipboard once event processing resumes
97 QMetaObject::invokeMethod(this, "releaseOwnership", Qt::QueuedConnection);
98 }
99
101 {
102 return m_userMimeData;
103 }
104
105protected:
115
116private Q_SLOTS:
117 void releaseOwnership()
118 {
119 if (m_userMimeData) {
120 qCDebug(lcQpaClipboard) << "user data formats=" << m_userMimeData->formats() << "system formats=" << formats();
121 delete m_userMimeData;
122 m_userMimeData = 0;
124 }
125 }
126
127private:
129
130 QSet<QString> m_formatsToCheck;
131 QMimeData *m_userMimeData;
132};
133
135 : m_mimeData(new MimeData(this))
136{
137}
138
140{
141 delete m_mimeData;
142}
143
144void QQnxClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode)
145{
146 if (mode != QClipboard::Clipboard)
147 return;
148
149 if (m_mimeData == data)
150 return;
151
152 if (m_mimeData->userMimeData() && m_mimeData->userMimeData() == data)
153 return;
154
155 empty_clipboard();
156
157 m_mimeData->clear();
158 m_mimeData->setUserMimeData(data);
159
160 if (data == 0) {
161 emitChanged(QClipboard::Clipboard);
162 return;
163 }
164
165 const QStringList formats = data->formats();
166 qCDebug(lcQpaClipboard) << "formats=" << formats;
167
168 Q_FOREACH (const QString &format, formats) {
169 const QByteArray buf = data->data(format);
170
171 if (buf.isEmpty())
172 continue;
173
174 int ret = set_clipboard_data(format.toUtf8().data(), buf.size(), buf.data());
175 qCDebug(lcQpaClipboard) << "set " << format << "to clipboard, size=" << buf.size() << ";ret=" << ret;
176 if (ret)
177 m_mimeData->addFormatToCheck(format);
178 }
179
180 emitChanged(QClipboard::Clipboard);
181}
182
183QMimeData *QQnxClipboard::mimeData(QClipboard::Mode mode)
184{
185 if (mode != QClipboard::Clipboard)
186 return 0;
187
188 if (m_mimeData->userMimeData())
189 return m_mimeData->userMimeData();
190
191 m_mimeData->clear();
192
193 return m_mimeData;
194}
195
196QT_END_NAMESPACE
197
198#include "qqnxclipboard.moc"
199
200#endif //QT_NO_CLIPBOARD
QMimeData * mimeData(QClipboard::Mode mode=QClipboard::Clipboard) override
void setMimeData(QMimeData *data, QClipboard::Mode mode=QClipboard::Clipboard) override
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
static QByteArray readClipboardBuff(const char *type)
static const char * typeList[]