|
1 /* |
|
2 * Copyright (c) 2009-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 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: Converter that creates icons from picture files.* |
|
15 */ |
|
16 |
|
17 |
|
18 #ifndef C_VCXNSIMAGECONVERTER_H |
|
19 #define C_VCXNSIMAGECONVERTER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 |
|
25 // FORWARD DECLARATIONS |
|
26 class CGulIcon; |
|
27 class CImageDecoder; |
|
28 class CFbsBitmap; |
|
29 class MVcxNsImageConverterObserver; |
|
30 |
|
31 // CONSTS |
|
32 |
|
33 const TInt KFileExtensionLength( 10 ); |
|
34 const TInt KSuffixPtrMinLength( 2 ); |
|
35 const TInt KSuffixPtrMaxLength( 9 ); |
|
36 |
|
37 |
|
38 /** |
|
39 * Converter that creates icons from picture files. |
|
40 * |
|
41 * @lib IptvUtil.lib |
|
42 * @since S60 v3.0 |
|
43 */ |
|
44 class CVcxNsImageConverter : public CActive |
|
45 { |
|
46 public: // Data types |
|
47 |
|
48 /** Image type enumeration */ |
|
49 enum TImageType |
|
50 { |
|
51 /** Image is of type .mif */ |
|
52 EMif, |
|
53 /** Image is of other type */ |
|
54 EOther |
|
55 }; |
|
56 |
|
57 public: // Constructors and destructor |
|
58 |
|
59 /** |
|
60 * Two-phased constructor. |
|
61 * |
|
62 * @param aObserver Reference to image converter observer. |
|
63 * @param aFsSession File Server session. |
|
64 */ |
|
65 IMPORT_C static CVcxNsImageConverter* NewL( |
|
66 MVcxNsImageConverterObserver& aObserver, RFs& aFsSession ); |
|
67 |
|
68 /** |
|
69 * Destructor. |
|
70 */ |
|
71 virtual ~CVcxNsImageConverter(); |
|
72 |
|
73 public: |
|
74 |
|
75 /** |
|
76 * Checks image type. |
|
77 * |
|
78 * @param aFileName File name of image which type to check. |
|
79 * @param aImageType On return, image type as TImageType enumeration. |
|
80 * @return KErrNone if successful. |
|
81 */ |
|
82 IMPORT_C TInt GetImageType( const TDesC& aFileName, |
|
83 TImageType& aImageType ); |
|
84 |
|
85 /** |
|
86 * Converts picture file (jpg/gif/png/etc.) synchronously. |
|
87 * |
|
88 * @param aFileName Name (and path) of the source image file. |
|
89 * @param aImageSize Size of target icon. |
|
90 * @param aCreateMask ETrue if icon should have mask, EFalse otherwise. |
|
91 * @return New icon if successful, NULL otherwise. |
|
92 */ |
|
93 IMPORT_C CGulIcon* ConvertL( const TDesC& aFileName, TSize aImageSize, |
|
94 TBool aCreateMask ); |
|
95 |
|
96 /** |
|
97 * Converts mif file (mif) synchronously. |
|
98 * |
|
99 * @param aFileName Name (and path) of the source image file. |
|
100 * @param aImageSize Size of target icon. |
|
101 * @param aBitmapId ID of bitmap in mif file. |
|
102 * @param aMaskId ID of mask in mif file. |
|
103 * @return New icon if successful, NULL otherwise. |
|
104 */ |
|
105 IMPORT_C CGulIcon* ConvertL( const TDesC& aFileName, TSize aImageSize, |
|
106 TInt aBitmapId, TInt aMaskId ); |
|
107 |
|
108 /** |
|
109 * Converts file (jpg/gif/png/etc.) asynchronously. |
|
110 * |
|
111 * @param aFileName Name (and path) of the source image file. |
|
112 * @param aImageSize Size of target icon. |
|
113 * @param aCreateMask ETrue if icon should have mask, EFalse otherwise. |
|
114 * @return KErrNone, or one of the system wide error codes if could not |
|
115 * start conversion. |
|
116 */ |
|
117 IMPORT_C TInt StartConvertL( const TDesC& aFileName, TSize aImageSize, |
|
118 TBool aCreateMask ); |
|
119 |
|
120 /** |
|
121 * Converts mif file (mif) asynchronously. |
|
122 * |
|
123 * @param aFileName Name (and path) of the source image file. |
|
124 * @param aImageSize Size of target icon. |
|
125 * @param aBitmapId ID of bitmap in mif file. |
|
126 * @param aMaskId ID of mask in mif file. |
|
127 * @return KErrNone, or one of the system wide error codes if could not |
|
128 * start conversion. |
|
129 */ |
|
130 IMPORT_C TInt StartConvertL( const TDesC& aFileName, TSize aImageSize, |
|
131 TInt aBitmapId, TInt aMaskId ); |
|
132 |
|
133 private: // From CActive |
|
134 |
|
135 /** |
|
136 * Handles an active object’s request completion event. Image conversion |
|
137 * complete. |
|
138 */ |
|
139 void RunL(); |
|
140 |
|
141 /** |
|
142 * Implements cancellation of an outstanding request, e.g. image |
|
143 * conversion. |
|
144 */ |
|
145 void DoCancel(); |
|
146 |
|
147 /** |
|
148 * Handles leaves in RunL. Frees memory and informs client. |
|
149 * |
|
150 * @param aError Error code in RunL leave. |
|
151 */ |
|
152 TInt RunError( TInt aError ); |
|
153 |
|
154 private: |
|
155 |
|
156 /** |
|
157 * Constructor |
|
158 * |
|
159 * @param aObserver Reference to image converter observer. |
|
160 * @param aFsSession File Server session. |
|
161 */ |
|
162 CVcxNsImageConverter( MVcxNsImageConverterObserver& aObserver, |
|
163 RFs& aFsSession ); |
|
164 |
|
165 /** |
|
166 * EPOC constructor. |
|
167 */ |
|
168 void ConstructL(); |
|
169 |
|
170 /** |
|
171 * Gets extension from file name. |
|
172 * |
|
173 * @param aPath Path and file name from which to extract the extension from. |
|
174 * @param aExtension On return, extension of the file. |
|
175 * @return ETrue if successful, EFalse otherwise. |
|
176 */ |
|
177 TBool GetExtension( const TDesC& aPath, TDes& aExtension ); |
|
178 |
|
179 /** |
|
180 * Creates icon after asynchronous conversion and informs observer. |
|
181 */ |
|
182 void CreateAndSetIconL(); |
|
183 |
|
184 /** |
|
185 * Informs observer about a conversion error in asynchronous conversion. |
|
186 */ |
|
187 void ReportErrorL(); |
|
188 |
|
189 private: // Data |
|
190 |
|
191 // Image decoder. |
|
192 CImageDecoder* iDecoder; |
|
193 |
|
194 // Bitmap for converted images. |
|
195 CFbsBitmap* iBitmap; |
|
196 // Bitmap mask for converted images. |
|
197 CFbsBitmap* iMask; |
|
198 |
|
199 // File server session. |
|
200 RFs& iFsSession; |
|
201 // Used to flag synchronous decoding. |
|
202 TBool iSynchronous; |
|
203 |
|
204 // Used to flag that conversion is done to mif file. |
|
205 TBool iConvertingMif; |
|
206 // Stores mif file name in asynchronous case. |
|
207 HBufC* iMifFileName; |
|
208 // Stores mif image size in asynchronous case. |
|
209 TSize iMifImageSize; |
|
210 // Stores mif bitmap Id in asynchronous case. |
|
211 TInt iMifBitmapId; |
|
212 // Stores mif mask Id in asynchronous case. |
|
213 TInt iMifMaskId; |
|
214 |
|
215 // Observer. |
|
216 MVcxNsImageConverterObserver& iObserver; |
|
217 |
|
218 // Flag for knowing if image is fully scalable or not |
|
219 TBool iImageScalable; |
|
220 }; |
|
221 |
|
222 #endif // C_VCXNSIMAGECONVERTER_H |