29 |
29 |
30 #include "MAknFileSelectionObserver.h" |
30 #include "MAknFileSelectionObserver.h" |
31 #include "MAknFileFilter.h" |
31 #include "MAknFileFilter.h" |
32 #include "AknCFDUtility.h" |
32 #include "AknCFDUtility.h" |
33 #include "CAknDataCagingFilter.h" |
33 #include "CAknDataCagingFilter.h" |
34 |
34 #include "commondialogsdata.hrh" |
35 // CONSTANTS |
35 // CONSTANTS |
|
36 _LIT( KImageHeader, "%d\t" ); |
|
37 const TInt KFileExtNameSize = 10; |
36 const TInt KEntryArrayGranularity( 10 ); |
38 const TInt KEntryArrayGranularity( 10 ); |
37 const TInt KFilterArrayGranularity( 2 ); |
39 const TInt KFilterArrayGranularity( 2 ); |
38 |
40 const TInt KIndexDataLen = 6; |
39 _LIT( KCFDMimeTypeImage, "image/*" ); |
41 |
40 _LIT( KCFDMimeTypeImageGms, "image/x-ota-bitmap" ); |
42 // Store file ext name and right icon index |
41 _LIT( KCFDMimeTypeRam, "audio/x-pn-realaudio-plugin" ); // = link |
43 class TCFDFileTypes |
42 _LIT( KCFDMimeTypeAudioVoiceRec, "audio/amr*" ); |
44 { |
43 _LIT( KCFDMimeTypeAudioVoiceRec2, "application/vnd.nokia.ringing-tone" ); |
45 public: |
44 _LIT( KCFDMimeTypeAudio, "audio/*" ); // = other sound files |
46 TBuf<KFileExtNameSize> iFileType; |
45 _LIT( KCFDMimeTypePlaylist, "audio/*mpegurl*" ); |
47 TInt iIconIndex; |
46 _LIT( KCFDMimeTypeVideo, "video/*" ); |
48 }; |
47 _LIT( KCFDMimeTypeVideoRealMedia, "application/*n-realmedia" ); |
|
48 _LIT( KCFDMimeTypeVideoSdp, "application/sdp" ); |
|
49 _LIT( KCFDMimeTypeGame, "application/*game*" ); |
|
50 _LIT( KCFDMimeTypeNote, "text/*" ); |
|
51 _LIT( KCFDMimeTypeJava, "application/java-archive" ); |
|
52 _LIT( KCFDMimeTypeFlash, "application/x-shockwave-flash" ); |
|
53 |
|
54 _LIT( KCFDFileExtSis, ".sis" ); |
|
55 _LIT( KCFDFileExtSisx, ".sisx"); |
|
56 _LIT( KCFDFileExtMid, ".mid" ); |
|
57 |
49 |
58 // ============================ MEMBER FUNCTIONS =============================== |
50 // ============================ MEMBER FUNCTIONS =============================== |
59 |
51 |
60 // ----------------------------------------------------------------------------- |
52 // ----------------------------------------------------------------------------- |
61 // CAknFileSelectionModel::CAknFileSelectionModel |
53 // CAknFileSelectionModel::CAknFileSelectionModel |
77 // |
68 // |
78 // ----------------------------------------------------------------------------- |
69 // ----------------------------------------------------------------------------- |
79 // |
70 // |
80 void CAknFileSelectionModel::ConstructL() |
71 void CAknFileSelectionModel::ConstructL() |
81 { |
72 { |
82 User::LeaveIfError( iApaSession.Connect() ); |
|
83 iLocalizer = CDirectoryLocalizer::NewL(); |
73 iLocalizer = CDirectoryLocalizer::NewL(); |
84 iEntryArray = new( ELeave ) CArrayPakFlat<TEntry>( KEntryArrayGranularity ); |
74 iEntryArray = new( ELeave ) CArrayPakFlat<TEntry>( KEntryArrayGranularity ); |
85 iFilterArray = new( ELeave ) CArrayPtrSeg<MAknFileFilter>( KFilterArrayGranularity ); |
75 iFilterArray = new( ELeave ) CArrayPtrSeg<MAknFileFilter>( KFilterArrayGranularity ); |
86 iItemWithImageIndex = HBufC::NewL(KMaxPath); |
76 iFileTypeArray = new ( ELeave ) CArrayFixFlat<TCFDFileTypes>( KEntryArrayGranularity ); |
|
77 |
|
78 // Directories should be shown in front of files in list, |
|
79 // create two arrays to save it respectively |
|
80 iLocalFileNameArray = new ( ELeave ) CDesC16ArraySeg( KEntryArrayGranularity ); |
|
81 iLocalDirNameArray = new ( ELeave ) CDesC16ArraySeg( KEntryArrayGranularity ); |
|
82 |
|
83 TResourceReader reader; |
|
84 iCoeEnv.CreateResourceReaderLC( reader, R_CDF_FILE_TYPE_ICON_SET ); |
|
85 ReadFileExtNameAndIconIndexL( reader ); |
|
86 CleanupStack::PopAndDestroy();//reader |
|
87 |
|
88 iStringBuf = HBufC::NewL(KMaxPath); |
|
89 |
87 User::LeaveIfError( iFs.Connect() ); |
90 User::LeaveIfError( iFs.Connect() ); |
88 iRootFolderText = iCoeEnv.AllocReadResourceL( R_CFD_QTN_FLDR_ROOT_LEVEL ); |
91 iRootFolderText = iCoeEnv.AllocReadResourceL( R_CFD_QTN_FLDR_ROOT_LEVEL ); |
89 |
|
90 AddFilterL( CAknDataCagingFilter::NewLC() ); |
92 AddFilterL( CAknDataCagingFilter::NewLC() ); |
91 CleanupStack::Pop(); //caging filter |
93 CleanupStack::Pop(); //caging filter |
92 } |
94 } |
93 |
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CAknFileSelectionModel::ReadFileExtNameAndIconIndexL |
|
98 // |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CAknFileSelectionModel::ReadFileExtNameAndIconIndexL( TResourceReader& aReader ) |
|
102 { |
|
103 // File icon will be selected by file extname. |
|
104 TInt count( aReader.ReadInt16() ); |
|
105 for ( TInt i = 0; i < count; i++ ) |
|
106 { |
|
107 TCFDFileTypes type; |
|
108 type.iFileType.Copy( aReader.ReadTPtrC() ); |
|
109 type.iIconIndex = aReader.ReadInt32(); |
|
110 iFileTypeArray->AppendL( type ); |
|
111 } |
|
112 } |
94 // ----------------------------------------------------------------------------- |
113 // ----------------------------------------------------------------------------- |
95 // CAknFileSelectionModel::NewL |
114 // CAknFileSelectionModel::NewL |
96 // |
115 // |
97 // ----------------------------------------------------------------------------- |
116 // ----------------------------------------------------------------------------- |
98 // |
117 // |
268 // CAknFileSelectionModel::UpdateItemListL |
293 // CAknFileSelectionModel::UpdateItemListL |
269 // ----------------------------------------------------------------------------- |
294 // ----------------------------------------------------------------------------- |
270 // |
295 // |
271 TInt CAknFileSelectionModel::UpdateItemListL() |
296 TInt CAknFileSelectionModel::UpdateItemListL() |
272 { |
297 { |
|
298 // Clear array contents |
273 iEntryArray->Reset(); |
299 iEntryArray->Reset(); |
274 iImageIndexArray.Reset(); |
300 iLocalDirNameArray->Reset(); |
275 |
301 iLocalFileNameArray->Reset(); |
|
302 |
276 CDir* entryArray = ReadDirectory( iCurrentPath.DriveAndPath() ); |
303 CDir* entryArray = ReadDirectory( iCurrentPath.DriveAndPath() ); |
277 if ( !entryArray ) |
304 if ( !entryArray ) |
278 { |
305 { |
279 return KErrNotFound; |
306 return KErrNotFound; |
280 } |
307 } |
281 CleanupStack::PushL( entryArray ); |
308 CleanupStack::PushL( entryArray ); |
282 |
309 |
283 TInt itemCount( entryArray->Count() ); |
310 TInt itemCount( entryArray->Count() ); |
284 if ( itemCount > 0 ) |
311 // entry index in iEntryArray |
285 { |
312 TInt entryIndex = 0; |
286 TInt filterCount( iFilterArray->Count() ); |
313 for ( TInt i( 0 ); i < itemCount; i++ ) // Add entry or not |
287 TInt filterIndex; |
314 { |
288 TBool accepted; |
315 TEntry entry = ( *entryArray )[i]; |
289 CDesC16Array* desC16FoldersArray = new ( ELeave ) |
316 if ( EntryIsAccepted( entry ) ) |
290 CDesC16ArrayFlat( KEntryArrayGranularity ); |
317 { |
291 CleanupStack::PushL( desC16FoldersArray ); |
318 // Add entry |
292 CDesC16Array* desC16FilesArray = new ( ELeave ) |
319 if ( entry.IsDir() ) |
293 CDesC16ArrayFlat( KEntryArrayGranularity ); |
|
294 CleanupStack::PushL( desC16FilesArray ); |
|
295 CArrayPakFlat<TEntry>* tmpFoldersArray = new( ELeave ) |
|
296 CArrayPakFlat<TEntry>( KEntryArrayGranularity ); |
|
297 CleanupStack::PushL( tmpFoldersArray ); |
|
298 CArrayPakFlat<TEntry>* tmpFilesArray = new( ELeave ) |
|
299 CArrayPakFlat<TEntry>( KEntryArrayGranularity ); |
|
300 CleanupStack::PushL( tmpFilesArray ); |
|
301 |
|
302 tmpFoldersArray->Reset(); |
|
303 desC16FoldersArray->Reset(); |
|
304 tmpFilesArray->Reset(); |
|
305 desC16FilesArray->Reset(); |
|
306 |
|
307 for ( TInt i( 0 ); i < itemCount; i++ ) // Generate filtered list |
|
308 { |
|
309 accepted = ETrue; // If there are no filters, accept the entry |
|
310 TEntry entry = ( *entryArray )[i]; |
|
311 filterIndex = 0; |
|
312 // Go thru the filters while the entry is accepted |
|
313 while( ( filterIndex < filterCount ) && ( accepted ) ) |
|
314 { |
320 { |
315 accepted = iFilterArray->At( filterIndex )->Accept( |
321 // Entry is a directory |
316 iCurrentPath.DriveAndPath(), entry ); |
322 TFileTypeIcon folderIcon( EFolderIcon ); |
317 filterIndex++; |
323 |
|
324 if( !AknCFDUtility::IsRemoteDrive( iCurrentPath.Drive() ) ) |
|
325 { |
|
326 if ( ContainsSubfolders( entry.iName ) ) |
|
327 { |
|
328 folderIcon = ESubFolderIcon; |
|
329 } |
|
330 else if ( !ContainsFiles( entry.iName ) ) |
|
331 { |
|
332 folderIcon = EFolderEmptyIcon; |
|
333 } |
|
334 } |
|
335 // List item uses localized name and icon index to show itself, |
|
336 // common dialogs need to give user the entry's iName, list item |
|
337 // need to bind unique entry. For sorting list and binding entry, |
|
338 // save icon index, localized name and right entry index of iEntryArray |
|
339 // in the element of iLocalDirNameArray and iLocalFileNameArray |
|
340 TFileName name( GetLocalizedName( entry.iName ) ); |
|
341 // Append icon index number at the end of entry's localized name |
|
342 name.AppendNumFixedWidth( folderIcon, EDecimal, KIndexDataLen ); |
|
343 // Append entry index number of iEntryArray in the end |
|
344 name.AppendNumFixedWidth( entryIndex, EDecimal, KIndexDataLen ); |
|
345 iLocalDirNameArray->AppendL( name ); |
318 } |
346 } |
319 if ( accepted ) // Directory entry has passed all filters |
347 else |
320 { |
348 { |
321 // Add filename to filtered list |
349 TInt icon(EUnknowTypeIcon); |
322 if ( entry.IsDir() ) |
350 icon = GetIconForFileL( entry.iName ); |
323 { |
351 TFileName name( GetLocalizedName( entry.iName ) ); |
324 desC16FoldersArray->AppendL( GetLocalizedName( entry.iName ) ); |
352 name.AppendNumFixedWidth( icon, EDecimal, KIndexDataLen ); |
325 tmpFoldersArray->AppendL( entry, sizeof( TEntry ) ); |
353 name.AppendNumFixedWidth( entryIndex, EDecimal, KIndexDataLen ); |
326 } |
354 iLocalFileNameArray->AppendL( name ); |
327 else |
|
328 { |
|
329 desC16FilesArray->AppendL( GetLocalizedName( entry.iName ) ); |
|
330 tmpFilesArray->AppendL( entry, sizeof( TEntry ) ); |
|
331 } |
|
332 } |
355 } |
333 } |
356 entryIndex++; |
334 |
357 iEntryArray->AppendL( entry, sizeof( TEntry ) ); |
335 TInt entryCount = 0; |
358 } |
336 TInt index; |
359 } |
337 TKeyArrayPak key( _FOFF( TEntry, iName ), ECmpCollated ); |
360 |
338 |
361 CleanupStack::PopAndDestroy( entryArray ); |
339 // Add folder entries |
362 // Sort list item to show |
340 desC16FoldersArray->Sort( ECmpCollated ); |
363 iLocalDirNameArray->Sort( ECmpCollated ); |
341 entryCount = desC16FoldersArray->MdcaCount(); |
364 iLocalFileNameArray->Sort( ECmpCollated ); |
342 for( TInt j( 0 ); j < entryCount; j++ ) |
365 if ( AknCFDUtility::DirectoriesOnly( iDialogType ) ) |
343 { |
366 { |
344 for( TInt k( 0 ); k < entryCount; k++ ) |
367 // Set the current folder name as first item. |
|
368 TPtr folder = iStringBuf->Des(); |
|
369 folder = iCurrentPath.DriveAndPath(); |
|
370 AknCFDUtility::RemoveTrailingBackslash( folder ); // ignore error |
|
371 TParsePtr parsedFolder(folder); |
|
372 folder = parsedFolder.NameAndExt(); |
|
373 TFileName name(folder); |
|
374 TEntry folderEntry; |
|
375 folderEntry.iName = name; |
|
376 if ( iDirectoryLevel == 0 ) |
|
377 { |
|
378 name = iRootFolderText->Des(); |
|
379 } |
|
380 else |
|
381 { |
|
382 folder = iCurrentPath.DriveAndPath(); |
|
383 iLocalizer->SetFullPath( folder ); |
|
384 if( iLocalizer->IsLocalized() ) |
345 { |
385 { |
346 if( ( *desC16FoldersArray )[j] == |
386 name = iLocalizer->LocalizedName(); |
347 GetLocalizedName( ( *tmpFoldersArray )[k].iName ) && |
|
348 iEntryArray->Find( ( *tmpFoldersArray )[k], key, index ) != 0 ) |
|
349 { |
|
350 TEntry tmpEntry = ( *tmpFoldersArray )[k]; |
|
351 |
|
352 iEntryArray->AppendL( tmpEntry, sizeof( TEntry ) ); |
|
353 |
|
354 // Entry is a directory |
|
355 TFileTypeIcon folderIcon( EFolderIcon ); |
|
356 |
|
357 if( !AknCFDUtility::IsRemoteDrive( iCurrentPath.Drive() ) ) |
|
358 { |
|
359 if ( ContainsSubfolders( tmpEntry.iName ) ) |
|
360 { |
|
361 folderIcon = ESubFolderIcon; |
|
362 } |
|
363 else if ( !ContainsFiles( tmpEntry.iName ) ) |
|
364 { |
|
365 folderIcon = EFolderEmptyIcon; |
|
366 } |
|
367 } |
|
368 iImageIndexArray.Append( folderIcon ); |
|
369 |
|
370 break; |
|
371 } |
|
372 } |
387 } |
373 } |
388 } |
374 |
389 name.AppendNumFixedWidth( EThisFolderIcon, EDecimal, KIndexDataLen ); |
375 // Add file entries |
390 name.AppendNumFixedWidth( entryIndex, EDecimal, KIndexDataLen ); |
376 desC16FilesArray->Sort( ECmpCollated ); |
391 iLocalDirNameArray->InsertL( 0, name ); |
377 entryCount = desC16FilesArray->MdcaCount(); |
392 iEntryArray->AppendL( folderEntry, sizeof(TEntry) ); |
378 for( TInt j( 0 ); j < entryCount; j++ ) |
393 } |
379 { |
|
380 for( TInt k( 0 ); k < entryCount; k++ ) |
|
381 { |
|
382 if( ( *desC16FilesArray )[j] == |
|
383 GetLocalizedName( ( *tmpFilesArray )[k].iName ) && |
|
384 iEntryArray->Find( ( *tmpFilesArray )[k], key, index ) != 0 ) |
|
385 { |
|
386 TEntry tmpFile = ( *tmpFilesArray )[k]; |
|
387 |
|
388 iEntryArray->AppendL( tmpFile, sizeof( TEntry ) ); |
|
389 |
|
390 // Entry is a file |
|
391 AppendIconForFileL( tmpFile.iName ); |
|
392 |
|
393 break; |
|
394 } |
|
395 } |
|
396 } |
|
397 |
|
398 CleanupStack::PopAndDestroy( tmpFilesArray ); |
|
399 CleanupStack::PopAndDestroy( tmpFoldersArray ); |
|
400 CleanupStack::Pop( desC16FilesArray ); |
|
401 desC16FilesArray->Reset(); |
|
402 delete desC16FilesArray; |
|
403 CleanupStack::Pop( desC16FoldersArray ); |
|
404 desC16FoldersArray->Reset(); |
|
405 delete desC16FoldersArray; |
|
406 } |
|
407 |
|
408 CleanupStack::PopAndDestroy( entryArray ); |
|
409 |
|
410 if ( AknCFDUtility::DirectoriesOnly( iDialogType ) ) |
|
411 { |
|
412 // Set the current folder name as first item. |
|
413 // Current folder is for example "E:\Images\Holiday\" |
|
414 // Remove trailing backslash, we get "E:\Images\Holiday" |
|
415 // Parse the path with TParse and ask for NameAndExt(). |
|
416 // TParse interpretes "Holiday" as file name and returns it. |
|
417 |
|
418 HBufC * bufFolder = HBufC::NewLC(KMaxPath); |
|
419 * bufFolder = iCurrentPath.DriveAndPath() ; |
|
420 TPtr folder = bufFolder->Des(); |
|
421 |
|
422 AknCFDUtility::RemoveTrailingBackslash( folder ); // ignore error |
|
423 |
|
424 TParsePtr parsedFolder(folder); |
|
425 |
|
426 folder = parsedFolder.NameAndExt(); |
|
427 iFolderEntry.iName = folder; |
|
428 iEntryArray->InsertL( 0, iFolderEntry, sizeof( TEntry ) ); |
|
429 iImageIndexArray.Insert( EThisFolderIcon, 0 ); |
|
430 |
|
431 CleanupStack::PopAndDestroy(); //bufFolder |
|
432 } |
|
433 |
|
434 return iEntryArray->Count(); |
394 return iEntryArray->Count(); |
435 } |
395 } |
436 |
396 |
437 // ----------------------------------------------------------------------------- |
397 // ----------------------------------------------------------------------------- |
|
398 // CAknFileSelectionModel::EntryIsAccepted |
|
399 // ----------------------------------------------------------------------------- |
|
400 // |
|
401 TBool CAknFileSelectionModel::EntryIsAccepted( const TEntry& aEntry ) const |
|
402 { |
|
403 TInt filterCount( iFilterArray->Count() ); |
|
404 // Go through the filters while the entry is accepted |
|
405 for ( TInt i = 0 ; i < filterCount ; ++i ) |
|
406 { |
|
407 if ( !( iFilterArray->At( i )->Accept( |
|
408 iCurrentPath.DriveAndPath(), aEntry ) ) ) |
|
409 { |
|
410 // Some filter does not accept this entry |
|
411 return EFalse; |
|
412 } |
|
413 } |
|
414 return ETrue; |
|
415 } |
|
416 |
|
417 // ----------------------------------------------------------------------------- |
438 // CAknFileSelectionModel::Entry |
418 // CAknFileSelectionModel::Entry |
439 // |
419 // |
440 // |
420 // |
441 // ----------------------------------------------------------------------------- |
421 // ----------------------------------------------------------------------------- |
442 // |
422 // |
443 const TEntry& CAknFileSelectionModel::Entry( const TInt& aIndex ) const |
423 const TEntry& CAknFileSelectionModel::Entry( const TInt& aIndex ) const |
444 { |
424 { |
445 return iEntryArray->At( aIndex ); |
425 TInt index = aIndex; |
|
426 // List item sequence is arranged in MdcaPoint() |
|
427 if ( aIndex < iLocalDirNameArray->Count() ) |
|
428 { |
|
429 // Get right entry index of iEntryArray |
|
430 TLex lex((*iLocalDirNameArray)[aIndex].Right(KIndexDataLen)); |
|
431 lex.Val( index ); |
|
432 } |
|
433 else |
|
434 { |
|
435 TLex lex((*iLocalFileNameArray)[aIndex - iLocalDirNameArray->Count()].Right(KIndexDataLen)); |
|
436 lex.Val( index ); |
|
437 } |
|
438 return iEntryArray->At( index ); |
446 } |
439 } |
447 |
440 |
448 // ----------------------------------------------------------------------------- |
441 // ----------------------------------------------------------------------------- |
449 // CAknFileSelectionModel::GetCurrentPath |
442 // CAknFileSelectionModel::GetCurrentPath |
450 // |
443 // |
517 // |
510 // |
518 // ----------------------------------------------------------------------------- |
511 // ----------------------------------------------------------------------------- |
519 // |
512 // |
520 TPtrC CAknFileSelectionModel::MdcaPoint( TInt aIndex ) const |
513 TPtrC CAknFileSelectionModel::MdcaPoint( TInt aIndex ) const |
521 { |
514 { |
522 TEntry entry = iEntryArray->At( aIndex ); // reference |
515 // List items sequence follows the sequence of sorted array |
523 TParsePtrC parsedEntry( entry.iName ); |
516 TPtr listItem = iStringBuf->Des(); |
524 TPtrC fileName( parsedEntry.NameAndExt() ); |
517 TInt icon(0); |
525 TInt entryType( iImageIndexArray[ aIndex ] ); |
518 if ( aIndex < iLocalDirNameArray->Count() ) |
526 |
519 { |
527 TPtr itemWithImageIndex = iItemWithImageIndex->Des(); |
520 // Directories need to arrange at ahead of files |
528 |
521 TInt len = (*iLocalDirNameArray)[aIndex].Length(); |
529 switch( entryType ) |
522 TLex lex( (*iLocalDirNameArray)[aIndex].Mid( |
530 { |
523 len - KIndexDataLen - KIndexDataLen, KIndexDataLen) ); |
531 case EThisFolderIcon: |
524 // Get icon index for the item |
532 { |
525 lex.Val( icon ); |
533 if ( iDirectoryLevel == 0 ) |
526 listItem.Format( KImageHeader, icon ); |
534 { |
527 // Append localized name as list item name |
535 // Root folder |
528 listItem.Append((*iLocalDirNameArray)[aIndex].Left( |
536 fileName.Set( iRootFolderText->Des() ); |
529 len - KIndexDataLen - KIndexDataLen ) ); |
537 } |
530 } |
538 else |
531 else |
539 { |
532 { |
540 // Not the root folder |
533 TInt len = (*iLocalFileNameArray)[aIndex - iLocalDirNameArray->Count()].Length(); |
541 iLocalizer->SetFullPath( iCurrentPath.DriveAndPath() ); |
534 TLex lex( (*iLocalFileNameArray)[aIndex - iLocalDirNameArray->Count()].Mid( |
542 if ( iLocalizer->IsLocalized() ) // Localized? |
535 len - KIndexDataLen - KIndexDataLen, KIndexDataLen) ); |
543 { |
536 lex.Val( icon ); |
544 // Folder name is localized |
537 listItem.Format( KImageHeader, icon ); |
545 fileName.Set( iLocalizer->LocalizedName() ); |
538 listItem.Append((*iLocalFileNameArray)[aIndex - iLocalDirNameArray->Count()].Left( |
546 } |
539 len - KIndexDataLen - KIndexDataLen ) ); |
547 } |
540 } |
548 break; |
541 return listItem; |
549 } |
|
550 case EFolderIcon: // fall through |
|
551 case ESubFolderIcon: |
|
552 case EFolderEmptyIcon: |
|
553 { |
|
554 itemWithImageIndex = iCurrentPath.DriveAndPath(); |
|
555 itemWithImageIndex.Append( entry.iName ); |
|
556 // ignore error: |
|
557 AknCFDUtility::AddTrailingBackslash( itemWithImageIndex ); |
|
558 iLocalizer->SetFullPath( itemWithImageIndex ); |
|
559 if( iLocalizer->IsLocalized() ) |
|
560 { |
|
561 fileName.Set( iLocalizer->LocalizedName() ); |
|
562 } |
|
563 break; |
|
564 } |
|
565 default: // EFileIcon |
|
566 { |
|
567 break; |
|
568 } |
|
569 } |
|
570 |
|
571 _LIT( KImageHeader, "%d\t" ); |
|
572 itemWithImageIndex.Format( KImageHeader, entryType ); |
|
573 itemWithImageIndex.Append( fileName ); |
|
574 |
|
575 return itemWithImageIndex; |
|
576 } |
542 } |
577 |
543 |
578 // ----------------------------------------------------------------------------- |
544 // ----------------------------------------------------------------------------- |
579 // CAknFileSelectionModel::ReadDirectory |
545 // CAknFileSelectionModel::ReadDirectory |
580 // |
546 // |
651 ret = ETrue; |
625 ret = ETrue; |
652 } |
626 } |
653 dir.Close(); |
627 dir.Close(); |
654 return ret; |
628 return ret; |
655 } |
629 } |
656 |
630 // ----------------------------------------------------------------------------- |
657 void CAknFileSelectionModel::AppendIconForFileL(const TDesC& aFileName) |
631 // CAknFileSelectionModel::AppendIconForFileL |
658 { |
632 // |
659 //TFileName absFileName( iCurrentPath.DriveAndPath() ); |
633 // ----------------------------------------------------------------------------- |
660 HBufC *bufAbsFileName = HBufC::NewLC(KMaxPath); |
634 // |
661 *bufAbsFileName = iCurrentPath.DriveAndPath(); |
635 TInt CAknFileSelectionModel::GetIconForFileL(const TDesC& aFileName ) const |
662 TPtr absFileName = bufAbsFileName->Des(); |
636 { |
663 |
637 TParsePtrC ptr( aFileName ); |
664 absFileName.Append( aFileName ); |
638 TPtrC ptrc = ptr.Ext(); |
665 TUid uidIgnore; |
639 for ( TInt i = 0; i < iFileTypeArray->Count(); i++ ) |
666 TDataType dataType; |
640 { |
667 TInt err = iApaSession.AppForDocument( absFileName, uidIgnore, dataType ); |
641 if ( ptrc.MatchF( (*iFileTypeArray)[i].iFileType ) == 0 ) |
668 TInt iconIndex = EUnknowTypeIcon; |
642 { |
669 CleanupStack::PopAndDestroy(); //bufAbsFileName |
643 return (*iFileTypeArray)[i].iIconIndex; |
670 |
644 } |
671 if( err != KErrNone ) |
645 } |
672 { |
646 return EUnknowTypeIcon; |
673 // Couldn't find out the data type, use generic file icon: |
|
674 iconIndex = EUnknowTypeIcon; |
|
675 } |
|
676 else |
|
677 { |
|
678 HBufC *bufDataTypeBuf = HBufC::NewLC(KMaxDataTypeLength); |
|
679 *bufDataTypeBuf = dataType.Des(); |
|
680 TPtr dataTypeBuf = bufDataTypeBuf->Des(); |
|
681 |
|
682 if( dataTypeBuf.MatchF( KCFDMimeTypeAudioVoiceRec ) == 0 || |
|
683 dataTypeBuf.MatchF( KCFDMimeTypeAudioVoiceRec2 ) == 0 ) |
|
684 { |
|
685 iconIndex = EVoiceRecFileIcon; |
|
686 } |
|
687 else if( dataTypeBuf.MatchF( KCFDMimeTypePlaylist ) == 0 ) |
|
688 { |
|
689 iconIndex = EPlaylistFileIcon; |
|
690 } |
|
691 else if( dataTypeBuf.MatchF( KCFDMimeTypeRam ) == 0 ) |
|
692 { |
|
693 iconIndex = ELinkFileIcon; |
|
694 } |
|
695 else if( dataTypeBuf.MatchF( KCFDMimeTypeAudio ) == 0 ) |
|
696 { |
|
697 iconIndex = ESoundFileIcon; |
|
698 } |
|
699 else if( dataTypeBuf.MatchF( KCFDMimeTypeImageGms ) == 0 ) |
|
700 { |
|
701 iconIndex = EGmsFileIcon; |
|
702 } |
|
703 else if( dataTypeBuf.MatchF( KCFDMimeTypeImage ) == 0 ) |
|
704 { |
|
705 iconIndex = EImageFileIcon; |
|
706 } |
|
707 else if( dataTypeBuf.MatchF( KCFDMimeTypeVideo ) == 0 || |
|
708 dataTypeBuf.MatchF( KCFDMimeTypeVideoRealMedia ) == 0 || |
|
709 dataTypeBuf.MatchF( KCFDMimeTypeVideoSdp ) == 0 ) |
|
710 { |
|
711 iconIndex = EVideoFileIcon; |
|
712 } |
|
713 else if( dataTypeBuf.MatchF( KCFDMimeTypeGame ) == 0 ) |
|
714 { |
|
715 iconIndex = EGameFileIcon; |
|
716 } |
|
717 else if( dataTypeBuf.MatchF( KCFDMimeTypeNote ) == 0 ) |
|
718 { |
|
719 iconIndex = ENoteFileIcon; |
|
720 } |
|
721 else if( dataTypeBuf.MatchF( KCFDMimeTypeJava ) == 0 ) |
|
722 { |
|
723 iconIndex = EJavaFileIcon; |
|
724 } |
|
725 else if ( dataTypeBuf.MatchF( KCFDMimeTypeFlash ) == 0 ) |
|
726 { |
|
727 iconIndex = EFlashFileIcon; |
|
728 } |
|
729 else |
|
730 { |
|
731 // Check from the file name extension, if it's a SIS file: |
|
732 //TParse fileName; |
|
733 //fileName.Set( aFileName, NULL, NULL ); |
|
734 |
|
735 HBufC * bufFileName = aFileName.AllocLC(); |
|
736 TPtr ptrFileName = bufFileName->Des(); |
|
737 TParsePtr fileName(ptrFileName); |
|
738 |
|
739 TPtrC ext( fileName.Ext() ); |
|
740 if( ext.CompareF( KCFDFileExtSis ) == 0 |
|
741 || ext.CompareF( KCFDFileExtSisx ) == 0 ) |
|
742 { |
|
743 iconIndex = ESisFileIcon; |
|
744 } |
|
745 // RApaLsSession does not recognize .mid's: |
|
746 else if( ext.CompareF( KCFDFileExtMid ) == 0 ) |
|
747 { |
|
748 iconIndex = ESoundFileIcon; |
|
749 } |
|
750 else |
|
751 { |
|
752 iconIndex = EUnknowTypeIcon; |
|
753 } |
|
754 CleanupStack::PopAndDestroy(); //bufFileName |
|
755 |
|
756 } |
|
757 |
|
758 CleanupStack::PopAndDestroy(); //bufDataTypeBuf |
|
759 } |
|
760 iImageIndexArray.Append( iconIndex ); |
|
761 } |
647 } |
762 |
648 |
763 TPtrC CAknFileSelectionModel::GetLocalizedName(const TDesC& aFileName) |
649 TPtrC CAknFileSelectionModel::GetLocalizedName(const TDesC& aFileName) |
764 { |
650 { |
765 TParsePtrC parsedEntry( aFileName ); |
651 TParsePtrC parsedEntry( aFileName ); |
766 TPtrC fileName( parsedEntry.NameAndExt() ); |
652 TPtrC fileName( parsedEntry.NameAndExt() ); |
767 |
653 |
768 TPtr itemWithImageIndex = iItemWithImageIndex->Des(); |
654 TPtr itemWithImageIndex = iStringBuf->Des(); |
769 |
655 |
770 itemWithImageIndex = iCurrentPath.DriveAndPath(); |
656 itemWithImageIndex = iCurrentPath.DriveAndPath(); |
771 itemWithImageIndex.Append( aFileName); |
657 itemWithImageIndex.Append( aFileName); |
772 // ignore error: |
658 // ignore error: |
773 AknCFDUtility::AddTrailingBackslash( itemWithImageIndex ); |
659 AknCFDUtility::AddTrailingBackslash( itemWithImageIndex ); |