|
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 * Picture Message model and converter. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef _GMSMODEL_ |
|
22 #define _GMSMODEL_ |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include<e32base.h> |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 const TInt KGmsMaxPictureWidthPixels = 72; //this is also in appl. LAF |
|
31 const TInt KGmsMaxPictureHeightPixels = 28; //this is also in appl. LAF |
|
32 const TInt KGmsMinPictureWidthPixels = 1; |
|
33 const TInt KGmsMinPictureHeightPixels = 1; |
|
34 |
|
35 // MACROS |
|
36 // DATA TYPES |
|
37 |
|
38 /** |
|
39 * After an import or after setting the text, the model will be in one of the |
|
40 * two modes. |
|
41 */ |
|
42 enum TGmsMode |
|
43 { |
|
44 EGmsModeUnicode, |
|
45 EGmsModeLatin |
|
46 }; |
|
47 |
|
48 enum TGmsModelPanic |
|
49 { |
|
50 EGmsMPanicNoPicData1, |
|
51 EGmsMPanicNoPicData2, |
|
52 EGmsMPanicNoPictureToExport, |
|
53 EGmsMPanicStreamIsEmpty, |
|
54 EGmsMPanicNotSupported, |
|
55 EGmsNullParameter1, |
|
56 EGmsNoPic1, |
|
57 EGmsNull1, |
|
58 EGmsProblem1, |
|
59 EGmsProblem2 |
|
60 }; |
|
61 |
|
62 // FORWARD DECLARATIONS |
|
63 |
|
64 class RReadStream; |
|
65 class RWriteStream; |
|
66 class CRichText; |
|
67 class RFs; |
|
68 |
|
69 // CLASS DECLARATION |
|
70 |
|
71 /** |
|
72 * Class for managing the data of a Picture Message. |
|
73 * It supports message text of type Unicode and ISO-8859-1. |
|
74 * See Smart Messaging Specification 3.0.0 for info on picture messaging. |
|
75 * |
|
76 * Note that the failure (leaving) of the import operation might |
|
77 * put the model in an invalid state. The model should be reset after a |
|
78 * failed import. |
|
79 */ |
|
80 class CGmsModel : public CBase |
|
81 { |
|
82 public: //construction and destruction |
|
83 /** |
|
84 * Two-phased constructor |
|
85 * @param aFs Reference to an open file session. |
|
86 * @param aLeaveCodeForCorrupt The leave code that is to be used for |
|
87 * signalling about corrupted data when importing. It is kept in |
|
88 * iLeaveCorrupt. |
|
89 * @return The newly created object. |
|
90 */ |
|
91 IMPORT_C static CGmsModel* NewL(RFs& aFs, TInt aLeaveCodeForCorrupt); |
|
92 |
|
93 /// Destructor |
|
94 IMPORT_C ~CGmsModel(); |
|
95 |
|
96 public: |
|
97 |
|
98 /** |
|
99 * Reads the GMS data from a descriptor, parses it and stores the |
|
100 * parsed data in members. The text and bitmap is extracted at this |
|
101 * stage. The bitmap is validated. |
|
102 * @param aInput The input. |
|
103 * @exception If data is corrupt or picture invalid, leaves with |
|
104 * iLeaveCorrupt. |
|
105 */ |
|
106 IMPORT_C void ImportGMSL(const TDesC8& aInput); |
|
107 |
|
108 /** |
|
109 * Imports the GMS data from a rich text object, and parses the data. |
|
110 * This is used primarily with rich text obtained from a CMsvStore. |
|
111 * Extracts text and bitmap. |
|
112 * Leaving happens if the extraction fails. |
|
113 * @param aRichText The source of extraction. |
|
114 * @exception If data is corrupt, leaves with iLeaveCorrupt. |
|
115 */ |
|
116 IMPORT_C void ImportGMSL(const CRichText& aRichText); |
|
117 |
|
118 /** |
|
119 * Returns the GMS message as a HBufC8 which is on the cleanup stack. |
|
120 * |
|
121 * The text part is exported as UCS-2 format if the model is in |
|
122 * Unicode mode. If the model is in Latin mode, the text is exported |
|
123 * Latin text. (see the S.M. specification) You can use the function |
|
124 * IsTextLatin() to find out the current text mode. (the model can |
|
125 * only be in Latin or Unicode mode) |
|
126 * |
|
127 * @return The GMS message in a HBufC8. |
|
128 * @exception Panics if there is no picture data. |
|
129 */ |
|
130 IMPORT_C HBufC8* ExportGMS8LC(); |
|
131 |
|
132 /** |
|
133 * Returns the GMS message as a HBufC16 which is on the cleanup stack. |
|
134 * Each data byte occupies a 16 bit slot. |
|
135 * |
|
136 * The text part is exported as UCS-2 format if the model is in |
|
137 * Unicode mode. If the model is in Latin mode, the text is exported |
|
138 * Latin text. (see the S.M. specification) You can use the function |
|
139 * IsTextLatin() to find out the current text mode. (the model can |
|
140 * only be in Latin or Unicode mode) |
|
141 * |
|
142 * @return The GMS message in a HBufC16. |
|
143 * @exception Panics if there is no picture data. |
|
144 */ |
|
145 IMPORT_C HBufC16* ExportGMS16LC(); |
|
146 |
|
147 /** |
|
148 * Gets text part as a HBufC, which is placed on the cleanup stack. |
|
149 * @return Text part of message as HBufC in cleanup stack. |
|
150 */ |
|
151 IMPORT_C HBufC* TextAsHBufC16LC() const; |
|
152 |
|
153 /** |
|
154 * Sets the text for this model. It is able to handle Unicode also. |
|
155 * Afterwards you can use the method IsTextLatin() for finding out if |
|
156 * the model is in Unicode mode or Latin mode. |
|
157 * If you set the text again, the earlier text is replaced. |
|
158 * There is no restriction on the length of the text. |
|
159 * @param aSource The source text. |
|
160 */ |
|
161 IMPORT_C void SetTextL(const TDesC& aSource); |
|
162 |
|
163 /** |
|
164 * Sets the message text with latin type of text. |
|
165 * Note that this function does not check the character set. |
|
166 * It sets the model to Latin mode. The mode can be queried |
|
167 * using IsTextLatin(). (the modes are Latin and Unicode) |
|
168 * If you set the text again, the earlier text is replaced. |
|
169 * There is no restriction on the length of the text. |
|
170 * @param aSource The source text. |
|
171 */ |
|
172 IMPORT_C void SetTextLatinL(const TDesC& aSource); |
|
173 |
|
174 /** |
|
175 * Sets the message text with Unicode type of text. |
|
176 * There is no restriction on the length of the text. |
|
177 * Note that this function does not check the character set. |
|
178 * It sets the model to Unicode mode. The mode can be queried |
|
179 * using IsTextLatin(). (the modes are Latin and Unicode) |
|
180 * If you set the text again, the earlier text is replaced. |
|
181 * UCS-2 encoding is used, so each char occupies two bytes. |
|
182 * @param aSource The source text. |
|
183 */ |
|
184 IMPORT_C void SetTextUnicodeL(const TDesC& aSource); |
|
185 |
|
186 /** |
|
187 * Exports only the OTA Bitmap. |
|
188 * @param aOutStream Reference to an output stream which is open. |
|
189 * @exception Panics with EGmsNoPictureToExport if there is no picture |
|
190 * data to export. |
|
191 */ |
|
192 IMPORT_C void ExportOTABitmapL(RWriteStream& aOutStream); |
|
193 |
|
194 /** |
|
195 * Imports an OTA Bitmap. |
|
196 * Leaves with iLeaveCorrupt if the data is invalid. |
|
197 * If you import again, the earlier data is replaced. |
|
198 * |
|
199 * @param aReadStream Reference to the input stream which is open. |
|
200 * @exception Panics if the stream buffer is empty. |
|
201 */ |
|
202 IMPORT_C void ImportOTABitmapL(RReadStream& aReadStream); |
|
203 |
|
204 /** |
|
205 * Size of complete message excluding text and pic. |
|
206 * @return Number of bytes. |
|
207 */ |
|
208 IMPORT_C TInt SizeOfCompleteMsgExcludingTextAndPic() const; |
|
209 |
|
210 /** |
|
211 * Does the converter have text data. |
|
212 * @return ETrue if there is text data. |
|
213 */ |
|
214 IMPORT_C TBool HasText() const; |
|
215 |
|
216 /** |
|
217 * Is there picture data? Note that the validity of the picture data |
|
218 * is not checked. |
|
219 * @return ETrue if there is picture data. |
|
220 */ |
|
221 IMPORT_C TBool HasPicture() const; |
|
222 |
|
223 /** |
|
224 * Tells if the text data is of type Latin or Unicode. |
|
225 * @return ETrue if the type of text is Latin, and EFalse if Unicode. |
|
226 */ |
|
227 IMPORT_C TBool IsTextLatin() const; |
|
228 |
|
229 /** |
|
230 * Returns the total message size but not taking into account the text |
|
231 * size. |
|
232 * @return Message size in bytes. |
|
233 */ |
|
234 IMPORT_C TInt TotalSizeExcludingText() const; |
|
235 |
|
236 /** |
|
237 * The total size of the message data in bytes. |
|
238 * @return Message size in bytes. |
|
239 */ |
|
240 IMPORT_C TInt TotalSize() const; |
|
241 |
|
242 /** |
|
243 * Length of the text. |
|
244 * It is not the same thing as size of text. You can use IsTextLatin() |
|
245 * to find out if it is Unicode or Latin. |
|
246 */ |
|
247 IMPORT_C TInt Textlength() const; |
|
248 |
|
249 /** |
|
250 * Size of picture in bytes. |
|
251 * @return Size of picture in bytes. |
|
252 */ |
|
253 IMPORT_C TInt PictureSize() const; |
|
254 |
|
255 /// Resets this model. |
|
256 IMPORT_C void Reset(); |
|
257 |
|
258 /** |
|
259 * Deprecated. Do not use this method. |
|
260 */ |
|
261 IMPORT_C TInt _TestingL(TInt aCode1, TInt& aCode2, const TDesC8& aDes1, const TDesC16& aDes2); |
|
262 |
|
263 /// Deprecated. Do not use this method. |
|
264 IMPORT_C HBufC* ExtractTextFromMsgLC(const TDesC& aMsg, TInt aAmount); |
|
265 |
|
266 /// Deprecated. Do not use this method. |
|
267 IMPORT_C TBool IsPictureValidL(); |
|
268 |
|
269 public: //not exported |
|
270 |
|
271 /** |
|
272 * Imports the OTA Bitmat and validates it. Does not leave if bitmap |
|
273 * is invalid. The validation result is returned by the method. |
|
274 * @param aFileName Source file name. |
|
275 * @return Validation result. |
|
276 */ |
|
277 TBool ImportOtaBitmapL(const TDesC& aFileName); |
|
278 |
|
279 private: //message data extraction functions |
|
280 |
|
281 /** |
|
282 * Checks if version of Picture Message is valid. Leaves with |
|
283 * iLeaveCorrupt if invalid. |
|
284 * This function is the first extraction function called. |
|
285 * @param aInput The source of extraction. |
|
286 * @param aIndex Reference to position of extraction. (not const) |
|
287 * @exception If data is corrupt, leaves with iLeaveCorrupt. |
|
288 */ |
|
289 void CheckVersionL(const TDesC8& aInput, TInt& aIndex); |
|
290 |
|
291 /** |
|
292 * Extracts a sub item which is either a picture, text or something |
|
293 * unknown: <item> |
|
294 * |
|
295 * @param aInput The source of extraction. |
|
296 * @param aIndex Reference to position of extraction. (not const) |
|
297 * @exception If data is corrupt, leaves with iLeaveCorrupt. |
|
298 */ |
|
299 void ExtractGMSSubItemL( |
|
300 const TDesC8& aInput, |
|
301 TInt& aIndex); |
|
302 |
|
303 /** |
|
304 * Extracts a sub item which is either a picture, text or something |
|
305 * unknown: <item> |
|
306 * |
|
307 * @param aInput The source of extraction. |
|
308 * @param aIndex Reference to position of extraction. (not const) |
|
309 * @param aSkipBitmap Whether to skip the OTA Bitmap. |
|
310 * @exception If data is corrupt, leaves with iLeaveCorrupt. |
|
311 */ |
|
312 void ExtractGMSSubItemL( |
|
313 const TDesC8& aInput, |
|
314 TInt& aIndex, |
|
315 TBool aSkipBitmap); |
|
316 |
|
317 /** |
|
318 * Extracts a Latin text entity: <item-length><ISO-8859-1-char>* |
|
319 * |
|
320 * @param aInput The source of extraction. |
|
321 * @param aIndex Reference to position of extraction. (not const) |
|
322 * @exception If data is corrupt, leaves with iLeaveCorrupt. |
|
323 */ |
|
324 void ExtractLatin1L(const TDesC8& aInput, TInt& aIndex); |
|
325 |
|
326 /** |
|
327 * Extracts a Unicode text entity: <item-length><UNICODE-char>* |
|
328 * |
|
329 * @param aInput The source of extraction. |
|
330 * @param aIndex Reference to position of extraction. (not const) |
|
331 * @exception If data is corrupt, leaves with iLeaveCorrupt. |
|
332 */ |
|
333 void ExtractUnicodeL(const TDesC8& aInput, TInt& aIndex); |
|
334 |
|
335 /** |
|
336 * Extracts OTA Bitmap data: <OTA-bitmap> |
|
337 * It also checks the OTA Bitmap syntax and leaves if it is bad or too |
|
338 * big. |
|
339 * @param aInput The source of extraction. |
|
340 * @param aIndex Reference to position of extraction. (not const) |
|
341 * @exception If there is less data than what the length field |
|
342 * specifies, it leaves with iLeaveCorrupt. |
|
343 * @exception Leaves with iLeaveCorrupt in case of syntax error. |
|
344 */ |
|
345 void ExtractOTABitmapL(const TDesC8& aInput, TInt& aIndex); |
|
346 |
|
347 /** |
|
348 * Skips an entity which is of unknown type. |
|
349 * @param aInput The source of extraction. |
|
350 * @param aIndex Reference to position of extraction. (not const) |
|
351 * @exception If there is less data than what the length field |
|
352 * specifies, it leaves with iLeaveCorrupt. |
|
353 */ |
|
354 void ExtractUnknownL(const TDesC8& aInput, TInt& aIndex); |
|
355 |
|
356 /** |
|
357 * Extracts the entity length header: <item-length> |
|
358 * @param aInput The source of extraction. |
|
359 * @param aIndex Reference to position of extraction. (not const) |
|
360 * @exception If data is corrupt, leaves with iLeaveCorrupt. |
|
361 */ |
|
362 TInt ExtractLengthL(const TDesC8& aInput, TInt& aIndex); |
|
363 |
|
364 private: // other private functions |
|
365 |
|
366 /** |
|
367 * Checks if the text contains any Unicode characters. |
|
368 * Unicode line breaks are ignored. They are converted to LF if |
|
369 * exporting in Latin-1 mode. |
|
370 * @param aText The text that is to be scanned. |
|
371 * @return ETrue if text contains Unicode characters. |
|
372 */ |
|
373 TBool ContainsUnicodeL(const TDesC& aText) const; |
|
374 |
|
375 /** |
|
376 * Appends <version> |
|
377 * @param aGms The descriptor to which the data is appended. |
|
378 */ |
|
379 void AppendVersionL(TDes8& aGms); |
|
380 |
|
381 /** |
|
382 * Appends "00" <Item-length> <ISO-8859-1-char>* |
|
383 * | "01" <Item-length> <UNICODE-char>* |
|
384 * @param aGms The descriptor to which the data is appended. |
|
385 */ |
|
386 void AppendTextSubItemL(TDes8& aGms); |
|
387 |
|
388 /** |
|
389 * Appends "02" <Item-length> <OTA-bitmap> |
|
390 * @param aGms The descriptor to which the data is appended. |
|
391 */ |
|
392 void AppendPictureSubItemL(TDes8& aGms); |
|
393 |
|
394 /** |
|
395 * Encodes Unicode text into UCS2 and appends it to a descriptor. |
|
396 * @param aGms The descriptor to which the data is appended. |
|
397 * @param aText The Unicode text. |
|
398 */ |
|
399 void AppendUCS2TextL(TDes8& aGms, const TDesC& aText); |
|
400 |
|
401 /** |
|
402 * Apppends the text to aGms, but replaces Unicode line breaks with |
|
403 * CR. |
|
404 * @param aGms The descriptor to which the data is appended. |
|
405 * @param aText The Latin1 text (which may contain Unicode line |
|
406 * breaks). |
|
407 */ |
|
408 void AppendLatin1TextL(TDes8& aGms, const TDesC& aText); |
|
409 |
|
410 /** |
|
411 * Checks the OTA syntax and size. It leaves with iLeaveCorrupt in |
|
412 * case the bitmap did not pass the tests. |
|
413 * @param aOta The data that is to be checked. |
|
414 * @return The checked and fixed bitmap. |
|
415 */ |
|
416 HBufC8* CheckedAndFixedOtaBitmapL(const TDesC8& aOta) const; |
|
417 |
|
418 /** |
|
419 * Checks the OTA syntax and size. Does not leave if the bitmap is |
|
420 * bad. The result is obtained using a TBool reference parameter. |
|
421 * @param aOta The data that is to be checked. |
|
422 * @param aSuccess Reference to a TBool that gets the result of the |
|
423 * validation. |
|
424 * @return The checked and fixed bitmap, or NULL if the validation |
|
425 * failed. |
|
426 */ |
|
427 HBufC8* CheckedAndFixedOtaBitmapL(const TDesC8& aOta, TBool& aSuccess) const; |
|
428 |
|
429 /** |
|
430 * Panic wrapper. |
|
431 * @param aCode The panic code. |
|
432 */ |
|
433 static void Panic(TGmsModelPanic aCode); |
|
434 |
|
435 private: // construction related |
|
436 |
|
437 /// constructor |
|
438 CGmsModel(RFs& aFs, TInt aLeaveCodeForCorrupt); |
|
439 |
|
440 /// Second phase constructor. |
|
441 void ConstructL(); |
|
442 |
|
443 private: // prohibited |
|
444 |
|
445 /// The default constructor is prohibited |
|
446 CGmsModel(); |
|
447 |
|
448 /// Copy contructor prohibited. |
|
449 CGmsModel(const CGmsModel& aSource); |
|
450 |
|
451 /// Assignment operator prohibited. |
|
452 const CGmsModel& operator=(const CGmsModel& aSource); |
|
453 |
|
454 private: //data |
|
455 |
|
456 /// The message text in Unicode (native Symbian OS) format. |
|
457 HBufC16* iText; |
|
458 |
|
459 /** |
|
460 * The OTA Bitmap data. |
|
461 */ |
|
462 HBufC8* iOTABitmap; |
|
463 |
|
464 /** |
|
465 * Flag which tells if the model is in Latin or Unicode mode |
|
466 * The mode is changed by either using the text setting functions, or |
|
467 * by importing a complete message. |
|
468 */ |
|
469 TGmsMode iMode; |
|
470 |
|
471 mutable RFs& iFs; |
|
472 |
|
473 /** |
|
474 * This leave code is used if the importing fails because of corrupt |
|
475 * data. It is set in the constructor. |
|
476 */ |
|
477 const TInt iLeaveCorrupt; |
|
478 }; |
|
479 |
|
480 |
|
481 |
|
482 #endif // _GMSMODEL_ |
|
483 |
|
484 // end of file |