|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "CAknFileSelectionModel.h" |
|
21 |
|
22 #include <CDirectoryLocalizer.h> |
|
23 #include <barsread.h> // TResourceReader |
|
24 #include <bautils.h> // BaflUtils for checking if a path exists |
|
25 #include <coemain.h> |
|
26 #include <commondialogs.rsg> |
|
27 #include <apmstd.h> // TDataType |
|
28 #include <badesca.h> //CDesC16Array |
|
29 |
|
30 #include "MAknFileSelectionObserver.h" |
|
31 #include "MAknFileFilter.h" |
|
32 #include "AknCFDUtility.h" |
|
33 #include "CAknDataCagingFilter.h" |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KEntryArrayGranularity( 10 ); |
|
37 const TInt KFilterArrayGranularity( 2 ); |
|
38 |
|
39 _LIT( KCFDMimeTypeImage, "image/*" ); |
|
40 _LIT( KCFDMimeTypeImageGms, "image/x-ota-bitmap" ); |
|
41 _LIT( KCFDMimeTypeRam, "audio/x-pn-realaudio-plugin" ); // = link |
|
42 _LIT( KCFDMimeTypeAudioVoiceRec, "audio/amr*" ); |
|
43 _LIT( KCFDMimeTypeAudioVoiceRec2, "application/vnd.nokia.ringing-tone" ); |
|
44 _LIT( KCFDMimeTypeAudio, "audio/*" ); // = other sound files |
|
45 _LIT( KCFDMimeTypePlaylist, "audio/*mpegurl*" ); |
|
46 _LIT( KCFDMimeTypeVideo, "video/*" ); |
|
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 |
|
58 // ============================ MEMBER FUNCTIONS =============================== |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CAknFileSelectionModel::CAknFileSelectionModel |
|
62 // |
|
63 // |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CAknFileSelectionModel::CAknFileSelectionModel( |
|
67 const TCommonDialogType& aDialogType, CCoeEnv& aCoeEnv ) |
|
68 : iImageIndexArray( KEntryArrayGranularity ), |
|
69 iDirectoryLevel( 0 ), |
|
70 iDialogType( aDialogType ), |
|
71 iCoeEnv( aCoeEnv ) |
|
72 { |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CAknFileSelectionModel::ConstructL |
|
77 // |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CAknFileSelectionModel::ConstructL() |
|
81 { |
|
82 User::LeaveIfError( iApaSession.Connect() ); |
|
83 iLocalizer = CDirectoryLocalizer::NewL(); |
|
84 iEntryArray = new( ELeave ) CArrayPakFlat<TEntry>( KEntryArrayGranularity ); |
|
85 iFilterArray = new( ELeave ) CArrayPtrSeg<MAknFileFilter>( KFilterArrayGranularity ); |
|
86 iItemWithImageIndex = HBufC::NewL(KMaxPath); |
|
87 User::LeaveIfError( iFs.Connect() ); |
|
88 iRootFolderText = iCoeEnv.AllocReadResourceL( R_CFD_QTN_FLDR_ROOT_LEVEL ); |
|
89 |
|
90 AddFilterL( CAknDataCagingFilter::NewLC() ); |
|
91 CleanupStack::Pop(); //caging filter |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CAknFileSelectionModel::NewL |
|
96 // |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CAknFileSelectionModel* CAknFileSelectionModel::NewL( |
|
100 const TCommonDialogType& aType, CCoeEnv& aCoeEnv ) |
|
101 { |
|
102 CAknFileSelectionModel* self = |
|
103 new( ELeave ) CAknFileSelectionModel( aType, aCoeEnv ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 CleanupStack::Pop(); |
|
107 return self; |
|
108 } |
|
109 |
|
110 // Destructor |
|
111 CAknFileSelectionModel::~CAknFileSelectionModel() |
|
112 { |
|
113 delete iRootFolderText; |
|
114 iImageIndexArray.Close(); |
|
115 iFs.Close(); |
|
116 |
|
117 delete iItemWithImageIndex; |
|
118 |
|
119 if ( iFilterArray ) |
|
120 { |
|
121 iFilterArray->ResetAndDestroy(); |
|
122 delete iFilterArray; |
|
123 } |
|
124 if ( iEntryArray ) |
|
125 { |
|
126 iEntryArray->Reset(); |
|
127 delete iEntryArray; |
|
128 } |
|
129 delete iLocalizer; |
|
130 |
|
131 |
|
132 iApaSession.Close(); |
|
133 } |
|
134 |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CAknFileSelectionModel::SetPathL |
|
138 // |
|
139 // |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 TInt CAknFileSelectionModel::SetPathL( const TDesC& aPath ) |
|
143 { |
|
144 HBufC * path = HBufC::NewLC( KMaxPath ); |
|
145 *path = aPath; |
|
146 TPtr ptrPath = path->Des(); |
|
147 |
|
148 TInt errorCode( AknCFDUtility::AddTrailingBackslash( ptrPath ) ); |
|
149 if ( errorCode != KErrNone ) |
|
150 { |
|
151 CleanupStack::PopAndDestroy(); |
|
152 return errorCode; |
|
153 } |
|
154 |
|
155 errorCode = iParse.SetNoWild( ptrPath, NULL, NULL ); |
|
156 |
|
157 if ( errorCode != KErrNone ) |
|
158 { |
|
159 // Converting path to TParse was unsuccessful |
|
160 CleanupStack::PopAndDestroy(); |
|
161 return errorCode; |
|
162 } |
|
163 TEntry entry; |
|
164 TInt err( iFs.Entry( ptrPath,entry ) ); |
|
165 if ( err == KErrNotFound || err == KErrPathNotFound ) |
|
166 { |
|
167 // Path doesn't exist |
|
168 CleanupStack::PopAndDestroy(); |
|
169 return KErrPathNotFound; |
|
170 } |
|
171 |
|
172 // Set as current path |
|
173 iCurrentPath = iParse; |
|
174 // Reset directory level |
|
175 iDirectoryLevel = 0; |
|
176 |
|
177 |
|
178 errorCode = UpdateItemListL(); |
|
179 |
|
180 CleanupStack::PopAndDestroy(); |
|
181 |
|
182 return errorCode; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CAknFileSelectionModel::AddFolderL |
|
187 // |
|
188 // |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 TInt CAknFileSelectionModel::AddFolderL( const TDesC& aFolder ) |
|
192 { |
|
193 // Cache the directory level because SetPath resets it |
|
194 TInt level( iDirectoryLevel ); |
|
195 |
|
196 // The engine only supports adding one folder at a time |
|
197 if ( AknCFDUtility::DirectoryCount( aFolder ) != 1 ) |
|
198 { |
|
199 return KErrNotSupported; |
|
200 } |
|
201 |
|
202 //TPath currentPath( iCurrentPath.DriveAndPath() ); |
|
203 |
|
204 HBufC * bufCurrentPath = HBufC::NewLC(KMaxPath); |
|
205 *bufCurrentPath = iCurrentPath.DriveAndPath(); |
|
206 TPtr currentPath = bufCurrentPath->Des(); |
|
207 |
|
208 currentPath.Append( aFolder ); |
|
209 |
|
210 TInt errorCode( SetPathL( currentPath ) ); |
|
211 |
|
212 CleanupStack::PopAndDestroy(); //bufCurrentPath |
|
213 |
|
214 if ( errorCode < KErrNone ) |
|
215 { |
|
216 return errorCode; |
|
217 } |
|
218 |
|
219 iDirectoryLevel = ++level; |
|
220 |
|
221 return errorCode; |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CAknFileSelectionModel::AddFilterL |
|
226 // Ownership of filter is moved to the engine |
|
227 // |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CAknFileSelectionModel::AddFilterL( MAknFileFilter* aFilter ) |
|
231 { |
|
232 iFilterArray->AppendL( aFilter ); |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CAknFileSelectionModel::GotoSubFolderL |
|
237 // |
|
238 // |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 TInt CAknFileSelectionModel::GotoSubFolderL( const TDesC& aFolder ) |
|
242 { |
|
243 return AddFolderL( aFolder ); |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CAknFileSelectionModel::GotoParentFolderL |
|
248 // |
|
249 // |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 TInt CAknFileSelectionModel::GotoParentFolderL() |
|
253 { |
|
254 TInt errorCode( KErrNotFound ); // Indicating under root situation |
|
255 if ( iDirectoryLevel > 0 ) |
|
256 { |
|
257 errorCode = iCurrentPath.PopDir(); |
|
258 if ( errorCode == KErrNone ) |
|
259 { |
|
260 iDirectoryLevel--; |
|
261 errorCode = UpdateItemListL(); |
|
262 } |
|
263 } |
|
264 return errorCode; |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CAknFileSelectionModel::UpdateItemListL |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 TInt CAknFileSelectionModel::UpdateItemListL() |
|
272 { |
|
273 iEntryArray->Reset(); |
|
274 iImageIndexArray.Reset(); |
|
275 |
|
276 CDir* entryArray = ReadDirectory( iCurrentPath.DriveAndPath() ); |
|
277 if ( !entryArray ) |
|
278 { |
|
279 return KErrNotFound; |
|
280 } |
|
281 CleanupStack::PushL( entryArray ); |
|
282 |
|
283 TInt itemCount( entryArray->Count() ); |
|
284 if ( itemCount > 0 ) |
|
285 { |
|
286 TInt filterCount( iFilterArray->Count() ); |
|
287 TInt filterIndex; |
|
288 TBool accepted; |
|
289 CDesC16Array* desC16FoldersArray = new ( ELeave ) |
|
290 CDesC16ArrayFlat( KEntryArrayGranularity ); |
|
291 CleanupStack::PushL( desC16FoldersArray ); |
|
292 CDesC16Array* desC16FilesArray = new ( ELeave ) |
|
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 { |
|
315 accepted = iFilterArray->At( filterIndex )->Accept( |
|
316 iCurrentPath.DriveAndPath(), entry ); |
|
317 filterIndex++; |
|
318 } |
|
319 if ( accepted ) // Directory entry has passed all filters |
|
320 { |
|
321 // Add filename to filtered list |
|
322 if ( entry.IsDir() ) |
|
323 { |
|
324 desC16FoldersArray->AppendL( GetLocalizedName( entry.iName ) ); |
|
325 tmpFoldersArray->AppendL( entry, sizeof( TEntry ) ); |
|
326 } |
|
327 else |
|
328 { |
|
329 desC16FilesArray->AppendL( GetLocalizedName( entry.iName ) ); |
|
330 tmpFilesArray->AppendL( entry, sizeof( TEntry ) ); |
|
331 } |
|
332 } |
|
333 } |
|
334 |
|
335 TInt entryCount = 0; |
|
336 TInt index; |
|
337 TKeyArrayPak key( _FOFF( TEntry, iName ), ECmpCollated ); |
|
338 |
|
339 // Add folder entries |
|
340 desC16FoldersArray->Sort( ECmpCollated ); |
|
341 entryCount = desC16FoldersArray->MdcaCount(); |
|
342 for( TInt j( 0 ); j < entryCount; j++ ) |
|
343 { |
|
344 for( TInt k( 0 ); k < entryCount; k++ ) |
|
345 { |
|
346 if( ( *desC16FoldersArray )[j] == |
|
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 } |
|
373 } |
|
374 |
|
375 // Add file entries |
|
376 desC16FilesArray->Sort( ECmpCollated ); |
|
377 entryCount = desC16FilesArray->MdcaCount(); |
|
378 for( TInt j( 0 ); j < entryCount; j++ ) |
|
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(); |
|
435 } |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // CAknFileSelectionModel::Entry |
|
439 // |
|
440 // |
|
441 // ----------------------------------------------------------------------------- |
|
442 // |
|
443 const TEntry& CAknFileSelectionModel::Entry( const TInt& aIndex ) const |
|
444 { |
|
445 return iEntryArray->At( aIndex ); |
|
446 } |
|
447 |
|
448 // ----------------------------------------------------------------------------- |
|
449 // CAknFileSelectionModel::GetCurrentPath |
|
450 // |
|
451 // |
|
452 // ----------------------------------------------------------------------------- |
|
453 // |
|
454 void CAknFileSelectionModel::GetCurrentPath( TDes& aPath ) const |
|
455 { |
|
456 aPath = iCurrentPath.DriveAndPath(); |
|
457 } |
|
458 |
|
459 // ----------------------------------------------------------------------------- |
|
460 // CAknFileSelectionModel::DirectoryLevel |
|
461 // |
|
462 // |
|
463 // ----------------------------------------------------------------------------- |
|
464 // |
|
465 TInt CAknFileSelectionModel::DirectoryLevel() const |
|
466 { |
|
467 return iDirectoryLevel; |
|
468 } |
|
469 |
|
470 // ----------------------------------------------------------------------------- |
|
471 // CAknFileSelectionModel::FolderIndex |
|
472 // |
|
473 // |
|
474 // ----------------------------------------------------------------------------- |
|
475 // |
|
476 TInt CAknFileSelectionModel::FolderIndex( const TDesC& aFolder ) const |
|
477 { |
|
478 TInt arrayCount( iEntryArray->Count() ); // Number of items in entry array |
|
479 TPath folder( aFolder ); |
|
480 TInt folderLength( folder.Length() ); |
|
481 if ( folderLength > 0 ) |
|
482 { |
|
483 // If the last character is backslash, delete it |
|
484 if ( folder[ folderLength - 1 ] == '\\' ) |
|
485 { |
|
486 folder.Delete( folderLength - 1, 1 ); |
|
487 } |
|
488 // Try to find the folder from list |
|
489 for ( TInt index( 0 ); index < arrayCount; index++ ) |
|
490 { |
|
491 if ( folder.CompareF( iEntryArray->At( index ).iName ) == 0 ) |
|
492 { |
|
493 // When found, return its index |
|
494 return index; |
|
495 } |
|
496 } |
|
497 } |
|
498 |
|
499 // Return not found if not found |
|
500 return KErrNotFound; |
|
501 } |
|
502 |
|
503 // ----------------------------------------------------------------------------- |
|
504 // CAknFileSelectionModel::MdcaCount |
|
505 // |
|
506 // |
|
507 // ----------------------------------------------------------------------------- |
|
508 // |
|
509 TInt CAknFileSelectionModel::MdcaCount() const |
|
510 { |
|
511 return iEntryArray->Count(); |
|
512 } |
|
513 |
|
514 // ----------------------------------------------------------------------------- |
|
515 // CAknFileSelectionModel::MdcaPoint |
|
516 // |
|
517 // |
|
518 // ----------------------------------------------------------------------------- |
|
519 // |
|
520 TPtrC CAknFileSelectionModel::MdcaPoint( TInt aIndex ) const |
|
521 { |
|
522 TEntry entry = iEntryArray->At( aIndex ); // reference |
|
523 TParsePtrC parsedEntry( entry.iName ); |
|
524 TPtrC fileName( parsedEntry.NameAndExt() ); |
|
525 TInt entryType( iImageIndexArray[ aIndex ] ); |
|
526 |
|
527 TPtr itemWithImageIndex = iItemWithImageIndex->Des(); |
|
528 |
|
529 switch( entryType ) |
|
530 { |
|
531 case EThisFolderIcon: |
|
532 { |
|
533 if ( iDirectoryLevel == 0 ) |
|
534 { |
|
535 // Root folder |
|
536 fileName.Set( iRootFolderText->Des() ); |
|
537 } |
|
538 else |
|
539 { |
|
540 // Not the root folder |
|
541 iLocalizer->SetFullPath( iCurrentPath.DriveAndPath() ); |
|
542 if ( iLocalizer->IsLocalized() ) // Localized? |
|
543 { |
|
544 // Folder name is localized |
|
545 fileName.Set( iLocalizer->LocalizedName() ); |
|
546 } |
|
547 } |
|
548 break; |
|
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 } |
|
577 |
|
578 // ----------------------------------------------------------------------------- |
|
579 // CAknFileSelectionModel::ReadDirectory |
|
580 // |
|
581 // |
|
582 // ----------------------------------------------------------------------------- |
|
583 // |
|
584 CDir* CAknFileSelectionModel::ReadDirectory( const TDesC& aDirectory ) |
|
585 { |
|
586 // All attributes but system and hidden attribute |
|
587 TUint mask( KEntryAttMaskSupported & ~( KEntryAttSystem | KEntryAttHidden ) ); |
|
588 CDir* entryArray = NULL; |
|
589 |
|
590 if ( AknCFDUtility::DirectoriesOnly( iDialogType ) ) |
|
591 { |
|
592 // Keep old code for possible roll-back. |
|
593 /* |
|
594 mask &= ~KEntryAttDir; |
|
595 CDir* temp; |
|
596 iFs.GetDir( aDirectory, mask, |
|
597 ESortByName | EDirsFirst | EAscending, temp, entryArray ); |
|
598 delete temp; |
|
599 */ |
|
600 iFs.GetDir( aDirectory, KEntryAttDir | KEntryAttMatchExclusive, |
|
601 ESortByName | EAscending, entryArray ); |
|
602 } |
|
603 else |
|
604 { |
|
605 iFs.GetDir( aDirectory, mask, |
|
606 ESortByName | EDirsFirst | EAscending, entryArray ); |
|
607 } |
|
608 |
|
609 if ( entryArray ) |
|
610 { |
|
611 // No errors. Remove possible system directory from list |
|
612 BaflUtils::RemoveSystemDirectory( *entryArray ); |
|
613 } |
|
614 return entryArray; |
|
615 } |
|
616 |
|
617 // ----------------------------------------------------------------------------- |
|
618 // CAknFileSelectionModel::ContainsSubfolders |
|
619 // |
|
620 // |
|
621 // ----------------------------------------------------------------------------- |
|
622 // |
|
623 TBool CAknFileSelectionModel::ContainsSubfolders( const TDesC& aFolder ) |
|
624 { |
|
625 TPath directory( iCurrentPath.DriveAndPath() ); |
|
626 directory.Append( aFolder ); |
|
627 AknCFDUtility::AddTrailingBackslash( directory ); // ignore error |
|
628 |
|
629 // Keep old code for possible roll-back |
|
630 /* |
|
631 CDir* array = ReadDirectory( directory ); |
|
632 if( ( !array ) || ( array->Count() == 0 ) || ( !(* array)[ 0 ].IsDir() ) ) |
|
633 { |
|
634 delete array; |
|
635 return EFalse; |
|
636 } |
|
637 delete array; |
|
638 return ETrue; |
|
639 */ |
|
640 |
|
641 RDir dir; |
|
642 TBool ret( EFalse ); |
|
643 if ( dir.Open( |
|
644 iFs, directory, KEntryAttDir | KEntryAttMatchExclusive ) != KErrNone ) |
|
645 { |
|
646 return EFalse; |
|
647 } |
|
648 TEntry entry; |
|
649 if ( dir.Read( entry ) == KErrNone ) |
|
650 { |
|
651 ret = ETrue; |
|
652 } |
|
653 dir.Close(); |
|
654 return ret; |
|
655 } |
|
656 |
|
657 void CAknFileSelectionModel::AppendIconForFileL(const TDesC& aFileName) |
|
658 { |
|
659 //TFileName absFileName( iCurrentPath.DriveAndPath() ); |
|
660 HBufC *bufAbsFileName = HBufC::NewLC(KMaxPath); |
|
661 *bufAbsFileName = iCurrentPath.DriveAndPath(); |
|
662 TPtr absFileName = bufAbsFileName->Des(); |
|
663 |
|
664 absFileName.Append( aFileName ); |
|
665 TUid uidIgnore; |
|
666 TDataType dataType; |
|
667 TInt err = iApaSession.AppForDocument( absFileName, uidIgnore, dataType ); |
|
668 TInt iconIndex = EUnknowTypeIcon; |
|
669 CleanupStack::PopAndDestroy(); //bufAbsFileName |
|
670 |
|
671 if( err != KErrNone ) |
|
672 { |
|
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 } |
|
762 |
|
763 TPtrC CAknFileSelectionModel::GetLocalizedName(const TDesC& aFileName) |
|
764 { |
|
765 TParsePtrC parsedEntry( aFileName ); |
|
766 TPtrC fileName( parsedEntry.NameAndExt() ); |
|
767 |
|
768 TPtr itemWithImageIndex = iItemWithImageIndex->Des(); |
|
769 |
|
770 itemWithImageIndex = iCurrentPath.DriveAndPath(); |
|
771 itemWithImageIndex.Append( aFileName); |
|
772 // ignore error: |
|
773 AknCFDUtility::AddTrailingBackslash( itemWithImageIndex ); |
|
774 iLocalizer->SetFullPath( itemWithImageIndex ); |
|
775 if( iLocalizer->IsLocalized() ) |
|
776 { |
|
777 fileName.Set( iLocalizer->LocalizedName() ); |
|
778 } |
|
779 return fileName; |
|
780 } |
|
781 |
|
782 // ----------------------------------------------------------------------------- |
|
783 // CAknFileSelectionModel::ContainsFiles |
|
784 // |
|
785 // ----------------------------------------------------------------------------- |
|
786 // |
|
787 TBool CAknFileSelectionModel::ContainsFiles( const TDesC& aFolder ) |
|
788 { |
|
789 TPath directory( iCurrentPath.DriveAndPath() ); |
|
790 directory.Append( aFolder ); |
|
791 AknCFDUtility::AddTrailingBackslash( directory ); // ignore error |
|
792 |
|
793 RDir dir; |
|
794 TBool ret( EFalse ); |
|
795 if ( dir.Open( |
|
796 iFs, directory, KEntryAttNormal ) != KErrNone ) |
|
797 { |
|
798 return EFalse; |
|
799 } |
|
800 TEntry entry; |
|
801 if ( dir.Read( entry ) == KErrNone ) |
|
802 { |
|
803 ret = ETrue; |
|
804 } |
|
805 dir.Close(); |
|
806 return ret; |
|
807 } |
|
808 // End of File |