summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/qnx/qqnxclipboard.cpp
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer.qnx@kdab.com>2012-03-09 17:21:22 +0000
committerQt by Nokia <qt-info@nokia.com>2012-03-12 13:14:05 +0100
commit9a81e371079d6aab20f6c4a43031857f4172688c (patch)
treef81830baa2d24622a7e9c83ff4759466e2242cce /src/plugins/platforms/qnx/qqnxclipboard.cpp
parent61692bfefec3f15a2be219bdb29893872a7feadf (diff)
Rename blackberry QPA plugin to QNX
Changing the naming scheme from Blackberry to QNX in line with pattern of using platform names. Change-Id: I048a6a18010bc932311d63c8dde19ccab97894c8 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
Diffstat (limited to 'src/plugins/platforms/qnx/qqnxclipboard.cpp')
-rw-r--r--src/plugins/platforms/qnx/qqnxclipboard.cpp244
1 files changed, 244 insertions, 0 deletions
diff --git a/src/plugins/platforms/qnx/qqnxclipboard.cpp b/src/plugins/platforms/qnx/qqnxclipboard.cpp
new file mode 100644
index 0000000000..8931a15139
--- /dev/null
+++ b/src/plugins/platforms/qnx/qqnxclipboard.cpp
@@ -0,0 +1,244 @@
+/***************************************************************************
+**
+** Copyright (C) 2011 - 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT_NO_CLIPBOARD
+
+#include "qqnxclipboard.h"
+
+#include <QtGui/QColor>
+
+#include <QtCore/QDebug>
+#include <QtCore/QMimeData>
+#include <QtCore/QStringList>
+#include <QtCore/QUrl>
+
+#include <clipboard/clipboard.h>
+#include <errno.h>
+
+QT_BEGIN_NAMESPACE
+
+// null terminated array
+static const char *typeList[] = {"text/html", "text/plain", "image/png", "image/jpeg", "application/x-color", 0};
+
+static QByteArray readClipboardBuff(const char *type)
+{
+ char *pbuffer;
+ if (is_clipboard_format_present(type) == 0) {
+ int size = get_clipboard_data(type, &pbuffer);
+ if (size != -1 && pbuffer) {
+ const QByteArray result = QByteArray(pbuffer, size);
+ free(pbuffer);
+ return result;
+ }
+ }
+
+ return QByteArray();
+}
+
+class QQnxClipboard::MimeData : public QMimeData
+{
+ Q_OBJECT
+public:
+ MimeData(QQnxClipboard *clipboard)
+ : QMimeData(),
+ m_clipboard(clipboard),
+ m_userMimeData(0)
+ {
+ Q_ASSERT(clipboard);
+
+ for (int i = 0; typeList[i] != 0; ++i) {
+ m_formatsToCheck << QString::fromUtf8(typeList[i]);
+ }
+ }
+
+ ~MimeData()
+ {
+ delete m_userMimeData;
+ }
+
+ void addFormatToCheck(const QString &format) {
+ m_formatsToCheck << format;
+
+#if defined(QQNXCLIPBOARD_DEBUG)
+ qDebug() << Q_FUNC_INFO << "formats=" << m_formatsToCheck;
+#endif
+ }
+
+ bool hasFormat(const QString &mimetype) const
+ {
+ const bool result = is_clipboard_format_present(mimetype.toUtf8().constData()) == 0;
+#if defined(QQNXCLIPBOARD_DEBUG)
+ qDebug() << Q_FUNC_INFO << "mimetype=" << mimetype << "result=" << result;
+#endif
+ return result;
+ }
+
+ QStringList formats() const
+ {
+ QStringList result;
+
+ Q_FOREACH (const QString &format, m_formatsToCheck) {
+ if (is_clipboard_format_present(format.toUtf8().constData()) == 0)
+ result << format;
+ }
+
+#if defined(QQNXCLIPBOARD_DEBUG)
+ qDebug() << Q_FUNC_INFO << "result=" << result;
+#endif
+ return result;
+ }
+
+ void setUserMimeData(QMimeData *userMimeData)
+ {
+ delete m_userMimeData;
+ m_userMimeData = userMimeData;
+
+ // system clipboard API doesn't allow detection of changes by other applications
+ // simulate an owner change through delayed invocation
+ // basically transfer ownership of data to the system clipboard once event processing resumes
+ if (m_userMimeData)
+ QMetaObject::invokeMethod(this, "releaseOwnership", Qt::QueuedConnection);
+ }
+
+ QMimeData *userMimeData()
+ {
+ return m_userMimeData;
+ }
+
+protected:
+ QVariant retrieveData(const QString &mimetype, QVariant::Type preferredType) const
+ {
+#if defined(QQNXCLIPBOARD_DEBUG)
+ qDebug() << Q_FUNC_INFO << "mimetype=" << mimetype << "preferredType=" << preferredType;
+#endif
+ if (is_clipboard_format_present(mimetype.toUtf8().constData()) != 0)
+ return QMimeData::retrieveData(mimetype, preferredType);
+
+ const QByteArray data = readClipboardBuff(mimetype.toUtf8().constData());
+ return qVariantFromValue(data);
+ }
+
+private Q_SLOTS:
+ void releaseOwnership()
+ {
+ if (m_userMimeData) {
+#if defined(QQNXCLIPBOARD_DEBUG)
+ qDebug() << Q_FUNC_INFO << "user data formats=" << m_userMimeData->formats() << "system formats=" << formats();
+#endif
+ delete m_userMimeData;
+ m_userMimeData = 0;
+ m_clipboard->emitChanged(QClipboard::Clipboard);
+ }
+ }
+
+private:
+ QQnxClipboard * const m_clipboard;
+
+ QSet<QString> m_formatsToCheck;
+ QMimeData *m_userMimeData;
+};
+
+QQnxClipboard::QQnxClipboard()
+ : m_mimeData(new MimeData(this))
+{
+}
+
+QQnxClipboard::~QQnxClipboard()
+{
+ delete m_mimeData;
+}
+
+void QQnxClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode)
+{
+ if (mode != QClipboard::Clipboard)
+ return;
+
+ if (data == m_mimeData || data == m_mimeData->userMimeData())
+ return;
+
+ empty_clipboard();
+
+ m_mimeData->clear();
+ m_mimeData->setUserMimeData(data);
+
+ if (data == 0)
+ return;
+
+ const QStringList formats = data->formats();
+#if defined(QQNXCLIPBOARD_DEBUG)
+ qDebug() << Q_FUNC_INFO << "formats=" << formats;
+#endif
+
+ Q_FOREACH (const QString &format, formats) {
+ const QByteArray buf = data->data(format);
+
+ if (buf.isEmpty())
+ continue;
+
+ int ret = set_clipboard_data(format.toUtf8().data(), buf.size(), buf.data());
+#if defined(QQNXCLIPBOARD_DEBUG)
+ qDebug() << "QQNX: set " << format << "to clipboard, size=" << buf.size() << ";ret=" << ret;
+#endif
+ if (ret)
+ m_mimeData->addFormatToCheck(format);
+ }
+
+ emitChanged(QClipboard::Clipboard);
+}
+
+QMimeData *QQnxClipboard::mimeData(QClipboard::Mode mode)
+{
+ if (mode != QClipboard::Clipboard)
+ return 0;
+
+ if (m_mimeData->userMimeData())
+ return m_mimeData->userMimeData();
+
+ m_mimeData->clear();
+
+ return m_mimeData;
+}
+
+QT_END_NAMESPACE
+
+#include "qqnxclipboard.moc"
+
+#endif //QT_NO_CLIPBOARD