|
1 /* |
|
2 * Copyright (c) 2002 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 * Utility class for HTML converter |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CMSGMAILVIEWERHTMLCONV_H |
|
21 #define CMSGMAILVIEWERHTMLCONV_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <txtrich.h> |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 class CMsgBodyControl; |
|
29 class CCnvCharacterSetConverter; |
|
30 |
|
31 // CLASS DECLARATION |
|
32 |
|
33 /** |
|
34 * Utility class for HTML converter. |
|
35 * A pair of two strings. |
|
36 */ |
|
37 class CStringPair : public CBase |
|
38 { |
|
39 public: |
|
40 /** |
|
41 * A constructor. |
|
42 * @param aName a HTML macro, e.g. lt |
|
43 * @param aValue a character that is represented by a macro e.g. < |
|
44 * @return created object. |
|
45 */ |
|
46 static CStringPair* NewLC(const TDesC& aName, const TDesC& aValue); |
|
47 |
|
48 /** |
|
49 * Destructor |
|
50 */ |
|
51 ~CStringPair(); |
|
52 |
|
53 /** |
|
54 * @return a name of the macro |
|
55 */ |
|
56 HBufC* GetName() const; |
|
57 |
|
58 /** |
|
59 * @return a value of the macro |
|
60 */ |
|
61 HBufC* GetValue() const; |
|
62 |
|
63 /** |
|
64 * Compares if two pairs are same. Names are compared. |
|
65 * @return as in TBufC::Compare. |
|
66 */ |
|
67 static TInt Compare(const CStringPair& aPair1, |
|
68 const CStringPair& aPair2); |
|
69 |
|
70 private: |
|
71 /** |
|
72 * A constructor |
|
73 */ |
|
74 CStringPair(); |
|
75 |
|
76 /** |
|
77 * A 2nd phase constructor |
|
78 * @param aName a HTML macro, e.g. lt |
|
79 * @param aValue a character that is represented by a macro e.g. < |
|
80 */ |
|
81 void ConstructL(const TDesC& aName, const TDesC& aValue); |
|
82 |
|
83 private: |
|
84 /// Name of the macro. Owns. |
|
85 HBufC* iName; |
|
86 |
|
87 /// Value of the macro. Owns. |
|
88 HBufC* iValue; |
|
89 }; |
|
90 |
|
91 |
|
92 /** |
|
93 * HTML converter. |
|
94 * This class is used in Mail viewer application to convert |
|
95 * messages with HTML-formatting to plain text. |
|
96 */ |
|
97 class CMsgMailViewerHtmlConv : public CActive |
|
98 { |
|
99 public: // Constructors and destructor |
|
100 |
|
101 /** |
|
102 * Two-phased constructor. |
|
103 * @param aHandle a handle to HTML-file. |
|
104 * @param aCharset Characterset ID |
|
105 * @param aForced forse converter to use passed Character set id |
|
106 * otherwise converter tries to use character set defined in HTML content |
|
107 * If zero character set id is tried to find out from the HTML content. |
|
108 */ |
|
109 static CMsgMailViewerHtmlConv* NewLC( |
|
110 RFile& aHandle, TUint aCharset, TBool aForced); |
|
111 static CMsgMailViewerHtmlConv* NewL( |
|
112 RFile& aHandle, TUint aCharset, TBool aForced); |
|
113 |
|
114 /** |
|
115 * Destructor. |
|
116 */ |
|
117 virtual ~CMsgMailViewerHtmlConv(); |
|
118 |
|
119 public: // New functions |
|
120 |
|
121 /** |
|
122 * Removes HTML-tags and replaces macros with real characters. |
|
123 * @return KErrNone if part of the conversion has been successful. |
|
124 * Returns KErrEof when conversion is done. |
|
125 */ |
|
126 TInt Convert(); |
|
127 |
|
128 /** |
|
129 * Removes HTML-tags and replaces macros with real characters. |
|
130 * Does the conversion asynchronously in low priority. |
|
131 * |
|
132 * @param aStatus Generic request status. |
|
133 * KErrNone when the convertion is succesful. |
|
134 * Other error codes are used to indicate an error during conversion. |
|
135 */ |
|
136 void Convert( TRequestStatus* aStatus ); |
|
137 |
|
138 |
|
139 /** |
|
140 * Returns a stripped text. |
|
141 * @return stripped text object. |
|
142 */ |
|
143 HBufC* GetText() const; |
|
144 |
|
145 /** |
|
146 * Return file id array of inline images. |
|
147 * @return Reference to array. |
|
148 * Ownership is transferred to caller |
|
149 **/ |
|
150 RPointerArray<HBufC>* FileIdArray(); |
|
151 /** |
|
152 * Checks if the charset name and identifiers were autoparsed |
|
153 */ |
|
154 TBool AutoParsedCharSetNameAndIdentifier() const; |
|
155 |
|
156 /** |
|
157 * Returns the auto parsed charset identifier |
|
158 */ |
|
159 TUint AutoParsedCharSetIdentifier() const; |
|
160 |
|
161 private: |
|
162 /** |
|
163 * C++ default constructor. |
|
164 */ |
|
165 CMsgMailViewerHtmlConv(); |
|
166 |
|
167 /** |
|
168 * By default Symbian OS constructor is private. |
|
169 * @param aHandle file handle to HTML content |
|
170 * @param aCharSet characterset id |
|
171 */ |
|
172 void ConstructL(RFile& aHandle, TUint aCharSet); |
|
173 |
|
174 /** |
|
175 * Deletes aLen characters beginning from aPos in iStrippedText. |
|
176 * @param aLen how many characters will be deleted. |
|
177 * @return New length of the message. |
|
178 */ |
|
179 TInt Delete(const TInt aLen); |
|
180 |
|
181 /** |
|
182 * Inserts characters beginning from aPos in iStrippedText. |
|
183 * @param aChars characters to be inserted. |
|
184 * @return New length of the message. |
|
185 */ |
|
186 TInt InsertTextL(const TDesC& aChars); |
|
187 |
|
188 /** |
|
189 * Replaces macro with real text |
|
190 * @return New length of the message. |
|
191 */ |
|
192 TInt ReplaceMacroL(); |
|
193 |
|
194 /** |
|
195 * Fills a map of macros with name, value pairs. |
|
196 */ |
|
197 void InitMacroArrayL(); |
|
198 |
|
199 /** |
|
200 * Converts unnumbered list to a text. |
|
201 * @param Indentation of the items. |
|
202 * @return New length of the message. |
|
203 */ |
|
204 TInt HandleUListL(const TInt aIndent); |
|
205 |
|
206 /** |
|
207 * Converts ordinal list to a text. |
|
208 * @param Indentation of the items. |
|
209 * @return New length of the message. |
|
210 */ |
|
211 TInt HandleOListL(const TInt aIndent); |
|
212 |
|
213 /** |
|
214 * Converts definition list to a text. |
|
215 * @param Indentation of the items. |
|
216 * @return New length of the message. |
|
217 */ |
|
218 TInt HandleDListL(const TInt aIndent); |
|
219 |
|
220 /** |
|
221 * Converts lists into a text. |
|
222 * @param aIndent Indentation of the items |
|
223 * @param aNumbered, ETrue if ordinal list, EFalse otherwise |
|
224 * @return New length of the message |
|
225 */ |
|
226 TInt HandleListL(const TInt aIndent, const TBool aNumbered); |
|
227 |
|
228 /** |
|
229 * Converts HTML tags to plain text. |
|
230 * @param indentation of the lists. |
|
231 * @return New length of the message. |
|
232 */ |
|
233 TInt HandleTagL(const TInt aIndent); |
|
234 |
|
235 /** |
|
236 * Removes characters from iPos to >-character. Shows an error |
|
237 * and interrupts conversion if it is not found. |
|
238 * @return New length of the message. |
|
239 */ |
|
240 TInt RemoveTagL(); |
|
241 |
|
242 /** |
|
243 * Adds an error message to end of the message |
|
244 * and shows an information note. |
|
245 */ |
|
246 void ShowErrorL(); |
|
247 |
|
248 /** |
|
249 * Adds a linefeed into a text. |
|
250 */ |
|
251 void InsertLinefeedL(); |
|
252 |
|
253 /** |
|
254 * Performs a character conversion for area started with |
|
255 * BeginConvertL(); |
|
256 */ |
|
257 void DoConvertL(); |
|
258 |
|
259 /** |
|
260 * Main loop |
|
261 */ |
|
262 void DoConversionL(); |
|
263 |
|
264 /** |
|
265 * Continue asynchronous conversion in next scheduler loop |
|
266 */ |
|
267 void ContinueAsyncConvert(); |
|
268 |
|
269 |
|
270 protected: // From CActive |
|
271 void RunL(); |
|
272 void DoCancel(); |
|
273 |
|
274 |
|
275 private: // Data |
|
276 /** |
|
277 * Contains a text read from file which is stripped (Owned). |
|
278 */ |
|
279 HBufC *iOrigText; |
|
280 |
|
281 /** |
|
282 * A position in text. |
|
283 */ |
|
284 TInt iPos; |
|
285 |
|
286 /** |
|
287 * An array which contains all HTML macro definitions which |
|
288 * are read from a resource file. |
|
289 */ |
|
290 RPointerArray<CStringPair> *iMacros; |
|
291 |
|
292 /** |
|
293 * An array which contains places for line feeds. These will |
|
294 * be inserted to a RTF object. |
|
295 */ |
|
296 RArray<TInt> *iNewLines; |
|
297 |
|
298 /** |
|
299 * Status of the conversion |
|
300 */ |
|
301 TInt iReturnValue; |
|
302 |
|
303 /** |
|
304 * Position where an error occured |
|
305 */ |
|
306 TInt iErrorPos; |
|
307 |
|
308 /** |
|
309 * Own: Character converter instance. |
|
310 */ |
|
311 CCnvCharacterSetConverter* iCharConv; |
|
312 |
|
313 /** |
|
314 * State conversion is in. |
|
315 */ |
|
316 TInt iConversionState; |
|
317 |
|
318 /** |
|
319 * An array containing inline image names |
|
320 */ |
|
321 RPointerArray<HBufC>* iFileIdArray; |
|
322 |
|
323 /** |
|
324 * Characterset name |
|
325 */ |
|
326 HBufC* iCharSetName; |
|
327 |
|
328 /** |
|
329 * Characterset id |
|
330 */ |
|
331 TUint iCharacterSetId; |
|
332 |
|
333 /** |
|
334 * Status flags |
|
335 */ |
|
336 TUint iStatusFlags; |
|
337 |
|
338 /** |
|
339 * Asynchronous convert request status |
|
340 */ |
|
341 TRequestStatus* iReqStatus; |
|
342 |
|
343 }; |
|
344 |
|
345 #include "MsgMailViewerHtmlConv.inl" // inline functions |
|
346 |
|
347 #endif // CMSGMAILVIEWERHTMLCONV_H |
|
348 |
|
349 // End of File |