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