contentstorage/srvsrc/casrvmmchistory.cpp
changeset 60 f62f87b200ec
child 80 397d00875918
equal deleted inserted replaced
4:1a2a00e78665 60:f62f87b200ec
       
     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 // CMenuSrvMmcHistory::LoadL
       
    30 // ---------------------------------------------------------
       
    31 //
       
    32 EXPORT_C void CCaSrvMmcHistory::LoadL( RFs& aFs, const TDesC& aFname )
       
    33     {
       
    34     iMmcList.Reset();
       
    35     TUint att;
       
    36     if( KErrNotFound != aFs.Att( aFname, att ) )
       
    37         {
       
    38         RFileReadStream stream;
       
    39         CleanupClosePushL( stream );
       
    40         User::LeaveIfError( stream.Open( aFs, aFname, EFileStream
       
    41                 | EFileShareReadersOnly ) );
       
    42         TInt len = Min( KCaMmcHistoryLength, stream.ReadInt32L() );
       
    43         while( len-- )
       
    44             {
       
    45             iMmcList.AppendL( stream.ReadUint32L() );
       
    46             }
       
    47         CleanupStack::PopAndDestroy( &stream );
       
    48         }
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CMenuSrvMmcHistory::SaveL
       
    53 // Method do not work if there is no free space on C drive.
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 EXPORT_C void CCaSrvMmcHistory::SaveL( RFs& aFs, const TDesC& aFname )
       
    57     {
       
    58     if( SysUtil::DiskSpaceBelowCriticalLevelL( &aFs, 0, EDriveC ) )
       
    59         {
       
    60         return;
       
    61         }
       
    62 
       
    63     RFileWriteStream stream;
       
    64     CleanupClosePushL( stream );
       
    65     User::LeaveIfError( stream.Replace( aFs, aFname, EFileStream
       
    66             | EFileShareExclusive ) );
       
    67     stream.WriteInt32L( iMmcList.Count() );
       
    68     for( TInt i = 0; i < iMmcList.Count(); i++ )
       
    69         {
       
    70         stream.WriteUint32L( iMmcList[i] );
       
    71         }
       
    72     CleanupStack::PopAndDestroy( &stream );
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // CMenuSrvMmcHistory::InsertL
       
    77 // ---------------------------------------------------------
       
    78 //
       
    79 EXPORT_C void CCaSrvMmcHistory::InsertL( TUint aMmc )
       
    80     {
       
    81     TInt i = iMmcList.Find( aMmc );
       
    82     switch( i )
       
    83         {
       
    84         case 0:
       
    85             {
       
    86             // aMmc is already first, do nothing.
       
    87             break;
       
    88             }
       
    89 
       
    90         case KErrNotFound:
       
    91             {
       
    92             // aMmc is not in the list. Insert as first.
       
    93             if( iMmcList.Count() == KCaMmcHistoryLength )
       
    94                 {
       
    95                 // List already full - remove last item to make space.
       
    96                 iMmcList.Remove( KCaMmcHistoryLength - 1 );
       
    97                 }
       
    98             iMmcList.InsertL( aMmc, 0 );
       
    99             break;
       
   100             }
       
   101 
       
   102         default:
       
   103             {
       
   104             // aMmc is in the list, but not first. Move to first place.
       
   105             iMmcList.Remove( i );
       
   106             iMmcList.InsertL( aMmc, 0 );
       
   107             break;
       
   108             }
       
   109         }
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CMenuSrvMmcHistory::Find
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 EXPORT_C TInt CCaSrvMmcHistory::Find( TUint aMmc )
       
   117     {
       
   118     return iMmcList.Find( aMmc );
       
   119     }
       
   120 
       
   121 //  End of File