skins/AknSkins/srvsrc/AknsDriveMaster.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Handles disk drive information
       
    15 *
       
    16 */
       
    17 
       
    18 #include "AknsDriveMaster.h"
       
    19 #include "AknsDebug.h"
       
    20 
       
    21 // Double colon character
       
    22 _LIT( KAknsSrvDoubleColon, ":" );
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // Appends drive letter and double colon to a descriptor.
       
    26 // Path should be zero length when calling this method.
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 void AppendDriveLetterToDes( const TInt aDrive, TDes& aPath )
       
    30     {
       
    31     TChar driveLetter;
       
    32     RFs::DriveToChar( aDrive, driveLetter );
       
    33     aPath.Append( driveLetter );
       
    34     aPath.Append( KAknsSrvDoubleColon );
       
    35     }
       
    36 
       
    37 // ======== MEMBER FUNCTIONS ========
       
    38 // ---------------------------------------------------------------------------
       
    39 // CAknsSrvDriveMaster::NewL
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CAknsSrvDriveMaster* CAknsSrvDriveMaster::NewL( MAknsSrvDriveObserver* aObserver )
       
    43     {
       
    44     AKNS_TRACE_INFO("CAknsSrvDriveMaster::NewL");
       
    45     CAknsSrvDriveMaster* self = new( ELeave ) CAknsSrvDriveMaster( aObserver );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Destructor
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CAknsSrvDriveMaster::~CAknsSrvDriveMaster()
       
    57     {
       
    58     AKNS_TRACE_INFO("CAknsSrvDriveMaster destructor");
       
    59     iStaticDriveArray.Reset();
       
    60     iStaticDriveArray.Close();
       
    61 
       
    62     iRemovableDriveArray.Reset();
       
    63     iRemovableDriveArray.Close();
       
    64 
       
    65     delete iDiskNotifier;
       
    66     iFsSession.Close();
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // Finds and appends skin server's private ROM-drive directory to a string.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CAknsSrvDriveMaster::DefaultSkinDirectoryOnRom( TDes& aPath )
       
    74     {
       
    75     AKNS_TRACE_INFO("CAknsSrvDriveMaster::DefaultSkinDirectoryOnRom");
       
    76     aPath.Zero();
       
    77     TInt drive = KErrNotFound;
       
    78     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, drive );
       
    79     AppendDriveLetterToDes( drive, aPath );
       
    80     if ( aPath.Length() )
       
    81         {
       
    82         aPath.Append( KAknSkinSrvPrivateSkinPath );
       
    83         }
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // Finds and appends skin server's private mass memory drive directory to a string.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CAknsSrvDriveMaster::DefaultSkinDirectoryOnMemoryCard( TDes& aPath )
       
    91     {
       
    92     AKNS_TRACE_INFO("CAknsSrvDriveMaster::DefaultSkinDirectoryOnMemoryCard");
       
    93     aPath.Zero();
       
    94     TInt drive = KErrNotFound;
       
    95     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
       
    96     AppendDriveLetterToDes( drive, aPath );
       
    97     if ( aPath.Length() )
       
    98         {
       
    99         aPath.Append( KAknSkinSrvPrivateSkinPath );
       
   100         }
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // Finds and appends skin server's private device drive directory to a string.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CAknsSrvDriveMaster::DefaultSkinDirectoryOnDevice( TDes& aPath )
       
   108     {
       
   109     AKNS_TRACE_INFO("CAknsSrvDriveMaster::DefaultSkinDirectoryOnDevice");
       
   110     aPath.Zero();
       
   111     TInt drive = KErrNotFound;
       
   112     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, drive );
       
   113     AppendDriveLetterToDes( drive, aPath );
       
   114     if ( aPath.Length() )
       
   115         {
       
   116         aPath.Append( KAknSkinSrvPrivateSkinPath );
       
   117         }
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // Gets default drive for the drive type.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CAknsSrvDriveMaster::GetDefaultDrive( const TInt& aDriveType, TDes& aDrive )
       
   125     {
       
   126     AKNS_TRACE_INFO("CAknsSrvDriveMaster::GetDefaultDrive");
       
   127     TFileName path;
       
   128     TInt drive = EDriveC;
       
   129     TInt err = DriveInfo::GetDefaultDrive( aDriveType, drive );
       
   130     if ( err == KErrNone )
       
   131         {
       
   132         AppendDriveLetterToDes( drive, aDrive );
       
   133         }
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // Checks if given drive is removable.
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 TBool CAknsSrvDriveMaster::IsRemovableDrive( RFs& aFileSession, const TDesC& aDrive )
       
   141     {
       
   142     AKNS_TRACE_INFO("CAknsSrvDriveMaster::IsRemovableDrive");
       
   143     TInt drive = EDriveC;
       
   144     RFs::CharToDrive( aDrive[0], drive );
       
   145     return CAknsSrvDriveMaster::IsRemovableDrive( aFileSession, drive );
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // Checks if given drive is removable.
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TBool CAknsSrvDriveMaster::IsRemovableDrive( RFs& aFileSession, const TInt aDrive )
       
   153     {
       
   154     AKNS_TRACE_INFO("CAknsSrvDriveMaster::IsRemovableDrive 2");
       
   155     TUint driveStatus = 0;
       
   156     TBool retVal = EFalse;
       
   157     TInt err = DriveInfo::GetDriveStatus( aFileSession, aDrive, driveStatus );
       
   158     if ( driveStatus & DriveInfo::EDriveExternallyMountable )
       
   159         {
       
   160         retVal = ETrue;
       
   161         }
       
   162     return retVal;
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // Returns number of drives in the device.
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 TInt CAknsSrvDriveMaster::GetNumberOfDrives( TAknsSrvSkinDriveList aDriveType ) const
       
   170     {
       
   171     AKNS_TRACE_INFO("CAknsSrvDriveMaster::GetNumberOfDrives");
       
   172     TInt drives = 0;
       
   173     if ( aDriveType == EAknsSrvStaticDrive )
       
   174         {
       
   175         drives = iStaticDriveArray.Count();
       
   176         AKNS_TRACE_INFO1("CAknsSrvDriveMaster::GetNumberOfDrives - static drives=%d", drives );
       
   177         }
       
   178     else if ( aDriveType == EAknsSrvRemovableDrive )
       
   179         {
       
   180         drives = iRemovableDriveArray.Count();
       
   181         AKNS_TRACE_INFO1("CAknsSrvDriveMaster::GetNumberOfDrives - removable drives=%d", drives );
       
   182         }
       
   183     else if ( aDriveType == EAknsSrvAnyDrive )
       
   184         {
       
   185         drives = iRemovableDriveArray.Count() + iStaticDriveArray.Count();
       
   186         AKNS_TRACE_INFO1("CAknsSrvDriveMaster::GetNumberOfDrives - all drives=%d", drives );
       
   187         }
       
   188     return drives;
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // Gets skin directory as descriptor based on drive type and array loc.
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CAknsSrvDriveMaster::SkinDirectoryOnDrive(
       
   196         TAknsSrvSkinDriveList aDriveType,
       
   197         TInt aLocation,
       
   198         TDes& aPath ) const
       
   199     {
       
   200     AKNS_TRACE_INFO("CAknsSrvDriveMaster::SkinDirectoryOnDrive");
       
   201     TInt driveNumber = KErrNotFound;
       
   202     aPath.Zero();
       
   203     if ( aDriveType == EAknsSrvStaticDrive )
       
   204         {
       
   205         if ( iStaticDriveArray.Count() == 0 )
       
   206             {
       
   207             return;
       
   208             }
       
   209         if ( aLocation >= 0 && aLocation <= iStaticDriveArray.Count() )
       
   210             {
       
   211             driveNumber = iStaticDriveArray[ aLocation ];
       
   212             AppendDriveLetterToDes( driveNumber, aPath );
       
   213             aPath.Append( KAknSkinSrvPrivateSkinPath );
       
   214             }
       
   215         }
       
   216     else if ( aDriveType == EAknsSrvRemovableDrive )
       
   217         {
       
   218         if ( iRemovableDriveArray.Count() == 0 )
       
   219             {
       
   220             return;
       
   221             }
       
   222         if ( aLocation >= 0 && aLocation <= iRemovableDriveArray.Count() )
       
   223             {
       
   224             driveNumber = iRemovableDriveArray[ aLocation ];
       
   225             AppendDriveLetterToDes( driveNumber, aPath );
       
   226             aPath.Append( KAknSkinSrvPrivateSkinPath );
       
   227             }
       
   228         }
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // Handle disk drive notifications.
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CAknsSrvDriveMaster::HandleNotifyDisk(
       
   236         TInt /*aError*/,
       
   237         const TDiskEvent& aEvent )
       
   238     {
       
   239     switch ( aEvent.iType )
       
   240         {
       
   241         // Add drive to arrays.
       
   242         case MDiskNotifyHandlerCallback::EDiskAdded:
       
   243             {
       
   244             TUint driveStatus = KErrNone;
       
   245             DriveInfo::GetDriveStatus( iFsSession, aEvent.iDrive, driveStatus );
       
   246             if ( driveStatus & DriveInfo::EDriveRemote )
       
   247                 {
       
   248                 return;
       
   249                 }
       
   250             if ( ( driveStatus & DriveInfo::EDriveRemovable ) ||
       
   251                       ( driveStatus & DriveInfo::EDriveExternallyMountable ) )
       
   252                 {
       
   253                 iRemovableDriveArray.Append( aEvent.iDrive );
       
   254                 }
       
   255             else if ( driveStatus & DriveInfo::EDriveInternal )
       
   256                 {
       
   257                 iStaticDriveArray.Append( aEvent.iDrive );
       
   258                 }
       
   259             // AknsInstallObserver re-builds the skin list again automatically.
       
   260             break;
       
   261             }
       
   262         // Remove drive from arrays.
       
   263         case MDiskNotifyHandlerCallback::EDiskRemoved:
       
   264             if ( aEvent.iInfo.iDriveAtt & KDriveAttInternal )
       
   265                 {
       
   266                 TInt loc = iStaticDriveArray.Find( aEvent.iDrive );
       
   267                 if ( loc != KErrNotFound )
       
   268                     {
       
   269                     iStaticDriveArray.Remove( loc );
       
   270                     }
       
   271                 else
       
   272                     {
       
   273                     AKNS_TRACE_ERROR("CAknsSrvDriveMaster::HandleNotifyDisk unknown removable drive removed" );
       
   274                     }
       
   275                 }
       
   276             else
       
   277                 {
       
   278                 TInt loc = iRemovableDriveArray.Find( aEvent.iDrive );
       
   279                 if ( loc != KErrNotFound )
       
   280                     {
       
   281                     iRemovableDriveArray.Remove( loc );
       
   282                     }
       
   283                 else
       
   284                     {
       
   285                     AKNS_TRACE_ERROR("CAknsSrvDriveMaster::HandleNotifyDisk unknown static drive removed" );
       
   286                     }
       
   287                 }
       
   288             iObserver->NotifyDriveStatusChange( aEvent.iDrive, ETrue );
       
   289             break;
       
   290         case MDiskNotifyHandlerCallback::EDiskStatusChanged:
       
   291             {
       
   292             TBool diskRemoved = EFalse;
       
   293             if( !( aEvent.iInfo.iDriveAtt & KDriveAttInternal ) )
       
   294                 {
       
   295                 diskRemoved = ( aEvent.iInfo.iType == EMediaNotPresent );
       
   296                 }
       
   297             iObserver->NotifyDriveStatusChange( aEvent.iDrive, diskRemoved );
       
   298             }
       
   299             break;
       
   300         default:
       
   301             // Uninteresting event.
       
   302             break;
       
   303         }
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // C++ constructor.
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 CAknsSrvDriveMaster::CAknsSrvDriveMaster( MAknsSrvDriveObserver* aObserver ) :
       
   311     iObserver( aObserver )
       
   312     {
       
   313     // We need own RFs session, so that this works in line with install observer,
       
   314     TInt err = iFsSession.Connect();
       
   315     AKNS_TRACE_INFO1("CAknsSrv::New RFs connected, ret=%d", err);
       
   316 
       
   317     TFileName path;
       
   318     TInt drive = EDriveC;
       
   319     err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, drive );
       
   320     AKNS_TRACE_INFO2("CAknsSrv::New Default Device Drive, ret=%d drive=%d", err, drive );
       
   321     if ( err == KErrNone )
       
   322         {
       
   323         iStaticDriveArray.Append( drive );
       
   324         }
       
   325     err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
       
   326     AKNS_TRACE_INFO2("CAknsSrv::New Default Removable Drive, ret=%d drive=%d", err, drive );
       
   327     if ( err == KErrNone )
       
   328         {
       
   329         iRemovableDriveArray.Append( drive );
       
   330         }
       
   331     TDriveList driveList;
       
   332     TInt driveCount = 0;
       
   333     TUint driveStatus = 0;
       
   334     err = DriveInfo::GetUserVisibleDrives( iFsSession, driveList, driveCount );
       
   335     for ( TInt i = 0; i < KMaxDrives; i++ )
       
   336         {
       
   337         // If drive has been set and it is not the default, append it
       
   338         if ( driveList[i] != 0 &&
       
   339              ( i != iStaticDriveArray[0] &&
       
   340                i != iRemovableDriveArray[0] ) )
       
   341             {
       
   342             driveStatus = 0;
       
   343             err = DriveInfo::GetDriveStatus( iFsSession, i, driveStatus );
       
   344             AKNS_TRACE_INFO3("CAknsSrv::New Drive Found, ret=%d drive=%d status=%d", err, driveList[i], driveStatus );
       
   345             if ( driveStatus & DriveInfo::EDriveRemote ) 
       
   346                 {
       
   347                 driveCount--;
       
   348                 continue;
       
   349                 }
       
   350             if ( ( driveStatus & DriveInfo::EDriveRemovable ) ||
       
   351             			( driveStatus & DriveInfo::EDriveExternallyMountable ) )
       
   352                 {
       
   353                 AKNS_TRACE_INFO("CAknsSrv::New Removable Drive Added ");
       
   354                 iRemovableDriveArray.Append( i );
       
   355                 }
       
   356             else if ( driveStatus & DriveInfo::EDriveInternal )
       
   357                 {
       
   358                 AKNS_TRACE_INFO("CAknsSrv::New Static Drive Added ");
       
   359                 iStaticDriveArray.Append( i );
       
   360                 }
       
   361             driveCount--;
       
   362             }
       
   363 
       
   364         // Check if all drives have already been found.
       
   365         if ( !driveCount )
       
   366             {
       
   367             break;
       
   368             }
       
   369         }
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // 2nd phase constructor.
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CAknsSrvDriveMaster::ConstructL()
       
   377     {
       
   378     AKNS_TRACE_INFO("CAknsSrvDriveMaster::ConstructL");
       
   379     // Start listening for drive events.
       
   380     iDiskNotifier = CDiskNotifyHandler::NewL( *this, iFsSession );
       
   381     User::LeaveIfError( iDiskNotifier->NotifyDisk() );
       
   382     }
       
   383 
       
   384 // End of file