webengine/widgetregistry/Server/src/WidgetMMCHandler.cpp
branchRCL_3
changeset 49 919f36ff910f
equal deleted inserted replaced
48:79859ed3eea9 49:919f36ff910f
       
     1 /*
       
     2 * Copyright (c) 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 the License "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:  Manages list of widget entries.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "WidgetMMCHandler.h"
       
    20 #include "WidgetRegistry.h"
       
    21 
       
    22 // CONSTANTS
       
    23 LOG_NAMES( "widreg", "widrmmc.txt" )
       
    24 
       
    25 // ============================================================================
       
    26 // CWidgetMMCHandler::NewL()
       
    27 // two-phase constructor
       
    28 //
       
    29 // @since 3.1
       
    30 // @param aRegistry - Widget registry for callback.
       
    31 // @param aFs - file session
       
    32 // @return pointer to CWidgetMMCHandler
       
    33 // ============================================================================
       
    34 //
       
    35 CWidgetMMCHandler* CWidgetMMCHandler::NewL(
       
    36     CWidgetRegistry& aRegistry,
       
    37     RFs& aFs )
       
    38     {
       
    39     CWidgetMMCHandler* self =
       
    40         new(ELeave) CWidgetMMCHandler( aRegistry , aFs );
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ============================================================================
       
    48 // CWidgetMMCHandler::CWidgetMMCHandler()
       
    49 // C++ default constructor
       
    50 //
       
    51 // @since 3.1
       
    52 // ============================================================================
       
    53 //
       
    54 CWidgetMMCHandler::CWidgetMMCHandler( CWidgetRegistry& aRegistry,
       
    55                                       RFs& aFs )
       
    56     : CActive( CActive::EPriorityStandard ),
       
    57       iRegistry( &aRegistry ),
       
    58       iFs( aFs ),
       
    59       iDriveFlags( 0 )
       
    60     {
       
    61     CActiveScheduler::Add( this );
       
    62     }
       
    63 
       
    64 // ============================================================================
       
    65 // CWidgetMMCHandler::ConstructL()
       
    66 // Symbian default constructor
       
    67 //
       
    68 // @since 3.1
       
    69 // ============================================================================
       
    70 //
       
    71 void CWidgetMMCHandler::ConstructL()
       
    72     {
       
    73     LOG_CONSTRUCTL;
       
    74     if ( KErrNone != ScanDrives( iDriveFlags ) )
       
    75         {
       
    76         iDriveFlags = 0;
       
    77         }
       
    78     iDeltaDriveFlags = 0;
       
    79     iApaAppListNotifier = CApaAppListNotifier::NewL(this,CActive::EPriorityStandard);
       
    80     }
       
    81 
       
    82 // ============================================================================
       
    83 // CWidgetMMCHandler::~CWidgetMMCHandler()
       
    84 // destructor
       
    85 //
       
    86 // @since 3.1
       
    87 // ============================================================================
       
    88 CWidgetMMCHandler::~CWidgetMMCHandler()
       
    89     {
       
    90     Cancel();
       
    91     LOG_DESTRUCT;
       
    92     }
       
    93 
       
    94 // ============================================================================
       
    95 // CWidgetMMCHandler::Start()
       
    96 // Start monitoring.
       
    97 //
       
    98 // @since 5.0
       
    99 // ============================================================================
       
   100 void CWidgetMMCHandler::Start()
       
   101     {
       
   102     iFs.NotifyChange( ENotifyDisk, iStatus );
       
   103     SetActive();
       
   104     }
       
   105 
       
   106 // ============================================================================
       
   107 // CWidgetMMCHandler::RunL()
       
   108 // Handle notifications of MMC events.
       
   109 //
       
   110 // @since 3.1
       
   111 // ============================================================================
       
   112 void CWidgetMMCHandler::RunL()
       
   113     {
       
   114     LOG_OPEN;
       
   115     LOG1( "MMC notification status %d", iStatus.Int() );
       
   116 
       
   117 	  TInt status = iStatus.Int();
       
   118 	
       
   119 	  // Request the notification before scanning
       
   120 	  iFs.NotifyChange( ENotifyDisk, iStatus );
       
   121     SetActive();
       
   122     
       
   123     if ( status == KErrNone )
       
   124       {
       
   125         TInt driveFlags = 0;
       
   126         TInt deltaDriveFlags = 0;
       
   127         if ( KErrNone == ScanDrives( driveFlags ) )
       
   128           {
       
   129             LOG1( " iDriveFlags 0x%x", iDriveFlags );
       
   130             LOG1( "  driveFlags 0x%x", driveFlags );
       
   131             deltaDriveFlags = iDriveFlags ^ driveFlags;
       
   132             iDeltaDriveFlags |= deltaDriveFlags;
       
   133             LOG1( " deltaDriveFlags 0x%x", deltaDriveFlags );
       
   134             iDriveFlags = driveFlags;
       
   135           }
       
   136       }
       
   137     LOG( "MMC notification done" );
       
   138     LOG_CLOSE;
       
   139     }
       
   140 
       
   141 // ============================================================================
       
   142 // CWidgetMMCHandler::RunError()
       
   143 // Ignore errors from RunL.
       
   144 //
       
   145 // @since 5.0
       
   146 // ============================================================================
       
   147 TInt CWidgetMMCHandler::RunError( TInt /* aError */ )
       
   148     {
       
   149     LOG_CLOSE;
       
   150     return KErrNone; // indicates error was handled
       
   151     }
       
   152 
       
   153 // ============================================================================
       
   154 // CWidgetMMCHandler::DoCancel()
       
   155 // Cancel the MMC event handler
       
   156 //
       
   157 // @since 3.1
       
   158 // ============================================================================
       
   159 void CWidgetMMCHandler::DoCancel()
       
   160     {
       
   161     LOG_CLOSE;
       
   162     iFs.NotifyChangeCancel();
       
   163     }
       
   164 
       
   165 /* Scans drives and records a bit flag for those that exist and are
       
   166  * suitable for installing widgets to.
       
   167  */
       
   168 TInt CWidgetMMCHandler::ScanDrives( TInt& aDriveFlags )
       
   169     {
       
   170     LOG_OPEN;
       
   171     LOG( "ScanDrives" );
       
   172     // List all drives in the system
       
   173     TDriveList driveList;
       
   174     TInt error = iFs.DriveList( driveList );
       
   175     if ( KErrNone == error )
       
   176         {
       
   177         for ( TInt driveNumber = EDriveY;
       
   178               driveNumber >= EDriveA;
       
   179               driveNumber-- )
       
   180             {
       
   181             // The drives that will be filtered out are the same ones that
       
   182             // WidgetInstaller filters out in CWidgetUIHandler::SelectDriveL()
       
   183             if ( (EDriveD == driveNumber)
       
   184                  || !driveList[driveNumber] )
       
   185                 {
       
   186                 // EDriveD is a temporary drive usually a RAM disk
       
   187                 continue;
       
   188                 }
       
   189 
       
   190             TVolumeInfo volInfo;
       
   191             if ( iFs.Volume( volInfo, driveNumber ) != KErrNone )
       
   192                 {
       
   193                 // volume is not usable (e.g. no media card inserted)
       
   194                 continue;
       
   195                 }
       
   196             if ( (volInfo.iDrive.iType == EMediaNotPresent) ||
       
   197                  (volInfo.iDrive.iType == EMediaRom) ||
       
   198                  (volInfo.iDrive.iType == EMediaRemote) ||
       
   199                  (volInfo.iDrive.iDriveAtt & KDriveAttRom) ||
       
   200                  (volInfo.iDrive.iDriveAtt & KDriveAttSubsted) )
       
   201                 {
       
   202                 // not a suitable widget install drive
       
   203                 continue;
       
   204                 }
       
   205 
       
   206             // found a usable drive
       
   207             aDriveFlags |= (1 << driveNumber);
       
   208             LOG2( " drive %d, flags 0x%x", driveNumber, aDriveFlags );
       
   209             }
       
   210         }
       
   211     LOG1( "ScanDrives done, error %d", error );
       
   212     LOG_CLOSE;
       
   213     return error;
       
   214     }
       
   215 
       
   216 void CWidgetMMCHandler::HandleAppListEvent(TInt aEvent)
       
   217     {
       
   218     TBool dirtyFlag = EFalse;
       
   219     TInt parseError = KErrNone;
       
   220     
       
   221     if ( iDeltaDriveFlags )
       
   222         {
       
   223         // Assume usual case and things are consistent
       
   224         // and the registry entry file can be parsed and used.
       
   225         TRAPD( error, iRegistry->InternalizeL( ETrue,
       
   226                                     ETrue,
       
   227                                     dirtyFlag,
       
   228                                     parseError ) );
       
   229         if ( KErrNone == error )
       
   230             {
       
   231             // internalize consistency enforcement may have altered registry
       
   232             if ( dirtyFlag )
       
   233                 {
       
   234                 TRAP_IGNORE( iRegistry->ExternalizeL(); );
       
   235                 }
       
   236             }
       
   237         iDeltaDriveFlags = 0;
       
   238         
       
   239         CWidgetRegistry::NotifyWidgetAltered();
       
   240         }
       
   241     }