appinstaller/AppinstUi/Plugin/CommonUI/Src/CUIDriveUtils.cpp
changeset 0 ba25891c3a9e
child 25 7333d7932ef7
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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:   This file contains the implementation of CCUIDriveSelection
       
    15 *                class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <StringLoader.h>
       
    22 #include <pathinfo.h>
       
    23 #include <data_caging_path_literals.hrh>
       
    24 #include <SWInstCommonUI.rsg>
       
    25 #include <AknCommonDialogs.h>
       
    26 #include <CAknMemorySelectionDialog.h>
       
    27 #ifdef RD_MULTIPLE_DRIVE 
       
    28 #include <CAknMemorySelectionDialogMultiDrive.h>
       
    29 #include <AknCommonDialogsDynMem.h>
       
    30 #else
       
    31 #include <CAknMemorySelectionDialog.h>
       
    32 #endif //RD_MULTIPLE_DRIVE
       
    33 
       
    34 #include "CUIDriveUtils.h"
       
    35 
       
    36 
       
    37 using namespace SwiUI::CommonUI;
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCUIDriveUtils::CCUIDriveUtils
       
    43 // C++ default constructor can NOT contain any code, that
       
    44 // might leave.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CCUIDriveUtils::CCUIDriveUtils( TInt64 aSize,
       
    48                                 const RArray<TDriveUnit>& aDriveUnits, 
       
    49                                 const RArray<TInt64>& aDriveSpaces)
       
    50     : iSize( aSize ),
       
    51       iDriveUnits( aDriveUnits ),
       
    52       iDriveSpaces( aDriveSpaces ),
       
    53       iInternalArrayIndex( -1 ),
       
    54       iCardArrayIndex( -1 )
       
    55     {
       
    56   
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CCUIDriveUtils::ConstructL
       
    61 // Symbian 2nd phase constructor can leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CCUIDriveUtils::ConstructL()
       
    65     {
       
    66     #ifndef RD_MULTIPLE_DRIVE
       
    67     // Find the Phone and memory card drives from the drive array
       
    68     // and store the corresponding indexes, drive letters and free memories.
       
    69     TDriveUnit phoneMemUnit( TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive() );
       
    70     TDriveUnit mmcUnit( TParsePtrC( PathInfo::MemoryCardRootPath() ).Drive() );    
       
    71 
       
    72     for ( TInt index = 0; index < iDriveUnits.Count(); index++ )
       
    73         {        
       
    74         // Check if it's the phone memory
       
    75         if ( (TInt)phoneMemUnit == (TInt)iDriveUnits[index] )
       
    76             {
       
    77             iInternalArrayIndex = index;
       
    78             iInternalFreeMemory = iDriveSpaces[index];            
       
    79             }
       
    80         // Check if it's the memory card
       
    81         else if ( PathInfo::MemoryCardRootPath().Length() > 0 && 
       
    82                   (TInt)mmcUnit == (TInt)iDriveUnits[index] )
       
    83             {
       
    84             iCardArrayIndex = index;                
       
    85             iCardFreeMemory = iDriveSpaces[index];  
       
    86             }
       
    87         }
       
    88     #endif // RD_MULTIPLE_DRIVE   
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CCUIDriveUtils::NewL
       
    93 // Two-phased constructor.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CCUIDriveUtils* CCUIDriveUtils::NewL(
       
    97     TInt64 aSize,
       
    98     const RArray<TDriveUnit>& aDriveUnits, 
       
    99     const RArray<TInt64>& aDriveSpaces )
       
   100     {
       
   101     CCUIDriveUtils* self = 
       
   102         new ( ELeave ) CCUIDriveUtils( aSize, aDriveUnits, aDriveSpaces );
       
   103     CleanupStack::PushL( self );
       
   104     self->ConstructL();
       
   105     CleanupStack::Pop( self );
       
   106     return self; 
       
   107     }
       
   108 
       
   109 // Destructor
       
   110 CCUIDriveUtils::~CCUIDriveUtils()
       
   111     {
       
   112     
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CCUIDriveUtils::ShowSelectionDialogL
       
   117 // Set callback for the wait dialog.
       
   118 // (other items were commented in a header).
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 TBool CCUIDriveUtils::ShowSelectionDialogL( TInt& aSelectedDrive )
       
   122     {       
       
   123     TBool result( EFalse );
       
   124     
       
   125     aSelectedDrive = 0;    
       
   126 
       
   127 #ifdef RD_MULTIPLE_DRIVE           
       
   128     TBool externalDriveFound = EFalse;
       
   129     RFs fs;
       
   130     User::LeaveIfError( fs.Connect() );
       
   131     CleanupClosePushL( fs );
       
   132     
       
   133     // Find out if there is MMC among the available drives.
       
   134     for ( TInt index = 0; index < iDriveUnits.Count(); index++ )
       
   135         {         
       
   136         TDriveInfo info;
       
   137                               
       
   138         if ( KErrNone != fs.Drive( info, iDriveUnits[index] ) )
       
   139             {            
       
   140             // Ignore errors since the next drive might work.            
       
   141             continue;
       
   142             }
       
   143         // Note that this do not work in WINS env.
       
   144         if ( info.iDriveAtt & KDriveAttRemovable )
       
   145             {            
       
   146             externalDriveFound = ETrue;
       
   147             }                                  
       
   148         } 
       
   149    
       
   150 #ifdef __WINS__
       
   151     // Removable drives are not found in WINS env. 
       
   152     externalDriveFound = ETrue;    
       
   153 #endif //__WINS__    
       
   154    
       
   155     CleanupStack::PopAndDestroy( &fs );
       
   156     TInt supportedMemTypes = 0;
       
   157 
       
   158     // If memory card is available for Symbian SWI, show all drives.
       
   159     if ( externalDriveFound )
       
   160         {
       
   161         supportedMemTypes = AknCommonDialogsDynMem::EMemoryTypePhone|
       
   162                             AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage|
       
   163                             AknCommonDialogsDynMem::EMemoryTypeMMCExternal;                   
       
   164         }
       
   165     else
       
   166         {
       
   167          // MMC is not available for Symbian SWI. Note that user may have insert the MMC
       
   168          // but Symbian SWI has select available drives before that and we can not use
       
   169          // drvie which is not listed. 
       
   170          // Note also that if device has two MMC cards this fix do not really work.
       
   171          supportedMemTypes = AknCommonDialogsDynMem::EMemoryTypePhone|
       
   172                              AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage;   
       
   173         }
       
   174     
       
   175     CAknMemorySelectionDialogMultiDrive* memoryDialog = 
       
   176                                CAknMemorySelectionDialogMultiDrive::NewL(
       
   177                                                   	ECFDDialogTypeSave,
       
   178                                                     R_SWCOMMON_MEMORY_SELECTION_DIALOG,
       
   179                                                     EFalse,
       
   180                                                     supportedMemTypes );
       
   181                                                               
       
   182 #else
       
   183     // Use ECFDDialogTypeSave to have double list box in the query
       
   184     CAknMemorySelectionDialog* memoryDialog = CAknMemorySelectionDialog::NewL(
       
   185         ECFDDialogTypeSave,
       
   186         R_SWCOMMON_MEMORY_SELECTION_DIALOG,
       
   187         ETrue );
       
   188 #endif  //RD_MULTIPLE_DRIVE      
       
   189     CleanupStack::PushL( memoryDialog );    
       
   190         
       
   191     TInt size( (TInt) iSize / 1024 );
       
   192     if ( size == 0 )
       
   193         {
       
   194         size = 1;        
       
   195         }
       
   196     
       
   197     HBufC* header = StringLoader::LoadLC( R_SWCOMMON_MEMORY_HEADING, size );
       
   198     memoryDialog->SetTitleL( header->Des() );    
       
   199 
       
   200 #ifdef RD_MULTIPLE_DRIVE
       
   201     TDriveNumber driveNumber((TDriveNumber)KErrNotFound);    
       
   202     result = memoryDialog->ExecuteL( driveNumber, NULL, NULL );
       
   203         
       
   204     if ( result != CAknCommonDialogsBase::TReturnKey(CAknCommonDialogsBase::ERightSoftkey) )
       
   205         {
       
   206     	for ( TInt index = 0; index < iDriveUnits.Count(); index++ )
       
   207             {             
       
   208             if (driveNumber == iDriveUnits[index] )  
       
   209                {
       
   210                aSelectedDrive = index;                  
       
   211                break;	
       
   212                }
       
   213             }
       
   214         }
       
   215 #else    
       
   216     CAknMemorySelectionDialog::TMemory mem( CAknMemorySelectionDialog::EPhoneMemory );
       
   217     result = memoryDialog->ExecuteL( mem );
       
   218 
       
   219     if ( mem == CAknMemorySelectionDialog::EPhoneMemory )
       
   220         {
       
   221         // Phone memory selected
       
   222         aSelectedDrive = GetInternalDriveIndex();        
       
   223         }
       
   224     
       
   225     else
       
   226         {
       
   227         // Memory card selected
       
   228         aSelectedDrive = GetCardDriveIndex();        
       
   229         }    
       
   230 
       
   231 #endif  //RD_MULTIPLE_DRIVE  
       
   232     CleanupStack::PopAndDestroy( 2 ); // header, memoryDialog
       
   233  
       
   234     return result;    
       
   235     }    
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CCUIDriveUtils::IsInternalDrivePresent
       
   239 // Set callback for the wait dialog.
       
   240 // (other items were commented in a header).
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 TBool CCUIDriveUtils::IsInternalDrivePresent() const
       
   244     {
       
   245     TBool result( EFalse );
       
   246     
       
   247     if ( iInternalArrayIndex > -1 )
       
   248         {
       
   249         result = ETrue;        
       
   250         }
       
   251     return result;    
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CCUIDriveUtils::IsCardDrivePresent
       
   256 // Set callback for the wait dialog.
       
   257 // (other items were commented in a header).
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TBool CCUIDriveUtils::IsCardDrivePresent() const
       
   261     {    
       
   262     TBool result( EFalse );
       
   263     
       
   264     if ( iCardArrayIndex > -1 )
       
   265         {
       
   266         result = ETrue;        
       
   267         }
       
   268     return result;    
       
   269     }
       
   270   
       
   271 // -----------------------------------------------------------------------------
       
   272 // CCUIDriveUtils::GetInternalDriveSpace
       
   273 // Set callback for the wait dialog.
       
   274 // (other items were commented in a header).
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 TInt64 CCUIDriveUtils::GetInternalDriveSpace() const
       
   278     {
       
   279     return iInternalFreeMemory;    
       
   280     }
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CCUIDriveUtils::GetCardDriveSpace
       
   284 // Set callback for the wait dialog.
       
   285 // (other items were commented in a header).
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 TInt64 CCUIDriveUtils::GetCardDriveSpace() const
       
   289     {
       
   290     return iCardFreeMemory;    
       
   291     }
       
   292 
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CCUIDriveUtils::GetDriveSpace
       
   296 // Get the free space on drive.
       
   297 // (other items were commented in a header).
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 TInt64 CCUIDriveUtils::GetDriveSpace( TInt aIndex ) const
       
   301     {
       
   302     if ( aIndex == GetInternalDriveIndex() )
       
   303         {
       
   304         return GetInternalDriveSpace();        
       
   305         }    
       
   306     else
       
   307         {
       
   308         return GetCardDriveSpace();        
       
   309         }    
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CCUIDriveUtils::GetInternalDriveSpace
       
   314 // Set callback for the wait dialog.
       
   315 // (other items were commented in a header).
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 TInt CCUIDriveUtils::GetInternalDriveIndex() const
       
   319     {
       
   320     return iInternalArrayIndex;    
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CCUIDriveUtils::GetCardDriveSpace
       
   325 // Set callback for the wait dialog.
       
   326 // (other items were commented in a header).
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 TInt CCUIDriveUtils::GetCardDriveIndex() const
       
   330     {
       
   331     return iCardArrayIndex;    
       
   332     }
       
   333 
       
   334 //  End of File
       
   335