|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Message header HTML |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <s32strm.h> |
|
19 #include <f32file.h> |
|
20 #include <s32file.h> |
|
21 #include <e32cmn.h> |
|
22 #include <utf.h> |
|
23 #include <StringLoader.h> |
|
24 |
|
25 #include <FreestyleEmailUi.rsg> |
|
26 |
|
27 #include "FreestyleMessageHeaderHTML.h" |
|
28 #include "FreestyleEmailUiUtilities.h" |
|
29 #include "ncsconstants.h" |
|
30 |
|
31 |
|
32 |
|
33 _LIT8( KShowDetailIconFileName, "plus.gif"); |
|
34 _LIT8( KAttachementIconGeneral, "attachment.gif"); |
|
35 |
|
36 _LIT8( KHeaderTableName, "header_table"); |
|
37 _LIT8( KToTableName, "to_table"); |
|
38 _LIT8( KCcTableName, "cc_table"); |
|
39 _LIT8( KBccTableName, "bcc_table"); |
|
40 _LIT8( KAttachmentTableName, "attachment_table"); |
|
41 _LIT8( KFromTableName,"from_table"); |
|
42 |
|
43 _LIT8( KFromFieldName, "from_field"); |
|
44 _LIT8( KToFieldName, "to_field"); |
|
45 _LIT8( KCcFieldName, "cc_field"); |
|
46 _LIT8( KBccFieldName, "bcc_field"); |
|
47 _LIT8( KSentFieldName, "sent_field"); |
|
48 _LIT8( KSubjectFieldName, "subject_field"); |
|
49 _LIT8( KAttachmentFieldName, "attachment_field"); |
|
50 |
|
51 _LIT8( KToImageName, "to_img"); |
|
52 _LIT8( KCcImageName, "cc_img"); |
|
53 _LIT8( KBccImageName, "bcc_img"); |
|
54 _LIT8( KAttachmentImageName, "attachment_img"); |
|
55 _LIT8( KDetailImageName, "detail_img"); |
|
56 |
|
57 _LIT8( KAttachmentSizeUnit, "kb"); |
|
58 _LIT8( KSpace8, " "); |
|
59 |
|
60 _LIT8( KMetaHeader, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" ); |
|
61 const TInt KMaxEventLength = 256; |
|
62 |
|
63 EXPORT_C CFreestyleMessageHeaderHTML* CFreestyleMessageHeaderHTML::NewL( CFSMailMessage& aMailMessage ) |
|
64 { |
|
65 CFreestyleMessageHeaderHTML* self = new (ELeave) CFreestyleMessageHeaderHTML( aMailMessage ); |
|
66 self->ConstructL(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( CFSMailMessage& aMailMessage, RWriteStream& aWriteStream ) |
|
71 { |
|
72 CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage ); |
|
73 CleanupStack::PushL( headerHtml ); |
|
74 headerHtml->ExportL( aWriteStream ); |
|
75 CleanupStack::PopAndDestroy( headerHtml ); |
|
76 } |
|
77 |
|
78 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( CFSMailMessage& aMailMessage, RFile& aFile ) |
|
79 { |
|
80 CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage ); |
|
81 CleanupStack::PushL( headerHtml ); |
|
82 headerHtml->ExportL( aFile ); |
|
83 CleanupStack::PopAndDestroy( headerHtml ); |
|
84 } |
|
85 |
|
86 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( CFSMailMessage& aMailMessage, RFs& aFs, const TPath& aFilePath) |
|
87 { |
|
88 CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage ); |
|
89 CleanupStack::PushL( headerHtml ); |
|
90 headerHtml->ExportL( aFs, aFilePath ); |
|
91 CleanupStack::PopAndDestroy( headerHtml ); |
|
92 } |
|
93 |
|
94 CFreestyleMessageHeaderHTML::~CFreestyleMessageHeaderHTML() |
|
95 { |
|
96 iAttachments.ResetAndDestroy(); |
|
97 } |
|
98 |
|
99 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( RWriteStream& aWriteStream ) const |
|
100 { |
|
101 HTMLStartL( aWriteStream ); |
|
102 ExportHTMLHeaderL( aWriteStream ); |
|
103 ExportHTMLBodyL( aWriteStream ); |
|
104 HTMLEndL( aWriteStream ); |
|
105 } |
|
106 |
|
107 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( RFile& aFile ) const |
|
108 { |
|
109 RFileWriteStream fwstream; |
|
110 fwstream.Attach( aFile, 0 ); |
|
111 CleanupClosePushL( fwstream ); |
|
112 ExportL( fwstream ); |
|
113 CleanupStack::PopAndDestroy( &fwstream ); |
|
114 } |
|
115 |
|
116 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( RFs& aFs, const TPath& aFilePath) const |
|
117 { |
|
118 RFileWriteStream fwstream; |
|
119 User::LeaveIfError( fwstream.Replace( aFs, aFilePath, EFileStreamText | EFileWrite) ); |
|
120 CleanupClosePushL( fwstream ); |
|
121 ExportL( fwstream ); |
|
122 CleanupStack::PopAndDestroy( &fwstream ); |
|
123 } |
|
124 |
|
125 CFreestyleMessageHeaderHTML::CFreestyleMessageHeaderHTML( CFSMailMessage& aMailMessage ) |
|
126 : iMailMessage( aMailMessage ) |
|
127 { |
|
128 } |
|
129 |
|
130 void CFreestyleMessageHeaderHTML::ConstructL() |
|
131 { |
|
132 iMailMessage.AttachmentListL( iAttachments ); |
|
133 } |
|
134 |
|
135 void CFreestyleMessageHeaderHTML::HTMLStartL( RWriteStream& aWriteStream ) const |
|
136 { |
|
137 aWriteStream.WriteL(_L8("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n")); |
|
138 aWriteStream.CommitL(); |
|
139 } |
|
140 |
|
141 void CFreestyleMessageHeaderHTML::HTMLEndL( RWriteStream& aWriteStream ) const |
|
142 { |
|
143 aWriteStream.WriteL(_L8("</html>\n")); |
|
144 aWriteStream.CommitL(); |
|
145 } |
|
146 |
|
147 void CFreestyleMessageHeaderHTML::ExportHTMLHeaderL( RWriteStream& aWriteStream ) const |
|
148 { |
|
149 HTMLHeaderStartL( aWriteStream ); |
|
150 HTMLMetaL( aWriteStream ); |
|
151 aWriteStream.WriteL(_L8("<title>Email Header</title>\n")); |
|
152 AddJavascriptL( aWriteStream ); |
|
153 AddStyleSheetL( aWriteStream ); |
|
154 HTMLHeaderEndL( aWriteStream ); |
|
155 } |
|
156 |
|
157 void CFreestyleMessageHeaderHTML::HTMLHeaderStartL( RWriteStream& aWriteStream ) const |
|
158 { |
|
159 aWriteStream.WriteL(_L8("<head>")); |
|
160 aWriteStream.CommitL(); |
|
161 } |
|
162 |
|
163 void CFreestyleMessageHeaderHTML::HTMLMetaL( RWriteStream& aWriteStream ) const |
|
164 { |
|
165 // Html file representing email header fields, is always constructed locally |
|
166 // in the phone, and it is always of charset UTF-8 irrespective of what |
|
167 // the email html-format body is |
|
168 aWriteStream.WriteL( KMetaHeader ); |
|
169 aWriteStream.CommitL(); |
|
170 } |
|
171 |
|
172 void CFreestyleMessageHeaderHTML::HTMLHeaderEndL( RWriteStream& aWriteStream ) const |
|
173 { |
|
174 aWriteStream.WriteL(_L8("</head>\n")); |
|
175 aWriteStream.CommitL(); |
|
176 } |
|
177 |
|
178 void CFreestyleMessageHeaderHTML::ExportHTMLBodyL( RWriteStream& aWriteStream ) const |
|
179 { |
|
180 HTMLBodyStartL( aWriteStream ); |
|
181 ExportInitialTableL( aWriteStream ); |
|
182 StartHeaderTableL( aWriteStream, KHeaderTableName ); |
|
183 ExportFromL( aWriteStream ); |
|
184 ExportToL( aWriteStream ); |
|
185 ExportCcL( aWriteStream ); |
|
186 ExportBccL( aWriteStream ); |
|
187 ExportAttachmentsL( aWriteStream ); |
|
188 ExportSentTimeL( aWriteStream ); |
|
189 ExportSubjectL( aWriteStream ); |
|
190 EndHeaderTableL( aWriteStream ); |
|
191 HTMLBodyEndL( aWriteStream ); |
|
192 } |
|
193 |
|
194 void CFreestyleMessageHeaderHTML::HTMLBodyStartL( RWriteStream& aWriteStream ) const |
|
195 { |
|
196 aWriteStream.WriteL(_L8("<body>\n")); |
|
197 aWriteStream.CommitL(); |
|
198 } |
|
199 void CFreestyleMessageHeaderHTML::ExportInitialTableL( RWriteStream& aWriteStream ) const |
|
200 { |
|
201 aWriteStream.WriteL(_L8("<table id=\"table_initial\" border=\"0\" width=\"50%\">\n")); |
|
202 aWriteStream.WriteL(_L8("<tr>\n")); |
|
203 |
|
204 // Add "show details" image |
|
205 aWriteStream.WriteL(_L8("<td width=\"1\" valign=middle><image id=\"detail_img\" border=\"0\" src=\"plus.gif\" onClick=\"expandHeader()\" ></td>\n")); |
|
206 |
|
207 //Sent time |
|
208 aWriteStream.WriteL(_L8("<td id=\"sent_initial\" valign=bottom>")); |
|
209 |
|
210 HBufC* dateText = TFsEmailUiUtility::DateTextFromMsgLC( &iMailMessage ); |
|
211 HBufC* timeText = TFsEmailUiUtility::TimeTextFromMsgLC( &iMailMessage ); |
|
212 |
|
213 TInt len = dateText->Length() + KSentLineDateAndTimeSeparatorText().Length() + timeText->Length(); |
|
214 HBufC* sentTimeText = HBufC::NewLC( len ); |
|
215 TPtr sentTimeTextPtr = sentTimeText->Des(); |
|
216 sentTimeTextPtr.Append( *dateText ); |
|
217 sentTimeTextPtr.Append( KSentLineDateAndTimeSeparatorText ); |
|
218 sentTimeTextPtr.Append( *timeText ); |
|
219 HBufC8* sentTimeText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( sentTimeTextPtr ); |
|
220 CleanupStack::PushL( sentTimeText8 ); |
|
221 aWriteStream.WriteL( *sentTimeText8 ); |
|
222 CleanupStack::PopAndDestroy( sentTimeText8 ); |
|
223 CleanupStack::PopAndDestroy( sentTimeText ); |
|
224 CleanupStack::PopAndDestroy( timeText ); |
|
225 CleanupStack::PopAndDestroy( dateText ); |
|
226 |
|
227 aWriteStream.WriteL(_L8("</td>\n</tr>\n")); |
|
228 aWriteStream.WriteL(_L8("<tr id=\"subject_initial\">\n")); |
|
229 |
|
230 if ( iAttachments.Count() > 0 ) |
|
231 { |
|
232 aWriteStream.WriteL(_L8("<td width=\"1\" align=left><image src=\"")); |
|
233 aWriteStream.WriteL(KAttachementIconGeneral); |
|
234 aWriteStream.WriteL(_L8("\" ></td>\n")); |
|
235 } |
|
236 else |
|
237 { |
|
238 aWriteStream.WriteL(_L8("<td></td>\n")); |
|
239 } |
|
240 aWriteStream.WriteL(_L8("<td valign=middle><b>")); |
|
241 //Subject |
|
242 HBufC8* subject8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( iMailMessage.GetSubject() ); |
|
243 CleanupStack::PushL( subject8 ); |
|
244 aWriteStream.WriteL( *subject8 ); |
|
245 CleanupStack::PopAndDestroy( subject8 ); |
|
246 |
|
247 aWriteStream.WriteL(_L8("</b></td>\n</tr>\n</table>\n")); |
|
248 |
|
249 aWriteStream.CommitL(); |
|
250 } |
|
251 void CFreestyleMessageHeaderHTML::HTMLBodyEndL( RWriteStream& aWriteStream ) const |
|
252 { |
|
253 aWriteStream.WriteL(_L8("</body>\n")); |
|
254 aWriteStream.CommitL(); |
|
255 } |
|
256 |
|
257 void CFreestyleMessageHeaderHTML::ExportSubjectL( RWriteStream& aWriteStream ) const |
|
258 { |
|
259 aWriteStream.WriteL( _L8("<tr id=\"") ); |
|
260 aWriteStream.WriteL( KSubjectFieldName ); |
|
261 aWriteStream.WriteL( _L8("\">\n") ); |
|
262 |
|
263 |
|
264 aWriteStream.WriteL( _L8("<td width=\"1\">") ); |
|
265 aWriteStream.WriteL( _L8("<b>") ); |
|
266 HBufC8* subjectHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_SUBJECT ); |
|
267 aWriteStream.WriteL( *subjectHeadingText ); |
|
268 CleanupStack::PopAndDestroy( subjectHeadingText ); |
|
269 aWriteStream.WriteL( _L8("</b>") ); |
|
270 aWriteStream.WriteL( _L8("</td>\n") ); |
|
271 aWriteStream.WriteL( _L8("</tr>\n") ); |
|
272 aWriteStream.WriteL( _L8("<tr>\n") ); |
|
273 aWriteStream.WriteL( _L8("<td>") ); |
|
274 |
|
275 HBufC8* subject8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( iMailMessage.GetSubject() ); |
|
276 CleanupStack::PushL( subject8 ); |
|
277 aWriteStream.WriteL( *subject8 ); |
|
278 CleanupStack::PopAndDestroy( subject8 ); |
|
279 |
|
280 aWriteStream.WriteL( _L8("</td>\n") ); |
|
281 |
|
282 aWriteStream.WriteL( _L8("</tr>\n") ); |
|
283 |
|
284 aWriteStream.CommitL(); |
|
285 } |
|
286 |
|
287 void CFreestyleMessageHeaderHTML::ExportFromL( RWriteStream& aWriteStream ) const |
|
288 { |
|
289 RPointerArray<CFSMailAddress> froms; |
|
290 CleanupClosePushL( froms ); |
|
291 CFSMailAddress* from = iMailMessage.GetSender(); // ownership not transferred |
|
292 if ( from ) |
|
293 { |
|
294 froms.AppendL( from ); |
|
295 } |
|
296 ExportEmailAddressesL(aWriteStream, FreestyleMessageHeaderURLFactory::EEmailAddressTypeFrom, froms ); |
|
297 CleanupStack::PopAndDestroy( &froms ); |
|
298 } |
|
299 |
|
300 void CFreestyleMessageHeaderHTML::ExportToL( RWriteStream& aWriteStream ) const |
|
301 { |
|
302 RPointerArray<CFSMailAddress>& recipients = iMailMessage.GetToRecipients(); |
|
303 ExportEmailAddressesL( aWriteStream, FreestyleMessageHeaderURLFactory::EEmailAddressTypeTo, recipients ); |
|
304 } |
|
305 |
|
306 void CFreestyleMessageHeaderHTML::ExportCcL( RWriteStream& aWriteStream ) const |
|
307 { |
|
308 RPointerArray<CFSMailAddress>& recipients = iMailMessage.GetCCRecipients(); |
|
309 ExportEmailAddressesL( aWriteStream, FreestyleMessageHeaderURLFactory::EEmailAddressTypeCc, recipients ); |
|
310 } |
|
311 |
|
312 void CFreestyleMessageHeaderHTML::ExportBccL( RWriteStream& aWriteStream ) const |
|
313 { |
|
314 RPointerArray<CFSMailAddress>& recipients = iMailMessage.GetBCCRecipients(); |
|
315 ExportEmailAddressesL( aWriteStream, FreestyleMessageHeaderURLFactory::EEmailAddressTypeBcc, recipients ); |
|
316 } |
|
317 |
|
318 void CFreestyleMessageHeaderHTML::ExportSentTimeL( RWriteStream& aWriteStream ) const |
|
319 { |
|
320 |
|
321 aWriteStream.WriteL( _L8("<tr id=\"") ); |
|
322 aWriteStream.WriteL( KSentFieldName ); |
|
323 aWriteStream.WriteL( _L8("\">\n") ); |
|
324 |
|
325 |
|
326 aWriteStream.WriteL( _L8("<td width=\"1\">") ); |
|
327 aWriteStream.WriteL( _L8("<b>") ); |
|
328 HBufC8* sentHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_SENT ); |
|
329 aWriteStream.WriteL( *sentHeadingText ); |
|
330 CleanupStack::PopAndDestroy( sentHeadingText ); |
|
331 aWriteStream.WriteL( _L8("</b>") ); |
|
332 aWriteStream.WriteL( _L8("</td>\n") ); |
|
333 aWriteStream.WriteL( _L8("</tr>\n") ); |
|
334 |
|
335 aWriteStream.WriteL( _L8("<tr>\n") ); |
|
336 aWriteStream.WriteL( _L8("<td>") ); |
|
337 |
|
338 HBufC* dateText = TFsEmailUiUtility::DateTextFromMsgLC( &iMailMessage ); |
|
339 HBufC* timeText = TFsEmailUiUtility::TimeTextFromMsgLC( &iMailMessage ); |
|
340 |
|
341 TInt len = dateText->Length() + KSentLineDateAndTimeSeparatorText().Length() + timeText->Length(); |
|
342 HBufC* sentTimeText = HBufC::NewLC( len ); |
|
343 TPtr sentTimeTextPtr = sentTimeText->Des(); |
|
344 sentTimeTextPtr.Append( *dateText ); |
|
345 sentTimeTextPtr.Append( KSentLineDateAndTimeSeparatorText ); |
|
346 sentTimeTextPtr.Append( *timeText ); |
|
347 HBufC8* sentTimeText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( sentTimeTextPtr ); |
|
348 CleanupStack::PushL( sentTimeText8 ); |
|
349 aWriteStream.WriteL( *sentTimeText8 ); |
|
350 CleanupStack::PopAndDestroy( sentTimeText8 ); |
|
351 CleanupStack::PopAndDestroy( sentTimeText ); |
|
352 CleanupStack::PopAndDestroy( timeText ); |
|
353 CleanupStack::PopAndDestroy( dateText ); |
|
354 |
|
355 aWriteStream.WriteL( _L8("</td>\n") ); |
|
356 |
|
357 aWriteStream.WriteL( _L8("</tr>\n") ); |
|
358 |
|
359 aWriteStream.CommitL(); |
|
360 } |
|
361 |
|
362 void CFreestyleMessageHeaderHTML::ExportAttachmentsL( RWriteStream& aWriteStream ) const |
|
363 { |
|
364 if ( iAttachments.Count() > 0 ) |
|
365 { |
|
366 aWriteStream.WriteL( _L8("<tr id=\"") ); |
|
367 aWriteStream.WriteL( KAttachmentFieldName ); |
|
368 aWriteStream.WriteL( _L8("\">\n") ); |
|
369 |
|
370 aWriteStream.WriteL( _L8("<td width=\"1\">") ); |
|
371 aWriteStream.WriteL( _L8("<b>") ); |
|
372 |
|
373 HBufC8* attachmentHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_ATTACHMENT, iAttachments.Count()); |
|
374 aWriteStream.WriteL( *attachmentHeadingText ); |
|
375 CleanupStack::PopAndDestroy( attachmentHeadingText ); |
|
376 |
|
377 |
|
378 aWriteStream.WriteL( _L8(":</b>") ); |
|
379 aWriteStream.WriteL( _L8("</td>\n") ); |
|
380 aWriteStream.WriteL( _L8("</tr>\n") ); |
|
381 |
|
382 |
|
383 aWriteStream.WriteL( _L8("<td>\n") ); |
|
384 StartTableL( aWriteStream, KAttachmentTableName ); |
|
385 for (TInt i=0; i<iAttachments.Count(); i++) |
|
386 { |
|
387 AddAttachmentL( aWriteStream, *iAttachments[i] ); |
|
388 } |
|
389 EndTableL( aWriteStream ); |
|
390 aWriteStream.WriteL( _L8("</td>\n") ); |
|
391 |
|
392 aWriteStream.WriteL( _L8("</tr>\n") ); |
|
393 } |
|
394 } |
|
395 |
|
396 void CFreestyleMessageHeaderHTML::ExportEmailAddressesL( RWriteStream& aWriteStream, |
|
397 FreestyleMessageHeaderURLFactory::TEmailAddressType aEmailAddressType, |
|
398 const RPointerArray<CFSMailAddress>& aEmailAddresses ) const |
|
399 { |
|
400 if (aEmailAddresses.Count() == 0) |
|
401 { |
|
402 return; |
|
403 } |
|
404 |
|
405 aWriteStream.WriteL( _L8("<tr id=\"") ); |
|
406 switch ( aEmailAddressType ) |
|
407 { |
|
408 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeFrom: |
|
409 aWriteStream.WriteL( KFromFieldName ); |
|
410 break; |
|
411 |
|
412 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeTo: |
|
413 aWriteStream.WriteL( KToFieldName ); |
|
414 break; |
|
415 |
|
416 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeCc: |
|
417 aWriteStream.WriteL( KCcFieldName ); |
|
418 break; |
|
419 |
|
420 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeBcc: |
|
421 aWriteStream.WriteL( KBccFieldName ); |
|
422 break; |
|
423 |
|
424 default: |
|
425 User::Leave( KErrNotSupported ); |
|
426 } |
|
427 aWriteStream.WriteL( _L8("\">\n") ); |
|
428 |
|
429 |
|
430 aWriteStream.WriteL( _L8("<td width=\"1\">") ); |
|
431 aWriteStream.WriteL( _L8("<b>") ); |
|
432 |
|
433 switch ( aEmailAddressType ) |
|
434 { |
|
435 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeFrom: |
|
436 { |
|
437 HBufC8* fromHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_FROM ); |
|
438 aWriteStream.WriteL( *fromHeadingText ); |
|
439 CleanupStack::PopAndDestroy( fromHeadingText ); |
|
440 } |
|
441 break; |
|
442 |
|
443 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeTo: |
|
444 { |
|
445 HBufC8* toHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_TO ); |
|
446 aWriteStream.WriteL( *toHeadingText ); |
|
447 CleanupStack::PopAndDestroy( toHeadingText ); |
|
448 } |
|
449 break; |
|
450 |
|
451 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeCc: |
|
452 { |
|
453 HBufC8* ccHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_CC ); |
|
454 aWriteStream.WriteL( *ccHeadingText ); |
|
455 CleanupStack::PopAndDestroy( ccHeadingText ); |
|
456 } |
|
457 break; |
|
458 |
|
459 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeBcc: |
|
460 { |
|
461 HBufC8* bccHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_BCC ); |
|
462 aWriteStream.WriteL( *bccHeadingText ); |
|
463 CleanupStack::PopAndDestroy( bccHeadingText ); |
|
464 } |
|
465 break; |
|
466 |
|
467 default: |
|
468 User::Leave( KErrNotSupported ); |
|
469 } |
|
470 aWriteStream.WriteL( _L8("</b>") ); |
|
471 aWriteStream.WriteL( _L8("</td>\n") ); |
|
472 aWriteStream.WriteL( _L8("</tr>\n") ); |
|
473 |
|
474 aWriteStream.WriteL( _L8("<tr>\n") ); |
|
475 aWriteStream.WriteL( _L8("<td>") ); |
|
476 |
|
477 switch ( aEmailAddressType ) |
|
478 { |
|
479 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeTo: |
|
480 StartTableL( aWriteStream, KToTableName ); |
|
481 break; |
|
482 |
|
483 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeCc: |
|
484 StartTableL( aWriteStream, KCcTableName ); |
|
485 break; |
|
486 |
|
487 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeBcc: |
|
488 StartTableL( aWriteStream, KBccTableName ); |
|
489 break; |
|
490 case FreestyleMessageHeaderURLFactory::EEmailAddressTypeFrom: |
|
491 StartTableL( aWriteStream, KFromTableName ); |
|
492 break; |
|
493 |
|
494 default: |
|
495 User::Leave( KErrNotSupported ); |
|
496 } |
|
497 for ( TInt i=0; i<aEmailAddresses.Count(); i++ ) |
|
498 { |
|
499 aWriteStream.WriteL( _L8("<tr><td>") ); |
|
500 AddEmailAddressL (aWriteStream, aEmailAddressType, *aEmailAddresses[i] ); |
|
501 aWriteStream.WriteL( _L8("</td></tr>\n") ); |
|
502 } |
|
503 |
|
504 EndTableL( aWriteStream ); |
|
505 aWriteStream.WriteL( _L8("</td>\n") ); |
|
506 aWriteStream.WriteL( _L8("</tr>\n") ); |
|
507 aWriteStream.CommitL(); |
|
508 } |
|
509 |
|
510 void CFreestyleMessageHeaderHTML::AddEmailAddressL( RWriteStream& aWriteStream, |
|
511 FreestyleMessageHeaderURLFactory::TEmailAddressType aEmailAddressType, |
|
512 const CFSMailAddress& aEmailAddress ) const |
|
513 { |
|
514 CFreestyleMessageHeaderURL* emailUrl = FreestyleMessageHeaderURLFactory::CreateEmailAddressUrlL( aEmailAddressType, aEmailAddress ); |
|
515 CleanupStack::PushL( emailUrl ); |
|
516 |
|
517 HBufC* url = emailUrl->ExternalizeL(); |
|
518 CleanupStack::PushL( url ); |
|
519 HBufC8* url8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *url ); |
|
520 CleanupStack::PushL( url8 ); |
|
521 StartHyperlinkL( aWriteStream, *url8 ); |
|
522 CleanupStack::PopAndDestroy( url8 ); |
|
523 CleanupStack::PopAndDestroy( url ); |
|
524 |
|
525 HBufC8* displayName8 = NULL; |
|
526 if ( aEmailAddress.GetDisplayName().Length() > 0 ) |
|
527 { |
|
528 displayName8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aEmailAddress.GetDisplayName() ); |
|
529 } |
|
530 else |
|
531 { |
|
532 displayName8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aEmailAddress.GetEmailAddress() ); |
|
533 } |
|
534 CleanupStack::PushL( displayName8 ); |
|
535 aWriteStream.WriteL( *displayName8 ); |
|
536 CleanupStack::PopAndDestroy( displayName8 ); |
|
537 |
|
538 EndHyperlinkL( aWriteStream ); |
|
539 |
|
540 CleanupStack::PopAndDestroy( emailUrl ); |
|
541 } |
|
542 |
|
543 void CFreestyleMessageHeaderHTML::AddAttachmentL( RWriteStream& aWriteStream, CFSMailMessagePart& aAttachment ) const |
|
544 { |
|
545 aWriteStream.WriteL( _L8("<tr><td>") ); |
|
546 |
|
547 TUint id = aAttachment.GetPartId().Id(); |
|
548 TBuf<32> itemId; |
|
549 itemId.AppendNum( id ); |
|
550 CFreestyleMessageHeaderURL* attnUrl = FreestyleMessageHeaderURLFactory::CreateAttachmentUrlL( itemId ); |
|
551 CleanupStack::PushL( attnUrl ); |
|
552 HBufC* attnUrlText = attnUrl->ExternalizeL(); |
|
553 CleanupStack::PushL( attnUrlText ); |
|
554 HBufC8* attnUrlText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *attnUrlText ); |
|
555 CleanupStack::PushL( attnUrlText8 ); |
|
556 StartHyperlinkL( aWriteStream, *attnUrlText8 ); |
|
557 CleanupStack::PopAndDestroy( attnUrlText8 ); |
|
558 CleanupStack::PopAndDestroy( attnUrlText ); |
|
559 CleanupStack::PopAndDestroy( attnUrl ); |
|
560 |
|
561 TDesC& attnName = aAttachment.AttachmentNameL(); |
|
562 HBufC8* attnName8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( attnName ); |
|
563 CleanupStack::PushL( attnName8 ); |
|
564 aWriteStream.WriteL( *attnName8 ); |
|
565 CleanupStack::PopAndDestroy( attnName8 ); |
|
566 |
|
567 TUint size = aAttachment.ContentSize(); |
|
568 TUint sizeInKB = size / 1024; |
|
569 |
|
570 if ( size % 1024 ) |
|
571 { |
|
572 // round up |
|
573 ++sizeInKB; |
|
574 } |
|
575 |
|
576 TBuf8<32> sizeText; |
|
577 sizeText.Append( KSpace8 ); |
|
578 sizeText.Append( _L8("(") ); |
|
579 sizeText.AppendNum( sizeInKB ); |
|
580 sizeText.Append( KSpace8 ); |
|
581 sizeText.Append( KAttachmentSizeUnit ); |
|
582 sizeText.Append( _L8(")") ); |
|
583 aWriteStream.WriteL( sizeText ); |
|
584 |
|
585 EndHyperlinkL( aWriteStream ); |
|
586 |
|
587 aWriteStream.WriteL( _L8("</td></tr>\n") ); |
|
588 aWriteStream.CommitL(); |
|
589 } |
|
590 |
|
591 |
|
592 void CFreestyleMessageHeaderHTML::StartHyperlinkL( RWriteStream& aWriteStream, const TDesC8& aUrl ) const |
|
593 { |
|
594 aWriteStream.WriteL( _L8("<a href=\"") ); |
|
595 aWriteStream.WriteL( aUrl ); |
|
596 aWriteStream.WriteL( _L8("\">")); |
|
597 aWriteStream.CommitL(); |
|
598 } |
|
599 |
|
600 void CFreestyleMessageHeaderHTML::EndHyperlinkL( RWriteStream& aWriteStream ) const |
|
601 { |
|
602 aWriteStream.WriteL( _L8("</a>") ); |
|
603 aWriteStream.CommitL(); |
|
604 } |
|
605 |
|
606 void CFreestyleMessageHeaderHTML::AddImageL( RWriteStream& aWriteStream, const TDesC8& aImageUrl ) const |
|
607 { |
|
608 aWriteStream.WriteL( _L8("<image border=\"0\" src=\"") ); |
|
609 aWriteStream.WriteL( aImageUrl ); |
|
610 aWriteStream.WriteL( _L8("\">")); |
|
611 aWriteStream.CommitL(); |
|
612 } |
|
613 |
|
614 void CFreestyleMessageHeaderHTML::AddImageL( RWriteStream& aWriteStream, |
|
615 const TDesC8& aImageId, |
|
616 const TDesC8& aImageUrl, |
|
617 const TDesC8& aImageEvent ) const |
|
618 { |
|
619 aWriteStream.WriteL( _L8("<image id=\"") ); |
|
620 aWriteStream.WriteL( aImageId ); |
|
621 aWriteStream.WriteL( _L8("\" ") ); |
|
622 aWriteStream.WriteL( _L8("border=\"0\" src=\"") ); |
|
623 aWriteStream.WriteL( aImageUrl ); |
|
624 aWriteStream.WriteL( _L8("\" ")); |
|
625 aWriteStream.WriteL( aImageEvent ); |
|
626 aWriteStream.WriteL( _L8(">")); |
|
627 aWriteStream.CommitL(); |
|
628 } |
|
629 |
|
630 void CFreestyleMessageHeaderHTML::AddJavascriptL( RWriteStream& aWriteStream ) const |
|
631 { |
|
632 aWriteStream.WriteL( _L8("<script language=\"javascript\" src=\"header.js\"></script>\n")); |
|
633 aWriteStream.CommitL(); |
|
634 } |
|
635 |
|
636 void CFreestyleMessageHeaderHTML::StartHeaderTableL( RWriteStream& aWriteStream, const TDesC8& aTableId ) const |
|
637 { |
|
638 aWriteStream.WriteL( _L8("<table id=\"") ); |
|
639 aWriteStream.WriteL( aTableId ); |
|
640 |
|
641 // use style="display:none" so that full header table is hidden initially |
|
642 aWriteStream.WriteL( _L8("\" border=\"0\" width=\"50%\" style=\"display: none\">\n") ); |
|
643 |
|
644 // Add "hide details" image |
|
645 aWriteStream.WriteL(_L8("<tr>\n")); |
|
646 aWriteStream.WriteL(_L8("<td width=\"1\" valign=middle><image id=\"hideDetails_img\" border=\"0\" src=\"minus.gif\" onClick=\"collapseHeader()\"></td>\n")); |
|
647 aWriteStream.WriteL(_L8("</tr>\n")); |
|
648 aWriteStream.CommitL(); |
|
649 } |
|
650 |
|
651 void CFreestyleMessageHeaderHTML::EndHeaderTableL( RWriteStream& aWriteStream ) const |
|
652 { |
|
653 EndTableL( aWriteStream ); |
|
654 } |
|
655 |
|
656 void CFreestyleMessageHeaderHTML::StartTableL( RWriteStream& aWriteStream, const TDesC8& aTableId ) const |
|
657 { |
|
658 aWriteStream.WriteL( _L8("<table id=\"") ); |
|
659 aWriteStream.WriteL( aTableId ); |
|
660 aWriteStream.WriteL( _L8("\" border=\"0\">\n") ); |
|
661 aWriteStream.CommitL(); |
|
662 } |
|
663 |
|
664 void CFreestyleMessageHeaderHTML::EndTableL( RWriteStream& aWriteStream ) const |
|
665 { |
|
666 aWriteStream.WriteL( _L8("</table>\n") ); |
|
667 aWriteStream.CommitL(); |
|
668 } |
|
669 |
|
670 void CFreestyleMessageHeaderHTML::AddShowDetailL( RWriteStream& aWriteStream ) const |
|
671 { |
|
672 HBufC8* event = ClickImageEventL( KDetailImageName ); |
|
673 CleanupStack::PushL( event ); |
|
674 AddImageL( aWriteStream, KDetailImageName, KShowDetailIconFileName, *event ); |
|
675 CleanupStack::PopAndDestroy( event ); |
|
676 aWriteStream.CommitL(); |
|
677 } |
|
678 |
|
679 HBufC8* CFreestyleMessageHeaderHTML::ClickImageEventL( const TDesC8& aImageName ) const |
|
680 { |
|
681 TBuf8<KMaxEventLength> event; |
|
682 if ( aImageName.Compare( KToImageName ) == 0 ) |
|
683 { |
|
684 event.Append( _L8("onClick=\"toggleField('") ); |
|
685 event.Append( KToTableName ); |
|
686 event.Append( _L8("', '") ); |
|
687 event.Append( KToImageName ); |
|
688 event.Append( _L8("')\"") ); |
|
689 } |
|
690 else if ( aImageName.Compare( KCcImageName ) == 0 ) |
|
691 { |
|
692 event.Append( _L8("onClick=\"toggleField('") ); |
|
693 event.Append( KCcTableName ); |
|
694 event.Append( _L8("', '") ); |
|
695 event.Append( KCcImageName ); |
|
696 event.Append( _L8("')\"") ); |
|
697 } |
|
698 else if ( aImageName.Compare( KBccImageName ) == 0 ) |
|
699 { |
|
700 event.Append( _L8("onClick=\"toggleField('") ); |
|
701 event.Append( KBccTableName ); |
|
702 event.Append( _L8("', '") ); |
|
703 event.Append( KBccImageName ); |
|
704 event.Append( _L8("')\"") ); |
|
705 } |
|
706 else if ( aImageName.Compare( KDetailImageName ) == 0 ) |
|
707 { |
|
708 event.Append( _L8("onClick=\"toggleHeader('") ); |
|
709 event.Append( KHeaderTableName ); |
|
710 event.Append( _L8("', '") ); |
|
711 event.Append( KDetailImageName ); |
|
712 event.Append( _L8("')\"") ); |
|
713 } |
|
714 else if ( aImageName.Compare( KAttachmentImageName ) == 0 ) |
|
715 { |
|
716 event.Append( _L8("onClick=\"toggleField('") ); |
|
717 event.Append( KAttachmentTableName ); |
|
718 event.Append( _L8("', '") ); |
|
719 event.Append( KAttachmentImageName ); |
|
720 event.Append( _L8("')\"") ); |
|
721 } |
|
722 else |
|
723 { |
|
724 User::Leave(KErrNotSupported); |
|
725 } |
|
726 return event.AllocL(); |
|
727 } |
|
728 |
|
729 HBufC8* CFreestyleMessageHeaderHTML::HeadingTextLC( TInt aId ) const |
|
730 { |
|
731 HBufC* headingText = StringLoader::LoadLC( aId ); |
|
732 HBufC8* headingText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *headingText ); |
|
733 CleanupStack::PopAndDestroy( headingText ); |
|
734 CleanupStack::PushL( headingText8 ); |
|
735 return headingText8; |
|
736 } |
|
737 |
|
738 HBufC8* CFreestyleMessageHeaderHTML::HeadingTextLC( TInt aId, TInt aSize ) const |
|
739 { |
|
740 HBufC* headingText = StringLoader::LoadLC( aId, aSize ); |
|
741 HBufC8* headingText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *headingText ); |
|
742 CleanupStack::PopAndDestroy( headingText ); |
|
743 CleanupStack::PushL( headingText8 ); |
|
744 return headingText8; |
|
745 } |
|
746 |
|
747 void CFreestyleMessageHeaderHTML::AddStyleSheetL( RWriteStream& aWriteStream ) const |
|
748 { |
|
749 // Add an internal style sheet |
|
750 // If the style becomes numerous or complicated, consider using an external style sheet |
|
751 |
|
752 aWriteStream.WriteL( _L8("<style type=\"text/css\">\n") ); |
|
753 |
|
754 // define a div class "header", specifying the background color |
|
755 // for the email header part |
|
756 |
|
757 // In future, query for which background color to use |
|
758 aWriteStream.WriteL( _L8("body { background-color: lightblue; }\n") ); |
|
759 |
|
760 // set font size to 75% of the default size |
|
761 // because, at the default size, the header text is too big relative to the text in the email body |
|
762 // Note: since the text in the body is too small at "normal" level, |
|
763 // we have the text size level in the browser set to "Larger" which is 20% larger than the specified size |
|
764 // the "larger" size affects all text which includes the header. |
|
765 aWriteStream.WriteL( _L8("td { font-family:arial,sans-serif ; font-size:75% }\n")); |
|
766 |
|
767 aWriteStream.WriteL( _L8("</style>\n") ); |
|
768 aWriteStream.CommitL(); |
|
769 } |
|
770 |
|
771 void CFreestyleMessageHeaderHTML::StartDivL( RWriteStream& aWriteStream ) const |
|
772 { |
|
773 // Add div, using "header" class |
|
774 aWriteStream.WriteL( _L8("<div class=\"header\">\n") ); |
|
775 aWriteStream.CommitL(); |
|
776 } |
|
777 |
|
778 void CFreestyleMessageHeaderHTML::EndDivL( RWriteStream& aWriteStream ) const |
|
779 { |
|
780 aWriteStream.WriteL( _L8("</div>\n") ); |
|
781 aWriteStream.CommitL(); |
|
782 } |