From 431bb1e39f2df69329607b96f7178aea42962318 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Tue, 22 Nov 2011 14:19:27 +0000 Subject: Symbian: don't merge native clipboard, overwrite. If copying text from a Qt application that has both plaintext and formatted text representations, then S60 applications only see the plaintext. If copying data from an S60 application, the Qt application can see the plaintext. However as this was merged with the existing clipboard contents in Qt, the formatted text was unchanged. Now, we clear the internal clipboard QMimeData before writing the contents of the symbian clipboard to it. This ensures stale data from a previous copy is not left behind. Task-Number: ou1cimx1#927246 Reviewed-By: mread --- src/gui/kernel/qclipboard_s60.cpp | 3 ++ tests/auto/qclipboard/tst_qclipboard.cpp | 64 +++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/gui/kernel/qclipboard_s60.cpp b/src/gui/kernel/qclipboard_s60.cpp index f5314bd..dc812fb 100644 --- a/src/gui/kernel/qclipboard_s60.cpp +++ b/src/gui/kernel/qclipboard_s60.cpp @@ -187,6 +187,7 @@ void readSymbianStoreLX(QMimeData* aData, CClipboard* clipboard) QString string = qt_TDesC2QString(buf); CleanupStack::PopAndDestroy(text); + aData->clear(); aData->setText(string); } @@ -196,6 +197,8 @@ void readFromStreamLX(QMimeData* aData,RReadStream& aStream) // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects. TCardinality mimeTypeCount; aStream >> mimeTypeCount; + if (mimeTypeCount > 0) + aData->clear(); for (int i = 0; i< mimeTypeCount;i++) { // mime type diff --git a/tests/auto/qclipboard/tst_qclipboard.cpp b/tests/auto/qclipboard/tst_qclipboard.cpp index 94981cf..ea470e7 100644 --- a/tests/auto/qclipboard/tst_qclipboard.cpp +++ b/tests/auto/qclipboard/tst_qclipboard.cpp @@ -73,6 +73,7 @@ private slots: #ifdef Q_OS_SYMBIAN void pasteCopySymbian(); void copyPasteSymbian(); + void copyCopyPasteSymbian(); #endif private: @@ -347,17 +348,17 @@ void tst_QClipboard::clearBeforeSetText() QCOMPARE(QApplication::clipboard()->text(), text); } +#ifdef Q_OS_SYMBIAN /* Test that text copied from qt application can be pasted with symbian clipboard */ -#ifdef Q_OS_SYMBIAN // ### This test case only makes sense in symbian void tst_QClipboard::pasteCopySymbian() { if (!nativeClipboardWorking()) QSKIP("Native clipboard not working in this setup", SkipAll); - const QString string("Test string symbian."); + const QString string("Test string qt->symbian."); QApplication::clipboard()->setText(string); const TInt KPlainTextBegin = 0; @@ -381,19 +382,9 @@ void tst_QClipboard::pasteCopySymbian() QCOMPARE(string, storeString); } -#endif -/* - Test that text copied to symbian clipboard - can be pasted to qt clipboard -*/ -#ifdef Q_OS_SYMBIAN -// ### This test case only makes sense in symbian -void tst_QClipboard::copyPasteSymbian() +static void nativeCopyHelper(const QString &string) { - if (!nativeClipboardWorking()) - QSKIP("Native clipboard not working in this setup", SkipAll); - const QString string("Test string symbian."); const TInt KPlainTextBegin = 0; RFs fs = qt_s60GetRFs(); @@ -412,8 +403,55 @@ void tst_QClipboard::copyPasteSymbian() (cb->StreamDictionary()).AssignL(KClipboardUidTypePlainText, symbianStId); cb->CommitL(); CleanupStack::PopAndDestroy(2, cb); +} + +/* + Test that text copied to symbian clipboard + can be pasted to qt clipboard +*/ +// ### This test case only makes sense in symbian +void tst_QClipboard::copyPasteSymbian() +{ + if (!nativeClipboardWorking()) + QSKIP("Native clipboard not working in this setup", SkipAll); + const QString string("Test string symbian->qt."); + + nativeCopyHelper(string); + + QCOMPARE(QApplication::clipboard()->text(), string); +} + +/* + Test that text copied to symbian clipboard + can be pasted to qt clipboard, even if Qt + clipboard already had copied formatted text +*/ +// ### This test case only makes sense in symbian +void tst_QClipboard::copyCopyPasteSymbian() +{ + if (!nativeClipboardWorking()) + QSKIP("Native clipboard not working in this setup", SkipAll); + + //first copy some mime data with text/html and text/plain representations + QMimeData *mimeData = new QMimeData; + const QString preCopy(QLatin1String("qt_symbian")); + mimeData->setText(preCopy); + mimeData->setHtml(preCopy); + QApplication::clipboard()->setMimeData(mimeData); + + //check both representations are pastable + QCOMPARE(QApplication::clipboard()->mimeData()->html(), preCopy); + QCOMPARE(QApplication::clipboard()->mimeData()->text(), preCopy); + + //native copy some plain text + const QString string("symbian_qt"); + nativeCopyHelper(string); + //check text/plain is pastable QCOMPARE(QApplication::clipboard()->text(), string); + QCOMPARE(QApplication::clipboard()->mimeData()->text(), string); + //check text/html is cleared + QVERIFY(QApplication::clipboard()->mimeData()->html().isEmpty()); } #endif -- cgit v0.12