14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <fbs.h> |
18 #include <fbs.h> |
19 #include <qtcore> |
19 #include <QtCore> |
20 #include <qpixmap.h> |
20 #include <qpixmap.h> |
21 #include <thumbnailmanager.h> |
21 #include <thumbnailmanager.h> |
22 #include <thumbnaildata.h> |
22 #include <thumbnaildata.h> |
23 |
23 |
24 #include "thumbnailmanager_qt.h" |
24 #include "thumbnailmanager_qt.h" |
25 #include "thumbnailmanager_p_qt.h" |
25 #include "thumbnailmanager_p_qt.h" |
26 |
26 |
27 ThumbnailManagerPrivate::ThumbnailManagerPrivate() : iThumbnailManager( NULL ), byteArray( NULL ) |
27 #include <e32base.h> |
|
28 |
|
29 const int ThumbnailMangerPriorityLowest = CActive::EPriorityIdle; |
|
30 const int ThumbnailMangerPriorityHighest = CActive::EPriorityHigh; |
|
31 |
|
32 ThumbnailManagerPrivate::ThumbnailManagerPrivate() : iThumbnailManager( NULL ), byteArray( NULL ), |
|
33 connectionCounterImage( 0 ), |
|
34 connectionCounterPixmap( 0 ) |
28 { |
35 { |
29 TRAP_IGNORE( |
36 TRAP_IGNORE( |
30 iThumbnailManager = CThumbnailManager::NewL( *this ); |
37 iThumbnailManager = CThumbnailManager::NewL( *this ); |
31 iThumbnailManager->SetDisplayModeL( EColor64K ); |
38 iThumbnailManager->SetDisplayModeL( EColor64K ); |
32 ); |
39 ); |
101 int ThumbnailManagerPrivate::getThumbnail( const QString& fileName, void* clientData, |
108 int ThumbnailManagerPrivate::getThumbnail( const QString& fileName, void* clientData, |
102 int priority ) |
109 int priority ) |
103 { |
110 { |
104 int result( -1 ); |
111 int result( -1 ); |
105 QString symbFileName( fileName ); |
112 QString symbFileName( fileName ); |
|
113 |
|
114 priority = convertPriority(priority); |
106 |
115 |
107 if( symbFileName.contains( "/" ) ) |
116 if( symbFileName.contains( "/" ) ) |
108 symbFileName.replace( "/", "\\", Qt::CaseSensitive ); |
117 symbFileName.replace( "/", "\\", Qt::CaseSensitive ); |
109 |
118 |
110 RBuf buf; |
119 RBuf buf; |
121 |
130 |
122 int ThumbnailManagerPrivate::getThumbnail( unsigned long int aThumbnailId, void* clientData, |
131 int ThumbnailManagerPrivate::getThumbnail( unsigned long int aThumbnailId, void* clientData, |
123 int priority ) |
132 int priority ) |
124 { |
133 { |
125 int result( -1 ); |
134 int result( -1 ); |
|
135 |
|
136 priority = convertPriority(priority); |
|
137 |
126 TRAP_IGNORE( result = iThumbnailManager->GetThumbnailL( aThumbnailId, clientData, priority )); |
138 TRAP_IGNORE( result = iThumbnailManager->GetThumbnailL( aThumbnailId, clientData, priority )); |
127 return result; |
139 return result; |
128 } |
140 } |
129 |
141 |
130 int ThumbnailManagerPrivate::setThumbnail( const QPixmap& source, const QString& fileName, |
142 int ThumbnailManagerPrivate::setThumbnail( const QPixmap& source, const QString& fileName, |
131 void * clientData, int priority ) |
143 void * clientData, int priority ) |
132 { |
144 { |
133 int result( -1 ); |
145 int result( -1 ); |
134 RBuf file; |
146 RBuf file; |
135 _LIT( mime, "image/png" ); |
147 _LIT( mime, "image/png" ); |
|
148 |
|
149 priority = convertPriority(priority); |
136 |
150 |
137 if( !byteArray ){ |
151 if( !byteArray ){ |
138 byteArray = new QByteArray(); |
152 byteArray = new QByteArray(); |
139 } |
153 } |
140 QBuffer buffer( byteArray ); |
154 QBuffer buffer( byteArray ); |
226 return ( iThumbnailManager->CancelRequest( id ) == KErrNone ); |
242 return ( iThumbnailManager->CancelRequest( id ) == KErrNone ); |
227 } |
243 } |
228 |
244 |
229 bool ThumbnailManagerPrivate::changePriority( int id, int newPriority ) |
245 bool ThumbnailManagerPrivate::changePriority( int id, int newPriority ) |
230 { |
246 { |
|
247 newPriority = convertPriority(newPriority); |
|
248 |
231 return ( iThumbnailManager->ChangePriority( id, newPriority ) == KErrNone ); |
249 return ( iThumbnailManager->ChangePriority( id, newPriority ) == KErrNone ); |
232 } |
250 } |
233 |
251 |
234 QPixmap ThumbnailManagerPrivate::copyPixmap( CFbsBitmap* bitmap ) |
252 QImage ThumbnailManagerPrivate::fromBitmap( CFbsBitmap* bitmap ) |
235 { |
253 { |
236 TSize size = bitmap->SizeInPixels(); |
254 TSize size = bitmap->SizeInPixels(); |
237 int bytesPerLine = bitmap->ScanLineLength( size.iWidth, |
255 int bytesPerLine = bitmap->ScanLineLength( size.iWidth, bitmap->DisplayMode() ); |
238 bitmap->DisplayMode() ); |
|
239 const uchar* dataPtr = ( const uchar* ) bitmap->DataAddress(); |
256 const uchar* dataPtr = ( const uchar* ) bitmap->DataAddress(); |
240 |
257 QImage image = QImage(dataPtr, size.iWidth, size.iHeight, bytesPerLine, QImage::Format_RGB16); |
241 return QPixmap::fromImage( QImage( dataPtr, |
258 return image.copy(); |
242 size.iWidth, |
259 } |
243 size.iHeight, |
260 |
244 bytesPerLine, |
261 QPixmap ThumbnailManagerPrivate::fromImage( CFbsBitmap* bitmap ) |
245 QImage::Format_RGB16 ) ); |
262 { |
|
263 return QPixmap::fromImage(fromBitmap(bitmap)); |
|
264 } |
|
265 |
|
266 int ThumbnailManagerPrivate::convertPriority(int basePriority) |
|
267 { |
|
268 return qBound(ThumbnailMangerPriorityLowest, basePriority, ThumbnailMangerPriorityHighest); |
246 } |
269 } |
247 |
270 |
248 void ThumbnailManagerPrivate::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, |
271 void ThumbnailManagerPrivate::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, |
249 TThumbnailRequestId /*aId*/ ) |
272 TThumbnailRequestId /*aId*/ ) |
250 { |
273 { |
256 if( byteArray ){ |
279 if( byteArray ){ |
257 delete byteArray; |
280 delete byteArray; |
258 byteArray = NULL; |
281 byteArray = NULL; |
259 } |
282 } |
260 |
283 |
261 QPixmap* pixmap( NULL ); |
284 if (connectionCounterImage || connectionCounterPixmap) { |
262 |
285 QImage image; |
263 if( aError == KErrNone ){ |
286 |
264 pixmap = new QPixmap( copyPixmap( aThumbnail.Bitmap() ) ); |
287 if (aError == KErrNone) { |
265 }else { |
288 image = fromBitmap(aThumbnail.Bitmap()); |
266 pixmap = new QPixmap(); |
289 } else { |
267 } |
290 image = QImage(); |
268 |
291 } |
269 emit thumbnailReady( *pixmap, aThumbnail.ClientData(), aId, aError ); |
292 |
270 delete pixmap; |
293 if (connectionCounterImage) { |
271 } |
294 emit thumbnailReady(image, aThumbnail.ClientData(), aId, aError); |
272 |
295 } |
|
296 |
|
297 if (connectionCounterPixmap) { |
|
298 QPixmap pixmap = QPixmap::fromImage(image); |
|
299 emit thumbnailReady(pixmap, aThumbnail.ClientData(), aId, aError); |
|
300 } |
|
301 } |
|
302 } |
|
303 |