iaupdate/IAD/backgroundchecker/src/iaupdatebgfirsttimehandler.cpp
changeset 0 ba25891c3a9e
child 25 7333d7932ef7
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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:   This module contains the implementation of CIAUpdateFirstTimeInfo class 
       
    15 *                member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 //INCLUDES
       
    22 #include "iaupdatebgfirsttimehandler.h"
       
    23 
       
    24 #include <bautils.h>  // bafl.lib 
       
    25 #include <s32file.h>  // estor.lib
       
    26 
       
    27 //MACROS
       
    28 _LIT( KPath, "c:\\private\\2000f85a\\");
       
    29 _LIT( KIAUpdateFirstTimeFile, "IADFirstTimeState");
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CIAUpdateBGFirstTimeHandler::NewL
       
    35 // Two-phased constructor.
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CIAUpdateBGFirstTimeHandler* CIAUpdateBGFirstTimeHandler::NewL()
       
    39     {
       
    40     CIAUpdateBGFirstTimeHandler* self = CIAUpdateBGFirstTimeHandler::NewLC();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CIAUpdateUiController::NewLC
       
    47 // Two-phased constructor.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CIAUpdateBGFirstTimeHandler* CIAUpdateBGFirstTimeHandler::NewLC()
       
    51     {
       
    52     CIAUpdateBGFirstTimeHandler* self = new( ELeave ) CIAUpdateBGFirstTimeHandler();
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     return self;
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CIAUpdateBGFirstTimeHandler::ConstructL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CIAUpdateBGFirstTimeHandler::ConstructL()
       
    64     {
       
    65     User::LeaveIfError( iFsSession.Connect() );   
       
    66     iPath.Append( KPath ); 
       
    67     BaflUtils::EnsurePathExistsL( iFsSession, iPath );
       
    68     iPath.Append( KIAUpdateFirstTimeFile );
       
    69     }    
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CIAUpdateBGFirstTimeHandler::CIAUpdateBGFirstTimeHandler
       
    73 // constructor
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CIAUpdateBGFirstTimeHandler::CIAUpdateBGFirstTimeHandler()  
       
    77     {
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CIAUpdateBGFirstTimeHandler::~CIAUpdateBGFirstTimeHandler
       
    82 // Destructor
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CIAUpdateBGFirstTimeHandler::~CIAUpdateBGFirstTimeHandler()
       
    86     {
       
    87     iFsSession.Close();
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CIAUpdateBGFirstTimeHandler::SetAgreementAcceptedL
       
    92 // Set Nokia agreement as accepted by an user
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CIAUpdateBGFirstTimeHandler::SetAgreementAcceptedL()
       
    96     {
       
    97     ReadDataL();
       
    98     iAgreementAccepted = ETrue;
       
    99     WriteDataL();
       
   100     }
       
   101     
       
   102 // ---------------------------------------------------------------------------
       
   103 // CIAUpdateBGFirstTimeHandler::SetAgreementAskedL
       
   104 // Set Nokia agreement as asked (prompted) to an user
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CIAUpdateBGFirstTimeHandler::SetAgreementAskedL()
       
   108     {
       
   109     ReadDataL();
       
   110     iAgreementAsked = ETrue;
       
   111     WriteDataL();
       
   112     }
       
   113         
       
   114 // ---------------------------------------------------------------------------
       
   115 // CIAUpdateBGFirstTimeHandler::SetAutomaticUpdatesAskedL
       
   116 // Set automatic update checks as prompted to an use
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CIAUpdateBGFirstTimeHandler::SetAutomaticUpdatesAskedL()
       
   120     {
       
   121 	ReadDataL();
       
   122 	iAutomaticUpdateChecksAsked = ETrue;
       
   123     WriteDataL();
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CIAUpdateBGFirstTimeHandler::AgreementAcceptedL
       
   128 // Is Nokia agreement of Application Update accepted by an user
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TBool CIAUpdateBGFirstTimeHandler::AgreementAcceptedL()
       
   132     {
       
   133     ReadDataL();
       
   134     return iAgreementAccepted;
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CIAUpdateBGFirstTimeHandler::AgreementAskedL
       
   140 // Is Nokia agreement of Application Update already asked 
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 TBool CIAUpdateBGFirstTimeHandler::AgreementAskedL()
       
   144     {
       
   145     ReadDataL();
       
   146     return iAgreementAsked;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CIAUpdateBGFirstTimeHandler::AutomaticUpdateChecksAskedL
       
   151 // Is activation for automatic update cheks from network already asked 
       
   152 // ---------------------------------------------------------------------------
       
   153 //    
       
   154 TBool CIAUpdateBGFirstTimeHandler::AutomaticUpdateChecksAskedL()
       
   155     {
       
   156     ReadDataL();
       
   157     return iAutomaticUpdateChecksAsked;
       
   158     }
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CIAUpdateBGFirstTimeHandler::ReadDataL
       
   163 //
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CIAUpdateBGFirstTimeHandler::ReadDataL()
       
   167 	{
       
   168 	RFile file;
       
   169     TInt err = file.Open( iFsSession, iPath, EFileRead|EFileShareAny );
       
   170     if ( err == KErrNotFound )
       
   171     	{
       
   172     	iAgreementAccepted = EFalse;
       
   173 	    iAgreementAsked = EFalse;
       
   174 	    iAutomaticUpdateChecksAsked = EFalse; 
       
   175     	}
       
   176     else
       
   177         {
       
   178         User::LeaveIfError( err );
       
   179         CleanupClosePushL( file );
       
   180     
       
   181         RFileReadStream stream( file, 0 );
       
   182         CleanupClosePushL( stream );
       
   183         InternalizeL( stream );
       
   184         CleanupStack::PopAndDestroy( &stream );	
       
   185         CleanupStack::PopAndDestroy( &file );
       
   186         }
       
   187 	}
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CIAUpdateBGFirstTimeHandler::WriteDataL
       
   191 //
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CIAUpdateBGFirstTimeHandler::WriteDataL()
       
   195 	{
       
   196 	RFile file;
       
   197     User::LeaveIfError( file.Replace( iFsSession, iPath, EFileWrite|EFileShareAny ) );
       
   198     CleanupClosePushL( file );
       
   199     
       
   200     RFileWriteStream stream( file, 0 );
       
   201     CleanupClosePushL( stream );
       
   202 
       
   203     ExternalizeL( stream );
       
   204     stream.CommitL();
       
   205         
       
   206     CleanupStack::PopAndDestroy( &stream );
       
   207     CleanupStack::PopAndDestroy( &file );
       
   208 	}
       
   209 
       
   210     
       
   211 // -----------------------------------------------------------------------------
       
   212 // CIAUpdateBGFirstTimeHandler::InternalizeL
       
   213 //
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CIAUpdateBGFirstTimeHandler::InternalizeL( RReadStream& aStream )
       
   217 	{
       
   218 	iAgreementAccepted = aStream.ReadInt32L();
       
   219 	iAgreementAsked = aStream.ReadInt32L();
       
   220 	iAutomaticUpdateChecksAsked = aStream.ReadInt32L();
       
   221 	}
       
   222 
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CIAUpdateBGFirstTimeHandler::ExternalizeL
       
   226 //
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CIAUpdateBGFirstTimeHandler::ExternalizeL( RWriteStream& aStream )
       
   230 	{
       
   231 	aStream.WriteInt32L( iAgreementAccepted );
       
   232 	aStream.WriteInt32L( iAgreementAsked );	
       
   233 	aStream.WriteInt32L( iAutomaticUpdateChecksAsked );
       
   234 	}
       
   235     
       
   236 // End of File