emailservices/emailserver/cmailhandlerplugin/src/cmaildriveobserver.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2000-2009 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: Drive observer implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <pathinfo.h>
       
    20 #include <f32file.h>
       
    21 #include "cmaildriveobserver.h"
       
    22 
       
    23 
       
    24 // ---------------------------------------------------------
       
    25 // CDriveWatcher::NewL
       
    26 // Second phase constructor
       
    27 // ---------------------------------------------------------
       
    28 //
       
    29 CDriveObserver* CDriveObserver::NewL( MDriveObserver& aDriveObserver )
       
    30 	{
       
    31 	CDriveObserver* self = CDriveObserver::NewLC(  aDriveObserver );
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 	
       
    36 // ---------------------------------------------------------
       
    37 // CDriveWatcher::NewLC
       
    38 // Second phase constructor
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 CDriveObserver* CDriveObserver::NewLC( MDriveObserver& aDriveObserver )
       
    42 	{
       
    43 	CDriveObserver* self = new(ELeave) CDriveObserver( aDriveObserver );
       
    44 	CleanupStack::PushL( self );
       
    45 	self->ConstructL();
       
    46 	return self;	
       
    47 	}
       
    48 	
       
    49 // ---------------------------------------------------------
       
    50 // CDriveWatcher::~CDriveWatcher
       
    51 // Destructor
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CDriveObserver::~CDriveObserver()
       
    55 	{	
       
    56 	
       
    57 	delete iDriveLetter;
       
    58 	Cancel();
       
    59 	
       
    60 	iFs.Close();
       
    61 	
       
    62 	}
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CDriveWatcher::CDriveWatcher
       
    66 // Default constructor
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 CDriveObserver::CDriveObserver( MDriveObserver& aDriveObserver )
       
    70 	: CActive( CActive::EPriorityStandard ), 
       
    71 	iDriveObserver( aDriveObserver )
       
    72 	{
       
    73 	}
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // CDriveWatcher::ConstructL
       
    77 // default Symbian OS constructor
       
    78 // ---------------------------------------------------------
       
    79 //
       
    80 void CDriveObserver::ConstructL()
       
    81 	{	
       
    82 	CActiveScheduler::Add(this);
       
    83 	User::LeaveIfError( iFs.Connect() );
       
    84 	}
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // CDriveWatcher::WaitForChangeL()
       
    89 // Request notification for disk change
       
    90 // ---------------------------------------------------------
       
    91 //	
       
    92 void CDriveObserver::WaitForChange()
       
    93 	{
       
    94 	if ( !IsActive() )
       
    95 	    {
       
    96 	    iFs.NotifyChange( ENotifyEntry, iStatus, *iDriveLetter );
       
    97 	    SetActive();
       
    98 	    }
       
    99 	}
       
   100 	
       
   101 // ---------------------------------------------------------
       
   102 // CDriveWatcher::MediaPresentL()
       
   103 // Call scanning if the memory card exists
       
   104 // ---------------------------------------------------------
       
   105 //	
       
   106 void CDriveObserver::MediaPresentL()
       
   107 	{
       
   108 	TVolumeInfo volumeInfo;
       
   109 	// Returns KErrNone, if drive exists
       
   110 	TInt err=iFs.Volume( volumeInfo, iDrive );
       
   111 	   
       
   112 	if ( err == KErrNone )
       
   113 		{
       
   114 		iDriveObserver.DriveStateChangedL( ETrue );
       
   115 		}
       
   116 	else
       
   117 	    {
       
   118         iDriveObserver.DriveStateChangedL( EFalse );
       
   119 	    }
       
   120 	}
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // Return true if drive is present and false otherwise.
       
   124  // ---------------------------------------------------------
       
   125  //
       
   126 TBool CDriveObserver::IsDrivePresent()
       
   127     {    
       
   128     TVolumeInfo volumeInfo;
       
   129     // Returns KErrNone, if drive exists
       
   130     TInt err=iFs.Volume( volumeInfo, iDrive );
       
   131     
       
   132     return ( KErrNone == err );    
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CDriveWatcher::DoCancel()
       
   137 // Derived from CActive, cancel request
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 void CDriveObserver::DoCancel()
       
   141 	{
       
   142 	iFs.NotifyChangeCancel();
       
   143 	}
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CDriveWatcher::RunL()
       
   147 // Derived from CActive, called when notification received
       
   148 // Check if media is present and call new notification request
       
   149 // ---------------------------------------------------------
       
   150 //	
       
   151 void CDriveObserver::RunL()
       
   152 	{	
       
   153 	if ( iStatus.Int() != KErrCancel )
       
   154 	    {	    
       
   155 	    WaitForChange();	   
       
   156 	    MediaPresentL();
       
   157 	    }
       
   158 	}
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // CDriveWatcher::RunError()
       
   162 // ---------------------------------------------------------
       
   163 //  
       
   164 
       
   165 TInt CDriveObserver::RunError(TInt /*aError*/)
       
   166     {
       
   167     return KErrNone;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CDriveObserver::SetDriveL()
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 void CDriveObserver::SetDriveL( TDriveNumber aDrive )
       
   175     {    
       
   176     if (iDrive == aDrive)
       
   177         {
       
   178         //if drives are the same don't need to do nothing
       
   179         return;
       
   180         }
       
   181     else if ( IsActive() )
       
   182         {
       
   183         //cancel request if drive to monitor changed
       
   184         Cancel();
       
   185         }
       
   186             
       
   187     const TUint KDriveBufSize = 2;
       
   188     
       
   189     iDrive = aDrive;
       
   190     
       
   191     TChar driveAsChar = 0;
       
   192     RFs::DriveToChar( iDrive, driveAsChar );
       
   193     
       
   194     delete iDriveLetter;
       
   195     iDriveLetter = NULL;
       
   196     iDriveLetter = HBufC::NewL( KDriveBufSize );
       
   197     
       
   198     iDriveLetter->Des().Append( driveAsChar );
       
   199     iDriveLetter->Des().Append(':');       
       
   200     }
       
   201 //EOF
       
   202