iaupdate/IAD/ui/src/iaupdatefirsttimeinfo.cpp
changeset 0 ba25891c3a9e
child 44 329d304c1aa1
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 "iaupdatefirsttimeinfo.h"
       
    23 #include "iaupdatefirsttimedatefile.h"
       
    24 
       
    25 #include <bautils.h>  // bafl.lib 
       
    26 #include <s32file.h>  // estor.lib
       
    27 #include <sysutil.h>
       
    28 
       
    29 //CONSTANTS
       
    30 const TInt KIAUpdateFirstTimeDrive( EDriveC );
       
    31 const TInt KSizeOfFile( 12 );
       
    32 const TTimeIntervalDays KFirstTimeDelayInDays( 14 );
       
    33 
       
    34 //MACROS
       
    35 _LIT( KIAUpdateFirstTimeFile, "IADFirstTimeState");
       
    36 _LIT( KIAUpdateFirstTimeDateFile, "IADFirstTimeDate");
       
    37 
       
    38 // ================= MEMBER FUNCTIONS =======================
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CIAUpdateFirstTimeInfo::NewL
       
    42 // Two-phased constructor.
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CIAUpdateFirstTimeInfo* CIAUpdateFirstTimeInfo::NewL()
       
    46     {
       
    47     CIAUpdateFirstTimeInfo* self = CIAUpdateFirstTimeInfo::NewLC();
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CIAUpdateUiController::NewLC
       
    54 // Two-phased constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CIAUpdateFirstTimeInfo* CIAUpdateFirstTimeInfo::NewLC()
       
    58     {
       
    59     CIAUpdateFirstTimeInfo* self = new( ELeave ) CIAUpdateFirstTimeInfo();
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     return self;
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CIAUpdateFirstTimeInfo::ConstructL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CIAUpdateFirstTimeInfo::ConstructL()
       
    71     {
       
    72     User::LeaveIfError( iFsSession.Connect() );
       
    73     User::LeaveIfError( iFsSession.SetSessionToPrivate( KIAUpdateFirstTimeDrive ) );
       
    74     
       
    75     // sessionpath in emulator: '\epoc32\winscw\c\private\2000F85A'
       
    76     User::LeaveIfError( iFsSession.SessionPath( iPath ) );
       
    77     BaflUtils::EnsurePathExistsL( iFsSession, iPath );
       
    78     iPath.Append( KIAUpdateFirstTimeFile );
       
    79     }    
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CIAUpdateFirstTimeInfo::CIAUpdateFirstTimeInfo
       
    83 // constructor
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CIAUpdateFirstTimeInfo::CIAUpdateFirstTimeInfo()  
       
    87     {
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CIAUpdateFirstTimeInfo::~CIAUpdateFirstTimeInfo
       
    92 // Destructor
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 CIAUpdateFirstTimeInfo::~CIAUpdateFirstTimeInfo()
       
    96     {
       
    97     iFsSession.Close();
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CIAUpdateFirstTimeInfo::SetAgreementAcceptedL
       
   102 // Set Nokia agreement as accepted by an user
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CIAUpdateFirstTimeInfo::SetAgreementAcceptedL()
       
   106     {
       
   107     ReadDataL();
       
   108     iAgreementAccepted = ETrue;
       
   109     WriteDataL();
       
   110     }
       
   111     
       
   112 // ---------------------------------------------------------------------------
       
   113 // CIAUpdateFirstTimeInfo::SetAgreementAskedL
       
   114 // Set Nokia agreement as asked (prompted) to an user
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CIAUpdateFirstTimeInfo::SetAgreementAskedL()
       
   118     {
       
   119     ReadDataL();
       
   120     iAgreementAsked = ETrue;
       
   121     WriteDataL();
       
   122     }
       
   123         
       
   124 // ---------------------------------------------------------------------------
       
   125 // CIAUpdateFirstTimeInfo::SetAutomaticUpdatesAskedL
       
   126 // Set automatic update checks as prompted to an use
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CIAUpdateFirstTimeInfo::SetAutomaticUpdatesAskedL()
       
   130     {
       
   131 	ReadDataL();
       
   132 	iAutomaticUpdateChecksAsked = ETrue;
       
   133     WriteDataL();
       
   134     }
       
   135     
       
   136 // ---------------------------------------------------------------------------
       
   137 // CIAUpdateFirstTimeInfo::SetFirstTimeIfNotSetL
       
   138 // 
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CIAUpdateFirstTimeInfo::SetFirstTimeIfNotSetL()
       
   142     {
       
   143 	if ( !AutomaticUpdateChecksAskedL() )
       
   144 	    {
       
   145 		CIAUpdateFirstTimeDateFile* firstTimeDateFile = 
       
   146 		      CIAUpdateFirstTimeDateFile::NewLC( KIAUpdateFirstTimeDateFile );
       
   147 		if ( firstTimeDateFile->FirstTime().Int64() == 0 )
       
   148 		    {
       
   149 			firstTimeDateFile->SetCurrentFirstTime();
       
   150 			firstTimeDateFile->WriteDataL();
       
   151 		    }
       
   152 		CleanupStack::PopAndDestroy( firstTimeDateFile );   
       
   153 	    }
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CIAUpdateFirstTimeInfo::AgreementAcceptedL
       
   158 // Is Nokia agreement of Application Update accepted by an user
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 TBool CIAUpdateFirstTimeInfo::AgreementAcceptedL()
       
   162     {
       
   163     ReadDataL();
       
   164     return iAgreementAccepted;
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CIAUpdateFirstTimeInfo::AgreementAskedL
       
   170 // Is Nokia agreement of Application Update already asked 
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 TBool CIAUpdateFirstTimeInfo::AgreementAskedL()
       
   174     {
       
   175 	ReadDataL();
       
   176 	return iAgreementAsked;
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CIAUpdateFirstTimeInfo::AutomaticUpdateChecksAskedL
       
   181 // Is activation for automatic update cheks from network already asked 
       
   182 // ---------------------------------------------------------------------------
       
   183 //    
       
   184 TBool CIAUpdateFirstTimeInfo::AutomaticUpdateChecksAskedL()
       
   185     {
       
   186     ReadDataL();
       
   187     return iAutomaticUpdateChecksAsked;
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CIAUpdateFirstTimeInfo::FirstTimeDelayL
       
   192 // 
       
   193 // ---------------------------------------------------------------------------
       
   194 //    
       
   195 TBool CIAUpdateFirstTimeInfo::FirstTimeDelayL()
       
   196     {
       
   197     TBool firstTimeDelay = EFalse;
       
   198     if ( !AutomaticUpdateChecksAskedL() )
       
   199 	    {
       
   200 		CIAUpdateFirstTimeDateFile* firstTimeDateFile = 
       
   201 		      CIAUpdateFirstTimeDateFile::NewL( KIAUpdateFirstTimeDateFile );
       
   202     
       
   203         TTime firstTime( firstTimeDateFile->FirstTime() );
       
   204   
       
   205         delete firstTimeDateFile;
       
   206   
       
   207         TTime expireTime( firstTime );
       
   208 
       
   209         expireTime += KFirstTimeDelayInDays;
       
   210     
       
   211         TTime universalTime;
       
   212         universalTime.UniversalTime();
       
   213 
       
   214         if ( universalTime < expireTime && universalTime >= firstTime )
       
   215             {
       
   216         	firstTimeDelay = ETrue;
       
   217             }
       
   218 	    }
       
   219     return firstTimeDelay;	
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CIAUpdateFirstTimeInfo::ReadDataL
       
   224 //
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CIAUpdateFirstTimeInfo::ReadDataL()
       
   228 	{
       
   229 	RFile file;
       
   230     TInt err = file.Open( iFsSession, iPath, EFileRead|EFileShareAny );
       
   231     if ( err == KErrNotFound )
       
   232     	{
       
   233     	iAgreementAccepted = EFalse;
       
   234 	    iAgreementAsked = EFalse;
       
   235 	    iAutomaticUpdateChecksAsked = EFalse; 
       
   236     	}
       
   237     else
       
   238         {
       
   239         User::LeaveIfError( err );
       
   240         CleanupClosePushL( file );
       
   241     
       
   242         RFileReadStream stream( file, 0 );
       
   243         CleanupClosePushL( stream );
       
   244         InternalizeL( stream );
       
   245         CleanupStack::PopAndDestroy( &stream );	
       
   246         CleanupStack::PopAndDestroy( &file );
       
   247         }
       
   248 	}
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CIAUpdateFirstTimeInfo::WriteDataL
       
   252 //
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CIAUpdateFirstTimeInfo::WriteDataL()
       
   256 	{
       
   257 	TDriveUnit driveUnit( KIAUpdateFirstTimeDrive );
       
   258 	if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFsSession, KSizeOfFile, driveUnit ) )
       
   259 	    {
       
   260 		User::Leave( KErrDiskFull );
       
   261 	    }
       
   262 	RFile file;
       
   263     User::LeaveIfError( file.Replace( iFsSession, iPath, EFileWrite|EFileShareAny ) );
       
   264     CleanupClosePushL( file );
       
   265     
       
   266     RFileWriteStream stream( file, 0 );
       
   267     CleanupClosePushL( stream );
       
   268 
       
   269     ExternalizeL( stream );
       
   270     stream.CommitL();
       
   271         
       
   272     CleanupStack::PopAndDestroy( &stream );
       
   273     CleanupStack::PopAndDestroy( &file );
       
   274 	}
       
   275 
       
   276     
       
   277 // -----------------------------------------------------------------------------
       
   278 // CIAUpdateFirstTimeInfo::InternalizeL
       
   279 //
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CIAUpdateFirstTimeInfo::InternalizeL( RReadStream& aStream )
       
   283 	{
       
   284 	iAgreementAccepted = aStream.ReadInt32L();
       
   285 	iAgreementAsked = aStream.ReadInt32L();
       
   286 	iAutomaticUpdateChecksAsked = aStream.ReadInt32L();
       
   287 	}
       
   288 
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CIAUpdateFirstTimeInfo::ExternalizeL
       
   292 //
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CIAUpdateFirstTimeInfo::ExternalizeL( RWriteStream& aStream )
       
   296 	{
       
   297 	aStream.WriteInt32L( iAgreementAccepted );
       
   298 	aStream.WriteInt32L( iAgreementAsked );	
       
   299 	aStream.WriteInt32L( iAutomaticUpdateChecksAsked );
       
   300 	}
       
   301     
       
   302 // End of File