|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <fbs.h> |
|
19 #include <qtcore> |
|
20 #include <qpixmap.h> |
|
21 #include <thumbnailmanager.h> |
|
22 #include <thumbnaildata.h> |
|
23 |
|
24 #include "thumbnailmanager_qt.h" |
|
25 #include "thumbnailmanager_p_qt.h" |
|
26 |
|
27 ThumbnailManagerPrivate::ThumbnailManagerPrivate() : iThumbnailManager( NULL ), byteArray( NULL ) |
|
28 { |
|
29 TRAP_IGNORE( |
|
30 iThumbnailManager = CThumbnailManager::NewL( *this ); |
|
31 iThumbnailManager->SetDisplayModeL( EColor64K ); |
|
32 ); |
|
33 } |
|
34 |
|
35 ThumbnailManagerPrivate::~ThumbnailManagerPrivate() |
|
36 { |
|
37 if( iThumbnailManager ){ |
|
38 delete iThumbnailManager; |
|
39 } |
|
40 if( byteArray ){ |
|
41 delete byteArray; |
|
42 } |
|
43 } |
|
44 |
|
45 ThumbnailManager::QualityPreference ThumbnailManagerPrivate::qualityPreference() const |
|
46 { |
|
47 return static_cast<ThumbnailManager::QualityPreference>( iThumbnailManager->QualityPreference() ); |
|
48 } |
|
49 |
|
50 bool ThumbnailManagerPrivate::setQualityPreference( ThumbnailManager::QualityPreference qualityPreference ) |
|
51 { |
|
52 TRAPD( err, iThumbnailManager->SetQualityPreferenceL( static_cast<CThumbnailManager::TThumbnailQualityPreference>(qualityPreference) )); |
|
53 return ( err == KErrNone ); |
|
54 } |
|
55 |
|
56 QSize ThumbnailManagerPrivate::thumbnailSize() const |
|
57 { |
|
58 TSize tsize( iThumbnailManager->ThumbnailSize() ); |
|
59 QSize qsize( tsize.iWidth, tsize.iHeight); |
|
60 return qsize; |
|
61 } |
|
62 |
|
63 bool ThumbnailManagerPrivate::setThumbnailSize( const QSize& thumbnailSize ) |
|
64 { |
|
65 TRAPD( err, iThumbnailManager->SetThumbnailSizeL( TSize( thumbnailSize.width(), thumbnailSize.height() ) ) ); |
|
66 return ( err == KErrNone ); |
|
67 } |
|
68 |
|
69 bool ThumbnailManagerPrivate::setThumbnailSize( ThumbnailManager::ThumbnailSize thumbnailSize ) |
|
70 { |
|
71 TThumbnailSize size(EUnknownThumbnailSize); |
|
72 switch( thumbnailSize ){ |
|
73 case ThumbnailManager::ThumbnailSmall: |
|
74 size = EListThumbnailSize; |
|
75 break; |
|
76 case ThumbnailManager::ThumbnailMedium: |
|
77 size = EGridThumbnailSize; |
|
78 break; |
|
79 case ThumbnailManager::ThumbnailLarge: |
|
80 size = EFullScreenThumbnailSize; |
|
81 break; |
|
82 default: |
|
83 break; |
|
84 } |
|
85 |
|
86 TRAPD( err, iThumbnailManager->SetThumbnailSizeL( size ) ); |
|
87 return ( err == KErrNone ); |
|
88 } |
|
89 |
|
90 ThumbnailManager::ThumbnailMode ThumbnailManagerPrivate::mode() const |
|
91 { |
|
92 return static_cast<ThumbnailManager::ThumbnailMode>( iThumbnailManager->Flags() ); |
|
93 } |
|
94 |
|
95 bool ThumbnailManagerPrivate::setMode( ThumbnailManager::ThumbnailMode mode ) |
|
96 { |
|
97 TRAPD( err, iThumbnailManager->SetFlagsL( static_cast<CThumbnailManager::TThumbnailFlags>( mode ) ) ); |
|
98 return ( err == KErrNone ); |
|
99 } |
|
100 |
|
101 int ThumbnailManagerPrivate::getThumbnail( const QString& fileName, void* clientData, |
|
102 int priority ) |
|
103 { |
|
104 int result( -1 ); |
|
105 QString symbFileName( fileName ); |
|
106 |
|
107 if( symbFileName.contains( "/" ) ) |
|
108 symbFileName.replace( "/", "\\", Qt::CaseSensitive ); |
|
109 |
|
110 RBuf buf; |
|
111 TRAP_IGNORE( |
|
112 CleanupClosePushL( buf ); |
|
113 buf.CreateL( symbFileName.length() ); |
|
114 buf.Copy( symbFileName.utf16(), symbFileName.length() ); |
|
115 CThumbnailObjectSource* objSrc = CThumbnailObjectSource::NewLC( buf, KNullDesC ); |
|
116 result = iThumbnailManager->GetThumbnailL( *objSrc, clientData, priority ); |
|
117 CleanupStack::PopAndDestroy( 2, &buf ); |
|
118 ); |
|
119 return result; |
|
120 } |
|
121 |
|
122 int ThumbnailManagerPrivate::getThumbnail( unsigned long int aThumbnailId, void* clientData, |
|
123 int priority ) |
|
124 { |
|
125 int result( -1 ); |
|
126 TRAP_IGNORE( result = iThumbnailManager->GetThumbnailL( aThumbnailId, clientData, priority )); |
|
127 return result; |
|
128 } |
|
129 |
|
130 int ThumbnailManagerPrivate::setThumbnail( const QPixmap& source, const QString& fileName, |
|
131 void * clientData, int priority ) |
|
132 { |
|
133 int result( -1 ); |
|
134 RBuf file; |
|
135 _LIT( mime, "image/png" ); |
|
136 |
|
137 if( !byteArray ){ |
|
138 byteArray = new QByteArray(); |
|
139 } |
|
140 QBuffer buffer( byteArray ); |
|
141 buffer.open( QBuffer::ReadWrite ); |
|
142 QDataStream dataStream( &buffer ); |
|
143 |
|
144 dataStream << source; |
|
145 |
|
146 int offset = ( dataStream.version() >= 5 ? 4 : 0 ); |
|
147 |
|
148 TRAP_IGNORE( |
|
149 CleanupClosePushL( file ); |
|
150 file.CreateL( fileName.length() ); |
|
151 file.Copy( fileName.utf16(), fileName.length() ); |
|
152 |
|
153 HBufC* mimetype = HBufC::NewLC( 9 ); |
|
154 mimetype->Des() = mime(); |
|
155 |
|
156 TPtrC8* ptr = new TPtrC8( reinterpret_cast<const TUint8*>( byteArray->data() + offset ), byteArray->count() - offset ); |
|
157 |
|
158 CThumbnailObjectSource* objSrc = CThumbnailObjectSource::NewLC( ptr, *mimetype, file ); |
|
159 result = iThumbnailManager->SetThumbnailL( *objSrc, clientData, priority ); |
|
160 CleanupStack::PopAndDestroy( 3, &file ); |
|
161 ); |
|
162 return result; |
|
163 } |
|
164 |
|
165 void ThumbnailManagerPrivate::deleteThumbnails( const QString& fileName ) |
|
166 { |
|
167 QString symbFileName( fileName ); |
|
168 |
|
169 if( symbFileName.contains( "/" ) ) |
|
170 symbFileName.replace( "/", "\\", Qt::CaseSensitive ); |
|
171 |
|
172 RBuf buf; |
|
173 TRAP_IGNORE( CleanupClosePushL( buf ); |
|
174 buf.CreateL( symbFileName.length() ); |
|
175 buf.Copy( symbFileName.utf16(), symbFileName.length() ); |
|
176 CThumbnailObjectSource* objSrc = CThumbnailObjectSource::NewL( buf, KNullDesC ); |
|
177 iThumbnailManager->DeleteThumbnails( *objSrc ); |
|
178 CleanupStack::PopAndDestroy( &buf ); |
|
179 delete objSrc; |
|
180 ); |
|
181 } |
|
182 |
|
183 void ThumbnailManagerPrivate::deleteThumbnails( unsigned long int thumbnailId ) |
|
184 { |
|
185 iThumbnailManager->DeleteThumbnails( thumbnailId ); |
|
186 } |
|
187 |
|
188 bool ThumbnailManagerPrivate::cancelRequest( int id ) |
|
189 { |
|
190 return ( iThumbnailManager->CancelRequest( id ) == KErrNone ); |
|
191 } |
|
192 |
|
193 bool ThumbnailManagerPrivate::changePriority( int id, int newPriority ) |
|
194 { |
|
195 return ( iThumbnailManager->ChangePriority( id, newPriority ) == KErrNone ); |
|
196 } |
|
197 |
|
198 QPixmap ThumbnailManagerPrivate::copyPixmap( CFbsBitmap* bitmap ) |
|
199 { |
|
200 TSize size = bitmap->SizeInPixels(); |
|
201 int bytesPerLine = bitmap->ScanLineLength( size.iWidth, |
|
202 bitmap->DisplayMode() ); |
|
203 const uchar* dataPtr = ( const uchar* ) bitmap->DataAddress(); |
|
204 |
|
205 return QPixmap::fromImage( QImage( dataPtr, |
|
206 size.iWidth, |
|
207 size.iHeight, |
|
208 bytesPerLine, |
|
209 QImage::Format_RGB16 ) ); |
|
210 } |
|
211 |
|
212 void ThumbnailManagerPrivate::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, |
|
213 TThumbnailRequestId /*aId*/ ) |
|
214 { |
|
215 } |
|
216 |
|
217 void ThumbnailManagerPrivate::ThumbnailReady( TInt aError, MThumbnailData& aThumbnail, |
|
218 TThumbnailRequestId aId ) |
|
219 { |
|
220 if( byteArray ){ |
|
221 delete byteArray; |
|
222 byteArray = NULL; |
|
223 } |
|
224 |
|
225 QPixmap* pixmap( NULL ); |
|
226 |
|
227 if( aError == KErrNone ){ |
|
228 pixmap = new QPixmap( copyPixmap( aThumbnail.Bitmap() ) ); |
|
229 }else { |
|
230 pixmap = new QPixmap(); |
|
231 } |
|
232 |
|
233 emit thumbnailReady( *pixmap, aThumbnail.ClientData(), aId, aError ); |
|
234 delete pixmap; |
|
235 } |
|
236 |