91 |
89 |
92 const TText KGreaterThan = 0x3e; |
90 const TText KGreaterThan = 0x3e; |
93 const TText KLessThan = 0x3c; |
91 const TText KLessThan = 0x3c; |
94 const TText KAmpersand = 0x26; |
92 const TText KAmpersand = 0x26; |
95 const TText KQuotation = 0x22; |
93 const TText KQuotation = 0x22; |
96 // const TText KCharacterSpace = 0x20; |
|
97 const TText KSOH = 0x01; // Start Of Heading |
94 const TText KSOH = 0x01; // Start Of Heading |
98 // const TText KCR = 0x0d; // Carriage Return |
|
99 const TText KLF = 0x0a; // Line Feed |
95 const TText KLF = 0x0a; // Line Feed |
100 // const TText KHT = 0x09; // Horizontal Tab |
|
101 const TText KUnicodeNewLineCharacter = 0x2028; |
96 const TText KUnicodeNewLineCharacter = 0x2028; |
102 const TText KUnicodeParagraphCharacter = 0x2029; |
97 const TText KUnicodeParagraphCharacter = 0x2029; |
103 const TReal KOverlayButtonMarginX = 0.01; // 1% |
98 const TReal KOverlayButtonMarginX = 0.01; // 1% |
104 const TReal KOverlayButtonMarginY = 0.01; // 1% |
99 const TReal KOverlayButtonMarginY = 0.01; // 1% |
105 const TReal KOverlayButtonSizeP = 0.15; // 15% |
100 const TReal KOverlayButtonSizeP = 0.15; // 15% |
106 const TReal KOverlayButtonSizeLs = 0.20; // 25% |
101 const TReal KOverlayButtonSizeLs = 0.20; // 25% |
107 |
102 |
108 |
103 |
109 const TInt KStatusIndicatorHeight = 50; |
104 const TInt KStatusIndicatorHeight = 50; |
110 const TInt KStatusIndicatorXMargin = 50; |
105 const TInt KStatusIndicatorXMargin = 50; |
|
106 |
|
107 // CONSTANTS |
|
108 // Zoom levels available on the UI |
|
109 const TInt KZoomLevels[] = { 75, 100, 125, 150 }; |
|
110 const TInt KZoomLevelCount = sizeof( KZoomLevels ) / sizeof( TInt ); |
|
111 const TInt KZoomLevelIndex100 = 100; // 100 in array KZoomLevels |
111 |
112 |
112 // CEUiHtmlViewerSettingsKeyListener |
113 // CEUiHtmlViewerSettingsKeyListener |
113 |
114 |
114 // --------------------------------------------------------------------------- |
115 // --------------------------------------------------------------------------- |
115 // |
116 // |
338 { |
340 { |
339 FUNC_LOG; |
341 FUNC_LOG; |
340 ResetContent(); |
342 ResetContent(); |
341 } |
343 } |
342 |
344 |
343 void CFsEmailUiHtmlViewerContainer::ConstructL() |
345 void CFsEmailUiHtmlViewerContainer::ZoomInL() |
344 { |
346 { |
345 FUNC_LOG; |
347 SetZoomLevelL( ZoomLevelL() + 1 ); |
346 iViewerSettings = CEUiHtmlViewerSettings::NewL(*this); |
348 } |
347 |
349 |
348 SetHtmlFolderPathL(); |
350 void CFsEmailUiHtmlViewerContainer::ZoomOutL() |
349 BaflUtils::EnsurePathExistsL( iFs, iHtmlFolderPath ); |
351 { |
350 SetTempHtmlFolderPath(); |
352 SetZoomLevelL( ZoomLevelL() - 1 ); |
351 BaflUtils::EnsurePathExistsL( iFs, iTempHtmlFolderPath ); |
353 } |
352 SetHTMLResourceFlagFullName(); |
354 |
353 EnsureHTMLResourceL(); |
355 TInt CFsEmailUiHtmlViewerContainer::ZoomLevelL() const |
354 |
356 { |
355 CreateWindowL(); |
357 FUNC_LOG; |
356 SetRect( iView.ContainerRect() ); |
358 TInt zoomLevelIdx = iBrCtlInterface->BrowserSettingL( |
|
359 TBrCtlDefs::ESettingsCurrentZoomLevelIndex ); |
|
360 |
|
361 // Behaviour of zooming in Browser Control Interface is different in version 7.1 |
|
362 // than in previous versions and we need to support both. In older versions there |
|
363 // are 4 preset zoom levels while version 7.1 can zoom to any percent. |
|
364 RArray<TUint>* zoomLevels = iBrCtlInterface->ZoomLevels(); |
|
365 |
|
366 if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] ) |
|
367 { |
|
368 // new browser: |
|
369 // BrowserControlIf gives zoom level percentage insted of index to array |
|
370 TBool found = EFalse; |
|
371 |
|
372 for ( TInt i = 0 ; i < KZoomLevelCount && !found ; ++i ) |
|
373 { |
|
374 if ( zoomLevelIdx == KZoomLevels[i] ) |
|
375 { |
|
376 zoomLevelIdx = i; |
|
377 found = ETrue; |
|
378 } |
|
379 } |
|
380 |
|
381 if ( !found ) |
|
382 { |
|
383 zoomLevelIdx = KErrNotFound; |
|
384 } |
|
385 } |
|
386 return zoomLevelIdx; |
|
387 } |
|
388 |
|
389 void CFsEmailUiHtmlViewerContainer::SetZoomLevelL( const TInt aZoomLevel ) |
|
390 { |
|
391 FUNC_LOG; |
|
392 TInt newValue = KMinTInt; |
|
393 |
|
394 // Behaviour of zooming in Browser Control Interface is different in version 7.1 |
|
395 // than in previous versions and we need to support both. In older versions there |
|
396 // are 4 preset zoom levels while version 7.1 can zoom to any percent. |
|
397 RArray<TUint>* zoomLevels = iBrCtlInterface->ZoomLevels(); |
|
398 |
|
399 if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] ) |
|
400 { |
|
401 // new browser: |
|
402 // BrowserControlIf takes zoom level percentage insted of index to array |
|
403 if ( aZoomLevel >= 0 && aZoomLevel < KZoomLevelCount ) |
|
404 { |
|
405 newValue = KZoomLevels[aZoomLevel]; |
|
406 } |
|
407 } |
|
408 else |
|
409 { |
|
410 // old browser |
|
411 newValue = aZoomLevel; |
|
412 } |
|
413 |
|
414 iZoomLevel = ( newValue > KMinTInt ) ? newValue : aZoomLevel; |
|
415 iBrCtlInterface->SetBrowserSettingL( |
|
416 TBrCtlDefs::ESettingsCurrentZoomLevelIndex, iZoomLevel ); |
|
417 } |
|
418 |
|
419 TInt CFsEmailUiHtmlViewerContainer::DoZoom( TAny* aPtr ) |
|
420 { |
|
421 TRAPD( error, reinterpret_cast<CFsEmailUiHtmlViewerContainer*>( aPtr )->DoZoomL() ); |
|
422 return error; |
|
423 } |
|
424 |
|
425 void CFsEmailUiHtmlViewerContainer::DoZoomL() |
|
426 { |
|
427 iBrCtlInterface->SetBrowserSettingL( |
|
428 TBrCtlDefs::ESettingsCurrentZoomLevelIndex, iZoomLevel ); |
|
429 } |
|
430 |
|
431 TInt CFsEmailUiHtmlViewerContainer::MaxZoomLevel() const |
|
432 { |
|
433 return KZoomLevelCount; |
|
434 } |
|
435 |
|
436 |
|
437 void CFsEmailUiHtmlViewerContainer::CreateBrowserControlInterfaceL() |
|
438 { |
|
439 FUNC_LOG; |
|
440 |
|
441 if ( iBrCtlInterface ) |
|
442 { |
|
443 delete iBrCtlInterface; |
|
444 iBrCtlInterface = NULL; |
|
445 } |
357 |
446 |
358 TUint brCtlCapabilities = TBrCtlDefs::ECapabilityClientResolveEmbeddedURL | |
447 TUint brCtlCapabilities = TBrCtlDefs::ECapabilityClientResolveEmbeddedURL | |
359 TBrCtlDefs::ECapabilityDisplayScrollBar | |
448 TBrCtlDefs::ECapabilityDisplayScrollBar | |
360 TBrCtlDefs::ECapabilityClientNotifyURL | |
449 TBrCtlDefs::ECapabilityClientNotifyURL | |
361 TBrCtlDefs::ECapabilityLoadHttpFw | |
450 TBrCtlDefs::ECapabilityLoadHttpFw | |
362 TBrCtlDefs::ECapabilityCursorNavigation | |
451 TBrCtlDefs::ECapabilityCursorNavigation | |
363 TBrCtlDefs::ECapabilityPinchZoom; |
452 TBrCtlDefs::ECapabilityPinchZoom | |
|
453 TBrCtlDefs::ECapabilityFitToScreen; |
364 |
454 |
365 // Set browsercontrol to whole screen |
455 // Set browsercontrol to whole screen |
366 TRect rect( TPoint(), Size() ); |
456 TRect rect( TPoint(), Size() ); |
367 |
457 |
368 iBrCtlInterface = CreateBrowserControlL( |
458 iBrCtlInterface = CreateBrowserControlL( |
369 this, // aParent |
459 this, // aParent |
370 rect, // aRect |
460 rect, // aRect |
371 brCtlCapabilities, // aBrCtlCapabilities |
461 brCtlCapabilities, // aBrCtlCapabilities |
372 TBrCtlDefs::ECommandIdBase, // aCommandIdBase |
462 TBrCtlDefs::ECommandIdBase, // aCommandIdBase |
373 NULL, // aBrCtlSoftkeysObserver |
463 NULL, // aBrCtlSoftkeysObserver |
374 this, // aBrCtlLinkResolver |
464 this, // aBrCtlLinkResolver |
375 this, // aBrCtlSpecialLoadObserver |
465 this, // aBrCtlSpecialLoadObserver |
376 NULL, // aBrCtlLayoutObserver |
466 NULL, // aBrCtlLayoutObserver |
377 NULL, // aBrCtlDialogsProvider |
467 NULL, // aBrCtlDialogsProvider |
378 this, // aBrCtlWindowObserver |
468 this, // aBrCtlWindowObserver |
379 NULL // aBrCtlDownloadObserver |
469 NULL // aBrCtlDownloadObserver |
380 ); |
470 ); |
381 |
471 |
382 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsEmbedded, ETrue ); |
472 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsEmbedded, ETrue ); |
383 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() ); |
473 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() ); |
384 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsPageOverview, EFalse ); |
474 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsPageOverview, EFalse ); |
385 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsTextWrapEnabled, ETrue ); |
475 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsTextWrapEnabled, ETrue ); |
386 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsFontSize, TBrCtlDefs::EFontSizeLevelLarger ); |
476 iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsFontSize, TBrCtlDefs::EFontSizeLevelLarger ); |
|
477 } |
|
478 |
|
479 void CFsEmailUiHtmlViewerContainer::ConstructL() |
|
480 { |
|
481 FUNC_LOG; |
|
482 iViewerSettings = CEUiHtmlViewerSettings::NewL(*this); |
|
483 |
|
484 SetHtmlFolderPathL(); |
|
485 BaflUtils::EnsurePathExistsL( iFs, iHtmlFolderPath ); |
|
486 SetTempHtmlFolderPath(); |
|
487 BaflUtils::EnsurePathExistsL( iFs, iTempHtmlFolderPath ); |
|
488 SetHTMLResourceFlagFullName(); |
|
489 EnsureHTMLResourceL(); |
|
490 |
|
491 CreateWindowL(); |
387 |
492 |
|
493 #if defined( BRDO_MULTITOUCH_ENABLED_FF ) && !defined ( __WINSCW__ ) |
|
494 //Enable advance pointer info for multi-touch. |
|
495 Window().EnableAdvancedPointers(); |
|
496 #endif |
|
497 |
|
498 |
|
499 SetRect( iView.ContainerRect() ); |
|
500 CreateBrowserControlInterfaceL(); |
|
501 |
388 iEventHandler = CFreestyleMessageHeaderURLEventHandler::NewL( iAppUi, iView ); |
502 iEventHandler = CFreestyleMessageHeaderURLEventHandler::NewL( iAppUi, iView ); |
389 |
503 |
390 TRect nextButtonRect = OverlayButtonRect( EFalse ); |
504 TRect nextButtonRect = OverlayButtonRect( EFalse ); |
391 iOverlayControlNext = COverlayControl::NewL( this, this, nextButtonRect, |
505 iOverlayControlNext = COverlayControl::NewL( this, this, nextButtonRect, |
392 EMbmFreestyleemailuiQgn_indi_cmail_arrow_next, |
506 EMbmFreestyleemailuiQgn_indi_cmail_arrow_next, |
393 EMbmFreestyleemailuiQgn_indi_cmail_arrow_next_mask ); |
507 EMbmFreestyleemailuiQgn_indi_cmail_arrow_next_mask ); |
394 |
508 |
395 TRect prevButtonRect = OverlayButtonRect( ETrue ); |
509 TRect prevButtonRect = OverlayButtonRect( ETrue ); |
396 iOverlayControlPrev = COverlayControl::NewL( this, this, prevButtonRect, |
510 iOverlayControlPrev = COverlayControl::NewL( this, this, prevButtonRect, |
397 EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous, |
511 EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous, |
523 ASSERT( aMailMessage ); |
637 ASSERT( aMailMessage ); |
524 iMessage = aMailMessage; |
638 iMessage = aMailMessage; |
525 // Cancel any browser fetch operation, just in case the browser is still |
639 // Cancel any browser fetch operation, just in case the browser is still |
526 // loading a previous message (since we are about to overwrite it). |
640 // loading a previous message (since we are about to overwrite it). |
527 CancelFetch(); |
641 CancelFetch(); |
528 |
642 |
529 TPath headerHtmlFile; |
643 TPath headerHtmlFile; |
530 headerHtmlFile.Copy( iHtmlFolderPath ); |
644 headerHtmlFile.Copy( iHtmlFolderPath ); |
531 headerHtmlFile.Append( KHeaderHtmlFile ); |
645 headerHtmlFile.Append( KHeaderHtmlFile ); |
532 |
646 |
533 // insert email header into email.html file |
647 // insert email header into email.html file |
534 // CFreestyleMessageHeaderHTML will replace contents of email.html |
648 // CFreestyleMessageHeaderHTML will replace contents of email.html |
535 // So, no need to clear the contents |
649 // So, no need to clear the contents |
536 if(aResetScrollPos) |
650 if(aResetScrollPos) |
537 { |
651 { |
538 iScrollPosition = 0; |
652 iScrollPosition = 0; |
539 } |
653 } |
540 const TInt visibleWidth(iAppUi.ClientRect().Width()); |
654 const TInt visibleWidth(iAppUi.ClientRect().Width()); |
541 CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, visibleWidth, iScrollPosition, |
655 CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, visibleWidth, iScrollPosition, |
542 iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage), |
656 iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage), |
543 iHeaderExpanded ); |
657 iHeaderExpanded ); |
544 |
658 |
545 // Remove all previously created files from temporary HTML folder |
659 // Remove all previously created files from temporary HTML folder |
546 EmptyTempHtmlFolderL(); |
660 EmptyTempHtmlFolderL(); |
547 |
661 |
548 TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) ); |
662 TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) ); |
549 if ( error != KErrNone ) |
663 if ( error != KErrNone ) |
1048 // <cmail> |
1175 // <cmail> |
1049 void CFsEmailUiHtmlViewerContainer::WriteContentToFileL( const TDesC8& aContent, |
1176 void CFsEmailUiHtmlViewerContainer::WriteContentToFileL( const TDesC8& aContent, |
1050 const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart ) |
1177 const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart ) |
1051 { |
1178 { |
1052 FUNC_LOG; |
1179 FUNC_LOG; |
1053 |
1180 |
1054 RBuf8 buffer; |
1181 RBuf8 buffer; |
1055 buffer.CreateL( aContent ); |
1182 buffer.CreateL( aContent ); |
1056 buffer.CleanupClosePushL(); |
1183 buffer.CleanupClosePushL(); |
1057 |
1184 |
1058 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, buffer.Size(), EDriveC ) ) |
1185 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, buffer.Size(), EDriveC ) ) |
1059 { |
1186 { |
1060 // Can not write the data, there's not enough free space on disk. |
1187 // Can not write the data, there's not enough free space on disk. |
1061 User::Leave( KErrDiskFull ); |
1188 User::Leave( KErrDiskFull ); |
1062 } |
1189 } |
1063 else |
1190 else |
1064 { |
1191 { |
1065 RFile targetFile; |
1192 RFile targetFile; |
1066 CleanupClosePushL( targetFile ); |
1193 CleanupClosePushL( targetFile ); |
1067 |
1194 |
1068 User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); |
1195 User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); |
1069 |
1196 |
1070 // Try to find initial html tag (both '<html' and '<HTML' versions are searched) |
1197 // Try to find initial html tag (both '<html' and '<HTML' versions are searched) |
1071 TInt startTagOffset = buffer.Left( KMaxCharsToSearch ).FindF( KStartTag ); |
1198 TInt startTagOffset = buffer.Left( KMaxCharsToSearch ).FindF( KStartTag ); |
1072 |
1199 |
1073 // Modifying text/html atta IF there's no '<html>' tag anywhere in |
1200 // Modifying text/html atta IF there's no '<html>' tag anywhere in |
1074 // the begining of file (KMaxCharsToSearch) AND there is charset |
1201 // the begining of file (KMaxCharsToSearch) AND there is charset |
1075 // parameter available |
1202 // parameter available |
1076 TBool modificationNeeded( EFalse ); |
1203 TBool modificationNeeded( EFalse ); |
1077 if( startTagOffset == KErrNotFound ) |
1204 if( startTagOffset == KErrNotFound ) |
1082 // Write starting metadata if needed |
1209 // Write starting metadata if needed |
1083 if ( modificationNeeded ) |
1210 if ( modificationNeeded ) |
1084 { |
1211 { |
1085 HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart ); |
1212 HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart ); |
1086 CleanupStack::PushL( charSet ); |
1213 CleanupStack::PushL( charSet ); |
1087 |
1214 |
1088 User::LeaveIfError( targetFile.Write( KHtmlHeader1 ) ); |
1215 User::LeaveIfError( targetFile.Write( KHtmlHeader1 ) ); |
1089 User::LeaveIfError( targetFile.Write( *charSet ) ); |
1216 User::LeaveIfError( targetFile.Write( *charSet ) ); |
1090 User::LeaveIfError( targetFile.Write( KHtmlHeader2 ) ); |
1217 User::LeaveIfError( targetFile.Write( KHtmlHeader2 ) ); |
1091 CleanupStack::PopAndDestroy( charSet ); |
1218 CleanupStack::PopAndDestroy( charSet ); |
1092 } |
1219 } |
1093 else |
1220 else |
1094 { |
1221 { |
1095 // Charset tag not found in html body |
1222 // Charset tag not found in html body |
1096 |
1223 |
1097 if ( buffer.Left( KMaxCharsToSearch ).FindF( KCharsetTag8 ) == KErrNotFound ) |
1224 if ( buffer.Left( KMaxCharsToSearch ).FindF( KCharsetTag8 ) == KErrNotFound ) |
1098 { |
1225 { |
1099 TInt startPos(0); |
1226 TInt startPos(0); |
1100 if ( ( startPos = buffer.Left( KMaxCharsToSearch ).FindF( KHeadTag ) ) != KErrNotFound ) |
1227 if ( ( startPos = buffer.Left( KMaxCharsToSearch ).FindF( KHeadTag ) ) != KErrNotFound ) |
1101 { |
1228 { |
1102 |
1229 |
1103 HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart ); |
1230 HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart ); |
1104 CleanupStack::PushL( charSet ); |
1231 CleanupStack::PushL( charSet ); |
1105 |
1232 |
1106 HBufC8* metaBuffer = HBufC8::NewLC( charSet->Des().Length() + KHtmlHeader3().Length() ); |
1233 HBufC8* metaBuffer = HBufC8::NewLC( charSet->Des().Length() + KHtmlHeader3().Length() ); |
1107 TPtr8 metaHeader( metaBuffer->Des() ); |
1234 TPtr8 metaHeader( metaBuffer->Des() ); |
1108 metaHeader.AppendFormat( KHtmlHeader3, charSet ); |
1235 metaHeader.AppendFormat( KHtmlHeader3, charSet ); |
1109 TInt maxLength = buffer.Length() + metaHeader.Length(); |
1236 TInt maxLength = buffer.Length() + metaHeader.Length(); |
1110 buffer.ReAllocL( maxLength ); |
1237 buffer.ReAllocL( maxLength ); |
1111 |
1238 |
1112 startPos += KHeadTag().Length(); |
1239 startPos += KHeadTag().Length(); |
1113 buffer.Insert( startPos, metaHeader ); |
1240 buffer.Insert( startPos, metaHeader ); |
1114 |
1241 |
1115 CleanupStack::PopAndDestroy( metaBuffer ); |
1242 CleanupStack::PopAndDestroy( metaBuffer ); |
1116 CleanupStack::PopAndDestroy( charSet ); |
1243 CleanupStack::PopAndDestroy( charSet ); |
1117 } |
1244 } |
1118 } |
1245 } |
1119 } |
1246 } |
1242 if( iMessage ) |
1369 if( iMessage ) |
1243 { |
1370 { |
1244 partData.iMailBoxId = iMessage->GetMailBoxId(); |
1371 partData.iMailBoxId = iMessage->GetMailBoxId(); |
1245 partData.iFolderId = iMessage->GetFolderId(); |
1372 partData.iFolderId = iMessage->GetFolderId(); |
1246 partData.iMessageId = iMessage->GetMessageId(); |
1373 partData.iMessageId = iMessage->GetMessageId(); |
1247 |
1374 |
1248 partData.iMessagePartId = aAttachment.GetPartId(); |
1375 partData.iMessagePartId = aAttachment.GetPartId(); |
1249 |
1376 |
1250 if ( iAppUi.DownloadInfoMediator() && |
1377 if ( iAppUi.DownloadInfoMediator() && |
1251 iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) ) |
1378 iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) ) |
1252 { |
1379 { |
1253 ASSERT( iLinkContents.Count() == iMessageParts.Count() ); |
1380 ASSERT( iLinkContents.Count() == iMessageParts.Count() ); |
1254 |
1381 |
1255 // Append message part details and embedded link content interface |
1382 // Append message part details and embedded link content interface |
1256 // to corresponding arrays so that the content can be returned |
1383 // to corresponding arrays so that the content can be returned |
1257 // when the download is completed. |
1384 // when the download is completed. |
1258 iLinkContents.AppendL( &aEmbeddedLinkContent ); |
1385 iLinkContents.AppendL( &aEmbeddedLinkContent ); |
1259 if ( iMessageParts.Append( partData ) != KErrNone ) |
1386 if ( iMessageParts.Append( partData ) != KErrNone ) |
1260 { |
1387 { |
1261 iLinkContents.Remove( iLinkContents.Count() - 1 ); |
1388 iLinkContents.Remove( iLinkContents.Count() - 1 ); |
1262 } |
1389 } |
1263 |
1390 |
1264 ASSERT( iLinkContents.Count() == iMessageParts.Count() ); |
1391 ASSERT( iLinkContents.Count() == iMessageParts.Count() ); |
1265 if(!iView.GetAsyncFetchStatus()) |
1392 if(!iView.GetAsyncFetchStatus()) |
1266 { |
1393 { |
1267 iAppUi.DownloadInfoMediator()->AddObserver( this, aAttachment.GetMessageId() ); |
1394 iAppUi.DownloadInfoMediator()->AddObserver( this, aAttachment.GetMessageId() ); |
1268 iObservingDownload=ETrue; |
1395 iObservingDownload=ETrue; |
1304 TFileName privatePath; |
1431 TFileName privatePath; |
1305 User::LeaveIfError( iFs.PrivatePath( privatePath ) ); |
1432 User::LeaveIfError( iFs.PrivatePath( privatePath ) ); |
1306 htmlFolderPathInZ.Append( privatePath ); |
1433 htmlFolderPathInZ.Append( privatePath ); |
1307 |
1434 |
1308 htmlFolderPathInZ.Append( KHtmlPath ); |
1435 htmlFolderPathInZ.Append( KHtmlPath ); |
1309 |
1436 |
1310 CDir* dirList; |
1437 CDir* dirList; |
1311 TPath listSpec; |
1438 TPath listSpec; |
1312 listSpec.Copy( htmlFolderPathInZ ); |
1439 listSpec.Copy( htmlFolderPathInZ ); |
1313 |
1440 |
1314 listSpec.Append( _L("*.*") ); |
1441 listSpec.Append( _L("*.*") ); |
1315 User::LeaveIfError( iFs.GetDir( listSpec, KEntryAttMaskSupported, ESortByName, dirList ) ); |
1442 User::LeaveIfError( iFs.GetDir( listSpec, KEntryAttMaskSupported, ESortByName, dirList ) ); |
1316 CleanupStack::PushL( dirList ); |
1443 CleanupStack::PushL( dirList ); |
1317 for ( TInt i=0; i < dirList->Count(); i++) |
1444 for ( TInt i=0; i < dirList->Count(); i++) |
1318 { |
1445 { |
1319 TPath sourceFileFullName; |
1446 TPath sourceFileFullName; |
1320 sourceFileFullName.Copy( htmlFolderPathInZ ); |
1447 sourceFileFullName.Copy( htmlFolderPathInZ ); |
1321 sourceFileFullName.Append( (*dirList)[i].iName ); |
1448 sourceFileFullName.Append( (*dirList)[i].iName ); |
1322 |
1449 |
1323 TBool isFolder( EFalse ); |
1450 TBool isFolder( EFalse ); |
1324 BaflUtils::IsFolder( iFs, sourceFileFullName, isFolder); |
1451 BaflUtils::IsFolder( iFs, sourceFileFullName, isFolder); |
1325 if ( isFolder ) |
1452 if ( isFolder ) |
1326 { |
1453 { |
1327 break; |
1454 break; |
1328 } |
1455 } |
1329 |
1456 |
1330 TPath targetFileFullName; |
1457 TPath targetFileFullName; |
1331 targetFileFullName.Copy( iHtmlFolderPath ); |
1458 targetFileFullName.Copy( iHtmlFolderPath ); |
1332 targetFileFullName.Append( (*dirList)[i].iName ); |
1459 targetFileFullName.Append( (*dirList)[i].iName ); |
1333 BaflUtils::DeleteFile( iFs, targetFileFullName ); |
1460 BaflUtils::DeleteFile( iFs, targetFileFullName ); |
1334 |
1461 |
1335 BaflUtils::CopyFile( iFs, sourceFileFullName, targetFileFullName); |
1462 BaflUtils::CopyFile( iFs, sourceFileFullName, targetFileFullName); |
1336 } |
1463 } |
1337 CleanupStack::PopAndDestroy( dirList ); |
1464 CleanupStack::PopAndDestroy( dirList ); |
1338 } |
1465 } |
1339 |
1466 |
1340 void CFsEmailUiHtmlViewerContainer::EnsureHTMLResourceL() |
1467 void CFsEmailUiHtmlViewerContainer::EnsureHTMLResourceL() |
1341 { |
1468 { |
1342 FUNC_LOG; |
1469 FUNC_LOG; |
1343 |
1470 |
1344 if ( !HTMLResourceFlagEnabled() ) |
1471 if ( !HTMLResourceFlagEnabled() ) |
1345 { |
1472 { |
1346 CopyHTMLResourceL(); |
1473 CopyHTMLResourceL(); |
1347 EnableHTMLResourceFlagL(); |
1474 EnableHTMLResourceFlagL(); |
1348 } |
1475 } |
1350 |
1477 |
1351 // --------------------------------------------------------------------------- |
1478 // --------------------------------------------------------------------------- |
1352 // Writes buffer content to given file after adding tags |
1479 // Writes buffer content to given file after adding tags |
1353 // --------------------------------------------------------------------------- |
1480 // --------------------------------------------------------------------------- |
1354 // |
1481 // |
1355 // <cmail> |
|
1356 void CFsEmailUiHtmlViewerContainer::ConvertToHTML( const TDesC& aContent, |
1482 void CFsEmailUiHtmlViewerContainer::ConvertToHTML( const TDesC& aContent, |
1357 const TDesC& aFileName, CFSMailMessagePart& /*aTextBodyPart*/ ) |
1483 const TDesC& aFileName, CFSMailMessagePart& /*aTextBodyPart*/ ) |
1358 { |
1484 { |
1359 FUNC_LOG; |
1485 FUNC_LOG; |
1360 const TInt KBodyTextChunkSize = 2048; |
1486 |
1361 |
|
1362 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aContent.Size(), EDriveC ) ) |
1487 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aContent.Size(), EDriveC ) ) |
1363 { |
1488 { |
1364 // Can not write the data, there's not enough free space on disk. |
1489 // Can not write the data, there's not enough free space on disk. |
1365 User::Leave( KErrDiskFull ); |
1490 User::Leave( KErrDiskFull ); |
1366 } |
1491 } |
1367 else |
1492 |
1368 { |
1493 RBuf htmlText; |
1369 RBuf bodyBuf; |
1494 CleanupClosePushL( htmlText ); |
1370 bodyBuf.CreateL( aContent.Size() + KBodyTextChunkSize ); |
|
1371 bodyBuf.CleanupClosePushL(); |
|
1372 bodyBuf.Insert( 0, aContent); |
|
1373 TInt maxlength = bodyBuf.MaxSize(); |
|
1374 |
1495 |
1375 TInt position( 0 ); |
1496 PlainTextToHtmlConverter::PlainTextToHtmlL( aContent, htmlText ); |
1376 TBool EndOfString( EFalse ); |
1497 WriteToFileL( aFileName, htmlText ); |
1377 |
1498 |
1378 while ( !EndOfString ) |
1499 CleanupStack::PopAndDestroy( &htmlText ); |
1379 { |
|
1380 TInt startPosition = position; |
|
1381 TPtr segment( bodyBuf.MidTPtr( startPosition ) ); |
|
1382 TInt i = 0; |
|
1383 |
|
1384 while(i < segment.Length()) |
|
1385 { |
|
1386 TInt currentPos = position + i; |
|
1387 TText ch = segment[i]; |
|
1388 |
|
1389 switch( ch ) |
|
1390 { |
|
1391 case KSOH: // end of line for IMAP and POP |
|
1392 bodyBuf.Delete( currentPos, 1 ); |
|
1393 maxlength = maxlength + KHtmlLineBreakCRLF().Length(); |
|
1394 bodyBuf.ReAlloc( maxlength ); |
|
1395 bodyBuf.Insert( currentPos, KHtmlLineBreakCRLF ); |
|
1396 i += KHtmlLineBreakCRLF().Length(); |
|
1397 segment.Set( bodyBuf.MidTPtr( startPosition ) ); |
|
1398 break; |
|
1399 case KLF: // line feed |
|
1400 case KUnicodeNewLineCharacter: |
|
1401 case KUnicodeParagraphCharacter: |
|
1402 maxlength = maxlength + KHtmlLineBreak().Length(); |
|
1403 bodyBuf.ReAlloc( maxlength ); |
|
1404 bodyBuf.Insert( currentPos, KHtmlLineBreak ); |
|
1405 i += KHtmlLineBreak().Length() + 1; |
|
1406 segment.Set( bodyBuf.MidTPtr( startPosition ) ); |
|
1407 break; |
|
1408 case KQuotation: |
|
1409 bodyBuf.Delete( currentPos, 1 ); |
|
1410 maxlength = maxlength + KHtmlQuotation().Length(); |
|
1411 bodyBuf.ReAlloc( maxlength ); |
|
1412 bodyBuf.Insert( currentPos, KHtmlQuotation ); |
|
1413 i += KHtmlQuotation().Length(); |
|
1414 segment.Set( bodyBuf.MidTPtr( startPosition ) ); |
|
1415 break; |
|
1416 case KAmpersand: |
|
1417 bodyBuf.Delete( currentPos, 1 ); |
|
1418 maxlength = maxlength + KHtmlAmpersand().Length(); |
|
1419 bodyBuf.ReAlloc( maxlength ); |
|
1420 bodyBuf.Insert( currentPos, KHtmlAmpersand ); |
|
1421 i += KHtmlAmpersand().Length(); |
|
1422 segment.Set( bodyBuf.MidTPtr( startPosition ) ); |
|
1423 break; |
|
1424 case KGreaterThan: |
|
1425 bodyBuf.Delete( currentPos, 1 ); |
|
1426 maxlength = maxlength + KHtmlGreaterThan().Length(); |
|
1427 bodyBuf.ReAlloc( maxlength ); |
|
1428 bodyBuf.Insert( currentPos, KHtmlGreaterThan ); |
|
1429 i += KHtmlGreaterThan().Length(); |
|
1430 segment.Set( bodyBuf.MidTPtr( startPosition ) ); |
|
1431 break; |
|
1432 case KLessThan: |
|
1433 bodyBuf.Delete( currentPos, 1 ); |
|
1434 maxlength = maxlength + KHtmlLessThan().Length(); |
|
1435 bodyBuf.ReAlloc( maxlength ); |
|
1436 bodyBuf.Insert( currentPos, KHtmlLessThan ); |
|
1437 i += KHtmlLessThan().Length(); |
|
1438 segment.Set( bodyBuf.MidTPtr( startPosition ) ); |
|
1439 break; |
|
1440 default: |
|
1441 i++; |
|
1442 break; |
|
1443 } |
|
1444 } |
|
1445 position += segment.Length(); |
|
1446 if ( ( bodyBuf.Length() - position ) <= 0 ) |
|
1447 { |
|
1448 EndOfString = ETrue; |
|
1449 } |
|
1450 } |
|
1451 |
|
1452 CreateHyperlinksFromUrlsL( bodyBuf ); |
|
1453 |
|
1454 HBufC8* content8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( bodyBuf ); |
|
1455 CleanupStack::PushL( content8 ); |
|
1456 |
|
1457 RFile targetFile; |
|
1458 CleanupClosePushL( targetFile ); |
|
1459 User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); |
|
1460 |
|
1461 RBuf8 messageHeader; |
|
1462 _LIT( KCharsetUtf8, "UTF-8" ); |
|
1463 TInt bufSize = KHtmlHeader1().Length() + KCharsetUtf8().Length() + KHtmlHeader2().Length(); |
|
1464 messageHeader.CreateL( bufSize ); |
|
1465 messageHeader.CleanupClosePushL(); |
|
1466 |
|
1467 messageHeader.Append( KHtmlHeader1 ); |
|
1468 messageHeader.Append( KCharsetUtf8 ); |
|
1469 messageHeader.Append( KHtmlHeader2 ); |
|
1470 |
|
1471 RFileWriteStream fileStream( targetFile ); |
|
1472 fileStream.PushL(); |
|
1473 fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() ); |
|
1474 |
|
1475 TInt bufPos( 0 ); |
|
1476 TInt bufTotalSize = content8->Size(); |
|
1477 |
|
1478 while ( bufPos < bufTotalSize ) |
|
1479 { |
|
1480 TInt segmentLength = content8->Mid( bufPos ).Length(); |
|
1481 fileStream.WriteL( content8->Mid( bufPos ).Ptr(), segmentLength ); |
|
1482 bufPos += segmentLength; |
|
1483 } |
|
1484 |
|
1485 fileStream.CommitL(); |
|
1486 |
|
1487 CleanupStack::PopAndDestroy( &fileStream ); |
|
1488 CleanupStack::PopAndDestroy( &messageHeader ); |
|
1489 CleanupStack::PopAndDestroy( &targetFile ); |
|
1490 CleanupStack::PopAndDestroy( content8 ); |
|
1491 CleanupStack::PopAndDestroy( &bodyBuf ); // calls bodyBuf.Close(); |
|
1492 |
|
1493 // </cmail> |
|
1494 } |
|
1495 } |
|
1496 |
|
1497 // --------------------------------------------------------------------------- |
|
1498 // Finds and html formats hyperlinks in a document |
|
1499 // --------------------------------------------------------------------------- |
|
1500 // |
|
1501 // <cmail> |
|
1502 void CFsEmailUiHtmlViewerContainer::CreateHyperlinksFromUrlsL( RBuf& aSource ) |
|
1503 { |
|
1504 FUNC_LOG; |
|
1505 const TInt searhCases( CFindItemEngine::EFindItemSearchURLBin ); |
|
1506 CFindItemEngine* itemEngine = CFindItemEngine::NewL( aSource, CFindItemEngine::TFindItemSearchCase( searhCases ) ); |
|
1507 CleanupStack::PushL ( itemEngine ); |
|
1508 if ( itemEngine->ItemCount() > 0 ) |
|
1509 { |
|
1510 _LIT( KSchemeDelimiter, "://" ); |
|
1511 _LIT( KUrlFormat, "<a href=\"%S\">%S</a>" ); |
|
1512 _LIT( KUrlFormatWithHttp, "<a href=\"http://%S\">%S</a>" ); |
|
1513 |
|
1514 const TInt sourceLength( aSource.Length() ); |
|
1515 // Allocate enough space for the final result |
|
1516 aSource.ReAllocL( sourceLength + TotalLengthOfItems( *itemEngine ) + KUrlFormatWithHttp().Length() * itemEngine->ItemCount() ); |
|
1517 aSource.SetMax(); |
|
1518 // Organize buffer so that original data is in the back of the aSource |
|
1519 aSource.RightTPtr( sourceLength ).Copy( aSource.Left( sourceLength ) ); |
|
1520 // Set source to new original data's position |
|
1521 const TPtrC source( aSource.RightTPtr( sourceLength ) ); |
|
1522 // Set target to aSource's beginning |
|
1523 TPtr target( aSource.MidTPtr( 0 ) ); |
|
1524 // Reset length, we now have an empty buffer to fill |
|
1525 target.SetLength( 0 ); |
|
1526 |
|
1527 TInt currentSourcePosition( 0 ); |
|
1528 CFindItemEngine::SFoundItem item; |
|
1529 for ( TBool available( itemEngine->Item( item ) ); available; available = itemEngine->NextItem( item ) ) |
|
1530 { |
|
1531 target.Append( source.Mid( currentSourcePosition, item.iStartPos - currentSourcePosition ) ); |
|
1532 const TPtrC url( source.Mid( item.iStartPos, item.iLength ) ); |
|
1533 TPtrC format( KUrlFormat() ); |
|
1534 if ( url.FindF( KSchemeDelimiter() ) == KErrNotFound ) |
|
1535 { |
|
1536 format.Set( KUrlFormatWithHttp() ); |
|
1537 } |
|
1538 HBufC* formatBuffer = HBufC::NewLC( format.Length() + url.Length() * 2 ); |
|
1539 formatBuffer->Des().Format( format, &url, &url ); |
|
1540 target.Append( *formatBuffer ); |
|
1541 CleanupStack::PopAndDestroy(); // formatBuffer |
|
1542 currentSourcePosition = item.iStartPos + item.iLength; |
|
1543 } |
|
1544 // Append characters that are left in buffer |
|
1545 if ( currentSourcePosition < sourceLength ) |
|
1546 { |
|
1547 target.Append( source.Mid( currentSourcePosition, sourceLength - currentSourcePosition ) ); |
|
1548 } |
|
1549 aSource.SetLength( target.Length() ); |
|
1550 } |
|
1551 CleanupStack::PopAndDestroy(); // itemEngine |
|
1552 } |
1500 } |
1553 |
1501 |
1554 |
1502 |
1555 TInt CFsEmailUiHtmlViewerContainer::TotalLengthOfItems( CFindItemEngine& aItemEngine ) const |
1503 TInt CFsEmailUiHtmlViewerContainer::TotalLengthOfItems( CFindItemEngine& aItemEngine ) const |
1556 { |
1504 { |
1822 TRect CFsEmailUiHtmlViewerContainer::CalcAttachmentStatusRect() |
1770 TRect CFsEmailUiHtmlViewerContainer::CalcAttachmentStatusRect() |
1823 { |
1771 { |
1824 TRect rect = Rect(); |
1772 TRect rect = Rect(); |
1825 TPoint topLeft = rect.iTl; |
1773 TPoint topLeft = rect.iTl; |
1826 TPoint bottomRight = rect.iBr; |
1774 TPoint bottomRight = rect.iBr; |
1827 |
1775 |
1828 TPoint statusTopLeft( topLeft.iX + KStatusIndicatorXMargin, bottomRight.iY - KStatusIndicatorHeight + 1 ); |
1776 TPoint statusTopLeft( topLeft.iX + KStatusIndicatorXMargin, bottomRight.iY - KStatusIndicatorHeight + 1 ); |
1829 TPoint statusBottomRight( bottomRight.iX - KStatusIndicatorXMargin, bottomRight.iY ); |
1777 TPoint statusBottomRight( bottomRight.iX - KStatusIndicatorXMargin, bottomRight.iY ); |
1830 return TRect( statusTopLeft, statusBottomRight ); |
1778 return TRect( statusTopLeft, statusBottomRight ); |
1831 } |
1779 } |
1832 |
1780 |
1833 void CFsEmailUiHtmlViewerContainer::TouchFeedback() |
1781 void CFsEmailUiHtmlViewerContainer::TouchFeedback() |
1834 { |
1782 { |
1835 iTouchFeedBack->InstantFeedback(this, ETouchFeedbackBasic); |
1783 iTouchFeedBack->InstantFeedback(this, ETouchFeedbackBasic); |
1836 } |
1784 } |
1837 |
1785 |
1838 /** |
1786 /** |
1839 * The body fetch link is cmail://body/fetch. Look for the URL separator |
1787 * The body fetch link is cmail://body/fetch. Look for the URL separator |
1840 * and the presence of cmail and body on the url. |
1788 * and the presence of cmail and body on the url. |
1841 * @param aUrl |
1789 * @param aUrl |
1842 * return ETrue for a valid body URL |
1790 * return ETrue for a valid body URL |
1843 */ |
1791 */ |
1844 TBool CFsEmailUiHtmlViewerContainer::IsMessageBodyURLL(const TDesC& aUrl) |
1792 TBool CFsEmailUiHtmlViewerContainer::IsMessageBodyURLL(const TDesC& aUrl) |
1845 { |
1793 { |
1846 TInt index = aUrl.Find(KURLSchemeSeparator); |
1794 TInt index = aUrl.Find(KURLSchemeSeparator); |
1946 { |
1894 { |
1947 TBool launchBrowser( ETrue ); |
1895 TBool launchBrowser( ETrue ); |
1948 // look for file:/// |
1896 // look for file:/// |
1949 _LIT( KFileLink, "file:///"); |
1897 _LIT( KFileLink, "file:///"); |
1950 _LIT( KUrlLink, "http"); |
1898 _LIT( KUrlLink, "http"); |
1951 |
1899 |
1952 // This might be linking to header.html or body.html frames |
1900 // This might be linking to header.html or body.html frames |
1953 // Ignore them. |
1901 // Ignore them. |
1954 if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 ) |
1902 if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 ) |
1955 { |
1903 { |
1956 //Now there is a chance that this could be from HTML folder |
1904 //Now there is a chance that this could be from HTML folder |
1957 // Replace all slash character with backslash characters |
1905 // Replace all slash character with backslash characters |
1958 HBufC* embeddedUrl = aUrl.AllocLC(); |
1906 HBufC* embeddedUrl = aUrl.AllocLC(); |
1959 TPtr ptr = embeddedUrl->Des(); |
1907 TPtr ptr = embeddedUrl->Des(); |
1960 |
1908 |
1961 _LIT( KBackslash, "\\" ); |
1909 _LIT( KBackslash, "\\" ); |
1962 for ( TInt pos = ptr.Locate('/'); pos >= 0; pos = ptr.Locate('/') ) |
1910 for ( TInt pos = ptr.Locate('/'); pos >= 0; pos = ptr.Locate('/') ) |
1963 { |
1911 { |
1964 ptr.Replace( pos, 1, KBackslash ); |
1912 ptr.Replace( pos, 1, KBackslash ); |
1965 } |
1913 } |
1966 |
1914 |
1967 // Check whether given url refers to file in the html folder |
1915 // Check whether given url refers to file in the html folder |
1968 TInt pos = embeddedUrl->FindF( iHtmlFolderPath ); |
1916 TInt pos = embeddedUrl->FindF( iHtmlFolderPath ); |
1969 CleanupStack::PopAndDestroy( embeddedUrl ); |
1917 CleanupStack::PopAndDestroy( embeddedUrl ); |
1970 pos >= 0 ? launchBrowser = EFalse : ETrue; |
1918 pos >= 0 ? launchBrowser = EFalse : ETrue; |
1971 } |
1919 } |
1972 // Ignore links starting with cmail:// |
1920 // Ignore links starting with cmail:// |
1973 else if ( aUrl.Left( KURLSchemeCmail().Length() ).CompareF( KURLSchemeCmail ) == 0 ) |
1921 else if ( aUrl.Left( KURLSchemeCmail().Length() ).CompareF( KURLSchemeCmail ) == 0 ) |
1974 { |
1922 { |
1975 launchBrowser = EFalse; |
1923 launchBrowser = EFalse; |
1976 } |
1924 } |
1977 // THAA-82BEAZ - show popup first |
1925 // THAA-82BEAZ - show popup first |
1978 else if ( aUrl.Left(KUrlLink().Length() ).CompareF( KUrlLink ) == 0 ) |
1926 else if ( aUrl.Left(KUrlLink().Length() ).CompareF( KUrlLink ) == 0 ) |
1979 { |
1927 { |
1980 launchBrowser = EFalse; |
1928 launchBrowser = EFalse; |
1981 } |
1929 } |
1982 // end THAA-82BEAZ |
1930 // end THAA-82BEAZ |
2063 { |
2011 { |
2064 FUNC_LOG; |
2012 FUNC_LOG; |
2065 UpdateOverlayButtons( IsVisible() ); |
2013 UpdateOverlayButtons( IsVisible() ); |
2066 } |
2014 } |
2067 |
2015 |
|
2016 |
|
2017 void CFsEmailUiHtmlViewerContainer::WriteToFileL(const TDesC& aFileName, RBuf& aHtmlText) |
|
2018 { |
|
2019 _LIT( KCharsetUtf8, "UTF-8" ); |
|
2020 |
|
2021 HBufC8* content8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aHtmlText ); |
|
2022 CleanupStack::PushL( content8 ); |
|
2023 |
|
2024 RFile targetFile; |
|
2025 CleanupClosePushL( targetFile ); |
|
2026 User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); |
|
2027 |
|
2028 RBuf8 messageHeader; |
|
2029 TInt bufSize = KHtmlHeader1().Length() + KCharsetUtf8().Length() + KHtmlHeader2().Length(); |
|
2030 messageHeader.CreateL( bufSize ); |
|
2031 messageHeader.CleanupClosePushL(); |
|
2032 |
|
2033 messageHeader.Append( KHtmlHeader1 ); |
|
2034 messageHeader.Append( KCharsetUtf8 ); |
|
2035 messageHeader.Append( KHtmlHeader2 ); |
|
2036 |
|
2037 RFileWriteStream fileStream( targetFile ); |
|
2038 fileStream.PushL(); |
|
2039 fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() ); |
|
2040 |
|
2041 TInt bufPos( 0 ); |
|
2042 TInt bufTotalSize = content8->Size(); |
|
2043 |
|
2044 while ( bufPos < bufTotalSize ) |
|
2045 { |
|
2046 TInt segmentLength = content8->Mid( bufPos ).Length(); |
|
2047 fileStream.WriteL( content8->Mid( bufPos ).Ptr(), segmentLength ); |
|
2048 bufPos += segmentLength; |
|
2049 } |
|
2050 |
|
2051 fileStream.CommitL(); |
|
2052 |
|
2053 CleanupStack::PopAndDestroy( &fileStream ); |
|
2054 CleanupStack::PopAndDestroy( &messageHeader ); |
|
2055 CleanupStack::PopAndDestroy( &targetFile ); |
|
2056 CleanupStack::PopAndDestroy( content8 ); |
|
2057 } |
|
2058 |
|
2059 |
|
2060 |
|
2061 /****************************************************************************** |
|
2062 * class PlainTextToHtmlConverter |
|
2063 ******************************************************************************/ |
|
2064 |
|
2065 |
|
2066 |
|
2067 // ----------------------------------------------------------------------------- |
|
2068 // PlainTextToHtmlConverter::PlainTextToHtmlL |
|
2069 // |
|
2070 // ----------------------------------------------------------------------------- |
|
2071 // |
|
2072 void PlainTextToHtmlConverter::PlainTextToHtmlL(const TDesC& aPlainText, RBuf& aHtmlText) |
|
2073 { |
|
2074 const TInt KAllocSize = 1024; |
|
2075 |
|
2076 aHtmlText.Close(); |
|
2077 aHtmlText.Create( aPlainText.Length() + KAllocSize ); |
|
2078 |
|
2079 const TInt searhCases( CFindItemEngine::EFindItemSearchURLBin ); |
|
2080 CFindItemEngine* itemEngine = CFindItemEngine::NewL( aPlainText, CFindItemEngine::TFindItemSearchCase( searhCases ) ); |
|
2081 CleanupStack::PushL ( itemEngine ); |
|
2082 |
|
2083 TInt currentPos = 0; |
|
2084 CFindItemEngine::SFoundItem item; |
|
2085 for ( TBool available(itemEngine->Item(item)); available; available=itemEngine->NextItem(item) ) |
|
2086 { |
|
2087 if ( item.iStartPos < currentPos ) |
|
2088 { |
|
2089 break; |
|
2090 } |
|
2091 |
|
2092 TPtrC textPtr = aPlainText.Mid( currentPos, item.iStartPos-currentPos ); |
|
2093 ConvertTextL( textPtr, aHtmlText ); |
|
2094 |
|
2095 TPtrC urlPtr = aPlainText.Mid( item.iStartPos, item.iLength ); |
|
2096 ConvertUrlL( urlPtr, aHtmlText); |
|
2097 |
|
2098 currentPos = item.iStartPos + item.iLength; |
|
2099 } |
|
2100 |
|
2101 TInt len = aPlainText.Length(); |
|
2102 if ( currentPos < len ) |
|
2103 { |
|
2104 TPtrC textPtr = aPlainText.Mid( currentPos ); |
|
2105 ConvertTextL( textPtr, aHtmlText ); |
|
2106 } |
|
2107 |
|
2108 CleanupStack::PopAndDestroy( itemEngine ); |
|
2109 } |
|
2110 |
|
2111 |
|
2112 // ----------------------------------------------------------------------------- |
|
2113 // PlainTextToHtmlConverter::ConvertTextL |
|
2114 // |
|
2115 // ----------------------------------------------------------------------------- |
|
2116 // |
|
2117 void PlainTextToHtmlConverter::ConvertTextL(const TDesC& aSource, RBuf& aTarget) |
|
2118 { |
|
2119 const TInt KAllocSize = 1024; |
|
2120 const TInt KEntitySize = 32; |
|
2121 |
|
2122 TInt count = aSource.Length(); |
|
2123 for ( TInt i=0; i<count; i++ ) |
|
2124 { |
|
2125 if ( aTarget.Length() + KEntitySize >= aTarget.MaxLength() ) |
|
2126 { |
|
2127 aTarget.ReAllocL( aTarget.MaxLength() + KAllocSize ); |
|
2128 } |
|
2129 |
|
2130 TText ch = aSource[i]; |
|
2131 switch( ch ) |
|
2132 { |
|
2133 case KSOH: // end of line for IMAP and POP |
|
2134 aTarget.Append( KHtmlLineBreakCRLF ); |
|
2135 break; |
|
2136 case KLF: // line feed |
|
2137 case KUnicodeNewLineCharacter: |
|
2138 case KUnicodeParagraphCharacter: |
|
2139 aTarget.Append(KHtmlLineBreak); |
|
2140 break; |
|
2141 case KQuotation: |
|
2142 aTarget.Append( KHtmlQuotation ); |
|
2143 break; |
|
2144 case KAmpersand: |
|
2145 aTarget.Append( KHtmlAmpersand ); |
|
2146 break; |
|
2147 case KGreaterThan: |
|
2148 aTarget.Append( KHtmlGreaterThan ); |
|
2149 break; |
|
2150 case KLessThan: |
|
2151 aTarget.Append( KHtmlLessThan ); |
|
2152 break; |
|
2153 default: |
|
2154 aTarget.Append( ch ); |
|
2155 break; |
|
2156 } |
|
2157 } |
|
2158 } |
|
2159 |
|
2160 |
|
2161 // ----------------------------------------------------------------------------- |
|
2162 // PlainTextToHtmlConverter::ConvertUrlL |
|
2163 // |
|
2164 // ----------------------------------------------------------------------------- |
|
2165 // |
|
2166 void PlainTextToHtmlConverter::ConvertUrlL(const TDesC& aSource, RBuf& aTarget) |
|
2167 { |
|
2168 _LIT( KSchemeDelimiter, "://" ); |
|
2169 _LIT( KUrlFormat, "<a href=\"%S\">%S</a>" ); |
|
2170 _LIT( KUrlFormatWithHttp, "<a href=\"http://%S\">%S</a>" ); |
|
2171 |
|
2172 TPtrC format( KUrlFormat() ); |
|
2173 if ( aSource.FindF( KSchemeDelimiter() ) == KErrNotFound ) |
|
2174 { |
|
2175 format.Set( KUrlFormatWithHttp() ); |
|
2176 } |
|
2177 |
|
2178 HBufC* formatBuffer = HBufC::NewLC( format.Length() + aSource.Length() * 2 ); |
|
2179 formatBuffer->Des().Format( format, &aSource, &aSource ); |
|
2180 |
|
2181 TInt len = formatBuffer->Des().Length(); |
|
2182 if ( aTarget.Length() + len >= aTarget.MaxLength() ) |
|
2183 { |
|
2184 aTarget.ReAllocL( aTarget.MaxLength() + len ); |
|
2185 } |
|
2186 |
|
2187 aTarget.Append( *formatBuffer ); |
|
2188 |
|
2189 CleanupStack::PopAndDestroy( formatBuffer ); |
|
2190 } |