contentstorage/srvsrc/casrvmmchistory.cpp
branchRCL_3
changeset 29 0efa10d348c0
equal deleted inserted replaced
28:053c6c7c14f3 29:0efa10d348c0
       
     1 /*
       
     2  * Copyright (c) 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:  ?Description
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <f32file.h>
       
    20 #include <s32file.h>
       
    21 #include <sysutil.h>
       
    22 #include "casrvmmchistory.h"
       
    23 // CONSTANTS
       
    24 LOCAL_D const TInt KCaMmcHistoryLength = 2;
       
    25 
       
    26 // ==================== MEMBER FUNCTIONS ====================
       
    27 
       
    28 // ---------------------------------------------------------
       
    29 //
       
    30 // ---------------------------------------------------------
       
    31 //
       
    32 CCaSrvMmcHistory::CCaSrvMmcHistory()
       
    33 	{
       
    34 	}
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 //
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 void CCaSrvMmcHistory::ConstructL()
       
    41 	{
       
    42 	}
       
    43 
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 EXPORT_C CCaSrvMmcHistory* CCaSrvMmcHistory::NewL()
       
    49      {
       
    50      CCaSrvMmcHistory* self = new (ELeave) CCaSrvMmcHistory();
       
    51      CleanupStack::PushL( self );
       
    52      self->ConstructL();
       
    53      CleanupStack::Pop( self );
       
    54      return self;
       
    55      }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 CCaSrvMmcHistory::~CCaSrvMmcHistory()
       
    62     {
       
    63     iMmcList.Close();
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 EXPORT_C void CCaSrvMmcHistory::LoadL( RFs& aFs, const TDesC& aFname )
       
    71     {
       
    72     iMmcList.Reset();
       
    73     TUint att;
       
    74     if( KErrNotFound != aFs.Att( aFname, att ) )
       
    75         {
       
    76         RFileReadStream stream;
       
    77         CleanupClosePushL( stream );
       
    78         User::LeaveIfError( stream.Open( aFs, aFname, EFileStream
       
    79                 | EFileShareReadersOnly ) );
       
    80         TInt len = Min( KCaMmcHistoryLength, stream.ReadInt32L() );
       
    81         while( len-- )
       
    82             {
       
    83             iMmcList.AppendL( stream.ReadUint32L() );
       
    84             }
       
    85         CleanupStack::PopAndDestroy( &stream );
       
    86         }
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------
       
    90 // CMenuSrvMmcHistory::SaveL
       
    91 // Method do not work if there is no free space on C drive.
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 EXPORT_C void CCaSrvMmcHistory::SaveL( RFs& aFs, const TDesC& aFname )
       
    95     {
       
    96     if( SysUtil::DiskSpaceBelowCriticalLevelL( &aFs, 0, EDriveC ) )
       
    97         {
       
    98         return;
       
    99         }
       
   100 
       
   101     RFileWriteStream stream;
       
   102     CleanupClosePushL( stream );
       
   103     User::LeaveIfError( stream.Replace( aFs, aFname, EFileStream
       
   104             | EFileShareExclusive ) );
       
   105     stream.WriteInt32L( iMmcList.Count() );
       
   106     for( TInt i = 0; i < iMmcList.Count(); i++ )
       
   107         {
       
   108         stream.WriteUint32L( iMmcList[i] );
       
   109         }
       
   110     CleanupStack::PopAndDestroy( &stream );
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------
       
   114 // CMenuSrvMmcHistory::InsertL
       
   115 // ---------------------------------------------------------
       
   116 //
       
   117 EXPORT_C void CCaSrvMmcHistory::InsertL( TUint aMmc )
       
   118     {
       
   119     TInt i = iMmcList.Find( aMmc );
       
   120     switch( i )
       
   121         {
       
   122         case 0:
       
   123             {
       
   124             // aMmc is already first, do nothing.
       
   125             break;
       
   126             }
       
   127 
       
   128         case KErrNotFound:
       
   129             {
       
   130             // aMmc is not in the list. Insert as first.
       
   131             if( iMmcList.Count() == KCaMmcHistoryLength )
       
   132                 {
       
   133                 // List already full - remove last item to make space.
       
   134                 iMmcList.Remove( KCaMmcHistoryLength - 1 );
       
   135                 }
       
   136             iMmcList.InsertL( aMmc, 0 );
       
   137             break;
       
   138             }
       
   139 
       
   140         default:
       
   141             {
       
   142             // aMmc is in the list, but not first. Move to first place.
       
   143             iMmcList.Remove( i );
       
   144             iMmcList.InsertL( aMmc, 0 );
       
   145             break;
       
   146             }
       
   147         }
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------
       
   151 // CMenuSrvMmcHistory::Find
       
   152 // ---------------------------------------------------------
       
   153 //
       
   154 EXPORT_C TInt CCaSrvMmcHistory::Find( TUint aMmc )
       
   155     {
       
   156     return iMmcList.Find( aMmc );
       
   157     }
       
   158 
       
   159 //  End of File