webengine/wrtharvester/src/wrtusbhandler.cpp
branchRCL_3
changeset 62 c711bdda59f4
parent 59 1f3c3f2f5b0a
child 64 ac77f89b1d9e
equal deleted inserted replaced
59:1f3c3f2f5b0a 62:c711bdda59f4
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "wrtusbhandler.h"
       
    20 #include "wrtharvester.h"
       
    21 #include "wrtusbhandler.h"
       
    22 #include <DriveInfo.h>
       
    23 
       
    24 // CONSTANTS
       
    25 
       
    26 
       
    27 // ============================================================================
       
    28 // CWrtUsbHandler::NewL()
       
    29 // two-phase constructor
       
    30 //
       
    31 // @since 3.1
       
    32 // @param aRegistry - Widget registry for callback.
       
    33 // @param aFs - file session
       
    34 // @return pointer to CWrtUsbHandler
       
    35 // ============================================================================
       
    36 //
       
    37 CWrtUsbHandler* CWrtUsbHandler::NewL(
       
    38     CWrtHarvester* aHarvester,
       
    39     RFs& aFs )
       
    40     {
       
    41     CWrtUsbHandler* self =
       
    42         new(ELeave) CWrtUsbHandler( aHarvester , aFs );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ============================================================================
       
    50 // CWrtUsbHandler::CWrtUsbHandler()
       
    51 // C++ default constructor
       
    52 //
       
    53 // @since 3.1
       
    54 // ============================================================================
       
    55 //
       
    56 CWrtUsbHandler::CWrtUsbHandler( CWrtHarvester* aHarvester,
       
    57                                       RFs& aFs )
       
    58     : CActive( CActive::EPriorityUserInput ),
       
    59       iHarvester( aHarvester ),
       
    60       iFs( aFs ),
       
    61       iDriveFlags( 0 )
       
    62     {
       
    63     CActiveScheduler::Add( this );
       
    64     }
       
    65 
       
    66 // ============================================================================
       
    67 // CWrtUsbHandler::ConstructL()
       
    68 // Symbian default constructor
       
    69 //
       
    70 // @since 3.1
       
    71 // ============================================================================
       
    72 //
       
    73 void CWrtUsbHandler::ConstructL()
       
    74     {
       
    75     if ( KErrNone != ScanDrives( iDriveFlags ) )
       
    76         {
       
    77         iDriveFlags = 0;
       
    78         }        
       
    79     }
       
    80 
       
    81 // ============================================================================
       
    82 // CWrtUsbHandler::~CWrtUsbHandler()
       
    83 // destructor
       
    84 //
       
    85 // @since 3.1
       
    86 // ============================================================================
       
    87 CWrtUsbHandler::~CWrtUsbHandler()
       
    88     {
       
    89     Cancel();
       
    90     }
       
    91 
       
    92 // ============================================================================
       
    93 // CWrtUsbHandler::Start()
       
    94 // Start monitoring.
       
    95 //
       
    96 // @since 5.0
       
    97 // ============================================================================
       
    98 void CWrtUsbHandler::Start()
       
    99     {
       
   100     iFs.NotifyChange( ENotifyDisk, iStatus );
       
   101     SetActive();
       
   102     }
       
   103 
       
   104 // ============================================================================
       
   105 // CWrtUsbHandler::RunL()
       
   106 // Handle notifications of MMC events.
       
   107 //
       
   108 // @since 3.1
       
   109 // ============================================================================
       
   110 void CWrtUsbHandler::RunL()
       
   111     {
       
   112     TInt status = iStatus.Int();
       
   113     
       
   114     // Restart NotifyChange
       
   115     Start();
       
   116     
       
   117     if ( status == KErrNone )
       
   118       {
       
   119       DoScanAndUpdate();
       
   120       }
       
   121     }
       
   122 
       
   123 void CWrtUsbHandler::DoScanAndUpdate()
       
   124     {
       
   125     TInt err = 0;
       
   126     TInt driveFlags = 0;
       
   127     TInt deltaDriveFlags = 0;
       
   128     if ( KErrNone == ScanDrives( driveFlags ) )
       
   129         {
       
   130         deltaDriveFlags = iDriveFlags ^ driveFlags;
       
   131         iDriveFlags = driveFlags;
       
   132         }
       
   133     
       
   134     if ( deltaDriveFlags )
       
   135         {
       
   136         TVolumeInfo volInfo;
       
   137         TInt temp = deltaDriveFlags;
       
   138         TBool massMemAltered = EFalse;        
       
   139         TBool massMemAvailable = EFalse;
       
   140         for(TInt DriveNo = EDriveA+1 ; DriveNo<=EDriveY; DriveNo++ )
       
   141             {   
       
   142             temp =  temp >> 1;
       
   143             if( temp & 01)
       
   144                 {
       
   145                 TUint status(0);
       
   146                 err = DriveInfo::GetDriveStatus( iFs, DriveNo , status );
       
   147                 if(!err && (status & DriveInfo::EDriveExternallyMountable) && (status & DriveInfo::EDriveInternal ))
       
   148                     {
       
   149                     //Internal Memory
       
   150                     massMemAltered = ETrue;                  
       
   151                     // Check is the internal memory available or not
       
   152                     if(iDriveFlags & (1<<DriveNo))
       
   153                       massMemAvailable = ETrue;
       
   154                     }                     
       
   155                 }            
       
   156             }
       
   157             if( massMemAltered )
       
   158               {
       
   159               if(!massMemAvailable)
       
   160                 {
       
   161                 // Mass storage is plugged
       
   162                 iHarvester->SetMSMode(1);
       
   163                 }
       
   164               else
       
   165                 {
       
   166                 // Mass storage was unplugged
       
   167                 if(iHarvester->IsInMSMode() == 1)
       
   168                   {
       
   169                   iHarvester->SetMSMode(0);	            
       
   170                   iHarvester->ClearAllOperations();                  
       
   171                   }
       
   172                 }
       
   173               }
       
   174         }
       
   175     }
       
   176 
       
   177 
       
   178 // ============================================================================
       
   179 // CWrtUsbHandler::RunError()
       
   180 // Ignore errors from RunL.
       
   181 //
       
   182 // @since 5.0
       
   183 // ============================================================================
       
   184 TInt CWrtUsbHandler::RunError( TInt /* aError */ )
       
   185     {
       
   186     return KErrNone; // indicates error was handled
       
   187     }
       
   188 
       
   189 // ============================================================================
       
   190 // CWrtUsbHandler::DoCancel()
       
   191 // Cancel the MMC event handler
       
   192 //
       
   193 // @since 3.1
       
   194 // ============================================================================
       
   195 void CWrtUsbHandler::DoCancel()
       
   196     {
       
   197     iFs.NotifyChangeCancel();
       
   198     }
       
   199 
       
   200 /* Scans drives and records a bit flag for those that exist and are
       
   201  * suitable for installing widgets to.
       
   202  */
       
   203 TInt CWrtUsbHandler::ScanDrives( TInt& aDriveFlags )
       
   204     {
       
   205     // List all drives in the system
       
   206     TDriveList driveList;
       
   207     TInt error = iFs.DriveList( driveList );
       
   208     if ( KErrNone == error )
       
   209         {
       
   210         for ( TInt driveNumber = EDriveY;
       
   211               driveNumber >= EDriveA;
       
   212               driveNumber-- )
       
   213             {
       
   214             // The drives that will be filtered out are the same ones that
       
   215             // WidgetInstaller filters out in CWidgetUIHandler::SelectDriveL()
       
   216             if ( (EDriveD == driveNumber)
       
   217                  || !driveList[driveNumber] )
       
   218                 {
       
   219                 // EDriveD is a temporary drive usually a RAM disk
       
   220                 continue;
       
   221                 }
       
   222 
       
   223             TVolumeInfo volInfo;
       
   224             if ( iFs.Volume( volInfo, driveNumber ) != KErrNone )
       
   225                 {
       
   226                 // volume is not usable (e.g. no media card inserted)
       
   227                 continue;
       
   228                 }
       
   229             if ( (volInfo.iDrive.iType == EMediaNotPresent) ||
       
   230                  (volInfo.iDrive.iType == EMediaRom) ||
       
   231                  (volInfo.iDrive.iType == EMediaRemote) ||
       
   232                  (volInfo.iDrive.iDriveAtt & KDriveAttRom) ||
       
   233                  (volInfo.iDrive.iDriveAtt & KDriveAttSubsted) )
       
   234                 {
       
   235                 // not a suitable widget install drive
       
   236                 continue;
       
   237                 }
       
   238 
       
   239             // found a usable drive
       
   240             aDriveFlags |= (1 << driveNumber);
       
   241           
       
   242             }
       
   243         }
       
   244 
       
   245     return error;
       
   246     }
       
   247