|
1 /* |
|
2 * Copyright (c) 2002-2006 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: Implementation of CDocumentHandler class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "DocumentHandler.h" // Class Declaration |
|
22 #include "DocConstants.h" |
|
23 |
|
24 // All special handlers and the default handler |
|
25 #include "DocDefaultHandler.h" |
|
26 #include "DocImageHandler.h" |
|
27 #include "DocGameHandler.h" |
|
28 #include "DocAppInstHandler.h" |
|
29 //#include "DocMidletHandler.h" |
|
30 |
|
31 #ifdef ENABLE_DRM |
|
32 #include "DocDCFHandler.h" |
|
33 #include <Oma2Agent.h> |
|
34 #endif // ENABLE_DRM |
|
35 |
|
36 #include <AiwGenericParam.h> |
|
37 |
|
38 #include <featmgr.h> |
|
39 |
|
40 #include <centralrepository.h> |
|
41 #include <CommonUiInternalCRKeys.h> |
|
42 |
|
43 #define LEAVEONERROR( error ) if( error != KUserCancel && error != KErrNone )\ |
|
44 User::Leave( error ) |
|
45 |
|
46 const TInt KDocMaxCenRepBufLen = 1024; |
|
47 const TInt KDocPDMaxMimeLen = 64; |
|
48 const TInt KDocPDMaxUids = 24; |
|
49 const TInt KDocPDMaxUidLen = 12; |
|
50 const TInt KDocMaxDigitsInHexString = 8; // 32 bits. |
|
51 |
|
52 // ================= MEMBER FUNCTIONS ======================= |
|
53 |
|
54 // C++ default constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // @since Series60 3.0 |
|
57 // |
|
58 CDocumentHandler::CDocumentHandler() |
|
59 { |
|
60 } |
|
61 |
|
62 // Two-phased constructor. |
|
63 // @since Series60 3.0 |
|
64 EXPORT_C CDocumentHandler* CDocumentHandler::NewL( ) |
|
65 { |
|
66 CDocumentHandler* self = NewLC( ); |
|
67 CleanupStack::Pop(); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // Two-phased constructor. |
|
72 // @since Series60 3.0 |
|
73 EXPORT_C CDocumentHandler* CDocumentHandler::NewLC( ) |
|
74 { |
|
75 CDocumentHandler* self = new( ELeave ) CDocumentHandler ( ); |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // EPOC default constructor can leave. |
|
82 void CDocumentHandler::ConstructL() |
|
83 { |
|
84 iApaLs = new ( ELeave ) RApaLsSession; |
|
85 User::LeaveIfError(iApaLs->Connect()); |
|
86 |
|
87 FeatureManager::InitializeLibL(); |
|
88 |
|
89 iTempFileName.Zero(); |
|
90 } |
|
91 |
|
92 // Two-phased constructor. |
|
93 EXPORT_C CDocumentHandler* CDocumentHandler::NewL( CEikProcess* /*aProcess*/ ) |
|
94 { |
|
95 CDocumentHandler* self = NewLC( ); |
|
96 CleanupStack::Pop(); |
|
97 return self; |
|
98 } |
|
99 |
|
100 // Two-phased constructor. |
|
101 EXPORT_C CDocumentHandler* CDocumentHandler::NewLC( CEikProcess* /*aProcess*/ ) |
|
102 { |
|
103 CDocumentHandler* self = new( ELeave ) CDocumentHandler ( ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 return self; |
|
107 } |
|
108 |
|
109 // Destructor |
|
110 EXPORT_C CDocumentHandler::~CDocumentHandler() |
|
111 { |
|
112 FeatureManager::UnInitializeLib(); |
|
113 |
|
114 if ( iApaLs ) |
|
115 { |
|
116 iApaLs->Close(); |
|
117 delete iApaLs; |
|
118 } |
|
119 |
|
120 CloseSharableFS(); |
|
121 |
|
122 // If we have temp file, we use iHandler services to delete this file |
|
123 if ( iTempFileName.Length() != 0 && iHandler ) |
|
124 { |
|
125 iHandler->DeleteFile(iTempFileName); |
|
126 } |
|
127 |
|
128 delete iHandler; |
|
129 |
|
130 if ( iInParams ) |
|
131 { |
|
132 delete iInParams; |
|
133 } |
|
134 |
|
135 #ifdef _DEBUG |
|
136 RDebug::Print( _L("DocumentHandler: CDocumentHandler instance destructed succesfully!")); |
|
137 #endif |
|
138 } |
|
139 |
|
140 |
|
141 // --------------------------------------------------------- |
|
142 // RApaLsSession* CDocumentHandler::ApaLs() |
|
143 // Returns Application list server object |
|
144 // --------------------------------------------------------- |
|
145 RApaLsSession* CDocumentHandler::ApaLs() |
|
146 { |
|
147 return iApaLs; |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------- |
|
151 // CDocumentHandler::DocOperation() |
|
152 // Returns CDocumentHandler::iOperation. |
|
153 // --------------------------------------------------------- |
|
154 TDocOperation CDocumentHandler::DocOperation() const |
|
155 { |
|
156 return iOperation; |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // MApaEmbeddedDocObserver* CDocumentHandler::ExitObserver() |
|
161 // Returns ExitObserver |
|
162 // @since Series60 3.0 |
|
163 // --------------------------------------------------------- |
|
164 MAknServerAppExitObserver* CDocumentHandler::ServerAppExitObserver() const |
|
165 { |
|
166 return iServerAppExitObserver; |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------- |
|
170 // CDocumentHandler::SaveL |
|
171 // Save content to the correct directory based on aDataType |
|
172 // with a generated filename and attributes. |
|
173 // |
|
174 // This functions calls other SaveL version. |
|
175 // |
|
176 // Returns: KErrNone: Everything went ok |
|
177 // KUserCancel: The user cancelled the operation |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 EXPORT_C TInt CDocumentHandler::SaveL( |
|
181 const TDesC8& aContent, // Content buffer |
|
182 TDataType& aDataType, // Mime type of the content |
|
183 const TUint aAttr ) // Save with these attributes |
|
184 { |
|
185 #ifdef _DEBUG |
|
186 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SaveL(aContent, aDataType, aAttr) Called")); |
|
187 TPtrC mimetype = aDataType.Des(); |
|
188 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S "), &mimetype); |
|
189 #endif |
|
190 |
|
191 TFileName nullFileName; |
|
192 |
|
193 return SaveL(aContent, aDataType, nullFileName, aAttr); |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CDocumentHandler::SaveL |
|
198 // Save content to the correct directory based on aDataType |
|
199 // with aFileName and attributes. |
|
200 // |
|
201 // We first save wile with SaveTempFileL command. |
|
202 // After that we use MoveL command. |
|
203 // |
|
204 // Returns: KErrNone: Everything went ok |
|
205 // KUserCancel: The user cancelled the operation |
|
206 // --------------------------------------------------------- |
|
207 // |
|
208 EXPORT_C TInt CDocumentHandler::SaveL( |
|
209 const TDesC8& aContent, // Content buffer |
|
210 TDataType& aDataType, // Mime type of the content |
|
211 const TDesC& aName, // Save with this name |
|
212 const TUint aAttr ) // Save with these attributes |
|
213 { |
|
214 #ifdef _DEBUG |
|
215 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SaveL(aContent, aDataType, aFileName, aAttr) Called")); |
|
216 TPtrC mimetype = aDataType.Des(); |
|
217 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- aFileName: %S "), &mimetype, &aName); |
|
218 #endif |
|
219 |
|
220 TUid uid = { 0 }; |
|
221 TInt error; |
|
222 |
|
223 if (aDataType.Des8().FindF( KDummyMimeType ) != KErrNotFound) |
|
224 { |
|
225 return KErrNone; |
|
226 } |
|
227 |
|
228 TFileName tempFileName; |
|
229 |
|
230 iOperation = EDocSaveTemp; // First save temp file |
|
231 |
|
232 // Use Default Handler for saving whatever mimetype actually is |
|
233 delete iHandler; // delete the old handler |
|
234 iHandler = NULL; |
|
235 iHandler = CDocDefaultHandler::NewL( aDataType, |
|
236 uid, this, EDocSaveOnly ); |
|
237 |
|
238 error = iHandler->SetDestName( aName ); // Save with this file name |
|
239 |
|
240 // Close if existing sharable RFs and create new for sharing purposes. |
|
241 if ( error == KErrNone ) |
|
242 { |
|
243 CloseSharableFS(); |
|
244 User::LeaveIfError(iSharableFS.Connect()); |
|
245 iSharableFS.ShareProtected(); |
|
246 } |
|
247 |
|
248 if ( error == KErrNone ) |
|
249 { |
|
250 error = iHandler->SaveTempFileL( aContent, KEntryAttNormal, tempFileName); |
|
251 } |
|
252 |
|
253 iOperation = EDocMove; // Move temp file to correct folder |
|
254 |
|
255 if ( error == KErrNone ) |
|
256 { |
|
257 RecognizeAndCheckFileL( tempFileName, aDataType, uid ); |
|
258 |
|
259 TRAP( error, FindHandlerL( aDataType, uid ) ); // allow unsupported. |
|
260 if ( error == KMimeNotSupported ) |
|
261 { |
|
262 iHandler = CDocDefaultHandler::NewL( aDataType, uid, this, EDocSaveOnly ); |
|
263 error = KErrNone; |
|
264 } |
|
265 else |
|
266 { |
|
267 User::LeaveIfError( error ); |
|
268 } |
|
269 } |
|
270 |
|
271 if ( !iHandler->CanSave() ) |
|
272 { |
|
273 User::Leave( KErrNotSupported ); |
|
274 } |
|
275 |
|
276 if ( error == KErrNone ) |
|
277 { |
|
278 error = iHandler->SetSrcFileName( tempFileName ); |
|
279 } |
|
280 |
|
281 if ( error == KErrNone ) |
|
282 { |
|
283 error = iHandler->SetDestName( aName ); |
|
284 } |
|
285 |
|
286 // We use CopyOrMoveL-function, iOperation is checked there |
|
287 if ( error == KErrNone ) |
|
288 { |
|
289 error = iHandler->CopyOrMoveL( aAttr ); |
|
290 } |
|
291 |
|
292 #ifdef _DEBUG |
|
293 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SaveL: finished with error=%d."), error); |
|
294 #endif |
|
295 |
|
296 LEAVEONERROR( error ); |
|
297 |
|
298 // Because DCF files are not tried to be recognized we return empty |
|
299 // type here. Normally the return value has the type which was used |
|
300 // when handler was selected. |
|
301 #ifdef ENABLE_DRM |
|
302 #ifdef __DRM_OMA2 |
|
303 if ( aDataType.Des8().FindF( KOma1DcfContentType ) != KErrNotFound || |
|
304 aDataType.Des8().FindF( KOma2DcfContentType ) != KErrNotFound ) |
|
305 #else // __DRM_OMA2 |
|
306 if ( aDataType.Des8().FindF( KOma1DcfContentType ) != KErrNotFound ) |
|
307 #endif // __DRM_OMA2 |
|
308 { |
|
309 TDataType emptyDataType; |
|
310 aDataType = emptyDataType; |
|
311 } |
|
312 #endif // ENABLE_DRM |
|
313 |
|
314 return error; |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------- |
|
318 // CDocumentHandler::CopyL |
|
319 // Copy file to the correct directory based on it's mime type. |
|
320 // |
|
321 // Returns: KErrNone: Everything went ok |
|
322 // KUserCancel: The user cancelled the operation |
|
323 // --------------------------------------------------------- |
|
324 // |
|
325 EXPORT_C TInt CDocumentHandler::CopyL( |
|
326 const TDesC& aFileNameOld, // copy data from this file |
|
327 const TDesC& aFileNameNew, // using this filename |
|
328 TDataType& aDataType, // Mime type of data |
|
329 const TUint aAttr ) // use these attributes |
|
330 { |
|
331 #ifdef _DEBUG |
|
332 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CopyL(aFileNameOld, aFileNameNew, aDataType, aAttr) Called")); |
|
333 TPtrC mimetype = aDataType.Des(); |
|
334 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- aFileNameOld: %S -- aFileNameNew: %S"), &mimetype, &aFileNameOld, &aFileNameNew); |
|
335 #endif |
|
336 |
|
337 TInt error = KErrNone; |
|
338 TUid uid = { 0 }; |
|
339 |
|
340 if (aDataType.Des8().FindF( KDummyMimeType ) != KErrNotFound) |
|
341 { |
|
342 return KErrNone; |
|
343 } |
|
344 |
|
345 iOperation = EDocCopy; |
|
346 |
|
347 RecognizeAndCheckFileL( aFileNameOld, aDataType, uid ); |
|
348 |
|
349 TRAP( error, FindHandlerL( aDataType, uid ) ); // allow unsupported. |
|
350 if ( error == KMimeNotSupported ) |
|
351 { |
|
352 iHandler = CDocDefaultHandler::NewL( aDataType, uid, this, EDocSaveOnly ); |
|
353 error = KErrNone; |
|
354 } |
|
355 else |
|
356 { |
|
357 User::LeaveIfError( error ); |
|
358 } |
|
359 |
|
360 if ( !iHandler->CanSave() ) |
|
361 { |
|
362 User::Leave( KErrNotSupported ); |
|
363 } |
|
364 |
|
365 error = iHandler->SetSrcFileName( aFileNameOld ); |
|
366 if ( error == KErrNone ) |
|
367 { |
|
368 // If aFileNameNew is not set, use source file name |
|
369 if (aFileNameNew.Length() != 0) |
|
370 { |
|
371 error = iHandler->SetDestName( aFileNameNew ); |
|
372 } |
|
373 else |
|
374 { |
|
375 error = iHandler->SetDestName( aFileNameOld ); |
|
376 } |
|
377 } |
|
378 |
|
379 // We use CopyOrMoveL-function, iOperation is checked there |
|
380 if ( error == KErrNone ) |
|
381 { |
|
382 error = iHandler->CopyOrMoveL( aAttr ); |
|
383 } |
|
384 |
|
385 #ifdef _DEBUG |
|
386 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CopyL: finished with error=%d."), error); |
|
387 #endif |
|
388 |
|
389 LEAVEONERROR( error ); |
|
390 |
|
391 return error; |
|
392 } |
|
393 |
|
394 |
|
395 // --------------------------------------------------------- |
|
396 // CDocumentHandler::CopyL |
|
397 // Copy file to the correct directory based on it's mime type. |
|
398 // |
|
399 // Returns: KErrNone: Everything went ok |
|
400 // KUserCancel: The user cancelled the operation |
|
401 // --------------------------------------------------------- |
|
402 // |
|
403 EXPORT_C TInt CDocumentHandler::CopyL( |
|
404 const RFile& aFileOld, // copy data from this file |
|
405 const TDesC& aFileNameNew, // using this filename |
|
406 TDataType& aDataType, // Mime type of data |
|
407 const TUint aAttr ) // use these attributes |
|
408 { |
|
409 #ifdef _DEBUG |
|
410 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CopyL(aFileOld, aFileNameNew, aDataType, aAttr) Called")); |
|
411 TPtrC mimetype = aDataType.Des(); |
|
412 TFileName fileNameOld; |
|
413 aFileOld.FullName(fileNameOld); |
|
414 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- aFileOld (name): %S -- aFileNameNew: %S"), &mimetype, &fileNameOld, &aFileNameNew); |
|
415 #endif |
|
416 |
|
417 TInt error = KErrNone; |
|
418 TUid uid = { 0 }; |
|
419 |
|
420 if (aDataType.Des8().FindF( KDummyMimeType ) != KErrNotFound) |
|
421 { |
|
422 return KErrNone; |
|
423 } |
|
424 |
|
425 iOperation = EDocCopy; |
|
426 |
|
427 RecognizeAndCheckFileL( const_cast<RFile&>(aFileOld), aDataType, uid ); |
|
428 |
|
429 TRAP( error, FindHandlerL( aDataType, uid ) ); // allow unsupported. |
|
430 if ( error == KMimeNotSupported ) |
|
431 { |
|
432 iHandler = CDocDefaultHandler::NewL( aDataType, uid, this, EDocSaveOnly ); |
|
433 error = KErrNone; |
|
434 } |
|
435 else |
|
436 { |
|
437 User::LeaveIfError( error ); |
|
438 } |
|
439 |
|
440 if ( !iHandler->CanSave() ) |
|
441 { |
|
442 User::Leave( KErrNotSupported ); |
|
443 } |
|
444 |
|
445 TFileName filenameold; |
|
446 aFileOld.FullName( filenameold ); |
|
447 iHandler->SetSrcFileName( filenameold ); |
|
448 |
|
449 // If aFileNameNew is not set, use source file name |
|
450 if (aFileNameNew.Length() != 0) |
|
451 { |
|
452 error = iHandler->SetDestName( aFileNameNew ); |
|
453 } |
|
454 else |
|
455 { |
|
456 aFileOld.Name( filenameold ); |
|
457 error = iHandler->SetDestName( filenameold ); |
|
458 } |
|
459 |
|
460 // Let's do actual copying using CopyHandleL method |
|
461 if ( error == KErrNone ) |
|
462 { |
|
463 error = iHandler->CopyHandleL( aFileOld, aAttr ); |
|
464 } |
|
465 |
|
466 #ifdef _DEBUG |
|
467 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CopyL: finished with error=%d."), error); |
|
468 #endif |
|
469 |
|
470 LEAVEONERROR( error ); |
|
471 |
|
472 return error; |
|
473 } |
|
474 |
|
475 // --------------------------------------------------------- |
|
476 // CDocumentHandler::MoveL |
|
477 // Move file to the correct directory based on it's mime type. |
|
478 // |
|
479 // Returns: KErrNone: Everything went ok |
|
480 // KUserCancel: The user cancelled the operation |
|
481 // --------------------------------------------------------- |
|
482 // |
|
483 EXPORT_C TInt CDocumentHandler::MoveL( |
|
484 const TDesC& aFileNameOld, // Move this file ... |
|
485 const TDesC& aFileNameNew, // ...to this filename |
|
486 TDataType& aDataType, // Mime type of data |
|
487 const TUint aAttr ) // use these attributes to new file |
|
488 { |
|
489 #ifdef _DEBUG |
|
490 RDebug::Print( _L("DocumentHandler: CDocumentHandler::MoveL(aFileNameOld, aFileNameNew, aDataType, aAttr) Called")); |
|
491 TPtrC mimetype = aDataType.Des(); |
|
492 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- aFileNameOld: %S -- aFileNameNew: %S"), &mimetype, &aFileNameOld, &aFileNameNew); |
|
493 #endif |
|
494 |
|
495 TInt error = KErrNone; |
|
496 TUid uid = { 0 }; |
|
497 |
|
498 if (aDataType.Des8().FindF( KDummyMimeType ) != KErrNotFound) |
|
499 { |
|
500 return KErrNone; |
|
501 } |
|
502 |
|
503 iOperation = EDocMove; |
|
504 |
|
505 RecognizeAndCheckFileL( aFileNameOld, aDataType, uid ); |
|
506 |
|
507 TRAP( error, FindHandlerL( aDataType, uid ) ); // allow unsupported. |
|
508 if ( error == KMimeNotSupported ) |
|
509 { |
|
510 iHandler = CDocDefaultHandler::NewL( aDataType, uid, this, EDocSaveOnly ); |
|
511 error = KErrNone; |
|
512 } |
|
513 else |
|
514 { |
|
515 User::LeaveIfError( error ); |
|
516 } |
|
517 |
|
518 if ( !iHandler->CanSave() ) |
|
519 { |
|
520 User::Leave( KErrNotSupported ); |
|
521 } |
|
522 |
|
523 error = iHandler->SetSrcFileName( aFileNameOld ); |
|
524 if ( error == KErrNone ) |
|
525 { |
|
526 error = iHandler->SetDestName( aFileNameNew ); |
|
527 } |
|
528 |
|
529 // We use CopyOrMoveL-function, iOperation is checked there |
|
530 if ( error == KErrNone ) |
|
531 { |
|
532 error = iHandler->CopyOrMoveL( aAttr ); |
|
533 } |
|
534 |
|
535 #ifdef _DEBUG |
|
536 RDebug::Print( _L("DocumentHandler: CDocumentHandler::MoveL: finished with error=%d."), error); |
|
537 #endif |
|
538 |
|
539 LEAVEONERROR( error ); |
|
540 |
|
541 return error; |
|
542 } |
|
543 |
|
544 // --------------------------------------------------------- |
|
545 // CDocumentHandler::SilentMoveL |
|
546 // Move file to the correct directory based on it's mime type. |
|
547 // Not any user interaction. |
|
548 // |
|
549 // Returns: KErrNone: Everything went ok |
|
550 // KUserCancel: The user cancelled the operation |
|
551 // --------------------------------------------------------- |
|
552 // |
|
553 EXPORT_C TInt CDocumentHandler::SilentMoveL( |
|
554 const TDesC& aFileNameOld, |
|
555 const TDesC& aNameNew, |
|
556 const TDesC& aRootPath, |
|
557 TDataType& aDataType, |
|
558 const TUint aAttr ) |
|
559 { |
|
560 #ifdef _DEBUG |
|
561 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SilentMoveL(aFileNameOld, aFileNameNew, aDataType, aAttr) Called")); |
|
562 TPtrC mimetype = aDataType.Des(); |
|
563 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- aFileNameOld: %S -- aFileNameNew: %S"), &mimetype, &aFileNameOld, &aNameNew); |
|
564 #endif |
|
565 |
|
566 TInt error = KErrNone; |
|
567 TUid uid = { 0 }; |
|
568 |
|
569 if (aDataType.Des8().FindF( KDummyMimeType ) != KErrNotFound) |
|
570 { |
|
571 return KErrNone; |
|
572 } |
|
573 |
|
574 iOperation = EDocSilentMove; |
|
575 |
|
576 RecognizeAndCheckFileL( aFileNameOld, aDataType, uid ); |
|
577 |
|
578 TRAP( error, FindHandlerL( aDataType, uid ) ); // allow unsupported. |
|
579 if ( error == KMimeNotSupported ) |
|
580 { |
|
581 iHandler = CDocDefaultHandler::NewL( aDataType, uid, this, EDocSaveOnly ); |
|
582 error = KErrNone; |
|
583 } |
|
584 else |
|
585 { |
|
586 User::LeaveIfError( error ); |
|
587 } |
|
588 |
|
589 if ( !iHandler->CanSave() ) |
|
590 { |
|
591 User::Leave( KErrNotSupported ); |
|
592 } |
|
593 |
|
594 error = iHandler->SetRootPath( aRootPath ); |
|
595 |
|
596 if ( error == KErrNone ) |
|
597 { |
|
598 error = iHandler->SetSrcFileName( aFileNameOld ); |
|
599 } |
|
600 if ( error == KErrNone ) |
|
601 { |
|
602 error = iHandler->SetDestName( aNameNew ); |
|
603 } |
|
604 |
|
605 // We use CopyOrMoveL-function, iOperation is checked there |
|
606 if ( error == KErrNone ) |
|
607 { |
|
608 error = iHandler->CopyOrMoveL( aAttr ); |
|
609 } |
|
610 |
|
611 #ifdef _DEBUG |
|
612 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SilentMoveL: finished with error=%d."), error); |
|
613 #endif |
|
614 |
|
615 LEAVEONERROR( error ); |
|
616 |
|
617 return error; |
|
618 } |
|
619 |
|
620 // --------------------------------------------------------- |
|
621 // CDocumentHandler::OpenFileL |
|
622 // |
|
623 // Open a file with a given data type standalone. |
|
624 // Calls other version of OpenFileL. |
|
625 // |
|
626 // Returns: KErrNone: Everything went ok |
|
627 // KUserCancel: The user cancelled the operation |
|
628 // --------------------------------------------------------- |
|
629 // |
|
630 EXPORT_C TInt CDocumentHandler::OpenFileL( |
|
631 const TDesC& aFileName, // Read data from here |
|
632 TDataType& aDataType ) // mime type of the data |
|
633 { |
|
634 #ifdef _DEBUG |
|
635 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenFileL(aFileName, aDataType) Called")); |
|
636 TPtrC mimetype = aDataType.Des(); |
|
637 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- aFileName: %S "), &mimetype, &aFileName); |
|
638 #endif |
|
639 |
|
640 RFile fileHandle; |
|
641 OpenTempFileL(aFileName, fileHandle); |
|
642 TInt error = OpenFileL(fileHandle, aDataType); |
|
643 fileHandle.Close(); |
|
644 return error; |
|
645 } |
|
646 |
|
647 // --------------------------------------------------------- |
|
648 // CDocumentHandler::OpenFileL |
|
649 // |
|
650 // Open a file with a given data type standalone. First |
|
651 // check that the content is supported and get the handler |
|
652 // application's UID. Based on that UID find the correct |
|
653 // handler for the content. File data is not copied over. |
|
654 // |
|
655 // Returns: KErrNone: Everything went ok |
|
656 // KUserCancel: The user cancelled the operation |
|
657 // --------------------------------------------------------- |
|
658 // |
|
659 EXPORT_C TInt CDocumentHandler::OpenFileL( |
|
660 RFile& aSharableFile, |
|
661 TDataType& aDataType) |
|
662 { |
|
663 #ifdef _DEBUG |
|
664 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenFileL(aSharableFile, aDataType) Called")); |
|
665 TPtrC mimetype = aDataType.Des(); |
|
666 TFileName filename; |
|
667 aSharableFile.FullName(filename); |
|
668 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- fullname of filehandle: %S "), &mimetype, &filename); |
|
669 #endif |
|
670 |
|
671 TUid uid = { 0 }; |
|
672 TInt error; |
|
673 |
|
674 if (aDataType.Des8().FindF( KDummyMimeType ) != KErrNotFound) |
|
675 { |
|
676 return KErrNone; |
|
677 } |
|
678 |
|
679 iOperation = EDocOpenFile; |
|
680 |
|
681 RecognizeAndCheckFileL( aSharableFile, aDataType, uid ); |
|
682 |
|
683 FindHandlerL( aDataType, uid ); |
|
684 |
|
685 if ( !iHandler->CanOpen() ) |
|
686 { |
|
687 User::Leave( KErrNotSupported ); |
|
688 } |
|
689 |
|
690 error = iHandler->OpenFileL(aSharableFile); // Do open file |
|
691 |
|
692 #ifdef _DEBUG |
|
693 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenFileL: finished with error=%d."), error); |
|
694 #endif |
|
695 |
|
696 LEAVEONERROR( error ); |
|
697 |
|
698 return error; |
|
699 } |
|
700 |
|
701 // --------------------------------------------------------- |
|
702 // CDocumentHandler::OpenFileEmbeddedL |
|
703 // Open a file with a given data type embedded. |
|
704 // Calls other version of OpenFileEmbeddedL. |
|
705 // |
|
706 // Returns: KErrNone: Everything went ok |
|
707 // KUserCancel: The user cancelled the operation |
|
708 // --------------------------------------------------------- |
|
709 // |
|
710 EXPORT_C TInt CDocumentHandler::OpenFileEmbeddedL( |
|
711 const TDesC& aFileName, // Read data from here |
|
712 TDataType& aDataType ) // mime type of the data |
|
713 { |
|
714 #ifdef _DEBUG |
|
715 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenFileEmbeddedL(aFileName, aDataType) Called")); |
|
716 TPtrC mimetype = aDataType.Des(); |
|
717 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- aFileName: %S "), &mimetype, &aFileName); |
|
718 #endif |
|
719 |
|
720 RFile fileHandle; |
|
721 OpenTempFileL(aFileName, fileHandle); |
|
722 TInt error = OpenFileEmbeddedL(fileHandle, aDataType, InParamListL()); |
|
723 fileHandle.Close(); |
|
724 return error; |
|
725 } |
|
726 |
|
727 // --------------------------------------------------------- |
|
728 // CDocumentHandler::OpenFileEmbeddedL |
|
729 // Calls other version of OpenFileEmbeddedL. |
|
730 // |
|
731 // Returns: KErrNone: Everything went ok |
|
732 // KUserCancel: The user cancelled the operation |
|
733 // --------------------------------------------------------- |
|
734 // |
|
735 EXPORT_C TInt CDocumentHandler::OpenFileEmbeddedL( |
|
736 RFile& aSharableFile, |
|
737 TDataType& aDataType) |
|
738 { |
|
739 #ifdef _DEBUG |
|
740 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenFileEmbeddedL(aSharableFile, aDataType) Called")); |
|
741 #endif |
|
742 |
|
743 return OpenFileEmbeddedL(aSharableFile, aDataType, InParamListL()); |
|
744 } |
|
745 |
|
746 // --------------------------------------------------------- |
|
747 // CDocumentHandler::OpenFileEmbeddedL |
|
748 // Open a file with a given data type embedded. First |
|
749 // check that the content is supported and get the handler |
|
750 // application's UID. Based on that UID find the correct |
|
751 // handler for the content. File data is not copied over. |
|
752 // |
|
753 // Returns: KErrNone: Everything went ok |
|
754 // KUserCancel: The user cancelled the operation |
|
755 // --------------------------------------------------------- |
|
756 // |
|
757 EXPORT_C TInt CDocumentHandler::OpenFileEmbeddedL( |
|
758 RFile& aSharableFile, |
|
759 TDataType& aDataType, |
|
760 const CAiwGenericParamList& aParamList) |
|
761 { |
|
762 #ifdef _DEBUG |
|
763 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenFileEmbeddedL(aSharableFile, aDataType, aParamList) Called")); |
|
764 TPtrC mimetype = aDataType.Des(); |
|
765 TFileName filename; |
|
766 aSharableFile.FullName(filename); |
|
767 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- fullname of filehandle: %S "), &mimetype, &filename); |
|
768 #endif |
|
769 |
|
770 TUid uid = { 0 }; |
|
771 TInt error; |
|
772 |
|
773 if (aDataType.Des8().FindF( KDummyMimeType ) != KErrNotFound) |
|
774 { |
|
775 return KErrNone; |
|
776 } |
|
777 |
|
778 iOperation = EDocOpenFileEmb; |
|
779 |
|
780 error = RecognizeAndCheckFileL( aSharableFile, aDataType, uid ); |
|
781 |
|
782 if ( error != KErrNone ) |
|
783 { |
|
784 User::Leave( KErrNotSupported ); |
|
785 } |
|
786 |
|
787 FindHandlerL( aDataType, uid ); |
|
788 |
|
789 if ( !iHandler->CanOpen() ) |
|
790 { |
|
791 User::Leave( KErrNotSupported ); |
|
792 } |
|
793 |
|
794 iHandler->AddToParamListL( aParamList ); |
|
795 |
|
796 |
|
797 // Default to true. |
|
798 TBool supportsEmbeddability = ETrue; |
|
799 |
|
800 // Check from AppArc whether the handler app. supports embeddability. |
|
801 TUid handlerUid; |
|
802 iHandler->HandlerAppUid( handlerUid ); |
|
803 |
|
804 TApaAppCapability caps; |
|
805 TPckg<TApaAppCapability> pack( caps ); |
|
806 TInt err = iApaLs->GetAppCapability( pack, handlerUid ); |
|
807 |
|
808 if ( err == KErrNone && caps.iEmbeddability == TApaAppCapability::ENotEmbeddable ) |
|
809 { |
|
810 supportsEmbeddability = EFalse; |
|
811 } |
|
812 |
|
813 if ( supportsEmbeddability ) |
|
814 { |
|
815 error = iHandler->OpenFileEmbeddedL(aSharableFile); // Open embedded |
|
816 } |
|
817 else |
|
818 { |
|
819 error = iHandler->OpenFileL(aSharableFile); // Open stand-alone |
|
820 } |
|
821 |
|
822 #ifdef _DEBUG |
|
823 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenFileEmbeddedL: finished with error=%d."), error); |
|
824 #endif |
|
825 |
|
826 LEAVEONERROR( error ); |
|
827 |
|
828 return error; |
|
829 } |
|
830 |
|
831 // --------------------------------------------------------- |
|
832 // CDocumentHandler::CanHandleL |
|
833 // Check if there is a handler application for aDataType. |
|
834 // |
|
835 // Returns: ETrue: The system is capable of handling aDataType |
|
836 // EFalse: The system is not capable of handling aDataType |
|
837 // --------------------------------------------------------- |
|
838 // |
|
839 EXPORT_C TBool CDocumentHandler::CanHandleL( const TDataType& aDataType ) |
|
840 { |
|
841 TUid appUid; |
|
842 TInt error; |
|
843 TBool response = EFalse; |
|
844 |
|
845 #ifdef _DEBUG |
|
846 TPtrC mimetype = aDataType.Des(); |
|
847 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CanHandleL called with aDataType: %S "), &mimetype ); |
|
848 #endif |
|
849 |
|
850 error = iApaLs->AppForDataType( aDataType, appUid ); |
|
851 if ( error == KErrNone ) |
|
852 { |
|
853 TRAP( error, FindHandlerL( aDataType, appUid ) ); // allow unsupported. |
|
854 if ( error == KMimeNotSupported ) |
|
855 { |
|
856 iHandler = CDocDefaultHandler::NewL( aDataType, appUid, this, EDocSaveOnly ); |
|
857 error = KErrNone; |
|
858 } |
|
859 else |
|
860 { |
|
861 User::LeaveIfError( error ); |
|
862 } |
|
863 |
|
864 if ( iHandler ) |
|
865 { |
|
866 response = ( iHandler->CanOpen() || |
|
867 iHandler->CanSave() ); |
|
868 } |
|
869 } |
|
870 return response; |
|
871 } |
|
872 |
|
873 // --------------------------------------------------------- |
|
874 // CDocumentHandler::CanOpenL |
|
875 // Check if there is a handler application for aDataType and |
|
876 // open is possible. |
|
877 // |
|
878 // Returns: ETrue: The system is capable of handling aDataType |
|
879 // EFalse: The system is not capable of handling aDataType |
|
880 // --------------------------------------------------------- |
|
881 // |
|
882 EXPORT_C TBool CDocumentHandler::CanOpenL( const TDataType& aDataType ) |
|
883 { |
|
884 TUid appUid; |
|
885 TInt error; |
|
886 TBool response = EFalse; |
|
887 |
|
888 #ifdef _DEBUG |
|
889 TPtrC mimetype = aDataType.Des(); |
|
890 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CanOpenL called with aDataType: %S "), &mimetype ); |
|
891 #endif |
|
892 |
|
893 error = iApaLs->AppForDataType( aDataType, appUid ); |
|
894 if ( error == KErrNone ) |
|
895 { |
|
896 FindHandlerL( aDataType, appUid ); // do not allow unsupported |
|
897 if ( iHandler ) |
|
898 { |
|
899 response = iHandler->CanOpen(); |
|
900 } |
|
901 } |
|
902 return response; |
|
903 } |
|
904 |
|
905 |
|
906 // --------------------------------------------------------- |
|
907 // CDocumentHandler::CanSaveL |
|
908 // Check if there is a handler application for aDataType and |
|
909 // saving is possible. |
|
910 // |
|
911 // Returns: ETrue: The system is capable of handling aDataType |
|
912 // EFalse: The system is not capable of handling aDataType |
|
913 // --------------------------------------------------------- |
|
914 // |
|
915 EXPORT_C TBool CDocumentHandler::CanSaveL( const TDataType& aDataType ) |
|
916 { |
|
917 TUid appUid; |
|
918 TInt error; |
|
919 TBool response = EFalse; |
|
920 |
|
921 #ifdef _DEBUG |
|
922 TPtrC mimetype = aDataType.Des(); |
|
923 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CanSaveL called with aDataType: %S "), &mimetype ); |
|
924 #endif |
|
925 |
|
926 error = iApaLs->AppForDataType( aDataType, appUid ); |
|
927 if ( error == KErrNone ) |
|
928 { |
|
929 TRAP( error, FindHandlerL( aDataType, appUid ) ); // allow unsupported. |
|
930 if ( error == KMimeNotSupported ) |
|
931 { |
|
932 iHandler = CDocDefaultHandler::NewL( aDataType, appUid, this, EDocSaveOnly ); |
|
933 error = KErrNone; |
|
934 } |
|
935 else |
|
936 { |
|
937 User::LeaveIfError( error ); |
|
938 } |
|
939 |
|
940 if ( iHandler ) |
|
941 { |
|
942 response = iHandler->CanSave(); |
|
943 } |
|
944 } |
|
945 return response; |
|
946 } |
|
947 |
|
948 |
|
949 // --------------------------------------------------------- |
|
950 // CDocumentHandler::CheckFileNameExtension |
|
951 // Add correct file extension to aFileName with aDatatype. |
|
952 // Calls CDocDefaultHandler::CheckFileNameExtensionL() |
|
953 // --------------------------------------------------------- |
|
954 // |
|
955 EXPORT_C void CDocumentHandler::CheckFileNameExtension( TDes& aFileName, const TDataType& aDatatype ) |
|
956 { |
|
957 #ifdef _DEBUG |
|
958 TPtrC mimetype = aDatatype.Des(); |
|
959 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CheckFileNameExtension called with: aFileName: %S -- aDataType: %S "), &aFileName, &mimetype ); |
|
960 #endif |
|
961 |
|
962 TUid appUid; |
|
963 TInt error; |
|
964 |
|
965 // Try to find uid |
|
966 error = iApaLs->AppForDataType( aDatatype, appUid ); |
|
967 if ( error == KErrNone ) |
|
968 { |
|
969 // Try to find handler. |
|
970 TRAPD(err, FindHandlerL(aDatatype, appUid)); |
|
971 |
|
972 if (err == KErrNone && iHandler) |
|
973 { |
|
974 // Check finally extension |
|
975 TRAP_IGNORE( iHandler->CheckFileNameExtensionL( aFileName, aDatatype ) ); |
|
976 } |
|
977 } |
|
978 |
|
979 #ifdef _DEBUG |
|
980 RDebug::Print( _L("DocumentHandler: CDocumentHandler::CheckFileNameExtension finished : aFileName: %S"), &aFileName ); |
|
981 #endif |
|
982 } |
|
983 |
|
984 // --------------------------------------------------------- |
|
985 // CDocumentHandler::SetExitObserver(..) |
|
986 // Delegate exit signals to aObserver too. |
|
987 // --------------------------------------------------------- |
|
988 // |
|
989 EXPORT_C void CDocumentHandler::SetExitObserver( |
|
990 MAknServerAppExitObserver* aObserver ) |
|
991 { |
|
992 #ifdef _DEBUG |
|
993 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SetExitObserver called.") ); |
|
994 #endif |
|
995 |
|
996 __ASSERT_DEBUG ( |
|
997 aObserver, |
|
998 User::Panic ( _L ( "DocumentHandler" ), KErrUnknown ) ); |
|
999 iServerAppExitObserver = aObserver; |
|
1000 } |
|
1001 |
|
1002 // --------------------------------------------------------- |
|
1003 // CDocumentHandler::FindHandlerByUidL(..) |
|
1004 // Try to find a handler for aUid. |
|
1005 // --------------------------------------------------------- |
|
1006 // |
|
1007 void CDocumentHandler::FindHandlerByUidL( const TUid& aUid, const TDataType& aDataType ) |
|
1008 { |
|
1009 switch ( aUid.iUid ) |
|
1010 { |
|
1011 case KTextHandler: // Notepad viewer |
|
1012 iHandler = CDocDefaultHandler::NewL( |
|
1013 aDataType, |
|
1014 aUid, this, EDocOpenAndSave ); |
|
1015 break; |
|
1016 case KCertSaveAppHandler: // Cert save app |
|
1017 iHandler = CDocDefaultHandler::NewL( |
|
1018 aDataType, |
|
1019 aUid, this, EDocOpenOnly ); |
|
1020 break; |
|
1021 case KLandmarkHandler: // Landmark UI app |
|
1022 iHandler = CDocDefaultHandler::NewL( |
|
1023 aDataType, |
|
1024 aUid, this, EDocOpenOnly ); |
|
1025 break; |
|
1026 case KImageViewerHandler: // Image Viewer |
|
1027 iHandler = CDocImageHandler::NewL( |
|
1028 aDataType, aUid, this); |
|
1029 break; |
|
1030 case KAppInstHandler: // Application Installer |
|
1031 iHandler = CDocAppInstHandler::NewL( |
|
1032 aDataType, |
|
1033 aUid, this, EDocOpenAndSave ); |
|
1034 break; |
|
1035 case KWmlcHandler: // Browser |
|
1036 iHandler = CDocDefaultHandler::NewL( |
|
1037 aDataType, |
|
1038 aUid, this, EDocOpenAndSave ); |
|
1039 break; |
|
1040 default: |
|
1041 /* TODO: Do we need midlet handler anymore? |
|
1042 if (FeatureManager::FeatureSupported( KFeatureIdCdmaExtendedAms ) ) |
|
1043 { |
|
1044 // Check if given UID belongs to a Java Midlet |
|
1045 if ( CDocMidletHandler::IsMidlet( aUid ) ) |
|
1046 { |
|
1047 iHandler = CDocMidletHandler::NewL( |
|
1048 aDataType, |
|
1049 aUid, this); |
|
1050 } |
|
1051 } |
|
1052 */ |
|
1053 break; // We will use default handler |
|
1054 } |
|
1055 } |
|
1056 |
|
1057 // --------------------------------------------------------- |
|
1058 // void CDocumentHandler::FindHandlerByMimeTypeL(..) |
|
1059 // Try to find a handler for aDataType |
|
1060 // --------------------------------------------------------- |
|
1061 // |
|
1062 void CDocumentHandler::FindHandlerByMimeTypeL( const TUid& aUid, const TDataType& aDataType ) |
|
1063 { |
|
1064 // All games are handler by the game handler |
|
1065 if ( aDataType.Des8().FindF( KGameMimeType ) != KErrNotFound ) |
|
1066 { |
|
1067 iHandler = CDocGameHandler::NewL( |
|
1068 aDataType, aUid, this, EDocSaveOnly ); |
|
1069 return; |
|
1070 } |
|
1071 |
|
1072 if (( aDataType.Des8().FindF( KDocMimeCard ) != KErrNotFound) || |
|
1073 ( aDataType.Des8().FindF( KDocMimeCalendar) != KErrNotFound) || |
|
1074 ( aDataType.Des8().FindF( KDocMimeCalendar2) != KErrNotFound)) |
|
1075 { |
|
1076 // |
|
1077 // vCal and vCard types are handled as 'read only' types |
|
1078 // (must be saved from application, not through doc handler). |
|
1079 // |
|
1080 iHandler = CDocDefaultHandler::NewL( |
|
1081 aDataType, |
|
1082 aUid, this, EDocOpenOnly ); |
|
1083 return; |
|
1084 } |
|
1085 #ifdef ENABLE_DRM |
|
1086 #ifdef __DRM_OMA2 |
|
1087 if ( aDataType.Des8().FindF( KOma1DcfContentType ) != KErrNotFound || |
|
1088 aDataType.Des8().FindF( KOma2DcfContentType ) != KErrNotFound ) |
|
1089 #else // __DRM_OMA2 |
|
1090 if ( aDataType.Des8().FindF( KOma1DcfContentType ) != KErrNotFound ) |
|
1091 #endif // __DRM_OMA2 |
|
1092 { |
|
1093 iHandler = CDocDCFHandler::NewL( aDataType, iOperation, aUid, this ); |
|
1094 return; |
|
1095 } |
|
1096 #endif // ENABLE_DRM |
|
1097 |
|
1098 } |
|
1099 |
|
1100 // --------------------------------------------------------- |
|
1101 // CDocumentHandler::FindHandlerL |
|
1102 // Based on app uid and mime type decide which handler |
|
1103 // implementation to use. |
|
1104 // |
|
1105 // |
|
1106 // Returns: KErrNone: The handler was constructed ok |
|
1107 // --------------------------------------------------------- |
|
1108 // |
|
1109 TInt CDocumentHandler::FindHandlerL( |
|
1110 const TDataType& aDataType, |
|
1111 const TUid& aUid) |
|
1112 { |
|
1113 delete iHandler; // delete the old handler |
|
1114 iHandler = NULL; |
|
1115 |
|
1116 // First check by the application uid |
|
1117 FindHandlerByUidL( aUid, aDataType ); |
|
1118 |
|
1119 // Then check by the mime type |
|
1120 if ( !iHandler ) |
|
1121 { |
|
1122 FindHandlerByMimeTypeL( aUid, aDataType ); |
|
1123 } |
|
1124 |
|
1125 // Default handler if everything else has failed |
|
1126 if ( !iHandler ) |
|
1127 { |
|
1128 TApaAppInfo info; |
|
1129 if ( iApaLs->GetAppInfo( info, aUid ) == KErrNone ) // Check the uid is real. |
|
1130 { |
|
1131 iHandler = CDocDefaultHandler::NewL( aDataType, |
|
1132 aUid, this, EDocOpenAndSave ); |
|
1133 } |
|
1134 else |
|
1135 { |
|
1136 User::Leave( KMimeNotSupported ); |
|
1137 } |
|
1138 } |
|
1139 |
|
1140 return KErrNone; |
|
1141 } |
|
1142 |
|
1143 |
|
1144 // --------------------------------------------------------- |
|
1145 // Get the whole path including filename where the content was saved. |
|
1146 // If the content was not saved in a file, return the id |
|
1147 // representing the object. |
|
1148 // returns: KErrNone: Ok |
|
1149 // KNotInitialized Handler is no initialized |
|
1150 // --------------------------------------------------------- |
|
1151 // |
|
1152 EXPORT_C TInt CDocumentHandler::GetPath( TDes& aPath ) |
|
1153 { |
|
1154 #ifdef _DEBUG |
|
1155 RDebug::Print( _L("DocumentHandler: CDocumentHandler::GetPath called.") ); |
|
1156 #endif |
|
1157 |
|
1158 __ASSERT_DEBUG ( |
|
1159 iHandler, |
|
1160 User::Panic ( _L( "DocumentHandler" ), KNotInitialized ) ); |
|
1161 |
|
1162 if ( !iHandler ) |
|
1163 { |
|
1164 aPath.Zero(); |
|
1165 return KNotInitialized; |
|
1166 } |
|
1167 iHandler->GetPath( aPath ); |
|
1168 |
|
1169 #ifdef _DEBUG |
|
1170 RDebug::Print( _L("DocumentHandler: CDocumentHandler::GetPath returns aPath: %S "), &aPath); |
|
1171 #endif |
|
1172 |
|
1173 return iHandler->Status(); |
|
1174 } |
|
1175 |
|
1176 // --------------------------------------------------------- |
|
1177 // Get the Uid of handler application. |
|
1178 // returns: KErrNone: Ok |
|
1179 // KNotInitialized Handler is no initialized |
|
1180 // --------------------------------------------------------- |
|
1181 // |
|
1182 EXPORT_C TInt CDocumentHandler::HandlerAppUid( TUid& aUid ) |
|
1183 { |
|
1184 #ifdef _DEBUG |
|
1185 RDebug::Print( _L("DocumentHandler: CDocumentHandler::HandlerAppUid called.") ); |
|
1186 #endif |
|
1187 |
|
1188 __ASSERT_DEBUG ( |
|
1189 iHandler, |
|
1190 User::Panic ( _L( "DocumentHandler" ), KNotInitialized ) ); |
|
1191 |
|
1192 if ( !iHandler ) |
|
1193 { |
|
1194 return KNotInitialized; |
|
1195 } |
|
1196 iHandler->HandlerAppUid( aUid ); |
|
1197 |
|
1198 #ifdef _DEBUG |
|
1199 RDebug::Print( _L("DocumentHandler: CDocumentHandler::HandlerAppUid returns uid: %x "), aUid.iUid); |
|
1200 #endif |
|
1201 |
|
1202 return iHandler->Status(); |
|
1203 } |
|
1204 |
|
1205 // --------------------------------------------------------- |
|
1206 // CDocumentHandler::ListSupportedMimeTypesL |
|
1207 // Lists all supported MIME-types using RDebug::Print |
|
1208 // --------------------------------------------------------- |
|
1209 // |
|
1210 void CDocumentHandler::ListSupportedMimeTypesL() |
|
1211 { |
|
1212 #ifdef _DEBUG |
|
1213 RDebug::Print( _L( "DocumentHandler: All supported mime types:" ) ); |
|
1214 RDebug::Print( _L( "**********************" ) ); |
|
1215 CDataTypeArray *dataTypes = new( ELeave ) CDataTypeArray( 20 ); |
|
1216 CleanupStack::PushL( dataTypes ); |
|
1217 iApaLs->GetSupportedDataTypesL( *dataTypes ); |
|
1218 for ( TInt i = dataTypes->Count() - 1; i; i-- ) |
|
1219 { |
|
1220 TBuf < KMaxDataTypeLength > buf; |
|
1221 buf.Copy( dataTypes->At( i ).Des8() ); |
|
1222 RDebug::Print( buf ); |
|
1223 TUid uid; |
|
1224 iApaLs->AppForDataType( dataTypes->At( i ), uid ); |
|
1225 TApaAppInfo appInfo; |
|
1226 iApaLs->GetAppInfo( appInfo, uid ); |
|
1227 RDebug::Print( _L(" -handler app uid - %x, caption - %S"), uid.iUid, &appInfo.iCaption); |
|
1228 |
|
1229 } |
|
1230 RDebug::Print( _L( "**********************" ) ); |
|
1231 CleanupStack::PopAndDestroy(); |
|
1232 #endif |
|
1233 } |
|
1234 |
|
1235 // --------------------------------------------------------- |
|
1236 // CDocumentHandler::RecognizeAndCheckFile |
|
1237 // Recognizes the file and makes other checks. |
|
1238 // This filehandle version is called from OpenFile*L methods |
|
1239 // --------------------------------------------------------- |
|
1240 // |
|
1241 TInt CDocumentHandler::RecognizeAndCheckFileL( |
|
1242 RFile& aFileHandle, |
|
1243 TDataType& aDataType, |
|
1244 TUid& aUid ) |
|
1245 { |
|
1246 #ifdef ENABLE_DRM |
|
1247 if ( aDataType.Des8().FindF( KOma1DcfContentType ) != KErrNotFound || |
|
1248 aDataType.Des8().FindF( KOma2DcfContentType ) != KErrNotFound ) |
|
1249 { |
|
1250 return KErrNone; |
|
1251 } |
|
1252 #endif |
|
1253 |
|
1254 #ifdef _DEBUG |
|
1255 ListSupportedMimeTypesL(); // Let's list all supported mime-types |
|
1256 #endif |
|
1257 |
|
1258 TDataType recognizedData; |
|
1259 TDataType emptyType; |
|
1260 |
|
1261 // TODO: Do we need some security checks for file? |
|
1262 TInt error = KErrNone; |
|
1263 |
|
1264 // Caller gave data type, try it first. |
|
1265 if ( aDataType != emptyType ) |
|
1266 { |
|
1267 error = iApaLs->AppForDataType( aDataType, aUid ); |
|
1268 if ( error == KErrNone ) |
|
1269 { |
|
1270 #ifdef _DEBUG |
|
1271 RDebug::Print( _L("DocumentHandler: CDocumentHandler::RecognizeAndCheckFileL: Use data type from caller:") ); |
|
1272 RDebug::Print( aDataType.Des() ); |
|
1273 #endif |
|
1274 return KErrNone; |
|
1275 } |
|
1276 } |
|
1277 |
|
1278 // Let's ask from RApaLsSession what datatype file is |
|
1279 // This will give us both uid of an application and the data type. |
|
1280 error = iApaLs->AppForDocument( aFileHandle, aUid, recognizedData ); |
|
1281 if ( error == KErrNone ) |
|
1282 { |
|
1283 #ifdef _DEBUG |
|
1284 RDebug::Print( _L( "DocumentHandler: CDocumentHandler::RecognizeAndCheckFileL: Recognized mime type:" ) ); |
|
1285 RDebug::Print( recognizedData.Des() ); |
|
1286 #endif |
|
1287 if ( recognizedData != emptyType ) |
|
1288 { |
|
1289 aDataType = recognizedData; |
|
1290 return KErrNone; |
|
1291 } |
|
1292 } |
|
1293 |
|
1294 return KErrNotFound; |
|
1295 } |
|
1296 |
|
1297 // --------------------------------------------------------- |
|
1298 // CDocumentHandler::RecognizeAndCheckFile |
|
1299 // Recognizes the file and makes other checks. |
|
1300 // This filename version is called from Copy/Move methods |
|
1301 // --------------------------------------------------------- |
|
1302 // |
|
1303 TInt CDocumentHandler::RecognizeAndCheckFileL( |
|
1304 const TDesC& aFileName, |
|
1305 TDataType& aDataType, |
|
1306 TUid& aUid ) |
|
1307 { |
|
1308 #ifdef ENABLE_DRM |
|
1309 if ( aDataType.Des8().FindF( KOma1DcfContentType ) != KErrNotFound || |
|
1310 aDataType.Des8().FindF( KOma2DcfContentType ) != KErrNotFound ) |
|
1311 { |
|
1312 return KErrNone; |
|
1313 } |
|
1314 #endif |
|
1315 |
|
1316 TDataType recognizedData; |
|
1317 TDataType emptyType; |
|
1318 |
|
1319 #ifdef _DEBUG |
|
1320 ListSupportedMimeTypesL(); // Let's list all supported mime-types |
|
1321 #endif |
|
1322 |
|
1323 // If the file is an executable, we are not allowed to continue |
|
1324 // for security reasons. |
|
1325 TBool executable; |
|
1326 User::LeaveIfError( iApaLs->IsProgram( aFileName, executable ) ); |
|
1327 if ( executable ) // Warn the caller about the content. |
|
1328 { |
|
1329 User::Leave( KExecNotAllowed ); |
|
1330 } |
|
1331 |
|
1332 TInt error = KErrNone; |
|
1333 |
|
1334 // Caller gave data type, try it first. |
|
1335 if ( aDataType != emptyType ) |
|
1336 { |
|
1337 error = iApaLs->AppForDataType( aDataType, aUid ); |
|
1338 if ( error == KErrNone ) |
|
1339 { |
|
1340 #ifdef _DEBUG |
|
1341 RDebug::Print( _L("DocumentHandler: CDocumentHandler::RecognizeAndCheckFileL: Use data type from caller:") ); |
|
1342 RDebug::Print( aDataType.Des() ); |
|
1343 #endif |
|
1344 // Success, we're done. |
|
1345 return KErrNone; |
|
1346 } |
|
1347 } |
|
1348 |
|
1349 // Let's ask from RApaLsSession what datatype file is |
|
1350 // This will give us both uid of an application and the data type. |
|
1351 error = iApaLs->AppForDocument( aFileName, aUid, recognizedData ); |
|
1352 if ( error == KErrNone ) |
|
1353 { |
|
1354 #ifdef _DEBUG |
|
1355 RDebug::Print( _L( "DocumentHandler: CDocumentHandler::RecognizeAndCheckFileL: Recognized mime type:" ) ); |
|
1356 RDebug::Print( recognizedData.Des() ); |
|
1357 #endif |
|
1358 if ( recognizedData != emptyType ) |
|
1359 { |
|
1360 aDataType = recognizedData; |
|
1361 return KErrNone; |
|
1362 } |
|
1363 } |
|
1364 |
|
1365 return KErrNotFound; |
|
1366 } |
|
1367 |
|
1368 // --------------------------------------------------------- |
|
1369 // CDocumentHandler::OpenTempFileL() |
|
1370 // Opens a new sharable filehandle from existing file. |
|
1371 // --------------------------------------------------------- |
|
1372 // |
|
1373 EXPORT_C void CDocumentHandler::OpenTempFileL( |
|
1374 const TDesC& aFileName, |
|
1375 RFile &aSharableFile) |
|
1376 { |
|
1377 #ifdef _DEBUG |
|
1378 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenTempFileL() Called")); |
|
1379 RDebug::Print( _L("DocumentHandler: Parameters are: aFileName: %S "), &aFileName); |
|
1380 #endif |
|
1381 |
|
1382 TInt error = KErrNone; |
|
1383 |
|
1384 // Cannot do anything if filename is not valid. |
|
1385 if (aFileName.Length() == 0) |
|
1386 { |
|
1387 error=KNotInitialized; |
|
1388 } |
|
1389 |
|
1390 // Close if existing sharable RFs and create new for sharing purposes. |
|
1391 if ( error == KErrNone ) |
|
1392 { |
|
1393 CloseSharableFS(); |
|
1394 User::LeaveIfError(iSharableFS.Connect()); |
|
1395 User::LeaveIfError(iSharableFS.ShareProtected()); |
|
1396 TInt err = aSharableFile.Open(iSharableFS,aFileName,EFileShareReadersOnly); |
|
1397 if (err == KErrInUse) |
|
1398 { |
|
1399 User::LeaveIfError(aSharableFile.Open(iSharableFS,aFileName,EFileShareReadersOrWriters)); |
|
1400 } |
|
1401 else if ( err != KErrNone ) |
|
1402 { |
|
1403 error = err; // Otherwise possible KErrNotReady caused by hotswap leads to crash later |
|
1404 } |
|
1405 } |
|
1406 #ifdef _DEBUG |
|
1407 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OpenTempFileL: finished with error=%d."), error); |
|
1408 #endif |
|
1409 |
|
1410 LEAVEONERROR( error ); |
|
1411 } |
|
1412 |
|
1413 // --------------------------------------------------------- |
|
1414 // CDocumentHandler::SaveTempFileL() |
|
1415 // Saves content (aContent) to file and opens that sharable file |
|
1416 // --------------------------------------------------------- |
|
1417 // |
|
1418 EXPORT_C void CDocumentHandler::SaveTempFileL( |
|
1419 const TDesC8& aContent, |
|
1420 TDataType& aDataType, |
|
1421 const TDesC& aFileName, |
|
1422 RFile &aSharableFile) |
|
1423 { |
|
1424 #ifdef _DEBUG |
|
1425 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SaveTempFileL() Called")); |
|
1426 TPtrC mimetype = aDataType.Des(); |
|
1427 RDebug::Print( _L("DocumentHandler: Parameters are: aDataType: %S -- aFileName: %S "), &mimetype, &aFileName); |
|
1428 #endif |
|
1429 |
|
1430 TUid uid = { 0 }; |
|
1431 TInt error; |
|
1432 TFileName createdFileName; |
|
1433 |
|
1434 iOperation = EDocSaveTemp; |
|
1435 |
|
1436 // Use Default Handler for saving whatever mimetype actually is |
|
1437 delete iHandler; // delete the old handler |
|
1438 iHandler = NULL; |
|
1439 iHandler = CDocDefaultHandler::NewL( aDataType, |
|
1440 uid, this, EDocSaveOnly ); |
|
1441 |
|
1442 error = iHandler->SetDestName( aFileName ); // Save with this file name |
|
1443 |
|
1444 // Close if existing sharable RFs and create new for sharing purposes. |
|
1445 if ( error == KErrNone ) |
|
1446 { |
|
1447 CloseSharableFS(); |
|
1448 User::LeaveIfError(iSharableFS.Connect()); |
|
1449 iSharableFS.ShareProtected(); |
|
1450 } |
|
1451 |
|
1452 if ( error == KErrNone ) |
|
1453 { |
|
1454 error = iHandler->SaveTempFileL( aContent, KEntryAttNormal, createdFileName ); // Do save the content |
|
1455 } |
|
1456 |
|
1457 if ( error == KErrNone ) |
|
1458 { |
|
1459 OpenTempFileL(createdFileName, aSharableFile); |
|
1460 } |
|
1461 |
|
1462 #ifdef _DEBUG |
|
1463 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SaveTempFileL: finished with error=%d."), error); |
|
1464 #endif |
|
1465 |
|
1466 LEAVEONERROR( error ); |
|
1467 } |
|
1468 |
|
1469 // --------------------------------------------------------- |
|
1470 // CDocumentHandler::InParamListL() |
|
1471 // Returns empty instance of CAiwGenericParamList |
|
1472 // --------------------------------------------------------- |
|
1473 // |
|
1474 EXPORT_C CAiwGenericParamList& CDocumentHandler::InParamListL() |
|
1475 { |
|
1476 #ifdef _DEBUG |
|
1477 RDebug::Print( _L("DocumentHandler: CDocumentHandler::InParamListL() Called")); |
|
1478 #endif |
|
1479 |
|
1480 if (!iInParams) |
|
1481 { |
|
1482 iInParams = CAiwGenericParamList::NewL(); |
|
1483 } |
|
1484 iInParams->Reset(); |
|
1485 return *iInParams; |
|
1486 } |
|
1487 |
|
1488 // --------------------------------------------------------- |
|
1489 // CDocumentHandler::OutParamList() |
|
1490 // Returns list of possible output parameters |
|
1491 // --------------------------------------------------------- |
|
1492 // |
|
1493 EXPORT_C const CAiwGenericParamList* CDocumentHandler::OutParamList() |
|
1494 { |
|
1495 #ifdef _DEBUG |
|
1496 RDebug::Print( _L("DocumentHandler: CDocumentHandler::OutParamListL() Called")); |
|
1497 #endif |
|
1498 |
|
1499 const CAiwGenericParamList* result = NULL; |
|
1500 |
|
1501 if (!iHandler) |
|
1502 { |
|
1503 return NULL; |
|
1504 } |
|
1505 |
|
1506 TRAPD(err, result = iHandler->OutputParamsL()); |
|
1507 if (err != KErrNone) |
|
1508 { |
|
1509 return NULL; |
|
1510 } |
|
1511 |
|
1512 return result; |
|
1513 } |
|
1514 |
|
1515 // --------------------------------------------------------- |
|
1516 // CDocumentHandler::CloseSharableFS |
|
1517 // Close iSharableFs |
|
1518 // --------------------------------------------------------- |
|
1519 // |
|
1520 void CDocumentHandler::CloseSharableFS() |
|
1521 { |
|
1522 if (iSharableFS.Handle() != NULL) |
|
1523 { |
|
1524 iSharableFS.Close(); |
|
1525 } |
|
1526 } |
|
1527 |
|
1528 // --------------------------------------------------------- |
|
1529 // CDocumentHandler::SetTempFile |
|
1530 // Set temp file, which will be deleted in destructor. |
|
1531 // --------------------------------------------------------- |
|
1532 // |
|
1533 void CDocumentHandler::SetTempFile(const TDesC& aTempFile) |
|
1534 { |
|
1535 #ifdef _DEBUG |
|
1536 RDebug::Print( _L("DocumentHandler: CDocumentHandler::SetTempFile called with %S "), &aTempFile); |
|
1537 #endif |
|
1538 |
|
1539 // If there allready is stored tempfile, delete it first |
|
1540 if ( iTempFileName.Length() > 0 && iHandler ) |
|
1541 { |
|
1542 iHandler->DeleteFile(iTempFileName); |
|
1543 } |
|
1544 |
|
1545 // Set new tempfile to member variable |
|
1546 if ( aTempFile.Length() > 0 ) |
|
1547 { |
|
1548 iTempFileName = aTempFile; |
|
1549 } |
|
1550 } |
|
1551 |
|
1552 // --------------------------------------------------------- |
|
1553 // CDocumentHandler::CanHandleProgressivelyL() |
|
1554 // Returns ETrue if progressive downloading is supported by |
|
1555 // some application for the requested data type. The Uid of |
|
1556 // the application for the given data type is also returned. |
|
1557 // |
|
1558 // --------------------------------------------------------- |
|
1559 // |
|
1560 EXPORT_C TBool CDocumentHandler::CanHandleProgressivelyL( |
|
1561 const TDataType& aDataType, |
|
1562 TUid& aUid ) |
|
1563 { |
|
1564 aUid.iUid = 0; // By default |
|
1565 |
|
1566 HBufC* buffer16 = HBufC::NewLC( KDocMaxCenRepBufLen ); |
|
1567 |
|
1568 // Get Uid list. |
|
1569 // |
|
1570 TInt err = KErrNone; |
|
1571 RArray<TInt32> uidList; |
|
1572 TRAP( err, GetProgressiveDownloadAppUidsL( uidList ) ) |
|
1573 CleanupClosePushL( uidList ); |
|
1574 User::LeaveIfError( err ); // KErrNotFound. |
|
1575 |
|
1576 // Check mimetypes. |
|
1577 // |
|
1578 CRepository* variation = CRepository::NewL( KCRUidCommonUi ); |
|
1579 CleanupStack::PushL( variation ); |
|
1580 |
|
1581 TPtr allMimePtr( buffer16->Des() ); |
|
1582 allMimePtr.Zero(); |
|
1583 |
|
1584 HBufC8* oneMime = HBufC8::NewLC( KDocPDMaxMimeLen ); |
|
1585 TPtr8 oneMimePtr( oneMime->Des() ); |
|
1586 TUint uidCount = uidList.Count(); |
|
1587 |
|
1588 for ( TInt i = 0; i < Min( uidCount, KDocPDMaxUids ); i++ ) |
|
1589 { |
|
1590 err = variation->Get( KCuiMimeTypeSet1 + i, allMimePtr ); |
|
1591 TInt start = 0; // leftmost pos. |
|
1592 TInt len = 0; |
|
1593 do |
|
1594 { |
|
1595 len = allMimePtr.Mid( start ).Locate( ';' ); |
|
1596 if ( len == KErrNotFound ) |
|
1597 { |
|
1598 len = allMimePtr.Mid( start ).Length(); |
|
1599 } |
|
1600 if ( len > KDocPDMaxMimeLen ) // resize buffer length |
|
1601 { |
|
1602 CleanupStack::PopAndDestroy( oneMime ); |
|
1603 oneMime = HBufC8::NewLC( len ); |
|
1604 oneMimePtr.Set( oneMime->Des() ); |
|
1605 } |
|
1606 oneMimePtr.Copy( allMimePtr.Mid( start, len ) ); |
|
1607 oneMimePtr.Trim(); |
|
1608 |
|
1609 if ( !aDataType.Des8().CompareF( oneMimePtr ) || |
|
1610 aDataType.Des8().MatchF( oneMimePtr ) != KErrNotFound ) |
|
1611 { |
|
1612 aUid.iUid = uidList[ i ]; |
|
1613 CleanupStack::PopAndDestroy( 4 ); // buffer16, uidList, variation |
|
1614 // oneMime |
|
1615 return ETrue; |
|
1616 } |
|
1617 |
|
1618 oneMimePtr.Zero(); |
|
1619 if ( len > KDocPDMaxMimeLen ) // return normal length |
|
1620 { |
|
1621 CleanupStack::PopAndDestroy( oneMime ); |
|
1622 oneMime = HBufC8::NewLC( KDocPDMaxMimeLen ); |
|
1623 oneMimePtr = oneMime->Des(); |
|
1624 } |
|
1625 start += len + 1; |
|
1626 } |
|
1627 while ( start < allMimePtr.Length() ); |
|
1628 } |
|
1629 |
|
1630 CleanupStack::PopAndDestroy( 4 ); // buffer16, uidList, variation, oneMime |
|
1631 |
|
1632 return EFalse; // not found. |
|
1633 } |
|
1634 |
|
1635 // --------------------------------------------------------- |
|
1636 // CDocumentHandler::GetProgressiveDownloadAppUidsL |
|
1637 // Returns |
|
1638 // |
|
1639 // --------------------------------------------------------- |
|
1640 // |
|
1641 EXPORT_C void CDocumentHandler::GetProgressiveDownloadAppUidsL( |
|
1642 RArray<TInt32>& aUidList ) |
|
1643 { |
|
1644 // 16-bit buffer for CenRep. |
|
1645 HBufC* buffer16 = HBufC::NewLC( KDocMaxCenRepBufLen ); |
|
1646 |
|
1647 // Read data to the buffer. |
|
1648 TInt err = KErrNone; |
|
1649 CRepository* variation = CRepository::NewL( KCRUidCommonUi ); |
|
1650 CleanupStack::PushL( variation ); |
|
1651 TPtr allUidPtr( buffer16->Des() ); |
|
1652 |
|
1653 err = variation->Get( KCuiProgDownloadUids, allUidPtr ); |
|
1654 if( err != KErrNone ) |
|
1655 { |
|
1656 User::LeaveIfError( KErrNotFound ); // Error: CenRep access failed. |
|
1657 } |
|
1658 CleanupStack::PopAndDestroy( 1 ); // variation |
|
1659 |
|
1660 HBufC* oneUid = HBufC::NewLC( KDocPDMaxUidLen ); |
|
1661 TPtr oneUidPtr( oneUid->Des() ); |
|
1662 |
|
1663 TInt start = 0; |
|
1664 TInt len = 0; |
|
1665 do |
|
1666 { |
|
1667 len = allUidPtr.Mid( start ).Locate( ';' ); |
|
1668 if ( len == KErrNotFound ) |
|
1669 { |
|
1670 len = allUidPtr.Mid( start ).Length(); |
|
1671 } |
|
1672 if ( len > KDocPDMaxUidLen ) // resize buffer length |
|
1673 { |
|
1674 CleanupStack::PopAndDestroy( oneUid ); |
|
1675 oneUid = HBufC::NewLC( len ); |
|
1676 oneUidPtr.Set( oneUid->Des() ); |
|
1677 } |
|
1678 oneUidPtr.Copy( allUidPtr.Mid( start, len ) ); |
|
1679 oneUidPtr.Trim(); |
|
1680 |
|
1681 TInt32 uid = 0; |
|
1682 if ( ConvertHexStringToInt32( oneUidPtr, uid ) != KErrNone ) |
|
1683 { |
|
1684 User::LeaveIfError( KErrNotFound ); // Error: conversion failed. |
|
1685 } |
|
1686 aUidList.AppendL( uid ); |
|
1687 |
|
1688 oneUidPtr.Zero(); |
|
1689 if ( len > KDocPDMaxUidLen ) // return normal length |
|
1690 { |
|
1691 CleanupStack::PopAndDestroy( oneUid ); |
|
1692 oneUid = HBufC::NewLC( KDocPDMaxUidLen ); |
|
1693 oneUidPtr = oneUid->Des(); |
|
1694 } |
|
1695 start += len + 1; |
|
1696 } |
|
1697 while ( start < allUidPtr.Length() ); |
|
1698 |
|
1699 CleanupStack::PopAndDestroy( 2 ); // buffer16, oneUid |
|
1700 } |
|
1701 |
|
1702 // --------------------------------------------------------- |
|
1703 // CDocumentHandler::ConvertHexStringToInt32 |
|
1704 // Returns TInt32 for a valid hex string, otherwise KErrArgument. |
|
1705 // |
|
1706 // --------------------------------------------------------- |
|
1707 // |
|
1708 TInt CDocumentHandler::ConvertHexStringToInt32( |
|
1709 const TDesC& aHexString, |
|
1710 TInt32& aInt32 ) |
|
1711 { |
|
1712 aInt32 = 0; |
|
1713 |
|
1714 TInt pos = aHexString.LocateF( 'x' ); |
|
1715 if ( pos == KErrNotFound ) |
|
1716 { |
|
1717 pos = 0; |
|
1718 } |
|
1719 else |
|
1720 { |
|
1721 pos++; |
|
1722 } |
|
1723 |
|
1724 if( ( aHexString.Length() - pos ) > KDocMaxDigitsInHexString ) |
|
1725 { |
|
1726 return KErrArgument; // Error: value too big. |
|
1727 } |
|
1728 TPtrC aHexStringPtr( aHexString.Mid( pos ) ); |
|
1729 |
|
1730 TInt64 value64; |
|
1731 if ( TLex( aHexStringPtr ).Val( value64, EHex ) != KErrNone ) |
|
1732 { |
|
1733 return KErrArgument; // Error: conversion failed. |
|
1734 } |
|
1735 aInt32 = value64; |
|
1736 |
|
1737 return KErrNone; |
|
1738 } |
|
1739 |
|
1740 // End of File |