-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If a Qt application shall use the clipboard, this must be configured as: <config clipboard="yes"> Fixes #1749
- Loading branch information
Showing
7 changed files
with
244 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
repos/libports/src/lib/qt5/qtbase/src/plugins/platforms/nitpicker/qgenodeclipboard.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* \brief QGenodeClipboard | ||
* \author Christian Prochaska | ||
* \date 2015-09-18 | ||
*/ | ||
|
||
/* | ||
* Copyright (C) 2015 Genode Labs GmbH | ||
* | ||
* This file is part of the Genode OS framework, which is distributed | ||
* under the terms of the GNU General Public License version 2. | ||
*/ | ||
|
||
#include "qgenodeclipboard.h" | ||
|
||
#ifndef QT_NO_CLIPBOARD | ||
|
||
/* Genode includes */ | ||
#include <os/config.h> | ||
#include <util/xml_node.h> | ||
|
||
/* Qt includes */ | ||
#include <QMimeData> | ||
|
||
QT_BEGIN_NAMESPACE | ||
|
||
|
||
static constexpr bool verbose = false; | ||
|
||
|
||
QGenodeClipboard::QGenodeClipboard(Genode::Signal_receiver &sig_rcv) | ||
: _clipboard_signal_dispatcher(sig_rcv, *this, &QGenodeClipboard::_handle_clipboard) | ||
{ | ||
try { | ||
|
||
if (Genode::config()->xml_node().attribute("clipboard").has_value("yes")) { | ||
|
||
try { | ||
|
||
_clipboard_ds = new (Genode::env()->heap()) | ||
Genode::Attached_rom_dataspace("clipboard"); | ||
|
||
_clipboard_ds->sigh(_clipboard_signal_dispatcher); | ||
_clipboard_ds->update(); | ||
|
||
} catch (...) { } | ||
|
||
try { | ||
_clipboard_reporter = new (Genode::env()->heap()) | ||
Genode::Reporter("clipboard"); | ||
_clipboard_reporter->enabled(true); | ||
} catch (...) { } | ||
|
||
} | ||
|
||
} catch (...) { } | ||
} | ||
|
||
|
||
QGenodeClipboard::~QGenodeClipboard() | ||
{ | ||
free(_decoded_clipboard_content); | ||
destroy(Genode::env()->heap(), _clipboard_ds); | ||
destroy(Genode::env()->heap(), _clipboard_reporter); | ||
} | ||
|
||
|
||
void QGenodeClipboard::_handle_clipboard(unsigned int) | ||
{ | ||
emitChanged(QClipboard::Clipboard); | ||
} | ||
|
||
|
||
QMimeData *QGenodeClipboard::mimeData(QClipboard::Mode mode) | ||
{ | ||
if (!_clipboard_ds) | ||
return 0; | ||
|
||
_clipboard_ds->update(); | ||
|
||
if (!_clipboard_ds->is_valid()) { | ||
if (verbose) | ||
PERR("invalid clipboard dataspace"); | ||
return 0; | ||
} | ||
|
||
char *xml_data = _clipboard_ds->local_addr<char>(); | ||
|
||
try { | ||
Genode::Xml_node node(xml_data); | ||
|
||
if (!node.has_type("clipboard")) { | ||
PERR("invalid clipboard xml syntax"); | ||
return 0; | ||
} | ||
|
||
free(_decoded_clipboard_content); | ||
|
||
_decoded_clipboard_content = (char*)malloc(node.content_size()); | ||
|
||
if (!_decoded_clipboard_content) { | ||
PERR("could not allocate buffer for decoded clipboard content"); | ||
return 0; | ||
} | ||
|
||
_mimedata->setText(QString::fromUtf8(_decoded_clipboard_content, | ||
node.decoded_content(_decoded_clipboard_content, | ||
node.content_size()))); | ||
|
||
} catch (Genode::Xml_node::Invalid_syntax) { | ||
PERR("invalid clipboard xml syntax"); | ||
return 0; | ||
} | ||
|
||
return _mimedata; | ||
} | ||
|
||
|
||
void QGenodeClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) | ||
{ | ||
if (!data || !data->hasText() || !supportsMode(mode)) | ||
return; | ||
|
||
QString text = data->text(); | ||
QByteArray utf8text = text.toUtf8(); | ||
|
||
if (!_clipboard_reporter) | ||
return; | ||
|
||
try { | ||
Genode::Reporter::Xml_generator xml(*_clipboard_reporter, [&] () { | ||
xml.append_sanitized(utf8text.constData(), utf8text.size()); }); | ||
} catch (...) { | ||
PERR("could not write clipboard data"); | ||
} | ||
} | ||
|
||
QT_END_NAMESPACE | ||
|
||
#endif /* QT_NO_CLIPBOARD */ |
57 changes: 57 additions & 0 deletions
57
repos/libports/src/lib/qt5/qtbase/src/plugins/platforms/nitpicker/qgenodeclipboard.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* \brief QGenodeClipboard | ||
* \author Christian Prochaska | ||
* \date 2015-09-18 | ||
*/ | ||
|
||
/* | ||
* Copyright (C) 2015 Genode Labs GmbH | ||
* | ||
* This file is part of the Genode OS framework, which is distributed | ||
* under the terms of the GNU General Public License version 2. | ||
*/ | ||
|
||
#ifndef _QGENODECLIPBOARD_H_ | ||
#define _QGENODECLIPBOARD_H_ | ||
|
||
#include <QtCore/qglobal.h> | ||
|
||
#ifndef QT_NO_CLIPBOARD | ||
|
||
/* Genode includes */ | ||
#include <os/attached_rom_dataspace.h> | ||
#include <os/reporter.h> | ||
#include <qoost/qmember.h> | ||
|
||
/* Qt includes */ | ||
#include <qpa/qplatformclipboard.h> | ||
|
||
QT_BEGIN_NAMESPACE | ||
|
||
class QGenodeClipboard : public QPlatformClipboard | ||
{ | ||
private: | ||
|
||
Genode::Attached_rom_dataspace *_clipboard_ds = nullptr; | ||
Genode::Signal_dispatcher<QGenodeClipboard> _clipboard_signal_dispatcher; | ||
|
||
Genode::Reporter *_clipboard_reporter = nullptr; | ||
|
||
char *_decoded_clipboard_content = nullptr; | ||
|
||
QMember<QMimeData> _mimedata; | ||
|
||
void _handle_clipboard(unsigned int); | ||
|
||
public: | ||
|
||
QGenodeClipboard(Genode::Signal_receiver &sig_rcv); | ||
~QGenodeClipboard(); | ||
QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard); | ||
void setMimeData(QMimeData *data, QClipboard::Mode mode = QClipboard::Clipboard); | ||
}; | ||
|
||
QT_END_NAMESPACE | ||
|
||
#endif /* QT_NO_CLIPBOARD */ | ||
#endif /* _QGENODECLIPBOARD_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters