mediasettings/videoplayersettingsengine/src/videosettingsdrivemonitor.cpp
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2007 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 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "videosettingsdrivemonitor.h"
       
    23 #include "mvideosettingsdrivemonitorobserver.h"
       
    24 #include "tvideosettingsdrivemonitorevent.h"
       
    25 #include "tvideosettingsdriveinfo.h"
       
    26 
       
    27 #include <bldvariant.hrh>
       
    28 #ifdef RD_MULTIPLE_DRIVE_ENABLERS
       
    29 #include <driveinfo.h>
       
    30 #endif
       
    31 
       
    32 #include <centralrepository.h>
       
    33 #include "videoplayercenrepkeys.h"
       
    34 
       
    35 #include "mpxlog.h"
       
    36 
       
    37 // EXTERNAL DATA STRUCTURES
       
    38 
       
    39 // EXTERNAL FUNCTION PROTOTYPES  
       
    40 
       
    41 // CONSTANTS
       
    42 #if IPTV_LOGGING_METHOD != 0
       
    43 _LIT( KIptvMediaNotPresentDes, "EMediaNotPresent");
       
    44 _LIT( KIptvMediaUnknownDes, "EMediaUnknown");
       
    45 _LIT( KIptvMediaFloppyDes, "EMediaFloppy");
       
    46 _LIT( KIptvMediaHardDiskDes, "EMediaHardDisk");
       
    47 _LIT( KIptvMediaCdRomDes, "EMediaCdRom");
       
    48 _LIT( KIptvMediaRamDes, "EMediaRam");
       
    49 _LIT( KIptvMediaFlashDes, "EMediaFlash");
       
    50 _LIT( KIptvMediaRomDes, "EMediaRom");
       
    51 _LIT( KIptvMediaRemoteDes, "EMediaRemote");
       
    52 _LIT( KIptvMediaNANDFlashDes, "EMediaNANDFlash");
       
    53 #endif
       
    54 
       
    55 _LIT( KIptvEmptyDes, "" );
       
    56 
       
    57 // MACROS
       
    58 
       
    59 // LOCAL CONSTANTS AND MACROS
       
    60 
       
    61 // MODULE DATA STRUCTURES
       
    62 
       
    63 // LOCAL FUNCTION PROTOTYPES
       
    64 
       
    65 // FORWARD DECLARATIONS
       
    66 
       
    67 // ============================= LOCAL FUNCTIONS ===============================
       
    68 
       
    69 
       
    70 // ============================ MEMBER FUNCTIONS ===============================
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CVideoSettingsDriveMonitor::CVideoSettingsDriveMonitor
       
    74 // C++ default constructor can NOT contain any code, that
       
    75 // might leave.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CVideoSettingsDriveMonitor::CVideoSettingsDriveMonitor()
       
    79 : CActive( EPriorityStandard )
       
    80     {
       
    81     MPX_FUNC("CIptvDriveMonitor::CIptvDriveMonitor()");
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CIptvEvents::ConstructL
       
    86 // Symbian 2nd phase constructor can leave.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CVideoSettingsDriveMonitor::ConstructL( const RFs& aFileSession )
       
    90     {
       
    91     iFs                  = aFileSession;
       
    92     iIfsIsProvidedByUser = ETrue;
       
    93    
       
    94     ConstructL();    
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CIptvEvents::ConstructL
       
    99 // Symbian 2nd phase constructor can leave.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CVideoSettingsDriveMonitor::ConstructL()
       
   103     {
       
   104     iObservers.Reset();
       
   105     iAvailableDrives.Reset();
       
   106     iPreviousAvailableDrives.Reset();
       
   107     
       
   108     if ( !iIfsIsProvidedByUser )
       
   109         {
       
   110         User::LeaveIfError( iFs.Connect() );
       
   111         }
       
   112         
       
   113     CActiveScheduler::Add( this );
       
   114     RefreshAvailableDrivesL();
       
   115 
       
   116     MPX_DEBUG2("CIptvDriveMonitor:: PhoneMemoryDrive() returns %d",
       
   117         PhoneMemoryDrive());
       
   118     MPX_DEBUG2("CIptvDriveMonitor:: MemoryCardDrive() returns %d",
       
   119         MemoryCardDrive());
       
   120     MPX_DEBUG2("CIptvDriveMonitor:: MassStorageDrive() returns %d",
       
   121         MassStorageDrive());
       
   122     MPX_DEBUG2("CIptvDriveMonitor:: FixedDrive(c-drive excluded) returns %d",
       
   123         FixedDrive( ETrue ));
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CVideoSettingsDriveMonitor::NewL
       
   128 // Two-phased constructor.
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C CVideoSettingsDriveMonitor* CVideoSettingsDriveMonitor::NewL()
       
   132     {
       
   133     MPX_FUNC("CIptvDriveMonitor::NewL() start");
       
   134 
       
   135     CVideoSettingsDriveMonitor* self = new( ELeave ) CVideoSettingsDriveMonitor();
       
   136         
       
   137     CleanupStack::PushL( self );
       
   138     self->ConstructL();
       
   139     CleanupStack::Pop(self);
       
   140 
       
   141     return self;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CVideoSettingsDriveMonitor::NewL
       
   146 // Two-phased constructor.
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C CVideoSettingsDriveMonitor* CVideoSettingsDriveMonitor::NewL( const RFs& aFileSession )
       
   150     {
       
   151     MPX_FUNC("CIptvDriveMonitor::NewL(RFs&) start");
       
   152 
       
   153     CVideoSettingsDriveMonitor* self = new( ELeave ) CVideoSettingsDriveMonitor();
       
   154         
       
   155     CleanupStack::PushL( self );
       
   156     self->ConstructL( aFileSession );
       
   157     CleanupStack::Pop(self);
       
   158 
       
   159     return self;
       
   160     }
       
   161     
       
   162 // Destructor
       
   163 EXPORT_C CVideoSettingsDriveMonitor::~CVideoSettingsDriveMonitor()
       
   164     {
       
   165     iObservers.Close();
       
   166     iAvailableDrives.Close();
       
   167     iPreviousAvailableDrives.Close();
       
   168     Cancel();
       
   169     
       
   170     if ( !iIfsIsProvidedByUser )
       
   171         {
       
   172         iFs.Close();
       
   173         }
       
   174     }
       
   175 
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CVideoSettingsDriveMonitor::RegisterObserverL
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 EXPORT_C void CVideoSettingsDriveMonitor::RegisterObserverL( MIptvDriveMonitorObserver* aObserver )
       
   182     {
       
   183     iObservers.AppendL( aObserver );
       
   184 
       
   185     if ( !IsActive() )
       
   186         {
       
   187         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   188         SetActive();
       
   189         }
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CVideoSettingsDriveMonitor::RemoveObserverL
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 EXPORT_C void CVideoSettingsDriveMonitor::RemoveObserverL( MIptvDriveMonitorObserver* aObserver )
       
   197     {
       
   198     TInt i;
       
   199     for ( i = 0; i < iObservers.Count(); i++ )
       
   200         {
       
   201         if ( aObserver == iObservers[i] )
       
   202             {
       
   203             iObservers.Remove( i );
       
   204             iObservers.Compress();
       
   205             break;
       
   206             }
       
   207         }
       
   208         
       
   209     if ( iObservers.Count() == 0 )
       
   210         {
       
   211         iFs.NotifyChangeCancel();
       
   212         }    
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CVideoSettingsDriveMonitor::RefreshAvailableDrivesL
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 EXPORT_C void CVideoSettingsDriveMonitor::RefreshAvailableDrivesL()
       
   220     {
       
   221     MPX_FUNC("CIptvDriveMonitor::RefreshAvailableDrivesL() start");
       
   222     
       
   223     TDriveList driveList;
       
   224     User::LeaveIfError( iFs.DriveList( driveList ) );
       
   225 
       
   226     iPreviousAvailableDrives.Reset();
       
   227     TInt i;
       
   228     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   229         {
       
   230         iPreviousAvailableDrives.Append( iAvailableDrives[i] );
       
   231         }
       
   232             
       
   233     iAvailableDrives.Reset();
       
   234     
       
   235     for ( i = 0; i < driveList.Length(); i++ )
       
   236         {
       
   237         if ( driveList[i] != 0 && i != EDriveY ) // Some phones have a 1MB small flash drive at y-drive, rule it out
       
   238             {
       
   239             TDriveInfo driveInfo;
       
   240             User::LeaveIfError( iFs.Drive( driveInfo, i ) );
       
   241             
       
   242             /*
       
   243             From e32cost.h:
       
   244             const TUint KMediaAttVariableSize   = 0x01;
       
   245             const TUint KMediaAttDualDensity    = 0x02;
       
   246             const TUint KMediaAttFormattable    = 0x04;
       
   247             const TUint KMediaAttWriteProtected = 0x08;
       
   248             const TUint KMediaAttLockable       = 0x10;
       
   249             const TUint KMediaAttLocked         = 0x20;
       
   250             const TUint KMediaAttHasPassword    = 0x40;
       
   251             const TUint KMediaAttReadWhileWrite = 0x80;
       
   252             const TUint KMediaAttDeleteNotify   = 0x100;
       
   253             
       
   254             The drive attributes.    
       
   255             
       
   256             const TUint KDriveAttLocal          = 0x01;
       
   257             const TUint KDriveAttRom            = 0x02;
       
   258             const TUint KDriveAttRedirected     = 0x04;
       
   259             const TUint KDriveAttSubsted        = 0x08;
       
   260             const TUint KDriveAttInternal       = 0x10;
       
   261             const TUint KDriveAttRemovable      = 0x20;
       
   262             const TUint KDriveAttRemote         = 0x40;
       
   263             const TUint KDriveAttTransaction    = 0x80;
       
   264             */
       
   265 
       
   266             MPX_DEBUG3("CIptvDriveMonitor:: drive[%d]: type = %S",
       
   267                                      i,
       
   268                                      &DriveTypeDes( driveInfo.iType ));
       
   269 
       
   270             MPX_DEBUG3(
       
   271                 "CIptvDriveMonitor::           MediaAtt flags = %x DriveAtt flags = %x",
       
   272                     driveInfo.iMediaAtt,
       
   273                     driveInfo.iDriveAtt );
       
   274 
       
   275 #ifdef __WINSCW__
       
   276             // (2) c-drive is EMediaRam
       
   277             // (3) d-drive is EMediaHardDisk
       
   278             // (4) e-drive is EMediaHardDisk or EMediaNotPresent
       
   279             // (25) z-drive is EMediaRom
       
   280             if ( (driveInfo.iType == EMediaRam) ||                                     // c
       
   281                  ((driveInfo.iType == EMediaHardDisk) && i != EDriveD /* skip d */) || // e
       
   282                  (driveInfo.iType == EMediaNANDFlash) ||                               // nothing
       
   283                  (driveInfo.iType == EMediaNotPresent) )                               // e
       
   284 #else
       
   285             // (2) c-drive is EMediaNANDFlash
       
   286             // (3) d-drive is EMediaRam
       
   287             // (4) e-drive is EMediaHardDisk or EMediaNotPresent
       
   288             // (5) f-drive is EMediaHardDisk or EMediaNotPresent
       
   289             // (25) z-drive is EMediaRom
       
   290             if ( (driveInfo.iType == EMediaHardDisk) ||  // e,f
       
   291                  (driveInfo.iType == EMediaNANDFlash) || // c
       
   292                  (driveInfo.iType == EMediaNotPresent) ) // e,f
       
   293 #endif // __WINSCW__
       
   294                 {                
       
   295                 if ( !(driveInfo.iMediaAtt & KMediaAttWriteProtected) &&
       
   296                       (driveInfo.iDriveAtt & KDriveAttLocal) )
       
   297                     {
       
   298                     TIptvDriveInfo iptvDriveInfo;
       
   299                     TVolumeInfo volumeInfo;
       
   300                     TChar ch;
       
   301 
       
   302                     iFs.DriveToChar( i, ch );
       
   303 
       
   304                     iptvDriveInfo.iDrive     = i;
       
   305                     iptvDriveInfo.iDriveChar = ch;
       
   306                     iptvDriveInfo.iType      = driveInfo.iType;
       
   307 
       
   308 
       
   309 #ifdef RD_MULTIPLE_DRIVE_ENABLERS
       
   310 
       
   311                     TUint driveStatus;
       
   312                     TInt err = DriveInfo::GetDriveStatus( iFs, i, driveStatus );
       
   313                     if ( err == KErrNone )
       
   314                         {
       
   315                         if ( driveStatus & DriveInfo::EDriveRemovable )
       
   316                             {
       
   317                             iptvDriveInfo.iFlags |= TIptvDriveInfo::ERemovable;
       
   318                             }
       
   319                         }
       
   320 
       
   321                     TInt massStorageDrive;
       
   322                     err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage,
       
   323                                                       massStorageDrive );
       
   324                     if ( err == KErrNone )
       
   325                         {
       
   326                         if ( i == massStorageDrive )
       
   327                             {
       
   328                             iptvDriveInfo.iFlags |= TIptvDriveInfo::EMassStorage;
       
   329                             }                        
       
   330                         }
       
   331 
       
   332 #else
       
   333 
       
   334                     if ( driveInfo.iDriveAtt & KDriveAttRemovable )
       
   335                         {
       
   336                         if ( driveInfo.iMediaAtt & KMediaAttLockable )
       
   337                             {
       
   338                             //memory card has KDriveAttRemovable and KMediaAttLockable flags set
       
   339                             iptvDriveInfo.iFlags |= TIptvDriveInfo::ERemovable;
       
   340                             }
       
   341                         else
       
   342                             {
       
   343                             //mass storage has KDriveAttRemovable set and KMediaAttLockable not set
       
   344                             iptvDriveInfo.iFlags |= TIptvDriveInfo::EMassStorage;
       
   345                             }
       
   346                         }
       
   347 
       
   348 #endif // RD_MULTIPLE_DRIVE_ENABLERS
       
   349 
       
   350                     if ( driveInfo.iMediaAtt & KMediaAttLocked )
       
   351                         {
       
   352                         iptvDriveInfo.iFlags |= TIptvDriveInfo::ELocked;
       
   353                         }
       
   354                     if ( driveInfo.iType == EMediaNotPresent )
       
   355                         {
       
   356                         iptvDriveInfo.iFlags |= TIptvDriveInfo::EMediaNotPresent;
       
   357                         }
       
   358 
       
   359                     // When mass storage mode is activated while application is running,
       
   360                     // the only hint about that is the TVolumeInfo not being available. 
       
   361                     // Therefore we mark drive as EMediaNotPresent if that structure
       
   362                     // is not available.
       
   363                     if ( iFs.Volume( volumeInfo, i ) != KErrNone )
       
   364                         {
       
   365                         iptvDriveInfo.iFlags |= TIptvDriveInfo::EMediaNotPresent;
       
   366                         iptvDriveInfo.iVolumeName.Zero();
       
   367                         }
       
   368                     else
       
   369                         {
       
   370                         iptvDriveInfo.iVolumeName = volumeInfo.iName;
       
   371                         }
       
   372 
       
   373                     if ( iptvDriveInfo.iFlags & TIptvDriveInfo::EMediaNotPresent )
       
   374                         {
       
   375                         iptvDriveInfo.iFlags |= TIptvDriveInfo::ERemovable;
       
   376                         }
       
   377 
       
   378                     iAvailableDrives.AppendL( iptvDriveInfo );
       
   379                     }
       
   380                 }
       
   381             }
       
   382         } // for
       
   383 
       
   384     // if e and f-drives are available, then c-drive is removed from the available drives list
       
   385     if ( ArrayPos( EDriveE ) != KErrNotFound &&
       
   386          ArrayPos( EDriveF ) != KErrNotFound )
       
   387         {
       
   388         TInt cDrivePos = ArrayPos( EDriveC );
       
   389         if ( cDrivePos != KErrNotFound )
       
   390             {
       
   391             MPX_DEBUG1(
       
   392                 "CIptvDriveMonitor:: e & f-drives available -> removing c from available drives");
       
   393             iAvailableDrives.Remove( cDrivePos );
       
   394             iAvailableDrives.Compress();
       
   395             }
       
   396         }
       
   397     
       
   398     }
       
   399     
       
   400 // -----------------------------------------------------------------------------
       
   401 // CVideoSettingsDriveMonitor::ArrayPos
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 EXPORT_C TInt CVideoSettingsDriveMonitor::ArrayPos( TInt aDrive )
       
   405     {
       
   406     TInt i;
       
   407     for (i = 0; i < iAvailableDrives.Count(); i++ )
       
   408         {
       
   409         if ( iAvailableDrives[i].iDrive == aDrive )
       
   410             {
       
   411             return i;
       
   412             }
       
   413         }
       
   414     return KErrNotFound;
       
   415     }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CVideoSettingsDriveMonitor::ArrayPosL
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 EXPORT_C TInt CVideoSettingsDriveMonitor::ArrayPosL( TInt aDrive )
       
   422     {
       
   423     TInt pos;
       
   424     User::LeaveIfError( pos = ArrayPos( aDrive ) );
       
   425     return pos;
       
   426     }
       
   427 
       
   428 // -----------------------------------------------------------------------------
       
   429 // CVideoSettingsDriveMonitor::FindMemoryCardDriveL
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 EXPORT_C TInt CVideoSettingsDriveMonitor::MemoryCardDriveL()
       
   433     {
       
   434     TInt drive;
       
   435     User::LeaveIfError( drive = MemoryCardDrive() );
       
   436     return drive;
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CVideoSettingsDriveMonitor::MemoryCardDrive
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 EXPORT_C TInt CVideoSettingsDriveMonitor::MemoryCardDrive()
       
   444     {
       
   445     TInt i;
       
   446     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   447         {
       
   448         if ( iAvailableDrives[i].iFlags & TIptvDriveInfo::ERemovable )
       
   449             {
       
   450             return iAvailableDrives[i].iDrive;
       
   451             }
       
   452         }
       
   453     return KErrNotFound;
       
   454     }
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 // CVideoSettingsDriveMonitor::MassStorageDriveL
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 EXPORT_C TInt CVideoSettingsDriveMonitor::MassStorageDriveL()
       
   461     {
       
   462     TInt drive;
       
   463     User::LeaveIfError( drive = MassStorageDrive() );
       
   464     return drive;
       
   465     }
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // CVideoSettingsDriveMonitor::MassStorageDrive
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 EXPORT_C TInt CVideoSettingsDriveMonitor::MassStorageDrive()
       
   472     {
       
   473     TInt i;
       
   474     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   475         {
       
   476         if ( iAvailableDrives[i].iFlags & TIptvDriveInfo::EMassStorage )
       
   477             {
       
   478             return iAvailableDrives[i].iDrive;
       
   479             }
       
   480         }
       
   481     return KErrNotFound;
       
   482     }
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 // CVideoSettingsDriveMonitor::PhoneMemoryDriveL
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 EXPORT_C TInt CVideoSettingsDriveMonitor::PhoneMemoryDriveL()
       
   489     {
       
   490     TInt drive;
       
   491     User::LeaveIfError( drive = PhoneMemoryDrive() );
       
   492     return drive;
       
   493     }
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CVideoSettingsDriveMonitor::PhoneMemoryDrive
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 EXPORT_C TInt CVideoSettingsDriveMonitor::PhoneMemoryDrive()
       
   500     {
       
   501     TInt i;
       
   502     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   503         {
       
   504         if ( iAvailableDrives[i].iDrive == EDriveC )
       
   505             {
       
   506             return iAvailableDrives[i].iDrive;
       
   507             }
       
   508         }
       
   509     return KErrNotFound;
       
   510     }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CVideoSettingsDriveMonitor::FixedDriveL
       
   514 // -----------------------------------------------------------------------------
       
   515 //
       
   516 EXPORT_C TInt CVideoSettingsDriveMonitor::FixedDriveL( TBool aExcludeCDrive )
       
   517     {
       
   518     TInt drive;
       
   519     User::LeaveIfError( drive = FixedDrive( aExcludeCDrive ) );
       
   520     return drive;
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // CVideoSettingsDriveMonitor::FixedDrive
       
   525 // -----------------------------------------------------------------------------
       
   526 //
       
   527 EXPORT_C TInt CVideoSettingsDriveMonitor::FixedDrive( TBool aExcludeCDrive )
       
   528     {
       
   529     TInt i;
       
   530     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   531         {
       
   532         MPX_DEBUG2("CIptvDriveMonitor:: iAvailableDrives[%d]", i);
       
   533 
       
   534         if ( !(iAvailableDrives[i].iFlags & TIptvDriveInfo::ERemovable) )
       
   535             {
       
   536             if ( iAvailableDrives[i].iDrive != EDriveC )
       
   537                 {
       
   538                 MPX_DEBUG2("CIptvDriveMonitor:: FixedDrive() returning drive %d", iAvailableDrives[i].iDrive);
       
   539                 return iAvailableDrives[i].iDrive;
       
   540                 }
       
   541             else
       
   542                 {
       
   543                 if ( !aExcludeCDrive )
       
   544                     {
       
   545                     MPX_DEBUG2("CIptvDriveMonitor:: FixedDrive() returning drive %d", iAvailableDrives[i].iDrive);
       
   546                     return iAvailableDrives[i].iDrive;
       
   547                     }   
       
   548                 }
       
   549             }
       
   550         }
       
   551     return KErrNotFound;
       
   552     }
       
   553     
       
   554 // -----------------------------------------------------------------------------
       
   555 // CVideoSettingsDriveMonitor::IsMmcInserted()
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 EXPORT_C TBool CVideoSettingsDriveMonitor::IsMmcInserted()
       
   559     {   
       
   560     TInt drive = MemoryCardDrive();
       
   561     
       
   562     if ( drive == KErrNotFound )
       
   563         {
       
   564         return EFalse;
       
   565         }
       
   566         
       
   567     TInt arrayPos = ArrayPos( drive );
       
   568     
       
   569     if ( arrayPos == KErrNotFound )
       
   570         {
       
   571         return EFalse;
       
   572         }
       
   573     
       
   574     TUint32 flags = iAvailableDrives[arrayPos].iFlags;
       
   575     
       
   576     if ( (flags & TIptvDriveInfo::ELocked) || (flags & TIptvDriveInfo::EMediaNotPresent) )
       
   577         {
       
   578         return EFalse;
       
   579         } 
       
   580     
       
   581     return ETrue;
       
   582     }
       
   583     
       
   584 // -----------------------------------------------------------------------------
       
   585 // CVideoSettingsDriveMonitor::RunL()
       
   586 // -----------------------------------------------------------------------------
       
   587 //
       
   588 void CVideoSettingsDriveMonitor::RunL()
       
   589     {
       
   590     MPX_FUNC("CIptvDriveMonitor::RunL() start");
       
   591     
       
   592     if ( iStatus == KErrNone )
       
   593         {        
       
   594         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   595         
       
   596         TRAPD( err, RefreshAvailableDrivesL() );
       
   597         if ( err != KErrNone )
       
   598             {
       
   599             MPX_DEBUG2("CIptvDriveMonitor:: RefreshAvailableDrivesL leaved with error code %d, ignoring", err);
       
   600             } 
       
   601         CompareOldAndNewAvailableDrives();
       
   602         SetActive();
       
   603         }
       
   604     else
       
   605         {
       
   606         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   607         SetActive();
       
   608         }
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CVideoSettingsDriveMonitor::DoCancel()
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void CVideoSettingsDriveMonitor::DoCancel()
       
   616     {
       
   617     iFs.NotifyChangeCancel( iStatus );
       
   618     }       
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CVideoSettingsDriveMonitor::RunError()
       
   622 // -----------------------------------------------------------------------------
       
   623 //
       
   624 TInt CVideoSettingsDriveMonitor::RunError( TInt /* aError */ )
       
   625     {
       
   626     MPX_FUNC("CIptvDriveMonitor::RunL() leaved (should never happen).");
       
   627     return KErrNone;
       
   628     }       
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // CVideoSettingsDriveMonitor::SendEvent()
       
   632 // -----------------------------------------------------------------------------
       
   633 //
       
   634 void CVideoSettingsDriveMonitor::SendEvent( TIptvDriveMonitorEvent::TEvent aEvent,
       
   635     TInt aDrive )
       
   636     {
       
   637     MPX_DEBUG4("CIptvDriveMonitor:: Sending event: %S(%d), drive: %d",
       
   638         &TIptvDriveMonitorEvent::EventDes( aEvent ),
       
   639         aEvent,
       
   640         aDrive );
       
   641 
       
   642     TIptvDriveMonitorEvent event;
       
   643         
       
   644     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   645         {
       
   646         event.iEvent = static_cast<TInt>(aEvent);
       
   647         event.iDrive = aDrive;
       
   648         iObservers[i]->HandleDriveMonitorEvent( event );
       
   649         }
       
   650 
       
   651 #if IPTV_LOGGING_METHOD != 0
       
   652     PrintAvailableDrives();
       
   653 #endif
       
   654     }
       
   655 
       
   656 // -----------------------------------------------------------------------------
       
   657 // CVideoSettingsDriveMonitor::CompareOldAndNewAvailableDrives
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 void CVideoSettingsDriveMonitor::CompareOldAndNewAvailableDrives()
       
   661     {
       
   662     // Run through old drives list to detect changes
       
   663     TInt i;
       
   664     for ( i = 0; i < iPreviousAvailableDrives.Count(); i++ )
       
   665         {
       
   666         TInt pos = ArrayPos( iPreviousAvailableDrives[i].iDrive );
       
   667         if ( pos == KErrNotFound )
       
   668             {
       
   669             // drive was dismounted
       
   670             SendEvent( TIptvDriveMonitorEvent::EDriveDismounted,
       
   671                 iPreviousAvailableDrives[i].iDrive );
       
   672             }
       
   673         else 
       
   674             {
       
   675             // drive still present
       
   676             if ( iPreviousAvailableDrives[i].iFlags != iAvailableDrives[pos].iFlags )
       
   677                 {
       
   678                 // drive was changed
       
   679                 if ( (iPreviousAvailableDrives[i].iFlags & TIptvDriveInfo::EMediaNotPresent) && 
       
   680                      !(iAvailableDrives[pos].iFlags & EMediaNotPresent) )
       
   681                     {
       
   682                     SendEvent( TIptvDriveMonitorEvent::EMediaInserted,
       
   683                         iAvailableDrives[pos].iDrive );
       
   684                     }
       
   685                     
       
   686                 if ( !(iPreviousAvailableDrives[i].iFlags & TIptvDriveInfo::EMediaNotPresent) && 
       
   687                      (iAvailableDrives[pos].iFlags & TIptvDriveInfo::EMediaNotPresent) )
       
   688                     {
       
   689                     SendEvent( TIptvDriveMonitorEvent::EMediaRemoved,
       
   690                         iAvailableDrives[pos].iDrive );
       
   691                     }
       
   692 
       
   693                 if ( !(iPreviousAvailableDrives[i].iFlags & TIptvDriveInfo::ELocked) && 
       
   694                      (iAvailableDrives[pos].iFlags & TIptvDriveInfo::ELocked) )
       
   695                     {
       
   696                     SendEvent( TIptvDriveMonitorEvent::EDriveLocked,
       
   697                         iAvailableDrives[pos].iDrive );
       
   698                     }
       
   699 
       
   700                 if ( (iPreviousAvailableDrives[i].iFlags & TIptvDriveInfo::ELocked) && 
       
   701                      !(iAvailableDrives[pos].iFlags & TIptvDriveInfo::ELocked) )
       
   702                     {
       
   703                     SendEvent( TIptvDriveMonitorEvent::EDriveUnlocked,
       
   704                         iAvailableDrives[pos].iDrive );
       
   705                     }               
       
   706                 }
       
   707             
       
   708             // drive volume name was changed
       
   709             if ( iPreviousAvailableDrives[i].iVolumeName.Compare( 
       
   710                  iAvailableDrives[pos].iVolumeName ) != 0 )
       
   711                 {
       
   712                 SendEvent( TIptvDriveMonitorEvent::EDriveVolumeNameChanged, 
       
   713                     iAvailableDrives[pos].iDrive ); 
       
   714                 }
       
   715             }
       
   716         }
       
   717 
       
   718     // Run through new drives list to detect mounted drives
       
   719     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   720         {
       
   721         TBool found = EFalse;
       
   722         for ( TInt j = 0; j < iPreviousAvailableDrives.Count(); j++ )
       
   723             {
       
   724             if ( iPreviousAvailableDrives[j].iDrive == iAvailableDrives[i].iDrive )
       
   725                 {
       
   726                 found = ETrue;
       
   727                 break;
       
   728                 }
       
   729             }
       
   730         if ( !found )
       
   731             {
       
   732             SendEvent( TIptvDriveMonitorEvent::EDriveMounted,
       
   733                 iAvailableDrives[i].iDrive );
       
   734             }
       
   735         }
       
   736     }
       
   737 
       
   738 // -----------------------------------------------------------------------------
       
   739 // CVideoSettingsDriveMonitor::DriveType()
       
   740 // -----------------------------------------------------------------------------
       
   741 //
       
   742 #if IPTV_LOGGING_METHOD != 0 
       
   743 const TDesC& CVideoSettingsDriveMonitor::DriveTypeDes( TInt aType )
       
   744     {
       
   745     switch (aType)
       
   746         {     
       
   747         case EMediaNotPresent:
       
   748             return KIptvMediaNotPresentDes;
       
   749 	      case EMediaUnknown:
       
   750             return KIptvMediaUnknownDes;
       
   751         case EMediaFloppy:
       
   752             return KIptvMediaFloppyDes;
       
   753         case EMediaHardDisk:
       
   754             return KIptvMediaHardDiskDes;
       
   755         case EMediaCdRom:
       
   756             return KIptvMediaCdRomDes;
       
   757         case EMediaRam:
       
   758             return KIptvMediaRamDes;
       
   759         case EMediaFlash:
       
   760             return KIptvMediaFlashDes;
       
   761         case EMediaRom:
       
   762             return KIptvMediaRomDes;
       
   763         case EMediaRemote:
       
   764             return KIptvMediaRemoteDes;
       
   765         case EMediaNANDFlash:
       
   766             return KIptvMediaNANDFlashDes;
       
   767         default:
       
   768             return KIptvMediaUnknownDes;
       
   769         }
       
   770     }
       
   771 #else
       
   772 const TDesC& CVideoSettingsDriveMonitor::DriveTypeDes( TInt /*aType*/ )
       
   773     {
       
   774     return KIptvEmptyDes;
       
   775     }
       
   776 #endif
       
   777     
       
   778 // -----------------------------------------------------------------------------
       
   779 // CVideoSettingsDriveMonitor::PrintAvailableDrives()
       
   780 // -----------------------------------------------------------------------------
       
   781 //
       
   782 void CVideoSettingsDriveMonitor::PrintAvailableDrives()
       
   783     {
       
   784 #if IPTV_LOGGING_METHOD != 0 
       
   785     for ( TInt i = 0; i < iAvailableDrives.Count(); i++ )
       
   786         {
       
   787         IPTVLOGSTRING3_HIGH_LEVEL("CIptvDriveMonitor:: iAvailableDrives[%d].iDrive = %d",
       
   788             i, iAvailableDrives[i].iDrive);
       
   789         IPTVLOGSTRING2_HIGH_LEVEL("    ERemovableDrive  = %d",
       
   790             !!(iAvailableDrives[i].iFlags & TIptvDriveInfo::ERemovable));
       
   791         IPTVLOGSTRING2_HIGH_LEVEL("    EMassStorage     = %d",
       
   792             !!(iAvailableDrives[i].iFlags & TIptvDriveInfo::EMassStorage));
       
   793         IPTVLOGSTRING2_HIGH_LEVEL("    ELockedDrive     = %d",
       
   794             !!(iAvailableDrives[i].iFlags & TIptvDriveInfo::ELocked));
       
   795         IPTVLOGSTRING2_HIGH_LEVEL("    EMediaNotPresent = %d",
       
   796             !!(iAvailableDrives[i].iFlags & TIptvDriveInfo::EMediaNotPresent));
       
   797         }
       
   798 #endif
       
   799     }
       
   800 
       
   801 // -----------------------------------------------------------------------------
       
   802 // CVideoSettingsDriveMonitor::GetUsedMemoryL()
       
   803 // -----------------------------------------------------------------------------
       
   804 //
       
   805 EXPORT_C void CVideoSettingsDriveMonitor::GetUsedMemoryL( TInt& aUsedMemory )
       
   806     {
       
   807     MPX_FUNC("CIptvDriveMonitor::GetUsedMemoryL() start");
       
   808     
       
   809     TInt cenRepMemory = KErrNotFound; //init to some non valid drive value, in case that cenrep wont change it at all
       
   810     
       
   811     CRepository* cenRep = CRepository::NewL( KIptvCenRepUid );
       
   812     CleanupStack::PushL( cenRep ); // 1->
       
   813 
       
   814     TInt cenRepError = cenRep->Get( KIptvCenRepPreferredMemoryKey, cenRepMemory );
       
   815                 
       
   816     aUsedMemory = EDriveC;
       
   817         
       
   818     if ( ArrayPos( cenRepMemory ) == KErrNotFound
       
   819         || cenRepError != KErrNone )
       
   820         {
       
   821         MPX_DEBUG1(
       
   822             "CIptvDriveMonitor:: cenrep value for used memory was not valid or not found.");
       
   823 
       
   824         // Non existing drive or no cen rep value -> figure out the default drive
       
   825         TInt massStorageDrive = MassStorageDrive();
       
   826         if ( massStorageDrive != KErrNotFound )
       
   827             {
       
   828             MPX_DEBUG1("CIptvDriveMonitor:: using mass storage");
       
   829             aUsedMemory = massStorageDrive;
       
   830             }
       
   831         else
       
   832             {    
       
   833             TInt memoryCardDrive  = MemoryCardDrive();
       
   834             if ( memoryCardDrive != KErrNotFound )
       
   835                 {
       
   836                 MPX_DEBUG1("CIptvDriveMonitor:: using memory card");
       
   837                 aUsedMemory = memoryCardDrive;
       
   838                 }
       
   839             }
       
   840 
       
   841         MPX_DEBUG2(
       
   842             "CIptvDriveMonitor:: writing new value to cenrep (%d)", aUsedMemory);
       
   843 
       
   844         cenRep->Set( KIptvCenRepPreferredMemoryKey, aUsedMemory );
       
   845         }
       
   846     else
       
   847         {
       
   848         //Cenrep value was valid, use it
       
   849         MPX_DEBUG1(
       
   850             "CIptvDriveMonitor:: cenrep value for used memory was valid, using it.");
       
   851         aUsedMemory = cenRepMemory;
       
   852         }
       
   853 
       
   854     CleanupStack::PopAndDestroy( cenRep ); // <-1
       
   855             
       
   856     MPX_DEBUG2("CIptvDriveMonitor:: using drive %d", aUsedMemory);
       
   857     }
       
   858     
       
   859 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   860 
       
   861 
       
   862 //  End of File