|
1 /* |
|
2 * Copyright (c) 2004,2005 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: This class provides helper functions and a reference |
|
15 * implementation for hyperlink handling, image fetching |
|
16 * and saving of the svg content. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include <browserlauncher.h> |
|
22 #include <DocumentHandler.h> |
|
23 #include <uri16.h> |
|
24 #include <uriutils.h> |
|
25 #include <eikenv.h> |
|
26 #include <eikappui.h> |
|
27 #include <eikapp.h> |
|
28 #include <eikdef.h> |
|
29 #include <flogger.h> |
|
30 #include <cdownloadmgruiuserinteractions.h> |
|
31 #include <cdownloadmgruidownloadslist.h> |
|
32 #include <cdownloadmgruilibregistry.h> |
|
33 #include <browseroverriddensettings.h> |
|
34 |
|
35 #ifdef __SERIES60_NATIVE_BROWSER |
|
36 #include <browseruisdkcrkeys.h> // Include only if s60 native |
|
37 // browser available |
|
38 #endif |
|
39 |
|
40 #include <centralrepository.h> |
|
41 #include <apgtask.h> // TApaTaskList |
|
42 #include <apmstd.h> // RApaLsSession |
|
43 #include <commdb.h> |
|
44 #include <ApDataHandler.h> // CApDataHandler |
|
45 #include <ApAccessPointItem.h> // CApAccessPointItem |
|
46 #include <ApUtils.h> // CApUtils |
|
47 #include <ApSelect.h> // CApSelect |
|
48 #include <aknnotewrappers.h> |
|
49 #include <AknGlobalNote.h> |
|
50 #include <AknWaitDialog.h> |
|
51 #include <AknCommonDialogs.h> |
|
52 #include <AknProgressDialog.h> |
|
53 #include <StringLoader.h> |
|
54 #include <data_caging_path_literals.hrh> |
|
55 #include <bautils.h> |
|
56 #include <eikprogi.h> |
|
57 #include <e32svr.h> |
|
58 #include <svgtappobserverutil.rsg> |
|
59 #include <SVGTAppObserverUtil.h> |
|
60 #include <pathinfo.h> |
|
61 #include <sysutil.h> |
|
62 #include <imcvcodc.h> //TImCodecB64 |
|
63 #include <AiwGenericParam.h> |
|
64 |
|
65 #include "SVGTViewerAppDbgFlags.hrh" |
|
66 #include "SVGTViewerAppDownloads.h" |
|
67 #include "SVGTAppObserver.h" // temp |
|
68 #include "SVGTUIDialog.h" // AppDialog |
|
69 #include "SVGTUIDialog.hrh" |
|
70 |
|
71 #ifdef RD_MULTIPLE_DRIVE |
|
72 #include <AknCommonDialogsDynMem.h> |
|
73 #endif |
|
74 // CONSTANTS |
|
75 |
|
76 _LIT( KBrowserParameter, "4" ); // magic number for browser to open the URL |
|
77 _LIT( KSpace, " " ); |
|
78 |
|
79 _LIT(KJpg, ".jpg" ); |
|
80 _LIT(KJpeg, ".jpeg" ); |
|
81 _LIT(KPng, ".png" ); |
|
82 _LIT(KBmp, ".bmp" ); |
|
83 _LIT(KSvg, ".svg" ); |
|
84 _LIT(KSvgz, ".svgz" ); |
|
85 |
|
86 #ifndef __SERIES60_NATIVE_BROWSER |
|
87 // Below constants need to be used if s60 native browser is not used. |
|
88 const TUid KCRUidBrowser = {0x10008D39}; |
|
89 const TUint32 KBrowserDefaultAccessPoint = 0x0000000E; |
|
90 #endif // __S60_REMOVE_BROWSER |
|
91 |
|
92 // SMIL Fit Value |
|
93 _LIT( KSvgtDefSmilFitValue,"meet" ); |
|
94 // Resource file for App Observer Util |
|
95 _LIT( KResourceFileName, "Z:SVGTAppObserverUtil.rsc" ); |
|
96 |
|
97 _LIT( KEmptyString, "" ); |
|
98 _LIT( KWww, "www" ); |
|
99 _LIT( KHttp, "http://"); |
|
100 _LIT( KDotDot, ".." ); |
|
101 _LIT( KBSlashStr, "/" ); |
|
102 _LIT( KSlashStr, "\\" ); |
|
103 _LIT( KDotSlashStr, ".\\" ); |
|
104 _LIT( KColonStr, ":" ); |
|
105 _LIT( KNewLineStr, "\n" ); |
|
106 |
|
107 #ifdef SVGTVIEWERAPP_DBG_FLAG |
|
108 _LIT( KFileLoggingDir, "SVGTViewer" ); |
|
109 _LIT( KFileLog, "SaveLog.txt" ); |
|
110 #endif |
|
111 |
|
112 // Maximum length of thread Id in Characters |
|
113 const TInt KSvgMaxThreadIdStr = 10; |
|
114 |
|
115 // ============================ MEMBER FUNCTIONS =============================== |
|
116 |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CSVGTAppObserverUtil::NewL |
|
120 // Two-phased constructor. |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 EXPORT_C CSVGTAppObserverUtil* CSVGTAppObserverUtil::NewL( |
|
124 CSVGTUIDialog* aAppDialog, |
|
125 RFile* aFileHdlPtr, |
|
126 const TDesC& aFilename, |
|
127 TBool aIsFileFullPathAvailable, |
|
128 TBool aCanSaveContent, |
|
129 TBool aShouldMoveContent) |
|
130 { |
|
131 CSVGTAppObserverUtil* self = |
|
132 CSVGTAppObserverUtil::NewLC( aAppDialog, |
|
133 aFileHdlPtr, |
|
134 aFilename, |
|
135 aIsFileFullPathAvailable, |
|
136 aCanSaveContent, |
|
137 aShouldMoveContent ); |
|
138 CleanupStack::Pop( self ); |
|
139 return self; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CSVGTAppObserverUtil::NewLC |
|
144 // Two-phased constructor. |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 CSVGTAppObserverUtil* CSVGTAppObserverUtil::NewLC( CSVGTUIDialog* aAppDialog, |
|
148 RFile* aFileHdlPtr, |
|
149 const TDesC& aFilename, |
|
150 TBool aIsFileFullPathAvailable, |
|
151 TBool aCanSaveContent, |
|
152 TBool aShouldMoveContent) |
|
153 { |
|
154 CSVGTAppObserverUtil* self = |
|
155 new( ELeave ) CSVGTAppObserverUtil( aAppDialog ); |
|
156 CleanupStack::PushL( self ); |
|
157 self->ConstructL( aFileHdlPtr, aFilename, aIsFileFullPathAvailable, |
|
158 aCanSaveContent, aShouldMoveContent ); |
|
159 return self; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CSVGTAppObserverUtil::NewL |
|
164 // Two-phased constructor. |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C CSVGTAppObserverUtil* CSVGTAppObserverUtil::NewL( |
|
168 CSVGTUIDialog* aAppDialog, |
|
169 RFile* aFileHdlPtr ) |
|
170 { |
|
171 CSVGTAppObserverUtil* self = |
|
172 CSVGTAppObserverUtil::NewLC( aAppDialog, |
|
173 aFileHdlPtr ); |
|
174 CleanupStack::Pop( self ); |
|
175 return self; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CSVGTAppObserverUtil::NewLC |
|
180 // Two-phased constructor. |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 CSVGTAppObserverUtil* CSVGTAppObserverUtil::NewLC( |
|
184 CSVGTUIDialog* aAppDialog, |
|
185 RFile* aFileHdlPtr ) |
|
186 { |
|
187 CSVGTAppObserverUtil* self = |
|
188 new( ELeave ) CSVGTAppObserverUtil( aAppDialog ); |
|
189 CleanupStack::PushL( self ); |
|
190 |
|
191 self->ConstructL( aFileHdlPtr ); |
|
192 return self; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // Destructor |
|
197 // ----------------------------------------------------------------------------- |
|
198 EXPORT_C CSVGTAppObserverUtil::~CSVGTAppObserverUtil() |
|
199 { |
|
200 |
|
201 #ifdef SVGTVIEWERAPP_DOWNLOADMGR_ENABLED |
|
202 |
|
203 CSVGTViewerAppDownloads* downloads; |
|
204 |
|
205 iDownloadIter.SetToFirst(); |
|
206 while ((downloads = iDownloadIter++) != NULL) |
|
207 { |
|
208 downloads->QueLink().Deque(); |
|
209 delete downloads; |
|
210 iDownloadIter.SetToFirst(); |
|
211 } |
|
212 |
|
213 // Close the DMgr UI Library first, as it uses the same |
|
214 // Download Manager session that the Viewer uses |
|
215 delete iDMgrUiReg; |
|
216 |
|
217 // Close the Download Manager connection |
|
218 iDownloadMgr.Close(); |
|
219 |
|
220 iDMgrDownloadsList = NULL; |
|
221 iDMgrUserInteractions = NULL; |
|
222 #endif |
|
223 // Reset the app dialog, it is already freed in OpenFileL |
|
224 iAppDialog = NULL; |
|
225 |
|
226 delete iFileManager; |
|
227 delete iSvgFileName; |
|
228 delete iSvgDstFileName; |
|
229 delete iDocHandler; |
|
230 |
|
231 delete iWaitNote; |
|
232 delete iTempFileName; |
|
233 if ( iResourceOffset != 0 ) |
|
234 { |
|
235 iEikEnv->DeleteResourceFile( iResourceOffset ); |
|
236 } |
|
237 |
|
238 // Reset the SVG File Handle as it is owned by the caller |
|
239 iSvgFileId = NULL; |
|
240 // Reset the Progress Info implementor pointer |
|
241 iProgressInfo = NULL; |
|
242 // Reset Environment pointer |
|
243 iEikEnv = NULL; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CSVGTAppObserverUtil::FetchImage |
|
248 // Called by Svg engine when there is an image tag encountered in the svg file |
|
249 // parameters: |
|
250 // aUri: the uri that needs to be downloaded or fetched locally |
|
251 // aSession: File Session in which the file is opened. |
|
252 // aFileHandle: handle of the downloaded file or locally fetched file. |
|
253 // return value: |
|
254 // KErrNone if the file is fetched successfully |
|
255 // KErrNotFound if the file could not be fetched. |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 EXPORT_C TInt CSVGTAppObserverUtil::FetchImage( |
|
259 const TDesC& aUri , RFs& aSession , |
|
260 RFile& aFileHandle ) |
|
261 { |
|
262 TInt ret = KErrNone; |
|
263 |
|
264 TDownloadNeeded downloadNeeded = ELocalImageFile; |
|
265 TRAPD( error, downloadNeeded = IsDownloadNeededL( aUri ) ); |
|
266 |
|
267 if ( error != KErrNone ) |
|
268 { |
|
269 return KErrNotFound; |
|
270 } |
|
271 |
|
272 if ( downloadNeeded == ELocalImageFile ) |
|
273 { |
|
274 TFileName fileName; |
|
275 if ( GetLocalFile( aUri, fileName, *iSvgFileName ) ) |
|
276 { |
|
277 return aFileHandle.Open( aSession, fileName, EFileShareAny ); |
|
278 } |
|
279 else |
|
280 { |
|
281 return KErrNotFound; |
|
282 } |
|
283 } |
|
284 else if ( downloadNeeded == ERemoteImageFile ) |
|
285 { |
|
286 TRAPD( err,ret = StartDownloadingImageL( aUri, |
|
287 aSession, |
|
288 aFileHandle, |
|
289 EFalse, |
|
290 EFalse /* Asynchronous mode */) ); |
|
291 if ( err != KErrNone ) |
|
292 { |
|
293 return KErrNotFound; |
|
294 } |
|
295 else |
|
296 { |
|
297 return ret; |
|
298 } |
|
299 |
|
300 } |
|
301 else |
|
302 { |
|
303 return KErrNotFound; |
|
304 } |
|
305 |
|
306 } |
|
307 |
|
308 TInt CSVGTAppObserverUtil::FetchFont( const TDesC& /* aUri */, |
|
309 RFs& /* aSession */, RFile& /* aFileHandle */ ) |
|
310 { |
|
311 return KErrNotSupported; |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // CSVGTAppObserverUtil::LinkActivated |
|
316 // Callback Function called by svg engine when a hyperlink is activated |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 |
|
320 EXPORT_C TBool CSVGTAppObserverUtil::LinkActivated( const TDesC& aUri ) |
|
321 { |
|
322 if( aUri.Length() == 0 ) |
|
323 { |
|
324 return KErrNone; |
|
325 } |
|
326 TRAPD( error, LinkActivatedL( aUri ) ); |
|
327 return ( error == KErrNone ); |
|
328 } |
|
329 |
|
330 |
|
331 // -------------------------------------------------------------------- |
|
332 // CSVGTAppObserverUtil::LinkActivatedWithShow |
|
333 // Callback Function called by the svg engine when a hyperlink with show |
|
334 // attribute is activated |
|
335 // -------------------------------------------------------------------- |
|
336 // |
|
337 EXPORT_C TBool CSVGTAppObserverUtil::LinkActivatedWithShow( |
|
338 const TDesC& aUri , |
|
339 const TDesC& aShow ) |
|
340 { |
|
341 if( aUri.Length() == 0 ) |
|
342 { |
|
343 return KErrNone; |
|
344 } |
|
345 TRAPD( error, LinkActivatedWithShowL( aUri, aShow ) ); |
|
346 return ( error == KErrNone ); |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CSVGTAppObserverUtil::GetSmilFitValue |
|
351 // Default implementation for observer function to get SMIL fit value. |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 EXPORT_C void CSVGTAppObserverUtil::GetSmilFitValue( TDes& aSmilValue ) |
|
355 { |
|
356 aSmilValue.Copy( KSvgtDefSmilFitValue ); |
|
357 } |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // CSVGTAppObserverUtil::SetDownloadMenu |
|
361 // Sets/Unsets the iDownloadMenuEnabled |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 |
|
365 EXPORT_C void CSVGTAppObserverUtil::SetDownloadMenu( TBool aAddDownloadMenu ) |
|
366 { |
|
367 iDownloadMenuEnabled = aAddDownloadMenu; |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CSVGTAppObserverUtil::SetDownloadMenu |
|
372 // Sets/Unsets the iDownloadMenuEnabled |
|
373 // ----------------------------------------------------------------------------- |
|
374 // |
|
375 EXPORT_C TBool CSVGTAppObserverUtil::CanShowDownload() const |
|
376 { |
|
377 if(iDownloadInProgress || iDownloadDone) |
|
378 { |
|
379 const CDownloadArray& array = iDownloadMgr.CurrentDownloads(); |
|
380 return ( array.Count() ? ETrue : EFalse ); |
|
381 } |
|
382 |
|
383 return EFalse; |
|
384 } |
|
385 |
|
386 // -------------------------------------------------------------------- |
|
387 // void CSVGTAppObserverUtil::DisplayDownloadMenuL() |
|
388 // Call back called by the UI dialog when the downloads menu is |
|
389 // selected. This function calls the DisplayDownloadsListL function |
|
390 // provided by the download manager ui lib. |
|
391 // -------------------------------------------------------------------- |
|
392 // |
|
393 EXPORT_C void CSVGTAppObserverUtil::DisplayDownloadMenuL() |
|
394 { |
|
395 #ifdef SVGTVIEWERAPP_DOWNLOADMGR_ENABLED |
|
396 if ( iDMgrDownloadsList ) |
|
397 { |
|
398 TRAPD( error, iDMgrDownloadsList->DisplayDownloadsListL() ); |
|
399 { |
|
400 if ( error != KErrNone ) |
|
401 { |
|
402 #ifdef _DEBUG |
|
403 TBuf<64> buffer; |
|
404 _LIT(msg, "AP error : %d" ); |
|
405 buffer.Format( msg, error ); |
|
406 iEikEnv->InfoMsg( buffer ); |
|
407 #endif |
|
408 } |
|
409 } |
|
410 } |
|
411 #endif |
|
412 } |
|
413 |
|
414 // ----------------------------------------------------------------------------- |
|
415 // CSVGTAppObserverUtil::HandleDMgrEventL |
|
416 // Called by Download manager when the image is being downloaded. |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 EXPORT_C void CSVGTAppObserverUtil::HandleDMgrEventL( RHttpDownload& aDownload, |
|
420 THttpDownloadEvent aEvent ) |
|
421 { |
|
422 |
|
423 #ifdef SVGTVIEWERAPP_DOWNLOADMGR_ENABLED |
|
424 |
|
425 #ifdef _DEBUG |
|
426 TBuf<64> buffer; |
|
427 _LIT(msg, "download progressing : %d, %d" ); |
|
428 buffer.Format( msg, aEvent.iDownloadState, aEvent.iProgressState ); |
|
429 iEikEnv->InfoMsg( buffer ); |
|
430 #endif |
|
431 { |
|
432 |
|
433 if ( EHttpDlInprogress == aEvent.iDownloadState ) |
|
434 { |
|
435 iDownloadInProgress = ETrue; |
|
436 iDownloadDone = EFalse; |
|
437 } |
|
438 |
|
439 if ( EHttpDlCompleted == aEvent.iDownloadState ) |
|
440 { |
|
441 |
|
442 iDownloadInProgress = EFalse; |
|
443 iDownloadDone = ETrue; |
|
444 |
|
445 // Get the download item from the list |
|
446 CSVGTViewerAppDownloads* downloadItem; |
|
447 downloadItem = FindDownload( &aDownload ); |
|
448 |
|
449 #ifdef _DEBUG |
|
450 |
|
451 |
|
452 _LIT(downloadMsg, "download found" ); |
|
453 iEikEnv->InfoMsg( downloadMsg ); |
|
454 #endif |
|
455 |
|
456 |
|
457 if ( downloadItem ) |
|
458 { |
|
459 // Get the file Name of the downloaded file |
|
460 TFileName fileName; |
|
461 aDownload.GetStringAttribute( EDlAttrDestFilename, fileName ); |
|
462 #ifdef _DEBUG |
|
463 |
|
464 _LIT(fileNameMsg, "got file name " ); |
|
465 iEikEnv->InfoMsg( fileNameMsg ); |
|
466 #endif |
|
467 |
|
468 //############################################## |
|
469 // For AssignImageData |
|
470 DoAssignImageDataL(downloadItem, aDownload); |
|
471 //############################################## |
|
472 downloadItem->SetFileName( fileName ); |
|
473 |
|
474 // Check whether the download happened in a synchronous way |
|
475 if ( downloadItem->SynchronousMode() ) |
|
476 { |
|
477 downloadItem->SetDownloadCompleted( ETrue ); |
|
478 |
|
479 // If wait note is being displayed, delete it |
|
480 if ( iWaitNote ) |
|
481 { |
|
482 // Delete the download wait note |
|
483 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
484 if ( err != KErrNone ) |
|
485 { |
|
486 delete iWaitNote; |
|
487 iWaitNote = NULL; |
|
488 } |
|
489 } |
|
490 |
|
491 // If synchronous stop the scheduler |
|
492 iWait.AsyncStop(); |
|
493 } |
|
494 else |
|
495 { |
|
496 // Otherwise check the embedded mode and open the file |
|
497 // using DocHandler |
|
498 downloadItem->QueLink().Deque(); |
|
499 delete downloadItem; |
|
500 } |
|
501 } |
|
502 } |
|
503 else |
|
504 { |
|
505 // added for if user cancels the download. |
|
506 if ( EHttpDlDeleting == aEvent.iDownloadState && !iDownloadDone) |
|
507 { |
|
508 aDownload.Pause(); |
|
509 aEvent.iDownloadState = EHttpDlFailed; |
|
510 } |
|
511 |
|
512 if ( EHttpDlFailed == aEvent.iDownloadState ) |
|
513 { |
|
514 #ifdef _DEBUG |
|
515 |
|
516 _LIT(failMsg, " downloading failed" ); |
|
517 iEikEnv->InfoMsg( failMsg ); |
|
518 #endif |
|
519 |
|
520 TInt32 error = 0; |
|
521 TInt32 globalError = 0; |
|
522 aDownload.GetIntAttribute( EDlAttrErrorId, error ); |
|
523 aDownload.GetIntAttribute( EDlAttrGlobalErrorId, globalError ); |
|
524 |
|
525 #ifdef _DEBUG |
|
526 TBuf<64> errorBuffer; |
|
527 _LIT(failedMsg, "downloading failed : %d, %d" ); |
|
528 buffer.Format( failedMsg, error, globalError ); |
|
529 iEikEnv->InfoMsg( errorBuffer ); |
|
530 #endif |
|
531 |
|
532 // Get the download item from the list |
|
533 CSVGTViewerAppDownloads* downloadItem; |
|
534 downloadItem = FindDownload( &aDownload ); |
|
535 // Check whether the download was started synchronously |
|
536 // if( !downloadItem->ImageLinkFlag()) |
|
537 { |
|
538 HBufC* lUriBuf = HBufC::NewLC( KMaxUrlLength ); |
|
539 TPtr lUriPtr(lUriBuf->Des()); |
|
540 aDownload.GetStringAttribute( EDlAttrReqUrl, lUriPtr ); |
|
541 iAppDialog->AssignImageData(lUriPtr , NULL ); |
|
542 CleanupStack::PopAndDestroy( lUriBuf ); |
|
543 } |
|
544 |
|
545 if ( downloadItem ) |
|
546 { |
|
547 if ( downloadItem->SynchronousMode() ) |
|
548 { |
|
549 |
|
550 downloadItem->SetDownloadCompleted( EFalse ); |
|
551 if ( iWaitNote ) |
|
552 { |
|
553 // Delete the download wait note |
|
554 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
555 if ( err != KErrNone ) |
|
556 { |
|
557 delete iWaitNote; |
|
558 iWaitNote = NULL; |
|
559 } |
|
560 } |
|
561 |
|
562 // If synchronous, stop the scheduler started. |
|
563 iWait.AsyncStop(); |
|
564 } |
|
565 else |
|
566 { |
|
567 // Otherwise delete the download item from the list |
|
568 downloadItem->QueLink().Deque(); |
|
569 delete downloadItem; |
|
570 } |
|
571 } |
|
572 } |
|
573 } |
|
574 } |
|
575 #endif |
|
576 } |
|
577 |
|
578 // --------------------------------------------------------------------------- |
|
579 // CSVGTAppObserverUtil::LinkActivatedL |
|
580 // Leave variant of LinkActivated |
|
581 // Launches the browser in embedded mode and passes the uri to the browser |
|
582 // if the uri is a web page, if the uri refers to a local image file, or a |
|
583 // remote image file, launches the file using doc handler. |
|
584 // --------------------------------------------------------------------------- |
|
585 // |
|
586 EXPORT_C void CSVGTAppObserverUtil::LinkActivatedL( const TDesC& aUri ) |
|
587 { |
|
588 |
|
589 TDownloadNeeded dnloadNeeded = IsDownloadNeededL( aUri ); |
|
590 |
|
591 if ( dnloadNeeded == ENotAnImageFile ) |
|
592 { |
|
593 |
|
594 // (2 = length of the first parameter + space) |
|
595 HBufC* parameters = NULL; |
|
596 parameters = HBufC::NewLC( aUri.Length() + 2 ); |
|
597 |
|
598 TPtr parametersPtr = parameters->Des(); |
|
599 parametersPtr.Copy( KBrowserParameter ); |
|
600 parametersPtr.Append( KSpace ); |
|
601 parametersPtr.Append( aUri ); |
|
602 |
|
603 // Create BrowserLauncher |
|
604 CBrowserLauncher* launcher = NULL; |
|
605 |
|
606 launcher = CBrowserLauncher::NewLC(); |
|
607 |
|
608 TBrowserOverriddenSettings overriddenSettings; |
|
609 launcher->LaunchBrowserSyncEmbeddedL( *parameters, NULL, &overriddenSettings ); |
|
610 |
|
611 //launcher, parameters |
|
612 CleanupStack::PopAndDestroy( 2, parameters ); |
|
613 } |
|
614 else |
|
615 { |
|
616 if ( dnloadNeeded == ERemoteImageFile ) |
|
617 { |
|
618 RFile fileHandle; // param not going to be used |
|
619 RFs fileSession; // param not going to be used |
|
620 StartDownloadingImageL( aUri, |
|
621 fileSession, |
|
622 fileHandle, |
|
623 EFalse, /* aSynchronous mode */ |
|
624 ETrue, |
|
625 ETrue /* Embedded mode */ ); |
|
626 } |
|
627 else if ( dnloadNeeded == ELocalImageFile ) |
|
628 { |
|
629 |
|
630 TFileName fileName; |
|
631 TInt error = KErrNone; |
|
632 |
|
633 if ( GetLocalFile( aUri, fileName, *iSvgFileName ) ) |
|
634 { |
|
635 TRAP( error, LaunchDownloadedFileL( fileName, ETrue, EFalse ) ); |
|
636 } |
|
637 else |
|
638 { |
|
639 error = KErrNotFound; |
|
640 } |
|
641 |
|
642 if ( error != KErrNone ) |
|
643 { |
|
644 TInt resourceId; |
|
645 resourceId = R_SVGT_FILE_NOT_FOUND; |
|
646 // Show information note |
|
647 HBufC* prompt = StringLoader::LoadLC( resourceId ); |
|
648 CAknInformationNote* note = |
|
649 new ( ELeave ) CAknInformationNote( ETrue ); |
|
650 note->ExecuteLD( *prompt ); |
|
651 |
|
652 CleanupStack::PopAndDestroy( prompt ); |
|
653 } |
|
654 } |
|
655 else |
|
656 { |
|
657 return; |
|
658 } |
|
659 } |
|
660 } |
|
661 |
|
662 |
|
663 // -------------------------------------------------------------------- |
|
664 // CSVGTAppObserverUtil::LinkActivatedWithShowL |
|
665 // Called by LinkActivatedWithShow |
|
666 // Calls LinkActivatedL |
|
667 // -------------------------------------------------------------------- |
|
668 // |
|
669 EXPORT_C void CSVGTAppObserverUtil::LinkActivatedWithShowL( |
|
670 const TDesC& aUri , |
|
671 const TDesC& /*aShow*/ ) |
|
672 { |
|
673 LinkActivatedL( aUri ); |
|
674 } |
|
675 // --------------------------------------------------------------------------- |
|
676 // CSVGTAppObserverUtil::StartDownloadingImageL |
|
677 // Called by FetchImage, LinkActivated, LinkActivatedWithShow to download the |
|
678 // image. This function calls the download manager client Api's to start the |
|
679 // download. The download completion will be indicated by the call back |
|
680 // HandleDownloadMgrEventL. As FetchImage is a synchronous function |
|
681 // a CActiveSchedulerWait loop is started, after starting the http download. |
|
682 // the wait loop is stopped when the call back HandleDownloadMgrEventL is |
|
683 // called. |
|
684 // 1. CreateDownloadAndSetAttributes |
|
685 // 2. check result |
|
686 // If result no |
|
687 // check the status of the download |
|
688 // if Completed |
|
689 // return the filehandle |
|
690 // if in progress |
|
691 // continue downloading |
|
692 // if failed |
|
693 // return |
|
694 // else |
|
695 // Start Download |
|
696 // 3. If Synchronous |
|
697 // Start DownloadWaitNote |
|
698 // Start ActiveSchedulerWait. |
|
699 // 4. Return |
|
700 // |
|
701 // parameters: |
|
702 // aUri: the hyperlink that needs to be downloaded. |
|
703 // aSession: File session in which the file handle is opened. |
|
704 // aFileHandle: Handle of the downloaded file |
|
705 // aIsSynchronous: flag indicating whether download is synchronous or not |
|
706 // aLinkFlag: Image flag to distinguish the Embeded & hyperlink. |
|
707 // aIsEmbedded: flag indicating whether downloaded file has to opened in |
|
708 // stand alone mode or embedded mode. |
|
709 // --------------------------------------------------------------------------- |
|
710 // |
|
711 TInt CSVGTAppObserverUtil::StartDownloadingImageL( |
|
712 const TDesC& aUri, |
|
713 RFs& aSession, |
|
714 RFile& aFileHandle, |
|
715 TBool aIsSynchronous, |
|
716 TBool aLinkFlag, |
|
717 TBool aIsEmbedded ) |
|
718 { |
|
719 |
|
720 #ifdef SVGTVIEWERAPP_DOWNLOADMGR_ENABLED |
|
721 |
|
722 |
|
723 #if defined(__WINS__) || defined(__WINSCW__) |
|
724 //do nothing, hard code later on |
|
725 #else |
|
726 |
|
727 |
|
728 TUint32 Iapid( 0 ); |
|
729 if ( !GetDefaultInetAccessPointL( Iapid ) ) |
|
730 { |
|
731 return KErrNotFound; |
|
732 } |
|
733 |
|
734 |
|
735 iDownloadMgr.SetIntAttribute( EDlMgrIap, (TInt32)Iapid ); |
|
736 #endif // __wins__|| __winscw__ |
|
737 |
|
738 |
|
739 #ifdef _DEBUG |
|
740 _LIT( setAP, "Access point set" ); |
|
741 iEikEnv->InfoMsg( setAP ); |
|
742 #endif |
|
743 |
|
744 |
|
745 TInt result = ETrue; |
|
746 // Add lDownload to cleanup stack and pop it after CreateDownloadL. |
|
747 CSVGTViewerAppDownloads *lDownload = CSVGTViewerAppDownloads::NewLC( |
|
748 aIsEmbedded, aIsSynchronous, aLinkFlag ); |
|
749 |
|
750 HBufC8* url8 = NULL; |
|
751 url8 = HBufC8::NewLC( aUri.Length() ); |
|
752 url8->Des().Copy( aUri ); |
|
753 |
|
754 lDownload->SetDownloadHandle( |
|
755 &iDownloadMgr.CreateDownloadL( *url8 , result ) ); |
|
756 |
|
757 CleanupStack::PopAndDestroy( url8 ); // url8 |
|
758 |
|
759 #ifdef _DEBUG |
|
760 _LIT(dlCreated, "download created" ); |
|
761 iEikEnv->InfoMsg( dlCreated ); |
|
762 #endif |
|
763 |
|
764 |
|
765 // Add Downloads to the Menu Option |
|
766 if ( !iDownloadMenuEnabled && !aIsSynchronous ) |
|
767 { |
|
768 SetDownloadMenu( ETrue ); |
|
769 } |
|
770 |
|
771 if ( !result ) |
|
772 { |
|
773 |
|
774 // url is already being downloaded or completed |
|
775 // Get the download State |
|
776 TInt32 downloadState = 0; |
|
777 TInt retval = KErrNone; |
|
778 lDownload->DownloadHandle()->GetIntAttribute( EDlAttrState, |
|
779 downloadState ); |
|
780 |
|
781 if ( downloadState == EHttpDlCompleted ) |
|
782 { |
|
783 TFileName fileName; |
|
784 lDownload->DownloadHandle()->GetStringAttribute( EDlAttrDestFilename |
|
785 , fileName ); |
|
786 if ( aIsSynchronous ) |
|
787 { |
|
788 retval = aFileHandle.Open( aSession, fileName, EFileShareAny ); |
|
789 } |
|
790 else |
|
791 { |
|
792 if(aLinkFlag) |
|
793 { |
|
794 // Handle Launching downloaded file in asynchronous mode |
|
795 LaunchDownloadedFileL( fileName, aIsEmbedded , ETrue); |
|
796 } |
|
797 else |
|
798 { |
|
799 DoAssignImageDataL(lDownload, *(lDownload->DownloadHandle())); |
|
800 } |
|
801 |
|
802 } |
|
803 |
|
804 CleanupStack::PopAndDestroy( lDownload ); // lDownload |
|
805 return retval; |
|
806 } |
|
807 else |
|
808 { |
|
809 if ( downloadState == EHttpDlFailed ) |
|
810 { |
|
811 // Retry |
|
812 // Add to the linked list |
|
813 iDownloads.AddFirst( *lDownload ); |
|
814 CleanupStack::Pop( lDownload ); // lDownload |
|
815 lDownload->DownloadHandle()->SetBoolAttribute( |
|
816 EDlAttrNoContentTypeCheck, ETrue ); |
|
817 // Start the download |
|
818 lDownload->DownloadHandle()->Start(); |
|
819 |
|
820 return KErrNone; |
|
821 } |
|
822 else |
|
823 { |
|
824 |
|
825 if ( !FindDownload( lDownload->DownloadHandle() ) ) |
|
826 { |
|
827 // Add to the linked list |
|
828 iDownloads.AddFirst( *lDownload ); |
|
829 CleanupStack::Pop( lDownload ); // lDownload |
|
830 } |
|
831 else |
|
832 { |
|
833 CleanupStack::PopAndDestroy( lDownload ); // lDownload |
|
834 } |
|
835 } |
|
836 } |
|
837 } |
|
838 else |
|
839 { |
|
840 if ( aIsSynchronous ) |
|
841 { |
|
842 TFileName fileName( KEmptyString ); |
|
843 GetFileNameFromUri( aUri, fileName ); |
|
844 LaunchWaitNoteL( R_SVGT_DOWNLOAD_WAIT_NOTE, ETrue, fileName ); |
|
845 } |
|
846 if ( !aIsSynchronous ) |
|
847 { |
|
848 lDownload->DownloadHandle()->SetIntAttribute( EDlAttrAction, |
|
849 lDownload->ImageLinkFlag() ? ELaunch : EDoNothing ); |
|
850 // iIsFetchImageCall ? EDoNothing : ELaunch ); |
|
851 } |
|
852 else |
|
853 { |
|
854 lDownload->DownloadHandle()->SetIntAttribute( EDlAttrAction, |
|
855 EDoNothing ); |
|
856 lDownload->DownloadHandle()->SetBoolAttribute( EDlAttrSilent, |
|
857 ETrue ); |
|
858 } |
|
859 |
|
860 lDownload->DownloadHandle()->SetBoolAttribute( |
|
861 EDlAttrNoContentTypeCheck, ETrue ); |
|
862 |
|
863 |
|
864 #ifdef _DEBUG |
|
865 _LIT(dlCreateMsg, "result true dl created" ); |
|
866 iEikEnv->InfoMsg( dlCreateMsg ); |
|
867 #endif |
|
868 |
|
869 // Add to the linked list |
|
870 iDownloads.AddFirst( *lDownload ); |
|
871 |
|
872 CleanupStack::Pop( lDownload ); // lDownload |
|
873 |
|
874 // Start the download |
|
875 lDownload->DownloadHandle()->Start(); |
|
876 } |
|
877 |
|
878 if ( aIsSynchronous ) |
|
879 { |
|
880 // Start the Scheduler Wait |
|
881 if ( !iWait.IsStarted() ) |
|
882 { |
|
883 iWait.Start(); |
|
884 } |
|
885 |
|
886 #ifdef _DEBUG |
|
887 _LIT(waitLoopMsg, "out of wait loop" ); |
|
888 iEikEnv->InfoMsg( waitLoopMsg ); |
|
889 #endif |
|
890 if ( iSynchronousDownloadStopped ) |
|
891 { |
|
892 // Download dismissed |
|
893 // Cancel the download |
|
894 lDownload->DownloadHandle()->Delete(); |
|
895 return KErrCancel; |
|
896 } |
|
897 |
|
898 CSVGTViewerAppDownloads* downloadItem = NULL; |
|
899 downloadItem = FindDownload( lDownload->DownloadHandle() ); |
|
900 |
|
901 if ( downloadItem ) |
|
902 { |
|
903 TInt retval = KErrNone; |
|
904 TBool downloadCompleted = downloadItem->DownloadCompleted(); |
|
905 |
|
906 if ( downloadCompleted ) |
|
907 { |
|
908 retval = aFileHandle.Open( aSession, |
|
909 downloadItem->FileName(), |
|
910 EFileShareAny ); |
|
911 } |
|
912 else |
|
913 { |
|
914 retval = KErrNotFound; |
|
915 } |
|
916 |
|
917 downloadItem->QueLink().Deque(); |
|
918 delete downloadItem; |
|
919 return retval; |
|
920 } |
|
921 else |
|
922 { |
|
923 return KErrNotFound; |
|
924 } |
|
925 } |
|
926 else |
|
927 { |
|
928 return KErrNone; |
|
929 } |
|
930 |
|
931 #else |
|
932 return KErrNotFound; |
|
933 #endif |
|
934 |
|
935 } |
|
936 |
|
937 // --------------------------------------------------------------------------- |
|
938 // CSVGTAppObserverUtil::GetDefaultInetAccessPointL |
|
939 // if the return value is true, aIapId has the default Iap id. |
|
940 // --------------------------------------------------------------------------- |
|
941 EXPORT_C TBool CSVGTAppObserverUtil::GetDefaultInetAccessPointL |
|
942 ( TUint32& aIapId ) const |
|
943 { |
|
944 |
|
945 // Try to find the default AP. |
|
946 // The Browser may stores the default AP in the shared data. |
|
947 CRepository* repository = CRepository::NewL( KCRUidBrowser ); |
|
948 CleanupStack::PushL( repository ); |
|
949 |
|
950 TInt wapApId = 0; |
|
951 TRAPD( error, repository->Get( KBrowserDefaultAccessPoint, wapApId ) ); |
|
952 if ( error != KErrNone ) |
|
953 { |
|
954 #ifdef _DEBUG |
|
955 TBuf<64> buffer; |
|
956 _LIT(msg, "AP error : %d" ); |
|
957 buffer.Format( msg, error ); |
|
958 iEikEnv->InfoMsg( buffer ); |
|
959 User::After(1000000); |
|
960 #endif |
|
961 return EFalse; |
|
962 } |
|
963 TUint32 wapApId32( wapApId ); |
|
964 TUint32 iapId32( 0 ); |
|
965 |
|
966 CleanupStack::PopAndDestroy( repository ); |
|
967 |
|
968 CCommsDatabase* commsDb = CCommsDatabase::NewL( EDatabaseTypeIAP ); |
|
969 CleanupStack::PushL( commsDb ); |
|
970 CApDataHandler* apDataHandler = CApDataHandler::NewLC( *commsDb ); |
|
971 CApAccessPointItem* apItem = CApAccessPointItem::NewLC(); |
|
972 TRAPD( err, apDataHandler->AccessPointDataL( wapApId32, *apItem ) ); |
|
973 CApUtils* apUtils = CApUtils::NewLC( *commsDb ); |
|
974 |
|
975 TBool wapApFound( EFalse ); |
|
976 TBool iapFound( EFalse ); |
|
977 |
|
978 if ( err == KErrNone ) |
|
979 { |
|
980 wapApFound = ETrue; |
|
981 } |
|
982 else |
|
983 { |
|
984 // The first valid access point has to be selected if exists |
|
985 CApSelect* apSelect = CApSelect::NewLC |
|
986 ( |
|
987 *commsDb, |
|
988 KEApIspTypeAll, |
|
989 EApBearerTypeAll, |
|
990 KEApSortNameAscending |
|
991 ); |
|
992 if ( apSelect->MoveToFirst() ) |
|
993 { |
|
994 wapApFound = ETrue; |
|
995 wapApId32 = apSelect->Uid(); |
|
996 } |
|
997 CleanupStack::PopAndDestroy( apSelect ); // apSelect |
|
998 } |
|
999 |
|
1000 if ( wapApFound ) |
|
1001 { |
|
1002 // Get the IAP ID from the WAP AP ID. |
|
1003 #ifndef __SERIES60_WSP |
|
1004 iapId32 = 0; |
|
1005 TRAPD( errTransl, iapId32 = apUtils->IapIdFromWapIdL( wapApId32 ) ); |
|
1006 |
|
1007 if ( errTransl == KErrNone ) |
|
1008 { |
|
1009 iapFound = ETrue; |
|
1010 } |
|
1011 #else |
|
1012 iapId32 = wapApId32; |
|
1013 iapFound = ETrue; |
|
1014 #endif // __SERIES60_WSP |
|
1015 } |
|
1016 |
|
1017 CleanupStack::PopAndDestroy( 4 ); // apUtils, apItem, |
|
1018 // apDataHandler, commsDb |
|
1019 |
|
1020 if ( iapFound ) |
|
1021 { |
|
1022 aIapId = iapId32; |
|
1023 } |
|
1024 return iapFound; |
|
1025 } |
|
1026 |
|
1027 // ----------------------------------------------------------------------------- |
|
1028 // CSVGTAppObserverUtil::LaunchDownloadedFileL |
|
1029 // Called by Download manager when the image is downloaded. |
|
1030 // This function uses the document handler to launch the downloaded file. |
|
1031 // ----------------------------------------------------------------------------- |
|
1032 // |
|
1033 EXPORT_C void CSVGTAppObserverUtil::LaunchDownloadedFileL( const TDesC& aFileName, |
|
1034 TBool /* aIsEmbedded */, |
|
1035 TBool aAllowSave ) const |
|
1036 { |
|
1037 |
|
1038 TDataType dataType = TDataType(); |
|
1039 RFile fileHandle; |
|
1040 // Creates a sharable file handle |
|
1041 iDocHandler->OpenTempFileL( aFileName, fileHandle ); |
|
1042 CleanupClosePushL( fileHandle ); |
|
1043 if ( aAllowSave ) |
|
1044 { |
|
1045 CAiwGenericParamList& paramList = iDocHandler->InParamListL(); |
|
1046 // To show/hide save confirmation dlg |
|
1047 TAiwVariant allowSaveVariant(aAllowSave); |
|
1048 TAiwGenericParam genericParamAllowSave( EGenericParamAllowSave, |
|
1049 allowSaveVariant ); |
|
1050 paramList.AppendL( genericParamAllowSave ); |
|
1051 |
|
1052 iDocHandler->OpenFileEmbeddedL( fileHandle, dataType, paramList ); |
|
1053 } |
|
1054 else |
|
1055 { |
|
1056 _LIT( KSvgFile, ".svg"); |
|
1057 _LIT( KSvgzFile, ".svgz"); |
|
1058 _LIT( KSvgbFile, ".svgb"); |
|
1059 if(aFileName.Right(4) == KSvgFile || aFileName.Right(5) == KSvgzFile || aFileName.Right(5) == KSvgbFile) |
|
1060 { |
|
1061 iDocHandler->OpenFileEmbeddedL( fileHandle, dataType ); |
|
1062 } |
|
1063 else |
|
1064 { |
|
1065 iDocHandler->OpenFileL( fileHandle, dataType ); |
|
1066 } |
|
1067 } |
|
1068 CleanupStack::PopAndDestroy( &fileHandle ); // fileHandle |
|
1069 } |
|
1070 |
|
1071 // --------------------------------------------------------------------------- |
|
1072 // CSVGTAppObserverUtil::IsDownloadNeededL |
|
1073 // Called by link activated(WithShow), FetchImage |
|
1074 // to check whether the uri needs a download |
|
1075 // If the filename is present in the uri and if it is a html, |
|
1076 // returns ENotAnImageFile |
|
1077 // If the host is present & filename is not present, |
|
1078 // returns ENotAnImageFile |
|
1079 // If the host is present & filename is present, |
|
1080 // returns ERemoteImageFile |
|
1081 // If the uri doesnt need a download and if it is locally available, |
|
1082 // returns ELocalImageFile |
|
1083 // --------------------------------------------------------------------------- |
|
1084 // |
|
1085 EXPORT_C CSVGTAppObserverUtil::TDownloadNeeded |
|
1086 CSVGTAppObserverUtil::IsDownloadNeededL( |
|
1087 const TDesC& aUri ) |
|
1088 { |
|
1089 |
|
1090 TUriParser UriParser; |
|
1091 |
|
1092 TBuf<KMaxFileName> localUri; |
|
1093 // url starts with www so append http:// |
|
1094 if ( !aUri.Left( 4 ).Compare( KWww ) ) |
|
1095 { |
|
1096 localUri.Append( KHttp ); |
|
1097 localUri.Append( aUri ); |
|
1098 User::LeaveIfError( UriParser.Parse( localUri ) ); |
|
1099 } |
|
1100 else |
|
1101 { |
|
1102 User::LeaveIfError( UriParser.Parse( aUri ) ); |
|
1103 } |
|
1104 |
|
1105 if ( UriParser.IsPresent( EUriHost ) ) |
|
1106 { |
|
1107 // Extract the Path, filename and extension from the uri |
|
1108 TFileName filename = UriParser.Extract( EUriPath ); |
|
1109 TParsePtrC fileParser( filename ); |
|
1110 |
|
1111 if ( fileParser.NamePresent() && fileParser.ExtPresent() ) |
|
1112 { |
|
1113 if ( fileParser.Ext().Compare( KJpg ) == 0 || |
|
1114 fileParser.Ext().Compare( KJpeg ) == 0 || |
|
1115 fileParser.Ext().Compare( KBmp ) == 0 || |
|
1116 fileParser.Ext().Compare( KPng ) == 0 || |
|
1117 fileParser.Ext().Compare( KSvg ) == 0 || |
|
1118 fileParser.Ext().Compare( KSvgz ) == 0 ) |
|
1119 { |
|
1120 // file name and ext present and |
|
1121 // it is amy of the supported image types |
|
1122 return ERemoteImageFile; |
|
1123 } |
|
1124 else |
|
1125 { |
|
1126 //file Extension present but not a supported image ext, |
|
1127 //may be some html file |
|
1128 return ENotAnImageFile; |
|
1129 } |
|
1130 } |
|
1131 else |
|
1132 { |
|
1133 //Should be a domain name so return ENotAnImageFile |
|
1134 return ENotAnImageFile; |
|
1135 } |
|
1136 } |
|
1137 else |
|
1138 { |
|
1139 return ELocalImageFile; |
|
1140 } |
|
1141 } |
|
1142 |
|
1143 // --------------------------------------------------------------------------- |
|
1144 // CSVGTAppObserverUtil::GetFileNameFromUri |
|
1145 // This function gets the filename from the uri, |
|
1146 // Returns true if the file name is retrieved |
|
1147 // Returns False if the file name could not be retrieved. |
|
1148 // --------------------------------------------------------------------------- |
|
1149 // |
|
1150 EXPORT_C TBool CSVGTAppObserverUtil::GetFileNameFromUri( const TDesC& aUri, |
|
1151 TDes& aFileName ) const |
|
1152 { |
|
1153 |
|
1154 const TChar KBSlash = '/'; |
|
1155 TUriParser UriParser; |
|
1156 if ( UriParser.Parse( aUri ) != KErrNone ) |
|
1157 { |
|
1158 return EFalse; |
|
1159 } |
|
1160 |
|
1161 if ( UriParser.IsPresent( EUriPath ) ) |
|
1162 { |
|
1163 // Extract the Path, filename and extension from the uri |
|
1164 TFileName filename = UriParser.Extract( EUriPath ); |
|
1165 |
|
1166 TParse fileParser; |
|
1167 fileParser.Set( filename, NULL, NULL ); |
|
1168 |
|
1169 TInt slashPos = filename.LocateReverse( KBSlash ); |
|
1170 if ( slashPos != KErrNotFound ) |
|
1171 { |
|
1172 aFileName = filename.Right( filename.Length() - (slashPos + 1)); |
|
1173 return ETrue; |
|
1174 } |
|
1175 else |
|
1176 { |
|
1177 return EFalse; |
|
1178 } |
|
1179 |
|
1180 } |
|
1181 else |
|
1182 { |
|
1183 return EFalse; |
|
1184 } |
|
1185 |
|
1186 } |
|
1187 // --------------------------------------------------------------------------- |
|
1188 // CSVGTAppObserverUtil::GetLocalFile |
|
1189 // This function gets the filename with full path from the uri, |
|
1190 // Returns true if the file name is retrieved |
|
1191 // Returns False if the file name could not be retrieved. |
|
1192 // --------------------------------------------------------------------------- |
|
1193 // |
|
1194 EXPORT_C TBool CSVGTAppObserverUtil::GetLocalFile( |
|
1195 const TDesC& aUri, |
|
1196 TDes& aFileName , |
|
1197 const TDesC& aSvgFileName ) |
|
1198 { |
|
1199 |
|
1200 TBuf<KMaxFileName> copyUri = aUri; |
|
1201 // Before giving the uri to the file parser, |
|
1202 // convert '/' to '\'. |
|
1203 TInt pos; |
|
1204 while( KErrNotFound != ( pos = copyUri.FindF( KBSlashStr ) ) ) |
|
1205 { |
|
1206 copyUri.Replace(pos,1,KSlashStr ); |
|
1207 } |
|
1208 |
|
1209 // if the uri starts with ".\" remove ".\" |
|
1210 if ( copyUri.Left( 2 ).Compare( KDotSlashStr ) == 0 ) |
|
1211 { |
|
1212 copyUri = copyUri.Right( copyUri.Length() - KDotSlashStr().Length() ); |
|
1213 } |
|
1214 |
|
1215 // If the second letter is not ':' |
|
1216 // and if it is not starting with '\', |
|
1217 // and if the path has '/', |
|
1218 // then prepend slash to it. |
|
1219 if ( copyUri.Length() >= 2 && |
|
1220 copyUri.Mid( 1, 1 ).Compare( KColonStr ) != 0 && |
|
1221 copyUri.Mid( 0, 1 ).Compare( KSlashStr ) != 0 && |
|
1222 ( copyUri.Find( KSlashStr ) != KErrNotFound ) ) |
|
1223 { |
|
1224 copyUri.Insert( 0, KSlashStr ); |
|
1225 } |
|
1226 |
|
1227 TParse fileParser; |
|
1228 if( fileParser.Set( copyUri, NULL, NULL ) != KErrNone ) |
|
1229 { |
|
1230 return EFalse; |
|
1231 } |
|
1232 |
|
1233 if ( fileParser.DrivePresent() ) |
|
1234 { |
|
1235 // The uri is an absolute path |
|
1236 aFileName.Append( fileParser.Drive() ); |
|
1237 // Append path, file name and extension from the uri. |
|
1238 if ( fileParser.PathPresent() ) |
|
1239 { |
|
1240 aFileName.Append( fileParser.Path() ); |
|
1241 } |
|
1242 if ( fileParser.NamePresent() ) |
|
1243 { |
|
1244 aFileName.Append( fileParser.Name() ); |
|
1245 } |
|
1246 if ( fileParser.ExtPresent() ) |
|
1247 { |
|
1248 aFileName.Append( fileParser.Ext() ); |
|
1249 } |
|
1250 RFs session; |
|
1251 TInt connectError=session.Connect(); |
|
1252 if(connectError==KErrNone) |
|
1253 { |
|
1254 RFile fileHandle; |
|
1255 TInt openError = fileHandle.Open( session, aFileName, EFileShareReadersOnly); |
|
1256 fileHandle.Close(); |
|
1257 session.Close(); |
|
1258 if ( openError != KErrNone ) |
|
1259 { |
|
1260 return EFalse; |
|
1261 } |
|
1262 return ETrue; |
|
1263 } |
|
1264 session.Close(); |
|
1265 return EFalse; |
|
1266 } |
|
1267 else |
|
1268 { |
|
1269 |
|
1270 TParse svgFilenameParser; |
|
1271 if ( svgFilenameParser.Set( aSvgFileName,NULL,NULL ) != KErrNone ) |
|
1272 { |
|
1273 return EFalse; |
|
1274 } |
|
1275 |
|
1276 if ( svgFilenameParser.DrivePresent() ) |
|
1277 { |
|
1278 aFileName.Append( svgFilenameParser.Drive() ); |
|
1279 } |
|
1280 |
|
1281 TInt dotdotPos = copyUri.Find( KDotDot ); |
|
1282 TInt rightPos = 0; |
|
1283 |
|
1284 if ( dotdotPos != KErrNotFound ) |
|
1285 { |
|
1286 // If ".." is present collapse it with the parent path |
|
1287 if ( svgFilenameParser.PathPresent() ) |
|
1288 { |
|
1289 do |
|
1290 { |
|
1291 if ( dotdotPos > 1 ) |
|
1292 { |
|
1293 svgFilenameParser.AddDir( copyUri.Left(dotdotPos - 1) ); |
|
1294 } |
|
1295 |
|
1296 if ( svgFilenameParser.PopDir() != KErrNone ) |
|
1297 { |
|
1298 return EFalse; |
|
1299 } |
|
1300 |
|
1301 rightPos = (copyUri.Length()) - (dotdotPos + 3); |
|
1302 |
|
1303 if ( rightPos > 0 ) |
|
1304 { |
|
1305 copyUri = copyUri.Right( rightPos ); |
|
1306 } |
|
1307 |
|
1308 }while ( (dotdotPos = copyUri.Find( KDotDot ) ) |
|
1309 != KErrNotFound ); |
|
1310 |
|
1311 aFileName.Append( svgFilenameParser.Path() ); |
|
1312 aFileName.Append( copyUri ); |
|
1313 } |
|
1314 else |
|
1315 { |
|
1316 return EFalse; |
|
1317 } |
|
1318 } |
|
1319 else |
|
1320 { |
|
1321 if ( svgFilenameParser.PathPresent() ) |
|
1322 { |
|
1323 aFileName.Append( svgFilenameParser.Path() ); |
|
1324 } |
|
1325 |
|
1326 // Append path, file name and extension from the uri. |
|
1327 if ( fileParser.PathPresent() ) |
|
1328 { |
|
1329 //deletes an extra slash in aFileName |
|
1330 TInt strlen = aFileName.Length(); |
|
1331 if(aFileName.Mid(strlen-1).Compare(KSlashStr) == 0) |
|
1332 { |
|
1333 aFileName.Delete(strlen-1, 1); |
|
1334 } |
|
1335 aFileName.Append( fileParser.Path() ); |
|
1336 } |
|
1337 |
|
1338 if ( fileParser.NamePresent() ) |
|
1339 { |
|
1340 aFileName.Append( fileParser.Name() ); |
|
1341 } |
|
1342 if ( fileParser.ExtPresent() ) |
|
1343 { |
|
1344 aFileName.Append( fileParser.Ext() ); |
|
1345 } |
|
1346 } |
|
1347 RFs session; |
|
1348 // The error is caught to avoid any code scanner error |
|
1349 TInt connectError=session.Connect(); |
|
1350 if(connectError==KErrNone) |
|
1351 { |
|
1352 RFile fileHandle; |
|
1353 TInt openError = fileHandle.Open(session, aFileName, EFileShareReadersOnly ); |
|
1354 fileHandle.Close(); |
|
1355 session.Close(); |
|
1356 if ( openError != KErrNone ) |
|
1357 { |
|
1358 return EFalse; |
|
1359 } |
|
1360 return ETrue; |
|
1361 } |
|
1362 session.Close(); |
|
1363 return EFalse; |
|
1364 } |
|
1365 } |
|
1366 |
|
1367 |
|
1368 #ifdef SVGTVIEWERAPP_DOWNLOADMGR_ENABLED |
|
1369 // --------------------------------------------------------------------------- |
|
1370 // CSVGTAppObserverUtil::FindDownload |
|
1371 // This iterates through the linked list and return the link |
|
1372 // corresponding to the given http download handle |
|
1373 // If a link is not found returns NULL. |
|
1374 // --------------------------------------------------------------------------- |
|
1375 // |
|
1376 CSVGTViewerAppDownloads* CSVGTAppObserverUtil::FindDownload( |
|
1377 const RHttpDownload* aHttpDownload ) |
|
1378 { |
|
1379 CSVGTViewerAppDownloads* downloadItem; |
|
1380 TDblQueIter<CSVGTViewerAppDownloads> Iter( iDownloads ); |
|
1381 if ( !iDownloads.IsEmpty() ) |
|
1382 { |
|
1383 Iter.SetToFirst(); |
|
1384 while ( ( downloadItem = Iter ) != NULL ) |
|
1385 { |
|
1386 if ( downloadItem->DownloadHandle() == aHttpDownload ) |
|
1387 { |
|
1388 return downloadItem; |
|
1389 } |
|
1390 Iter++; |
|
1391 } |
|
1392 } |
|
1393 return NULL; |
|
1394 } |
|
1395 #endif |
|
1396 |
|
1397 // ----------------------------------------------------------------------------- |
|
1398 // CSVGTAppObserverUtil::CSVGTAppObserverUtil |
|
1399 // C++ default constructor can NOT contain any code, that |
|
1400 // might leave. |
|
1401 // ----------------------------------------------------------------------------- |
|
1402 // |
|
1403 EXPORT_C CSVGTAppObserverUtil::CSVGTAppObserverUtil( |
|
1404 CSVGTUIDialog* aAppDialog ) : |
|
1405 #ifdef SVGTVIEWERAPP_DOWNLOADMGR_ENABLED |
|
1406 iDownloads( CSVGTViewerAppDownloads::LinkOffset() ) , |
|
1407 iDownloadIter( iDownloads ), |
|
1408 iDownloadMenuEnabled( EFalse ), // construct header & iterator |
|
1409 iSynchronousDownloadStopped( EFalse ), |
|
1410 #endif |
|
1411 iAppDialog( aAppDialog ), |
|
1412 iSavingDone( EFalse ), |
|
1413 iCommandId( 0 ), |
|
1414 // iIsFetchImageCall(EFalse), |
|
1415 iTempFileUsed( EFalse ), |
|
1416 iDownloadDone( EFalse ), |
|
1417 iDownloadInProgress( EFalse ) |
|
1418 |
|
1419 { |
|
1420 } |
|
1421 // ----------------------------------------------------------------------------- |
|
1422 // CSVGTAppObserverUtil::ConstructL |
|
1423 // Symbian 2nd phase constructor can leave. |
|
1424 // ----------------------------------------------------------------------------- |
|
1425 // |
|
1426 EXPORT_C void CSVGTAppObserverUtil::ConstructL() |
|
1427 { |
|
1428 |
|
1429 // Get the CEikonEnv pointer |
|
1430 iEikEnv = CEikonEnv::Static(); |
|
1431 |
|
1432 // Find which drive this DLL is installed. |
|
1433 TFileName fileName; |
|
1434 |
|
1435 // Get the full resource file |
|
1436 TParse fp; |
|
1437 |
|
1438 // Add the resource dir |
|
1439 fp.Set( KResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL); |
|
1440 |
|
1441 // Get the filename with full path |
|
1442 fileName = fp.FullName(); |
|
1443 |
|
1444 BaflUtils::NearestLanguageFile( iEikEnv->FsSession(), fileName ); //for |
|
1445 // localization |
|
1446 iResourceOffset = iEikEnv->AddResourceFileL( fileName ); |
|
1447 |
|
1448 |
|
1449 // File manager utility needed for saving/moving files. |
|
1450 iFileManager = CSVGTFileManager::NewL(); |
|
1451 |
|
1452 iDocHandler = CDocumentHandler::NewL(); |
|
1453 |
|
1454 #ifdef SVGTVIEWERAPP_DOWNLOADMGR_ENABLED |
|
1455 TUid hostUid = iEikEnv->EikAppUi()->Application()->AppDllUid(); |
|
1456 |
|
1457 //creates a download manager session |
|
1458 //parameters - uid, mhttpdownloadmgrobserver |
|
1459 //embedded mode on - master flag True has to be passed when the app is |
|
1460 //in stand alone mode, false in case of embedded mode |
|
1461 iDownloadMgr.ConnectL( hostUid ,*this , EFalse /* Embedded mode*/); |
|
1462 // When SVGT Viewer exits, all the downloads are |
|
1463 // cancelled by the download manager |
|
1464 iDownloadMgr.SetIntAttribute( EDlMgrExitAction , EExitDelete ); |
|
1465 |
|
1466 iDMgrUiReg = CDownloadMgrUiLibRegistry::NewL( iDownloadMgr ); |
|
1467 iDMgrDownloadsList = &iDMgrUiReg->RegisterDownloadsListL(); |
|
1468 iDMgrUserInteractions = &iDMgrUiReg->RegisterUserInteractionsL(); |
|
1469 iDMgrUserInteractions->SetBoolAttributeL( CDownloadMgrUiUserInteractions::EAttrSuppressDownloadConfirmation, |
|
1470 ETrue ); |
|
1471 #endif |
|
1472 } |
|
1473 |
|
1474 // ----------------------------------------------------------------------------- |
|
1475 // CSVGTAppObserverUtil::ConstructL |
|
1476 // Symbian 2nd phase constructor can leave. |
|
1477 // ----------------------------------------------------------------------------- |
|
1478 // |
|
1479 EXPORT_C void CSVGTAppObserverUtil::ConstructL( |
|
1480 RFile* aFileHdlPtr, |
|
1481 const TDesC& aFilename, |
|
1482 TBool aIsFileFullPathAvailable, |
|
1483 TBool aCanSaveContent, |
|
1484 TBool aShouldMoveContent ) |
|
1485 { |
|
1486 iIsFullFilePathValid = aIsFileFullPathAvailable; |
|
1487 iCanSaveContent = aCanSaveContent; |
|
1488 iShouldMoveContent = aShouldMoveContent; |
|
1489 iSvgFileId = aFileHdlPtr; |
|
1490 if ( aIsFileFullPathAvailable ) |
|
1491 { |
|
1492 iSvgFileName = aFilename.AllocL(); |
|
1493 } |
|
1494 else |
|
1495 { |
|
1496 TFileName fullPathName; |
|
1497 iSvgFileId->FullName( fullPathName ); |
|
1498 iSvgFileName = fullPathName.AllocL(); |
|
1499 } |
|
1500 ConstructL(); |
|
1501 } |
|
1502 |
|
1503 // ----------------------------------------------------------------------------- |
|
1504 // CSVGTAppObserverUtil::ConstructL |
|
1505 // Symbian 2nd phase constructor can leave. |
|
1506 // ----------------------------------------------------------------------------- |
|
1507 // |
|
1508 EXPORT_C void CSVGTAppObserverUtil::ConstructL( |
|
1509 RFile* aFileHdlPtr |
|
1510 ) |
|
1511 { |
|
1512 TBuf<1> lDummyFileName; /* This is needed by ConstructL, |
|
1513 but will be ignored */ |
|
1514 |
|
1515 ConstructL( aFileHdlPtr, |
|
1516 lDummyFileName, |
|
1517 EFalse /* IsFileFullPathAvailable */, |
|
1518 ETrue /* CanSaveContent */, |
|
1519 EFalse /* aShouldMoveContent */ |
|
1520 ); |
|
1521 } |
|
1522 // ----------------------------------------------------------------------------- |
|
1523 // CSVGTAppObserverUtil::CanShowSave |
|
1524 // Tells the SVG-T dialog if the save option should be displayed. |
|
1525 // e.g. If the dialog is launched from SVG-T viewer and which is launched |
|
1526 // embedded from Browser/Messaging then Save option would be displayed. |
|
1527 // Also when MMS launches the dialog. |
|
1528 // ----------------------------------------------------------------------------- |
|
1529 // |
|
1530 EXPORT_C TBool CSVGTAppObserverUtil::CanShowSave() |
|
1531 { |
|
1532 return iCanSaveContent; |
|
1533 } |
|
1534 |
|
1535 // ----------------------------------------------------------------------------- |
|
1536 // CSVGTAppObserverUtil::CanShowSave |
|
1537 // Tells the SVG-T dialog if saving of the content is done. |
|
1538 // ----------------------------------------------------------------------------- |
|
1539 // |
|
1540 EXPORT_C TBool CSVGTAppObserverUtil::IsSavingDone() |
|
1541 { |
|
1542 return iSavingDone; |
|
1543 } |
|
1544 // ----------------------------------------------------------------------------- |
|
1545 // CSVGTAppObserverUtil::DoSaveL |
|
1546 // Performs the save operation on the content opened. |
|
1547 // ----------------------------------------------------------------------------- |
|
1548 // |
|
1549 EXPORT_C void CSVGTAppObserverUtil::DoSaveL( TInt aCommandId ) |
|
1550 { |
|
1551 iCommandId = aCommandId; |
|
1552 // Get filename. |
|
1553 // Run Dialog. |
|
1554 // Need to pause content |
|
1555 iAppDialog->ProcessCommandL( ESvgtDlgPauseCommand ); |
|
1556 |
|
1557 // Get the currently playing svg file's name and extension. |
|
1558 HBufC* lFileNameBuf = HBufC::NewLC( KMaxFileName ); |
|
1559 TPtr lFileNamePtr = lFileNameBuf->Des(); |
|
1560 GetFileNameAndExt( lFileNamePtr ); |
|
1561 |
|
1562 #ifndef RD_MULTIPLE_DRIVE |
|
1563 // Get User's choice of name and folder for target file. |
|
1564 TBool retval = AknCommonDialogs::RunSaveDlgNoDirectorySelectionLD( |
|
1565 lFileNamePtr, |
|
1566 R_SVGT_SAVE_LOCATIONS ); |
|
1567 #else |
|
1568 |
|
1569 TBool retval = AknCommonDialogsDynMem::RunSaveDlgNoDirectorySelectionLD( |
|
1570 AknCommonDialogsDynMem::EMemoryTypeRemote | |
|
1571 AknCommonDialogsDynMem::EMemoryTypePhone | |
|
1572 AknCommonDialogsDynMem::EMemoryTypeMMC, |
|
1573 lFileNamePtr, R_SVGT_SAVE_LOCATIONS); |
|
1574 #endif |
|
1575 |
|
1576 if ( retval ) |
|
1577 { |
|
1578 // User chose a valid file name |
|
1579 TBool lMoveFlag = EFalse; |
|
1580 TBuf<1> lDummyFileName; |
|
1581 RFile lDummyFile; |
|
1582 TInt errSaveContent = KErrNone; |
|
1583 TInt errSaveText = KErrNone; |
|
1584 |
|
1585 // Assume it is not the overwrite case by default |
|
1586 iIsOverwriteCase = EFalse; |
|
1587 |
|
1588 // Get the currently playing svg file's full path |
|
1589 HBufC* lFullFilePathBuf = HBufC::NewLC( KMaxFileName ); |
|
1590 TPtr lFullFilePathPtr = lFullFilePathBuf->Des(); |
|
1591 |
|
1592 if ( iSvgFileId ) |
|
1593 { |
|
1594 iSvgFileId->FullName( lFullFilePathPtr ); |
|
1595 } |
|
1596 // Check if file name is same as orig file -> overwrite case |
|
1597 if ( !( lFileNamePtr.CompareF( lFullFilePathPtr ) ) ) |
|
1598 { |
|
1599 iIsOverwriteCase = ETrue; |
|
1600 } |
|
1601 CleanupStack::PopAndDestroy( lFullFilePathBuf ); |
|
1602 lFullFilePathBuf = NULL; |
|
1603 |
|
1604 // Check if text edit happened |
|
1605 if ( iAppDialog->IsTextContentChanged() ) |
|
1606 { |
|
1607 if ( iTempFileName ) |
|
1608 { |
|
1609 delete iTempFileName; |
|
1610 iTempFileName = NULL; |
|
1611 } |
|
1612 iTempFileName = HBufC::NewL( KMaxFileName ); |
|
1613 TPtr lTempFilePtr = iTempFileName->Des(); |
|
1614 |
|
1615 // Indicate that cleanup is to be performed in SVGTSavingDoneL |
|
1616 iTempFileUsed = ETrue; |
|
1617 |
|
1618 TRAP( errSaveText, SaveSvgTextContentL( *iSvgFileId, lTempFilePtr ) ); |
|
1619 |
|
1620 if ( !errSaveText ) |
|
1621 { |
|
1622 // Temp file should be moved instead of |
|
1623 // original file |
|
1624 lMoveFlag = ETrue; |
|
1625 |
|
1626 if ( IsAllowMove() || iIsOverwriteCase ) |
|
1627 { |
|
1628 // Based on Move option/self overwrite case, need to close |
|
1629 // the content being played. |
|
1630 // Need to close the currently running file-handle, |
|
1631 // need to inform dialog to stop using it. |
|
1632 iAppDialog->StopUsingContentFileHandle(); |
|
1633 iSvgFileId->Close(); |
|
1634 } |
|
1635 |
|
1636 if ( IsAllowMove() ) |
|
1637 { |
|
1638 // Remember that the original file should |
|
1639 // be deleted if file save is successful. |
|
1640 iDeleteOrigFile = ETrue; |
|
1641 } |
|
1642 |
|
1643 |
|
1644 TRAP( errSaveContent, SaveContentL( |
|
1645 lDummyFile, |
|
1646 lTempFilePtr, |
|
1647 lFileNamePtr, |
|
1648 lMoveFlag )); |
|
1649 } |
|
1650 } |
|
1651 else // No text editing happened |
|
1652 { |
|
1653 |
|
1654 if ( IsAllowMove() || iIsOverwriteCase ) |
|
1655 { |
|
1656 // Based on Move option/self overwrite case, need to close |
|
1657 // the content being played. |
|
1658 // Need to close the currently running file-handle, |
|
1659 // need to inform dialog to stop using it. |
|
1660 iAppDialog->StopUsingContentFileHandle(); |
|
1661 iSvgFileId->Close(); |
|
1662 } |
|
1663 |
|
1664 if ( IsAllowMove() ) |
|
1665 { |
|
1666 lMoveFlag = ETrue; |
|
1667 TRAP( errSaveContent, SaveContentL( |
|
1668 lDummyFile, |
|
1669 *iSvgFileName, |
|
1670 lFileNamePtr, |
|
1671 lMoveFlag )); |
|
1672 } |
|
1673 else |
|
1674 { |
|
1675 TRAP( errSaveContent, SaveContentL( |
|
1676 *iSvgFileId, |
|
1677 lDummyFileName, |
|
1678 lFileNamePtr, |
|
1679 lMoveFlag )); |
|
1680 } |
|
1681 } |
|
1682 |
|
1683 CleanupStack::PopAndDestroy( lFileNameBuf ); |
|
1684 |
|
1685 |
|
1686 if ( errSaveText || errSaveContent ) |
|
1687 { |
|
1688 // If disk full problem, display note. |
|
1689 if ( errSaveContent == KErrDiskFull || errSaveText == KErrDiskFull ) |
|
1690 { |
|
1691 // mmc full note |
|
1692 HBufC* text = StringLoader::LoadLC( R_SVGT_MMC_FULL ); |
|
1693 CAknGlobalNote* note = CAknGlobalNote::NewLC(); |
|
1694 note->SetSoftkeys( R_AVKON_SOFTKEYS_OK_EMPTY__OK ); |
|
1695 note->ShowNoteL( EAknGlobalErrorNote, *text ); |
|
1696 CleanupStack::PopAndDestroy(2);// note, text |
|
1697 } |
|
1698 |
|
1699 // If temporary file was used, perform cleanup |
|
1700 if ( iTempFileUsed ) |
|
1701 { |
|
1702 if ( iTempFileName ) |
|
1703 { |
|
1704 // Try and delete the temp file, ignore the error. |
|
1705 iEikEnv->FsSession().Delete( iTempFileName->Des() ); |
|
1706 delete iTempFileName; |
|
1707 iTempFileName = NULL; |
|
1708 } |
|
1709 iTempFileUsed = EFalse; |
|
1710 } |
|
1711 |
|
1712 // If the File Couldn't be Moved, then Open the original |
|
1713 // file again and Set it back to dialog. |
|
1714 if ( IsAllowMove() ) |
|
1715 { |
|
1716 if( iSvgFileId->Open(iEikEnv->FsSession(), |
|
1717 iSvgFileName->Des(), EFileShareAny) != KErrNone ) |
|
1718 { |
|
1719 // This should not happen, Couldn't reopen back the |
|
1720 // Original content!, No Point in showing save. |
|
1721 iCanSaveContent = EFalse; |
|
1722 return; |
|
1723 } |
|
1724 else |
|
1725 { |
|
1726 iAppDialog->StartUsingContentFileHandle(); |
|
1727 } |
|
1728 } |
|
1729 } |
|
1730 else |
|
1731 { |
|
1732 LaunchWaitNoteL( R_SVGT_SAVING_WAIT_NOTE, ETrue, lDummyFileName ); |
|
1733 } |
|
1734 } |
|
1735 else |
|
1736 { |
|
1737 // User pressed cancel in save dialog - cleanup |
|
1738 CleanupStack::PopAndDestroy( lFileNameBuf ); |
|
1739 } |
|
1740 } |
|
1741 |
|
1742 EXPORT_C TInt CSVGTAppObserverUtil::NewFetchImageData( const TDesC& aUri ) |
|
1743 { |
|
1744 // iIsFetchImageCall = ETrue |
|
1745 TInt ret = KErrNone; |
|
1746 |
|
1747 TDownloadNeeded downloadNeeded = ELocalImageFile; |
|
1748 TRAPD( error, downloadNeeded = IsDownloadNeededL( aUri ) ); |
|
1749 |
|
1750 if ( error != KErrNone ) |
|
1751 { |
|
1752 return KErrNotFound; |
|
1753 } |
|
1754 |
|
1755 if ( downloadNeeded == ELocalImageFile ) |
|
1756 { |
|
1757 TFileName fileName; |
|
1758 if ( GetLocalFile( aUri, fileName, *iSvgFileName ) ) |
|
1759 { |
|
1760 TRAPD(error, DoAssignLocalFileDataL( aUri, fileName )); |
|
1761 return error; |
|
1762 } |
|
1763 else |
|
1764 { |
|
1765 iAppDialog->AssignImageData(aUri , NULL ); |
|
1766 return KErrNotFound; |
|
1767 } |
|
1768 } |
|
1769 else if ( downloadNeeded == ERemoteImageFile ) |
|
1770 { |
|
1771 //creatred for Dummy purpose |
|
1772 RFs fs; |
|
1773 RFile file; |
|
1774 |
|
1775 TRAPD( err,ret = StartDownloadingImageL( aUri, fs, file, |
|
1776 EFalse, |
|
1777 EFalse /* Asynchronous mode */) ); |
|
1778 if ( err != KErrNone ) |
|
1779 { |
|
1780 return KErrNotFound; |
|
1781 } |
|
1782 else |
|
1783 { |
|
1784 return ret; |
|
1785 } |
|
1786 |
|
1787 } |
|
1788 else |
|
1789 { |
|
1790 return KErrNotFound; |
|
1791 } |
|
1792 } |
|
1793 |
|
1794 // ----------------------------------------------------------------------------- |
|
1795 // CSVGTAppObserverUtil::SaveContentL |
|
1796 // Performs the save operation on the content opened given |
|
1797 // source file handle, src/dst filename and whether to move/copy. |
|
1798 // ----------------------------------------------------------------------------- |
|
1799 // |
|
1800 void CSVGTAppObserverUtil::SaveContentL( RFile& aSrcFileHandle, // Used in copy |
|
1801 const TDesC& aSrcFileName, // Used in move |
|
1802 TDes& aDstFileName, // Dest File name |
|
1803 TBool aMoveFlag ) // ETrue = Move |
|
1804 { |
|
1805 TInt ret = KErrNone; |
|
1806 // Start Saving Operation. |
|
1807 // Create directory |
|
1808 TInt error = iEikEnv->FsSession().MkDirAll( aDstFileName ); |
|
1809 if ( error != KErrNone && error != KErrAlreadyExists ) |
|
1810 { |
|
1811 User::Leave( error ); |
|
1812 } |
|
1813 |
|
1814 // Check if the content should be moved. e.g. In Browser case. |
|
1815 iFileManager->SetAllowMove( aMoveFlag ); |
|
1816 |
|
1817 // Ask FileManager to start saving. ObserverUtil acts as |
|
1818 // observer for filemanager operations. Based on whether |
|
1819 // the Move operation is required or not, |
|
1820 // there are two versions of filecopy operations. |
|
1821 // In Move Full filepath is required |
|
1822 if ( aMoveFlag ) |
|
1823 { |
|
1824 if ( IsFileFullPathAvailable() ) |
|
1825 { |
|
1826 // Keep the Destination file reference. |
|
1827 if ( iSvgDstFileName ) |
|
1828 { |
|
1829 delete iSvgDstFileName; |
|
1830 iSvgDstFileName = NULL; |
|
1831 } |
|
1832 iSvgDstFileName = aDstFileName.AllocL(); |
|
1833 |
|
1834 // Start the Move Now. |
|
1835 ret = iFileManager->StartCopyOperationL( |
|
1836 this, aSrcFileName, aDstFileName ); |
|
1837 } |
|
1838 else |
|
1839 { |
|
1840 // Shouldn't happen. If Move operation is required, |
|
1841 // Full file path must be there. |
|
1842 ret = KErrPathNotFound; |
|
1843 } |
|
1844 } |
|
1845 else |
|
1846 { |
|
1847 ret = iFileManager->StartCopyOperationL( |
|
1848 this, aSrcFileHandle, aDstFileName ); |
|
1849 } |
|
1850 User::LeaveIfError( ret ); |
|
1851 } |
|
1852 |
|
1853 // ----------------------------------------------------------------------------- |
|
1854 // CSVGTAppObserverUtil::GetUniqueFileName |
|
1855 // Generates a unique filename in the private directory |
|
1856 // ----------------------------------------------------------------------------- |
|
1857 // |
|
1858 void CSVGTAppObserverUtil::GetUniqueFileName( TDes& aName ) const |
|
1859 { |
|
1860 TFileName lPpath; |
|
1861 iEikEnv->FsSession().PrivatePath( lPpath ); |
|
1862 RThread lThread; |
|
1863 _LIT( KFNameFormatStr,"%u"); |
|
1864 TBuf<KSvgMaxThreadIdStr> lThreadIdStr; |
|
1865 lThreadIdStr.Format( KFNameFormatStr, (TUint)(lThread.Id()) ); |
|
1866 aName.Append( lPpath ); |
|
1867 aName.Append( lThreadIdStr ); |
|
1868 } |
|
1869 |
|
1870 // ----------------------------------------------------------------------------- |
|
1871 // CSVGTAppObserverUtil::IsGzipContent |
|
1872 // Checks whether the file is a GZipped content |
|
1873 // ----------------------------------------------------------------------------- |
|
1874 // |
|
1875 TBool CSVGTAppObserverUtil::IsGzipContent( const RFile& aFileHandle ) const |
|
1876 { |
|
1877 TUint8 ids[2]; |
|
1878 TPtr8 des( ids, 0, sizeof( TUint8 ) * 2 ); |
|
1879 TInt zero = 0; |
|
1880 |
|
1881 // Reset to the beginning |
|
1882 aFileHandle.Seek( ESeekStart, zero ); |
|
1883 |
|
1884 // Read the first two bytes |
|
1885 if ( aFileHandle.Read( des ) != KErrNone ) |
|
1886 { |
|
1887 return EFalse; |
|
1888 } |
|
1889 |
|
1890 // reset to start of file |
|
1891 aFileHandle.Seek( ESeekStart, zero ); |
|
1892 return ( ids[0] == 31 && ids[1] == 139 ); |
|
1893 // return ( ids[0] == EZGZipFile::ID1 && ids[1] == EZGZipFile::ID2 ); |
|
1894 } |
|
1895 |
|
1896 // ----------------------------------------------------------------------------- |
|
1897 // CSVGTAppObserverUtil::SaveSvgContent |
|
1898 // Saves the SVG content to a temporary file |
|
1899 // ----------------------------------------------------------------------------- |
|
1900 // |
|
1901 void CSVGTAppObserverUtil::SaveSvgTextContentL( const RFile& aSrcFileHandle, |
|
1902 TDes& aTempFileName ) |
|
1903 { |
|
1904 TFileName lTempFileName; |
|
1905 |
|
1906 // Save the content path |
|
1907 HBufC* lOrigFileNameBuf = HBufC::NewLC( KMaxFileName ); |
|
1908 TPtr lOrigFileNamePtr = lOrigFileNameBuf->Des(); |
|
1909 aSrcFileHandle.FullName( lOrigFileNamePtr ); |
|
1910 |
|
1911 // Create the temp file in the same drive as the content file |
|
1912 TParsePtrC lOrigPath( lOrigFileNamePtr ); |
|
1913 |
|
1914 // Put the drive into the path |
|
1915 lTempFileName.Append( lOrigPath.Drive() ); |
|
1916 |
|
1917 // lOrigFileNameBuf no longer needed. No more references to |
|
1918 // lOrigFileNamePtr. |
|
1919 // CleanupStack::PopAndDestroy( lOrigFileNameBuf ); |
|
1920 |
|
1921 // Generate a unique file name |
|
1922 GetUniqueFileName( lTempFileName ); |
|
1923 |
|
1924 TInt lOrigFileSize = 0; |
|
1925 TInt lFileSizeErr = aSrcFileHandle.Size( lOrigFileSize ); |
|
1926 if ( lFileSizeErr ) |
|
1927 { |
|
1928 User::Leave( lFileSizeErr ); |
|
1929 } |
|
1930 |
|
1931 // Check whether freespace available |
|
1932 // Assume that the new file occupies same amount of space as the original |
|
1933 // file. Not so in the case of svgz file. |
|
1934 #ifndef RD_MULTIPLE_DRIVE |
|
1935 if( lOrigPath.Drive().CompareF( PathInfo::MemoryCardRootPath().Left(2) ) |
|
1936 == 0 ) |
|
1937 { |
|
1938 if (SysUtil::MMCSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()), |
|
1939 lOrigFileSize )) |
|
1940 { |
|
1941 User::Leave( KErrDiskFull ); // MMC full, Avkon shows note |
|
1942 } |
|
1943 } |
|
1944 else |
|
1945 { |
|
1946 if (SysUtil::FFSSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()), |
|
1947 lOrigFileSize )) |
|
1948 { |
|
1949 User::Leave( KErrDiskFull ); // Phone memory full, Avkon shows |
|
1950 // note |
|
1951 } |
|
1952 } |
|
1953 #else |
|
1954 //******************* Added to support multiple drives ************************* |
|
1955 TInt intDrive; |
|
1956 TChar ch = lOrigPath.Drive()[0]; |
|
1957 |
|
1958 User::LeaveIfError( RFs::CharToDrive(ch,intDrive) ); |
|
1959 |
|
1960 if( SysUtil::DiskSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()), |
|
1961 lOrigFileSize, intDrive )) |
|
1962 { |
|
1963 User::Leave( KErrDiskFull ); // MMC full, Avkon shows note |
|
1964 } |
|
1965 |
|
1966 //********************************************************************************* |
|
1967 #endif |
|
1968 // lOrigFileNameBuf no longer needed. No more references to |
|
1969 // lOrigFileNamePtr. |
|
1970 CleanupStack::PopAndDestroy( lOrigFileNameBuf ); |
|
1971 |
|
1972 // Create the directory to the temp filename |
|
1973 TInt lDirCreateError = iEikEnv->FsSession().MkDirAll( lTempFileName ); |
|
1974 |
|
1975 // Ignore error if the directory already exists |
|
1976 if ( lDirCreateError != KErrNone && lDirCreateError != KErrAlreadyExists ) |
|
1977 { |
|
1978 User::Leave( lDirCreateError ); |
|
1979 } |
|
1980 |
|
1981 // Save the changed SVG content to that file name |
|
1982 iAppDialog->SaveSvgDom( lTempFileName ); |
|
1983 |
|
1984 // Check if content is gzipped |
|
1985 if ( IsGzipContent( aSrcFileHandle ) ) |
|
1986 { |
|
1987 // Zip the content |
|
1988 } |
|
1989 aTempFileName = lTempFileName; |
|
1990 } |
|
1991 |
|
1992 // ----------------------------------------------------------------------------- |
|
1993 // CSVGTAppObserverUtil::GetFileNameAndExt |
|
1994 // ----------------------------------------------------------------------------- |
|
1995 // |
|
1996 EXPORT_C void CSVGTAppObserverUtil::GetFileNameAndExt(TDes& filename) const |
|
1997 { |
|
1998 |
|
1999 // If FileName is valid use that, else check filehandle |
|
2000 // and give back file-name from that. |
|
2001 if ( iIsFullFilePathValid ) |
|
2002 { |
|
2003 if ( iSvgFileName ) |
|
2004 { |
|
2005 TParsePtrC p(*iSvgFileName); |
|
2006 TPtrC ptr(p.NameAndExt()); |
|
2007 filename = ptr; |
|
2008 } |
|
2009 } |
|
2010 else |
|
2011 { |
|
2012 if ( iSvgFileId ) |
|
2013 { |
|
2014 iSvgFileId->Name( filename ); |
|
2015 } |
|
2016 } |
|
2017 |
|
2018 } |
|
2019 |
|
2020 // ----------------------------------------------------------------------------- |
|
2021 // CSVGTAppObserverUtil::IsAllowMove |
|
2022 // ----------------------------------------------------------------------------- |
|
2023 EXPORT_C TBool CSVGTAppObserverUtil::IsAllowMove() const |
|
2024 { |
|
2025 return iShouldMoveContent; |
|
2026 } |
|
2027 |
|
2028 // ----------------------------------------------------------------------------- |
|
2029 // CSVGTAppObserverUtil::IsFileFullPathAvailable |
|
2030 // ----------------------------------------------------------------------------- |
|
2031 EXPORT_C TBool CSVGTAppObserverUtil::IsFileFullPathAvailable() const |
|
2032 { |
|
2033 return 1; |
|
2034 } |
|
2035 |
|
2036 // ----------------------------------------------------------------------------- |
|
2037 // CSVGTAppObserverUtil::LauncWaitNoteL |
|
2038 // ----------------------------------------------------------------------------- |
|
2039 // |
|
2040 void CSVGTAppObserverUtil::LaunchWaitNoteL(TInt aResourceId, |
|
2041 TBool aVisibilityDelayOff, const TDesC& aFileName ) |
|
2042 { |
|
2043 |
|
2044 delete iWaitNote; |
|
2045 iWaitNote = NULL; |
|
2046 iProgressInfo = NULL; |
|
2047 |
|
2048 if ( aResourceId == R_SVGT_DOWNLOAD_WAIT_NOTE ) |
|
2049 { |
|
2050 iWaitNote = new (ELeave) CAknWaitDialog( (CEikDialog**)&iWaitNote, |
|
2051 aVisibilityDelayOff ); |
|
2052 iWaitNote->PrepareLC(aResourceId); |
|
2053 |
|
2054 TInt resourceId = R_SVGT_DOWNLOADING_FILE; |
|
2055 HBufC* downloadMsg = StringLoader::LoadLC( resourceId ); |
|
2056 |
|
2057 TBuf<KMaxFileName> titleString; |
|
2058 titleString.Append( downloadMsg->Des() ); |
|
2059 |
|
2060 CleanupStack::PopAndDestroy( downloadMsg ); // downloadMsg |
|
2061 |
|
2062 // Add a force line feed to the note: |
|
2063 // qtn_svgt_waiting_downloading [ Downloading file ], |
|
2064 // and the note will read like this: |
|
2065 // Downloading file |
|
2066 // filename |
|
2067 titleString.Append( KNewLineStr ); |
|
2068 |
|
2069 // Append the filename |
|
2070 titleString.Append( aFileName ); |
|
2071 |
|
2072 iWaitNote->SetTextL( titleString ); |
|
2073 |
|
2074 iWaitNoteState = EDownloadImageWait; |
|
2075 } |
|
2076 else if ( aResourceId == R_SVGT_SAVING_WAIT_NOTE ) |
|
2077 { |
|
2078 iWaitNote = new (ELeave) CAknProgressDialog( (CEikDialog**)&iWaitNote, |
|
2079 aVisibilityDelayOff ); |
|
2080 iWaitNote->PrepareLC(aResourceId); |
|
2081 iProgressInfo = iWaitNote->GetProgressInfoL(); |
|
2082 iProgressInfo->SetFinalValue( KSVGTPercent ); |
|
2083 iWaitNoteState = ESaveFileWait; |
|
2084 } |
|
2085 else |
|
2086 { |
|
2087 return; |
|
2088 } |
|
2089 |
|
2090 if ( iWaitNote ) |
|
2091 { |
|
2092 iWaitNote->SetCallback(this); |
|
2093 iWaitNote->RunLD(); |
|
2094 } |
|
2095 else |
|
2096 { |
|
2097 return; |
|
2098 } |
|
2099 } |
|
2100 |
|
2101 // ----------------------------------------------------------------------------- |
|
2102 // CSVGTAppObserverUtil::DialogDismissedL |
|
2103 // This is for CAknWaitDialog callback |
|
2104 // ----------------------------------------------------------------------------- |
|
2105 // |
|
2106 EXPORT_C void CSVGTAppObserverUtil::DialogDismissedL( TInt aButtonId ) |
|
2107 { |
|
2108 |
|
2109 switch (aButtonId) |
|
2110 { |
|
2111 case EAknSoftkeyQuit: |
|
2112 { |
|
2113 if ( iWaitNoteState == ESaveFileWait ) |
|
2114 { |
|
2115 // Handle Save Cancel |
|
2116 iFileManager->CancelCopy(); |
|
2117 // Resume the presentation |
|
2118 iAppDialog->ProcessCommandL( iCommandId ); |
|
2119 } |
|
2120 else if ( iWaitNoteState == EDownloadImageWait ) |
|
2121 { |
|
2122 if ( iWait.IsStarted() ) |
|
2123 { |
|
2124 iSynchronousDownloadStopped = ETrue; |
|
2125 iWait.AsyncStop(); |
|
2126 } |
|
2127 } |
|
2128 else |
|
2129 { |
|
2130 return; |
|
2131 } |
|
2132 break; |
|
2133 } |
|
2134 default: |
|
2135 break; |
|
2136 } |
|
2137 } |
|
2138 |
|
2139 |
|
2140 // ----------------------------------------------------------------------------- |
|
2141 // CSVGTAppObserverUtil::SVGTSavingDoneL |
|
2142 // ----------------------------------------------------------------------------- |
|
2143 // |
|
2144 EXPORT_C void CSVGTAppObserverUtil::SVGTSavingDoneL( TInt aError ) |
|
2145 { |
|
2146 #ifdef SVGTVIEWERAPP_DBG_FLAG |
|
2147 TBuf<40> msg; |
|
2148 _LIT( errorMsg, "Save Done Err %d" ); |
|
2149 msg.Format(errorMsg, aError ); |
|
2150 PrintDebugMsg( msg ); |
|
2151 #endif |
|
2152 // If temporary file was used then, perform cleanup |
|
2153 if ( iTempFileUsed ) |
|
2154 { |
|
2155 if ( iTempFileName ) |
|
2156 { |
|
2157 iEikEnv->FsSession().Delete( iTempFileName->Des() ); |
|
2158 delete iTempFileName; |
|
2159 iTempFileName = NULL; |
|
2160 } |
|
2161 iTempFileUsed = EFalse; |
|
2162 } |
|
2163 |
|
2164 // Indicate to the dialog about the save completion |
|
2165 iAppDialog->SaveComplete( aError ); |
|
2166 |
|
2167 if ( !aError ) |
|
2168 { |
|
2169 iSavingDone = ETrue; |
|
2170 } |
|
2171 |
|
2172 if( iWaitNote ) |
|
2173 { |
|
2174 if ( !aError && iProgressInfo ) |
|
2175 { |
|
2176 iProgressInfo->SetAndDraw( KSVGTPercent ); |
|
2177 } |
|
2178 iWaitNote->ProcessFinishedL(); |
|
2179 delete iWaitNote; |
|
2180 iWaitNote = NULL; |
|
2181 |
|
2182 #ifdef SVGTVIEWERAPP_DBG_FLAG |
|
2183 _LIT( errorMsg, "Proc Finished called" ); |
|
2184 PrintDebugMsg( errorMsg() ); |
|
2185 #endif |
|
2186 |
|
2187 } |
|
2188 |
|
2189 if ( !aError ) |
|
2190 { |
|
2191 |
|
2192 // "saved" note |
|
2193 HBufC* text = StringLoader::LoadLC(R_SVGT_CLIP_SAVED); |
|
2194 CAknInformationNote* dlg = new (ELeave) CAknInformationNote( ETrue ); |
|
2195 dlg->ExecuteLD(*text); |
|
2196 CleanupStack::PopAndDestroy( text ); // text |
|
2197 |
|
2198 |
|
2199 } |
|
2200 else |
|
2201 { |
|
2202 iEikEnv->HandleError( aError ); |
|
2203 } |
|
2204 |
|
2205 // If move allowed or it is the overwriting self case then |
|
2206 if ( IsAllowMove() || iIsOverwriteCase ) |
|
2207 { |
|
2208 if ( !aError ) |
|
2209 { |
|
2210 // No error occurred |
|
2211 |
|
2212 // File has been moved and source |
|
2213 // deleted hence don't show save now. |
|
2214 iCanSaveContent = EFalse; |
|
2215 // If It was Move operation, then Open the new file |
|
2216 // and give the handle to dialog. |
|
2217 if ( iSvgFileId->Open(iEikEnv->FsSession(), |
|
2218 iSvgDstFileName->Des(), EFileShareAny) != KErrNone ) |
|
2219 { |
|
2220 // Shouldn't happen. |
|
2221 return; |
|
2222 } |
|
2223 else |
|
2224 { |
|
2225 iAppDialog->StartUsingContentFileHandle(); |
|
2226 } |
|
2227 } |
|
2228 else // Error occurred while saving, try to recover |
|
2229 { |
|
2230 // If it was Move Operation, and failed, then Open |
|
2231 // Original Source file again and give the handle to |
|
2232 // dialog. Note this could fail potentially as the |
|
2233 // original file could have been deleted. |
|
2234 if ( iSvgFileId->Open(iEikEnv->FsSession(), |
|
2235 iSvgFileName->Des(), EFileShareAny) != KErrNone ) |
|
2236 { |
|
2237 //Inconsistent state, can't show save also. |
|
2238 iCanSaveContent = EFalse; |
|
2239 return; |
|
2240 } |
|
2241 else |
|
2242 { |
|
2243 // Can keep showing the save option still. |
|
2244 iAppDialog->StartUsingContentFileHandle(); |
|
2245 } |
|
2246 } |
|
2247 } |
|
2248 |
|
2249 if ( !aError ) |
|
2250 { |
|
2251 if ( iDeleteOrigFile ) |
|
2252 { |
|
2253 iEikEnv->FsSession().Delete( iSvgFileName->Des() ); |
|
2254 iSvgFileName->Des().Zero(); |
|
2255 } |
|
2256 // Pass the command id back to UiDialog |
|
2257 iAppDialog->ProcessCommandL( iCommandId ); |
|
2258 } |
|
2259 } |
|
2260 |
|
2261 // ----------------------------------------------------------------------------- |
|
2262 // CSVGTAppObserverUtil::SVGTPositionChanged |
|
2263 // ----------------------------------------------------------------------------- |
|
2264 // |
|
2265 EXPORT_C void CSVGTAppObserverUtil::SVGTPositionChanged(TInt aPosition) |
|
2266 { |
|
2267 if (iWaitNote && iProgressInfo) |
|
2268 { |
|
2269 iProgressInfo->SetAndDraw(aPosition); |
|
2270 } |
|
2271 /* |
|
2272 else if (iFullScreen) |
|
2273 { |
|
2274 TRAPD(ignore, iContainer->UpdateBufferingL(aPosition) ); |
|
2275 } // (L961) |
|
2276 */ |
|
2277 } |
|
2278 |
|
2279 #ifdef SVGTVIEWERAPP_DBG_FLAG |
|
2280 // ----------------------------------------------------------------------------- |
|
2281 // CSVGTAppObserverUtil::PrintDebugMsg |
|
2282 // ----------------------------------------------------------------------------- |
|
2283 // |
|
2284 void CSVGTAppObserverUtil::PrintDebugMsg( const TDesC& aMsg ) |
|
2285 { |
|
2286 #ifdef _DEBUG |
|
2287 RFileLogger::Write( KFileLoggingDir, KFileLog, |
|
2288 EFileLoggingModeAppend, aMsg ); |
|
2289 #endif |
|
2290 } |
|
2291 #endif |
|
2292 |
|
2293 // ----------------------------------------------------------------------------- |
|
2294 // CSVGTAppObserverUtil::DoAssignImageDataL |
|
2295 // Reads the downloaded file & gives data to the svg engine. |
|
2296 // ----------------------------------------------------------------------------- |
|
2297 // |
|
2298 void CSVGTAppObserverUtil::DoAssignImageDataL(const CSVGTViewerAppDownloads* aDownloadItem, |
|
2299 RHttpDownload& aDownload) |
|
2300 { |
|
2301 if( aDownloadItem && !aDownloadItem->ImageLinkFlag() ) |
|
2302 { |
|
2303 TFileName lFileName; |
|
2304 // Get the file path of the downloaded file |
|
2305 aDownload.GetStringAttribute( EDlAttrDestFilename, lFileName ); |
|
2306 |
|
2307 TInt lFileSize = 0; |
|
2308 RFile lSvgFile; |
|
2309 // Attempt to open the file in read mode |
|
2310 User::LeaveIfError( lSvgFile.Open(iEikEnv->FsSession(),lFileName,EFileRead ) ); |
|
2311 |
|
2312 // Save on cleanup stack |
|
2313 CleanupClosePushL( lSvgFile ); |
|
2314 |
|
2315 // Get the size of the data to create read buffer |
|
2316 User::LeaveIfError( lSvgFile.Size(lFileSize) ); |
|
2317 |
|
2318 // Create buffer that will contain the file data |
|
2319 HBufC8* lFileData = HBufC8::NewLC(lFileSize); |
|
2320 TPtr8 lFileDataPtr(lFileData->Des()); |
|
2321 |
|
2322 // Read from the file |
|
2323 User::LeaveIfError( lSvgFile.Read(lFileDataPtr) ); |
|
2324 |
|
2325 // Create buffer to store the URI of the file |
|
2326 HBufC* lUriBuf = HBufC::NewLC( KMaxUrlLength ); |
|
2327 TPtr lUriPtr(lUriBuf->Des()); |
|
2328 |
|
2329 // Get the URI from data structure |
|
2330 aDownload.GetStringAttribute( EDlAttrReqUrl, lUriPtr ); |
|
2331 |
|
2332 // Call the AssignImageData function |
|
2333 // Mapping is maintained between URI <-> FileData |
|
2334 iAppDialog->AssignImageData(lUriPtr , lFileData ); |
|
2335 |
|
2336 CleanupStack::PopAndDestroy( lUriBuf ); |
|
2337 CleanupStack::Pop( lFileData ); |
|
2338 CleanupStack::PopAndDestroy(&lSvgFile); // lSvgFile.Close() |
|
2339 } |
|
2340 } |
|
2341 |
|
2342 void CSVGTAppObserverUtil::DoAssignLocalFileDataL( const TDesC& aOriginalUri, |
|
2343 const TDesC& aNewUri ) const |
|
2344 { |
|
2345 TInt lFileSize = 0; |
|
2346 TBuf<KMaxPath>lFileName; |
|
2347 lFileName.Copy(aNewUri); |
|
2348 RFile lSvgFile; |
|
2349 // Attempt to open the file in read mode |
|
2350 User::LeaveIfError( lSvgFile.Open(iEikEnv->FsSession(),lFileName,EFileRead ) ); |
|
2351 |
|
2352 // Save on cleanup stack |
|
2353 CleanupClosePushL( lSvgFile ); |
|
2354 |
|
2355 // Get the size of the data to create read buffer |
|
2356 User::LeaveIfError( lSvgFile.Size(lFileSize) ); |
|
2357 // Create buffer that will contain the file data |
|
2358 HBufC8* lFileData = HBufC8::NewLC(lFileSize); |
|
2359 TPtr8 lFileDataPtr(lFileData->Des()); |
|
2360 // Read from the file |
|
2361 User::LeaveIfError( lSvgFile.Read(lFileDataPtr) ); |
|
2362 |
|
2363 // Call the AssignImageData function |
|
2364 // Mapping is maintained between URI <-> FileData |
|
2365 iAppDialog->AssignImageData(aOriginalUri , lFileData ); |
|
2366 |
|
2367 CleanupStack::Pop( lFileData ); |
|
2368 CleanupStack::PopAndDestroy(&lSvgFile); // lSvgFile.Close() |
|
2369 } |
|
2370 |
|
2371 EXPORT_C void CSVGTAppObserverUtil::AssignEmbededDataL( const TDesC& aUri ) |
|
2372 { |
|
2373 HBufC8* decoded = DoGetProcessedEmbededDataL( aUri ); |
|
2374 if ( decoded ) |
|
2375 { |
|
2376 iAppDialog->AssignImageData( aUri, decoded ); |
|
2377 } |
|
2378 } |
|
2379 |
|
2380 HBufC8* CSVGTAppObserverUtil::DoGetProcessedEmbededDataL( const TDesC& aXlinkHrefValue ) const |
|
2381 { |
|
2382 HBufC8* retPtr = NULL; |
|
2383 // find positions for ';' and ',' to determine encoding, mimetype |
|
2384 TInt startIndex = aXlinkHrefValue.Locate( ';' ); |
|
2385 TInt endIndex = aXlinkHrefValue.Locate( ',' ); |
|
2386 |
|
2387 // mimetype is after 'data:' : xlink:href="data:image/png;base64, |
|
2388 // ignore mimetype extraction, decode will detect mimetype from decoded data. |
|
2389 |
|
2390 if ( startIndex != KErrNotFound && |
|
2391 endIndex != KErrNotFound && |
|
2392 startIndex < endIndex ) |
|
2393 { |
|
2394 // extract encoding type |
|
2395 TPtrC encoding( aXlinkHrefValue.Left( endIndex ).Right( endIndex - startIndex - 1 ) ); |
|
2396 // handle Base64 encoding |
|
2397 _LIT( KEncodingBase64, "base64" ); |
|
2398 if ( encoding == KEncodingBase64 ) |
|
2399 { |
|
2400 // find index of first character after white-space |
|
2401 TInt index = endIndex + 1; |
|
2402 while ( index < aXlinkHrefValue.Length() && TChar( aXlinkHrefValue[index] ).IsSpace() ) |
|
2403 index++; |
|
2404 |
|
2405 // must be 8-bit |
|
2406 TInt length = aXlinkHrefValue.Length() - index; |
|
2407 HBufC8* encoded = HBufC8::NewLC( length ); |
|
2408 encoded->Des().Copy( aXlinkHrefValue.Right( length ) ); |
|
2409 |
|
2410 HBufC8* decoded = HBufC8::NewLC( length ); |
|
2411 TPtr8 decodedDes = decoded->Des(); |
|
2412 |
|
2413 // decode |
|
2414 TImCodecB64 encodingBase64; |
|
2415 TInt decodeError = encodingBase64.Decode( *encoded, decodedDes ); |
|
2416 |
|
2417 // Cleanup |
|
2418 CleanupStack::Pop( decoded ); // encoded, decoded |
|
2419 CleanupStack::PopAndDestroy( encoded ); |
|
2420 //delete encoded; |
|
2421 |
|
2422 // Check for decoding error |
|
2423 if ( decodeError != KErrNone ) |
|
2424 { |
|
2425 delete decoded; |
|
2426 } |
|
2427 else |
|
2428 { |
|
2429 retPtr = decoded; |
|
2430 } |
|
2431 } |
|
2432 } |
|
2433 return retPtr; |
|
2434 } |
|
2435 TBool CSVGTAppObserverUtil::ExitWhenOrientationChange() |
|
2436 { |
|
2437 return EFalse; |
|
2438 } |
|
2439 |
|
2440 // End of File |
|
2441 |