summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qclipboard_s60.cpp
diff options
context:
space:
mode:
authorTitta Heikkala <EXT-Titta.2.Heikkala@nokia.com>2010-10-21 08:09:33 (GMT)
committerJanne Koskinen <janne.p.koskinen@digia.com>2010-10-21 08:09:33 (GMT)
commita3ceea583b9d14f809e4bf24a9c86fb9179a7797 (patch)
treeb9f688444cf148f8e7f4a763bfdf21d5ef4ac9c1 /src/gui/kernel/qclipboard_s60.cpp
parent80f031dfca7c161de4461514dfd8d9d664ea2f03 (diff)
downloadQt-a3ceea583b9d14f809e4bf24a9c86fb9179a7797.zip
Qt-a3ceea583b9d14f809e4bf24a9c86fb9179a7797.tar.gz
Qt-a3ceea583b9d14f809e4bf24a9c86fb9179a7797.tar.bz2
Support for clipboard between Qt and Symbian applications
Clipboard now supports copying text between Qt and Symbian applications. Text is always copied to QClipboard and to Symbian clipboard. If QClipboard is empty, Symbian clipboard is checked and text is pasted from there. Corresponding test cases added. Task-number: QT-2085 Reviewed-by: Janne Koskinen Merge-request: 870 Reviewed-by: Janne Koskinen <janne.p.koskinen@digia.com>
Diffstat (limited to 'src/gui/kernel/qclipboard_s60.cpp')
-rw-r--r--src/gui/kernel/qclipboard_s60.cpp85
1 files changed, 75 insertions, 10 deletions
diff --git a/src/gui/kernel/qclipboard_s60.cpp b/src/gui/kernel/qclipboard_s60.cpp
index f07e066..7b145a8 100644
--- a/src/gui/kernel/qclipboard_s60.cpp
+++ b/src/gui/kernel/qclipboard_s60.cpp
@@ -50,16 +50,15 @@
#include "qwidget.h"
#include "qevent.h"
#include "private/qcore_symbian_p.h"
+#include "txtetext.h"
#include <QtDebug>
// Symbian's clipboard
#include <baclipb.h>
QT_BEGIN_NAMESPACE
-//### Mime Type mapping to UIDs
-
const TUid KQtCbDataStream = {0x2001B2DD};
-
+const TInt KPlainTextBegin = 0;
class QClipboardData
{
@@ -141,7 +140,6 @@ void writeToStreamLX(const QMimeData* aData, RWriteStream& aStream)
{
HBufC* stringData = TPtrC(reinterpret_cast<const TUint16*>((*iter).utf16())).AllocLC();
QByteArray ba = aData->data((*iter));
- qDebug() << "copy to clipboard mime: " << *iter << " data: " << ba;
// mime type
aStream << TCardinality(stringData->Size());
aStream << *(stringData);
@@ -152,6 +150,43 @@ void writeToStreamLX(const QMimeData* aData, RWriteStream& aStream)
}
}
+void writeToSymbianStoreLX(const QMimeData* aData, CClipboard* clipboard)
+{
+ // This function both leaves and throws exceptions. There must be no destructor
+ // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
+ if (aData->hasText()) {
+ CPlainText* text = CPlainText::NewL();
+ CleanupStack::PushL(text);
+
+ TPtrC textPtr(qt_QString2TPtrC(aData->text()));
+ text->InsertL(KPlainTextBegin, textPtr);
+ text->CopyToStoreL(clipboard->Store(), clipboard->StreamDictionary(),
+ KPlainTextBegin, textPtr.Length());
+ CleanupStack::PopAndDestroy(text);
+ }
+}
+
+void readSymbianStoreLX(QMimeData* aData, CClipboard* clipboard)
+{
+ // This function both leaves and throws exceptions. There must be no destructor
+ // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
+ CPlainText* text = CPlainText::NewL();
+ CleanupStack::PushL(text);
+ TInt dataLength = text->PasteFromStoreL(clipboard->Store(), clipboard->StreamDictionary(),
+ KPlainTextBegin);
+ if (dataLength == 0) {
+ User::Leave(KErrNotFound);
+ }
+ HBufC* hBuf = HBufC::NewL(dataLength);
+ TPtr buf = hBuf->Des();
+ text->Extract(buf, KPlainTextBegin, dataLength);
+
+ QString string = qt_TDesC2QString(buf);
+ CleanupStack::PopAndDestroy(text);
+
+ aData->setText(string);
+}
+
void readFromStreamLX(QMimeData* aData,RReadStream& aStream)
{
// This function both leaves and throws exceptions. There must be no destructor
@@ -174,7 +209,6 @@ void readFromStreamLX(QMimeData* aData,RReadStream& aStream)
ba.reserve(dataSize);
aStream.ReadL(reinterpret_cast<uchar*>(ba.data_ptr()->data),dataSize);
ba.data_ptr()->size = dataSize;
- qDebug() << "paste from clipboard mime: " << mimeType << " data: " << ba;
aData->setData(mimeType,ba);
}
}
@@ -192,18 +226,41 @@ const QMimeData* QClipboard::mimeData(Mode mode) const
{
if (mode != Clipboard) return 0;
QClipboardData *d = clipboardData();
+ bool dataExists(false);
if (d)
{
TRAPD(err,{
RFs fs = qt_s60GetRFs();
CClipboard* cb = CClipboard::NewForReadingLC(fs);
Q_ASSERT(cb);
+ //stream for qt
RStoreReadStream stream;
TStreamId stid = (cb->StreamDictionary()).At(KQtCbDataStream);
- stream.OpenLC(cb->Store(),stid);
- QT_TRYCATCH_LEAVING(readFromStreamLX(d->source(),stream));
- CleanupStack::PopAndDestroy(2,cb);
- return d->source();
+ if (stid != 0) {
+ stream.OpenLC(cb->Store(),stid);
+ QT_TRYCATCH_LEAVING(readFromStreamLX(d->source(),stream));
+ CleanupStack::PopAndDestroy(&stream);
+ dataExists = true;
+ }
+ else {
+ //symbian clipboard
+ RStoreReadStream symbianStream;
+ TStreamId symbianStId = (cb->StreamDictionary()).At(KClipboardUidTypePlainText);
+ if (symbianStId != 0) {
+ symbianStream.OpenLC(cb->Store(), symbianStId);
+ QT_TRYCATCH_LEAVING(readSymbianStoreLX(d->source(), cb));
+ CleanupStack::PopAndDestroy(&symbianStream);
+ dataExists = true;
+ }
+ }
+ CleanupStack::PopAndDestroy(cb);
+ if (dataExists) {
+ return d->source();
+ }
+ else {
+ return 0;
+ }
+
});
if (err != KErrNone){
qDebug()<< "clipboard is empty/err: " << err;
@@ -223,6 +280,7 @@ void QClipboard::setMimeData(QMimeData* src, Mode mode)
TRAPD(err,{
RFs fs = qt_s60GetRFs();
CClipboard* cb = CClipboard::NewForWritingLC(fs);
+ //stream for qt
RStoreWriteStream stream;
TStreamId stid = stream.CreateLC(cb->Store());
QT_TRYCATCH_LEAVING(writeToStreamLX(src,stream));
@@ -230,7 +288,14 @@ void QClipboard::setMimeData(QMimeData* src, Mode mode)
stream.CommitL();
(cb->StreamDictionary()).AssignL(KQtCbDataStream,stid);
cb->CommitL();
- CleanupStack::PopAndDestroy(2,cb);
+
+ //stream for symbian
+ RStoreWriteStream symbianStream;
+ TStreamId symbianStId = symbianStream.CreateLC(cb->Store());
+ QT_TRYCATCH_LEAVING(writeToSymbianStoreLX(src, cb));
+ (cb->StreamDictionary()).AssignL(KClipboardUidTypePlainText, symbianStId);
+ cb->CommitL();
+ CleanupStack::PopAndDestroy(3,cb);
});
if (err != KErrNone){
qDebug()<< "clipboard write err :" << err;