28 #include <bautils.h> // FileExists |
28 #include <bautils.h> // FileExists |
29 #include <mtp/cmtptypeopaquedata.h> |
29 #include <mtp/cmtptypeopaquedata.h> |
30 #include "cmtpimagedpthumbnailcreator.h" |
30 #include "cmtpimagedpthumbnailcreator.h" |
31 #include "mtpimagedpconst.h" |
31 #include "mtpimagedpconst.h" |
32 #include "mtpimagedputilits.h" |
32 #include "mtpimagedputilits.h" |
|
33 #include "cmtpimagedp.h" |
33 |
34 |
34 __FLOG_STMT(_LIT8(KComponent,"CMTPImageDpThumbnailCreator");) |
35 __FLOG_STMT(_LIT8(KComponent,"CMTPImageDpThumbnailCreator");) |
35 // -------------------------------------------------------------------------- |
36 // -------------------------------------------------------------------------- |
36 // CMTPImageDpThumbnailCreator::NewL |
37 // CMTPImageDpThumbnailCreator::NewL |
37 // 2-phased constructor. |
38 // 2-phased constructor. |
38 // -------------------------------------------------------------------------- |
39 // -------------------------------------------------------------------------- |
39 // |
40 // |
40 CMTPImageDpThumbnailCreator* CMTPImageDpThumbnailCreator::NewL() |
41 CMTPImageDpThumbnailCreator* CMTPImageDpThumbnailCreator::NewL(CMTPImageDataProvider& aDataProvider) |
41 { |
42 { |
42 CMTPImageDpThumbnailCreator* self= new (ELeave) CMTPImageDpThumbnailCreator(); |
43 CMTPImageDpThumbnailCreator* self= new (ELeave) CMTPImageDpThumbnailCreator(aDataProvider); |
43 CleanupStack::PushL(self); |
44 CleanupStack::PushL(self); |
44 self->ConstructL(); |
45 self->ConstructL(); |
45 CleanupStack::Pop(self); |
46 CleanupStack::Pop(self); |
46 return self; |
47 return self; |
47 } |
48 } |
80 // -------------------------------------------------------------------------- |
81 // -------------------------------------------------------------------------- |
81 // CMTPImageDpThumbnailCreator::CMTPImageDpThumbnailCreator |
82 // CMTPImageDpThumbnailCreator::CMTPImageDpThumbnailCreator |
82 // C++ constructor. |
83 // C++ constructor. |
83 // -------------------------------------------------------------------------- |
84 // -------------------------------------------------------------------------- |
84 // |
85 // |
85 CMTPImageDpThumbnailCreator::CMTPImageDpThumbnailCreator(): |
86 CMTPImageDpThumbnailCreator::CMTPImageDpThumbnailCreator(CMTPImageDataProvider& aDataProvider): |
86 CActive(EPriorityStandard) |
87 CActive(EPriorityStandard), |
|
88 iDataProvider(aDataProvider) |
87 { |
89 { |
88 __FLOG_OPEN(KMTPSubsystem, KComponent); |
90 __FLOG_OPEN(KMTPSubsystem, KComponent); |
89 __FLOG(_L8("CMTPImageDpThumbnailCreator::CMTPImageDpThumbnailCreator(), begin")); |
91 __FLOG(_L8("CMTPImageDpThumbnailCreator::CMTPImageDpThumbnailCreator(), begin")); |
90 CActiveScheduler::Add(this); |
92 CActiveScheduler::Add(this); |
91 __FLOG(_L8("CMTPImageDpThumbnailCreator::CMTPImageDpThumbnailCreator(), end")); |
93 __FLOG(_L8("CMTPImageDpThumbnailCreator::CMTPImageDpThumbnailCreator(), end")); |
98 // |
100 // |
99 void CMTPImageDpThumbnailCreator::ConstructL() |
101 void CMTPImageDpThumbnailCreator::ConstructL() |
100 { |
102 { |
101 __FLOG(_L8("CMTPImageDpThumbnailCreator::ConstructL(), begin")); |
103 __FLOG(_L8("CMTPImageDpThumbnailCreator::ConstructL(), begin")); |
102 iThumbMgr = CThumbnailManager::NewL( *this ); |
104 iThumbMgr = CThumbnailManager::NewL( *this ); |
103 iThumbMgr->SetThumbnailSizeL( EFullScreenThumbnailSize ); |
105 iThumbMgr->SetThumbnailSizeL( EGridThumbnailSize ); |
104 #ifdef MTPTHUMBSCALING |
106 #ifdef MTPTHUMBSCALING |
105 iScaler = CBitmapScaler::NewL(); |
107 iScaler = CBitmapScaler::NewL(); |
106 #endif |
108 #endif |
107 iActiveSchedulerWait = new (ELeave) CActiveSchedulerWait(); |
109 iActiveSchedulerWait = new (ELeave) CActiveSchedulerWait(); |
108 __FLOG(_L8("CMTPImageDpThumbnailCreator::ConstructL(), end")); |
110 __FLOG(_L8("CMTPImageDpThumbnailCreator::ConstructL(), end")); |
169 if (iThumbMgr->Flags() == CThumbnailManager::EDoNotCreate) |
171 if (iThumbMgr->Flags() == CThumbnailManager::EDoNotCreate) |
170 { |
172 { |
171 __FLOG_VA((_L8("CMTPImageDpThumbnailCreator::RunL(),EDoNotCreate; iState %d"), iState)); |
173 __FLOG_VA((_L8("CMTPImageDpThumbnailCreator::RunL(),EDoNotCreate; iState %d"), iState)); |
172 delete iData; |
174 delete iData; |
173 iData = HBufC8::NewL(1); |
175 iData = HBufC8::NewL(1); |
174 iBuffer->Write(*iData); |
|
175 } |
|
176 else{ |
|
177 iBuffer->Write(*iData); |
|
178 } |
176 } |
179 |
177 |
180 __FLOG_VA((_L8("<< CMTPImageDpThumbnailCreator::RunL(),iBuffer->Write(*iData); iState %d"), iState)); |
178 __FLOG_VA((_L8("<< CMTPImageDpThumbnailCreator::RunL(),iBuffer->Write(*iData); iState %d"), iState)); |
181 if(iActiveSchedulerWait->IsStarted()) |
179 if(iActiveSchedulerWait->IsStarted()) |
182 { |
180 { |
213 |
211 |
214 // -------------------------------------------------------------------------- |
212 // -------------------------------------------------------------------------- |
215 // |
213 // |
216 // -------------------------------------------------------------------------- |
214 // -------------------------------------------------------------------------- |
217 // |
215 // |
218 void CMTPImageDpThumbnailCreator::GetThumbnailL(const TDesC& aFileName, CMTPTypeOpaqueData& aThumbName, TInt& result) |
216 void CMTPImageDpThumbnailCreator::GetThumbnailL(const TDesC& aFileName, HBufC8*& aDestinationData, TInt& result) |
219 { |
217 { |
220 __FLOG(_L8(">> CMtpImageDphumbnailCreator::GetThumbnailL()")); |
218 __FLOG(_L8(">> CMtpImageDphumbnailCreator::GetThumbnailL()")); |
221 iBuffer = &aThumbName; |
|
222 GetThumbL(aFileName); |
219 GetThumbL(aFileName); |
223 iCreationErr = &result; //reset the err flag |
220 iCreationErr = &result; //reset the err flag |
224 *iCreationErr = KErrNone; |
221 *iCreationErr = KErrNone; |
225 __FLOG(_L8("<< CMTPImageDpThumbnailCreator::CreateThumbnailL()")); |
222 __FLOG(_L8("<< CMTPImageDpThumbnailCreator::CreateThumbnailL()")); |
226 iActiveSchedulerWait->Start(); |
223 iActiveSchedulerWait->Start(); |
|
224 |
|
225 /** |
|
226 * transfer the ownership of iData if query successfully |
|
227 */ |
|
228 if (*iCreationErr == KErrNone) |
|
229 { |
|
230 aDestinationData = iData; |
|
231 iData = NULL; |
|
232 } |
|
233 else |
|
234 { |
|
235 aDestinationData = NULL; |
|
236 } |
227 } |
237 } |
228 |
238 |
229 // -------------------------------------------------------------------------- |
239 // -------------------------------------------------------------------------- |
230 // |
240 // |
231 // -------------------------------------------------------------------------- |
241 // -------------------------------------------------------------------------- |
248 // Create an object source representing a path to a file on local |
258 // Create an object source representing a path to a file on local |
249 // file system. |
259 // file system. |
250 delete iObjectSource; |
260 delete iObjectSource; |
251 iObjectSource = NULL; |
261 iObjectSource = NULL; |
252 |
262 |
253 iObjectSource = CThumbnailObjectSource::NewL(aFileName, KJpegMimeType); |
263 TParsePtrC parse(aFileName); |
|
264 const TDesC& mimeType = iDataProvider.FindMimeType(parse.Ext().Mid(1)); |
|
265 __FLOG_VA((_L16("CMtpImageDphumbnailCreator::GetThumbL() - FileName:%S, MimeType:%S"), &aFileName, &mimeType)); |
|
266 |
|
267 iObjectSource = CThumbnailObjectSource::NewL(aFileName, mimeType); |
254 iCurrentReq = iThumbMgr->GetThumbnailL( *iObjectSource ); |
268 iCurrentReq = iThumbMgr->GetThumbnailL( *iObjectSource ); |
255 iState = EGetting; |
269 iState = EGetting; |
256 __FLOG(_L8("<< CMtpImageDphumbnailCreator::GetThumbL()")); |
270 __FLOG(_L8("<< CMtpImageDphumbnailCreator::GetThumbL()")); |
257 } |
271 } |
258 |
272 |
265 void CMTPImageDpThumbnailCreator::ScaleBitmap() |
279 void CMTPImageDpThumbnailCreator::ScaleBitmap() |
266 { |
280 { |
267 __FLOG(_L8("CMTPImageDpThumbnailCreator::ScaleBitmapL(), begin")); |
281 __FLOG(_L8("CMTPImageDpThumbnailCreator::ScaleBitmapL(), begin")); |
268 TSize size( KThumbWidht, KThumbHeigth ); // size 160x120 |
282 TSize size( KThumbWidht, KThumbHeigth ); // size 160x120 |
269 // Resize image to thumbnail size |
283 // Resize image to thumbnail size |
270 iScaler->Scale( &iStatus, *iBitmap, size ); |
284 // iScaler->Scale( &iStatus, *iBitmap, size ); |
|
285 |
|
286 /** |
|
287 * [Thumbnail SIZE]: performance improvement |
|
288 * comments scaling code, but it breaks PTP spect. |
|
289 * so if we meet any break of compatible test, we should re-scale thumbnail size |
|
290 */ |
|
291 TRequestStatus* status = &iStatus; |
|
292 User::RequestComplete( status, KErrNone ); |
|
293 |
271 SetActive(); |
294 SetActive(); |
272 __FLOG(_L8("CMTPImageDpThumbnailCreator::ScaleBitmapL(), end")); |
295 __FLOG(_L8("CMTPImageDpThumbnailCreator::ScaleBitmapL(), end")); |
273 } |
296 } |
274 #endif |
297 #endif |
275 |
298 |
307 return; |
330 return; |
308 } |
331 } |
309 if (aError == KErrNone) |
332 if (aError == KErrNone) |
310 { |
333 { |
311 TRAP_IGNORE(iThumbMgr->SetFlagsL(CThumbnailManager::EDefaultFlags)); |
334 TRAP_IGNORE(iThumbMgr->SetFlagsL(CThumbnailManager::EDefaultFlags)); |
312 delete iBitmap; |
335 delete iBitmap; |
313 // Claim ownership of the bitmap instance for later use |
336 // Claim ownership of the bitmap instance for later use |
314 iBitmap = aThumbnail.DetachBitmap(); |
337 iBitmap = aThumbnail.DetachBitmap(); |
315 #ifdef MTPTHUMBSCALING |
338 #ifdef MTPTHUMBSCALING |
316 iState = EGetted; |
339 iState = EGetted; |
317 #else |
340 #else |
320 } |
343 } |
321 else if ((iThumbMgr->Flags() == CThumbnailManager::EDoNotCreate) && (aError == KErrNotFound)) |
344 else if ((iThumbMgr->Flags() == CThumbnailManager::EDoNotCreate) && (aError == KErrNotFound)) |
322 { |
345 { |
323 __FLOG(_L8("CMTPImageDpThumbnailCreator::ThumbnailReady(),EDoNotCreate, KErrNotFound")); |
346 __FLOG(_L8("CMTPImageDpThumbnailCreator::ThumbnailReady(),EDoNotCreate, KErrNotFound")); |
324 iState = EEncoding; |
347 iState = EEncoding; |
325 iThumbMgr->CreateThumbnails(*iObjectSource); |
348 //don't trigger TNM to create thumbnail if image files are too big |
|
349 //iThumbMgr->CreateThumbnails(*iObjectSource); |
326 aError = KErrNone; |
350 aError = KErrNone; |
327 } |
351 } |
328 iStatus=KRequestPending; |
352 iStatus=KRequestPending; |
329 TRequestStatus* status=&iStatus; |
353 TRequestStatus* status=&iStatus; |
330 User::RequestComplete(status, aError); |
354 User::RequestComplete(status, aError); |