|
1 /* |
|
2 * Copyright (c) 2004 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 the License "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 * View images popup dialog listbox |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "BrowserViewImagesListBox.h" |
|
23 #include "BrowserDialogsProviderConstants.h" |
|
24 |
|
25 #include <gulicon.h> |
|
26 #include <e32math.h> |
|
27 #include <akniconarray.h> |
|
28 #include <Oma2Agent.h> |
|
29 using namespace ContentAccess; |
|
30 //----------------------------------------------------------------------------- |
|
31 // CBrowserViewImagesListBox::CBrowserViewImagesListBox |
|
32 // |
|
33 // EPOC first phase Constructor - must not leave |
|
34 //----------------------------------------------------------------------------- |
|
35 // |
|
36 CBrowserViewImagesListBox::CBrowserViewImagesListBox( ) |
|
37 : CAknDoubleLargeGraphicPopupMenuStyleListBox(), |
|
38 iFormat(), |
|
39 iCodec(), |
|
40 iDRMOutputBuf(NULL), |
|
41 iImageIndex(0) |
|
42 { |
|
43 iRetryingConvert = EFalse; |
|
44 } |
|
45 |
|
46 |
|
47 //----------------------------------------------------------------------------- |
|
48 // CBrowserViewImagesListBox::~CBrowserViewImagesListBox |
|
49 // |
|
50 // Destructor |
|
51 //----------------------------------------------------------------------------- |
|
52 // |
|
53 CBrowserViewImagesListBox::~CBrowserViewImagesListBox() |
|
54 { |
|
55 delete [] iDRMOutputBuf; |
|
56 delete iConverter; |
|
57 delete iCurrentBitmap; |
|
58 } |
|
59 |
|
60 //----------------------------------------------------------------------------- |
|
61 // CBrowserViewImagesListBox::ConstructL( |
|
62 // CCoeControl& aParent, |
|
63 // CArrayFixFlat<TBrCtlImageCarrier>& aImages ) |
|
64 // |
|
65 // Second Phase constructor |
|
66 //----------------------------------------------------------------------------- |
|
67 // |
|
68 void CBrowserViewImagesListBox::ConstructL( |
|
69 CCoeControl& aParent, |
|
70 CArrayFixFlat<TBrCtlImageCarrier>& aImages ) |
|
71 { |
|
72 iImages = &aImages; |
|
73 |
|
74 CAknDoubleLargeGraphicPopupMenuStyleListBox::ConstructL( &aParent, 0 ); |
|
75 |
|
76 iConverter = CMdaImageDescToBitmapUtility::NewL( *this ); |
|
77 |
|
78 iIcons = new( ELeave) CAknIconArray( 5 ); // iIcons must not be deleted in destructor! |
|
79 |
|
80 // create placeholder icon |
|
81 CGulIcon* icon = CreatePlaceholderIconL(); |
|
82 CleanupStack::PushL(icon); |
|
83 iIcons->AppendL(icon); |
|
84 CleanupStack::Pop(); // icon |
|
85 |
|
86 ItemDrawer()->ColumnData()->SetIconArray( iIcons ); // iIcons NOT DELETED IN DESTRUCTOR!!! |
|
87 |
|
88 // --------------------------------------------------------------------------------- |
|
89 // items |
|
90 |
|
91 iItemList = STATIC_CAST(CDesCArray*, Model()->ItemTextArray()); // MUST NOT BE DELETED IN DESTRUCTOR |
|
92 |
|
93 TBuf<KMaxAltTextLength> buf; |
|
94 TInt cstart = 0; |
|
95 TInt cend = 0; |
|
96 |
|
97 // append items with placeholder thumbnail |
|
98 for(TInt i=0; i<iImages->Count(); i++) |
|
99 { |
|
100 buf = _L("0\t"); |
|
101 TBrCtlImageCarrier& img = iImages->At(i); |
|
102 |
|
103 if( img.AltText().Length() > 0 ) |
|
104 { |
|
105 buf.Append(img.AltText().Left( buf.MaxLength() - buf.Length() ) ); |
|
106 } |
|
107 else |
|
108 { |
|
109 //get filename w/o extension from url |
|
110 cstart = img.Url().LocateReverse('/') + 1; |
|
111 cend = img.Url().LocateReverse('.'); |
|
112 if ( cend <= cstart ) cend = img.Url().Length(); |
|
113 { |
|
114 buf.Append( img.Url().Mid |
|
115 ( cstart, |
|
116 ( cend - cstart ) < ( buf.MaxLength() - buf.Length() ) |
|
117 ? |
|
118 ( cend - cstart ) |
|
119 : |
|
120 ( buf.MaxLength() - buf.Length() ) |
|
121 ) |
|
122 ); |
|
123 } |
|
124 } |
|
125 |
|
126 iItemList->AppendL(buf); |
|
127 } |
|
128 |
|
129 ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue ); |
|
130 } |
|
131 |
|
132 |
|
133 //----------------------------------------------------------------------------- |
|
134 // CBrowserViewImagesListBox::CurrentlySelectedImage() |
|
135 //----------------------------------------------------------------------------- |
|
136 // |
|
137 const TBrCtlImageCarrier& CBrowserViewImagesListBox::CurrentlySelectedImage() |
|
138 { |
|
139 return iImages->At( CurrentItemIndex() ); |
|
140 } |
|
141 |
|
142 |
|
143 //----------------------------------------------------------------------------- |
|
144 // CBrowserViewImagesListBox::CreatePlaceholderIconL() |
|
145 //----------------------------------------------------------------------------- |
|
146 // |
|
147 CGulIcon* CBrowserViewImagesListBox::CreatePlaceholderIconL() |
|
148 { |
|
149 CFbsBitmap* bitmap = new(ELeave) CFbsBitmap; |
|
150 CleanupStack::PushL(bitmap); |
|
151 if(KErrNone != bitmap->Create(TSize(42,32), EColor16M)) |
|
152 User::Leave(KErrNoMemory); |
|
153 |
|
154 // create icon |
|
155 CGulIcon* icon = CGulIcon::NewL(bitmap); // bitmap is owned, no mask used |
|
156 CleanupStack::Pop(); // bitmap |
|
157 return icon; |
|
158 } |
|
159 |
|
160 |
|
161 //----------------------------------------------------------------------------- |
|
162 // CBrowserViewImagesListBox::Fit() |
|
163 //----------------------------------------------------------------------------- |
|
164 // |
|
165 TSize CBrowserViewImagesListBox::Fit( const TSize& aSrc, const TSize& aTgt ) |
|
166 { |
|
167 TSize result1(aTgt); |
|
168 TSize result2(aTgt); |
|
169 |
|
170 TInt dA( aTgt.iWidth - aSrc.iWidth ); |
|
171 TInt dB( aTgt.iHeight - aSrc.iHeight ); |
|
172 TReal tmp = aSrc.iHeight + ((TReal)(aSrc.iHeight * dA) / (TReal)aSrc.iWidth); |
|
173 TReal res; |
|
174 Math::Round( res, tmp, 0); |
|
175 result1.iHeight = (TInt)res; |
|
176 tmp = aSrc.iWidth + ((TReal)(aSrc.iWidth * dB) / (TReal)aSrc.iHeight); |
|
177 Math::Round( res, tmp, 0); |
|
178 result2.iWidth = (TInt)res; |
|
179 |
|
180 TSize result; |
|
181 if(result1.iWidth <= aTgt.iWidth && result1.iHeight <= aTgt.iHeight) |
|
182 result = result1; |
|
183 else |
|
184 result = result2; |
|
185 |
|
186 return result; |
|
187 } |
|
188 |
|
189 |
|
190 //----------------------------------------------------------------------------- |
|
191 // CBrowserViewImagesListBox::CreateIconL( |
|
192 // CFbsBitmap* aBitmap, TBool aShrinkIt ) |
|
193 //----------------------------------------------------------------------------- |
|
194 // |
|
195 CGulIcon* CBrowserViewImagesListBox::CreateIconL( |
|
196 CFbsBitmap* aBitmap, TBool aShrinkIt) |
|
197 { |
|
198 CGulIcon* icon = NULL; |
|
199 |
|
200 // create icon |
|
201 if(aShrinkIt) |
|
202 { |
|
203 CFbsBitmap* bmp = new(ELeave)CFbsBitmap; |
|
204 CleanupStack::PushL(bmp); |
|
205 User::LeaveIfError(bmp->Create(TSize(42,32), EColor16M)); |
|
206 |
|
207 // create bitmap device |
|
208 CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(bmp); |
|
209 CleanupStack::PushL(dev); |
|
210 |
|
211 // create graphics context for bitmap device |
|
212 CGraphicsContext* ctx = NULL; |
|
213 User::LeaveIfError( dev->CreateContext(ctx) ); |
|
214 CleanupStack::PushL(ctx); |
|
215 |
|
216 // calculate aspect ratio |
|
217 TSize targetSize = Fit(aBitmap->SizeInPixels(), bmp->SizeInPixels()); |
|
218 // copy bitmap to temporary bitmap |
|
219 ctx->DrawBitmap(TRect(TPoint(0,0), targetSize), aBitmap, TRect(TPoint(0,0), aBitmap->SizeInPixels())); |
|
220 |
|
221 CleanupStack::PopAndDestroy(2); // ctx, dev |
|
222 |
|
223 icon = CGulIcon::NewL(bmp); // bmp is owned, no mask used |
|
224 CleanupStack::Pop(); // bmp |
|
225 delete aBitmap; |
|
226 } |
|
227 else |
|
228 { |
|
229 icon = CGulIcon::NewL(aBitmap); // bitmap is owned, no mask used |
|
230 } |
|
231 |
|
232 return icon; |
|
233 } |
|
234 |
|
235 |
|
236 //----------------------------------------------------------------------------- |
|
237 // CBrowserViewImagesListBox::StartConversionL() |
|
238 //----------------------------------------------------------------------------- |
|
239 // |
|
240 void CBrowserViewImagesListBox::StartConversionL() |
|
241 { |
|
242 // if we are out of index, stop |
|
243 if (iImageIndex >= iImages->Count()) |
|
244 { |
|
245 // zero non-owned pointers |
|
246 iCurrentBitmap = NULL; |
|
247 iIcons = NULL; |
|
248 iItemList = NULL; |
|
249 |
|
250 // delete converter because it is not needed anymore |
|
251 delete iConverter; |
|
252 iConverter = NULL; |
|
253 return; |
|
254 } |
|
255 |
|
256 // begin open |
|
257 TBrCtlImageCarrier& img = iImages->At( iImageIndex ); |
|
258 |
|
259 if ( img.ImageType() == EImageTypeWbmp ) |
|
260 { |
|
261 iConverter->OpenL( img.RawData(), &iFormat, &iCodec ); |
|
262 } |
|
263 else if ( img.ImageType() == EImageTypeOta ) |
|
264 { |
|
265 iConverter->OpenL( img.RawData(), &iFormat, &iCodec ); |
|
266 } |
|
267 else |
|
268 { |
|
269 iConverter->OpenL( img.RawData() ); |
|
270 } |
|
271 // MiuoOpenComplete will be called next |
|
272 } |
|
273 |
|
274 |
|
275 //----------------------------------------------------------------------------- |
|
276 // CBrowserViewImagesListBox::MiuoConvertComplete( TInt aError ) |
|
277 //----------------------------------------------------------------------------- |
|
278 // |
|
279 void CBrowserViewImagesListBox::MiuoConvertComplete( TInt aError ) |
|
280 { |
|
281 TRAPD(err, MiuoConvertCompleteL(aError)); |
|
282 if(err!=KErrNone) |
|
283 { |
|
284 DeleteCurrentBitmap(); |
|
285 TRAP(err, ConvertNextImageL()); |
|
286 } |
|
287 } |
|
288 |
|
289 |
|
290 //----------------------------------------------------------------------------- |
|
291 // CBrowserViewImagesListBox::ConvertNextImageL() |
|
292 //----------------------------------------------------------------------------- |
|
293 // |
|
294 void CBrowserViewImagesListBox::ConvertNextImageL() |
|
295 { |
|
296 // close converter |
|
297 iConverter->Close(); |
|
298 iImageIndex++; |
|
299 StartConversionL(); |
|
300 } |
|
301 |
|
302 |
|
303 //----------------------------------------------------------------------------- |
|
304 // CBrowserViewImagesListBox::CreateCurrentBitmapL( TBool aUseBitmapSize ) |
|
305 //----------------------------------------------------------------------------- |
|
306 // |
|
307 TInt CBrowserViewImagesListBox::CreateCurrentBitmapL( TBool aUseBitmapSize ) |
|
308 { |
|
309 DeleteCurrentBitmap(); // just in case |
|
310 iCurrentBitmap = new(ELeave) CFbsBitmap; |
|
311 |
|
312 TInt err = KErrNone; |
|
313 if( aUseBitmapSize ) |
|
314 { |
|
315 err = iCurrentBitmap->Create(iFrameInfo.iOverallSizeInPixels, EColor16M); |
|
316 } |
|
317 else |
|
318 { |
|
319 // Store the size of the thumbnail |
|
320 err = iCurrentBitmap->Create( TSize(42,32), EColor16M); |
|
321 } |
|
322 |
|
323 return err; |
|
324 } |
|
325 |
|
326 |
|
327 //----------------------------------------------------------------------------- |
|
328 // CBrowserViewImagesListBox::MiuoOpenComplete(TInt aError) |
|
329 //----------------------------------------------------------------------------- |
|
330 // |
|
331 void CBrowserViewImagesListBox::MiuoOpenComplete(TInt aError) |
|
332 { |
|
333 TRAPD(err, MiuoOpenCompleteL(aError)); |
|
334 if(err!=KErrNone) |
|
335 { |
|
336 // just in case, delete iCurrentBitmap if MiuoOpenCompleteL left |
|
337 // after allocating the bitmap |
|
338 DeleteCurrentBitmap(); |
|
339 |
|
340 // try to convert next thumbnail image until all have been tried |
|
341 // if this fails, placeholders will still remain |
|
342 TRAP(err, ConvertNextImageL()); |
|
343 } |
|
344 } |
|
345 |
|
346 |
|
347 //----------------------------------------------------------------------------- |
|
348 // CBrowserViewImagesListBox::MiuoOpenCompleteL( TInt aError ) |
|
349 //----------------------------------------------------------------------------- |
|
350 // |
|
351 void CBrowserViewImagesListBox::MiuoOpenCompleteL( TInt aError ) |
|
352 { |
|
353 if(aError==KErrNone) |
|
354 { |
|
355 iConverter->FrameInfo(0, iFrameInfo); |
|
356 // create new current bitmap for conversion |
|
357 TInt err = CreateCurrentBitmapL(); |
|
358 if(err!=KErrNone) |
|
359 { |
|
360 // unable to create bitmap, so we won't transfer its ownership to iIcons |
|
361 // -> delete |
|
362 DeleteCurrentBitmap(); |
|
363 // try next image if available |
|
364 ConvertNextImageL(); |
|
365 } |
|
366 else |
|
367 { |
|
368 // start converter, MiuoConvertComplete will be called next |
|
369 // if this leaves, iCurrentBitmap will remain allocated, but deleted in MiuoOpenComplete |
|
370 iConverter->ConvertL(*iCurrentBitmap); |
|
371 } |
|
372 } |
|
373 else |
|
374 { |
|
375 TInt error(KErrNone); |
|
376 |
|
377 // error occurred, we decide to try next image. placeholder |
|
378 // will remain in its place |
|
379 // if this leaves, iCurrentBitmap is not allocated |
|
380 |
|
381 // input buffers for image conversion |
|
382 TBrCtlImageCarrier& img = iImages->At( iImageIndex ); |
|
383 iImageDataPtr.Set( (const TUint8*) img.RawData().Ptr(), |
|
384 img.RawData().Size() ); |
|
385 |
|
386 |
|
387 TInt inputBufLen = iImageDataPtr.Size() + 1; // Input buffer length |
|
388 |
|
389 HBufC8* bufInput = HBufC8::NewL( inputBufLen + 1 ); |
|
390 CleanupStack::PushL( bufInput ); |
|
391 TPtr8 ptrInput( NULL,0,0 ); |
|
392 ptrInput.Set( bufInput->Des() ); |
|
393 ptrInput.Append( EView ); |
|
394 ptrInput.Append( (const TUint8 *) iImageDataPtr.Ptr(), iImageDataPtr.Size() ); |
|
395 |
|
396 // output buffer for image conversion |
|
397 if ( iDRMOutputBuf ) |
|
398 { |
|
399 delete [] iDRMOutputBuf; |
|
400 iDRMOutputBuf = NULL; |
|
401 } |
|
402 TInt outputBufLen = iImageDataPtr.Size() + 256; // Output buffer length |
|
403 iDRMOutputBuf = new (ELeave) TUint8[outputBufLen]; |
|
404 TPtr8 ptrOutput( iDRMOutputBuf, 0, outputBufLen ); |
|
405 |
|
406 |
|
407 // Do we have a DRM image? |
|
408 TAgent agentDRM; |
|
409 TRequestStatus status; |
|
410 |
|
411 ContentAccess::CManager* manager = CManager::NewLC(); |
|
412 |
|
413 RArray<ContentAccess::TAgent> agents; |
|
414 //Add agents to cleanup stack |
|
415 CleanupClosePushL(agents); |
|
416 |
|
417 manager->ListAgentsL( agents ); |
|
418 for ( TInt i = 0; i < agents.Count(); i++ ) |
|
419 { |
|
420 if ( agents[i].Name().Compare( KOmaDrm2AgentName ) == 0) |
|
421 { |
|
422 agentDRM = agents[i]; |
|
423 break; |
|
424 } |
|
425 } |
|
426 |
|
427 //Cleanup the agents |
|
428 CleanupStack::PopAndDestroy(/*agents*/); |
|
429 |
|
430 // convert the DRM image (asynchronous) |
|
431 manager->AgentSpecificCommand( agentDRM, |
|
432 EBufferContainsOma1Dcf, |
|
433 iImageDataPtr, |
|
434 ptrOutput, |
|
435 status ); |
|
436 // wait for it to finish |
|
437 User::WaitForRequest(status); |
|
438 |
|
439 // Conversion completed ok (if not image is skipped) |
|
440 if ( status == KErrNone ) |
|
441 { |
|
442 //Now decrypt the buffer. |
|
443 error = manager->AgentSpecificCommand( |
|
444 agentDRM, |
|
445 EDecryptOma1DcfBuffer, |
|
446 ptrInput, |
|
447 ptrOutput); |
|
448 if ( !error ) |
|
449 { |
|
450 iImageDataPtr.Set( (const TUint8*) ptrOutput.Ptr(), |
|
451 ptrOutput.Size() ); |
|
452 delete iConverter; |
|
453 iConverter = NULL; |
|
454 TRAP( error, iConverter = CMdaImageDescToBitmapUtility::NewL( *this ); ); |
|
455 |
|
456 // Decrypted ok (if not image is skipped) |
|
457 if ( !error ) |
|
458 { |
|
459 TRAP_IGNORE( iConverter->OpenL( iImageDataPtr ) ); |
|
460 } |
|
461 } |
|
462 } |
|
463 CleanupStack::PopAndDestroy(); // bufInput |
|
464 CleanupStack::Pop(); //manager |
|
465 } |
|
466 } |
|
467 |
|
468 |
|
469 //----------------------------------------------------------------------------- |
|
470 // CBrowserViewImagesListBox::MiuoConvertCompleteL( TInt aError ) |
|
471 //----------------------------------------------------------------------------- |
|
472 // |
|
473 void CBrowserViewImagesListBox::MiuoConvertCompleteL(TInt aError) |
|
474 { |
|
475 if ( !aError ) |
|
476 { |
|
477 // create icon out of the converted bitmap |
|
478 // if retrying convert, we have original size bitmap so shrink it into thumbnail icon |
|
479 CGulIcon* icon = CreateIconL(iCurrentBitmap, iRetryingConvert); |
|
480 iCurrentBitmap = NULL; // ownership transferred to icon |
|
481 iRetryingConvert = EFalse; // no more retrying |
|
482 CleanupStack::PushL(icon); |
|
483 iIcons->AppendL(icon); |
|
484 CleanupStack::Pop(); // icon now owned by iIcons |
|
485 |
|
486 // append item |
|
487 TBuf<KMaxAltTextLength> buf; |
|
488 TInt cstart = 1; |
|
489 TInt cend = 1; |
|
490 buf = _L(""); |
|
491 buf.AppendNum(iIcons->Count()-1); // 0 is always the placeholder |
|
492 buf.Append(_L("\t")); |
|
493 |
|
494 TBrCtlImageCarrier& img = iImages->At(iImageIndex); |
|
495 |
|
496 if ( img.AltText().Length() > 0 ) |
|
497 { |
|
498 buf.Append( img.AltText().Left( buf.MaxLength() - buf.Length() ) ); |
|
499 } |
|
500 else |
|
501 { |
|
502 //get filename w/o extension from url |
|
503 cstart = img.Url().LocateReverse('/') + 1; |
|
504 cend = img.Url().LocateReverse('.'); |
|
505 if ( cend <= cstart ) cend = img.Url().Length(); |
|
506 { |
|
507 buf.Append( img.Url().Mid |
|
508 ( cstart, |
|
509 ( cend - cstart ) < ( buf.MaxLength() - buf.Length() ) |
|
510 ? |
|
511 ( cend - cstart ) |
|
512 : |
|
513 ( buf.MaxLength() - buf.Length() ) |
|
514 ) |
|
515 ); |
|
516 } |
|
517 } |
|
518 |
|
519 // replace item (having placeholder icon) with real thumbnail |
|
520 TRAPD(err, iItemList->InsertL(iImageIndex,buf)); |
|
521 // if succeeded, delete the old one that has moved next to the new item |
|
522 // in case error occurred, the placeholder will remain. |
|
523 if(err==KErrNone) |
|
524 iItemList->Delete(iImageIndex+1); |
|
525 |
|
526 // redraw list |
|
527 HandleItemAdditionL(); |
|
528 |
|
529 // open next image and convert it |
|
530 ConvertNextImageL(); |
|
531 } |
|
532 else |
|
533 { |
|
534 if( aError == KErrArgument ) |
|
535 { |
|
536 // retry this image |
|
537 // iCurrentBitmap has been allocated when MiuoConvertComplete |
|
538 // is called, so delete it |
|
539 DeleteCurrentBitmap(); |
|
540 CreateCurrentBitmapL(ETrue); // use original image size |
|
541 iRetryingConvert = ETrue; |
|
542 iConverter->ConvertL(*iCurrentBitmap); // retry conversion |
|
543 } |
|
544 else |
|
545 { |
|
546 DeleteCurrentBitmap(); |
|
547 // convert next image (anyway) |
|
548 ConvertNextImageL(); |
|
549 } |
|
550 } |
|
551 } |
|
552 |
|
553 |
|
554 //----------------------------------------------------------------------------- |
|
555 // CBrowserViewImagesListBox::DeleteCurrentBitmap() |
|
556 //----------------------------------------------------------------------------- |
|
557 // |
|
558 void CBrowserViewImagesListBox::DeleteCurrentBitmap() |
|
559 { |
|
560 delete iCurrentBitmap; |
|
561 iCurrentBitmap = NULL; |
|
562 } |
|
563 |
|
564 |
|
565 |
|
566 //----------------------------------------------------------------------------- |
|
567 // CBrowserViewImagesListBox::DeleteCurrentBitmap() |
|
568 // |
|
569 // not used - comes from abstract base class |
|
570 //----------------------------------------------------------------------------- |
|
571 // |
|
572 void CBrowserViewImagesListBox::MiuoCreateComplete(TInt /* aError */) |
|
573 { |
|
574 } |
|
575 |
|
576 |
|
577 // End of File |