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