ipsservices/ipssosaoplugin/src/IpsSosAOMboxLogic.cpp
changeset 23 2dc6caa42ec3
parent 18 578830873419
child 30 759dc5235cdb
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    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 //<Qmail>
    20 //<cmail> internal dependency removed
       
    21 /*#ifdef _DEBUG
       
    22 #include "../../internal/IpsSosAOPluginTester/inc/IpsSosAOPluginTester.hrh"
       
    23 #endif // _DEBUG*/
       
    24 //</cmail>
       
    25 
       
    26 #include <cmmanager.h>
    20 #include <cmmanager.h>
       
    21 //</Qmail>
    27 
    22 
    28 #include "emailtrace.h"
    23 #include "emailtrace.h"
    29 #include "IpsSosAOMboxLogic.h"
    24 #include "IpsSosAOMboxLogic.h"
    30 //<QMail>
    25 //<QMail>
    31 
    26 #include "IpsSosAOSettingsHandler.h"
    32 //</QMail>
    27 //</QMail>
    33 #include "IpsSosAOSchedulerUtils.h"
    28 #include "IpsSosAOSchedulerUtils.h"
    34 #include "IpsSosAOPlugin.hrh"
    29 #include "IpsSosAOPlugin.hrh"
    35 #include "IpsSosAOImapPopLogic.h"
    30 #include "IpsSosAOImapPopLogic.h"
    36 
    31 
    37 //<QMail>
    32 //<QMail>
    38 //const TInt KAOSecondsInMinute = 60;
    33 const TInt KAOSecondsInMinute = 60;
    39 //</QMail>
    34 //</QMail>
    40 const TInt KIpsSosAOMboxLogicMinGra = 1;
    35 const TInt KIpsSosAOMboxLogicMinGra = 1;
    41 
    36 
    42 // ----------------------------------------------------------------------------
    37 // ----------------------------------------------------------------------------
    43 // ----------------------------------------------------------------------------
    38 // ----------------------------------------------------------------------------
    91     {
    86     {
    92     FUNC_LOG;
    87     FUNC_LOG;
    93     iTimer = CIpsSosAOPluginTimer::NewL( CActive::EPriorityStandard, *this );
    88     iTimer = CIpsSosAOPluginTimer::NewL( CActive::EPriorityStandard, *this );
    94 	//<QMail>
    89 	//<QMail>
    95 
    90 
    96 	//</QMail>
    91 	
    97     iAgent = CIpsSosAOBaseAgent::CreateAgentL( iSession, *this, iMailboxId );
    92     iAgent = CIpsSosAOBaseAgent::CreateAgentL( iSession, *this, iMailboxId );
    98     LoadSettingsL();
    93     
       
    94     //</QMail>
    99     }
    95     }
   100 
    96 
   101 // ----------------------------------------------------------------------------
    97 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
    98 // ----------------------------------------------------------------------------
   103 //   
    99 //   
   183 // ----------------------------------------------------------------------------
   179 // ----------------------------------------------------------------------------
   184 //  
   180 //  
   185 void CIpsSosAOMBoxLogic::FetchMessagesL( const RArray<TMsvId> aArray )
   181 void CIpsSosAOMBoxLogic::FetchMessagesL( const RArray<TMsvId> aArray )
   186     {
   182     {
   187     FUNC_LOG;
   183     FUNC_LOG;
   188     LoadSettingsL();
   184     //<Qmail>
       
   185     
       
   186     //</Qmail>
   189     for ( TInt i = 0; i < aArray.Count(); i++ )
   187     for ( TInt i = 0; i < aArray.Count(); i++ )
   190         {
   188         {
   191         iFetchMsgArray.AppendL( aArray[i] );
   189         iFetchMsgArray.AppendL( aArray[i] );
   192         }
   190         }
   193     HandleEventAndSwitchStateL( EEventFetchMessages );
   191     HandleEventAndSwitchStateL( EEventFetchMessages );
   217 TBool CIpsSosAOMBoxLogic::IsEmnOn() const
   215 TBool CIpsSosAOMBoxLogic::IsEmnOn() const
   218     {
   216     {
   219     FUNC_LOG;
   217     FUNC_LOG;
   220     TBool ret = ETrue;
   218     TBool ret = ETrue;
   221 	//<QMail>
   219 	//<QMail>
   222     /*
   220     CIpsSosAOSettingsHandler* settings = NULL;
   223     TIpsSetDataEmnStates state = EMailEmnOff;
   221     TRAP_IGNORE( settings = 
   224     if ( iExtendedSettings )
   222             CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId));
   225         {
   223     
   226         state = iExtendedSettings->EmailNotificationState();
   224     if(settings){
   227         }
   225         IpsServices::TIpsSetDataEmnStates state = IpsServices::EMailEmnOff;
   228     if ( state == EMailEmnOff )
   226         state = settings->EmailNotificationState();
   229         {
   227         
   230         ret = EFalse;
   228         if ( state == IpsServices::EMailEmnOff )
   231         }
   229             {
   232         */
   230             ret = EFalse;
       
   231             }
       
   232         
       
   233         delete settings;
       
   234         }
       
   235     
   233 	//</QMail>
   236 	//</QMail>
   234     return ret;
   237     return ret;
   235     }
   238     }
   236 
   239 
   237 // ----------------------------------------------------------------------------
   240 // ----------------------------------------------------------------------------
   238 // ----------------------------------------------------------------------------
   241 // ----------------------------------------------------------------------------
   239 // 
   242 // 
   240 //<QMail>
   243 //<QMail>
   241 void CIpsSosAOMBoxLogic::GetEmailAddress(  
   244 void CIpsSosAOMBoxLogic::GetEmailAddress(  
   242     TBuf<KIpsSosAOTextBufferSize>& /*aEmailAddress*/ ) const
   245     TBuf<KIpsSosAOTextBufferSize>& aEmailAddress ) const
   243     {
   246     {
   244     FUNC_LOG;
   247     FUNC_LOG;
   245     /*
   248     CIpsSosAOSettingsHandler* settings = NULL;
   246     const TDesC& addr = iExtendedSettings->EmailAddress();
   249 
   247     __ASSERT_DEBUG( ( 
   250     TRAPD( err, settings = CIpsSosAOSettingsHandler::NewL(
   248             addr.Length() <= KIpsSosAOTextBufferSize ), 
   251             iSession, iMailboxId) );
   249             User::Panic( KIpsSosAOPanicLit, KErrGeneral) );
   252     
   250     
   253     if(settings){
   251     if ( addr.Length() <= KIpsSosAOTextBufferSize )
   254         HBufC* addr = NULL;
   252         {
   255         TRAP(err, addr = settings->EmailAddressL());
   253         aEmailAddress.Copy( addr );
   256         
   254         }
   257         if(addr){
   255         */
   258             __ASSERT_DEBUG( ( 
       
   259                     addr->Length() <= KIpsSosAOTextBufferSize ), 
       
   260                     User::Panic( KIpsSosAOPanicLit, KErrGeneral) );
       
   261             
       
   262             if ( addr->Length() <= KIpsSosAOTextBufferSize )
       
   263                 {
       
   264                 aEmailAddress.Copy( *addr );
       
   265                 }
       
   266             delete addr;
       
   267             }   
       
   268         
       
   269         delete settings;
       
   270         }
       
   271     
   256 	//<QMail>
   272 	//<QMail>
   257     }
   273     }
   258 
   274 
   259 // ----------------------------------------------------------------------------
   275 // ----------------------------------------------------------------------------
   260 // ----------------------------------------------------------------------------
   276 // ----------------------------------------------------------------------------
   261 //<QMail>
   277 //<QMail>
   262 //<cmail>
   278 void CIpsSosAOMBoxLogic::SetEmnReceivedFlagL( TBool aNewValue )
   263 void CIpsSosAOMBoxLogic::SetEmnReceivedFlagL( TBool /*aNewValue*/ )
   279     {
   264 //</cmail>
   280     
   265     {
   281     CIpsSosAOSettingsHandler* settings = 
   266     LoadSettingsL();
   282             CIpsSosAOSettingsHandler::NewL(
   267     /*
   283                 iSession, iMailboxId );
   268     iExtendedSettings->SetEmnReceivedButNotSyncedFlag( aNewValue );
   284     CleanupStack::PushL(settings);
   269     iDataApi->SaveExtendedSettingsL(
   285     
   270         *iExtendedSettings );
   286     settings->SetEmnReceivedButNotSyncedFlag( aNewValue );
   271     */
   287     
       
   288     CleanupStack::PopAndDestroy(settings);
   272 	//</QMail>
   289 	//</QMail>
   273     }
   290     }
   274 
   291 
   275 // ----------------------------------------------------------------------------
   292 // ----------------------------------------------------------------------------
   276 // ----------------------------------------------------------------------------
   293 // ----------------------------------------------------------------------------
   277 //
   294 //
   278 //<cmail>
       
   279 TBool CIpsSosAOMBoxLogic::IsMailboxRoamingStoppedL()
   295 TBool CIpsSosAOMBoxLogic::IsMailboxRoamingStoppedL()
   280 //</cmail>
       
   281     {
   296     {
   282     TBool ret = EFalse;
   297     TBool ret = EFalse;
   283     if ( iIsRoaming && !CanConnectIfRoamingL() )
   298     if ( iIsRoaming && !CanConnectIfRoamingL() )
   284         {
   299         {
   285         ret = ETrue;
   300         ret = ETrue;
   307         iState = EStateWaitSyncStart;
   322         iState = EStateWaitSyncStart;
   308         }
   323         }
   309     
   324     
   310     while ( event != EEventNop && iState != EStateError )
   325     while ( event != EEventNop && iState != EStateError )
   311         {
   326         {
   312 //<cmail> removing flags    
       
   313 /*#ifdef IPSSOSIMAPPOLOGGING_ON
       
   314         WriteDebugData( event );
       
   315 #endif*/
       
   316 //</cmail>
       
   317         switch ( event )
   327         switch ( event )
   318             {
   328             {
   319             case EEventTimerFired:
   329             case EEventTimerFired:
   320                 event = HandleTimerFiredL();
   330                 event = HandleTimerFiredL();
   321               break;
   331               break;
   330                     {
   340                     {
   331                     // start sync command in idle state is currently 
   341                     // start sync command in idle state is currently 
   332                     // received when emn arrives, checking scheduling 
   342                     // received when emn arrives, checking scheduling 
   333                     // if user have selected week days / hours in setting
   343                     // if user have selected week days / hours in setting
   334 					//<QMail>
   344 					//<QMail>
   335                 /*
   345                     CIpsSosAOSettingsHandler* settings = 
       
   346                              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   347                     CleanupStack::PushL(settings);
       
   348                     
   336                     CIpsSosAOSchedulerUtils* scheduler = 
   349                     CIpsSosAOSchedulerUtils* scheduler = 
   337                         CIpsSosAOSchedulerUtils::NewLC( *iExtendedSettings );
   350                         CIpsSosAOSchedulerUtils::NewLC( *settings );
   338                         */
   351                         
   339                     TTimeIntervalSeconds seconds;
   352                     TTimeIntervalSeconds seconds;
   340                     TIpsSosAOConnectionType type = EAOCConnectAfter; 
   353                     TIpsSosAOConnectionType type = 
   341                         //= scheduler->SecondsToNextMark( seconds );
   354                             scheduler->SecondsToNextMark( seconds );
       
   355                     
   342 					//</QMail>
   356 					//</QMail>
   343                     if ( type == EAOCConnectAfter )
   357                     if ( type == EAOCConnectAfter )
   344                         {
   358                         {
   345                         iState = EStateWaitSyncStart;
   359                         iState = EStateWaitSyncStart;
   346                         iTimer->After( seconds );
   360                         iTimer->After( seconds );
   347                         //<cmail>
   361                         
   348                         SetEmnReceivedFlagL( ETrue );
   362                         SetEmnReceivedFlagL( ETrue );
   349                         //</cmail>
       
   350                         }
   363                         }
   351                     else
   364                     else
   352                         {
   365                         {
   353                         iError = KErrNone;
   366                         iError = KErrNone;
   354                         iAgent->StartSyncL();
   367                         iAgent->StartSyncL();
   355                         iState = EStateSyncOngoing;
   368                         iState = EStateSyncOngoing;
   356                         }
   369                         }
   357 					//<QMail>
   370 					//<QMail>
   358                     //CleanupStack::PopAndDestroy( scheduler );
   371                     CleanupStack::PopAndDestroy( 2, settings );
   359 					//</QMail>
   372 					//</QMail>
   360                     }
   373                     }
   361                 // ignore in other states
   374                 // ignore in other states
   362                 event = EEventNop;
   375                 event = EEventNop;
   363                 break;
   376                 break;
   480 // 
   493 // 
   481 TInt CIpsSosAOMBoxLogic::HandleOperationCompletionL()
   494 TInt CIpsSosAOMBoxLogic::HandleOperationCompletionL()
   482     {
   495     {
   483     FUNC_LOG;
   496     FUNC_LOG;
   484     TInt event = EEventNop;
   497     TInt event = EEventNop;
       
   498 	//<Qmail>
       
   499     CIpsSosAOSettingsHandler* settings = 
       
   500              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   501     CleanupStack::PushL(settings);
       
   502 	//</Qmail>     
   485     if ( iState == EStateSyncOngoing )
   503     if ( iState == EStateSyncOngoing )
   486         {
   504         {
   487         if ( !( iError == KErrNone || iError == KErrCancel ) )
   505         if ( !( iError == KErrNone || iError == KErrCancel ) )
   488             {
   506             {
   489             ++iErrorCounter;
   507             ++iErrorCounter;
   491         else
   509         else
   492             {
   510             {
   493             iError = KErrNone;
   511             iError = KErrNone;
   494             iErrorCounter = 0;
   512             iErrorCounter = 0;
   495             }
   513             }
   496         //<cmail>
   514         
   497         if ( iError != KErrNone && 
   515         if ( iError != KErrNone && 
   498                 IsErrorFatalL( iError ) )
   516                 IsErrorFatalL( iError ) )
   499         //</cmail>
       
   500             {
   517             {
   501             iAgent->CancelAllAndDisconnectL();
   518             iAgent->CancelAllAndDisconnectL();
   502             // switch ao off
   519             // switch ao off
   503 			//<QMail>
   520 			//<QMail>
   504             /*
   521             
   505             iExtendedSettings->SetAlwaysOnlineState( EMailAoOff );
   522             settings->SetAlwaysOnlineState( IpsServices::EMailAoOff );
   506             // emn not swithced of if its going to be "always on" in
   523             // emn not swithced of if its going to be "always on" in
   507             // future
   524             // future
   508             iExtendedSettings->SetEmnReceivedButNotSyncedFlag( EFalse );
   525             
   509             iDataApi->SaveExtendedSettingsL(
   526             settings->SetEmnReceivedButNotSyncedFlag( EFalse );
   510                 *iExtendedSettings );
   527             //</QMail>
   511                 */
       
   512 			//</QMail>
       
   513             iState = EStateError;
   528             iState = EStateError;
   514             iErrorCounter = 0;
   529             iErrorCounter = 0;
   515             }
   530             }
   516         else if ( iError != KErrNone && 
   531         else if ( iError != KErrNone && 
   517                 iErrorCounter < KIpsSosAOMaxReTryTimes )
   532                 iErrorCounter < KIpsSosAOMaxReTryTimes )
   518             {
   533             {
   519             // not fatal error
   534             // not fatal error
   520 			//<QMail>
   535 			//<QMail>
   521         /*
   536             IpsServices::TIpsSetDataAoStates state = 
   522             TIpsSetDataAoStates state = iExtendedSettings->AlwaysOnlineState();
   537                     settings->AlwaysOnlineState();
   523             if ( state == EMailAoOff )
   538             
       
   539             if ( state == IpsServices::EMailAoOff )
   524                 {
   540                 {
   525                 iState = EStateIdleAndWaitCommands;
   541                 iState = EStateIdleAndWaitCommands;
   526                 }
   542                 }
   527             else
   543             else
   528                 {
   544                 {
   529                 if( !iTimer->IsActive() )
   545                 if( !iTimer->IsActive() )
   530                     {
   546                     {
   531                 iTimer->After( KIpsSosAOReTryInterval );
   547                     iTimer->After( KIpsSosAOReTryInterval );
   532                     }
   548                     }
   533                 iState = EStateWaitSyncStart;
   549                 iState = EStateWaitSyncStart;
   534                 }
   550                 }
   535                 */
   551 
   536 			//</QMail>
   552 			//</QMail>
   537             }
   553             }
   538         else if ( iError != KErrNone && 
   554         else if ( iError != KErrNone && 
   539                 iErrorCounter >= KIpsSosAOMaxReTryTimes )
   555                 iErrorCounter >= KIpsSosAOMaxReTryTimes )
   540             {
   556             {
   541             //<cmail>
   557             
   542             SetEmnReceivedFlagL( EFalse );
   558             SetEmnReceivedFlagL( EFalse );
   543             //</cmail>
       
   544             // not fatal, but all re trys are gone
   559             // not fatal, but all re trys are gone
   545             CalculateToNextIntervalL();
   560             CalculateToNextIntervalL();
   546             }
   561             }
   547         else
   562         else
   548             {
   563             {
   563         else
   578         else
   564             {
   579             {
   565             event = CheckSchedulingAndSwitchStateL();          
   580             event = CheckSchedulingAndSwitchStateL();          
   566             }
   581             }
   567         }
   582         }
       
   583 		//<Qmail>
       
   584     CleanupStack::PopAndDestroy(settings);
       
   585 	//</Qmail>
   568     return event;
   586     return event;
   569     }
   587     }
   570 
   588 
   571 // ----------------------------------------------------------------------------
   589 // ----------------------------------------------------------------------------
   572 // ----------------------------------------------------------------------------
   590 // ----------------------------------------------------------------------------
   588     }
   606     }
   589 
   607 
   590 // ----------------------------------------------------------------------------
   608 // ----------------------------------------------------------------------------
   591 // ----------------------------------------------------------------------------
   609 // ----------------------------------------------------------------------------
   592 //<QMail>
   610 //<QMail>
   593 //<cmail>
   611 
   594 TBool CIpsSosAOMBoxLogic::IsErrorFatalL( TInt /*aError*/ )
   612 TBool CIpsSosAOMBoxLogic::IsErrorFatalL( TInt aError )
   595 //</cmail>
       
   596     {
   613     {
   597     FUNC_LOG;
   614     FUNC_LOG;
   598     // error can be fatal only if we haven't got successful connect
   615     // error can be fatal only if we haven't got successful connect
   599     // in mailbox ever and error is something else than KErrNone or
   616     // in mailbox ever and error is something else than KErrNone or
   600     // KErrCancel, and retry interval is reached
   617     // KErrCancel, and retry interval is reached
   601     TBool ret = EFalse;
   618     TBool ret = EFalse;
   602     LoadSettingsL();
   619     //<Qmail>
   603     /*
   620     
   604     TAOInfo info = iExtendedSettings->LastUpdateInfo();
   621     //</Qmail>
       
   622     
       
   623     CIpsSosAOSettingsHandler* settings = 
       
   624              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   625     CleanupStack::PushL(settings);
       
   626     
       
   627     IpsServices::TAOInfo info = settings->LastUpdateInfo();
   605     if ( aError != KErrNone && aError != KErrCancel 
   628     if ( aError != KErrNone && aError != KErrCancel 
   606             && !info.iUpdateSuccessfulWithCurSettings
   629             && !info.iUpdateSuccessfulWithCurSettings
   607             && iErrorCounter >= KIpsSosAOMaxReTryTimes )
   630             && iErrorCounter >= KIpsSosAOMaxReTryTimes )
   608         {
   631         {
   609         ret = ETrue;
   632         ret = ETrue;
   610         }
   633         }
   611         */
   634     
   612 	//</QMail>
   635     CleanupStack::PopAndDestroy(settings);
       
   636     //</QMail>
   613     return ret;
   637     return ret;
   614     }
   638     }
   615 
   639 
   616 // ----------------------------------------------------------------------------
   640 // ----------------------------------------------------------------------------
   617 // ----------------------------------------------------------------------------
   641 // ----------------------------------------------------------------------------
   618 //
   642 //
   619 CIpsSosAOMBoxLogic::TMBoxLogicEvent 
   643 CIpsSosAOMBoxLogic::TMBoxLogicEvent 
   620     CIpsSosAOMBoxLogic::CheckSchedulingAndSwitchStateL()
   644     CIpsSosAOMBoxLogic::CheckSchedulingAndSwitchStateL()
   621     {
   645     {
   622      //<cmail> logs removed </cmail>
   646 	//<Qmail>
   623     iTimer->Cancel();
   647     FUNC_LOG;
       
   648      iTimer->Cancel();
   624     TMBoxLogicEvent event = EEventNop;
   649     TMBoxLogicEvent event = EEventNop;
   625     TTimeIntervalSeconds secondsToConnect = CalculateScheduledSyncTimeL();
   650     TTimeIntervalSeconds secondsToConnect = CalculateScheduledSyncTimeL();
   626     //<cmail> logs removed </cmail>
   651     
       
   652     CIpsSosAOSettingsHandler* settings = 
       
   653              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   654     CleanupStack::PushL(settings);
       
   655       
   627     if ( secondsToConnect.Int() == 0 )
   656     if ( secondsToConnect.Int() == 0 )
   628         {
   657         {
   629         //check last successfull sync time and check is interval reached
   658         //check last successfull sync time and check is interval reached
   630 	//<QMail>
   659 
   631     /*
   660     
   632         TAOInfo info = iExtendedSettings->LastUpdateInfo();
   661         IpsServices::TAOInfo info = settings->LastUpdateInfo();
   633         if ( !info.iUpdateSuccessfulWithCurSettings )
   662         if ( !info.iUpdateSuccessfulWithCurSettings )
   634             {
   663             {
   635         
       
   636             event = EEventStartSync;
   664             event = EEventStartSync;
   637             }
   665             }
   638         else 
   666         else 
   639             {
   667             {
   640             TTime now;
   668             TTime now;
   641             now.HomeTime();
   669             now.HomeTime();
   642             TInt interval = 
   670             TInt interval = 
   643                 iExtendedSettings->InboxRefreshTime() * KAOSecondsInMinute;
   671                     settings->InboxRefreshTime() * KAOSecondsInMinute;
   644             TTimeIntervalSeconds secsFromLastSync;
   672             TTimeIntervalSeconds secsFromLastSync;
   645             now.SecondsFrom( info.iLastSuccessfulUpdate, secsFromLastSync );
   673             now.SecondsFrom( info.iLastSuccessfulUpdate, secsFromLastSync );
   646             if ( (secsFromLastSync.Int() > 0) && ( 
   674             if ( (secsFromLastSync.Int() > 0) && ( 
   647                     secsFromLastSync.Int() < interval ) )
   675                     secsFromLastSync.Int() < interval ) )
   648                 {
   676                 {
   659         }
   687         }
   660     else if ( secondsToConnect.Int() == KErrNotFound )
   688     else if ( secondsToConnect.Int() == KErrNotFound )
   661         {
   689         {
   662         // means that ao is not on (but emn is)
   690         // means that ao is not on (but emn is)
   663         iState = EStateIdleAndWaitCommands;
   691         iState = EStateIdleAndWaitCommands;
   664        
   692       
   665         if ( iExtendedSettings->EmnReceivedButNotSyncedFlag() )
   693         if ( settings->EmnReceivedButNotSyncedFlag() )
   666             {
   694             {
   667             // got emn when logic was stopped
   695             // got emn when logic was stopped
   668             event = EEventStartSync;
   696             event = EEventStartSync;
   669             }
   697             }
   670             
       
   671         }
   698         }
   672     else
   699     else
   673         {
   700         {
   674         iTimer->After( secondsToConnect );
   701         iTimer->After( secondsToConnect );
   675         iState = EStateWaitSyncStart;
   702         iState = EStateWaitSyncStart;
   676         }
   703         
   677     */
   704 
   678 	//</QMail>
   705         }
   679         }
   706     CleanupStack::PopAndDestroy(settings);
   680     
   707     //</Qmail>
   681     return event;
   708     return event;
   682     }
   709     }
   683 
   710 
   684 // ----------------------------------------------------------------------------
   711 // ----------------------------------------------------------------------------
   685 // ----------------------------------------------------------------------------
   712 // ----------------------------------------------------------------------------
   686 //
   713 //
   687 void CIpsSosAOMBoxLogic::CalculateToNextIntervalL()
   714 void CIpsSosAOMBoxLogic::CalculateToNextIntervalL()
   688     {
   715     {
   689     FUNC_LOG;
   716     FUNC_LOG;
   690     //<cmail> logs removed </cmail>
   717     
   691     iTimer->Cancel();
   718     iTimer->Cancel();
   692     TTimeIntervalSeconds interval;
   719     TTimeIntervalSeconds interval;
   693     // first check and calculate scheduling function also loads settings
   720     // first check and calculate scheduling function also loads settings
   694     interval = CalculateScheduledSyncTimeL();
   721     interval = CalculateScheduledSyncTimeL();
   695     //<cmail> logs removed </cmail>
   722     
   696     if ( interval.Int() == 0 )
   723     if ( interval.Int() == 0 )
   697         {
   724         {
   698         // add next interval, if interval is grater than 0 it means
   725         // add next interval, if interval is grater than 0 it means
   699         // that off-line time is going, user have selected days / times from
   726         // that off-line time is going, user have selected days / times from
   700         // settings
   727         // settings
   701 		
   728 		
   702 		//<QMail>
   729 		//<QMail>
   703        // iTimer->After( 
   730         CIpsSosAOSettingsHandler* settings = 
   704        //         iExtendedSettings->InboxRefreshTime() * KAOSecondsInMinute );
   731                  CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   732         CleanupStack::PushL(settings);
       
   733         iTimer->After( 
       
   734                 settings->InboxRefreshTime() * KAOSecondsInMinute );
       
   735         CleanupStack::PopAndDestroy(settings);
   705 	   //</QMail>
   736 	   //</QMail>
   706         iState = EStateWaitSyncStart;
   737         iState = EStateWaitSyncStart;
   707         }
   738         }
   708     else if ( interval.Int() > 0 )
   739     else if ( interval.Int() > 0 )
   709         {
   740         {
   720 // ----------------------------------------------------------------------------
   751 // ----------------------------------------------------------------------------
   721 // ----------------------------------------------------------------------------
   752 // ----------------------------------------------------------------------------
   722 //
   753 //
   723 TTimeIntervalSeconds CIpsSosAOMBoxLogic::CalculateScheduledSyncTimeL()
   754 TTimeIntervalSeconds CIpsSosAOMBoxLogic::CalculateScheduledSyncTimeL()
   724     {
   755     {
   725     FUNC_LOG;
   756     FUNC_LOG;    
   726     //<cmail> logs removed </cmail> 
   757 	//<Qmail>
   727     LoadSettingsL();
   758     
   728     TTimeIntervalSeconds seconds;
   759     TTimeIntervalSeconds seconds=KErrNotFound;
   729 	//<QMail>
   760 	
   730     /*
   761     
       
   762     CIpsSosAOSettingsHandler* settings = 
       
   763              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   764     CleanupStack::PushL(settings);
       
   765             
   731     // first check is ao or emn on at all
   766     // first check is ao or emn on at all
   732     if ( (iExtendedSettings->AlwaysOnlineState() == EMailAoOff && 
   767     if ( (settings->AlwaysOnlineState() == IpsServices::EMailAoOff && 
   733             iExtendedSettings->EmailNotificationState() == EMailEmnOff  )||
   768             settings->EmailNotificationState() == IpsServices::EMailEmnOff  )||
   734         iExtendedSettings->SelectedWeekDays() == 0 ) // no week days chosen
   769             settings->SelectedWeekDays() == 0 ) // no week days chosen
   735         {
   770         {
   736         // no timed sync on
   771         // no timed sync on
       
   772         CleanupStack::PopAndDestroy(settings);    
   737         return KErrNotFound;
   773         return KErrNotFound;
   738         }
   774         }
   739     
   775     
   740     if ( iExtendedSettings->EmailNotificationState() != EMailEmnOff && 
   776     if ( settings->EmailNotificationState() != IpsServices::EMailEmnOff && 
   741          !iExtendedSettings->EmnReceivedButNotSyncedFlag()   )
   777          !settings->EmnReceivedButNotSyncedFlag()   )
   742         {
   778         {
       
   779         CleanupStack::PopAndDestroy(settings);
   743         return KErrNotFound;
   780         return KErrNotFound;
   744         }
   781         }
   745     
   782     
   746     
   783     
   747     CIpsSosAOSchedulerUtils* scheduler = CIpsSosAOSchedulerUtils::NewLC(
   784     CIpsSosAOSchedulerUtils* scheduler = CIpsSosAOSchedulerUtils::NewLC(
   748         *iExtendedSettings );
   785         *settings );
   749 
   786 
   750     TIpsSosAOConnectionType type = scheduler->SecondsToNextMark( seconds );
   787     TIpsSosAOConnectionType type = scheduler->SecondsToNextMark( seconds );
   751     if ( type == EAOCDisconnectAfter ) 
   788     if ( type == EAOCDisconnectAfter ) 
   752         {
   789         {
   753         // if type is EAOCDisconnectAfter it means that scheduled days / times
   790         // if type is EAOCDisconnectAfter it means that scheduled days / times
   759     else
   796     else
   760         {
   797         {
   761         // this means that user have choosed time/day schedule at 
   798         // this means that user have choosed time/day schedule at 
   762         // timed sync and now we have to wait sync time
   799         // timed sync and now we have to wait sync time
   763         }
   800         }
   764     CleanupStack::PopAndDestroy( scheduler );
   801     CleanupStack::PopAndDestroy( 2, settings );
   765     */
   802     
   766 	//</QMail>
   803 	//</QMail>
   767     return seconds;
   804     return seconds;
   768     }
   805     }
   769 
   806 
   770 // ----------------------------------------------------------------------------
   807 // ----------------------------------------------------------------------------
   771 // ----------------------------------------------------------------------------
   808 // ----------------------------------------------------------------------------
   772 //
   809 //
   773 void CIpsSosAOMBoxLogic::LoadSettingsL()
   810 void CIpsSosAOMBoxLogic::LoadSettingsL()
   774     {
   811     {
   775     FUNC_LOG;
   812     FUNC_LOG;
   776     //<cmail> logs removed </cmail> 
   813     //<QMail>
   777 	//<QMail>
       
   778     //removed loading
   814     //removed loading
   779 	//</QMail>
   815 	//</QMail>
   780     //<cmail> logs removed </cmail>
       
   781     }
   816     }
   782 
   817 
   783 // ----------------------------------------------------------------------------
   818 // ----------------------------------------------------------------------------
   784 // ----------------------------------------------------------------------------
   819 // ----------------------------------------------------------------------------
   785 //
   820 //
   786 void CIpsSosAOMBoxLogic::SaveSuccessfulSyncTimeL()
   821 void CIpsSosAOMBoxLogic::SaveSuccessfulSyncTimeL()
   787     {
   822     {
   788     FUNC_LOG;
   823     FUNC_LOG;
   789     TTime now;
   824     TTime now;
   790     now.HomeTime();
   825     now.HomeTime();
   791     LoadSettingsL();
   826     //<QMail>
   792 	//<QMail>
   827     
   793     /*
   828 	
   794     TAOInfo info;
   829     CIpsSosAOSettingsHandler* settings = 
       
   830              CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId);
       
   831     CleanupStack::PushL(settings);
       
   832         
       
   833     IpsServices::TAOInfo info;
   795     info.iLastSuccessfulUpdate = now;
   834     info.iLastSuccessfulUpdate = now;
   796     info.iUpdateSuccessfulWithCurSettings = ETrue;
   835     info.iUpdateSuccessfulWithCurSettings = ETrue;
   797     iExtendedSettings->SetLastUpdateInfo( info );
   836     settings->SetLastUpdateInfo( info );
   798     // clear flag
   837     // clear flag
   799     iExtendedSettings->SetEmnReceivedButNotSyncedFlag( EFalse );
   838     settings->SetEmnReceivedButNotSyncedFlag( EFalse );
   800     iDataApi->SaveExtendedSettingsL(
   839             
   801             *iExtendedSettings );
   840     CleanupStack::PopAndDestroy(settings);
   802             */
       
   803 	//</QMail>
   841 	//</QMail>
   804     }
   842     }
   805 
   843 
   806 // ----------------------------------------------------------------------------
   844 // ----------------------------------------------------------------------------
   807 // ----------------------------------------------------------------------------
   845 // ----------------------------------------------------------------------------
   808 TBool CIpsSosAOMBoxLogic::CanConnectIfRoamingL()
   846 TBool CIpsSosAOMBoxLogic::CanConnectIfRoamingL()
   809     {
   847     {
   810     FUNC_LOG;
   848     FUNC_LOG;
   811     TBool ret = ETrue;
   849     TBool ret = EFalse;
   812     LoadSettingsL();
   850     //<Qmail>
       
   851     RCmManager mgr;
       
   852     CleanupClosePushL(mgr);
       
   853     TRAPD(err, mgr.OpenL());
       
   854     
       
   855     TCmGenConnSettings set;
       
   856     
       
   857     if(err==KErrNone){
       
   858         TRAP(err, mgr.ReadGenConnSettingsL(set));
       
   859         }
       
   860     
       
   861     CleanupStack::PopAndDestroy(&mgr);
       
   862     
       
   863     if( err==KErrNone && 
       
   864             set.iCellularDataUsageVisitor == ECmCellularDataUsageAutomatic){
       
   865         ret = ETrue;
       
   866         }
       
   867     else{
       
   868         ret = EFalse;
       
   869         }
       
   870    
       
   871     //</QMail>
       
   872     return ret;          
       
   873     }
       
   874 
       
   875 // ----------------------------------------------------------------------------
       
   876 // ----------------------------------------------------------------------------
       
   877 TBool CIpsSosAOMBoxLogic::FirstEMNReceived()
       
   878     {
   813 	//<QMail>
   879 	//<QMail>
   814     /*
   880     CIpsSosAOSettingsHandler* settings = NULL;
   815     if ( ( iExtendedSettings->EmailNotificationState() == EMailEmnHomeOnly 
   881     TBool ret = EFalse;
   816           || iExtendedSettings->AlwaysOnlineState() == EMailAoHomeOnly
   882     TRAP_IGNORE(CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId));
   817           || iExtendedSettings->RoamHomeOnlyFlag() ) && iIsRoaming )
   883     if(settings){
   818         {
   884         ret = settings->FirstEmnReceived();
   819         ret = EFalse;
   885         delete settings;
   820         }
   886         }
   821         */
   887     
       
   888     return ret;
       
   889     
   822 	//</QMail>
   890 	//</QMail>
   823     return ret;          
   891     }
   824     }
   892 
   825 
   893 // ----------------------------------------------------------------------------
   826 // ----------------------------------------------------------------------------
   894 // ----------------------------------------------------------------------------
   827 // ----------------------------------------------------------------------------
   895 void CIpsSosAOMBoxLogic::SetFirstEMNReceived()
   828 TBool CIpsSosAOMBoxLogic::FirstEMNReceived()
   896     {
   829     {
   897     //<QMail>
   830 	//<QMail>
   898     
   831     //return iExtendedSettings->FirstEmnReceived();
   899     CIpsSosAOSettingsHandler* settings = NULL;
   832     return false;
   900     TRAP_IGNORE( settings = 
       
   901             CIpsSosAOSettingsHandler::NewL(iSession, iMailboxId));
       
   902     
       
   903     if(settings){
       
   904         settings->SetFirstEmnReceived( ETrue );
       
   905         
       
   906     
       
   907         //if alwaysonline was allowed to roam, so will EMN be.
       
   908         settings->SetEmailNotificationState(
       
   909             settings->AlwaysOnlineState() == 
       
   910             IpsServices::EMailAoAlways ? 
       
   911                 IpsServices::EMailEmnAutomatic : IpsServices::EMailEmnHomeOnly );
       
   912         
       
   913         
       
   914         // set always online state off when emn is on
       
   915         settings->SetAlwaysOnlineState( IpsServices::EMailAoOff );
       
   916         delete settings;
       
   917         }
       
   918     
   833 	//</QMail>
   919 	//</QMail>
   834     }
   920     }
   835 
   921 
   836 // ----------------------------------------------------------------------------
       
   837 // ----------------------------------------------------------------------------
       
   838 void CIpsSosAOMBoxLogic::SetFirstEMNReceived()
       
   839     {
       
   840     TRAP_IGNORE( LoadSettingsL() );
       
   841 	//<QMail>
       
   842     /*
       
   843     iExtendedSettings->SetFirstEmnReceived( ETrue );
       
   844     
       
   845     //if alwaysonline was allowed to roam, so will EMN be.
       
   846     iExtendedSettings->SetEmailNotificationState(
       
   847             iExtendedSettings->AlwaysOnlineState() == 
       
   848             EMailAoAlways ? EMailEmnAutomatic : EMailEmnHomeOnly );
       
   849     
       
   850     
       
   851     // set always online state off when emn is on
       
   852     iExtendedSettings->SetAlwaysOnlineState( EMailAoOff );    
       
   853     iExtendedSettings->SetInboxRefreshTime( KErrNotFound );
       
   854     
       
   855     TRAP_IGNORE( iDataApi->SaveExtendedSettingsL(
       
   856        *iExtendedSettings ) );    
       
   857     */
       
   858 	//</QMail>
       
   859     }
       
   860 //<cmail> removing flags
       
   861 /*
       
   862 #ifdef IPSSOSIMAPPOLOGGING_ON
       
   863 // ----------------------------------------------------------------------------
       
   864 // ----------------------------------------------------------------------------
       
   865 //
       
   866 void CIpsSosAOMBoxLogic::WriteDebugData( TInt aEvent )
       
   867     {
       
   868     switch ( aEvent )
       
   869         {
       
   870         case EEventTimerFired:
       
   871             break;
       
   872         case EEventStartSync:
       
   873             break;
       
   874         case EEventFetchMessages:
       
   875             break;
       
   876         case EEventOperationCompleted:
       
   877             break;
       
   878         case EEventSuspendOperations:
       
   879             break;
       
   880         case EEventContinueOperations:
       
   881             break;
       
   882         case EEventStart:
       
   883             break;
       
   884         case EEventStopAndRemoveOps:
       
   885             break;
       
   886         case EEventNop:
       
   887             break;
       
   888         default:
       
   889             break;
       
   890         }
       
   891 
       
   892     switch ( iState )
       
   893         {
       
   894         case EStateWaitSyncStart:
       
   895             break;
       
   896         case EStateSyncOngoing:
       
   897             break;
       
   898         case EStateFetchOngoing:
       
   899             break;
       
   900         case EStateSuspended:
       
   901             break;
       
   902         case EStateIdleAndWaitCommands:
       
   903             break;
       
   904         case EStateError:
       
   905             break;
       
   906         default:
       
   907             break;
       
   908         };
       
   909     }
       
   910 #endif // IPSSMTPLOGGING_ON*/
       
   911 //</cmail>    
       
   912 
       
   913 // End of file
   922 // End of file
   914 
   923