59 * Add a image to wallpaper cache |
59 * Add a image to wallpaper cache |
60 */ |
60 */ |
61 TAknsSrvWallpaper* CAknsSrvWallpaperCache::AddL( RFs& aRFs, const TDesC& aFileName, |
61 TAknsSrvWallpaper* CAknsSrvWallpaperCache::AddL( RFs& aRFs, const TDesC& aFileName, |
62 const TSize aTrgSize, const TSize aMaxSize ) |
62 const TSize aTrgSize, const TSize aMaxSize ) |
63 { |
63 { |
64 if ( aFileName.Length() == 0 ) |
|
65 { |
|
66 return NULL; |
|
67 } |
|
68 |
|
69 if ( aTrgSize == TSize(-1, -1) ) |
64 if ( aTrgSize == TSize(-1, -1) ) |
70 { |
65 { |
71 TryDecodeImageL( aRFs,aFileName ); |
66 TryDecodeImageL( aRFs,aFileName ); |
72 return NULL; |
67 return NULL; |
73 } |
68 } |
74 |
69 |
|
70 TBool cached = EFalse; |
75 TAknsSrvWallpaper* wp = NULL; |
71 TAknsSrvWallpaper* wp = NULL; |
|
72 |
76 wp = CachedImage( aFileName ); |
73 wp = CachedImage( aFileName ); |
77 if ( wp ) |
74 if ( !wp ) |
78 { |
75 { |
79 return wp; |
76 wp = new TAknsSrvWallpaper; |
80 } |
77 ZeroItem ( *wp ); |
81 |
78 } |
82 wp = new ( ELeave ) TAknsSrvWallpaper; |
79 else |
83 ZeroItem ( *wp ); |
80 { |
84 CleanupStack::PushL( wp ); |
81 cached = ETrue; |
|
82 } |
85 |
83 |
86 |
84 |
87 _LIT( KSvgFileExt, ".svg" ); |
85 _LIT( KSvgFileExt, ".svg" ); |
88 TBool isSvgFormat = aFileName.Right(4).CompareF( KSvgFileExt ) == 0; |
86 TBool isSvgFormat = aFileName.Right(4).CompareF( KSvgFileExt ) == 0; |
89 |
87 |
90 TSize prtSize, lscSize; |
88 TBool needDecodePortrait = EFalse; |
|
89 TBool needDecodeLandscape = EFalse; |
91 |
90 |
92 if( aTrgSize.iHeight >= aTrgSize.iWidth ) //Portait |
91 if( aTrgSize.iHeight >= aTrgSize.iWidth ) //Portait |
93 { |
92 { |
94 prtSize = aTrgSize; |
93 if ( aTrgSize != iPrtSize || ( !wp->iPortrait && !wp->iPortraitMask) ) |
95 lscSize = TSize( aTrgSize.iHeight, aTrgSize.iWidth ); |
94 { |
|
95 needDecodePortrait = ETrue; |
|
96 iPrtSize = aTrgSize; |
|
97 } |
96 } |
98 } |
97 else //Landscape |
99 else //Landscape |
98 { |
100 { |
99 prtSize = TSize( aTrgSize.iHeight, aTrgSize.iWidth ); |
101 if ( aTrgSize != iLscSize || ( !wp->iLandscape && !wp->iLandscapeMask ) ) |
100 lscSize = aTrgSize; |
102 { |
|
103 needDecodeLandscape = ETrue; |
|
104 iLscSize = aTrgSize; |
|
105 } |
101 } |
106 } |
102 |
107 |
103 if( isSvgFormat ) |
108 if( isSvgFormat ) |
104 { |
109 { |
105 CAknsSrvSVGImageDecoder* svgdecoder = CAknsSrvSVGImageDecoder::NewL(); |
110 if( needDecodePortrait ) |
106 CleanupStack::PushL( svgdecoder ); |
111 { |
107 svgdecoder->DecodeImageL( aFileName, prtSize, wp->iPortrait, |
112 CAknsSrvSVGImageDecoder* svgdecoder = CAknsSrvSVGImageDecoder::NewL(); |
108 wp->iPortraitMask ); |
113 CleanupStack::PushL( svgdecoder ); |
109 svgdecoder->DecodeImageL( aFileName, lscSize, wp->iLandscape, |
114 svgdecoder->DecodeImageL( |
110 wp->iLandscapeMask ); |
115 aFileName, |
111 CleanupStack::PopAndDestroy( svgdecoder ); |
116 aTrgSize, |
|
117 wp->iPortrait, |
|
118 wp->iPortraitMask ); |
|
119 CleanupStack::PopAndDestroy( svgdecoder ); |
|
120 } |
|
121 if( needDecodeLandscape ) |
|
122 { |
|
123 CAknsSrvSVGImageDecoder* svgdecoder = CAknsSrvSVGImageDecoder::NewL(); |
|
124 CleanupStack::PushL( svgdecoder ); |
|
125 svgdecoder->DecodeImageL( |
|
126 aFileName, |
|
127 aTrgSize, |
|
128 wp->iLandscape, |
|
129 wp->iLandscapeMask ); |
|
130 CleanupStack::PopAndDestroy( svgdecoder ); |
|
131 } |
112 } |
132 } |
113 else |
133 else |
114 { |
134 { |
115 CAknsSrvImageConverter::DecodeImageL( aRFs, aFileName, prtSize, |
135 if( needDecodePortrait ) |
116 wp->iPortrait, wp->iPortraitMask, aMaxSize ); |
136 { |
117 CAknsSrvImageConverter::DecodeImageL( aRFs, aFileName, lscSize, |
137 CAknsSrvImageConverter::DecodeImageL( |
118 wp->iLandscape, wp->iLandscapeMask, aMaxSize ); |
138 aRFs, |
119 } |
139 aFileName, |
120 |
140 aTrgSize, |
|
141 wp->iPortrait, |
|
142 wp->iPortraitMask, |
|
143 aMaxSize ); |
|
144 } |
|
145 if( needDecodeLandscape ) |
|
146 { |
|
147 CAknsSrvImageConverter::DecodeImageL( |
|
148 aRFs, |
|
149 aFileName, |
|
150 aTrgSize, |
|
151 wp->iLandscape, |
|
152 wp->iLandscapeMask, |
|
153 aMaxSize ); |
|
154 } |
|
155 } |
121 wp->iName.Copy( aFileName ); |
156 wp->iName.Copy( aFileName ); |
122 |
157 if ( !cached ) |
123 RemoveOldestItem(); |
158 { |
124 iCache.Append( wp ); |
159 RemoveOldestItem(); |
125 CleanupStack::Pop( wp ); |
160 iCache.Append( wp ); |
126 |
161 } |
127 return wp; |
162 return wp; |
128 } |
163 } |
129 |
164 |
130 /** |
165 /** |
131 * Try Decode image |
166 * Try Decode image |