|
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 * CWmImageConverter declaration |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef WMIMAGECONVERTER_H |
|
20 #define WMIMAGECONVERTER_H |
|
21 |
|
22 //includes |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 #include <AknIconUtils.h> // MAknIconFileProvider |
|
27 |
|
28 // Forward declarations |
|
29 class CFbsBitmap; |
|
30 class CBitmapScaler; |
|
31 class CImageDecoder; |
|
32 class TAknsItemID; |
|
33 class CWmUnitTest; |
|
34 class MSvgError; |
|
35 |
|
36 // Class declaration |
|
37 /** |
|
38 * MConverterObserver |
|
39 * To notify when image is converted |
|
40 */ |
|
41 NONSHARABLE_CLASS( MConverterObserver ) |
|
42 { |
|
43 public: |
|
44 virtual void NotifyCompletion( TInt aError ) = 0; |
|
45 }; |
|
46 |
|
47 // Class declaration |
|
48 /** |
|
49 * CWmImageConverter |
|
50 * Image converter |
|
51 */ |
|
52 NONSHARABLE_CLASS ( CWmImageConverter ) : public CActive, |
|
53 public MAknIconFileProvider |
|
54 { |
|
55 /** states for this converter */ |
|
56 enum TState |
|
57 { |
|
58 EIdle = 0, |
|
59 EDecoding, |
|
60 EScalingBitmap, |
|
61 EScalingMask |
|
62 }; |
|
63 |
|
64 public: //contructors/destructors |
|
65 /** |
|
66 * Two-phased constructor. |
|
67 * @param aObserver observer |
|
68 */ |
|
69 static CWmImageConverter* NewL( MConverterObserver* aObserver ); |
|
70 |
|
71 /** Destructor */ |
|
72 ~CWmImageConverter(); |
|
73 |
|
74 public: // interface methods |
|
75 |
|
76 /** |
|
77 * Parses icon string and prepares logo image. |
|
78 * |
|
79 * @param aWidth wanted widht |
|
80 * @param aHeight wanted height |
|
81 * @param aIconStr str containing logo icon |
|
82 * Supported values: |
|
83 * - skin(<major id> <minor id>):mif(<path> <bitmapid> <maskid>) |
|
84 * - mif(<path> <bitmapid> <maskid>) |
|
85 * - uid(<application uid>) |
|
86 * - <file name>.<png/svg> |
|
87 */ |
|
88 void HandleIconStringL( TInt aWidth, TInt aHeight, const TDesC& aIconStr ); |
|
89 |
|
90 /** |
|
91 * Returns converted bitmap. Caller takes ownership |
|
92 * |
|
93 * @return CFbsBitmap |
|
94 */ |
|
95 CFbsBitmap* Bitmap(); |
|
96 |
|
97 /** |
|
98 * Returns converted mask. Caller takes ownership |
|
99 * |
|
100 * @return CFbsBitmap |
|
101 */ |
|
102 CFbsBitmap* Mask(); |
|
103 |
|
104 /** |
|
105 * sets the size for decoding |
|
106 * @param aSize the logo size |
|
107 */ |
|
108 void SetLogoSize( const TSize& aSize ); |
|
109 |
|
110 /** supported image conversion methods */ |
|
111 enum TConversionMethod |
|
112 { |
|
113 EUnrecognized, // we could not recognise the icon string |
|
114 EUidIcon, // App.UID-coded icon |
|
115 ESvgIcon, // Icon from SVG-file |
|
116 ESkinIcon, // Icon from SKIN id |
|
117 EMifIcon, // Icon from MIF file, known graphic index |
|
118 ESkinAndMifIcon, // Icon from SKIN and MIF combination |
|
119 EImageIcon, // Icon from image file (jpeg or png) |
|
120 }; |
|
121 |
|
122 /** |
|
123 * The type of currently converted image. |
|
124 * This method can be used to check if correct conversion was used. |
|
125 * @return conversion method used for current image |
|
126 */ |
|
127 TConversionMethod ConversionMethod(); |
|
128 |
|
129 protected: // implementation of CActive |
|
130 /** |
|
131 * Implements cancellation of an outstanding request. |
|
132 * |
|
133 * @see CActive::DoCancel |
|
134 */ |
|
135 void DoCancel(); |
|
136 |
|
137 /** |
|
138 * Handles an active object's request completion event. |
|
139 * |
|
140 * @see CActive::RunL |
|
141 */ |
|
142 void RunL(); |
|
143 |
|
144 /** |
|
145 * RunError |
|
146 * |
|
147 * @see CActive::RunError |
|
148 */ |
|
149 TInt RunError(TInt aError); |
|
150 |
|
151 private: |
|
152 CWmImageConverter(); |
|
153 void ConstructL( MConverterObserver* aObserver ); |
|
154 void CheckSvgErrorL( MSvgError* aError ); |
|
155 |
|
156 private: |
|
157 |
|
158 void ScaleBitmap( TInt aWidth, TInt aHeight ); |
|
159 void ScaleMask( TInt aWidth, TInt aHeight ); |
|
160 void CreateIconFromUidL( const TUid& aUid ); |
|
161 void CreateIconFromSvgL( const TDesC& aFileName ); |
|
162 void CreateIconFromOtherL( const TDesC& aFileName ); |
|
163 void CreateSkinOrMifIconL( |
|
164 const TAknsItemID& aItemId, TInt aBitmapId, |
|
165 TInt aMaskId, const TDesC& aFileName ); |
|
166 // resolvers |
|
167 TBool ResolveUid( const TDesC& aPath, TUid& aUid ); |
|
168 TBool ResolveSkinId( const TDesC& aPath, TAknsItemID& aItemId ); |
|
169 TBool ResolveMifId( const TDesC& aPath, TInt& aBitmapId, |
|
170 TInt& aMaskId, TDes& aFileName ); |
|
171 TBool ResolveSkinIdAndMifId( const TDesC& aPath, TAknsItemID& aItemId, |
|
172 TInt& aBitmapId, TInt& aMaskId, TDes& aFileName ); |
|
173 TBool EndsWith( const TDesC& aString, const TDesC& aPattern ); |
|
174 |
|
175 private: // from MAknIconFileProvider |
|
176 |
|
177 /** Returns an open file handle to the icon file. */ |
|
178 void RetrieveIconFileHandleL( RFile& aFile, const TIconFileType aType ); |
|
179 |
|
180 /** Stops using this MAknIconFileProvider instance */ |
|
181 void Finished(); |
|
182 |
|
183 private: |
|
184 /** |
|
185 * Converter observer (not owned) |
|
186 */ |
|
187 MConverterObserver* iObserver; |
|
188 |
|
189 /** |
|
190 * decoded image |
|
191 */ |
|
192 CFbsBitmap* iBitmap; |
|
193 |
|
194 /** |
|
195 * decoded image mask |
|
196 */ |
|
197 CFbsBitmap* iMask; |
|
198 |
|
199 /** |
|
200 * decoder from ICL API |
|
201 */ |
|
202 CImageDecoder* iImageDecoder; |
|
203 |
|
204 /** |
|
205 * bitmap scaler |
|
206 */ |
|
207 CBitmapScaler* iScaler; |
|
208 |
|
209 /** |
|
210 * internal state |
|
211 */ |
|
212 TState iState; |
|
213 |
|
214 /** |
|
215 * File name to convert |
|
216 */ |
|
217 TFileName iFilename; |
|
218 |
|
219 /** |
|
220 * size to convert |
|
221 */ |
|
222 TSize iSize; |
|
223 |
|
224 /** |
|
225 * is scaling needed |
|
226 */ |
|
227 TBool iScaleNeeded; |
|
228 |
|
229 /** |
|
230 * File handle |
|
231 */ |
|
232 RFs iFs; |
|
233 |
|
234 /** |
|
235 * Conversion method for current image |
|
236 */ |
|
237 TConversionMethod iConversionMethod; |
|
238 |
|
239 }; |
|
240 |
|
241 #endif // #ifndef WMIMAGECONVERTER_H |
|
242 |
|
243 // end of file |