author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
0 | 8 |
** |
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
167 |
QString mimeType = QString(reinterpret_cast<const QChar *>(mimeTypeBuf->Des().Ptr()), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
168 |
mimeTypeBuf->Length()); |
0 | 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 |