|
1 /* |
|
2 * Copyright (c) 2002-2008 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: Utility class to provide common functionalities internally. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <coemain.h> |
|
21 #include <bautils.h> |
|
22 #include <AknIconArray.h> |
|
23 #include <eikenv.h> |
|
24 #include <AknsUtils.h> |
|
25 #include <gulicon.h> |
|
26 #include <fbs.h> |
|
27 #include <rsfwmountman.h> |
|
28 #include <driveinfo.h> |
|
29 #include <StringLoader.h> |
|
30 #include <commondialogs.rsg> |
|
31 #include "AknCFDUtility.h" |
|
32 #include <AknUtils.h> |
|
33 |
|
34 _LIT(KFreeFormate, "%.1f"); |
|
35 |
|
36 const TInt KListBoxEntryMaxLength( KMaxFileName + 32 ); |
|
37 const TInt KFreeLen = 10; |
|
38 const TInt KNoIndex = -1; |
|
39 const TInt KHundredNum = 100; |
|
40 const TInt KThousandNum = 1024; |
|
41 const TInt KMegaNum = 1024*1024; |
|
42 const TInt KGigaNum = 1024*1024*1024; |
|
43 // ======== MEMBER FUNCTIONS ======== |
|
44 |
|
45 #pragma message("TODO: CFDUtilityDUMMY is still not updated identical to CFDUtility") |
|
46 |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // AknCFDUtility::DriveInfoL |
|
50 // aDriveInfo.iDriveStatus is set according the error code given by RFs |
|
51 // functions. Drive status differs slightly from RFs error codes. This is |
|
52 // because CFD functionality does need most of the error codes. Few drive |
|
53 // status codes are sufficient. This should simplify CFD error handling. |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 TInt AknCFDUtility::DriveInfoL( const TDriveNumber aDriveNumber, |
|
57 TCFDDriveInfo& aDriveInfo) |
|
58 { |
|
59 TInt error; |
|
60 TFullName fsName; |
|
61 TDriveInfo driveInfo; |
|
62 TVolumeInfo volumeInfo; |
|
63 |
|
64 aDriveInfo.iVolumeLabel.Des().Zero(); |
|
65 aDriveInfo.iDriveNumber = aDriveNumber; |
|
66 aDriveInfo.iDiskSpace = KDiskSpaceNotAvailable; |
|
67 aDriveInfo.iMediaType = EMediaNotPresent; |
|
68 aDriveInfo.iDriveStatus = EDriveOK; |
|
69 |
|
70 //iConnectionState: KMountStronglyConnected, KMountNotConnected |
|
71 aDriveInfo.iConnectionState = NULL; |
|
72 aDriveInfo.iStatus = NULL; |
|
73 |
|
74 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
75 _LIT( KFat, "Fat" ); |
|
76 |
|
77 // Check drive's media status |
|
78 error = DriveInfo::GetDriveStatus( fs, aDriveNumber, aDriveInfo.iStatus ); |
|
79 if( error ) |
|
80 { |
|
81 aDriveInfo.iStatus = DriveInfo::EDriveCorrupt; |
|
82 return error; |
|
83 } |
|
84 |
|
85 // Check if the drive is already mounted |
|
86 error = fs.FileSystemName( fsName, aDriveNumber ); |
|
87 if( error ) |
|
88 { |
|
89 aDriveInfo.iDriveStatus = EDriveNotReady; |
|
90 return error; |
|
91 } |
|
92 |
|
93 // check if MMC already mounted |
|
94 if( fsName.Length() == 0 ) |
|
95 { |
|
96 // MMC drive isnt mounted at present, so try it now.... |
|
97 error = fs.MountFileSystem( KFat, aDriveInfo.iDriveNumber ); |
|
98 |
|
99 // If it's a locked MMC and the password is already known it'll be |
|
100 // unlocked automatically when it's mounted., otherwise the mount will |
|
101 // return with KErrLocked..... |
|
102 switch( error ) |
|
103 { |
|
104 case KErrNone: |
|
105 { |
|
106 // OK to continue... |
|
107 break; |
|
108 } |
|
109 case KErrLocked: |
|
110 { |
|
111 aDriveInfo.iDriveStatus = EDriveLocked; |
|
112 return error; |
|
113 } |
|
114 default: |
|
115 { |
|
116 aDriveInfo.iDriveStatus = EDriveNotReady; |
|
117 return error; |
|
118 } |
|
119 } |
|
120 } |
|
121 error = fs.Drive( driveInfo, aDriveNumber ); |
|
122 if( error ) |
|
123 { |
|
124 aDriveInfo.iDriveStatus = EDriveNotReady; |
|
125 return error; |
|
126 } |
|
127 aDriveInfo.iMediaType = driveInfo.iType; |
|
128 |
|
129 // MMC is in slot |
|
130 if( driveInfo.iMediaAtt & KMediaAttLocked ) |
|
131 { |
|
132 aDriveInfo.iDriveStatus = EDriveLocked; |
|
133 return error; |
|
134 } |
|
135 |
|
136 if( driveInfo.iDriveAtt & KDriveAttRemote ) |
|
137 { |
|
138 // Initialize volumeInfo. |
|
139 error = fs.Volume( volumeInfo, aDriveNumber ); |
|
140 volumeInfo.iName.Des().Zero(); |
|
141 |
|
142 if ( !error ) |
|
143 { |
|
144 TPtr ptr = volumeInfo.iName.Des(); |
|
145 // Get remote drive name, RFs::Volume() can only got the name |
|
146 // which is less than 11, so use GetDriveName to got the name. |
|
147 error = fs.GetDriveName( aDriveNumber, ptr ); |
|
148 } |
|
149 } |
|
150 else |
|
151 { |
|
152 error = fs.Volume( volumeInfo, aDriveNumber ); |
|
153 } |
|
154 |
|
155 if( error ) |
|
156 { |
|
157 aDriveInfo.iDriveStatus = EDriveNotReady; |
|
158 return error; |
|
159 } |
|
160 |
|
161 #pragma message("TODO: Disk space checking for remote drives might need different implementation (CRsfwMountMan?).") |
|
162 |
|
163 TInt64 free( volumeInfo.iFree ); |
|
164 aDriveInfo.iDiskSpace = free; |
|
165 aDriveInfo.iVolumeLabel = volumeInfo.iName; |
|
166 |
|
167 // If type is remote drive and aConnectionState is required |
|
168 if( driveInfo.iDriveAtt & KDriveAttRemote ) |
|
169 { |
|
170 TChar driveLetter; |
|
171 fs.DriveToChar( aDriveNumber, driveLetter ); |
|
172 |
|
173 // This statement migth cause leave.. to be solved |
|
174 CRsfwMountMan* mountMgr = CRsfwMountMan::NewL( 0, NULL ); |
|
175 TRsfwMountInfo mountInfo; |
|
176 error = mountMgr->GetMountInfo( driveLetter, mountInfo ); |
|
177 delete mountMgr; |
|
178 aDriveInfo.iConnectionState = mountInfo.iMountStatus.iConnectionState; |
|
179 if( error || |
|
180 mountInfo.iMountStatus.iConnectionState != KMountStronglyConnected ) |
|
181 { |
|
182 aDriveInfo.iDriveStatus = EDriveNotReady; |
|
183 return error; |
|
184 } |
|
185 } |
|
186 return error; |
|
187 } |
|
188 |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // AknCFDUtility::DriveStatusL |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 TCFDDriveStatus AknCFDUtility::DriveStatusL( const TDriveNumber aDriveNumber ) |
|
195 { |
|
196 #pragma message("TODO: Find out the actual functions needed for checking drive status - this might be too heavy checking.") |
|
197 |
|
198 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
199 _LIT( KFat, "Fat" ); |
|
200 |
|
201 // Check if the drive is already mounted |
|
202 TFullName fsName; |
|
203 TInt error( fs.FileSystemName( fsName, aDriveNumber ) ); |
|
204 if( error ) |
|
205 { |
|
206 return EDriveNotReady; |
|
207 } |
|
208 |
|
209 // check if MMC already mounted |
|
210 if( fsName.Length() == 0 ) |
|
211 { |
|
212 // MMC drive isnt mounted at present, so try it now.... |
|
213 error = fs.MountFileSystem( KFat, aDriveNumber ); |
|
214 |
|
215 // If it's a locked MMC and the password is already known it'll be |
|
216 // unlocked automatically when it's mounted., otherwise the mount will |
|
217 // return with KErrLocked..... |
|
218 switch( error ) |
|
219 { |
|
220 case KErrNone: |
|
221 { |
|
222 // OK to continue... |
|
223 break; |
|
224 } |
|
225 case KErrLocked: |
|
226 { |
|
227 return EDriveLocked; |
|
228 } |
|
229 default: |
|
230 { |
|
231 return EDriveNotReady; |
|
232 } |
|
233 } |
|
234 } |
|
235 TDriveInfo driveInfo; |
|
236 error = fs.Drive( driveInfo, aDriveNumber ); |
|
237 if( error ) |
|
238 { |
|
239 return EDriveNotReady; |
|
240 } |
|
241 |
|
242 // MMC is in slot |
|
243 if( driveInfo.iMediaAtt & KMediaAttLocked ) |
|
244 { |
|
245 return EDriveLocked; |
|
246 } |
|
247 |
|
248 TVolumeInfo volumeInfo; |
|
249 error = fs.Volume( volumeInfo, aDriveNumber ); |
|
250 if( error ) |
|
251 { |
|
252 return EDriveNotReady; |
|
253 } |
|
254 |
|
255 // If type is remote drive and aConnectionState is required |
|
256 if( driveInfo.iDriveAtt & KDriveAttRemote ) |
|
257 { |
|
258 TChar driveLetter; |
|
259 fs.DriveToChar( aDriveNumber, driveLetter ); |
|
260 // This statement migth cause leave.. to be solved |
|
261 CRsfwMountMan* mountMgr = CRsfwMountMan::NewL( 0, NULL ); |
|
262 TRsfwMountInfo mountInfo; |
|
263 error = mountMgr->GetMountInfo( driveLetter, mountInfo ); |
|
264 delete mountMgr; |
|
265 |
|
266 if( error || |
|
267 mountInfo.iMountStatus.iConnectionState != KMountStronglyConnected ) |
|
268 { |
|
269 return EDriveNotReady; |
|
270 } |
|
271 } |
|
272 return EDriveOK; |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // AknCFDUtility::DriveNumber |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 TInt AknCFDUtility::DriveNumber( const TDesC& aPath ) |
|
280 { |
|
281 TDriveUnit unit( aPath ); |
|
282 return TInt( unit ); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // AknCFDUtility::DirectoryCount |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 TInt AknCFDUtility::DirectoryCount( const TDesC& aPath ) |
|
290 { |
|
291 TInt pathLength( aPath.Length() ); |
|
292 if( pathLength == 0 ) |
|
293 { |
|
294 return 0; |
|
295 } |
|
296 TInt directoryCount( 0 ); |
|
297 TUint character( 0 ); |
|
298 for( TInt index( 0 ); index < pathLength; index++ ) |
|
299 { |
|
300 // Find backslash characters from path |
|
301 character = aPath[ index ]; |
|
302 if( character == '\\' ) |
|
303 { |
|
304 directoryCount++; |
|
305 } |
|
306 } |
|
307 // If the path doesn't end to a backslash |
|
308 if( character != '\\' ) |
|
309 { |
|
310 // Add folder count with one |
|
311 // e.g. "Nokia\Images" would return 1 folder but it should |
|
312 // return 2, like "Nokia\Images\" does |
|
313 directoryCount++; |
|
314 } |
|
315 return directoryCount; |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // AknCFDUtility::AddTrailingBackslash |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 TInt AknCFDUtility::AddTrailingBackslash( TDes& aPath ) |
|
323 { |
|
324 TInt descriptorLength( aPath.Length() ); |
|
325 if( descriptorLength == 0 ) |
|
326 { |
|
327 return KErrBadDescriptor; |
|
328 } |
|
329 // Check if path ends to a backslash |
|
330 if( aPath[ descriptorLength - 1 ] == '\\' ) |
|
331 { |
|
332 return KErrNone; |
|
333 } |
|
334 // Check that descriptor has space for one character |
|
335 if( aPath.MaxLength() == descriptorLength ) |
|
336 { |
|
337 return KErrOverflow; |
|
338 } |
|
339 aPath.Append( TChar( '\\' ) ); |
|
340 return KErrNone; |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 // AknCFDUtility::RemoveTrailingBackslash |
|
345 // --------------------------------------------------------------------------- |
|
346 // |
|
347 TInt AknCFDUtility::RemoveTrailingBackslash( TDes& aPath ) |
|
348 { |
|
349 TInt descriptorLength( aPath.Length() ); |
|
350 if( descriptorLength == 0 ) |
|
351 { |
|
352 return KErrBadDescriptor; |
|
353 } |
|
354 // Check if path already ends to a backslash |
|
355 if( aPath[ descriptorLength - 1 ] == '\\' ) |
|
356 { |
|
357 aPath.Delete( descriptorLength - 1, 1 ); |
|
358 } |
|
359 return KErrNone; |
|
360 } |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // AknCFDUtility::AllocateIfValidL |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 void AknCFDUtility::AllocateIfValidL( HBufC*& aDestination, const TDesC& aSource ) |
|
367 { |
|
368 if( aSource.Length() ) |
|
369 { |
|
370 delete aDestination; |
|
371 aDestination = NULL; |
|
372 aDestination = aSource.AllocL(); |
|
373 } |
|
374 } |
|
375 |
|
376 // --------------------------------------------------------------------------- |
|
377 // AknCFDUtility::AllocateOrNullL |
|
378 // --------------------------------------------------------------------------- |
|
379 // |
|
380 void AknCFDUtility::AllocateOrNullL( HBufC*& aDestination, const TDesC& aSource ) |
|
381 { |
|
382 delete aDestination; |
|
383 aDestination = NULL; |
|
384 if( aSource.Length() ) |
|
385 { |
|
386 aDestination = aSource.AllocL(); |
|
387 } |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // AknCFDUtility::AllocateIfNullL |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 void AknCFDUtility::AllocateIfNullL( HBufC*& aDestination, const TDesC& aSource ) |
|
395 { |
|
396 if( !aDestination ) |
|
397 { |
|
398 AllocateOrNullL( aDestination, aSource ); |
|
399 } |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------------------------- |
|
403 // AknCFDUtility::AppendImageToArrayL |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void AknCFDUtility::AppendImageToArrayL( |
|
407 CEikonEnv& /*aEnv*/, CAknIconArray& aArray, |
|
408 const TDesC& aBitmapFile, TInt aBitmapId, TInt aMaskId ) |
|
409 { |
|
410 CFbsBitmap* bitmap = NULL; |
|
411 CFbsBitmap* mask = NULL; |
|
412 AknIconUtils::CreateIconLC( |
|
413 bitmap, mask, aBitmapFile, aBitmapId, aMaskId ); |
|
414 CleanupStack::PushL( bitmap ); |
|
415 CleanupStack::PushL( mask ); |
|
416 |
|
417 // Ownership is transferred to CGulIcon |
|
418 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
419 |
|
420 CleanupStack::Pop( 2 ); // mask, bitmap |
|
421 CleanupStack::PushL( icon ); |
|
422 aArray.AppendL( icon ); // Ownership is transferred to CAknIconArray |
|
423 CleanupStack::Pop( icon ); // icon |
|
424 } |
|
425 |
|
426 // --------------------------------------------------------------------------- |
|
427 // AknCFDUtility::AppendSkinnedImageToArrayL |
|
428 // --------------------------------------------------------------------------- |
|
429 // |
|
430 void AknCFDUtility::AppendSkinnedImageToArrayL( CEikonEnv& /*aEnv*/, |
|
431 CAknIconArray& aArray, |
|
432 MAknsSkinInstance* aSkin, |
|
433 const TAknsItemID& aItemID, |
|
434 const TDesC& aBitmapFile, |
|
435 TInt aBitmapId, |
|
436 TInt aMaskId, |
|
437 TBool aColorIcon) |
|
438 { |
|
439 TRgb defaultColour( KRgbBlack ); |
|
440 |
|
441 CFbsBitmap* bitmap = NULL; |
|
442 CFbsBitmap* mask = NULL; |
|
443 if( aColorIcon ) |
|
444 { |
|
445 AknsUtils::GetCachedColor( aSkin, defaultColour, |
|
446 KAknsIIDQsnIconColors, |
|
447 EAknsCIQsnIconColorsCG13 ); |
|
448 AknsUtils::CreateColorIconLC( aSkin, aItemID, |
|
449 KAknsIIDQsnIconColors, |
|
450 EAknsCIQsnIconColorsCG13, bitmap, mask, |
|
451 aBitmapFile, aBitmapId, aMaskId, |
|
452 defaultColour ); |
|
453 |
|
454 // Ownership is transferred to CGulIcon |
|
455 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
456 CleanupStack::Pop( 2 ); // mask, bitmap |
|
457 CleanupStack::PushL( icon ); |
|
458 aArray.AppendL( icon ); // Ownership is transferred to CAknIconArray |
|
459 CleanupStack::Pop( icon ); // icon |
|
460 } |
|
461 else |
|
462 { |
|
463 AknsUtils::CreateIconL( aSkin, aItemID, bitmap, mask, aBitmapFile, |
|
464 aBitmapId, aMaskId ); |
|
465 CleanupStack::PushL( bitmap ); |
|
466 CleanupStack::PushL( mask ); |
|
467 |
|
468 // Ownership is transferred to CGulIcon |
|
469 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
470 CleanupStack::Pop( 2 ); // mask, bitmap |
|
471 CleanupStack::PushL( icon ); |
|
472 aArray.AppendL( icon ); // Ownership is transferred to CAknIconArray |
|
473 CleanupStack::Pop( icon ); // icon |
|
474 } |
|
475 } |
|
476 |
|
477 // --------------------------------------------------------------------------- |
|
478 // AknCFDUtility::DirectoriesOnly |
|
479 // --------------------------------------------------------------------------- |
|
480 // |
|
481 TBool AknCFDUtility::DirectoriesOnly( TCommonDialogType aType ) |
|
482 { |
|
483 if ( aType == ECFDDialogTypeMove || |
|
484 aType == ECFDDialogTypeSave || |
|
485 aType == ECFDDialogTypeBrowse || |
|
486 aType == ECFDDialogTypeCopy ) |
|
487 { |
|
488 return ETrue; |
|
489 } |
|
490 return EFalse; |
|
491 } |
|
492 |
|
493 |
|
494 // --------------------------------------------------------------------------- |
|
495 // AknCFDUtility::ReadDynamicDrivesL |
|
496 // --------------------------------------------------------------------------- |
|
497 // |
|
498 void AknCFDUtility::ReadDynamicDrivesL( |
|
499 CDesCArrayFlat& aRootPathArray, TInt aIncludedMedias ) |
|
500 { |
|
501 #ifdef _DEBUG |
|
502 CDesCArray* mediaTypeStrings = new (ELeave) CDesCArrayFlat(10); |
|
503 CleanupStack::PushL( mediaTypeStrings ); |
|
504 |
|
505 // TMediaType enumeration as string representation for debugging. |
|
506 mediaTypeStrings->AppendL( _L( "EMediaNotPresent" ) ); |
|
507 mediaTypeStrings->AppendL( _L( "EMediaUnknown" ) ); |
|
508 mediaTypeStrings->AppendL( _L( "EMediaFloppy" ) ); |
|
509 mediaTypeStrings->AppendL( _L( "EMediaHardDisk" )); |
|
510 mediaTypeStrings->AppendL( _L( "EMediaCdRom" )); |
|
511 mediaTypeStrings->AppendL( _L( "EMediaRam" )); |
|
512 mediaTypeStrings->AppendL( _L( "EMediaFlash" )); |
|
513 mediaTypeStrings->AppendL( _L( "EMediaRom" )); |
|
514 mediaTypeStrings->AppendL( _L( "EMediaRemote" )); |
|
515 mediaTypeStrings->AppendL( _L( "EMediaNANDFlash" )); |
|
516 _LOG( "[CFDUtility] Drive info: " ); |
|
517 #endif // _DEBUG |
|
518 |
|
519 // Get list of drives dynamically (move this to CFDUtility?) |
|
520 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
521 TDriveList driveList; |
|
522 |
|
523 CRsfwMountMan* mountMgr = CRsfwMountMan::NewL( 0, NULL ); |
|
524 CleanupStack::PushL( mountMgr ); |
|
525 mountMgr->GetRemoteMountListL( driveList ); |
|
526 CleanupStack::PopAndDestroy( mountMgr ); |
|
527 |
|
528 _LOG1( "[CFDUtility] driveList:%S", &driveList ); |
|
529 |
|
530 TChar driveLetter; |
|
531 TInt driveNumber = 0; |
|
532 _LIT( KDrivePath, "%c:\\" ); |
|
533 TDriveInfo driveInfo; |
|
534 |
|
535 for( TInt i = 0; i < driveList.Length(); i++ ) |
|
536 { |
|
537 driveLetter = driveList[ i ]; |
|
538 User::LeaveIfError( fs.CharToDrive( driveLetter, driveNumber ) ); |
|
539 User::LeaveIfError( fs.Drive( driveInfo, driveNumber ) ); |
|
540 |
|
541 #ifdef _DEBUG |
|
542 TPtrC mediaType( mediaTypeStrings->MdcaPoint( driveInfo.iType ) ); |
|
543 _LOG4( "[CFDUtility] %c:, ID:%d, Type:%S (%d)", |
|
544 TUint( driveLetter ), |
|
545 driveNumber, |
|
546 &mediaType, |
|
547 driveInfo.iType ); |
|
548 #endif // _DEBUG |
|
549 // If drive does not already exist and it is required in included |
|
550 // media types, append drive letter to rootpaths in correct format: |
|
551 if( !DriveAlreadyExists( aRootPathArray, driveLetter ) && |
|
552 IsIncludedMedia( driveInfo, aIncludedMedias ) ) |
|
553 { |
|
554 TBuf<5> driveBuf; |
|
555 TDesC16 drivePath(KDrivePath); |
|
556 driveBuf.Format( drivePath, &driveLetter ); |
|
557 aRootPathArray.AppendL( driveBuf ); |
|
558 } |
|
559 |
|
560 } |
|
561 |
|
562 #ifdef _DEBUG |
|
563 CleanupStack::PopAndDestroy( mediaTypeStrings ); |
|
564 #endif // _DEBUG |
|
565 } |
|
566 |
|
567 |
|
568 // --------------------------------------------------------------------------- |
|
569 // AknCFDUtility::DriveAlreadyExists |
|
570 // --------------------------------------------------------------------------- |
|
571 // |
|
572 TBool AknCFDUtility::DriveAlreadyExists( CDesCArrayFlat& aRootPathArray, |
|
573 TChar aDriveLetter ) |
|
574 { |
|
575 // Check that a drive does not already exist in roothpaths. This is done by |
|
576 // comparing the first letter in the descriptor. Both compared are |
|
577 // converted to upper case before comparison to prevent case mismatch. |
|
578 TBool driveAlreadyExists = EFalse; |
|
579 aDriveLetter = aDriveLetter.GetUpperCase(); |
|
580 for( TInt i = 0; i < aRootPathArray.MdcaCount(); i++ ) |
|
581 { |
|
582 TPtrC drive = aRootPathArray.MdcaPoint( i ).Left( 1 ); |
|
583 TChar driveLetter = drive[0]; |
|
584 driveLetter = driveLetter.GetUpperCase(); |
|
585 if( driveLetter == aDriveLetter ) |
|
586 { |
|
587 driveAlreadyExists = ETrue; |
|
588 break; |
|
589 } |
|
590 } |
|
591 _LOG1( "[CFDUtility] driveAlreadyExists=%d", driveAlreadyExists ); |
|
592 return driveAlreadyExists; |
|
593 } |
|
594 |
|
595 |
|
596 // --------------------------------------------------------------------------- |
|
597 // AknCFDUtility::IsIncludedMedia |
|
598 // --------------------------------------------------------------------------- |
|
599 // |
|
600 TBool AknCFDUtility::IsIncludedMedia( TDriveInfo aDriveInfo, |
|
601 TInt aIncludedMedias ) |
|
602 { |
|
603 TBool isIncludedMedia = EFalse; |
|
604 TMediaType aMediaType = aDriveInfo.iType; |
|
605 |
|
606 // Check each included media type bitflag: |
|
607 if( aIncludedMedias & AknCommonDialogsDynMem::EMemoryTypePhone ) |
|
608 { |
|
609 // Different memory types mapped to phone memory are not clear. |
|
610 // Therefore this is left empty for the time being. However |
|
611 // Most application logic is based on division between phone and |
|
612 // MMC memory. |
|
613 |
|
614 // TODO: Maybe could use EDriveC? |
|
615 _LOG( "[CFDUtility] Checking for EMemoryTypePhone" ); |
|
616 } |
|
617 if( aIncludedMedias & AknCommonDialogsDynMem::EMemoryTypeMMC ) |
|
618 { |
|
619 // Different memory types mapped to phone memory are not clear. |
|
620 // Therefore this is left empty for the time being. However |
|
621 // Most application logic is based on division between phone and |
|
622 // MMC memory. |
|
623 |
|
624 // TODO: Maybe could use EDriveE? |
|
625 _LOG( "[CFDUtility] Checking for EMemoryTypeMMC" ); |
|
626 } |
|
627 if( aIncludedMedias & AknCommonDialogsDynMem::EMemoryTypeRemote ) |
|
628 { |
|
629 _LOG( "[CFDUtility] Checking for EMemoryTypeRemote" ); |
|
630 if( aMediaType == EMediaRemote ) |
|
631 { |
|
632 isIncludedMedia = ETrue; |
|
633 } |
|
634 } |
|
635 _LOG1( "[CFDUtility] isIncludedMedia=%d", isIncludedMedia ); |
|
636 return isIncludedMedia; |
|
637 } |
|
638 |
|
639 |
|
640 // --------------------------------------------------------------------------- |
|
641 // AknCFDUtility::EffectiveDriveCountL |
|
642 // --------------------------------------------------------------------------- |
|
643 // |
|
644 TInt AknCFDUtility::EffectiveDriveCountL() |
|
645 { |
|
646 // Great! So any drive will be counted except Z: and D: (hey it's simple!) |
|
647 // which should not be visible to user in any case. Or should they be: |
|
648 // are these just RAM and ROM in S60, not in any Symbian specification??? |
|
649 // Naturally, C: and E: are also constants extending the Symbian |
|
650 // specification. |
|
651 // So... Count the drives essential and visible to the user. But if the |
|
652 // drive media is not present or it is locked? |
|
653 // |
|
654 // Check if there are more than one effective drives. |
|
655 |
|
656 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
657 TDriveList driveList; |
|
658 |
|
659 // Use new Symbian function to get all drives by using filter flags. |
|
660 TInt error = fs.DriveList( driveList, KDriveAttExclude | KDriveAttRom ); |
|
661 if( error ) |
|
662 { |
|
663 return KErrGeneral; |
|
664 } |
|
665 |
|
666 TInt effectiveDriveCount = 0; |
|
667 TCFDDriveStatus driveInfo; |
|
668 for( TInt i = 0; i < KMaxDrives; i++ ) |
|
669 { |
|
670 if( driveList[i] && i != EDriveD && i != EDriveZ ) |
|
671 { |
|
672 driveInfo = EDriveNotReady ; |
|
673 driveInfo = AknCFDUtility::DriveStatusL( TDriveNumber( i ) ); |
|
674 // count only if it is available |
|
675 if (driveInfo != EDriveNotReady) |
|
676 { |
|
677 effectiveDriveCount++; |
|
678 } |
|
679 } |
|
680 } |
|
681 |
|
682 return effectiveDriveCount; |
|
683 } |
|
684 |
|
685 // --------------------------------------------------------------------------- |
|
686 // AknCFDUtility::IsRemoteDrive |
|
687 // --------------------------------------------------------------------------- |
|
688 // |
|
689 TBool AknCFDUtility::IsRemoteDrive( const TDesC& aDrive ) |
|
690 { |
|
691 TBool ret( EFalse ); |
|
692 TDriveInfo drvInfo; |
|
693 TDriveUnit driveUnit( aDrive); |
|
694 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
695 |
|
696 if ( fs.Drive( drvInfo, TInt( driveUnit) ) == KErrNone ) |
|
697 { |
|
698 if ( drvInfo.iDriveAtt & KDriveAttRemote ) |
|
699 { |
|
700 ret = ETrue; |
|
701 } |
|
702 } |
|
703 return ret; |
|
704 } |
|
705 |
|
706 |
|
707 // --------------------------------------------------------------------------- |
|
708 // AknCFDUtility::DriveMemoryTypeL |
|
709 // --------------------------------------------------------------------------- |
|
710 // |
|
711 AknCommonDialogsDynMem::TMemoryTypes |
|
712 AknCFDUtility::DriveMemoryTypeL( const TDriveNumber& aDrive ) |
|
713 { |
|
714 // Set default value to device memory just in case. |
|
715 AknCommonDialogsDynMem::TMemoryTypes |
|
716 memoryType( AknCommonDialogsDynMem::EMemoryTypePhone ); |
|
717 |
|
718 TCFDDriveInfo driveInfo; |
|
719 AknCFDUtility::DriveInfoL( aDrive , driveInfo ); |
|
720 |
|
721 // Listbox items are differend depending on the media type. |
|
722 if ( driveInfo.iStatus & DriveInfo::EDriveInternal ) |
|
723 { |
|
724 // Internal drives including device memory and internal mass storage |
|
725 if ( driveInfo.iStatus & DriveInfo::EDriveExternallyMountable ) |
|
726 { |
|
727 // Internal mass storage drive |
|
728 memoryType = |
|
729 AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage; |
|
730 } |
|
731 else |
|
732 { |
|
733 // Device memory drive |
|
734 memoryType = AknCommonDialogsDynMem::EMemoryTypePhone; |
|
735 } |
|
736 } |
|
737 else if( driveInfo.iStatus & DriveInfo::EDriveRemovable ) |
|
738 { |
|
739 // External MMC |
|
740 memoryType = AknCommonDialogsDynMem::EMemoryTypeMMCExternal; |
|
741 } |
|
742 else if ( ( driveInfo.iStatus & DriveInfo::EDriveRemote ) |
|
743 && ( driveInfo.iMediaType == EMediaRemote ) ) |
|
744 // 2 conditions used here just for sure |
|
745 { |
|
746 // Remote drive |
|
747 memoryType = AknCommonDialogsDynMem::EMemoryTypeRemote; |
|
748 } |
|
749 return memoryType; |
|
750 } |
|
751 |
|
752 |
|
753 // --------------------------------------------------------------------------- |
|
754 // AknCFDUtility::SetSecondRowTextL |
|
755 // --------------------------------------------------------------------------- |
|
756 // |
|
757 void AknCFDUtility::SetSecondRowTextL( TInt64 aFreeSpace, TDes& aUnitBuf ) |
|
758 { |
|
759 _LIT( KTempString0, "0U" ); //For find "Free: %0U[05] %1U" |
|
760 _LIT( KTempString1, "1U" ); //For find "Free: %0U[05] %1U" |
|
761 _LIT( KDefinedString, "qtn_memc_free_memory_var_units_dot" ); |
|
762 TReal64 tempNum = aFreeSpace; |
|
763 HBufC* unitBuf = NULL; |
|
764 HBufC* loadBuf = NULL; |
|
765 HBufC* tempBuf1 = HBufC::NewLC( KListBoxEntryMaxLength ); |
|
766 HBufC* tempBuf2 = HBufC::NewLC( KListBoxEntryMaxLength ); |
|
767 HBufC* hBuf = HBufC::NewLC( KListBoxEntryMaxLength ); |
|
768 TPtr tempBufPtr1( tempBuf1->Des() ); |
|
769 TPtr tempBufPtr2( tempBuf2->Des() ); |
|
770 TPtr hBufPtr( hBuf->Des() ); |
|
771 if (( aFreeSpace >= 0 ) && ( aFreeSpace < KHundredNum )) |
|
772 { |
|
773 unitBuf = StringLoader::LoadLC( |
|
774 R_CFD_QTN_MEMC_UNITS_BYTE, |
|
775 CCoeEnv::Static()); |
|
776 TPtr unitString = unitBuf->Des(); |
|
777 loadBuf = StringLoader::LoadLC( |
|
778 R_CFD_QTN_MEMC_FREE_MEMORY_VAR_UNITS, |
|
779 CCoeEnv::Static()); |
|
780 StringLoader::Format( |
|
781 tempBufPtr1, |
|
782 *loadBuf, |
|
783 KNoIndex, |
|
784 tempNum |
|
785 ); |
|
786 StringLoader::Format( |
|
787 aUnitBuf, |
|
788 tempBufPtr1, |
|
789 KNoIndex, |
|
790 unitString |
|
791 ); |
|
792 } |
|
793 else |
|
794 { |
|
795 |
|
796 if (( aFreeSpace >= KHundredNum ) && ( aFreeSpace < KMegaNum )) |
|
797 { |
|
798 tempNum /= KThousandNum; // Divide to kilobytes |
|
799 tempNum = TReal32( TInt( tempNum * 10 ) ) / 10; |
|
800 unitBuf = StringLoader::LoadLC( |
|
801 R_CFD_QTN_MEMC_UNITS_KILOBYTE, |
|
802 CCoeEnv::Static()); |
|
803 } |
|
804 else if (( aFreeSpace >= KMegaNum ) && ( aFreeSpace < KGigaNum )) |
|
805 { |
|
806 tempNum /= KMegaNum; // Divide to Megabytes |
|
807 tempNum = TReal32( TInt( tempNum * 10 ) ) / 10; |
|
808 unitBuf = StringLoader::LoadLC( |
|
809 R_CFD_QTN_MEMC_UNITS_MEGABYTE, |
|
810 CCoeEnv::Static()); |
|
811 } |
|
812 else if (aFreeSpace >= KGigaNum ) |
|
813 { |
|
814 tempNum /= KGigaNum; // Divide to Gigabytes |
|
815 tempNum = TReal32( TInt( tempNum * 10 ) ) / 10; |
|
816 unitBuf = StringLoader::LoadLC( |
|
817 R_CFD_QTN_MEMC_UNITS_GIGABYTE, |
|
818 CCoeEnv::Static()); |
|
819 } |
|
820 |
|
821 if ( !unitBuf ) |
|
822 { |
|
823 User::Leave( KErrArgument ); |
|
824 } |
|
825 |
|
826 |
|
827 loadBuf = StringLoader::LoadLC( |
|
828 R_CFD_QTN_MEMC_FREE_MEMORY_VAR_UNITS_DOT, |
|
829 CCoeEnv::Static()); |
|
830 |
|
831 if( loadBuf && |
|
832 ( loadBuf->Des().Find( KTempString0 ) == KErrNotFound || |
|
833 loadBuf->Des().Find( KTempString1 ) == KErrNotFound ) ) |
|
834 { |
|
835 aUnitBuf.Copy( KDefinedString ); |
|
836 } |
|
837 else |
|
838 { |
|
839 // Change string formate. |
|
840 TBuf<KFreeLen> buf; |
|
841 buf.Format(KFreeFormate, tempNum); |
|
842 StringLoader::Format( tempBufPtr1, *loadBuf, 0, buf ); |
|
843 |
|
844 TPtr unitString = unitBuf->Des(); |
|
845 StringLoader::Format( tempBufPtr2, *tempBuf1, 1, unitString ); |
|
846 aUnitBuf.Format( tempBufPtr2, tempNum ); |
|
847 } |
|
848 |
|
849 } |
|
850 |
|
851 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( aUnitBuf ); // Localize digits |
|
852 |
|
853 CleanupStack::PopAndDestroy( loadBuf ); |
|
854 CleanupStack::PopAndDestroy( unitBuf ); |
|
855 CleanupStack::PopAndDestroy( hBuf ); |
|
856 CleanupStack::PopAndDestroy( tempBuf2 ); |
|
857 CleanupStack::PopAndDestroy( tempBuf1 ); |
|
858 |
|
859 } |
|
860 |
|
861 // --------------------------------------------------------------------------- |
|
862 // AknCFDUtility::UserVisibleDriveCountL |
|
863 // --------------------------------------------------------------------------- |
|
864 // |
|
865 TInt AknCFDUtility::UserVisibleDriveCountL( TInt aIncludedMedias ) |
|
866 { |
|
867 TInt visibleDriveCount = 0; |
|
868 |
|
869 TInt driveCount = 0; |
|
870 TDriveList driveList; |
|
871 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
872 |
|
873 User::LeaveIfError( DriveInfo::GetUserVisibleDrives( |
|
874 fs, driveList, driveCount, KDriveAttAll ) ); |
|
875 |
|
876 if ( driveCount > 0 ) |
|
877 { |
|
878 // Convert EMemoryTypeMMC to EMemoryTypeInternalMassStorage & |
|
879 // EMemoryTypeMMCExternal if include. |
|
880 if( aIncludedMedias & AknCommonDialogsDynMem::EMemoryTypeMMC ) |
|
881 { |
|
882 aIncludedMedias = aIncludedMedias | |
|
883 AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage |
|
884 | AknCommonDialogsDynMem::EMemoryTypeMMCExternal; |
|
885 aIncludedMedias &= ( ~AknCommonDialogsDynMem::EMemoryTypeMMC ); |
|
886 } |
|
887 |
|
888 TDriveNumber driveNumber; |
|
889 AknCommonDialogsDynMem::TMemoryTypes memoryType; |
|
890 TCFDDriveStatus driveStatus; |
|
891 for( TInt i = 0; i < KMaxDrives; i++ ) |
|
892 { |
|
893 if( driveList[i] ) |
|
894 { |
|
895 driveNumber = TDriveNumber( i ); |
|
896 memoryType = DriveMemoryTypeL( driveNumber ); |
|
897 if( memoryType & aIncludedMedias ) |
|
898 { |
|
899 driveStatus = EDriveNotReady ; |
|
900 driveStatus = AknCFDUtility::DriveStatusL( driveNumber ); |
|
901 // count only if it is available |
|
902 if( driveStatus != EDriveNotReady ) |
|
903 { |
|
904 visibleDriveCount++; |
|
905 } |
|
906 } |
|
907 } |
|
908 } |
|
909 } |
|
910 |
|
911 return visibleDriveCount; |
|
912 } |
|
913 |
|
914 // End of File |
|
915 |