author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:48:24 +0300 | |
branch | RCL_3 |
changeset 26 | 968773a0b6ef |
parent 25 | 3533d4323edc |
permissions | -rw-r--r-- |
25 | 1 |
/* |
2 |
* Copyright (c) 2007 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: CFsEmailUiHtmlViewerContainer class implementation |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "emailtrace.h" |
|
20 |
#include <AknsDrawUtils.h> |
|
21 |
#include <coemain.h> |
|
22 |
#include <commdbconnpref.h> |
|
23 |
#include <bautils.h> |
|
24 |
#include <biditext.h> |
|
25 |
#include <StringLoader.h> |
|
26 |
#include <e32base.h> |
|
27 |
#include <badesca.h> |
|
28 |
#include <utf.h> |
|
29 |
#include <finditemengine.h> |
|
30 |
||
31 |
//<cmail> |
|
32 |
#include "cfsmailmessage.h" |
|
33 |
//</cmail> |
|
34 |
#include <brctlinterface.h> |
|
35 |
#include <sysutil.h> |
|
36 |
#include <schemehandler.h> |
|
37 |
||
38 |
#include <FreestyleEmailUi.rsg> |
|
39 |
||
40 |
#include "FreestyleEmailUiAppui.h" |
|
41 |
#include "FreestyleEmailUiUtilities.h" |
|
42 |
#include "FreestyleEmailUiHtmlViewerContainer.h" |
|
43 |
#include "FreestyleEmailUiHtmlViewerView.h" |
|
44 |
#include "FreestyleEmailUiShortcutBinding.h" |
|
45 |
||
46 |
#include "FreestyleMessageHeaderHTML.h" |
|
47 |
#include "FreestyleMessageHeaderURLEventHandler.h" |
|
48 |
#include "FreestyleEmailUiAttachmentsListModel.h" |
|
49 |
||
50 |
_LIT( KContentIdPrefix, "cid:" ); |
|
51 |
_LIT( KCDrive, "c:" ); |
|
52 |
_LIT( KHtmlPath, "HtmlFile\\" ); |
|
53 |
_LIT( KTempHtmlPath, "temp\\" ); |
|
54 |
_LIT( KAllFiles, "*" ); |
|
55 |
||
56 |
_LIT( KHeaderHtmlFile, "header.html" ); |
|
57 |
_LIT( KBodyHtmlFile, "body.html" ); |
|
58 |
_LIT( KMessageHtmlFile, "email.html" ); |
|
59 |
_LIT( KMessageHtmlRTLFile, "email_rtl.html" ); |
|
60 |
_LIT( KZDrive, "z:" ); |
|
61 |
_LIT( KHtmlFlagFile, "html.flag" ); |
|
62 |
_LIT( KURLSlash, "/"); |
|
63 |
// Constants used in html content modification |
|
64 |
const TInt KMaxCharsToSearch( 200 ); |
|
65 |
_LIT8( KStartTag, "<html" ); |
|
66 |
_LIT8( KHeadTag, "<head>"); |
|
67 |
_LIT8( KHtmlHeader1, "<html><head><title></title><meta http-equiv=\"Content-Type\" content=\"text/html; charset="); |
|
68 |
_LIT8( KHtmlHeader2, "\"/></head><body bgcolor=\"#ECECEC\">\xD\xA"); |
|
69 |
_LIT8( KHtmlHeader3, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%S\">\n"); |
|
70 |
_LIT8( KHtmlEndTags, "\xD\xA</body></html>\xD\xA"); |
|
71 |
_LIT8( KCharsetTag8, "charset"); |
|
72 |
_LIT( KCharsetTag, "charset"); |
|
73 |
_LIT8( KHTMLEmptyContent, "<html><body></body></html>"); |
|
74 |
_LIT( KHTMLDataScheme, "data:0"); |
|
75 |
||
76 |
||
77 |
_LIT( KHtmlLineBreak, "<br>" ); |
|
78 |
_LIT( KHtmlLineBreakCRLF, "<br>\xD\xA" ); |
|
79 |
_LIT( KHtmlLessThan, "<" ); |
|
80 |
_LIT( KHtmlGreaterThan, ">" ); |
|
81 |
_LIT( KHtmlAmpersand, "&" ); |
|
82 |
_LIT( KHtmlQuotation, """ ); |
|
83 |
_LIT( KURLTypeBody, "body"); |
|
84 |
||
85 |
_LIT( KURLDisplayImages, "cmail://displayImages/" ); |
|
86 |
_LIT( KURLLoadImages, "cmail://loadImages/" ); |
|
87 |
_LIT( KURLCollapseHeader, "cmail://collapseHeader/" ); |
|
88 |
_LIT( KURLExpandHeader, "cmail://expandHeader/" ); |
|
89 |
_LIT( KURLExpandItem, "cmail://expand_" ); |
|
90 |
_LIT( KURLItemTo, "to" ); |
|
91 |
_LIT( KURLItemCc, "cc" ); |
|
92 |
_LIT( KURLItemBcc, "bcc" ); |
|
93 |
_LIT( KURLItemAttachments, "attachments" ); |
|
94 |
||
95 |
const TText KGreaterThan = 0x3e; |
|
96 |
const TText KLessThan = 0x3c; |
|
97 |
const TText KAmpersand = 0x26; |
|
98 |
const TText KQuotation = 0x22; |
|
99 |
const TText KSOH = 0x01; // Start Of Heading |
|
100 |
const TText KLF = 0x0a; // Line Feed |
|
101 |
const TText KUnicodeNewLineCharacter = 0x2028; |
|
102 |
const TText KUnicodeParagraphCharacter = 0x2029; |
|
103 |
const TReal KOverlayButtonMarginX = 0.01; // 1% |
|
104 |
const TReal KOverlayButtonMarginY = 0.01; // 1% |
|
105 |
const TReal KOverlayButtonSizeP = 0.15; // 15% |
|
106 |
const TReal KOverlayButtonSizeLs = 0.20; // 25% |
|
107 |
||
108 |
||
109 |
const TInt KStatusIndicatorHeight = 55; |
|
110 |
const TInt KStatusIndicatorXMargin = 58; |
|
111 |
const TInt KStatusIndicatorBottomMargin = 6; |
|
112 |
||
113 |
// CONSTANTS |
|
114 |
// Zoom levels available on the UI |
|
115 |
const TInt KZoomLevels[] = { 75, 100, 125, 150 }; |
|
116 |
const TInt KZoomLevelCount = sizeof( KZoomLevels ) / sizeof( TInt ); |
|
117 |
const TInt KZoomLevelIndex100 = 1; // 100 in array KZoomLevels |
|
118 |
||
119 |
// CEUiHtmlViewerSettingsKeyListener |
|
120 |
||
121 |
// --------------------------------------------------------------------------- |
|
122 |
// |
|
123 |
// --------------------------------------------------------------------------- |
|
124 |
// |
|
125 |
CEUiHtmlViewerSettingsKeyListener::CEUiHtmlViewerSettingsKeyListener( MObserver& aObserver, TUint32 aKey ) |
|
126 |
: CActive( EPriorityStandard ), iObserver( aObserver ), iKey( aKey ) |
|
127 |
{ |
|
128 |
CActiveScheduler::Add(this); |
|
129 |
StartListening(); |
|
130 |
} |
|
131 |
||
132 |
// --------------------------------------------------------------------------- |
|
133 |
// |
|
134 |
// --------------------------------------------------------------------------- |
|
135 |
// |
|
136 |
CEUiHtmlViewerSettingsKeyListener::~CEUiHtmlViewerSettingsKeyListener() |
|
137 |
{ |
|
138 |
Cancel(); |
|
139 |
} |
|
140 |
||
141 |
// --------------------------------------------------------------------------- |
|
142 |
// |
|
143 |
// --------------------------------------------------------------------------- |
|
144 |
// |
|
145 |
void CEUiHtmlViewerSettingsKeyListener::StartListening() |
|
146 |
{ |
|
147 |
SetActive(); |
|
148 |
iObserver.Repository().NotifyRequest(iKey, iStatus); |
|
149 |
} |
|
150 |
||
151 |
// --------------------------------------------------------------------------- |
|
152 |
// |
|
153 |
// --------------------------------------------------------------------------- |
|
154 |
// |
|
155 |
void CEUiHtmlViewerSettingsKeyListener::RunL() |
|
156 |
{ |
|
157 |
iObserver.KeyValueChangedL(iKey); |
|
158 |
StartListening(); |
|
159 |
} |
|
160 |
||
161 |
// --------------------------------------------------------------------------- |
|
162 |
// |
|
163 |
// --------------------------------------------------------------------------- |
|
164 |
// |
|
165 |
void CEUiHtmlViewerSettingsKeyListener::DoCancel() |
|
166 |
{ |
|
167 |
iObserver.Repository().NotifyCancel(iKey); |
|
168 |
} |
|
169 |
||
170 |
// CEUiHtmlViewerSettings |
|
171 |
||
172 |
// --------------------------------------------------------------------------- |
|
173 |
// |
|
174 |
// --------------------------------------------------------------------------- |
|
175 |
// |
|
176 |
CEUiHtmlViewerSettings* CEUiHtmlViewerSettings::NewL( MObserver& aObserver ) |
|
177 |
{ |
|
178 |
CEUiHtmlViewerSettings* self = new (ELeave) CEUiHtmlViewerSettings(aObserver); |
|
179 |
CleanupStack::PushL( self ); |
|
180 |
self->ConstructL(); |
|
181 |
CleanupStack::Pop( self ); |
|
182 |
return self; |
|
183 |
} |
|
184 |
||
185 |
// --------------------------------------------------------------------------- |
|
186 |
// |
|
187 |
// --------------------------------------------------------------------------- |
|
188 |
// |
|
189 |
CEUiHtmlViewerSettings::~CEUiHtmlViewerSettings() |
|
190 |
{ |
|
191 |
iKeyListeners.ResetAndDestroy(); |
|
192 |
delete iRepository; |
|
193 |
} |
|
194 |
||
195 |
// --------------------------------------------------------------------------- |
|
196 |
// |
|
197 |
// --------------------------------------------------------------------------- |
|
198 |
// |
|
199 |
CEUiHtmlViewerSettings::CEUiHtmlViewerSettings( MObserver& aObserver ) : iObserver( aObserver ) |
|
200 |
{ |
|
201 |
} |
|
202 |
||
203 |
// --------------------------------------------------------------------------- |
|
204 |
// |
|
205 |
// --------------------------------------------------------------------------- |
|
206 |
// |
|
207 |
void CEUiHtmlViewerSettings::ConstructL() |
|
208 |
{ |
|
209 |
iRepository = CRepository::NewL(KFreestyleEmailCenRep); |
|
210 |
AddKeyListenerL(KFreestyleEmailDownloadHTMLImages); |
|
211 |
} |
|
212 |
||
213 |
// --------------------------------------------------------------------------- |
|
214 |
// |
|
215 |
// --------------------------------------------------------------------------- |
|
216 |
// |
|
217 |
void CEUiHtmlViewerSettings::AddKeyListenerL( TUint32 aKey ) |
|
218 |
{ |
|
219 |
CEUiHtmlViewerSettingsKeyListener* listener = |
|
220 |
new (ELeave) CEUiHtmlViewerSettingsKeyListener( *this, aKey ); |
|
221 |
CleanupStack::PushL( listener ); |
|
222 |
iKeyListeners.AppendL( listener ); |
|
223 |
CleanupStack::Pop( listener ); |
|
224 |
UpdateValue( aKey ); |
|
225 |
} |
|
226 |
||
227 |
// --------------------------------------------------------------------------- |
|
228 |
// |
|
229 |
// --------------------------------------------------------------------------- |
|
230 |
// |
|
231 |
void CEUiHtmlViewerSettings::UpdateValue( TUint32 aKey ) |
|
232 |
{ |
|
233 |
TInt value; |
|
234 |
iRepository->Get(aKey, value); |
|
235 |
switch (aKey) |
|
236 |
{ |
|
237 |
case KFreestyleEmailDownloadHTMLImages: |
|
238 |
// 0 = automatic, 1 = ask always |
|
239 |
iFlags.Assign(aKey, value == 0); |
|
240 |
break; |
|
241 |
default: |
|
242 |
iFlags.Assign(aKey, value); |
|
243 |
break; |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
// --------------------------------------------------------------------------- |
|
248 |
// |
|
249 |
// --------------------------------------------------------------------------- |
|
250 |
// |
|
251 |
void CEUiHtmlViewerSettings::KeyValueChangedL( TUint32 aKey ) |
|
252 |
{ |
|
253 |
UpdateValue(aKey); |
|
254 |
iObserver.ViewerSettingsChangedL(aKey); |
|
255 |
} |
|
256 |
||
257 |
// --------------------------------------------------------------------------- |
|
258 |
// |
|
259 |
// --------------------------------------------------------------------------- |
|
260 |
// |
|
261 |
CRepository& CEUiHtmlViewerSettings::Repository() |
|
262 |
{ |
|
263 |
return *iRepository; |
|
264 |
} |
|
265 |
||
266 |
// --------------------------------------------------------------------------- |
|
267 |
// |
|
268 |
// --------------------------------------------------------------------------- |
|
269 |
// |
|
270 |
TBool CEUiHtmlViewerSettings::AutoLoadImages() const |
|
271 |
{ |
|
272 |
return iFlags.IsSet(EAutoLoadImages); |
|
273 |
} |
|
274 |
||
275 |
// --------------------------------------------------------------------------- |
|
276 |
// Two-phased constructor. |
|
277 |
// --------------------------------------------------------------------------- |
|
278 |
// |
|
279 |
CFsEmailUiHtmlViewerContainer* CFsEmailUiHtmlViewerContainer::NewL( |
|
280 |
CFreestyleEmailUiAppUi& aAppUi, CFsEmailUiHtmlViewerView& aView ) |
|
281 |
{ |
|
282 |
FUNC_LOG; |
|
283 |
CFsEmailUiHtmlViewerContainer* self = |
|
284 |
new (ELeave) CFsEmailUiHtmlViewerContainer( aAppUi, aView ); |
|
285 |
CleanupStack::PushL( self ); |
|
286 |
self->ConstructL(); |
|
287 |
CleanupStack::Pop( self ); |
|
288 |
return self; |
|
289 |
} |
|
290 |
||
291 |
// --------------------------------------------------------------------------- |
|
292 |
// C++ constructor. |
|
293 |
// --------------------------------------------------------------------------- |
|
294 |
// |
|
295 |
CFsEmailUiHtmlViewerContainer::CFsEmailUiHtmlViewerContainer( |
|
296 |
CFreestyleEmailUiAppUi& aAppUi, CFsEmailUiHtmlViewerView& aView ) |
|
297 |
: |
|
298 |
iAppUi( aAppUi ), |
|
299 |
iView( aView ), |
|
300 |
iFs( iCoeEnv->FsSession() ), |
|
301 |
iFirstTime( ETrue ), |
|
302 |
iZoomLevel( KZoomLevelIndex100 ) |
|
303 |
{ |
|
304 |
FUNC_LOG; |
|
305 |
} |
|
306 |
||
307 |
// --------------------------------------------------------------------------- |
|
308 |
// Destructor. |
|
309 |
// --------------------------------------------------------------------------- |
|
310 |
// |
|
311 |
CFsEmailUiHtmlViewerContainer::~CFsEmailUiHtmlViewerContainer() |
|
312 |
{ |
|
313 |
FUNC_LOG; |
|
314 |
delete iViewerSettings; |
|
315 |
if ( iObservingDownload && iAppUi.DownloadInfoMediator() ) |
|
316 |
{ |
|
317 |
iAppUi.DownloadInfoMediator()->StopObserving( this ); |
|
318 |
} |
|
319 |
iFile.Close(); |
|
320 |
iLinkContents.Close(); |
|
321 |
iMessageParts.Close(); |
|
322 |
delete iEventHandler; |
|
323 |
delete iBrCtlInterface; |
|
324 |
iConnection.Close(); |
|
325 |
iSocketServer.Close(); |
|
326 |
delete iStatusIndicator; |
|
327 |
delete iOverlayControlNext; |
|
328 |
delete iOverlayControlPrev; |
|
329 |
} |
|
330 |
||
331 |
void CFsEmailUiHtmlViewerContainer::PrepareForExit() |
|
332 |
{ |
|
333 |
FUNC_LOG; |
|
334 |
HideDownloadStatus(); |
|
335 |
if ( iObservingDownload && iAppUi.DownloadInfoMediator() ) |
|
336 |
{ |
|
337 |
iAppUi.DownloadInfoMediator()->StopObserving( this ); |
|
338 |
iObservingDownload = EFalse; |
|
339 |
} |
|
340 |
delete iBrCtlInterface; |
|
341 |
iBrCtlInterface = NULL; |
|
342 |
iConnection.Close(); |
|
343 |
iSocketServer.Close(); |
|
344 |
} |
|
345 |
||
346 |
void CFsEmailUiHtmlViewerContainer::PrepareForMessageNavigation() |
|
347 |
{ |
|
348 |
FUNC_LOG; |
|
349 |
ResetContent(); |
|
350 |
} |
|
351 |
||
352 |
void CFsEmailUiHtmlViewerContainer::ZoomInL() |
|
353 |
{ |
|
354 |
SetZoomLevelL( ZoomLevelL() + 1 ); |
|
355 |
} |
|
356 |
||
357 |
void CFsEmailUiHtmlViewerContainer::ZoomOutL() |
|
358 |
{ |
|
359 |
SetZoomLevelL( ZoomLevelL() - 1 ); |
|
360 |
} |
|
361 |
||
362 |
TInt CFsEmailUiHtmlViewerContainer::ZoomLevelL() const |
|
363 |
{ |
|
364 |
FUNC_LOG; |
|
365 |
TInt zoomLevelIdx = iBrCtlInterface->BrowserSettingL( |
|
366 |
TBrCtlDefs::ESettingsCurrentZoomLevelIndex ); |
|
367 |
||
368 |
// Behaviour of zooming in Browser Control Interface is different in version 7.1 |
|
369 |
// than in previous versions and we need to support both. In older versions there |
|
370 |
// are 4 preset zoom levels while version 7.1 can zoom to any percent. |
|
371 |
RArray<TUint>* zoomLevels = iBrCtlInterface->ZoomLevels(); |
|
372 |
||
373 |
if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] ) |
|
374 |
{ |
|
375 |
// new browser: |
|
376 |
// BrowserControlIf gives zoom level percentage insted of index to array |
|
377 |
TBool found = EFalse; |
|
378 |
||
379 |
for ( TInt i = 0 ; i < KZoomLevelCount && !found ; ++i ) |
|
380 |
{ |
|
381 |
if ( zoomLevelIdx == KZoomLevels[i] ) |
|
382 |
{ |
|
383 |
zoomLevelIdx = i; |
|
384 |
found = ETrue; |
|
385 |
} |
|
386 |
} |
|
387 |
||
388 |
if ( !found ) |
|
389 |
{ |
|
390 |
zoomLevelIdx = KErrNotFound; |
|
391 |
} |
|
392 |
} |
|
393 |
return zoomLevelIdx; |
|
394 |
} |
|
395 |
||
396 |
void CFsEmailUiHtmlViewerContainer::SetZoomLevelL( const TInt aZoomLevel ) |
|
397 |
{ |
|
398 |
FUNC_LOG; |
|
399 |
TInt newValue = KMinTInt; |
|
400 |
||
401 |
// Behaviour of zooming in Browser Control Interface is different in version 7.1 |
|
402 |
// than in previous versions and we need to support both. In older versions there |
|
403 |
// are 4 preset zoom levels while version 7.1 can zoom to any percent. |
|
404 |
RArray<TUint>* zoomLevels = iBrCtlInterface->ZoomLevels(); |
|
405 |
||
406 |
if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] ) |
|
407 |
{ |
|
408 |
// new browser: |
|
409 |
// BrowserControlIf takes zoom level percentage insted of index to array |
|
410 |
if ( aZoomLevel >= 0 && aZoomLevel < KZoomLevelCount ) |
|
411 |
{ |
|
412 |
newValue = KZoomLevels[aZoomLevel]; |
|
413 |
} |
|
414 |
} |
|
415 |
else |
|
416 |
{ |
|
417 |
// old browser |
|
418 |
newValue = aZoomLevel; |
|
419 |
} |
|
420 |
||
421 |
iZoomLevel = ( newValue > KMinTInt ) ? newValue : aZoomLevel; |
|
422 |
iBrCtlInterface->SetBrowserSettingL( |
|
423 |
TBrCtlDefs::ESettingsCurrentZoomLevelIndex, iZoomLevel ); |
|
424 |
} |
|
425 |
||
426 |
TInt CFsEmailUiHtmlViewerContainer::DoZoom( TAny* aPtr ) |
|
427 |
{ |
|
428 |
TRAPD( error, reinterpret_cast<CFsEmailUiHtmlViewerContainer*>( aPtr )->DoZoomL() ); |
|
429 |
return error; |
|
430 |
} |
|
431 |
||
432 |
void CFsEmailUiHtmlViewerContainer::DoZoomL() |
|
433 |
{ |
|
434 |
iBrCtlInterface->SetBrowserSettingL( |
|
435 |
TBrCtlDefs::ESettingsCurrentZoomLevelIndex, iZoomLevel ); |
|
436 |
} |
|
437 |
||
438 |
TInt CFsEmailUiHtmlViewerContainer::MaxZoomLevel() const |
|
439 |
{ |
|
440 |
return KZoomLevelCount; |
|
441 |
} |
|
442 |
||
443 |
||
444 |
void CFsEmailUiHtmlViewerContainer::CreateBrowserControlInterfaceL() |
|
445 |
{ |
|
446 |
FUNC_LOG; |
|
447 |
||
448 |
if ( iBrCtlInterface ) |
|
449 |
{ |
|
450 |
SetZoomLevelL(100); |
|
451 |
iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() ); |
|
452 |
return; |
|
453 |
} |
|
454 |
||
455 |
TUint brCtlCapabilities = TBrCtlDefs::ECapabilityClientResolveEmbeddedURL | |
|
456 |
TBrCtlDefs::ECapabilityDisplayScrollBar | |
|
457 |
TBrCtlDefs::ECapabilityClientNotifyURL | |
|
458 |
TBrCtlDefs::ECapabilityLoadHttpFw | |
|
459 |
TBrCtlDefs::ECapabilityCursorNavigation | |
|
460 |
TBrCtlDefs::ECapabilityPinchZoom | |
|
461 |
TBrCtlDefs::ECapabilityFitToScreen; |
|
462 |
||
463 |
// Set browsercontrol to whole screen |
|
464 |
TRect rect( TPoint(), Size() ); |
|
465 |
||
466 |
iBrCtlInterface = CreateBrowserControlL( |
|
467 |
this, // aParent |
|
468 |
rect, // aRect |
|
469 |
brCtlCapabilities, // aBrCtlCapabilities |
|
470 |
TBrCtlDefs::ECommandIdBase, // aCommandIdBase |
|
471 |
NULL, // aBrCtlSoftkeysObserver |
|
472 |
this, // aBrCtlLinkResolver |
|
473 |
this, // aBrCtlSpecialLoadObserver |
|
474 |
NULL, // aBrCtlLayoutObserver |
|
475 |
NULL, // aBrCtlDialogsProvider |
|
476 |
this, // aBrCtlWindowObserver |
|
477 |
NULL // aBrCtlDownloadObserver |
|
478 |
); |
|
479 |
||
480 |
iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsEmbedded, ETrue ); |
|
481 |
iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() ); |
|
482 |
iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsPageOverview, EFalse ); |
|
483 |
iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsTextWrapEnabled, ETrue ); |
|
484 |
iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsFontSize, TBrCtlDefs::EFontSizeLevelLarger ); |
|
485 |
} |
|
486 |
||
487 |
void CFsEmailUiHtmlViewerContainer::ConstructL() |
|
488 |
{ |
|
489 |
FUNC_LOG; |
|
490 |
iViewerSettings = CEUiHtmlViewerSettings::NewL(*this); |
|
491 |
||
492 |
SetHtmlFolderPathL(); |
|
493 |
BaflUtils::EnsurePathExistsL( iFs, iHtmlFolderPath ); |
|
494 |
SetTempHtmlFolderPath(); |
|
495 |
BaflUtils::EnsurePathExistsL( iFs, iTempHtmlFolderPath ); |
|
496 |
SetHTMLResourceFlagFullName(); |
|
497 |
EnsureHTMLResourceL(); |
|
498 |
||
499 |
CreateWindowL(); |
|
500 |
||
501 |
#if defined( BRDO_MULTITOUCH_ENABLED_FF ) && !defined ( __WINSCW__ ) |
|
502 |
//Enable advance pointer info for multi-touch. |
|
503 |
Window().EnableAdvancedPointers(); |
|
504 |
#endif |
|
505 |
||
506 |
||
507 |
iEventHandler = CFreestyleMessageHeaderURLEventHandler::NewL( iAppUi, iView ); |
|
508 |
||
509 |
TRect nextButtonRect = OverlayButtonRect( EFalse ); |
|
510 |
iOverlayControlNext = COverlayControl::NewL( this, this, nextButtonRect, |
|
511 |
EMbmFreestyleemailuiQgn_indi_cmail_arrow_next, |
|
512 |
EMbmFreestyleemailuiQgn_indi_cmail_arrow_next_mask ); |
|
513 |
||
514 |
TRect prevButtonRect = OverlayButtonRect( ETrue ); |
|
515 |
iOverlayControlPrev = COverlayControl::NewL( this, this, prevButtonRect, |
|
516 |
EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous, |
|
517 |
EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous_mask ); |
|
518 |
iScrollPosition = 0; |
|
519 |
iAttachmentDownloadImageHandle = 0; |
|
520 |
||
521 |
iTouchFeedBack = MTouchFeedback::Instance(); |
|
522 |
iTouchFeedBack->EnableFeedbackForControl(this, ETrue); |
|
523 |
||
524 |
CreateBrowserControlInterfaceL(); |
|
525 |
SetRect( iView.ContainerRect() ); |
|
526 |
||
527 |
ActivateL(); |
|
528 |
} |
|
529 |
||
530 |
void CFsEmailUiHtmlViewerContainer::MakeVisible( TBool aVisible ) |
|
531 |
{ |
|
532 |
UpdateOverlayButtons( aVisible ); |
|
533 |
CCoeControl::MakeVisible( aVisible ); |
|
534 |
} |
|
535 |
||
536 |
void CFsEmailUiHtmlViewerContainer::HandleOverlayPointerEventL( COverlayControl* aControl, |
|
537 |
const TPointerEvent& aEvent ) |
|
538 |
{ |
|
539 |
if( aEvent.iType == TPointerEvent::EButton1Up ) |
|
540 |
{ |
|
541 |
if( aControl == iOverlayControlNext ) |
|
542 |
{ |
|
543 |
iView.HandleCommandL( EFsEmailUiCmdNextMessage ); |
|
544 |
} |
|
545 |
else if( aControl == iOverlayControlPrev ) |
|
546 |
{ |
|
547 |
iView.HandleCommandL( EFsEmailUiCmdPreviousMessage ); |
|
548 |
} |
|
549 |
} |
|
550 |
} |
|
551 |
||
552 |
void CFsEmailUiHtmlViewerContainer::UpdateOverlayButtons( TBool aVisible ) |
|
553 |
{ |
|
554 |
TBool nextAvailable = EFalse; |
|
555 |
TBool prevAvailable = EFalse; |
|
556 |
if( iMessage ) |
|
557 |
{ |
|
558 |
TFSMailMsgId currentMsgId = iMessage->GetMessageId(); |
|
559 |
TFSMailMsgId tmpMsgId; |
|
560 |
TFSMailMsgId tmpMsgFolderId; |
|
561 |
nextAvailable = iAppUi.IsNextMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId ); |
|
562 |
prevAvailable = iAppUi.IsPreviousMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId ); |
|
563 |
} |
|
564 |
||
565 |
if( iOverlayControlPrev ) |
|
566 |
{ |
|
567 |
iOverlayControlPrev->SetRect( OverlayButtonRect( ETrue ) ); |
|
568 |
iOverlayControlPrev->MakeVisible( aVisible && prevAvailable ); |
|
569 |
} |
|
570 |
if( iOverlayControlNext ) |
|
571 |
{ |
|
572 |
iOverlayControlNext->SetRect( OverlayButtonRect( EFalse ) ); |
|
573 |
iOverlayControlNext->MakeVisible( aVisible && nextAvailable ); |
|
574 |
} |
|
575 |
} |
|
576 |
||
577 |
// Get rect for button |
|
578 |
TRect CFsEmailUiHtmlViewerContainer::OverlayButtonRect( TBool aLeft ) |
|
579 |
{ |
|
580 |
TRect rect = Rect(); |
|
581 |
TSize size = rect.Size(); |
|
582 |
||
583 |
TBool landscape = size.iWidth > size.iHeight; |
|
584 |
TInt buttonSize; |
|
585 |
||
586 |
if( landscape ) |
|
587 |
{ |
|
588 |
buttonSize = size.iHeight * KOverlayButtonSizeLs; |
|
589 |
} |
|
590 |
else |
|
591 |
{ |
|
592 |
buttonSize = size.iWidth * KOverlayButtonSizeP; |
|
593 |
} |
|
594 |
||
595 |
rect.iBr.iY = size.iHeight * (1-KOverlayButtonMarginY); |
|
596 |
||
597 |
if( aLeft ) |
|
598 |
{ |
|
599 |
rect.iTl.iX = size.iWidth * KOverlayButtonMarginX; |
|
600 |
rect.iBr.iX = rect.iTl.iX + buttonSize; |
|
601 |
} |
|
602 |
else |
|
603 |
{ |
|
604 |
rect.iBr.iX = size.iWidth * (1 - KOverlayButtonMarginX); |
|
605 |
rect.iTl.iX = rect.iBr.iX - buttonSize; |
|
606 |
} |
|
607 |
||
608 |
rect.iTl.iY = rect.iBr.iY - buttonSize; |
|
609 |
return rect; |
|
610 |
} |
|
611 |
||
612 |
// Getter for br contro, interface |
|
613 |
CBrCtlInterface* CFsEmailUiHtmlViewerContainer::BrowserControlIf() |
|
614 |
{ |
|
615 |
FUNC_LOG; |
|
616 |
return iBrCtlInterface; |
|
617 |
} |
|
618 |
||
619 |
void CFsEmailUiHtmlViewerContainer::LoadContentFromFileL( const TDesC& aFileName ) |
|
620 |
{ |
|
621 |
FUNC_LOG; |
|
622 |
iBrCtlInterface->LoadFileL( aFileName ); |
|
623 |
} |
|
624 |
||
625 |
void CFsEmailUiHtmlViewerContainer::LoadContentFromFileL( RFile& aFile ) |
|
626 |
{ |
|
627 |
FUNC_LOG; |
|
628 |
iBrCtlInterface->LoadFileL( aFile ); |
|
629 |
} |
|
630 |
||
631 |
void CFsEmailUiHtmlViewerContainer::LoadContentFromUrlL( const TDesC& aUrl ) |
|
632 |
{ |
|
633 |
FUNC_LOG; |
|
634 |
iBrCtlInterface->LoadUrlL( aUrl ); |
|
635 |
} |
|
636 |
||
637 |
// --------------------------------------------------------------------------- |
|
638 |
// Loads content from given mail message. |
|
639 |
// --------------------------------------------------------------------------- |
|
640 |
// |
|
641 |
void CFsEmailUiHtmlViewerContainer::LoadContentFromMailMessageL( |
|
642 |
CFSMailMessage* aMailMessage, TBool aResetScrollPos ) |
|
643 |
{ |
|
644 |
FUNC_LOG; |
|
645 |
ASSERT( aMailMessage ); |
|
646 |
iMessage = aMailMessage; |
|
647 |
// Cancel any browser fetch operation, just in case the browser is still |
|
648 |
// loading a previous message (since we are about to overwrite it). |
|
649 |
CancelFetch(); |
|
650 |
||
651 |
TPath headerHtmlFile; |
|
652 |
headerHtmlFile.Copy( iHtmlFolderPath ); |
|
653 |
headerHtmlFile.Append( KHeaderHtmlFile ); |
|
654 |
||
655 |
// insert email header into email.html file |
|
656 |
// CFreestyleMessageHeaderHTML will replace contents of email.html |
|
657 |
// So, no need to clear the contents |
|
658 |
if(aResetScrollPos) |
|
659 |
{ |
|
660 |
iScrollPosition = 0; |
|
661 |
} |
|
662 |
const TInt visibleWidth(iAppUi.ClientRect().Width()); |
|
663 |
CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, visibleWidth, iScrollPosition, |
|
664 |
iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage), iFlags ); |
|
665 |
||
666 |
// Remove all previously created files from temporary HTML folder |
|
667 |
EmptyTempHtmlFolderL(); |
|
668 |
||
669 |
TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) ); |
|
670 |
if ( error != KErrNone ) |
|
671 |
{ |
|
672 |
WriteEmptyBodyHtmlL( KBodyHtmlFile ); |
|
673 |
} |
|
674 |
||
675 |
// pass the emailHtmlFile to the browser for it to load |
|
676 |
TPath emailHtmlFile; |
|
677 |
emailHtmlFile.Copy( iHtmlFolderPath ); |
|
678 |
if ( !AknLayoutUtils::LayoutMirrored() ) |
|
679 |
{ |
|
680 |
emailHtmlFile.Append( KMessageHtmlFile ); |
|
681 |
} |
|
682 |
else |
|
683 |
{ |
|
684 |
emailHtmlFile.Append( KMessageHtmlRTLFile ); |
|
685 |
} |
|
686 |
||
687 |
// If scroll position is not to be reset, re-creation of browser control |
|
688 |
// interface object is skipped (we're just reloading the page with new |
|
689 |
// content) |
|
690 |
if ( aResetScrollPos ) |
|
691 |
{ |
|
692 |
CreateBrowserControlInterfaceL(); |
|
693 |
} |
|
694 |
||
695 |
LoadContentFromFileL( emailHtmlFile ); |
|
696 |
||
697 |
UpdateOverlayButtons( ETrue ); |
|
698 |
} |
|
699 |
||
700 |
// --------------------------------------------------------------------------- |
|
701 |
// Reset content |
|
702 |
// --------------------------------------------------------------------------- |
|
703 |
// |
|
704 |
void CFsEmailUiHtmlViewerContainer::ResetContent( TBool aDisconnect, |
|
705 |
TBool aClearFlags ) |
|
706 |
{ |
|
707 |
FUNC_LOG; |
|
708 |
if ( iBrCtlInterface ) |
|
709 |
{ |
|
710 |
TRAP_IGNORE( |
|
711 |
iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase + |
|
712 |
( TInt )TBrCtlDefs::ECommandFreeMemory ) ); |
|
713 |
if (aDisconnect) |
|
714 |
{ |
|
715 |
TRAP_IGNORE( |
|
716 |
iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase + |
|
717 |
( TInt )TBrCtlDefs::ECommandDisconnect ) ); |
|
718 |
} |
|
719 |
} |
|
720 |
iFile.Close(); |
|
721 |
iLinkContents.Reset(); |
|
722 |
iMessageParts.Reset(); |
|
723 |
iMessage = NULL; |
|
724 |
if ( aClearFlags ) |
|
725 |
{ |
|
726 |
iFlags.ClearAll(); |
|
727 |
} |
|
728 |
iScrollPosition = 0; |
|
729 |
} |
|
730 |
||
731 |
// --------------------------------------------------------------------------- |
|
732 |
// From CCoeControl. |
|
733 |
// --------------------------------------------------------------------------- |
|
734 |
// |
|
735 |
CCoeControl* CFsEmailUiHtmlViewerContainer::ComponentControl( TInt aIndex ) const |
|
736 |
{ |
|
737 |
FUNC_LOG; |
|
738 |
switch ( aIndex ) |
|
739 |
{ |
|
740 |
case 0: |
|
741 |
{ |
|
742 |
return iBrCtlInterface; |
|
743 |
} |
|
744 |
case 1: |
|
745 |
{ |
|
746 |
return iOverlayControlNext; |
|
747 |
} |
|
748 |
case 2: |
|
749 |
{ |
|
750 |
return iOverlayControlPrev; |
|
751 |
} |
|
752 |
case 3: |
|
753 |
{ |
|
754 |
if ( iStatusIndicator ) |
|
755 |
return iStatusIndicator; |
|
756 |
else |
|
757 |
return NULL; |
|
758 |
} |
|
759 |
default: |
|
760 |
{ |
|
761 |
return NULL; |
|
762 |
} |
|
763 |
} |
|
764 |
} |
|
765 |
||
766 |
// --------------------------------------------------------------------------- |
|
767 |
// From CCoeControl. |
|
768 |
// --------------------------------------------------------------------------- |
|
769 |
// |
|
770 |
TInt CFsEmailUiHtmlViewerContainer::CountComponentControls() const |
|
771 |
{ |
|
772 |
FUNC_LOG; |
|
773 |
if ( iStatusIndicator ) |
|
774 |
{ |
|
775 |
return 4; |
|
776 |
} |
|
777 |
else |
|
778 |
{ |
|
779 |
return 3; |
|
780 |
} |
|
781 |
} |
|
782 |
||
783 |
// --------------------------------------------------------------------------- |
|
784 |
// From CCoeControl. |
|
785 |
// Draw this application's view to the screen |
|
786 |
// --------------------------------------------------------------------------- |
|
787 |
// |
|
788 |
void CFsEmailUiHtmlViewerContainer::Draw( const TRect& /*aRect*/ ) const |
|
789 |
{ |
|
790 |
FUNC_LOG; |
|
791 |
// Get the standard graphics context |
|
792 |
CWindowGc& gc = SystemGc(); |
|
793 |
||
794 |
// Gets the control's extent |
|
795 |
TRect rect = Rect(); |
|
796 |
||
797 |
// Clears the screen |
|
798 |
gc.Clear( rect ); |
|
799 |
} |
|
800 |
||
801 |
// --------------------------------------------------------------------------- |
|
802 |
// From CCoeControl. |
|
803 |
// --------------------------------------------------------------------------- |
|
804 |
// |
|
805 |
void CFsEmailUiHtmlViewerContainer::SizeChanged() |
|
806 |
{ |
|
807 |
FUNC_LOG; |
|
808 |
||
809 |
TRect rect = Rect(); |
|
810 |
if ( iBrCtlInterface ) |
|
811 |
{ |
|
812 |
iBrCtlInterface->SetRect( rect ); |
|
813 |
} |
|
814 |
||
815 |
UpdateOverlayButtons( IsVisible() ); |
|
816 |
||
817 |
if ( iStatusIndicator ) |
|
818 |
{ |
|
819 |
TRect rect = CalcAttachmentStatusRect(); |
|
820 |
iStatusIndicator->SetRect( rect ); |
|
821 |
} |
|
822 |
} |
|
823 |
||
824 |
// --------------------------------------------------------------------------- |
|
825 |
// From CCoeControl. |
|
826 |
// --------------------------------------------------------------------------- |
|
827 |
// |
|
828 |
TKeyResponse CFsEmailUiHtmlViewerContainer::OfferKeyEventL( |
|
829 |
const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
830 |
{ |
|
831 |
FUNC_LOG; |
|
832 |
||
833 |
TKeyResponse retVal = EKeyWasNotConsumed; |
|
834 |
||
835 |
// Handle keyboard shortcuts already on key down event as all keys |
|
836 |
// do not necessarily send the key event at all. |
|
837 |
if ( aType == EEventKeyDown ) |
|
838 |
{ |
|
839 |
// Check keyboard shortcuts |
|
840 |
TInt shortcutCommand = iAppUi.ShortcutBinding().CommandForShortcutKey( |
|
841 |
aKeyEvent, CFSEmailUiShortcutBinding::EContextHtmlViewer ); |
|
842 |
||
843 |
if ( shortcutCommand != KErrNotFound ) |
|
844 |
{ |
|
845 |
iView.HandleCommandL( shortcutCommand ); |
|
846 |
retVal = EKeyWasConsumed; |
|
847 |
} |
|
848 |
} |
|
849 |
||
850 |
if ( iBrCtlInterface && retVal == EKeyWasNotConsumed ) |
|
851 |
{ |
|
852 |
TKeyEvent event = aKeyEvent; |
|
853 |
if ( iBrCtlInterface->FocusedElementType() == TBrCtlDefs::EElementButton |
|
854 |
&& ( aKeyEvent.iScanCode == EStdKeyNkpEnter |
|
855 |
|| aKeyEvent.iScanCode == EStdKeyEnter ) ) |
|
856 |
{ |
|
857 |
// Enter key events are converted to selection key event in |
|
858 |
// order to get browser to handle them in similar way. |
|
859 |
event.iScanCode = EStdKeyDevice3; |
|
860 |
event.iCode = aKeyEvent.iCode ? EKeyDevice3 : 0; |
|
861 |
} |
|
862 |
retVal = iBrCtlInterface->OfferKeyEventL( event, aType ); |
|
863 |
} |
|
864 |
||
865 |
iView.SetMskL(); |
|
866 |
||
867 |
return retVal; |
|
868 |
} |
|
869 |
||
870 |
// --------------------------------------------------------------------------- |
|
871 |
// From MBrCtlSpecialLoadObserver. |
|
872 |
// --------------------------------------------------------------------------- |
|
873 |
// |
|
874 |
void CFsEmailUiHtmlViewerContainer::NetworkConnectionNeededL( |
|
875 |
TInt* aConnectionPtr, |
|
876 |
TInt* aSockSvrHandle, |
|
877 |
TBool* aNewConn, |
|
878 |
TApBearerType* aBearerType ) |
|
879 |
{ |
|
880 |
FUNC_LOG; |
|
881 |
*aBearerType = EApBearerTypeAllBearers; |
|
882 |
||
883 |
if ( iFirstTime ) |
|
884 |
{ |
|
885 |
User::LeaveIfError( iSocketServer.Connect( KESockDefaultMessageSlots ) ); |
|
886 |
User::LeaveIfError( iConnection.Open( iSocketServer, KConnectionTypeDefault ) ); |
|
887 |
TCommDbConnPref prefs; |
|
888 |
prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
889 |
prefs.SetDirection( ECommDbConnectionDirectionOutgoing ); |
|
890 |
prefs.SetIapId( 0 ); // Ask for access point |
|
891 |
User::LeaveIfError( iConnection.Start( prefs ) ); |
|
892 |
*aNewConn = ETrue; |
|
893 |
iFirstTime = EFalse; |
|
894 |
} |
|
895 |
else |
|
896 |
{ |
|
897 |
*aNewConn = EFalse; |
|
898 |
} |
|
899 |
||
900 |
*aConnectionPtr = reinterpret_cast<TInt>(&iConnection); |
|
901 |
*aSockSvrHandle = iSocketServer.Handle(); |
|
902 |
} |
|
903 |
||
904 |
// --------------------------------------------------------------------------- |
|
905 |
// From MBrCtlSpecialLoadObserver. |
|
906 |
// --------------------------------------------------------------------------- |
|
907 |
// |
|
908 |
TBool CFsEmailUiHtmlViewerContainer::HandleRequestL( |
|
909 |
RArray<TUint>* /*aTypeArray*/, CDesCArrayFlat* /*aDesArray*/ ) |
|
910 |
{ |
|
911 |
FUNC_LOG; |
|
912 |
// Let browser control handle these |
|
913 |
return EFalse; |
|
914 |
} |
|
915 |
||
916 |
// --------------------------------------------------------------------------- |
|
917 |
// From MBrCtlSpecialLoadObserver. |
|
918 |
// --------------------------------------------------------------------------- |
|
919 |
// |
|
920 |
TBool CFsEmailUiHtmlViewerContainer::HandleDownloadL( |
|
921 |
RArray<TUint>* /*aTypeArray*/, CDesCArrayFlat* /*aDesArray*/ ) |
|
922 |
{ |
|
923 |
FUNC_LOG; |
|
924 |
// Let browser control handle these |
|
925 |
return EFalse; |
|
926 |
} |
|
927 |
||
928 |
// --------------------------------------------------------------------------- |
|
929 |
// From MFSEmailDownloadInformationObserver. |
|
930 |
// --------------------------------------------------------------------------- |
|
931 |
// |
|
932 |
void CFsEmailUiHtmlViewerContainer::RequestResponseL( const TFSProgress& aEvent, |
|
933 |
const TPartData& aPart ) |
|
934 |
{ |
|
935 |
FUNC_LOG; |
|
936 |
if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete ) |
|
937 |
{ |
|
938 |
MBrCtlLinkContent* linkContent = NULL; |
|
939 |
for ( TInt ii = iMessageParts.Count() - 1; ii >= 0 && !linkContent; --ii ) |
|
940 |
{ |
|
941 |
if ( iMessageParts[ii] == aPart ) |
|
942 |
{ |
|
943 |
iMessageParts.Remove( ii ); |
|
944 |
linkContent = iLinkContents[ii]; |
|
945 |
iLinkContents.Remove( ii ); |
|
946 |
} |
|
947 |
} |
|
948 |
||
949 |
if ( !iMessageParts.Count() && iAppUi.DownloadInfoMediator() ) |
|
950 |
{ |
|
951 |
iAppUi.DownloadInfoMediator()->StopObserving( this ); |
|
952 |
} |
|
953 |
||
954 |
if ( iMessage && linkContent ) |
|
955 |
{ |
|
956 |
CFSMailMessagePart* part = iMessage->ChildPartL( aPart.iMessagePartId ); |
|
957 |
CleanupStack::PushL( part ); |
|
958 |
RFile contentFile = part->GetContentFileL(); |
|
959 |
CleanupClosePushL( contentFile ); |
|
960 |
HBufC8* content = ReadContentFromFileLC( contentFile, *part ); |
|
961 |
linkContent->HandleResolveComplete( |
|
962 |
part->GetContentType(), KNullDesC(), content ); |
|
963 |
CleanupStack::PopAndDestroy( content ); |
|
964 |
CleanupStack::PopAndDestroy( &contentFile ); |
|
965 |
CleanupStack::PopAndDestroy( part ); |
|
966 |
} |
|
967 |
||
968 |
if ( iMessage ) |
|
969 |
{ |
|
970 |
LoadContentFromMailMessageL( iMessage, EFalse ); |
|
971 |
UpdateOverlayButtons( ETrue ); |
|
972 |
} |
|
973 |
} |
|
974 |
else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled || |
|
975 |
aEvent.iProgressStatus < 0 ) |
|
976 |
{ |
|
977 |
if ( iAppUi.DownloadInfoMediator() ) |
|
978 |
{ |
|
979 |
iAppUi.DownloadInfoMediator()->StopObserving( this, aPart.iMessageId ); |
|
980 |
} |
|
981 |
} |
|
982 |
} |
|
983 |
||
984 |
// --------------------------------------------------------------------------- |
|
985 |
// From MBrCtlLinkResolver. |
|
986 |
// --------------------------------------------------------------------------- |
|
987 |
// |
|
988 |
TBool CFsEmailUiHtmlViewerContainer::ResolveEmbeddedLinkL( |
|
989 |
const TDesC& aEmbeddedUrl, const TDesC& /*aCurrentUrl*/, |
|
990 |
TBrCtlLoadContentType /*aLoadContentType*/, |
|
991 |
MBrCtlLinkContent& aEmbeddedLinkContent ) |
|
992 |
{ |
|
993 |
FUNC_LOG; |
|
994 |
TBool linkResolved = EFalse; |
|
995 |
||
996 |
// Check if given link contains content ID |
|
997 |
if ( aEmbeddedUrl.Left( KContentIdPrefix().Length() ).CompareF( KContentIdPrefix ) == 0 ) |
|
998 |
{ |
|
999 |
TPtrC cid = aEmbeddedUrl.Mid( KContentIdPrefix().Length() ); |
|
1000 |
linkResolved = ResolveLinkL( cid, ETrue, aEmbeddedLinkContent ); |
|
1001 |
} |
|
1002 |
else |
|
1003 |
{ |
|
1004 |
// Replace all slash character with backslash characters |
|
1005 |
HBufC* embeddedUrl = aEmbeddedUrl.AllocLC(); |
|
1006 |
TPtr ptr = embeddedUrl->Des(); |
|
1007 |
_LIT( KBackslash, "\\" ); |
|
1008 |
for ( TInt pos = ptr.Locate('/'); pos >= 0; pos = ptr.Locate('/') ) |
|
1009 |
{ |
|
1010 |
ptr.Replace( pos, 1, KBackslash ); |
|
1011 |
} |
|
1012 |
||
1013 |
// Check whether given url refers to file in the temporary html folder |
|
1014 |
TInt pos = embeddedUrl->FindF( iTempHtmlFolderPath ); |
|
1015 |
if ( pos >= 0 ) |
|
1016 |
{ |
|
1017 |
TPtrC filename = embeddedUrl->Mid( pos + iTempHtmlFolderPath.Length() ); |
|
1018 |
linkResolved = ResolveLinkL( filename, EFalse, aEmbeddedLinkContent ); |
|
1019 |
} |
|
1020 |
||
1021 |
CleanupStack::PopAndDestroy( embeddedUrl ); |
|
1022 |
} |
|
1023 |
||
1024 |
// Return whether link is resolved by host application. |
|
1025 |
return linkResolved; |
|
1026 |
} |
|
1027 |
||
1028 |
// --------------------------------------------------------------------------- |
|
1029 |
// From MBrCtlLinkResolver. |
|
1030 |
// --------------------------------------------------------------------------- |
|
1031 |
// |
|
1032 |
TBool CFsEmailUiHtmlViewerContainer::ResolveLinkL( const TDesC& aUrl, |
|
1033 |
const TDesC& /*aCurrentUrl*/, MBrCtlLinkContent& /*aBrCtlLinkContent*/ ) |
|
1034 |
{ |
|
1035 |
FUNC_LOG; |
|
1036 |
if ( IsMessageBodyURLL(aUrl) ) |
|
1037 |
{ |
|
1038 |
if ( iMessage ) |
|
1039 |
{ |
|
1040 |
iView.StartFetchingMessageL(); |
|
1041 |
} |
|
1042 |
return ETrue; |
|
1043 |
} |
|
1044 |
else |
|
1045 |
{ |
|
26
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1046 |
// special handling for such file links that for which corresponding |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1047 |
// file is not found in local disk. We try to modify such links to |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1048 |
// have http prefix so that browser could open them as they're likely |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1049 |
// <href=www...> type tags (i.e., tags missing the scheme) which the |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1050 |
// browser control has interpreted as local files |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1051 |
HBufC* modifiedUrl = CreateModifiedUrlIfNeededL( aUrl ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1052 |
if ( modifiedUrl ) |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1053 |
{ |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1054 |
TBool rVal( ETrue ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1055 |
CleanupStack::PushL( modifiedUrl ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1056 |
rVal = iEventHandler->HandleEventL( *modifiedUrl ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1057 |
CleanupStack::PopAndDestroy( modifiedUrl ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1058 |
return rVal; |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1059 |
} |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
1060 |
|
25 | 1061 |
if ( NeedToLaunchBrowserL( aUrl ) ) |
1062 |
{ |
|
1063 |
LaunchBrowserL( aUrl ); |
|
1064 |
return ETrue; |
|
1065 |
} |
|
1066 |
else |
|
1067 |
{ |
|
1068 |
return iEventHandler->HandleEventL( aUrl ); |
|
1069 |
} |
|
1070 |
} |
|
1071 |
} |
|
1072 |
||
1073 |
// --------------------------------------------------------------------------- |
|
1074 |
// From MBrCtlLinkResolver. |
|
1075 |
// --------------------------------------------------------------------------- |
|
1076 |
// |
|
1077 |
void CFsEmailUiHtmlViewerContainer::CancelAll() |
|
1078 |
{ |
|
1079 |
FUNC_LOG; |
|
1080 |
} |
|
1081 |
||
1082 |
// --------------------------------------------------------------------------- |
|
1083 |
// From MBrCtlSoftkeysObserver |
|
1084 |
// --------------------------------------------------------------------------- |
|
1085 |
// |
|
1086 |
void CFsEmailUiHtmlViewerContainer::UpdateSoftkeyL( |
|
1087 |
TBrCtlKeySoftkey /*aKeySoftkey*/, const TDesC& /*aLabel*/, |
|
1088 |
TUint32 /*aCommandId*/, |
|
1089 |
TBrCtlSoftkeyChangeReason /*aBrCtlSoftkeyChangeReason*/ ) |
|
1090 |
{ |
|
1091 |
FUNC_LOG; |
|
1092 |
} |
|
1093 |
||
1094 |
// --------------------------------------------------------------------------- |
|
1095 |
// Set HTML folder path name |
|
1096 |
// --------------------------------------------------------------------------- |
|
1097 |
// |
|
1098 |
void CFsEmailUiHtmlViewerContainer::SetHtmlFolderPathL() |
|
1099 |
{ |
|
1100 |
FUNC_LOG; |
|
1101 |
iHtmlFolderPath.Copy( KCDrive ); |
|
1102 |
||
1103 |
TFileName privatePath; |
|
1104 |
User::LeaveIfError( iFs.PrivatePath( privatePath ) ); |
|
1105 |
iHtmlFolderPath.Append( privatePath ); |
|
1106 |
||
1107 |
iHtmlFolderPath.Append( KHtmlPath ); |
|
1108 |
} |
|
1109 |
||
1110 |
// --------------------------------------------------------------------------- |
|
1111 |
// Sets temporary HTML folder path name |
|
1112 |
// --------------------------------------------------------------------------- |
|
1113 |
// |
|
1114 |
void CFsEmailUiHtmlViewerContainer::SetTempHtmlFolderPath() |
|
1115 |
{ |
|
1116 |
FUNC_LOG; |
|
1117 |
iTempHtmlFolderPath.Copy( iHtmlFolderPath ); |
|
1118 |
iTempHtmlFolderPath.Append( KTempHtmlPath ); |
|
1119 |
} |
|
1120 |
||
1121 |
// --------------------------------------------------------------------------- |
|
1122 |
// Remove all previously created files from temporary HTML folder |
|
1123 |
// --------------------------------------------------------------------------- |
|
1124 |
// |
|
1125 |
void CFsEmailUiHtmlViewerContainer::EmptyTempHtmlFolderL() |
|
1126 |
{ |
|
1127 |
FUNC_LOG; |
|
1128 |
// Delete all files from temp folder |
|
1129 |
TFileName allFiles; |
|
1130 |
allFiles.Append( iTempHtmlFolderPath ); |
|
1131 |
allFiles.Append( KAllFiles ); |
|
1132 |
TInt err = BaflUtils::DeleteFile( iFs, allFiles ); |
|
1133 |
if ( err != KErrNotFound && err != KErrNone ) |
|
1134 |
{ |
|
1135 |
User::LeaveIfError( err ); |
|
1136 |
} |
|
1137 |
} |
|
1138 |
||
1139 |
// --------------------------------------------------------------------------- |
|
1140 |
// Copies given read-only file to HTML file |
|
1141 |
// --------------------------------------------------------------------------- |
|
1142 |
// |
|
1143 |
// <cmail> |
|
1144 |
void CFsEmailUiHtmlViewerContainer::CopyToHtmlFileL( CFSMailMessagePart& aHtmlBodyPart, const TDesC& aFileName ) |
|
1145 |
{ |
|
1146 |
FUNC_LOG; |
|
1147 |
TFileName targetFileName; |
|
1148 |
targetFileName.Copy( iTempHtmlFolderPath ); |
|
1149 |
targetFileName.Append( aFileName ); |
|
1150 |
||
1151 |
RFile htmlFile = aHtmlBodyPart.GetContentFileL(); |
|
1152 |
CleanupClosePushL( htmlFile ); |
|
1153 |
||
1154 |
// Read content from given source file |
|
1155 |
HBufC8* content = ReadContentFromFileLC( htmlFile, aHtmlBodyPart ); |
|
1156 |
||
1157 |
// Write content to target file |
|
1158 |
WriteContentToFileL( *content, targetFileName, aHtmlBodyPart ); |
|
1159 |
||
1160 |
CleanupStack::PopAndDestroy( content ); |
|
1161 |
CleanupStack::PopAndDestroy( &htmlFile ); |
|
1162 |
} |
|
1163 |
// </cmail> |
|
1164 |
||
1165 |
// --------------------------------------------------------------------------- |
|
1166 |
// Copies given buffer to HTML file |
|
1167 |
// --------------------------------------------------------------------------- |
|
1168 |
// |
|
1169 |
// <cmail> |
|
1170 |
void CFsEmailUiHtmlViewerContainer::ConvertToHtmlFileL( CFSMailMessagePart& aTextBodyPart, const TDesC& aHtmlFileName ) |
|
1171 |
{ |
|
1172 |
FUNC_LOG; |
|
1173 |
TFileName targetFileName; |
|
1174 |
targetFileName.Copy( iTempHtmlFolderPath ); |
|
1175 |
targetFileName.Append( aHtmlFileName ); |
|
1176 |
||
1177 |
TInt contentsize = aTextBodyPart.FetchedContentSize(); |
|
1178 |
||
1179 |
TInt limit(0); |
|
1180 |
TInt err = iViewerSettings->Repository().Get( KFreestyleMaxBodySize , limit ); |
|
1181 |
limit *= KKilo; // cenrep value is in kB, 0 means unlimited |
|
1182 |
||
1183 |
if ( limit == 0 || err ) |
|
1184 |
{ |
|
1185 |
limit = KMaxTInt; |
|
1186 |
} |
|
1187 |
||
1188 |
TInt size = Min(limit,contentsize); |
|
1189 |
HBufC* content = HBufC::NewLC( size ); |
|
1190 |
TPtr contentPtr( content->Des() ); |
|
1191 |
||
1192 |
aTextBodyPart.GetContentToBufferL( contentPtr, 0 ); |
|
1193 |
//When we found EFSMsgFlag_BodyTruncated was set, add "--Message too long--" in the end of plain html view |
|
1194 |
if ( limit < contentsize ) |
|
1195 |
{ |
|
1196 |
// Disable this is PS1 until we have translations available |
|
1197 |
// HBufC* addingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEW_ADDITIONAL_INFO , limit/KKilo ); |
|
1198 |
// TInt pos = contentPtr.Length() - addingText->Length(); |
|
1199 |
// contentPtr.Replace(pos,addingText->Length(),*addingText); |
|
1200 |
// CleanupStack::PopAndDestroy( addingText ); |
|
1201 |
aTextBodyPart.SetFlag(EFSMsgFlag_BodyTruncated); |
|
1202 |
} |
|
1203 |
||
1204 |
ConvertToHTML( *content, targetFileName, aTextBodyPart ); |
|
1205 |
CleanupStack::PopAndDestroy( content ); |
|
1206 |
} |
|
1207 |
||
1208 |
// --------------------------------------------------------------------------- |
|
1209 |
// Reads given file content to buffer and return pointer to it |
|
1210 |
// --------------------------------------------------------------------------- |
|
1211 |
// |
|
1212 |
HBufC8* CFsEmailUiHtmlViewerContainer::ReadContentFromFileLC( RFile& aFile, |
|
1213 |
CFSMailMessagePart& aBodyPart ) |
|
1214 |
{ |
|
1215 |
FUNC_LOG; |
|
1216 |
TInt fileSize = 0; |
|
1217 |
User::LeaveIfError( aFile.Size( fileSize ) ); |
|
1218 |
||
1219 |
HBufC* contentType = aBodyPart.GetContentType().AllocLC(); |
|
1220 |
TInt length = contentType->Locate(';'); |
|
1221 |
if( length >= 0 ) |
|
1222 |
{ |
|
1223 |
contentType->Des().SetLength( length ); |
|
1224 |
} |
|
1225 |
TBool body = KFSMailContentTypeTextPlain().CompareF( contentType->Des() ) == 0 || |
|
1226 |
KFSMailContentTypeTextHtml().CompareF( contentType->Des() ) == 0; |
|
1227 |
CleanupStack::PopAndDestroy( contentType ); |
|
1228 |
||
1229 |
if ( body ) |
|
1230 |
{ |
|
1231 |
// limit message size if not done already by plugins |
|
1232 |
TInt limit(0); |
|
1233 |
TInt err = iViewerSettings->Repository().Get( KFreestyleMaxBodySize , limit ); |
|
1234 |
limit *= KKilo; // cenrep value is in kB, 0 means unlimited |
|
1235 |
||
1236 |
if ( limit == 0 || err ) |
|
1237 |
{ |
|
1238 |
limit = KMaxTInt; |
|
1239 |
} |
|
1240 |
fileSize = Min( limit, fileSize ); // read no more than limit bytes.. |
|
1241 |
||
1242 |
TInt contentSize = aBodyPart.ContentSize(); |
|
1243 |
TInt fetchedSize = aBodyPart.FetchedContentSize(); |
|
1244 |
||
1245 |
if ( ( limit!=KMaxTInt && fileSize < contentSize ) |
|
1246 |
|| ( fetchedSize < contentSize ) ) |
|
1247 |
{ |
|
1248 |
aBodyPart.SetFlag( EFSMsgFlag_BodyTruncated ); |
|
1249 |
} |
|
1250 |
} |
|
1251 |
HBufC8* buffer = HBufC8::NewLC( fileSize ); |
|
1252 |
TPtr8 ptr = buffer->Des(); |
|
1253 |
User::LeaveIfError( aFile.Read( ptr, fileSize ) ); |
|
1254 |
return buffer; |
|
1255 |
} |
|
1256 |
||
1257 |
// --------------------------------------------------------------------------- |
|
1258 |
// Writes buffer content to given file |
|
1259 |
// --------------------------------------------------------------------------- |
|
1260 |
// |
|
1261 |
// <cmail> |
|
1262 |
void CFsEmailUiHtmlViewerContainer::WriteContentToFileL( const TDesC8& aContent, |
|
1263 |
const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart ) |
|
1264 |
{ |
|
1265 |
FUNC_LOG; |
|
1266 |
||
1267 |
RBuf8 buffer; |
|
1268 |
buffer.CreateL( aContent ); |
|
1269 |
buffer.CleanupClosePushL(); |
|
1270 |
||
1271 |
if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, buffer.Size(), EDriveC ) ) |
|
1272 |
{ |
|
1273 |
// Can not write the data, there's not enough free space on disk. |
|
1274 |
User::Leave( KErrDiskFull ); |
|
1275 |
} |
|
1276 |
else |
|
1277 |
{ |
|
1278 |
RFile targetFile; |
|
1279 |
CleanupClosePushL( targetFile ); |
|
1280 |
||
1281 |
User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); |
|
1282 |
||
1283 |
// Try to find initial html tag (both '<html' and '<HTML' versions are searched) |
|
1284 |
TInt startTagOffset = buffer.Left( KMaxCharsToSearch ).FindF( KStartTag ); |
|
1285 |
||
1286 |
// Modifying text/html atta IF there's no '<html>' tag anywhere in |
|
1287 |
// the begining of file (KMaxCharsToSearch) AND there is charset |
|
1288 |
// parameter available |
|
1289 |
TBool modificationNeeded( EFalse ); |
|
1290 |
if( startTagOffset == KErrNotFound ) |
|
1291 |
{ |
|
1292 |
modificationNeeded = ETrue; |
|
1293 |
} |
|
1294 |
||
1295 |
// Write starting metadata if needed |
|
1296 |
if ( modificationNeeded ) |
|
1297 |
{ |
|
1298 |
HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart ); |
|
1299 |
CleanupStack::PushL( charSet ); |
|
1300 |
||
1301 |
User::LeaveIfError( targetFile.Write( KHtmlHeader1 ) ); |
|
1302 |
User::LeaveIfError( targetFile.Write( *charSet ) ); |
|
1303 |
User::LeaveIfError( targetFile.Write( KHtmlHeader2 ) ); |
|
1304 |
CleanupStack::PopAndDestroy( charSet ); |
|
1305 |
} |
|
1306 |
else |
|
1307 |
{ |
|
1308 |
// Charset tag not found in html body |
|
1309 |
||
1310 |
if ( buffer.Left( KMaxCharsToSearch ).FindF( KCharsetTag8 ) == KErrNotFound ) |
|
1311 |
{ |
|
1312 |
TInt startPos(0); |
|
1313 |
if ( ( startPos = buffer.Left( KMaxCharsToSearch ).FindF( KHeadTag ) ) != KErrNotFound ) |
|
1314 |
{ |
|
1315 |
||
1316 |
HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart ); |
|
1317 |
CleanupStack::PushL( charSet ); |
|
1318 |
||
1319 |
HBufC8* metaBuffer = HBufC8::NewLC( charSet->Des().Length() + KHtmlHeader3().Length() ); |
|
1320 |
TPtr8 metaHeader( metaBuffer->Des() ); |
|
1321 |
metaHeader.AppendFormat( KHtmlHeader3, charSet ); |
|
1322 |
TInt maxLength = buffer.Length() + metaHeader.Length(); |
|
1323 |
buffer.ReAllocL( maxLength ); |
|
1324 |
||
1325 |
startPos += KHeadTag().Length(); |
|
1326 |
buffer.Insert( startPos, metaHeader ); |
|
1327 |
||
1328 |
CleanupStack::PopAndDestroy( metaBuffer ); |
|
1329 |
CleanupStack::PopAndDestroy( charSet ); |
|
1330 |
} |
|
1331 |
} |
|
1332 |
} |
|
1333 |
||
1334 |
// Write the original content |
|
1335 |
User::LeaveIfError( targetFile.Write( buffer ) ); |
|
1336 |
if( aHtmlBodyPart.GetFlags() & EFSMsgFlag_BodyTruncated ) |
|
1337 |
{ |
|
1338 |
//When we found EFSMsgFlag_BodyTruncated was set, add "--- Message limited to %N kB ---" in the end of html view |
|
1339 |
TInt limit(0); |
|
1340 |
TInt err = iViewerSettings->Repository().Get( KFreestyleMaxBodySize , limit ); |
|
1341 |
limit *= KKilo; // cenrep value is in kB, 0 means unlimited |
|
1342 |
if ( limit == 0 || err ) |
|
1343 |
{ |
|
1344 |
limit = KMaxTInt; |
|
1345 |
} |
|
1346 |
||
1347 |
// Disable this is PS1 until we have translations available |
|
1348 |
// HBufC* addingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEW_ADDITIONAL_INFO, limit/KKilo ); |
|
1349 |
// HBufC8* addingText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *addingText ); |
|
1350 |
// CleanupStack::PopAndDestroy( addingText ); |
|
1351 |
// CleanupStack::PushL( addingText8 ); |
|
1352 |
// User::LeaveIfError( targetFile.Write( *addingText8 ) ); |
|
1353 |
// CleanupStack::PopAndDestroy( addingText8 ); |
|
1354 |
} |
|
1355 |
// Write ending metadata if needed |
|
1356 |
if ( modificationNeeded || (aHtmlBodyPart.GetFlags()&EFSMsgFlag_BodyTruncated) ) |
|
1357 |
{ |
|
1358 |
INFO("Add end tags"); |
|
1359 |
User::LeaveIfError( targetFile.Write( KHtmlEndTags ) ); |
|
1360 |
} |
|
1361 |
||
1362 |
CleanupStack::PopAndDestroy( &targetFile ); |
|
1363 |
} |
|
1364 |
CleanupStack::PopAndDestroy( &buffer ); |
|
1365 |
// </cmail> |
|
1366 |
} |
|
1367 |
||
1368 |
// --------------------------------------------------------------------------- |
|
1369 |
// Finds the attachment from the list that matches the given content ID |
|
1370 |
// --------------------------------------------------------------------------- |
|
1371 |
// |
|
1372 |
CFSMailMessagePart* CFsEmailUiHtmlViewerContainer::MatchingAttacmentL( |
|
1373 |
const TDesC& aContentId, |
|
1374 |
const RPointerArray<CFSMailMessagePart>& aAttachments ) const |
|
1375 |
{ |
|
1376 |
FUNC_LOG; |
|
1377 |
TBool contentFound = EFalse; |
|
1378 |
CFSMailMessagePart* attachment = NULL; |
|
1379 |
TInt attachmentCount = aAttachments.Count(); |
|
1380 |
||
1381 |
// Check whether one of the attachments has the given conten ID |
|
1382 |
for ( TInt i = 0; i < attachmentCount && !contentFound; i++ ) |
|
1383 |
{ |
|
1384 |
attachment = aAttachments[i]; |
|
1385 |
const TDesC& contentId = attachment->ContentID(); |
|
1386 |
if ( contentId.Compare( aContentId ) == 0 ) |
|
1387 |
{ |
|
1388 |
contentFound = ETrue; |
|
1389 |
} |
|
1390 |
} |
|
1391 |
||
1392 |
// If attacment with given content ID was not found, check whether |
|
1393 |
// the given content ID contains the name of one of the attachments |
|
1394 |
for ( TInt i = 0; i < attachmentCount && !contentFound; ++i ) |
|
1395 |
{ |
|
1396 |
attachment = aAttachments[i]; |
|
1397 |
const TDesC& name = attachment->AttachmentNameL(); |
|
1398 |
if ( aContentId.FindF( name ) >= 0 ) |
|
1399 |
{ |
|
1400 |
contentFound = ETrue; |
|
1401 |
} |
|
1402 |
} |
|
1403 |
||
1404 |
if ( !contentFound ) |
|
1405 |
{ |
|
1406 |
attachment = NULL; |
|
1407 |
} |
|
1408 |
return attachment; |
|
1409 |
} |
|
1410 |
||
1411 |
// --------------------------------------------------------------------------- |
|
1412 |
// Resolves link referring to file in temporary HTML folder |
|
1413 |
// --------------------------------------------------------------------------- |
|
1414 |
// |
|
1415 |
TBool CFsEmailUiHtmlViewerContainer::ResolveLinkL( const TDesC& aLink, |
|
1416 |
TBool aContentId, MBrCtlLinkContent& aEmbeddedLinkContent ) |
|
1417 |
{ |
|
1418 |
FUNC_LOG; |
|
1419 |
TBool linkResolved = EFalse; |
|
1420 |
CFSMailMessagePart* attachment = NULL; |
|
1421 |
||
1422 |
RPointerArray<CFSMailMessagePart> attachments; |
|
1423 |
CleanupResetAndDestroyClosePushL( attachments ); |
|
1424 |
iMessage->AttachmentListL( attachments ); |
|
1425 |
||
1426 |
if ( aContentId ) |
|
1427 |
{ |
|
1428 |
attachment = MatchingAttacmentL( aLink, attachments ); |
|
1429 |
} |
|
1430 |
else |
|
1431 |
{ |
|
1432 |
const TInt attachmentCount = attachments.Count(); |
|
1433 |
for ( TInt ii = 0; ii < attachmentCount && !attachment; ++ii ) |
|
1434 |
{ |
|
1435 |
if ( aLink.CompareF( attachments[ii]->AttachmentNameL() ) == 0 ) |
|
1436 |
{ |
|
1437 |
attachment = attachments[ii]; |
|
1438 |
} |
|
1439 |
} |
|
1440 |
} |
|
1441 |
||
1442 |
if ( attachment ) |
|
1443 |
{ |
|
1444 |
DownloadAttachmentL( *attachment, aEmbeddedLinkContent ); |
|
1445 |
linkResolved = ETrue; |
|
1446 |
} |
|
1447 |
||
1448 |
CleanupStack::PopAndDestroy( &attachments ); |
|
1449 |
return linkResolved; |
|
1450 |
} |
|
1451 |
||
1452 |
// --------------------------------------------------------------------------- |
|
1453 |
// Download attachment and return the content via MBrCtlLinkContent interface |
|
1454 |
// --------------------------------------------------------------------------- |
|
1455 |
// |
|
1456 |
void CFsEmailUiHtmlViewerContainer::DownloadAttachmentL( |
|
1457 |
CFSMailMessagePart& aAttachment, MBrCtlLinkContent& aEmbeddedLinkContent ) |
|
1458 |
{ |
|
1459 |
FUNC_LOG; |
|
1460 |
if ( aAttachment.FetchLoadState() == EFSFull ) |
|
1461 |
{ |
|
1462 |
RFile attachmentFile = aAttachment.GetContentFileL(); |
|
1463 |
CleanupClosePushL( attachmentFile ); |
|
1464 |
HBufC8* content = ReadContentFromFileLC( attachmentFile, aAttachment ); |
|
1465 |
aEmbeddedLinkContent.HandleResolveComplete( |
|
1466 |
aAttachment.GetContentType(), KNullDesC(), content ); |
|
1467 |
CleanupStack::PopAndDestroy( content ); |
|
1468 |
CleanupStack::PopAndDestroy( &attachmentFile ); |
|
1469 |
} |
|
1470 |
else |
|
1471 |
{ |
|
1472 |
TPartData partData; |
|
1473 |
if( iMessage ) |
|
1474 |
{ |
|
1475 |
partData.iMailBoxId = iMessage->GetMailBoxId(); |
|
1476 |
partData.iFolderId = iMessage->GetFolderId(); |
|
1477 |
partData.iMessageId = iMessage->GetMessageId(); |
|
1478 |
||
1479 |
partData.iMessagePartId = aAttachment.GetPartId(); |
|
1480 |
||
1481 |
if ( iAppUi.DownloadInfoMediator() && |
|
1482 |
iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) ) |
|
1483 |
{ |
|
1484 |
ASSERT( iLinkContents.Count() == iMessageParts.Count() ); |
|
1485 |
||
1486 |
// Append message part details and embedded link content interface |
|
1487 |
// to corresponding arrays so that the content can be returned |
|
1488 |
// when the download is completed. |
|
1489 |
iLinkContents.AppendL( &aEmbeddedLinkContent ); |
|
1490 |
if ( iMessageParts.Append( partData ) != KErrNone ) |
|
1491 |
{ |
|
1492 |
iLinkContents.Remove( iLinkContents.Count() - 1 ); |
|
1493 |
} |
|
1494 |
||
1495 |
ASSERT( iLinkContents.Count() == iMessageParts.Count() ); |
|
1496 |
if(!iView.GetAsyncFetchStatus()) |
|
1497 |
{ |
|
1498 |
iAppUi.DownloadInfoMediator()->AddObserver( this, aAttachment.GetMessageId() ); |
|
1499 |
iObservingDownload=ETrue; |
|
1500 |
iAppUi.DownloadInfoMediator()->DownloadL( partData, EFalse ); |
|
1501 |
} |
|
1502 |
} |
|
1503 |
} |
|
1504 |
} |
|
1505 |
} |
|
1506 |
||
1507 |
void CFsEmailUiHtmlViewerContainer::SetHTMLResourceFlagFullName() |
|
1508 |
{ |
|
1509 |
FUNC_LOG; |
|
1510 |
iHtmlResourceFlagPath.Copy( iHtmlFolderPath ); |
|
1511 |
iHtmlResourceFlagPath.Append( KHtmlFlagFile ); |
|
1512 |
} |
|
1513 |
||
1514 |
void CFsEmailUiHtmlViewerContainer::EnableHTMLResourceFlagL() |
|
1515 |
{ |
|
1516 |
FUNC_LOG; |
|
1517 |
RFile flag; |
|
1518 |
User::LeaveIfError( flag.Replace(iFs, iHtmlResourceFlagPath, EFileWrite) ); |
|
1519 |
flag.Close(); |
|
1520 |
} |
|
1521 |
||
1522 |
TBool CFsEmailUiHtmlViewerContainer::HTMLResourceFlagEnabled() |
|
1523 |
{ |
|
1524 |
FUNC_LOG; |
|
1525 |
return BaflUtils::FileExists( iFs, iHtmlResourceFlagPath ); |
|
1526 |
} |
|
1527 |
||
1528 |
void CFsEmailUiHtmlViewerContainer::CopyHTMLResourceL() |
|
1529 |
{ |
|
1530 |
FUNC_LOG; |
|
1531 |
||
1532 |
TPath htmlFolderPathInZ; |
|
1533 |
htmlFolderPathInZ.Copy( KZDrive ); |
|
1534 |
||
1535 |
TFileName privatePath; |
|
1536 |
User::LeaveIfError( iFs.PrivatePath( privatePath ) ); |
|
1537 |
htmlFolderPathInZ.Append( privatePath ); |
|
1538 |
||
1539 |
htmlFolderPathInZ.Append( KHtmlPath ); |
|
1540 |
||
1541 |
CDir* dirList; |
|
1542 |
TPath listSpec; |
|
1543 |
listSpec.Copy( htmlFolderPathInZ ); |
|
1544 |
||
1545 |
listSpec.Append( _L("*.*") ); |
|
1546 |
User::LeaveIfError( iFs.GetDir( listSpec, KEntryAttMaskSupported, ESortByName, dirList ) ); |
|
1547 |
CleanupStack::PushL( dirList ); |
|
1548 |
for ( TInt i=0; i < dirList->Count(); i++) |
|
1549 |
{ |
|
1550 |
TPath sourceFileFullName; |
|
1551 |
sourceFileFullName.Copy( htmlFolderPathInZ ); |
|
1552 |
sourceFileFullName.Append( (*dirList)[i].iName ); |
|
1553 |
||
1554 |
TBool isFolder( EFalse ); |
|
1555 |
BaflUtils::IsFolder( iFs, sourceFileFullName, isFolder); |
|
1556 |
if ( isFolder ) |
|
1557 |
{ |
|
1558 |
break; |
|
1559 |
} |
|
1560 |
||
1561 |
TPath targetFileFullName; |
|
1562 |
targetFileFullName.Copy( iHtmlFolderPath ); |
|
1563 |
targetFileFullName.Append( (*dirList)[i].iName ); |
|
1564 |
BaflUtils::DeleteFile( iFs, targetFileFullName ); |
|
1565 |
||
1566 |
BaflUtils::CopyFile( iFs, sourceFileFullName, targetFileFullName); |
|
1567 |
} |
|
1568 |
CleanupStack::PopAndDestroy( dirList ); |
|
1569 |
} |
|
1570 |
||
1571 |
void CFsEmailUiHtmlViewerContainer::EnsureHTMLResourceL() |
|
1572 |
{ |
|
1573 |
FUNC_LOG; |
|
1574 |
||
1575 |
if ( !HTMLResourceFlagEnabled() ) |
|
1576 |
{ |
|
1577 |
CopyHTMLResourceL(); |
|
1578 |
EnableHTMLResourceFlagL(); |
|
1579 |
} |
|
1580 |
} |
|
1581 |
||
1582 |
// --------------------------------------------------------------------------- |
|
1583 |
// Writes buffer content to given file after adding tags |
|
1584 |
// --------------------------------------------------------------------------- |
|
1585 |
// |
|
1586 |
void CFsEmailUiHtmlViewerContainer::ConvertToHTML( const TDesC& aContent, |
|
1587 |
const TDesC& aFileName, CFSMailMessagePart& /*aTextBodyPart*/ ) |
|
1588 |
{ |
|
1589 |
FUNC_LOG; |
|
1590 |
||
1591 |
if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aContent.Size(), EDriveC ) ) |
|
1592 |
{ |
|
1593 |
// Can not write the data, there's not enough free space on disk. |
|
1594 |
User::Leave( KErrDiskFull ); |
|
1595 |
} |
|
1596 |
||
1597 |
RBuf htmlText; |
|
1598 |
CleanupClosePushL( htmlText ); |
|
1599 |
||
1600 |
PlainTextToHtmlConverter::PlainTextToHtmlL( aContent, htmlText ); |
|
1601 |
WriteToFileL( aFileName, htmlText ); |
|
1602 |
||
1603 |
CleanupStack::PopAndDestroy( &htmlText ); |
|
1604 |
} |
|
1605 |
||
1606 |
||
1607 |
TInt CFsEmailUiHtmlViewerContainer::TotalLengthOfItems( CFindItemEngine& aItemEngine ) const |
|
1608 |
{ |
|
1609 |
TInt totalLength( 0 ); |
|
1610 |
CFindItemEngine::SFoundItem item; |
|
1611 |
aItemEngine.ResetPosition(); |
|
1612 |
for ( TBool available( aItemEngine.Item( item ) ); available; available = aItemEngine.NextItem( item ) ) |
|
1613 |
{ |
|
1614 |
totalLength += item.iLength; |
|
1615 |
} |
|
1616 |
aItemEngine.ResetPosition(); |
|
1617 |
return totalLength; |
|
1618 |
} |
|
1619 |
||
1620 |
// --------------------------------------------------------------------------- |
|
1621 |
// Get Character set from CFSMailMessagePart |
|
1622 |
// --------------------------------------------------------------------------- |
|
1623 |
// |
|
1624 |
// <cmail> |
|
1625 |
HBufC8* CFsEmailUiHtmlViewerContainer::GetCharacterSetL( CFSMailMessagePart& aHtmlBodyPart ) |
|
1626 |
{ |
|
1627 |
FUNC_LOG; |
|
1628 |
||
1629 |
CDesCArray& contentTypeArray( aHtmlBodyPart.ContentTypeParameters() ); |
|
1630 |
HBufC8* charSet = KNullDesC8().AllocLC(); |
|
1631 |
||
1632 |
for ( TInt i = 0; i < contentTypeArray.Count(); i++ ) |
|
1633 |
{ |
|
1634 |
TPtrC contentEntry( contentTypeArray.MdcaPoint( i ) ); |
|
1635 |
if ( ( contentEntry.FindF( KCharsetTag ) != KErrNotFound ) && |
|
1636 |
contentTypeArray.Count() >= ( i+1) ) |
|
1637 |
{ |
|
1638 |
TPtrC value( contentTypeArray.MdcaPoint( i+1 ) ); |
|
1639 |
if ( value.Length() ) |
|
1640 |
{ |
|
1641 |
CleanupStack::PopAndDestroy( charSet ); |
|
1642 |
charSet = NULL; |
|
1643 |
charSet = HBufC8::NewLC( value.Length() ); |
|
1644 |
charSet->Des().Copy( value ); |
|
1645 |
break; |
|
1646 |
} |
|
1647 |
} |
|
1648 |
i++; |
|
1649 |
} |
|
1650 |
||
1651 |
CleanupStack::Pop( charSet ); |
|
1652 |
return charSet; |
|
1653 |
} |
|
1654 |
||
1655 |
void CFsEmailUiHtmlViewerContainer::StopObserving() |
|
1656 |
{ |
|
1657 |
if( iObservingDownload ) |
|
1658 |
{ |
|
1659 |
if ( iMessage && iAppUi.DownloadInfoMediator() ) |
|
1660 |
{ |
|
1661 |
iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() ); |
|
1662 |
} |
|
1663 |
iObservingDownload=EFalse; |
|
1664 |
} |
|
1665 |
} |
|
1666 |
||
1667 |
void CFsEmailUiHtmlViewerContainer::CancelFetch() |
|
1668 |
{ |
|
1669 |
FUNC_LOG; |
|
1670 |
if ( iBrCtlInterface ) |
|
1671 |
{ |
|
1672 |
TRAP_IGNORE( iBrCtlInterface->HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelFetch + (TInt)TBrCtlDefs::ECommandIdBase )); |
|
1673 |
} |
|
1674 |
} |
|
1675 |
||
1676 |
void CFsEmailUiHtmlViewerContainer::ClearCacheAndLoadEmptyContent() |
|
1677 |
{ |
|
1678 |
FUNC_LOG; |
|
1679 |
if ( iBrCtlInterface ) |
|
1680 |
{ |
|
1681 |
iBrCtlInterface->ClearCache(); |
|
1682 |
TUid uid; |
|
1683 |
uid.iUid = KCharacterSetIdentifierUtf8; |
|
1684 |
TRAP_IGNORE( iBrCtlInterface->LoadDataL(KHTMLDataScheme, KHTMLEmptyContent, _L8("text/html"), uid) ); |
|
1685 |
} |
|
1686 |
} |
|
1687 |
||
1688 |
void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType ) |
|
1689 |
{ |
|
1690 |
CCoeControl::HandleResourceChange( aType ); |
|
1691 |
if ( aType == CFsEmailUiViewBase::EScreenLayoutChanged ) |
|
1692 |
{ |
|
1693 |
RefreshCurrentMailHeader(); |
|
1694 |
SetRect( iView.ContainerRect() ); |
|
1695 |
} |
|
1696 |
} |
|
1697 |
||
1698 |
void CFsEmailUiHtmlViewerContainer::RefreshCurrentMailHeader() |
|
1699 |
{ |
|
1700 |
if ( iMessage ) |
|
1701 |
{ |
|
1702 |
// Update the width in header part and reload |
|
1703 |
TPath headerHtmlFile; |
|
1704 |
headerHtmlFile.Copy( iHtmlFolderPath ); |
|
1705 |
headerHtmlFile.Append( KHeaderHtmlFile ); |
|
1706 |
||
1707 |
TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, |
|
1708 |
headerHtmlFile, iAppUi.ClientRect().Width(), iScrollPosition, |
|
1709 |
iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage), |
|
1710 |
iFlags ) ) |
|
1711 |
||
1712 |
||
1713 |
if(!iEventHandler->IsMenuVisible()) |
|
1714 |
{ |
|
1715 |
TRAP_IGNORE( ReloadPageL() ); |
|
1716 |
} |
|
1717 |
else |
|
1718 |
{ |
|
1719 |
//Load page asynchronously after dismissing menu |
|
1720 |
//this is outdated call because it cancels Action menu which is no longer used in 9.2 |
|
1721 |
// iEventHandler->DismissMenuAndReload(); |
|
1722 |
} |
|
1723 |
} |
|
1724 |
} |
|
1725 |
||
1726 |
void CFsEmailUiHtmlViewerContainer::ReloadPageL() |
|
1727 |
{ |
|
1728 |
TRAP_IGNORE( iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase + |
|
1729 |
( TInt )TBrCtlDefs::ECommandReload ) ); |
|
1730 |
} |
|
1731 |
||
1732 |
void CFsEmailUiHtmlViewerContainer::ShowAttachmentDownloadStatusL( |
|
1733 |
TFSProgress::TFSProgressStatus aProgressStatus, |
|
1734 |
const TAttachmentData& aAttachmentData ) |
|
1735 |
{ |
|
1736 |
TBool freshDraw = EFalse; |
|
1737 |
//If the indicator was displaying fetching body then we will be displaying a different indicator |
|
1738 |
//this is just to make sure the image is updated |
|
1739 |
if(iStatusIndicator) |
|
1740 |
{ |
|
1741 |
if (iStatusIndicator->Image()) |
|
1742 |
{ |
|
1743 |
if(iStatusIndicator->Image()->Handle() != iAttachmentDownloadImageHandle) |
|
1744 |
{ |
|
1745 |
freshDraw = ETrue; |
|
1746 |
} |
|
1747 |
} |
|
1748 |
} |
|
1749 |
if ( !iStatusIndicator ) |
|
1750 |
{ |
|
1751 |
TRect rect = CalcAttachmentStatusRect(); |
|
1752 |
iStatusIndicator = CFreestyleEmailUiAknStatusIndicator::NewL( rect, this ); |
|
1753 |
freshDraw = ETrue; |
|
1754 |
} |
|
1755 |
||
1756 |
if ( !iStatusIndicator->IsVisible() |
|
1757 |
|| ( aAttachmentData.downloadProgress == KNone ) |
|
1758 |
|| ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled ) ) |
|
1759 |
{ |
|
1760 |
freshDraw = ETrue; |
|
1761 |
} |
|
1762 |
||
1763 |
TInt duration = KStatusIndicatorDefaultDuration; |
|
1764 |
if ( ( aAttachmentData.downloadProgress == TFSProgress::EFSStatus_RequestComplete ) |
|
1765 |
|| ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled ) |
|
1766 |
|| ( aAttachmentData.downloadProgress == KComplete ) ) |
|
1767 |
{ |
|
1768 |
duration = KStatusIndicatorAutomaticHidingDuration; |
|
1769 |
} |
|
1770 |
||
1771 |
HBufC* statusText = NULL; |
|
1772 |
switch ( aProgressStatus ) |
|
1773 |
{ |
|
1774 |
case TFSProgress::EFSStatus_Status: |
|
1775 |
case TFSProgress::EFSStatus_RequestComplete: |
|
1776 |
{ |
|
1777 |
CDesCArray* descArray = new (ELeave) CDesCArrayFlat( 1 ); |
|
1778 |
CleanupStack::PushL( descArray ); |
|
1779 |
descArray->AppendL( aAttachmentData.fileName ); |
|
1780 |
CArrayFix<TInt>* intArray = new (ELeave) CArrayFixFlat<TInt>( 1 ); |
|
1781 |
CleanupStack::PushL( intArray ); |
|
1782 |
intArray->AppendL( aAttachmentData.downloadProgress ); |
|
1783 |
||
1784 |
statusText = StringLoader::LoadL( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOAD, |
|
1785 |
*descArray, |
|
1786 |
*intArray ); |
|
1787 |
CleanupStack::PopAndDestroy( intArray ); |
|
1788 |
CleanupStack::PopAndDestroy( descArray ); |
|
1789 |
CleanupStack::PushL( statusText ); |
|
1790 |
} |
|
1791 |
break; |
|
1792 |
||
1793 |
case TFSProgress::EFSStatus_RequestCancelled: |
|
1794 |
{ |
|
1795 |
statusText = aAttachmentData.fileName.AllocLC(); |
|
1796 |
} |
|
1797 |
break; |
|
1798 |
||
1799 |
default: |
|
1800 |
statusText = KNullDesC().AllocLC(); |
|
1801 |
break; |
|
1802 |
} |
|
1803 |
||
1804 |
if ( statusText->Length() > 0 ) |
|
1805 |
{ |
|
1806 |
if ( freshDraw ) |
|
1807 |
{ |
|
1808 |
CFbsBitmap* image = NULL; |
|
1809 |
CFbsBitmap* imageMask = NULL; |
|
1810 |
if ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled ) |
|
1811 |
{ |
|
1812 |
iAppUi.FsTextureManager()->ProvideBitmapL(EAttachmentsCancelDownload, image, imageMask ); |
|
1813 |
} |
|
1814 |
else |
|
1815 |
{ |
|
1816 |
iAppUi.FsTextureManager()->ProvideBitmapL(EAttachmentsDownload, image, imageMask ); |
|
1817 |
} |
|
1818 |
if(image) |
|
1819 |
{ |
|
1820 |
iAttachmentDownloadImageHandle = image->Handle(); |
|
1821 |
} |
|
1822 |
iStatusIndicator->ShowIndicatorL( image, imageMask, statusText, duration ); |
|
1823 |
} |
|
1824 |
else |
|
1825 |
{ |
|
1826 |
iStatusIndicator->SetTextL( statusText ); |
|
1827 |
if ( duration > -1 ) |
|
1828 |
{ |
|
1829 |
iStatusIndicator->HideIndicator( duration ); |
|
1830 |
} |
|
1831 |
} |
|
1832 |
} |
|
1833 |
||
1834 |
CleanupStack::Pop( statusText ); |
|
1835 |
} |
|
1836 |
||
1837 |
TBool CFsEmailUiHtmlViewerContainer::AttachmentDownloadStatusVisible() |
|
1838 |
{ |
|
1839 |
if ( iStatusIndicator ) |
|
1840 |
{ |
|
1841 |
return iStatusIndicator->IsVisible(); |
|
1842 |
} |
|
1843 |
else |
|
1844 |
{ |
|
1845 |
return EFalse; |
|
1846 |
} |
|
1847 |
} |
|
1848 |
void CFsEmailUiHtmlViewerContainer::ViewerSettingsChangedL( const TUint32 aKey ) |
|
1849 |
{ |
|
1850 |
FUNC_LOG; |
|
1851 |
if (aKey == KFreestyleEmailDownloadHTMLImages) |
|
1852 |
{ |
|
1853 |
if (iBrCtlInterface) |
|
1854 |
{ |
|
1855 |
iBrCtlInterface->SetBrowserSettingL( |
|
1856 |
TBrCtlDefs::ESettingsAutoLoadImages, |
|
1857 |
iViewerSettings->AutoLoadImages() ); |
|
1858 |
if (iViewerSettings->AutoLoadImages() && iMessage) |
|
1859 |
{ |
|
1860 |
LoadContentFromMailMessageL(iMessage, EFalse); |
|
1861 |
} |
|
1862 |
} |
|
1863 |
} |
|
1864 |
} |
|
1865 |
||
1866 |
void CFsEmailUiHtmlViewerContainer::HideDownloadStatus() |
|
1867 |
{ |
|
1868 |
if ( iStatusIndicator ) |
|
1869 |
{ |
|
1870 |
iStatusIndicator->MakeVisible( EFalse ); |
|
1871 |
} |
|
1872 |
} |
|
1873 |
||
1874 |
TRect CFsEmailUiHtmlViewerContainer::CalcAttachmentStatusRect() |
|
1875 |
{ |
|
1876 |
TRect rect( Rect() ); |
|
1877 |
TPoint topLeft = rect.iTl; |
|
1878 |
TPoint bottomRight = rect.iBr; |
|
1879 |
TPoint statusTopLeft( topLeft.iX + KStatusIndicatorXMargin, bottomRight.iY - KStatusIndicatorHeight + 1 ); |
|
1880 |
TPoint statusBottomRight( bottomRight.iX - KStatusIndicatorXMargin, bottomRight.iY ); |
|
1881 |
rect = TRect(statusTopLeft, statusBottomRight); |
|
1882 |
rect.Move(0, -KStatusIndicatorBottomMargin); |
|
1883 |
return rect; |
|
1884 |
} |
|
1885 |
||
1886 |
void CFsEmailUiHtmlViewerContainer::TouchFeedback() |
|
1887 |
{ |
|
1888 |
iTouchFeedBack->InstantFeedback(this, ETouchFeedbackBasic); |
|
1889 |
} |
|
1890 |
||
1891 |
/** |
|
1892 |
* The body fetch link is cmail://body/fetch. Look for the URL separator |
|
1893 |
* and the presence of cmail and body on the url. |
|
1894 |
* @param aUrl |
|
1895 |
* return ETrue for a valid body URL |
|
1896 |
*/ |
|
1897 |
TBool CFsEmailUiHtmlViewerContainer::IsMessageBodyURLL(const TDesC& aUrl) |
|
1898 |
{ |
|
1899 |
TInt index = aUrl.Find(KURLSchemeSeparator); |
|
1900 |
if (index == KErrNotFound) |
|
1901 |
{ |
|
1902 |
return EFalse; |
|
1903 |
} |
|
1904 |
else |
|
1905 |
{ |
|
1906 |
if (aUrl.Compare(KURLLoadImages()) == 0) |
|
1907 |
{ |
|
1908 |
iBrCtlInterface->HandleCommandL(TBrCtlDefs::ECommandLoadImages + TBrCtlDefs::ECommandIdBase); |
|
1909 |
return ETrue; |
|
1910 |
} |
|
1911 |
else if (aUrl.Compare(KURLDisplayImages()) == 0) |
|
1912 |
{ |
|
1913 |
DisplayStatusIndicatorL(KStatusIndicatorAutomaticHidingDuration); |
|
1914 |
if( iMessage ) |
|
1915 |
{ |
|
1916 |
iAppUi.DisplayImagesCache().AddMessageL(*iMessage); |
|
1917 |
} |
|
1918 |
iBrCtlInterface->HandleCommandL(TBrCtlDefs::ECommandLoadImages + TBrCtlDefs::ECommandIdBase); |
|
1919 |
return ETrue; |
|
1920 |
} |
|
1921 |
else if (aUrl.Compare(KURLCollapseHeader()) == 0) |
|
1922 |
{ |
|
1923 |
TouchFeedback(); |
|
1924 |
iFlags.ClearAll(); |
|
1925 |
return ETrue; |
|
1926 |
} |
|
1927 |
else if (aUrl.Compare(KURLExpandHeader()) == 0) |
|
1928 |
{ |
|
1929 |
TouchFeedback(); |
|
1930 |
iFlags.Set( CFreestyleMessageHeaderHTML::EHeaderExpanded ); |
|
1931 |
return ETrue; |
|
1932 |
} |
|
1933 |
else if ( aUrl.Find( KURLExpandItem() ) == 0 ) { |
|
1934 |
const TPtrC item( aUrl.Mid( KURLExpandItem().Length() ) ); |
|
1935 |
if ( item.Find( KURLItemTo() ) == 0 ) |
|
1936 |
{ |
|
1937 |
iFlags.Assign( CFreestyleMessageHeaderHTML::EToExpanded, ETrue ); |
|
1938 |
} |
|
1939 |
else if ( item.Find( KURLItemCc() ) == 0 ) |
|
1940 |
{ |
|
1941 |
iFlags.Assign( CFreestyleMessageHeaderHTML::ECcExpanded, ETrue ); |
|
1942 |
} |
|
1943 |
else if ( item.Find( KURLItemBcc() ) == 0 ) |
|
1944 |
{ |
|
1945 |
iFlags.Assign( CFreestyleMessageHeaderHTML::EBccExpanded, ETrue ); |
|
1946 |
} |
|
1947 |
else if ( item.Find( KURLItemAttachments() ) == 0 ) |
|
1948 |
{ |
|
1949 |
iFlags.Assign( CFreestyleMessageHeaderHTML::EAttachmentExpanded, ETrue ); |
|
1950 |
} |
|
1951 |
return ETrue; |
|
1952 |
} else if (aUrl.Left(index).CompareF(KURLSchemeCmail) == 0) |
|
1953 |
{ |
|
1954 |
TInt bodyIndex = aUrl.Find(KURLTypeBody); |
|
1955 |
if (bodyIndex == KErrNotFound) |
|
1956 |
{ |
|
1957 |
return EFalse; |
|
1958 |
} |
|
1959 |
else |
|
1960 |
{ |
|
1961 |
TPtrC16 data= aUrl.Mid(bodyIndex); |
|
1962 |
TInt separator = data.Find(KURLSlash); |
|
1963 |
if(separator == KErrNotFound) |
|
1964 |
{ |
|
1965 |
return EFalse; |
|
1966 |
} |
|
1967 |
else |
|
1968 |
{ |
|
1969 |
TPtrC16 temp = data.Mid(separator+1); |
|
1970 |
TLex lex(temp); |
|
1971 |
lex.Val(iScrollPosition); |
|
1972 |
} |
|
1973 |
return ETrue; |
|
1974 |
} |
|
1975 |
||
1976 |
} |
|
1977 |
else |
|
1978 |
{ |
|
1979 |
return EFalse; |
|
1980 |
} |
|
1981 |
} |
|
1982 |
} |
|
1983 |
||
1984 |
// --------------------------------------------------------------------------- |
|
1985 |
// From MBrCtlWindowObserver |
|
1986 |
// --------------------------------------------------------------------------- |
|
1987 |
// |
|
1988 |
CBrCtlInterface* CFsEmailUiHtmlViewerContainer::OpenWindowL( TDesC& /*aUrl*/, TDesC* /*aTargetName*/, |
|
1989 |
TBool /*aUserInitiated*/, TAny* /*aReserved*/ ) |
|
1990 |
{ |
|
1991 |
return iBrCtlInterface; |
|
1992 |
} |
|
1993 |
||
1994 |
// --------------------------------------------------------------------------- |
|
1995 |
// From MBrCtlWindowObserver |
|
1996 |
// --------------------------------------------------------------------------- |
|
1997 |
// |
|
1998 |
CBrCtlInterface* CFsEmailUiHtmlViewerContainer::FindWindowL( const TDesC& /*aTargetName*/ ) const |
|
1999 |
{ |
|
2000 |
return NULL; |
|
2001 |
} |
|
2002 |
||
2003 |
// --------------------------------------------------------------------------- |
|
2004 |
// From MBrCtlWindowObserver |
|
2005 |
// --------------------------------------------------------------------------- |
|
2006 |
// |
|
2007 |
void CFsEmailUiHtmlViewerContainer::HandleWindowCommandL( const TDesC& /*aTargetName*/, |
|
2008 |
TBrCtlWindowCommand /*aCommand*/ ) |
|
2009 |
{ |
|
2010 |
||
2011 |
} |
|
2012 |
||
2013 |
// --------------------------------------------------------------------------- |
|
2014 |
// Check if a tap on the URL requires browser(standalone) to be launched |
|
2015 |
// --------------------------------------------------------------------------- |
|
2016 |
// |
|
2017 |
TBool CFsEmailUiHtmlViewerContainer::NeedToLaunchBrowserL( const TDesC& aUrl ) |
|
2018 |
{ |
|
2019 |
TBool launchBrowser( ETrue ); |
|
2020 |
// look for file:/// |
|
2021 |
_LIT( KFileLink, "file:///"); |
|
2022 |
_LIT( KUrlLink, "http"); |
|
2023 |
||
2024 |
// This might be linking to header.html or body.html frames |
|
2025 |
// Ignore them. |
|
2026 |
if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 ) |
|
2027 |
{ |
|
2028 |
//Now there is a chance that this could be from HTML folder |
|
2029 |
// Replace all slash character with backslash characters |
|
2030 |
HBufC* embeddedUrl = aUrl.AllocLC(); |
|
2031 |
TPtr ptr = embeddedUrl->Des(); |
|
2032 |
||
2033 |
_LIT( KBackslash, "\\" ); |
|
2034 |
for ( TInt pos = ptr.Locate('/'); pos >= 0; pos = ptr.Locate('/') ) |
|
2035 |
{ |
|
2036 |
ptr.Replace( pos, 1, KBackslash ); |
|
2037 |
} |
|
2038 |
||
2039 |
// Check whether given url refers to file in the html folder |
|
2040 |
TInt pos = embeddedUrl->FindF( iHtmlFolderPath ); |
|
2041 |
CleanupStack::PopAndDestroy( embeddedUrl ); |
|
2042 |
pos >= 0 ? launchBrowser = EFalse : ETrue; |
|
2043 |
} |
|
2044 |
// Ignore links starting with cmail:// |
|
2045 |
else if ( aUrl.Left( KURLSchemeCmail().Length() ).CompareF( KURLSchemeCmail ) == 0 ) |
|
2046 |
{ |
|
2047 |
launchBrowser = EFalse; |
|
2048 |
} |
|
2049 |
// THAA-82BEAZ - show popup first |
|
2050 |
else if ( aUrl.Left(KUrlLink().Length() ).CompareF( KUrlLink ) == 0 ) |
|
2051 |
{ |
|
2052 |
launchBrowser = EFalse; |
|
2053 |
} |
|
2054 |
// end THAA-82BEAZ |
|
2055 |
||
2056 |
return launchBrowser; |
|
2057 |
} |
|
2058 |
||
2059 |
// --------------------------------------------------------------------------- |
|
2060 |
// Launch the browser as a standalone app |
|
2061 |
// --------------------------------------------------------------------------- |
|
2062 |
// |
|
2063 |
void CFsEmailUiHtmlViewerContainer::LaunchBrowserL( const TDesC& aUrl ) |
|
2064 |
{ |
|
2065 |
CSchemeHandler* handler = CSchemeHandler::NewL( aUrl ); |
|
2066 |
CleanupStack::PushL( handler ); |
|
2067 |
handler->HandleUrlStandaloneL(); |
|
2068 |
CleanupStack::PopAndDestroy( handler ); |
|
2069 |
} |
|
2070 |
||
2071 |
void CFsEmailUiHtmlViewerContainer::PrepareBodyHtmlL( const TDesC& aFileName ) |
|
2072 |
{ |
|
2073 |
||
2074 |
if( iMessage ) |
|
2075 |
{ |
|
2076 |
CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL(); |
|
2077 |
||
2078 |
if ( htmlBodyPart ) |
|
2079 |
{ |
|
2080 |
CleanupStack::PushL( htmlBodyPart ); |
|
2081 |
// Copy html body part to email html file |
|
2082 |
CopyToHtmlFileL( *htmlBodyPart, aFileName ); |
|
2083 |
CleanupStack::PopAndDestroy( htmlBodyPart ); |
|
2084 |
} |
|
2085 |
else |
|
2086 |
{ |
|
2087 |
CFSMailMessagePart* textBodyPart = iMessage->PlainTextBodyPartL(); |
|
2088 |
||
2089 |
if ( textBodyPart ) |
|
2090 |
{ |
|
2091 |
CleanupStack::PushL( textBodyPart ); |
|
2092 |
// Copy html body part to email html file |
|
2093 |
ConvertToHtmlFileL( *textBodyPart, aFileName ); |
|
2094 |
CleanupStack::PopAndDestroy( textBodyPart ); |
|
2095 |
} |
|
2096 |
else |
|
2097 |
{ |
|
2098 |
User::Leave( KErrNotFound ); |
|
2099 |
} |
|
2100 |
} |
|
2101 |
} |
|
2102 |
} |
|
2103 |
||
2104 |
void CFsEmailUiHtmlViewerContainer::WriteEmptyBodyHtmlL( const TDesC& aFileName ) |
|
2105 |
{ |
|
2106 |
FUNC_LOG; |
|
2107 |
TFileName targetFileName; |
|
2108 |
targetFileName.Copy( iTempHtmlFolderPath ); |
|
2109 |
targetFileName.Append( aFileName ); |
|
2110 |
||
2111 |
RFile targetFile; |
|
2112 |
CleanupClosePushL( targetFile ); |
|
2113 |
User::LeaveIfError( targetFile.Replace( iFs, targetFileName, EFileWrite ) ); |
|
2114 |
User::LeaveIfError( targetFile.Write( KHTMLEmptyContent ) ); |
|
2115 |
CleanupStack::PopAndDestroy( &targetFile ); |
|
2116 |
} |
|
2117 |
||
2118 |
void CFsEmailUiHtmlViewerContainer::DisplayStatusIndicatorL(TInt aDuration) |
|
2119 |
{ |
|
2120 |
FUNC_LOG; |
|
2121 |
TRect rect = CalcAttachmentStatusRect(); |
|
2122 |
if(!iStatusIndicator) |
|
2123 |
{ |
|
2124 |
iStatusIndicator = CFreestyleEmailUiAknStatusIndicator::NewL( rect, this ); |
|
2125 |
} |
|
2126 |
CFbsBitmap* image = NULL; |
|
2127 |
CFbsBitmap* imageMask = NULL; |
|
2128 |
HBufC* statusText = NULL; |
|
2129 |
statusText = StringLoader::LoadL(R_FREESTYLE_EMAIL_UI_VIEWER_FETCHING_CONTENT_TEXT); |
|
2130 |
iAppUi.FsTextureManager()->ProvideBitmapL(EStatusTextureSynchronising, image, imageMask ); |
|
2131 |
iStatusIndicator->ShowIndicatorL( image, imageMask, statusText, aDuration, ETrue ); |
|
2132 |
} |
|
2133 |
||
2134 |
void CFsEmailUiHtmlViewerContainer::MailListModelUpdatedL() |
|
2135 |
{ |
|
2136 |
FUNC_LOG; |
|
2137 |
UpdateOverlayButtons( IsVisible() ); |
|
2138 |
} |
|
2139 |
||
2140 |
||
2141 |
void CFsEmailUiHtmlViewerContainer::WriteToFileL(const TDesC& aFileName, RBuf& aHtmlText) |
|
2142 |
{ |
|
2143 |
_LIT( KCharsetUtf8, "UTF-8" ); |
|
2144 |
||
2145 |
HBufC8* content8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aHtmlText ); |
|
2146 |
CleanupStack::PushL( content8 ); |
|
2147 |
||
2148 |
RFile targetFile; |
|
2149 |
CleanupClosePushL( targetFile ); |
|
2150 |
User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); |
|
2151 |
||
2152 |
RBuf8 messageHeader; |
|
2153 |
TInt bufSize = KHtmlHeader1().Length() + KCharsetUtf8().Length() + KHtmlHeader2().Length(); |
|
2154 |
messageHeader.CreateL( bufSize ); |
|
2155 |
messageHeader.CleanupClosePushL(); |
|
2156 |
||
2157 |
messageHeader.Append( KHtmlHeader1 ); |
|
2158 |
messageHeader.Append( KCharsetUtf8 ); |
|
2159 |
messageHeader.Append( KHtmlHeader2 ); |
|
2160 |
||
2161 |
RFileWriteStream fileStream( targetFile ); |
|
2162 |
fileStream.PushL(); |
|
2163 |
fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() ); |
|
2164 |
||
2165 |
TInt bufPos( 0 ); |
|
2166 |
TInt bufTotalSize = content8->Size(); |
|
2167 |
||
2168 |
while ( bufPos < bufTotalSize ) |
|
2169 |
{ |
|
2170 |
TInt segmentLength = content8->Mid( bufPos ).Length(); |
|
2171 |
fileStream.WriteL( content8->Mid( bufPos ).Ptr(), segmentLength ); |
|
2172 |
bufPos += segmentLength; |
|
2173 |
} |
|
2174 |
||
2175 |
fileStream.CommitL(); |
|
2176 |
||
2177 |
CleanupStack::PopAndDestroy( &fileStream ); |
|
2178 |
CleanupStack::PopAndDestroy( &messageHeader ); |
|
2179 |
CleanupStack::PopAndDestroy( &targetFile ); |
|
2180 |
CleanupStack::PopAndDestroy( content8 ); |
|
2181 |
} |
|
2182 |
||
26
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2183 |
HBufC* CFsEmailUiHtmlViewerContainer::CreateModifiedUrlIfNeededL( |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2184 |
const TDesC& aUrl ) |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2185 |
{ |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2186 |
_LIT( KFileLink, "file:///"); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2187 |
HBufC* modifiedUrl = NULL; |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2188 |
|
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2189 |
// check if this really is file-URL |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2190 |
if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 ) |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2191 |
{ |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2192 |
// convert URL-style slashes to backslashes |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2193 |
_LIT( KBackslash, "\\" ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2194 |
HBufC* url = aUrl.Mid( KFileLink().Length() ).AllocLC(); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2195 |
TPtr urlPtr = url->Des(); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2196 |
for ( TInt pos = urlPtr.Locate('/'); pos >= 0; pos = urlPtr.Locate('/') ) |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2197 |
{ |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2198 |
urlPtr.Replace( pos, 1, KBackslash ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2199 |
} |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2200 |
// check if the file exists, if not convert the file-URL to http-URL |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2201 |
// (i.e., remove the whole path and replace the prefix with "http:") |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2202 |
if ( !BaflUtils::FileExists( iFs, *url ) ) |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2203 |
{ |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2204 |
TInt pos = url->FindF( iTempHtmlFolderPath ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2205 |
if ( pos >= 0 ) |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2206 |
{ |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2207 |
_LIT( KHttpPrefix, "http://" ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2208 |
TPtrC filename = url->Mid( pos + iTempHtmlFolderPath.Length() ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2209 |
modifiedUrl = HBufC::NewL( filename.Length() + KHttpPrefix().Length() ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2210 |
TPtr modifiedPtr = modifiedUrl->Des(); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2211 |
modifiedPtr.Append( KHttpPrefix ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2212 |
modifiedPtr.Append( filename ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2213 |
} |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2214 |
} |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2215 |
CleanupStack::PopAndDestroy( url ); |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2216 |
} |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2217 |
return modifiedUrl; |
968773a0b6ef
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
2218 |
} |
25 | 2219 |
|
2220 |
||
2221 |
/****************************************************************************** |
|
2222 |
* class PlainTextToHtmlConverter |
|
2223 |
******************************************************************************/ |
|
2224 |
||
2225 |
||
2226 |
||
2227 |
// ----------------------------------------------------------------------------- |
|
2228 |
// PlainTextToHtmlConverter::PlainTextToHtmlL |
|
2229 |
// |
|
2230 |
// ----------------------------------------------------------------------------- |
|
2231 |
// |
|
2232 |
void PlainTextToHtmlConverter::PlainTextToHtmlL(const TDesC& aPlainText, RBuf& aHtmlText) |
|
2233 |
{ |
|
2234 |
const TInt KAllocSize = 1024; |
|
2235 |
||
2236 |
aHtmlText.Close(); |
|
2237 |
aHtmlText.Create( aPlainText.Length() + KAllocSize ); |
|
2238 |
||
2239 |
const TInt searhCases( CFindItemEngine::EFindItemSearchURLBin ); |
|
2240 |
CFindItemEngine* itemEngine = CFindItemEngine::NewL( aPlainText, CFindItemEngine::TFindItemSearchCase( searhCases ) ); |
|
2241 |
CleanupStack::PushL ( itemEngine ); |
|
2242 |
||
2243 |
TInt currentPos = 0; |
|
2244 |
CFindItemEngine::SFoundItem item; |
|
2245 |
for ( TBool available(itemEngine->Item(item)); available; available=itemEngine->NextItem(item) ) |
|
2246 |
{ |
|
2247 |
if ( item.iStartPos < currentPos ) |
|
2248 |
{ |
|
2249 |
break; |
|
2250 |
} |
|
2251 |
||
2252 |
TPtrC textPtr = aPlainText.Mid( currentPos, item.iStartPos-currentPos ); |
|
2253 |
ConvertTextL( textPtr, aHtmlText ); |
|
2254 |
||
2255 |
TPtrC urlPtr = aPlainText.Mid( item.iStartPos, item.iLength ); |
|
2256 |
ConvertUrlL( urlPtr, aHtmlText); |
|
2257 |
||
2258 |
currentPos = item.iStartPos + item.iLength; |
|
2259 |
} |
|
2260 |
||
2261 |
TInt len = aPlainText.Length(); |
|
2262 |
if ( currentPos < len ) |
|
2263 |
{ |
|
2264 |
TPtrC textPtr = aPlainText.Mid( currentPos ); |
|
2265 |
ConvertTextL( textPtr, aHtmlText ); |
|
2266 |
} |
|
2267 |
||
2268 |
CleanupStack::PopAndDestroy( itemEngine ); |
|
2269 |
} |
|
2270 |
||
2271 |
||
2272 |
// ----------------------------------------------------------------------------- |
|
2273 |
// PlainTextToHtmlConverter::ConvertTextL |
|
2274 |
// |
|
2275 |
// ----------------------------------------------------------------------------- |
|
2276 |
// |
|
2277 |
void PlainTextToHtmlConverter::ConvertTextL(const TDesC& aSource, RBuf& aTarget) |
|
2278 |
{ |
|
2279 |
const TInt KAllocSize = 1024; |
|
2280 |
const TInt KEntitySize = 32; |
|
2281 |
||
2282 |
TInt count = aSource.Length(); |
|
2283 |
for ( TInt i=0; i<count; i++ ) |
|
2284 |
{ |
|
2285 |
if ( aTarget.Length() + KEntitySize >= aTarget.MaxLength() ) |
|
2286 |
{ |
|
2287 |
aTarget.ReAllocL( aTarget.MaxLength() + KAllocSize ); |
|
2288 |
} |
|
2289 |
||
2290 |
TText ch = aSource[i]; |
|
2291 |
switch( ch ) |
|
2292 |
{ |
|
2293 |
case KSOH: // end of line for IMAP and POP |
|
2294 |
aTarget.Append( KHtmlLineBreakCRLF ); |
|
2295 |
break; |
|
2296 |
case KLF: // line feed |
|
2297 |
case KUnicodeNewLineCharacter: |
|
2298 |
case KUnicodeParagraphCharacter: |
|
2299 |
aTarget.Append(KHtmlLineBreak); |
|
2300 |
break; |
|
2301 |
case KQuotation: |
|
2302 |
aTarget.Append( KHtmlQuotation ); |
|
2303 |
break; |
|
2304 |
case KAmpersand: |
|
2305 |
aTarget.Append( KHtmlAmpersand ); |
|
2306 |
break; |
|
2307 |
case KGreaterThan: |
|
2308 |
aTarget.Append( KHtmlGreaterThan ); |
|
2309 |
break; |
|
2310 |
case KLessThan: |
|
2311 |
aTarget.Append( KHtmlLessThan ); |
|
2312 |
break; |
|
2313 |
default: |
|
2314 |
aTarget.Append( ch ); |
|
2315 |
break; |
|
2316 |
} |
|
2317 |
} |
|
2318 |
} |
|
2319 |
||
2320 |
||
2321 |
// ----------------------------------------------------------------------------- |
|
2322 |
// PlainTextToHtmlConverter::ConvertUrlL |
|
2323 |
// |
|
2324 |
// ----------------------------------------------------------------------------- |
|
2325 |
// |
|
2326 |
void PlainTextToHtmlConverter::ConvertUrlL(const TDesC& aSource, RBuf& aTarget) |
|
2327 |
{ |
|
2328 |
_LIT( KSchemeDelimiter, "://" ); |
|
2329 |
_LIT( KUrlFormat, "<a href=\"%S\">%S</a>" ); |
|
2330 |
_LIT( KUrlFormatWithHttp, "<a href=\"http://%S\">%S</a>" ); |
|
2331 |
||
2332 |
TPtrC format( KUrlFormat() ); |
|
2333 |
if ( aSource.FindF( KSchemeDelimiter() ) == KErrNotFound ) |
|
2334 |
{ |
|
2335 |
format.Set( KUrlFormatWithHttp() ); |
|
2336 |
} |
|
2337 |
||
2338 |
HBufC* formatBuffer = HBufC::NewLC( format.Length() + aSource.Length() * 2 ); |
|
2339 |
formatBuffer->Des().Format( format, &aSource, &aSource ); |
|
2340 |
||
2341 |
TInt len = formatBuffer->Des().Length(); |
|
2342 |
if ( aTarget.Length() + len >= aTarget.MaxLength() ) |
|
2343 |
{ |
|
2344 |
aTarget.ReAllocL( aTarget.MaxLength() + len ); |
|
2345 |
} |
|
2346 |
||
2347 |
aTarget.Append( *formatBuffer ); |
|
2348 |
||
2349 |
CleanupStack::PopAndDestroy( formatBuffer ); |
|
2350 |
} |