88 CWmImageConverter::~CWmImageConverter() |
88 CWmImageConverter::~CWmImageConverter() |
89 { |
89 { |
90 Cancel(); |
90 Cancel(); |
91 delete iImageDecoder; |
91 delete iImageDecoder; |
92 iFs.Close(); |
92 iFs.Close(); |
93 if (iBitmap) |
93 if ( iBitmap ) |
94 { |
94 { |
95 delete iBitmap; |
95 delete iBitmap; |
96 iBitmap = NULL; |
96 iBitmap = NULL; |
97 } |
97 } |
98 if (iMask) |
98 if ( iMask ) |
99 { |
99 { |
100 delete iMask; |
100 delete iMask; |
101 iMask = NULL; |
101 iMask = NULL; |
102 } |
102 } |
103 delete iScaler; |
103 delete iScaler; |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------- |
|
107 // CWmImageConverter::HandleIconString |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 TInt CWmImageConverter::HandleIconString( |
|
111 TInt aWidth, TInt aHeight, |
|
112 const TDesC& aIconStr ) |
|
113 { |
|
114 TInt err( KErrNone ); |
|
115 TRAP( err, HandleIconStringL( aWidth, aHeight, aIconStr ); ); |
|
116 if ( KErrNone != err ) |
|
117 { |
|
118 iState = EFailed; |
|
119 if ( iBitmap ) |
|
120 { |
|
121 delete iBitmap; |
|
122 iBitmap = NULL; |
|
123 } |
|
124 if ( iMask ) |
|
125 { |
|
126 delete iMask; |
|
127 iMask = NULL; |
|
128 } |
|
129 } |
|
130 return err; |
104 } |
131 } |
105 |
132 |
106 // --------------------------------------------------------- |
133 // --------------------------------------------------------- |
107 // CWmImageConverter::HandleIconStringL |
134 // CWmImageConverter::HandleIconStringL |
108 // --------------------------------------------------------- |
135 // --------------------------------------------------------- |
109 // |
136 // |
110 void CWmImageConverter::HandleIconStringL( |
137 void CWmImageConverter::HandleIconStringL( |
111 TInt aWidth, TInt aHeight, |
138 TInt aWidth, TInt aHeight, |
112 const TDesC& aIconStr ) |
139 const TDesC& aIconStr ) |
113 { |
140 { |
|
141 iConversionMethod = EUnrecognized; |
|
142 iState = EDecoding; |
114 if ( aIconStr.Length() ) |
143 if ( aIconStr.Length() ) |
115 { |
144 { |
116 TAknsItemID skinItemId; |
145 TAknsItemID skinItemId; |
117 skinItemId.iMajor = 0; |
146 skinItemId.iMajor = 0; |
118 skinItemId.iMinor = 0; |
147 skinItemId.iMinor = 0; |
119 TInt bitmapId( KErrNotFound ); |
148 TInt bitmapId( KErrNotFound ); |
120 TInt maskId( KErrNotFound ); |
149 TInt maskId( KErrNotFound ); |
121 TUid appUid; |
150 TUid appUid; |
122 iFilename = KNullDesC; |
151 iFilename = KNullDesC; |
123 iScaleNeeded = EFalse; |
152 iScaleNeeded = EFalse; |
124 iSize.SetSize( aWidth, aHeight ); |
153 iSize.SetSize( aWidth, aHeight ); |
125 |
154 |
126 if ( ResolveSkinIdAndMifId( |
155 if ( ResolveSkinIdAndMifId( |
127 aIconStr, skinItemId, bitmapId, maskId, iFilename ) ) |
156 aIconStr, skinItemId, bitmapId, maskId, iFilename ) ) |
128 { |
157 { |
152 iConversionMethod = EImageIcon; |
181 iConversionMethod = EImageIcon; |
153 CreateIconFromOtherL( aIconStr ); |
182 CreateIconFromOtherL( aIconStr ); |
154 } |
183 } |
155 else |
184 else |
156 { |
185 { |
157 iConversionMethod = EUnrecognized; |
|
158 User::Leave( KErrArgument ); |
186 User::Leave( KErrArgument ); |
159 } |
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 User::Leave( KErrArgument ); |
160 } |
192 } |
161 } |
193 } |
162 |
194 |
163 // --------------------------------------------------------- |
195 // --------------------------------------------------------- |
164 // CWmImageConverter::CreateIconFromUidL |
196 // CWmImageConverter::CreateIconFromUidL |
334 // CWmImageConverter::CreateIconFromOtherL |
370 // CWmImageConverter::CreateIconFromOtherL |
335 // --------------------------------------------------------- |
371 // --------------------------------------------------------- |
336 // |
372 // |
337 void CWmImageConverter::CreateIconFromOtherL( const TDesC& aFileName ) |
373 void CWmImageConverter::CreateIconFromOtherL( const TDesC& aFileName ) |
338 { |
374 { |
339 if ( IsActive() || iState != EIdle ) |
375 if ( IsActive() ) |
340 { |
376 { |
341 User::Leave( KErrNotReady ); |
377 User::Leave( KErrNotReady ); |
342 } |
378 } |
343 |
379 |
344 if ( iImageDecoder ) delete iImageDecoder; iImageDecoder = NULL; |
380 if ( iImageDecoder ) delete iImageDecoder; iImageDecoder = NULL; |
362 |
398 |
363 if ( size != iSize ) |
399 if ( size != iSize ) |
364 { |
400 { |
365 iScaleNeeded = ETrue; |
401 iScaleNeeded = ETrue; |
366 } |
402 } |
|
403 |
367 // start conversion to bitmap |
404 // start conversion to bitmap |
368 iState = EDecoding; |
|
369 iImageDecoder->Convert( &iStatus, *iBitmap, *iMask ); |
405 iImageDecoder->Convert( &iStatus, *iBitmap, *iMask ); |
370 SetActive(); |
406 SetActive(); |
371 } |
407 } |
372 |
408 |
373 // --------------------------------------------------------- |
409 // --------------------------------------------------------- |
374 // CWmImageConverter::DoCancel |
410 // CWmImageConverter::DoCancel |
375 // --------------------------------------------------------- |
411 // --------------------------------------------------------- |
376 // |
412 // |
377 void CWmImageConverter::DoCancel() |
413 void CWmImageConverter::DoCancel() |
378 { |
414 { |
379 if( iState == EDecoding ) |
415 if( iState == EDecoding && |
380 { |
416 iConversionMethod == EImageIcon ) |
381 iImageDecoder->Cancel(); |
417 { |
|
418 iImageDecoder->Cancel(); |
|
419 iState = EIdle; |
382 if ( iObserver ) |
420 if ( iObserver ) |
383 { |
421 { |
384 iObserver->NotifyCompletion( KErrCancel ); |
422 iObserver->NotifyCompletion( KErrCancel ); |
385 } |
423 } |
386 } |
424 } |
387 else if( iState == EScalingBitmap || |
425 else if( iState == EScalingBitmap || |
388 iState == EScalingMask ) |
426 iState == EScalingMask ) |
389 { |
427 { |
390 iScaler->Cancel(); |
428 iScaler->Cancel(); |
|
429 iState = EIdle; |
391 if ( iObserver ) |
430 if ( iObserver ) |
392 { |
431 { |
393 iObserver->NotifyCompletion( KErrCancel ); |
432 iObserver->NotifyCompletion( KErrCancel ); |
394 } |
433 } |
395 } |
434 } |
396 else |
435 else |
397 { |
436 { |
398 // State is EIdle, do nothing |
437 // State is EIdle, do nothing |
399 } |
438 } |
400 iState = EIdle; |
|
401 iScaleNeeded = EFalse; |
439 iScaleNeeded = EFalse; |
402 } |
440 } |
403 |
441 |
404 // --------------------------------------------------------- |
442 // --------------------------------------------------------- |
405 // CWmImageConverter::RunL |
443 // CWmImageConverter::RunL |
527 { |
565 { |
528 if ( !IsActive() && |
566 if ( !IsActive() && |
529 iBitmap && |
567 iBitmap && |
530 ( iState == EDecoding || iState == EIdle ) ) |
568 ( iState == EDecoding || iState == EIdle ) ) |
531 { |
569 { |
|
570 iState = EScalingBitmap; |
532 // the maintain aspect ratio is by default set to true |
571 // the maintain aspect ratio is by default set to true |
533 iScaler->Scale( &iStatus, *iBitmap, TSize( aWidth,aHeight ), EFalse ); |
572 iScaler->Scale( &iStatus, *iBitmap, TSize( aWidth,aHeight ), EFalse ); |
534 iState = EScalingBitmap; |
|
535 SetActive(); |
573 SetActive(); |
536 } |
574 } |
537 } |
575 } |
538 |
576 |
539 // --------------------------------------------------------- |
577 // --------------------------------------------------------- |
544 { |
582 { |
545 if ( !IsActive() && |
583 if ( !IsActive() && |
546 iState == EScalingBitmap && |
584 iState == EScalingBitmap && |
547 iMask ) |
585 iMask ) |
548 { |
586 { |
|
587 iState = EScalingMask; |
549 // the maintain aspect ratio is by default set to true |
588 // the maintain aspect ratio is by default set to true |
550 iScaler->Scale( &iStatus, *iMask, TSize(aWidth,aHeight), EFalse ); |
589 iScaler->Scale( &iStatus, *iMask, TSize(aWidth,aHeight), EFalse ); |
551 iState = EScalingMask; |
|
552 SetActive(); |
590 SetActive(); |
553 } |
591 } |
554 } |
592 } |
555 |
593 |
556 // --------------------------------------------------------- |
594 // --------------------------------------------------------- |
605 // Syntax: uid(0x12345678) |
643 // Syntax: uid(0x12345678) |
606 TInt error = KErrNotFound; |
644 TInt error = KErrNotFound; |
607 TInt pos = aPath.FindF( KUid ); |
645 TInt pos = aPath.FindF( KUid ); |
608 if( pos == 0 ) |
646 if( pos == 0 ) |
609 { |
647 { |
610 // Skip skin token |
648 // Skip uid token |
611 pos += KUid().Length(); |
649 pos += KUid().Length(); |
612 |
650 |
613 // Initialize lexer |
651 // Initialize lexer |
614 TLex lex( aPath.Mid( pos ) ); |
652 TLex lex( aPath.Mid( pos ) ); |
615 |
653 lex.SkipSpaceAndMark(); |
|
654 |
616 // Check left parenthesis |
655 // Check left parenthesis |
617 if ( lex.Get() == KLeftParenthesis ) |
656 if ( lex.Get() == KLeftParenthesis ) |
618 { |
657 { |
619 lex.SkipSpaceAndMark(); |
658 error = ParseNextUint( lex, (TUint&)aUid.iUid ); |
620 lex.SkipCharacters(); |
|
621 |
|
622 TPtrC mtoken = lex.MarkedToken(); |
|
623 pos = mtoken.FindF( KHexPrefix ); |
|
624 if ( pos == 0 ) |
|
625 { |
|
626 TLex lex( mtoken.Mid( KHexPrefix().Length() ) ); |
|
627 TUint id = 0; |
|
628 error = lex.Val( id, EHex ); |
|
629 aUid = TUid::Uid( (TInt)id ); |
|
630 } |
|
631 else |
|
632 { |
|
633 TInt id( 0 ); |
|
634 error = lex.Val( id ); |
|
635 aUid.iUid = id; |
|
636 } |
|
637 } |
659 } |
638 } |
660 } |
639 |
661 |
640 return (error == KErrNone ); |
662 return (error == KErrNone ); |
641 } |
663 } |
655 // Skip skin token |
677 // Skip skin token |
656 pos += KSkin().Length(); |
678 pos += KSkin().Length(); |
657 |
679 |
658 // Initialize lexer |
680 // Initialize lexer |
659 TLex lex( aPath.Mid( pos ) ); |
681 TLex lex( aPath.Mid( pos ) ); |
|
682 lex.SkipSpaceAndMark(); |
660 |
683 |
661 lex.SkipSpaceAndMark(); |
|
662 // Check left parenthesis |
684 // Check left parenthesis |
663 if ( lex.Get() == KLeftParenthesis ) |
685 if ( lex.Get() == KLeftParenthesis ) |
664 { |
686 { |
665 pos++; |
687 TUint majorId = 0; |
666 TLex lex( aPath.Mid( pos ) ); |
688 TUint minorId = 0; |
667 lex.SkipSpaceAndMark(); |
689 error = ParseNextUint( lex, majorId ); |
668 |
690 error |= ParseNextUint( lex, minorId ); |
669 TPtrC mtoken = lex.MarkedToken(); |
691 aItemId.Set( majorId, minorId ); |
670 pos = mtoken.FindF( KHexPrefix ); |
|
671 if ( pos == 0 ) |
|
672 { |
|
673 TUint majorId( 0 ); |
|
674 TUint minorId( 0 ); |
|
675 lex.Assign( mtoken.Mid( KHexPrefix().Length() ) ); |
|
676 error = lex.Val( majorId, EHex ); |
|
677 lex.SkipSpace(); |
|
678 lex.SkipAndMark( KHexPrefix().Length() ); |
|
679 error |= lex.Val( minorId, EHex ); |
|
680 aItemId.Set( majorId, minorId ); |
|
681 } |
|
682 else |
|
683 { |
|
684 TInt majorId(0); |
|
685 TInt minorId(0); |
|
686 error = lex.Val( majorId ); |
|
687 lex.SkipSpace(); |
|
688 error |= lex.Val( minorId ); |
|
689 aItemId.Set( majorId, minorId ); |
|
690 } |
|
691 } |
692 } |
692 } |
693 } |
693 |
694 |
694 return (error == KErrNone ); |
695 return (error == KErrNone ); |
695 } |
696 } |
709 { |
710 { |
710 // Skip mif token |
711 // Skip mif token |
711 pos += KMif().Length(); |
712 pos += KMif().Length(); |
712 // Initialize lexer |
713 // Initialize lexer |
713 TLex lex( aPath.Mid( pos ) ); |
714 TLex lex( aPath.Mid( pos ) ); |
714 |
715 lex.SkipSpaceAndMark(); |
|
716 |
715 // Check left parenthesis |
717 // Check left parenthesis |
716 if ( lex.Get() == KLeftParenthesis ) |
718 if ( lex.Get() == KLeftParenthesis ) |
717 { |
719 { |
718 lex.SkipSpaceAndMark(); |
720 lex.SkipSpaceAndMark(); |
719 lex.SkipCharacters(); |
721 lex.SkipCharacters(); |
720 // Resolve MifFile name |
722 // Resolve MifFile name |
721 aFileName.Copy(lex.MarkedToken()); |
723 aFileName.Copy(lex.MarkedToken()); |
722 if( aFileName.Length()!= 0) |
724 if( aFileName.Length()!= 0) |
723 { |
725 { |
724 // Resolve bitmap id |
726 TUint bitmap, mask; |
725 lex.SkipSpace(); |
727 error = ParseNextUint( lex, bitmap ); |
726 error = lex.Val( aBitmapId ); |
728 ParseNextUint( lex, mask ); // mask is not mandatory |
727 |
729 aBitmapId = bitmap; |
728 // Resolve mask id |
730 aMaskId = mask; |
729 // dont return error if it is not found, that is ok |
|
730 lex.SkipSpace(); |
|
731 lex.Val( aMaskId ); |
|
732 } |
|
733 else |
|
734 { |
|
735 error = KErrNotFound; |
|
736 } |
731 } |
737 } |
732 } |
738 } |
733 } |
739 return (error == KErrNone ); |
734 return ( error == KErrNone ); |
740 } |
735 } |
741 |
736 |
742 // --------------------------------------------------------------------------- |
737 // --------------------------------------------------------------------------- |
743 // CWmImageConverter::ResolveSkinIdAndMifId |
738 // CWmImageConverter::ResolveSkinIdAndMifId |
744 // --------------------------------------------------------------------------- |
739 // --------------------------------------------------------------------------- |
794 itemData->SetBitmap( NULL ); |
789 itemData->SetBitmap( NULL ); |
795 mask = itemData->Mask(); |
790 mask = itemData->Mask(); |
796 itemData->SetMask( NULL ); |
791 itemData->SetMask( NULL ); |
797 CleanupStack::PopAndDestroy( itemData ); |
792 CleanupStack::PopAndDestroy( itemData ); |
798 } |
793 } |
799 else |
794 else |
800 { |
795 { |
801 // look in imagetable |
796 // look in imagetable |
802 CAknsImageTableItemData* iconData = NULL; |
797 CAknsImageTableItemData* iconData = NULL; |
803 TRAP( err, iconData = static_cast<CAknsImageTableItemData*>( |
798 TRAP( err, iconData = static_cast<CAknsImageTableItemData*>( |
804 skin->CreateUncachedItemDataL( aItemId, EAknsITImageTable ) ); ); |
799 skin->CreateUncachedItemDataL( aItemId, EAknsITImageTable ) ); ); |
853 bitmap = AknIconUtils::CreateIconL( *this, aBitmapId ); |
849 bitmap = AknIconUtils::CreateIconL( *this, aBitmapId ); |
854 } |
850 } |
855 } |
851 } |
856 else |
852 else |
857 { |
853 { |
|
854 iState = EIdle; |
858 User::Leave( KErrArgument ); |
855 User::Leave( KErrArgument ); |
859 } |
856 } |
860 |
857 |
861 iBitmap = bitmap; |
858 iBitmap = bitmap; |
862 iMask = mask; |
859 iMask = mask; |
863 |
860 |
864 TInt err = AknIconUtils::SetSize( iBitmap , iSize, EAspectRatioNotPreserved ); |
861 TInt err = AknIconUtils::SetSize( iBitmap , iSize, EAspectRatioNotPreserved ); |
865 if ( KErrNone == err ) |
862 if ( KErrNone == err ) |
866 { |
863 { |
867 err = AknIconUtils::SetSize( iMask , iSize, EAspectRatioNotPreserved ); |
864 err = AknIconUtils::SetSize( iMask , iSize, EAspectRatioNotPreserved ); |
868 } |
865 } |
869 |
866 |
|
867 iState = EIdle; |
870 // notify observer |
868 // notify observer |
871 iObserver->NotifyCompletion( err ); |
869 iObserver->NotifyCompletion( err ); |
872 } |
870 } |
873 |
871 |
874 // --------------------------------------------------------------------------- |
872 // --------------------------------------------------------------------------- |
|
873 // CWmImageConverter::ParseNextUint() |
|
874 // --------------------------------------------------------------------------- |
|
875 // |
|
876 TInt CWmImageConverter::ParseNextUint( TLex& aLex, TUint& aValue ) |
|
877 { |
|
878 TInt error = KErrNone; |
|
879 aLex.SkipSpaceAndMark(); |
|
880 aLex.SkipCharacters(); |
|
881 |
|
882 TPtrC mtoken = aLex.MarkedToken(); |
|
883 TInt pos = mtoken.FindF( KHexPrefix ); |
|
884 if ( pos == 0 ) |
|
885 { |
|
886 TLex innerLex( mtoken.Mid( KHexPrefix().Length() ) ); |
|
887 error = innerLex.Val( aValue, EHex ); |
|
888 } |
|
889 else |
|
890 { |
|
891 TLex innerLex( mtoken ); |
|
892 error = innerLex.Val( aValue, EDecimal ); |
|
893 } |
|
894 |
|
895 return error; |
|
896 } |
|
897 |
|
898 // --------------------------------------------------------------------------- |
875 // CWmImageConverter::SetLogoSize() |
899 // CWmImageConverter::SetLogoSize() |
876 // --------------------------------------------------------------------------- |
900 // --------------------------------------------------------------------------- |
877 // |
901 // |
878 void CWmImageConverter::SetLogoSize( const TSize& aSize ) |
902 void CWmImageConverter::SetLogoSize( const TSize& aSize ) |
879 { |
903 { |
894 // --------------------------------------------------------------------------- |
918 // --------------------------------------------------------------------------- |
895 // |
919 // |
896 void CWmImageConverter::RetrieveIconFileHandleL( |
920 void CWmImageConverter::RetrieveIconFileHandleL( |
897 RFile& aFile, const TIconFileType /*aType*/ ) |
921 RFile& aFile, const TIconFileType /*aType*/ ) |
898 { |
922 { |
899 User::LeaveIfError( aFile.Open( iFs, iFilename, EFileShareAny ) ); |
923 TInt err = aFile.Open( iFs, iFilename, |
|
924 EFileRead | EFileShareReadersOnly ); |
|
925 if ( KErrNone != err ) |
|
926 { |
|
927 iState = EIdle; |
|
928 User::Leave( err ); |
|
929 } |
900 } |
930 } |
901 |
931 |
902 // --------------------------------------------------------------------------- |
932 // --------------------------------------------------------------------------- |
903 // CWmImageConverter::Finished |
933 // CWmImageConverter::Finished |
904 // --------------------------------------------------------------------------- |
934 // --------------------------------------------------------------------------- |