| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qclipboard.h"
|
|---|
| 43 |
|
|---|
| 44 | #ifndef QT_NO_CLIPBOARD
|
|---|
| 45 |
|
|---|
| 46 | #include "qapplication.h"
|
|---|
| 47 | #include "qbitmap.h"
|
|---|
| 48 | #include "qdatetime.h"
|
|---|
| 49 | #include "qbuffer.h"
|
|---|
| 50 | #include "qwidget.h"
|
|---|
| 51 | #include "qevent.h"
|
|---|
| 52 | #include "private/qcore_symbian_p.h"
|
|---|
| 53 | #include <QtDebug>
|
|---|
| 54 |
|
|---|
| 55 | // Symbian's clipboard
|
|---|
| 56 | #include <baclipb.h>
|
|---|
| 57 | QT_BEGIN_NAMESPACE
|
|---|
| 58 |
|
|---|
| 59 | //### Mime Type mapping to UIDs
|
|---|
| 60 |
|
|---|
| 61 | const TUid KQtCbDataStream = {0x2001B2DD};
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | class QClipboardData
|
|---|
| 65 | {
|
|---|
| 66 | public:
|
|---|
| 67 | QClipboardData();
|
|---|
| 68 | ~QClipboardData();
|
|---|
| 69 |
|
|---|
| 70 | void setSource(QMimeData* s)
|
|---|
| 71 | {
|
|---|
| 72 | if (s == src)
|
|---|
| 73 | return;
|
|---|
| 74 | delete src;
|
|---|
| 75 | src = s;
|
|---|
| 76 | }
|
|---|
| 77 | QMimeData* source()
|
|---|
| 78 | { return src; }
|
|---|
| 79 | bool connected()
|
|---|
| 80 | { return connection; }
|
|---|
| 81 | void clear();
|
|---|
| 82 |
|
|---|
| 83 | private:
|
|---|
| 84 | QMimeData* src;
|
|---|
| 85 | bool connection;
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | QClipboardData::QClipboardData():src(0),connection(true)
|
|---|
| 89 | {
|
|---|
| 90 | clear();
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | QClipboardData::~QClipboardData()
|
|---|
| 94 | {
|
|---|
| 95 | connection = false;
|
|---|
| 96 | delete src;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | void QClipboardData::clear()
|
|---|
| 100 | {
|
|---|
| 101 | QMimeData* newSrc = new QMimeData;
|
|---|
| 102 | delete src;
|
|---|
| 103 | src = newSrc;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | static QClipboardData *internalCbData = 0;
|
|---|
| 107 |
|
|---|
| 108 | static void cleanupClipboardData()
|
|---|
| 109 | {
|
|---|
| 110 | delete internalCbData;
|
|---|
| 111 | internalCbData = 0;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | static QClipboardData *clipboardData()
|
|---|
| 115 | {
|
|---|
| 116 | if (internalCbData == 0) {
|
|---|
| 117 | internalCbData = new QClipboardData;
|
|---|
| 118 | if (internalCbData)
|
|---|
| 119 | {
|
|---|
| 120 | if (!internalCbData->connected())
|
|---|
| 121 | {
|
|---|
| 122 | delete internalCbData;
|
|---|
| 123 | internalCbData = 0;
|
|---|
| 124 | }
|
|---|
| 125 | else
|
|---|
| 126 | {
|
|---|
| 127 | qAddPostRoutine(cleanupClipboardData);
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | return internalCbData;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | void writeToStreamLX(const QMimeData* aData, RWriteStream& aStream)
|
|---|
| 135 | {
|
|---|
| 136 | // This function both leaves and throws exceptions. There must be no destructor
|
|---|
| 137 | // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
|
|---|
| 138 | QStringList headers = aData->formats();
|
|---|
| 139 | aStream << TCardinality(headers.count());
|
|---|
| 140 | for (QStringList::const_iterator iter= headers.constBegin();iter != headers.constEnd();iter++)
|
|---|
| 141 | {
|
|---|
| 142 | HBufC* stringData = TPtrC(reinterpret_cast<const TUint16*>((*iter).utf16())).AllocLC();
|
|---|
| 143 | QByteArray ba = aData->data((*iter));
|
|---|
| 144 | qDebug() << "copy to clipboard mime: " << *iter << " data: " << ba;
|
|---|
| 145 | // mime type
|
|---|
| 146 | aStream << TCardinality(stringData->Size());
|
|---|
| 147 | aStream << *(stringData);
|
|---|
| 148 | // mime data
|
|---|
| 149 | aStream << TCardinality(ba.size());
|
|---|
| 150 | aStream.WriteL(reinterpret_cast<const uchar*>(ba.constData()),ba.size());
|
|---|
| 151 | CleanupStack::PopAndDestroy(stringData);
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | void readFromStreamLX(QMimeData* aData,RReadStream& aStream)
|
|---|
| 156 | {
|
|---|
| 157 | // This function both leaves and throws exceptions. There must be no destructor
|
|---|
| 158 | // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
|
|---|
| 159 | TCardinality mimeTypeCount;
|
|---|
| 160 | aStream >> mimeTypeCount;
|
|---|
| 161 | for (int i = 0; i< mimeTypeCount;i++)
|
|---|
| 162 | {
|
|---|
| 163 | // mime type
|
|---|
| 164 | TCardinality mimeTypeSize;
|
|---|
| 165 | aStream >> mimeTypeSize;
|
|---|
| 166 | HBufC* mimeTypeBuf = HBufC::NewLC(aStream,mimeTypeSize);
|
|---|
| 167 | QString mimeType = QString(reinterpret_cast<const QChar *>(mimeTypeBuf->Des().Ptr()),
|
|---|
| 168 | mimeTypeBuf->Length());
|
|---|
| 169 | CleanupStack::PopAndDestroy(mimeTypeBuf);
|
|---|
| 170 | // mime data
|
|---|
| 171 | TCardinality dataSize;
|
|---|
| 172 | aStream >> dataSize;
|
|---|
| 173 | QByteArray ba;
|
|---|
| 174 | ba.reserve(dataSize);
|
|---|
| 175 | aStream.ReadL(reinterpret_cast<uchar*>(ba.data_ptr()->data),dataSize);
|
|---|
| 176 | ba.data_ptr()->size = dataSize;
|
|---|
| 177 | qDebug() << "paste from clipboard mime: " << mimeType << " data: " << ba;
|
|---|
| 178 | aData->setData(mimeType,ba);
|
|---|
| 179 | }
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 | /*****************************************************************************
|
|---|
| 184 | QClipboard member functions
|
|---|
| 185 | *****************************************************************************/
|
|---|
| 186 |
|
|---|
| 187 | void QClipboard::clear(Mode mode)
|
|---|
| 188 | {
|
|---|
| 189 | setText(QString(), mode);
|
|---|
| 190 | }
|
|---|
| 191 | const QMimeData* QClipboard::mimeData(Mode mode) const
|
|---|
| 192 | {
|
|---|
| 193 | if (mode != Clipboard) return 0;
|
|---|
| 194 | QClipboardData *d = clipboardData();
|
|---|
| 195 | if (d)
|
|---|
| 196 | {
|
|---|
| 197 | TRAPD(err,{
|
|---|
| 198 | RFs fs = qt_s60GetRFs();
|
|---|
| 199 | CClipboard* cb = CClipboard::NewForReadingLC(fs);
|
|---|
| 200 | Q_ASSERT(cb);
|
|---|
| 201 | RStoreReadStream stream;
|
|---|
| 202 | TStreamId stid = (cb->StreamDictionary()).At(KQtCbDataStream);
|
|---|
| 203 | stream.OpenLC(cb->Store(),stid);
|
|---|
| 204 | QT_TRYCATCH_LEAVING(readFromStreamLX(d->source(),stream));
|
|---|
| 205 | CleanupStack::PopAndDestroy(2,cb);
|
|---|
| 206 | return d->source();
|
|---|
| 207 | });
|
|---|
| 208 | if (err != KErrNone){
|
|---|
| 209 | qDebug()<< "clipboard is empty/err: " << err;
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | }
|
|---|
| 213 | return 0;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 | void QClipboard::setMimeData(QMimeData* src, Mode mode)
|
|---|
| 218 | {
|
|---|
| 219 | if (mode != Clipboard) return;
|
|---|
| 220 | QClipboardData *d = clipboardData();
|
|---|
| 221 | if (d)
|
|---|
| 222 | {
|
|---|
| 223 | TRAPD(err,{
|
|---|
| 224 | RFs fs = qt_s60GetRFs();
|
|---|
| 225 | CClipboard* cb = CClipboard::NewForWritingLC(fs);
|
|---|
| 226 | RStoreWriteStream stream;
|
|---|
| 227 | TStreamId stid = stream.CreateLC(cb->Store());
|
|---|
| 228 | QT_TRYCATCH_LEAVING(writeToStreamLX(src,stream));
|
|---|
| 229 | d->setSource(src);
|
|---|
| 230 | stream.CommitL();
|
|---|
| 231 | (cb->StreamDictionary()).AssignL(KQtCbDataStream,stid);
|
|---|
| 232 | cb->CommitL();
|
|---|
| 233 | CleanupStack::PopAndDestroy(2,cb);
|
|---|
| 234 | });
|
|---|
| 235 | if (err != KErrNone){
|
|---|
| 236 | qDebug()<< "clipboard write err :" << err;
|
|---|
| 237 | }
|
|---|
| 238 | }
|
|---|
| 239 | emitChanged(QClipboard::Clipboard);
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | bool QClipboard::supportsMode(Mode mode) const
|
|---|
| 243 | {
|
|---|
| 244 | return (mode == Clipboard);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | bool QClipboard::ownsMode(Mode mode) const
|
|---|
| 248 | {
|
|---|
| 249 | if (mode == Clipboard)
|
|---|
| 250 | qWarning("QClipboard::ownsClipboard: UNIMPLEMENTED!");
|
|---|
| 251 | return false;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | bool QClipboard::event(QEvent * /* e */)
|
|---|
| 255 | {
|
|---|
| 256 | return true;
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | void QClipboard::connectNotify( const char * )
|
|---|
| 260 | {
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | void QClipboard::ownerDestroyed()
|
|---|
| 264 | {
|
|---|
| 265 | }
|
|---|
| 266 | QT_END_NAMESPACE
|
|---|
| 267 | #endif // QT_NO_CLIPBOARD
|
|---|