ipsservices/ipssosaoplugin/src/IpsSosAOMboxLogic.cpp
branchRCL_3
changeset 63 d189ee25cf9d
parent 13 0396474f30f5
child 64 3533d4323edc
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 * Description: 
    14 * Description: 
    15 *     Contains mailbox specified always online logic
    15 *     Contains mailbox specified always online logic
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 #include "ipssosaopluginheaders.h"
    20 //<cmail> internal dependency removed
    20 
    21 /*#ifdef _DEBUG
    21 //<QMail>
    22 #include "../../internal/IpsSosAOPluginTester/inc/IpsSosAOPluginTester.hrh"
       
    23 #endif // _DEBUG*/
       
    24 //</cmail>
       
    25 
       
    26 #include <cmmanager.h>
       
    27 
       
    28 #include "emailtrace.h"
       
    29 #include "IpsSosAOMboxLogic.h"
       
    30 #include "ipssetdataapi.h"
       
    31 #include "IpsSosAOSchedulerUtils.h"
       
    32 #include "IpsSosAOPlugin.hrh"
       
    33 #include "IpsSosAOImapPopLogic.h"
       
    34 
       
    35 const TInt KAOSecondsInMinute = 60;
    22 const TInt KAOSecondsInMinute = 60;
       
    23 //</QMail>
    36 const TInt KIpsSosAOMboxLogicMinGra = 1;
    24 const TInt KIpsSosAOMboxLogicMinGra = 1;
    37 
    25 
    38 // ----------------------------------------------------------------------------
    26 // ----------------------------------------------------------------------------
    39 // ----------------------------------------------------------------------------
    27 // ----------------------------------------------------------------------------
    40 //
    28 //
    41 CIpsSosAOMBoxLogic::CIpsSosAOMBoxLogic( 
    29 CIpsSosAOMBoxLogic::CIpsSosAOMBoxLogic( 
    42         CMsvSession& aSession, 
    30         CMsvSession& aSession, 
    43         TMsvId aMailboxId ) :
    31         TMsvId aMailboxId ) :
    44     iSession( aSession ), iMailboxId( aMailboxId ), iState( EStateError ),
    32     iSession( aSession ), iMailboxId( aMailboxId ), iState( EStateError ),
    45     iErrorCounter( 0 ), iError( KErrNone ), iTimer( NULL ),
    33     iErrorCounter( 0 ), iError( KErrNone ), iTimer( NULL ),
    46     iFetchMsgArray( KIpsSosAOMboxLogicMinGra ), iDataApi( NULL ), iAgent( NULL ),
    34 	//<QMail>
    47     iExtendedSettings( NULL ), iIsRoaming( EFalse )
    35     iFetchMsgArray( KIpsSosAOMboxLogicMinGra ), iAgent( NULL ),
       
    36     iIsRoaming( EFalse )
       
    37 	//</QMail>
    48     {
    38     {
    49     FUNC_LOG;
    39     FUNC_LOG;
    50     }
    40     }
    51 
    41 
    52 // ----------------------------------------------------------------------------
    42 // ----------------------------------------------------------------------------
    54 //
    44 //
    55 CIpsSosAOMBoxLogic::~CIpsSosAOMBoxLogic()
    45 CIpsSosAOMBoxLogic::~CIpsSosAOMBoxLogic()
    56     {
    46     {
    57     FUNC_LOG;
    47     FUNC_LOG;
    58     delete iTimer;
    48     delete iTimer;
    59     delete iDataApi;
    49 	//<QMail>
    60     delete iExtendedSettings;
    50 	//</QMail>
    61     delete iAgent;
    51     delete iAgent;
    62     iFetchMsgArray.Close();
    52     iFetchMsgArray.Close();
    63     }
    53     }
    64 
    54 
    65 // ----------------------------------------------------------------------------
    55 // ----------------------------------------------------------------------------
    83 //
    73 //
    84 void CIpsSosAOMBoxLogic::ConstructL()
    74 void CIpsSosAOMBoxLogic::ConstructL()
    85     {
    75     {
    86     FUNC_LOG;
    76     FUNC_LOG;
    87     iTimer = CIpsSosAOPluginTimer::NewL( CActive::EPriorityStandard, *this );
    77     iTimer = CIpsSosAOPluginTimer::NewL( CActive::EPriorityStandard, *this );
    88     iDataApi = CIpsSetDataApi::NewL( iSession );
    78 	//<QMail>
       
    79 
       
    80 	
    89     iAgent = CIpsSosAOBaseAgent::CreateAgentL( iSession, *this, iMailboxId );
    81     iAgent = CIpsSosAOBaseAgent::CreateAgentL( iSession, *this, iMailboxId );
    90     LoadSettingsL();
    82     
       
    83     //</QMail>
    91     }
    84     }
    92 
    85 
    93 // ----------------------------------------------------------------------------
    86 // ----------------------------------------------------------------------------
    94 // ----------------------------------------------------------------------------
    87 // ----------------------------------------------------------------------------
    95 //   
    88 //   
   175 // ----------------------------------------------------------------------------
   168 // ----------------------------------------------------------------------------
   176 //  
   169 //  
   177 void CIpsSosAOMBoxLogic::FetchMessagesL( const RArray<TMsvId> aArray )
   170 void CIpsSosAOMBoxLogic::FetchMessagesL( const RArray<TMsvId> aArray )
   178     {
   171     {
   179     FUNC_LOG;
   172     FUNC_LOG;
   180     LoadSettingsL();
   173     //<Qmail>
       
   174     
       
   175     //</Qmail>
   181     for ( TInt i = 0; i < aArray.Count(); i++ )
   176     for ( TInt i = 0; i < aArray.Count(); i++ )
   182         {
   177         {
   183         iFetchMsgArray.AppendL( aArray[i] );
   178         iFetchMsgArray.AppendL( aArray[i] );
   184         }
   179         }
   185     HandleEventAndSwitchStateL( EEventFetchMessages );
   180     HandleEventAndSwitchStateL( EEventFetchMessages );
   208 // 
   203 // 
   209 TBool CIpsSosAOMBoxLogic::IsEmnOn() const
   204 TBool CIpsSosAOMBoxLogic::IsEmnOn() const
   210     {
   205     {
   211     FUNC_LOG;
   206     FUNC_LOG;
   212     TBool ret = ETrue;
   207     TBool ret = ETrue;
   213     TIpsSetDataEmnStates state = EMailEmnOff;
   208 	//<QMail>
   214     if ( iExtendedSettings )
   209     CIpsSosAOSettingsHandler* settings = NULL;
   215         {
   210     TRAP_IGNORE( settings = 
   216         state = iExtendedSettings->EmailNotificationState();
   211             CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId));
   217         }
   212     
   218     if ( state == EMailEmnOff )
   213     if( settings )
   219         {
   214         {
   220         ret = EFalse;
   215         IpsServices::TIpsSetDataEmnStates state = IpsServices::EMailEmnOff;
   221         }
   216         state = settings->EmailNotificationState();
       
   217         
       
   218         if ( state == IpsServices::EMailEmnOff )
       
   219             {
       
   220             ret = EFalse;
       
   221             }
       
   222         
       
   223         delete settings;
       
   224         }
       
   225     
       
   226 	//</QMail>
   222     return ret;
   227     return ret;
   223     }
   228     }
   224 
   229 
   225 // ----------------------------------------------------------------------------
   230 // ----------------------------------------------------------------------------
   226 // ----------------------------------------------------------------------------
   231 // ----------------------------------------------------------------------------
   227 // 
   232 // 
       
   233 //<QMail>
   228 void CIpsSosAOMBoxLogic::GetEmailAddress(  
   234 void CIpsSosAOMBoxLogic::GetEmailAddress(  
   229     TBuf<KIpsSosAOTextBufferSize>& aEmailAddress ) const
   235     TBuf<KIpsSosAOTextBufferSize>& aEmailAddress ) const
   230     {
   236     {
   231     FUNC_LOG;
   237     FUNC_LOG;
   232     const TDesC& addr = iExtendedSettings->EmailAddress();
   238     CIpsSosAOSettingsHandler* settings = NULL;
   233     __ASSERT_DEBUG( ( 
   239 
   234             addr.Length() <= KIpsSosAOTextBufferSize ), 
   240     TRAPD( err, settings = CIpsSosAOSettingsHandler::NewL(
   235             User::Panic( KIpsSosAOPanicLit, KErrGeneral) );
   241             iSession, iMailboxId) );
   236     
   242     
   237     if ( addr.Length() <= KIpsSosAOTextBufferSize )
   243     if( settings )
   238         {
   244         {
   239         aEmailAddress.Copy( addr );
   245         HBufC* addr = NULL;
   240         }
   246         TRAP(err, addr = settings->EmailAddressL());
   241     }
   247         
   242 
   248         if( addr )
   243 // ----------------------------------------------------------------------------
   249             {
   244 // ----------------------------------------------------------------------------
   250             __ASSERT_DEBUG( ( 
   245 //  
   251                     addr->Length() <= KIpsSosAOTextBufferSize ), 
   246 //<cmail>
   252                     User::Panic( KIpsSosAOPanicLit, KErrGeneral) );
       
   253             
       
   254             if ( addr->Length() <= KIpsSosAOTextBufferSize )
       
   255                 {
       
   256                 aEmailAddress.Copy( *addr );
       
   257                 }
       
   258             delete addr;
       
   259             }   
       
   260         
       
   261         delete settings;
       
   262         }
       
   263     
       
   264 	//<QMail>
       
   265     }
       
   266 
       
   267 // ----------------------------------------------------------------------------
       
   268 // ----------------------------------------------------------------------------
       
   269 //<QMail>
   247 void CIpsSosAOMBoxLogic::SetEmnReceivedFlagL( TBool aNewValue )
   270 void CIpsSosAOMBoxLogic::SetEmnReceivedFlagL( TBool aNewValue )
   248 //</cmail>
   271     {
   249     {
   272     
   250     LoadSettingsL();
   273     CIpsSosAOSettingsHandler* settings = 
   251     iExtendedSettings->SetEmnReceivedButNotSyncedFlag( aNewValue );
   274             CIpsSosAOSettingsHandler::NewL(
   252     iDataApi->SaveExtendedSettingsL(
   275                 iSession, iMailboxId );
   253         *iExtendedSettings );
   276     CleanupStack::PushL(settings);
       
   277     
       
   278     settings->SetEmnReceivedButNotSyncedFlag( aNewValue );
       
   279     
       
   280     CleanupStack::PopAndDestroy(settings);
       
   281 	//</QMail>
   254     }
   282     }
   255 
   283 
   256 // ----------------------------------------------------------------------------
   284 // ----------------------------------------------------------------------------
   257 // ----------------------------------------------------------------------------
   285 // ----------------------------------------------------------------------------
   258 //
   286 //
   259 //<cmail>
       
   260 TBool CIpsSosAOMBoxLogic::IsMailboxRoamingStoppedL()
   287 TBool CIpsSosAOMBoxLogic::IsMailboxRoamingStoppedL()
   261 //</cmail>
       
   262     {
   288     {
   263     TBool ret = EFalse;
   289     TBool ret = EFalse;
   264     if ( iIsRoaming && !CanConnectIfRoamingL() )
   290     if ( iIsRoaming && !CanConnectIfRoamingL() )
   265         {
   291         {
   266         ret = ETrue;
   292         ret = ETrue;
   277     FUNC_LOG;
   303     FUNC_LOG;
   278     TInt event = aEvent;
   304     TInt event = aEvent;
   279     TInt cycles = 0;
   305     TInt cycles = 0;
   280     
   306     
   281     if ( event == EEventStart && iState == EStateError && 
   307     if ( event == EEventStart && iState == EStateError && 
   282             CanConnectIfRoamingL() )
   308           ( (iIsRoaming && CanConnectIfRoamingL())||
   283         {
   309              !iIsRoaming ) )
       
   310         {
       
   311         NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventStart");
   284         event = EEventNop;
   312         event = EEventNop;
   285         iAgent->LoadSettingsL();
   313         iAgent->LoadSettingsL();
   286         iTimer->Cancel();
   314         iTimer->Cancel();
       
   315         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", KIpsSosAOStartDelaySeconds);
   287         iTimer->After( KIpsSosAOStartDelaySeconds );
   316         iTimer->After( KIpsSosAOStartDelaySeconds );
   288         iState = EStateWaitSyncStart;
   317         iState = EStateWaitSyncStart;
       
   318         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   289         }
   319         }
   290     
   320     
   291     while ( event != EEventNop && iState != EStateError )
   321     while ( event != EEventNop && iState != EStateError )
   292         {
   322         {
   293 //<cmail> removing flags    
       
   294 /*#ifdef IPSSOSIMAPPOLOGGING_ON
       
   295         WriteDebugData( event );
       
   296 #endif*/
       
   297 //</cmail>
       
   298         switch ( event )
   323         switch ( event )
   299             {
   324             {
   300             case EEventTimerFired:
   325             case EEventTimerFired:
       
   326                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventTimerFired");
   301                 event = HandleTimerFiredL();
   327                 event = HandleTimerFiredL();
   302               break;
   328               break;
   303             case EEventStartSync:
   329             case EEventStartSync:
       
   330                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventStartSync");
   304                 if ( iState == EStateWaitSyncStart )
   331                 if ( iState == EStateWaitSyncStart )
   305                     {         
   332                     {         
   306                     iError = KErrNone;
   333                     iError = KErrNone;
   307                     iAgent->StartSyncL();
   334                     iAgent->StartSyncL();
   308                     iState = EStateSyncOngoing;
   335                     iState = EStateSyncOngoing;
       
   336                     NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateSyncOngoing");
   309                     }
   337                     }
   310                 else if ( iState == EStateIdleAndWaitCommands )
   338                 else if ( iState == EStateIdleAndWaitCommands )
   311                     {
   339                     {
   312                     // start sync command in idle state is currently 
   340                     // start sync command in idle state is currently 
   313                     // received when emn arrives, checking scheduling 
   341                     // received when emn arrives, checking scheduling 
   314                     // if user have selected week days / hours in setting
   342                     // if user have selected week days / hours in setting
       
   343 					//<QMail>
       
   344                     CIpsSosAOSettingsHandler* settings = 
       
   345                              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   346                     CleanupStack::PushL(settings);
       
   347                     
   315                     CIpsSosAOSchedulerUtils* scheduler = 
   348                     CIpsSosAOSchedulerUtils* scheduler = 
   316                         CIpsSosAOSchedulerUtils::NewLC( *iExtendedSettings );
   349                         CIpsSosAOSchedulerUtils::NewLC( *settings );
       
   350                         
   317                     TTimeIntervalSeconds seconds;
   351                     TTimeIntervalSeconds seconds;
   318                     TIpsSosAOConnectionType type = 
   352                     TIpsSosAOConnectionType type = 
   319                         scheduler->SecondsToNextMark( seconds );
   353                             scheduler->SecondsToNextMark( seconds );
       
   354                     
       
   355 					//</QMail>
   320                     if ( type == EAOCConnectAfter )
   356                     if ( type == EAOCConnectAfter )
   321                         {
   357                         {
       
   358                         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   322                         iState = EStateWaitSyncStart;
   359                         iState = EStateWaitSyncStart;
       
   360                         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", seconds);
   323                         iTimer->After( seconds );
   361                         iTimer->After( seconds );
   324                         //<cmail>
   362                         
   325                         SetEmnReceivedFlagL( ETrue );
   363                         SetEmnReceivedFlagL( ETrue );
   326                         //</cmail>
       
   327                         }
   364                         }
   328                     else
   365                     else
   329                         {
   366                         {
   330                         iError = KErrNone;
   367                         iError = KErrNone;
   331                         iAgent->StartSyncL();
   368                         iAgent->StartSyncL();
   332                         iState = EStateSyncOngoing;
   369                         iState = EStateSyncOngoing;
       
   370                         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateSyncOngoing");
   333                         }
   371                         }
   334                     CleanupStack::PopAndDestroy( scheduler );
   372 					//<QMail>
       
   373                     CleanupStack::PopAndDestroy( 2, settings );
       
   374 					//</QMail>
   335                     }
   375                     }
   336                 // ignore in other states
   376                 // ignore in other states
   337                 event = EEventNop;
   377                 event = EEventNop;
   338                 break;
   378                 break;
   339             case EEventFetchMessages:
   379             case EEventFetchMessages:
       
   380                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventFetchMessages");
   340                 if ( ( iState == EStateWaitSyncStart || 
   381                 if ( ( iState == EStateWaitSyncStart || 
   341                        iState == EStateIdleAndWaitCommands ) &&
   382                        iState == EStateIdleAndWaitCommands ) &&
   342                         iFetchMsgArray.Count() > 0 )
   383                         iFetchMsgArray.Count() > 0 )
   343                     {
   384                     {
   344                     iError = KErrNone;
   385                     iError = KErrNone;
   345                     iAgent->StartFetchMessagesL( iFetchMsgArray );
   386                     iAgent->StartFetchMessagesL( iFetchMsgArray );
   346                     iFetchMsgArray.Reset();
   387                     iFetchMsgArray.Reset();
       
   388                     NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateFetchOngoing");
   347                     iState = EStateFetchOngoing;
   389                     iState = EStateFetchOngoing;
   348                     }
   390                     }
   349                 else 
   391                 else 
   350                     {
   392                     {
   351                     // ignore event in other states
   393                     // ignore event in other states
   352                     iFetchMsgArray.Reset();
   394                     iFetchMsgArray.Reset();
   353                     }
   395                     }
   354                 event = EEventNop;
   396                 event = EEventNop;
   355                 break;
   397                 break;
   356             case EEventOperationCompleted:
   398             case EEventOperationCompleted:
       
   399                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventOperationCompleted");
   357                 event = HandleOperationCompletionL();
   400                 event = HandleOperationCompletionL();
   358                 break;
   401                 break;
   359             case EEventSuspendOperations:
   402             case EEventSuspendOperations:
       
   403                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventSuspendOperations");
   360                 SuspendOperations();
   404                 SuspendOperations();
   361                 iState = EStateSuspended;
   405                 iState = EStateSuspended;
   362                 event = EEventNop;
   406                 event = EEventNop;
   363                 break;
   407                 break;
   364             case EEventContinueOperations:
   408             case EEventContinueOperations:
       
   409                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventContinueOperations");
   365                 if ( iState == EStateSuspended )
   410                 if ( iState == EStateSuspended )
   366                     {
   411                     {
       
   412                     INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", KIpsSosAOContinueWaitTime);
   367                     iTimer->After( KIpsSosAOContinueWaitTime );
   413                     iTimer->After( KIpsSosAOContinueWaitTime );
   368                     }
   414                     }
   369                 else
   415                 event = EEventNop;
   370                     {
       
   371                     event = EEventNop;
       
   372                     }
       
   373                 // ignore if in other states
   416                 // ignore if in other states
   374                 break;
   417                 break;
   375             case EEventStopAndRemoveOps:
   418             case EEventStopAndRemoveOps:
       
   419                 NM_COMMENT("CIpsSosAOMBoxLogic: event: EEventStopAndRemoveOps");
   376                 // notify deletion
   420                 // notify deletion
   377                 iAgent->CancelAllAndDisconnectL();
   421                 iAgent->CancelAllAndDisconnectL();
   378                 iTimer->Cancel();
   422                 iTimer->Cancel();
       
   423                 NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateError");
   379                 iState = EStateError;
   424                 iState = EStateError;
   380                 event = EEventNop;
   425                 event = EEventNop;
   381                 break;
   426                 break;
   382             case EEventStart:
   427             case EEventStart:
   383             default:
   428             default:
   430     CIpsSosAOBaseAgent::TAgentState agentState = iAgent->GetState();
   475     CIpsSosAOBaseAgent::TAgentState agentState = iAgent->GetState();
   431     if ( iState == EStateSuspended &&
   476     if ( iState == EStateSuspended &&
   432         ( agentState == CIpsSosAOBaseAgent::EStateConnectAndSyncOnHold || 
   477         ( agentState == CIpsSosAOBaseAgent::EStateConnectAndSyncOnHold || 
   433           agentState == CIpsSosAOBaseAgent::EStatePopulateOnHold ) )
   478           agentState == CIpsSosAOBaseAgent::EStatePopulateOnHold ) )
   434         {
   479         {
       
   480         iTimer->Cancel();
   435         iAgent->ContinueHoldOperations();
   481         iAgent->ContinueHoldOperations();
       
   482         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateSyncOngoing");
   436         iState = EStateSyncOngoing;
   483         iState = EStateSyncOngoing;
   437         }
   484         }
   438     else if ( iState == EStateSuspended && 
   485     else if ( iState == EStateSuspended && 
   439             agentState == CIpsSosAOBaseAgent::EStateFetchOnHold )
   486             agentState == CIpsSosAOBaseAgent::EStateFetchOnHold )
   440         {
   487         {
       
   488         iTimer->Cancel();
   441         iAgent->ContinueHoldOperations();
   489         iAgent->ContinueHoldOperations();
       
   490         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateFetchOngoing");
   442         iState = EStateFetchOngoing;
   491         iState = EStateFetchOngoing;
   443         }
   492         }
   444     else
   493     else
   445         {
   494         {
   446         event = CheckSchedulingAndSwitchStateL();
   495         event = CheckSchedulingAndSwitchStateL();
   455 // 
   504 // 
   456 TInt CIpsSosAOMBoxLogic::HandleOperationCompletionL()
   505 TInt CIpsSosAOMBoxLogic::HandleOperationCompletionL()
   457     {
   506     {
   458     FUNC_LOG;
   507     FUNC_LOG;
   459     TInt event = EEventNop;
   508     TInt event = EEventNop;
       
   509 	//<Qmail>
       
   510     CIpsSosAOSettingsHandler* settings = 
       
   511              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   512     CleanupStack::PushL(settings);
       
   513 	//</Qmail>     
   460     if ( iState == EStateSyncOngoing )
   514     if ( iState == EStateSyncOngoing )
   461         {
   515         {
       
   516         INFO_1("CIpsSosAOMBoxLogic: operation completed error: %d", iError);
       
   517         bool doSaveSyncTime = EFalse;
   462         if ( !( iError == KErrNone || iError == KErrCancel ) )
   518         if ( !( iError == KErrNone || iError == KErrCancel ) )
   463             {
   519             {
   464             ++iErrorCounter;
   520             ++iErrorCounter;
   465             }
   521             }
   466         else
   522         else
   467             {
   523             {
       
   524             if (iError == KErrNone)
       
   525                 {
       
   526                 doSaveSyncTime = ETrue;
       
   527                 }
   468             iError = KErrNone;
   528             iError = KErrNone;
   469             iErrorCounter = 0;
   529             iErrorCounter = 0;
   470             }
   530             }
   471         //<cmail>
   531         
   472         if ( iError != KErrNone && 
   532         if ( iError != KErrNone && 
   473                 IsErrorFatalL( iError ) )
   533                 IsErrorFatalL( iError ) )
   474         //</cmail>
       
   475             {
   534             {
   476             iAgent->CancelAllAndDisconnectL();
   535             iAgent->CancelAllAndDisconnectL();
   477             // switch ao off
   536             // switch ao off
   478             iExtendedSettings->SetAlwaysOnlineState( EMailAoOff );
   537 			//<QMail>
       
   538             
       
   539             settings->SetAlwaysOnlineState( IpsServices::EMailAoOff );
   479             // emn not swithced of if its going to be "always on" in
   540             // emn not swithced of if its going to be "always on" in
   480             // future
   541             // future
   481             iExtendedSettings->SetEmnReceivedButNotSyncedFlag( EFalse );
   542             
   482             iDataApi->SaveExtendedSettingsL(
   543             settings->SetEmnReceivedButNotSyncedFlag( EFalse );
   483                 *iExtendedSettings );
   544             //</QMail>
       
   545             NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateError");
   484             iState = EStateError;
   546             iState = EStateError;
   485             iErrorCounter = 0;
   547             iErrorCounter = 0;
   486             }
   548             }
   487         else if ( iError != KErrNone && 
   549         else if ( iError != KErrNone && 
   488                 iErrorCounter < KIpsSosAOMaxReTryTimes )
   550                 iErrorCounter < KIpsSosAOMaxReTryTimes )
   489             {
   551             {
   490             // not fatal error
   552             // not fatal error
   491             TIpsSetDataAoStates state = iExtendedSettings->AlwaysOnlineState();
   553 			//<QMail>
   492             if ( state == EMailAoOff )
   554             IpsServices::TIpsSetDataAoStates state = 
       
   555                     settings->AlwaysOnlineState();
       
   556             
       
   557             if ( state == IpsServices::EMailAoOff )
   493                 {
   558                 {
       
   559                 NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateIdleAndWaitCommands");
   494                 iState = EStateIdleAndWaitCommands;
   560                 iState = EStateIdleAndWaitCommands;
   495                 }
   561                 }
   496             else
   562             else
   497                 {
   563                 {
   498                 if( !iTimer->IsActive() )
   564                 if( !iTimer->IsActive() )
   499                     {
   565                     {
   500                 iTimer->After( KIpsSosAOReTryInterval );
   566                     INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", KIpsSosAOReTryInterval);
       
   567                     iTimer->After( KIpsSosAOReTryInterval );
   501                     }
   568                     }
       
   569                 NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   502                 iState = EStateWaitSyncStart;
   570                 iState = EStateWaitSyncStart;
   503                 }
   571                 }
       
   572 
       
   573 			//</QMail>
   504             }
   574             }
   505         else if ( iError != KErrNone && 
   575         else if ( iError != KErrNone && 
   506                 iErrorCounter >= KIpsSosAOMaxReTryTimes )
   576                 iErrorCounter >= KIpsSosAOMaxReTryTimes )
   507             {
   577             {
   508             //<cmail>
   578             
   509             SetEmnReceivedFlagL( EFalse );
   579             SetEmnReceivedFlagL( EFalse );
   510             //</cmail>
       
   511             // not fatal, but all re trys are gone
   580             // not fatal, but all re trys are gone
   512             CalculateToNextIntervalL();
   581             CalculateToNextIntervalL();
   513             }
   582             }
   514         else
   583         else
   515             {
   584             {
   516             // no errors
   585             // no errors
   517             // update successfull sync time to settings
   586             // update successfull sync time to settings
   518             SaveSuccessfulSyncTimeL();
   587             if (doSaveSyncTime)
       
   588                 {
       
   589                 SaveSuccessfulSyncTimeL();
       
   590                 }
   519             // and adjust timer to sync interval
   591             // and adjust timer to sync interval
   520             CalculateToNextIntervalL();
   592             CalculateToNextIntervalL();
   521             }
   593             }
   522         }
   594         }
   523     else if ( iState == EStateFetchOngoing )
   595     else if ( iState == EStateFetchOngoing )
   524         {
   596         {
   525         iError = KErrNone;
   597         iError = KErrNone;
   526         if ( iTimer->IsActive() )
   598         if ( iTimer->IsActive() )
   527             {
   599             {
       
   600             NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   528             iState = EStateWaitSyncStart;
   601             iState = EStateWaitSyncStart;
   529             }
   602             }
   530         else
   603         else
   531             {
   604             {
   532             event = CheckSchedulingAndSwitchStateL();          
   605             event = CheckSchedulingAndSwitchStateL();          
   533             }
   606             }
   534         }
   607         }
       
   608 		//<Qmail>
       
   609     CleanupStack::PopAndDestroy(settings);
       
   610 	//</Qmail>
   535     return event;
   611     return event;
   536     }
   612     }
   537 
   613 
   538 // ----------------------------------------------------------------------------
   614 // ----------------------------------------------------------------------------
   539 // ----------------------------------------------------------------------------
   615 // ----------------------------------------------------------------------------
   543     FUNC_LOG;
   619     FUNC_LOG;
   544     if ( iState == EStateSyncOngoing || iState == EStateFetchOngoing )
   620     if ( iState == EStateSyncOngoing || iState == EStateFetchOngoing )
   545         {
   621         {
   546         iAgent->HoldOperations();
   622         iAgent->HoldOperations();
   547         }
   623         }
   548     iState = EStateSuspended;
       
   549     // set suspend watchdog, if clien not continue this
   624     // set suspend watchdog, if clien not continue this
   550     // ensure ao logic to continue
   625     // ensure ao logic to continue
   551     if ( !iTimer->IsActive() )
   626     if ( !iTimer->IsActive() || iState == EStateSyncOngoing || iState == EStateFetchOngoing)
   552         {
   627         {
       
   628         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", KIpsSosAOSuspendWatchdogTime);
   553         iTimer->After( KIpsSosAOSuspendWatchdogTime );
   629         iTimer->After( KIpsSosAOSuspendWatchdogTime );
   554         }
   630         }
   555     }
   631     NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateSuspended");
   556 
   632     iState = EStateSuspended;
   557 // ----------------------------------------------------------------------------
   633     }
   558 // ----------------------------------------------------------------------------
   634 
   559 //
   635 // ----------------------------------------------------------------------------
   560 //<cmail>
   636 // ----------------------------------------------------------------------------
       
   637 //<QMail>
       
   638 
   561 TBool CIpsSosAOMBoxLogic::IsErrorFatalL( TInt aError )
   639 TBool CIpsSosAOMBoxLogic::IsErrorFatalL( TInt aError )
   562 //</cmail>
       
   563     {
   640     {
   564     FUNC_LOG;
   641     FUNC_LOG;
   565     // error can be fatal only if we haven't got successful connect
   642     // error can be fatal only if we haven't got successful connect
   566     // in mailbox ever and error is something else than KErrNone or
   643     // in mailbox ever and error is something else than KErrNone or
   567     // KErrCancel, and retry interval is reached
   644     // KErrCancel, and retry interval is reached
   568     TBool ret = EFalse;
   645     TBool ret = EFalse;
   569     LoadSettingsL();
   646     //<Qmail>
   570     TAOInfo info = iExtendedSettings->LastUpdateInfo();
   647     
       
   648     //</Qmail>
       
   649     
       
   650     CIpsSosAOSettingsHandler* settings = 
       
   651              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   652     CleanupStack::PushL(settings);
       
   653     
       
   654     IpsServices::TAOInfo info = settings->LastUpdateInfo();
   571     if ( aError != KErrNone && aError != KErrCancel 
   655     if ( aError != KErrNone && aError != KErrCancel 
   572             && !info.iUpdateSuccessfulWithCurSettings
   656             && !info.iUpdateSuccessfulWithCurSettings
   573             && iErrorCounter >= KIpsSosAOMaxReTryTimes )
   657             && iErrorCounter >= KIpsSosAOMaxReTryTimes )
   574         {
   658         {
   575         ret = ETrue;
   659         ret = ETrue;
   576         }
   660         }
       
   661     
       
   662     CleanupStack::PopAndDestroy(settings);
       
   663     //</QMail>
   577     return ret;
   664     return ret;
   578     }
   665     }
   579 
   666 
   580 // ----------------------------------------------------------------------------
   667 // ----------------------------------------------------------------------------
   581 // ----------------------------------------------------------------------------
   668 // ----------------------------------------------------------------------------
   582 //
   669 //
   583 CIpsSosAOMBoxLogic::TMBoxLogicEvent 
   670 CIpsSosAOMBoxLogic::TMBoxLogicEvent 
   584     CIpsSosAOMBoxLogic::CheckSchedulingAndSwitchStateL()
   671     CIpsSosAOMBoxLogic::CheckSchedulingAndSwitchStateL()
   585     {
   672     {
   586      //<cmail> logs removed </cmail>
   673 	//<Qmail>
       
   674     FUNC_LOG;
   587     iTimer->Cancel();
   675     iTimer->Cancel();
   588     TMBoxLogicEvent event = EEventNop;
   676     TMBoxLogicEvent event = EEventNop;
   589     TTimeIntervalSeconds secondsToConnect = CalculateScheduledSyncTimeL();
   677     TTimeIntervalSeconds secondsToConnect = CalculateScheduledSyncTimeL();
   590     //<cmail> logs removed </cmail>
   678     
       
   679     CIpsSosAOSettingsHandler* settings = 
       
   680              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   681     CleanupStack::PushL(settings);
       
   682       
   591     if ( secondsToConnect.Int() == 0 )
   683     if ( secondsToConnect.Int() == 0 )
   592         {
   684         {
   593         //check last successfull sync time and check is interval reached
   685         //check last successfull sync time and check is interval reached
   594         TAOInfo info = iExtendedSettings->LastUpdateInfo();
   686 
       
   687     
       
   688         IpsServices::TAOInfo info = settings->LastUpdateInfo();
   595         if ( !info.iUpdateSuccessfulWithCurSettings )
   689         if ( !info.iUpdateSuccessfulWithCurSettings )
   596             {
   690             {
   597             event = EEventStartSync;
   691             event = EEventStartSync;
   598             }
   692             }
   599         else 
   693         else 
   600             {
   694             {
   601             TTime now;
   695             TTime now;
   602             now.HomeTime();
   696             now.HomeTime();
   603             TInt interval = 
   697             TInt interval = 
   604                 iExtendedSettings->InboxRefreshTime() * KAOSecondsInMinute;
   698                     settings->InboxRefreshTime() * KAOSecondsInMinute;
   605             TTimeIntervalSeconds secsFromLastSync;
   699             TTimeIntervalSeconds secsFromLastSync;
   606             now.SecondsFrom( info.iLastSuccessfulUpdate, secsFromLastSync );
   700             now.SecondsFrom( info.iLastSuccessfulUpdate, secsFromLastSync );
   607             if ( (secsFromLastSync.Int() > 0) && ( 
   701             if ( (secsFromLastSync.Int() > 0) && ( 
   608                     secsFromLastSync.Int() < interval ) )
   702                     secsFromLastSync.Int() < interval ) )
   609                 {
   703                 {
   610                 // adjust timer to correct sync time
   704                 // adjust timer to correct sync time
   611                 iTimer->After(interval - secsFromLastSync.Int());        
   705                 TInt syncAfter = interval - secsFromLastSync.Int();
       
   706                 INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", syncAfter);
       
   707                 iTimer->After(syncAfter); 
       
   708                 NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   612                 iState = EStateWaitSyncStart;
   709                 iState = EStateWaitSyncStart;
   613                 }
   710                 }
   614             else
   711             else
   615                 {
   712                 {
   616                 event = EEventStartSync;
   713                 event = EEventStartSync;
   617                 }
   714                 }
   618             }
   715             }
       
   716         
   619         }
   717         }
   620     else if ( secondsToConnect.Int() == KErrNotFound )
   718     else if ( secondsToConnect.Int() == KErrNotFound )
   621         {
   719         {
   622         // means that ao is not on (but emn is)
   720         // means that ao is not on (but emn is)
       
   721         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateIdleAndWaitCommands");
   623         iState = EStateIdleAndWaitCommands;
   722         iState = EStateIdleAndWaitCommands;
   624         if ( iExtendedSettings->EmnReceivedButNotSyncedFlag() )
   723       
       
   724         if ( settings->EmnReceivedButNotSyncedFlag() )
   625             {
   725             {
   626             // got emn when logic was stopped
   726             // got emn when logic was stopped
   627             event = EEventStartSync;
   727             event = EEventStartSync;
   628             }
   728             }
   629         }
   729         }
   630     else
   730     else
   631         {
   731         {
       
   732         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", secondsToConnect);
   632         iTimer->After( secondsToConnect );
   733         iTimer->After( secondsToConnect );
       
   734         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   633         iState = EStateWaitSyncStart;
   735         iState = EStateWaitSyncStart;
   634         }
   736         
   635     
   737 
       
   738         }
       
   739     CleanupStack::PopAndDestroy(settings);
       
   740     //</Qmail>
   636     return event;
   741     return event;
   637     }
   742     }
   638 
   743 
   639 // ----------------------------------------------------------------------------
   744 // ----------------------------------------------------------------------------
   640 // ----------------------------------------------------------------------------
   745 // ----------------------------------------------------------------------------
   641 //
   746 //
   642 void CIpsSosAOMBoxLogic::CalculateToNextIntervalL()
   747 void CIpsSosAOMBoxLogic::CalculateToNextIntervalL()
   643     {
   748     {
   644     FUNC_LOG;
   749     FUNC_LOG;
   645     //<cmail> logs removed </cmail>
   750     
   646     iTimer->Cancel();
   751     iTimer->Cancel();
   647     TTimeIntervalSeconds interval;
   752     TTimeIntervalSeconds interval;
   648     // first check and calculate scheduling function also loads settings
   753     // first check and calculate scheduling function also loads settings
   649     interval = CalculateScheduledSyncTimeL();
   754     interval = CalculateScheduledSyncTimeL();
   650     //<cmail> logs removed </cmail>
   755     
   651     if ( interval.Int() == 0 )
   756     if ( interval.Int() == 0 )
   652         {
   757         {
   653         // add next interval, if interval is grater than 0 it means
   758         // add next interval, if interval is grater than 0 it means
   654         // that off-line time is going, user have selected days / times from
   759         // that off-line time is going, user have selected days / times from
   655         // settings
   760         // settings
   656         iTimer->After( 
   761 		
   657                 iExtendedSettings->InboxRefreshTime() * KAOSecondsInMinute );
   762 		//<QMail>
       
   763         CIpsSosAOSettingsHandler* settings = 
       
   764                  CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   765         CleanupStack::PushL(settings);
       
   766         TInt inboxRefreshTime = settings->InboxRefreshTime();
       
   767         TInt secs = inboxRefreshTime * KAOSecondsInMinute;
       
   768         INFO_1("CIpsSosAOMBoxLogic: inboxRefreshTime: %d", inboxRefreshTime);
       
   769         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", secs);
       
   770         if (secs > 0) 
       
   771             {
       
   772             iTimer->After(TTimeIntervalSeconds(secs));
       
   773             }
       
   774         else 
       
   775             {
       
   776             // panic at this point when we get zero time from settings
       
   777             __ASSERT_DEBUG( EFalse, User::Panic( KIpsSosAOPanicLit, KErrGeneral) );
       
   778             iTimer->After(TTimeIntervalSeconds(KAODefaultInboxSyncTimeSecs));
       
   779             }
       
   780             
       
   781         CleanupStack::PopAndDestroy(settings);
       
   782 	   //</QMail>
       
   783         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   658         iState = EStateWaitSyncStart;
   784         iState = EStateWaitSyncStart;
   659         }
   785         }
   660     else if ( interval.Int() > 0 )
   786     else if ( interval.Int() > 0 )
   661         {
   787         {
       
   788         INFO_1("CIpsSosAOMBoxLogic: timer scheduled: %d", interval);
   662         iTimer->After( interval );
   789         iTimer->After( interval );
       
   790         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateWaitSyncStart");
   663         iState = EStateWaitSyncStart;
   791         iState = EStateWaitSyncStart;
   664         }
   792         }
   665     else 
   793     else 
   666         {
   794         {
       
   795         NM_COMMENT("CIpsSosAOMBoxLogic: switching state: EStateIdleAndWaitCommands");
   667         iState = EStateIdleAndWaitCommands;
   796         iState = EStateIdleAndWaitCommands;
   668         }
   797         }
   669     
   798     
   670     }
   799     }
   671 
   800 
   672 // ----------------------------------------------------------------------------
   801 // ----------------------------------------------------------------------------
   673 // ----------------------------------------------------------------------------
   802 // ----------------------------------------------------------------------------
   674 //
   803 //
   675 TTimeIntervalSeconds CIpsSosAOMBoxLogic::CalculateScheduledSyncTimeL()
   804 TTimeIntervalSeconds CIpsSosAOMBoxLogic::CalculateScheduledSyncTimeL()
   676     {
   805     {
   677     FUNC_LOG;
   806     FUNC_LOG;    
   678     //<cmail> logs removed </cmail> 
   807 	//<Qmail>
   679     LoadSettingsL();
   808     
   680     TTimeIntervalSeconds seconds;
   809     TTimeIntervalSeconds seconds=KErrNotFound;
   681     
   810 	
       
   811     
       
   812     CIpsSosAOSettingsHandler* settings = 
       
   813              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   814     CleanupStack::PushL(settings);
       
   815             
   682     // first check is ao or emn on at all
   816     // first check is ao or emn on at all
   683     if ( (iExtendedSettings->AlwaysOnlineState() == EMailAoOff && 
   817     if ( (settings->AlwaysOnlineState() == IpsServices::EMailAoOff && 
   684             iExtendedSettings->EmailNotificationState() == EMailEmnOff  )||
   818             settings->EmailNotificationState() == IpsServices::EMailEmnOff  )||
   685         iExtendedSettings->SelectedWeekDays() == 0 ) // no week days chosen
   819             settings->SelectedWeekDays() == 0 ) // no week days chosen
   686         {
   820         {
   687         // no timed sync on
   821         // no timed sync on
       
   822         CleanupStack::PopAndDestroy(settings);    
   688         return KErrNotFound;
   823         return KErrNotFound;
   689         }
   824         }
   690     
   825     
   691     if ( iExtendedSettings->EmailNotificationState() != EMailEmnOff && 
   826     if ( settings->EmailNotificationState() != IpsServices::EMailEmnOff && 
   692          !iExtendedSettings->EmnReceivedButNotSyncedFlag()   )
   827          !settings->EmnReceivedButNotSyncedFlag()   )
   693         {
   828         {
       
   829         CleanupStack::PopAndDestroy(settings);
   694         return KErrNotFound;
   830         return KErrNotFound;
   695         }
   831         }
   696     
   832     
   697     
   833     
   698     CIpsSosAOSchedulerUtils* scheduler = CIpsSosAOSchedulerUtils::NewLC(
   834     CIpsSosAOSchedulerUtils* scheduler = CIpsSosAOSchedulerUtils::NewLC(
   699         *iExtendedSettings );
   835         *settings );
   700 
   836 
   701     TIpsSosAOConnectionType type = scheduler->SecondsToNextMark( seconds );
   837     TIpsSosAOConnectionType type = scheduler->SecondsToNextMark( seconds );
   702     if ( type == EAOCDisconnectAfter ) 
   838     if ( type == EAOCDisconnectAfter ) 
   703         {
   839         {
   704         // if type is EAOCDisconnectAfter it means that scheduled days / times
   840         // if type is EAOCDisconnectAfter it means that scheduled days / times
   710     else
   846     else
   711         {
   847         {
   712         // this means that user have choosed time/day schedule at 
   848         // this means that user have choosed time/day schedule at 
   713         // timed sync and now we have to wait sync time
   849         // timed sync and now we have to wait sync time
   714         }
   850         }
   715     CleanupStack::PopAndDestroy( scheduler );
   851     CleanupStack::PopAndDestroy( 2, settings );
       
   852     
       
   853 	//</QMail>
   716     return seconds;
   854     return seconds;
   717     }
   855     }
   718 
   856 
   719 // ----------------------------------------------------------------------------
   857 // ----------------------------------------------------------------------------
   720 // ----------------------------------------------------------------------------
   858 // ----------------------------------------------------------------------------
   721 //
   859 //
   722 void CIpsSosAOMBoxLogic::LoadSettingsL()
   860 void CIpsSosAOMBoxLogic::LoadSettingsL()
   723     {
   861     {
   724     FUNC_LOG;
   862     FUNC_LOG;
   725     //<cmail> logs removed </cmail> 
   863     //<QMail>
   726     delete iExtendedSettings;
   864     //removed loading
   727     iExtendedSettings = NULL;
   865 	//</QMail>
   728     iExtendedSettings = CIpsSetDataExtension::NewL();
       
   729     iDataApi->LoadExtendedSettingsL( iMailboxId, *iExtendedSettings );
       
   730     //<cmail> logs removed </cmail>
       
   731     }
   866     }
   732 
   867 
   733 // ----------------------------------------------------------------------------
   868 // ----------------------------------------------------------------------------
   734 // ----------------------------------------------------------------------------
   869 // ----------------------------------------------------------------------------
   735 //
   870 //
   736 void CIpsSosAOMBoxLogic::SaveSuccessfulSyncTimeL()
   871 void CIpsSosAOMBoxLogic::SaveSuccessfulSyncTimeL()
   737     {
   872     {
   738     FUNC_LOG;
   873     FUNC_LOG;
   739     TTime now;
   874     TTime now;
   740     now.HomeTime();
   875     now.HomeTime();
   741     LoadSettingsL();
   876     //<QMail>
   742     TAOInfo info;
   877     
       
   878 	
       
   879     CIpsSosAOSettingsHandler* settings = 
       
   880              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   881     CleanupStack::PushL(settings);
       
   882         
       
   883     IpsServices::TAOInfo info;
   743     info.iLastSuccessfulUpdate = now;
   884     info.iLastSuccessfulUpdate = now;
   744     info.iUpdateSuccessfulWithCurSettings = ETrue;
   885     info.iUpdateSuccessfulWithCurSettings = ETrue;
   745     info.iLastUpdateFailed=EFalse;
   886     settings->SetLastUpdateInfo( info );
   746     iExtendedSettings->SetLastUpdateInfo( info );
       
   747     // clear flag
   887     // clear flag
   748     iExtendedSettings->SetEmnReceivedButNotSyncedFlag( EFalse );
   888     settings->SetEmnReceivedButNotSyncedFlag( EFalse );
   749     iDataApi->SaveExtendedSettingsL(
   889             
   750             *iExtendedSettings );
   890     CleanupStack::PopAndDestroy(settings);
       
   891 	//</QMail>
   751     }
   892     }
   752 
   893 
   753 // ----------------------------------------------------------------------------
   894 // ----------------------------------------------------------------------------
   754 // ----------------------------------------------------------------------------
   895 // ----------------------------------------------------------------------------
   755 TBool CIpsSosAOMBoxLogic::CanConnectIfRoamingL()
   896 TBool CIpsSosAOMBoxLogic::CanConnectIfRoamingL()
   756     {
   897     {
   757     FUNC_LOG;
   898     FUNC_LOG;
   758     TBool ret = ETrue;
   899     TBool ret = EFalse;
   759 
   900     //<Qmail>
   760     RCmManager cmManager;
   901     RCmManager mgr;
   761     cmManager.OpenLC();
   902     CleanupClosePushL(mgr);
   762     TCmGenConnSettings OccSettings;
   903     TRAPD(err, mgr.OpenL());
   763     
   904     
   764     //ask roaming settings from occ
   905     TCmGenConnSettings set;
   765     cmManager.ReadGenConnSettingsL(OccSettings);
   906     if(err==KErrNone){
   766     if(OccSettings.iCellularDataUsageVisitor == ECmCellularDataUsageDisabled && iIsRoaming)
   907         TRAP(err, mgr.ReadGenConnSettingsL(set));
   767         {
   908         }
       
   909     
       
   910     CleanupStack::PopAndDestroy(&mgr);
       
   911     
       
   912     if( err==KErrNone && 
       
   913             set.iCellularDataUsageVisitor == ECmCellularDataUsageAutomatic){
       
   914         ret = ETrue;
       
   915         }
       
   916     else{
   768         ret = EFalse;
   917         ret = EFalse;
   769         }
   918         }
   770     
   919    
   771     CleanupStack::PopAndDestroy(&cmManager); // cmManager
   920     //</QMail>
   772     
       
   773     return ret;          
   921     return ret;          
   774     }
   922     }
   775 
   923 
   776 // ----------------------------------------------------------------------------
   924 // ----------------------------------------------------------------------------
   777 // ----------------------------------------------------------------------------
   925 // ----------------------------------------------------------------------------
   778 TBool CIpsSosAOMBoxLogic::FirstEMNReceived()
   926 TBool CIpsSosAOMBoxLogic::FirstEMNReceived()
   779     {
   927     {
   780     return iExtendedSettings->FirstEmnReceived();
   928 	//<QMail>
       
   929     CIpsSosAOSettingsHandler* settings = NULL;
       
   930     TBool ret = EFalse;
       
   931     TRAP_IGNORE(CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId));
       
   932     if(settings){
       
   933         ret = settings->FirstEmnReceived();
       
   934         delete settings;
       
   935         }
       
   936     
       
   937     return ret;
       
   938     
       
   939 	//</QMail>
   781     }
   940     }
   782 
   941 
   783 // ----------------------------------------------------------------------------
   942 // ----------------------------------------------------------------------------
   784 // ----------------------------------------------------------------------------
   943 // ----------------------------------------------------------------------------
   785 void CIpsSosAOMBoxLogic::SetFirstEMNReceived()
   944 void CIpsSosAOMBoxLogic::SetFirstEMNReceived()
   786     {
   945     {
   787     TRAP_IGNORE( LoadSettingsL() );
   946     //<QMail>
   788     iExtendedSettings->SetFirstEmnReceived( ETrue );
   947     
   789     
   948     CIpsSosAOSettingsHandler* settings = NULL;
   790     //if alwaysonline was allowed to roam, so will EMN be.
   949     TRAP_IGNORE( settings = 
   791     iExtendedSettings->SetEmailNotificationState( EMailEmnAutomatic );
   950             CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId));
   792     
   951     
   793     
   952     if(settings){
   794     // set always online state off when emn is on
   953         settings->SetFirstEmnReceived( ETrue );
   795     iExtendedSettings->SetAlwaysOnlineState( EMailAoOff );    
   954         
   796     iExtendedSettings->SetInboxRefreshTime( KErrNotFound );
   955     
   797     
   956         //if alwaysonline was allowed to roam, so will EMN be.
   798     TRAP_IGNORE( iDataApi->SaveExtendedSettingsL(
   957         settings->SetEmailNotificationState(
   799        *iExtendedSettings ) );    
   958             settings->AlwaysOnlineState() == 
   800     
   959             IpsServices::EMailAoAlways ? 
   801     }
   960                 IpsServices::EMailEmnAutomatic : IpsServices::EMailEmnHomeOnly );
   802 //<cmail> removing flags
   961         
   803 /*
   962         
   804 #ifdef IPSSOSIMAPPOLOGGING_ON
   963         // set always online state off when emn is on
   805 // ----------------------------------------------------------------------------
   964         settings->SetAlwaysOnlineState( IpsServices::EMailAoOff );
   806 // ----------------------------------------------------------------------------
   965         delete settings;
   807 //
   966         }
   808 void CIpsSosAOMBoxLogic::WriteDebugData( TInt aEvent )
   967     
   809     {
   968 	//</QMail>
   810     switch ( aEvent )
   969     }
   811         {
       
   812         case EEventTimerFired:
       
   813             break;
       
   814         case EEventStartSync:
       
   815             break;
       
   816         case EEventFetchMessages:
       
   817             break;
       
   818         case EEventOperationCompleted:
       
   819             break;
       
   820         case EEventSuspendOperations:
       
   821             break;
       
   822         case EEventContinueOperations:
       
   823             break;
       
   824         case EEventStart:
       
   825             break;
       
   826         case EEventStopAndRemoveOps:
       
   827             break;
       
   828         case EEventNop:
       
   829             break;
       
   830         default:
       
   831             break;
       
   832         }
       
   833 
       
   834     switch ( iState )
       
   835         {
       
   836         case EStateWaitSyncStart:
       
   837             break;
       
   838         case EStateSyncOngoing:
       
   839             break;
       
   840         case EStateFetchOngoing:
       
   841             break;
       
   842         case EStateSuspended:
       
   843             break;
       
   844         case EStateIdleAndWaitCommands:
       
   845             break;
       
   846         case EStateError:
       
   847             break;
       
   848         default:
       
   849             break;
       
   850         };
       
   851     }
       
   852 #endif // IPSSMTPLOGGING_ON*/
       
   853 //</cmail>    
       
   854 
   970 
   855 // End of file
   971 // End of file
   856 
   972