ipsservices/ipssosplugin/src/ipsplgpop3connectop.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 30 759dc5235cdb
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    16 */
    16 */
    17 
    17 
    18 #include "emailtrace.h"
    18 #include "emailtrace.h"
    19 #include "ipsplgheaders.h"
    19 #include "ipsplgheaders.h"
    20 
    20 
       
    21 
    21 // Constants and defines
    22 // Constants and defines
    22 const TInt KIpsPlgPop3PopulateLimitInitValue = 50;
    23 // <qmail> rename const
    23 
    24 const TInt KDefaultPopulateLimit( 50 );
    24 _LIT( KIpsPlgPopConnectPanic, "PopConnectOp" );
    25 const TInt KPopulateAlgorithmBytesInKilo( 1024 );
       
    26 const TInt KPopulateAlgorithmRowLength( 75 );
       
    27 
    25 
    28 
    26 // ----------------------------------------------------------------------------
    29 // ----------------------------------------------------------------------------
    27 // CIpsPlgPop3ConnectOp::NewL()
    30 // CIpsPlgPop3ConnectOp::NewL()
    28 // ----------------------------------------------------------------------------
    31 // ----------------------------------------------------------------------------
    29 //
    32 // <qmail> MFSMailRequestObserver& changed to pointer
       
    33 // <qmail> aSignallingAllowed parameter removed
    30 CIpsPlgPop3ConnectOp* CIpsPlgPop3ConnectOp::NewL(
    34 CIpsPlgPop3ConnectOp* CIpsPlgPop3ConnectOp::NewL(
    31     CMsvSession& aMsvSession,                           
    35     CMsvSession& aMsvSession,                           
    32     TRequestStatus& aObserverRequestStatus,
    36     TRequestStatus& aObserverRequestStatus,
    33     TMsvId aService,
    37     TMsvId aService,
    34     TBool aForcePopulate,
    38     TBool aForcePopulate,
    37     MFSMailRequestObserver* aFSOperationObserver,
    41     MFSMailRequestObserver* aFSOperationObserver,
    38     TInt aFSRequestId,
    42     TInt aFSRequestId,
    39     CIpsPlgEventHandler* aEventHandler )
    43     CIpsPlgEventHandler* aEventHandler )
    40     {
    44     {
    41     FUNC_LOG;
    45     FUNC_LOG;
    42     CIpsPlgPop3ConnectOp* op = 
    46     CIpsPlgPop3ConnectOp* op = new(ELeave) CIpsPlgPop3ConnectOp(
    43         new(ELeave) CIpsPlgPop3ConnectOp( aMsvSession, aObserverRequestStatus, 
    47         aMsvSession,
    44             aService, aForcePopulate, aActivityTimer, aFSMailBoxId,
    48         aObserverRequestStatus,
    45             aFSOperationObserver, aFSRequestId, 
    49         aService,
    46             aEventHandler );
    50         aForcePopulate,
    47         
    51         aActivityTimer,
       
    52         aFSMailBoxId,
       
    53         aFSOperationObserver,
       
    54         aFSRequestId,
       
    55         aEventHandler );
       
    56 
    48     CleanupStack::PushL( op );
    57     CleanupStack::PushL( op );
    49     op->ConstructL();
    58     op->ConstructL();
    50     CleanupStack::Pop( op );
    59     CleanupStack::Pop( op );
    51     return op;
    60     return op;
    52     }
    61     }
    56 // ----------------------------------------------------------------------------
    65 // ----------------------------------------------------------------------------
    57 //
    66 //
    58 CIpsPlgPop3ConnectOp::~CIpsPlgPop3ConnectOp()
    67 CIpsPlgPop3ConnectOp::~CIpsPlgPop3ConnectOp()
    59     {
    68     {
    60     FUNC_LOG;
    69     FUNC_LOG;
    61     delete iEntry;
    70     // <qmail> removed iEntry;
    62     delete iSelection;
    71     // <qmail> removed iSelection;
    63     iState = EIdle;
    72     // <qmail> removed state setting
    64     }
    73     }
    65 
    74 
    66 // ----------------------------------------------------------------------------
    75 // ----------------------------------------------------------------------------
    67 // CIpsPlgPop3ConnectOp::ProgressL()
    76 // CIpsPlgPop3ConnectOp::ProgressL()
    68 // ----------------------------------------------------------------------------
    77 // ----------------------------------------------------------------------------
   101 // ----------------------------------------------------------------------------
   110 // ----------------------------------------------------------------------------
   102 //
   111 //
   103 void CIpsPlgPop3ConnectOp::DoRunL()
   112 void CIpsPlgPop3ConnectOp::DoRunL()
   104     {
   113     {
   105     FUNC_LOG;
   114     FUNC_LOG;
   106     // handle these error situations properly, 
   115     // <qmail> move TInt err declaration later, and narrow the scope
   107     // and report somehow back to framework
   116 
   108     TInt err( KErrNone );
   117     // <qmail> remove EQueryingDetails state
   109  
       
   110 // <qmail> remove EQueryingDetails state
       
   111     if ( iState == EStartConnect )
   118     if ( iState == EStartConnect )
   112         {
   119         {
   113         if ( iSubOperation )
   120         if ( iSubOperation )
   114             {
   121             {
   115             // operation exist and it means 
   122             // operation exist and it means 
   116             // disconnect operation was ongoing.
   123             // disconnect operation was ongoing.
   117             // How handle errors
       
   118             delete iSubOperation;
   124             delete iSubOperation;
   119             iSubOperation = NULL;
   125             iSubOperation = NULL;
   120             }
   126             }
   121         
   127         
       
   128 // <qmail> ValidateL removed
   122         // Begin Connect.
   129         // Begin Connect.
   123         DoConnectL();
   130         DoConnectL();
   124         iState = EConnected;
   131         iState = EConnected;
   125         }
   132         }
   126     else if ( iState == EConnected )
   133     else if ( iState == EConnected )
   127         {
   134         {
   128         // Connect completed
   135         // Connect completed
   129         err = GetOperationErrorCodeL( );
   136 // <qmail> Login details checking removed
   130         User::LeaveIfError( err );
   137         User::LeaveIfError( iStatus.Int() );
   131         if ( iForcePopulate && Connected() )
   138         if ( iForcePopulate && Connected() )
   132             {
   139             {
   133             iState = EPopulate;
   140             iState = EPopulate;
   134             DoPopulateL();
   141             DoPopulateL();
   135             }
   142             }
   142             // </qmail>
   149             // </qmail>
   143             }
   150             }
   144         }
   151         }
   145     else if ( iState == EPopulate )
   152     else if ( iState == EPopulate )
   146         {
   153         {
   147         err = GetOperationErrorCodeL( );
   154         // <qmail> suboperation has completed, the result is in 'this->iStatus'
   148         if ( iEventHandler )
   155         if ( iEventHandler )
   149             {
   156             {
   150             iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncCompleted, err );
   157             iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncCompleted, iStatus.Int() );
   151             }
   158             }
   152         CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( iMsvSession, iService );
   159         CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( iMsvSession, iService );
   153 
   160 
   154         // <qmail>
   161         // <qmail>
   155         // start disconnecting
   162         // start disconnecting
   156         iState = Disconnecting;
   163         iState = EDisconnecting;
   157         DoDisconnect();
   164         DoDisconnect();
   158         // </qmail>
   165         // </qmail>
   159         }
   166         }
   160     // <qmail>
   167     // <qmail>
   161     else if ( iState == EDisconnecting )
   168     else if ( iState == EDisconnecting )
   162         {
   169         {
   163         // we're done here
   170         // we're done here
   164         CompleteObserver( KErrNone );
   171         CompleteObserver( KErrNone );
   165         }
   172         }
   166     // </qmail>
   173     // </qmail>
   167     else if ( iState == EErrInvalidDetails )
   174     // <qmail> removed state EErrInvalidDetails
   168         {
       
   169         // proper error code;
       
   170         CompleteObserver( KErrGeneral );
       
   171         }
       
   172     else
   175     else
   173         {
   176         {
   174         User::Panic( KIpsPlgPopConnectPanic ,KErrNotFound);
   177         User::Panic( KIpsPlgPopConnectPanic ,KErrNotFound);
   175         }
   178         }
   176     }
   179     }
   204 // ----------------------------------------------------------------------------
   207 // ----------------------------------------------------------------------------
   205 //
   208 //
   206 TFSProgress CIpsPlgPop3ConnectOp::GetFSProgressL() const
   209 TFSProgress CIpsPlgPop3ConnectOp::GetFSProgressL() const
   207     {
   210     {
   208     FUNC_LOG;
   211     FUNC_LOG;
   209     // might not never called, but gives something reasonable if called
       
   210     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   212     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   211     result.iError = KErrNone;
       
   212     switch( iState )
   213     switch( iState )
   213         {
   214         {
   214         // <qmail> removed queryingdetails case
   215         // <qmail> removed queryingdetails cases
   215         case EStartConnect:
   216         case EStartConnect:
   216         case EConnected:
   217         case EConnected:
   217             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   218             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   218             break;
   219             break;
   219         case EPopulate:
   220         case EPopulate:
   236 // ----------------------------------------------------------------------------
   237 // ----------------------------------------------------------------------------
   237 // CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp
   238 // CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp
   238 // ----------------------------------------------------------------------------
   239 // ----------------------------------------------------------------------------
   239 //
   240 //
   240 // <qmail> priority parameter has been removed
   241 // <qmail> priority parameter has been removed
       
   242 // <qmail> MFSMailRequestObserver& changed to pointer
       
   243 // <qmail> aSignallingAllowed parameter removed
   241 CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp(
   244 CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp(
   242     CMsvSession& aMsvSession,
   245     CMsvSession& aMsvSession,
   243     TRequestStatus& aObserverRequestStatus,
   246     TRequestStatus& aObserverRequestStatus,
   244     TMsvId aServiceId,
   247     TMsvId aServiceId,
   245     TBool aForcePopulate,
   248     TBool aForcePopulate,
   255         aActivityTimer, 
   258         aActivityTimer, 
   256         aFSMailBoxId,
   259         aFSMailBoxId,
   257         aFSOperationObserver, 
   260         aFSOperationObserver, 
   258         aFSRequestId ),
   261         aFSRequestId ),
   259     iState( EIdle ),
   262     iState( EIdle ),
   260     iEntry( NULL ),
       
   261     iPopulateLimit( KIpsPlgPop3PopulateLimitInitValue ),
       
   262     iForcePopulate( aForcePopulate ),
   263     iForcePopulate( aForcePopulate ),
   263     iSelection( NULL ),
   264     iEventHandler( aEventHandler ),
   264     iEventHandler( aEventHandler )
   265     iAlreadyConnected( EFalse )
   265     {
   266     {
   266     iService = aServiceId; 
   267     iService = aServiceId; 
   267     }
   268     }
   268 
   269 
   269 // ----------------------------------------------------------------------------
   270 // ----------------------------------------------------------------------------
   272 //
   273 //
   273 void CIpsPlgPop3ConnectOp::ConstructL()
   274 void CIpsPlgPop3ConnectOp::ConstructL()
   274     {
   275     {
   275     FUNC_LOG;
   276     FUNC_LOG;
   276     BaseConstructL( KUidMsgTypePOP3 );
   277     BaseConstructL( KUidMsgTypePOP3 );
   277    	
   278 
   278     iEntry = iMsvSession.GetEntryL( iService );
   279     // <qmail> iSelection construction has been removed
   279     if ( !iEntry )
   280 
   280         {
   281     CMsvEntry* cEntry = iMsvSession.GetEntryL( iService );
   281         User::Leave( KErrGeneral );
   282     User::LeaveIfNull( cEntry );
   282         }
   283     // NOTE: Not using cleanupStack as it is not needed in this situation:
   283     iSelection = new(ELeave) CMsvEntrySelection;
   284     const TMsvEntry tentry = cEntry->Entry();
   284     const TMsvEntry& tentry = iEntry->Entry();
   285     delete cEntry;
       
   286     cEntry = NULL;
       
   287 
       
   288     if ( tentry.iType.iUid != KUidMsvServiceEntryValue )
       
   289         {
       
   290         // should we panic with own codes?
       
   291         User::Leave( KErrNotSupported );
       
   292         }
       
   293 
       
   294     // <qmail> no need to have population limit as member variable
       
   295     // <qmail> it is read from settings when needed
   285     
   296     
   286     if ( tentry.iType.iUid != KUidMsvServiceEntryValue )
   297     if ( tentry.Connected() )
   287         {
   298         {      
   288         User::Leave( KErrNotSupported );
   299         iState = EConnected;
   289         }
   300 		iAlreadyConnected = ETrue;
   290     
   301         }
   291     // get correct populate and sync limet values from settings
   302     else
       
   303         {
       
   304         iState = EStartConnect;
       
   305         }
       
   306     // <qmail> SetActive(); moved inside CompleteThis();
       
   307     CompleteThis();
       
   308     }
       
   309 
       
   310 // ----------------------------------------------------------------------------
       
   311 // CIpsPlgPop3ConnectOp::DoConnectL()
       
   312 // ----------------------------------------------------------------------------
       
   313 //
       
   314 void CIpsPlgPop3ConnectOp::DoConnectL()
       
   315     {
       
   316     FUNC_LOG;
       
   317     // <qmail> unnecessary: iStatus = KRequestPending;
       
   318     InvokeClientMtmAsyncFunctionL( KPOP3MTMConnect, iService ); // <qmail> 1 param removed
       
   319     SetActive();
       
   320 
       
   321 // <qmail>
       
   322     if ( iEventHandler )
       
   323         {
       
   324         iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncStarted, KErrNone );
       
   325         }
       
   326 // </qmail>
       
   327     }
       
   328 
       
   329 // ----------------------------------------------------------------------------
       
   330 // CIpsPlgPop3ConnectOp::DoPopulateL()
       
   331 // ----------------------------------------------------------------------------
       
   332 //
       
   333 void CIpsPlgPop3ConnectOp::DoPopulateL()
       
   334     {
       
   335     FUNC_LOG;
       
   336     // <qmail> unnecessary: iStatus = KRequestPending;
       
   337 
       
   338     // Prepare parameters and include filtering
       
   339     TImPop3PopulateOptions pop3GetMailInfo;
       
   340     pop3GetMailInfo.SetMaxEmailSize( KMaxTInt32 );
       
   341 // <qmail>
       
   342     pop3GetMailInfo.SetPopulationLimit( GetPopulateLimitFromSettingsL() );
       
   343     TPckgBuf<TImPop3PopulateOptions> params( pop3GetMailInfo );
       
   344 
       
   345     // <qmail> selection is no longer a member variable
       
   346     CMsvEntrySelection* selection = new(ELeave) CMsvEntrySelection;
       
   347     CleanupStack::PushL( selection );
       
   348     selection->InsertL( 0, iService );
       
   349     iBaseMtm->SwitchCurrentEntryL( iService );
       
   350     // Start the fetch operation
       
   351     InvokeClientMtmAsyncFunctionL( KPOP3MTMPopulateAll, *selection, params ); // <qmail> 1 param removed
       
   352     SetActive();
       
   353     CleanupStack::PopAndDestroy( selection );
       
   354 // <qmail> iEventHandler->SetNewPropertyEvent call removed from here
       
   355 // </qmail>
       
   356     }
       
   357 // <qmail> Connected() moved to baseclass
       
   358 
       
   359 // ----------------------------------------------------------------------------
       
   360 // ----------------------------------------------------------------------------
       
   361 // <qmail> return type
       
   362 TIpsOpType CIpsPlgPop3ConnectOp::IpsOpType() const
       
   363     {
       
   364     FUNC_LOG;
       
   365     return EIpsOpTypePop3SyncOp;
       
   366     }
       
   367 
       
   368 // <qmail> removed QueryUsrPassL() from here as unneeded
       
   369 // <qmail> removed ValidateL() (did nothing)
       
   370 // <qmail> removed TInt CIpsPlgPop3ConnectOp::GetOperationErrorCodeL( )
       
   371 // <qmail> removed CIpsPlgImap4ConnectOp::CredientialsSetL
       
   372 
       
   373 //<qmail> new functions
       
   374 // ----------------------------------------------------------------------------
       
   375 // ----------------------------------------------------------------------------
       
   376 void CIpsPlgPop3ConnectOp::DoDisconnect()
       
   377     {
       
   378     FUNC_LOG;
       
   379     // <qmail> unnecessary: iStatus = KRequestPending;
       
   380     InvokeClientMtmAsyncFunctionL( KPOP3MTMDisconnect, iService ); // <qmail> 1 param removed
       
   381     SetActive();
       
   382     }
       
   383 
       
   384 // ----------------------------------------------------------------------------
       
   385 // ----------------------------------------------------------------------------
       
   386 TInt CIpsPlgPop3ConnectOp::GetPopulateLimitFromSettingsL()
       
   387     {
       
   388     FUNC_LOG;
       
   389     TInt limit( KDefaultPopulateLimit );
       
   390         
   292     CImPop3Settings* settings = new(ELeave) CImPop3Settings();
   391     CImPop3Settings* settings = new(ELeave) CImPop3Settings();
   293     CleanupStack::PushL( settings );
   392     CleanupStack::PushL( settings );
   294     TPopAccount popAccountId;
   393     TPopAccount popAccountId;
   295     CEmailAccounts* accounts = CEmailAccounts::NewLC();
   394     CEmailAccounts* accounts = CEmailAccounts::NewLC();
   296     accounts->GetPopAccountL( iService , popAccountId );
   395     accounts->GetPopAccountL( iService , popAccountId );
   297     accounts->LoadPopSettingsL( popAccountId, *settings );
   396     accounts->LoadPopSettingsL( popAccountId, *settings );
   298     iPopulateLimit = settings->PopulationLimit();
   397     limit = settings->PopulationLimit();
   299     if ( iPopulateLimit > 0 )
   398     if ( limit > 0 )
   300         {
   399         {
   301         iPopulateLimit = ( iPopulateLimit * 1024 ) / 75;
   400         // basically doing a _very_rough_ conversion from kilobyte value to number-of-rows
   302         }
   401     limit = ( limit * KPopulateAlgorithmBytesInKilo ) / KPopulateAlgorithmRowLength;
   303     else
   402         }
   304         {
       
   305         iPopulateLimit = KMaxTInt;
       
   306         }
       
   307     
       
   308     CleanupStack::PopAndDestroy( 2, settings );
   403     CleanupStack::PopAndDestroy( 2, settings );
   309        
   404     return limit;
   310     if ( tentry.Connected() )
   405     }
   311         {      
   406 
   312         iState = EConnected; 
       
   313         // <qmail> SetActive(); moved inside CompleteThis();
       
   314         CompleteThis();
       
   315         }
       
   316     else
       
   317         {
       
   318         iState = EStartConnect; 
       
   319         // <qmail> SetActive(); moved inside CompleteThis();
       
   320         CompleteThis();
       
   321         }    
       
   322     }
       
   323 
       
   324 // ----------------------------------------------------------------------------
       
   325 // CIpsPlgPop3ConnectOp::DoConnectL()
       
   326 // ----------------------------------------------------------------------------
       
   327 //
       
   328 void CIpsPlgPop3ConnectOp::DoConnectL()
       
   329     {
       
   330     FUNC_LOG;
       
   331     // <qmail> unnecessary: iStatus = KRequestPending;
       
   332     InvokeClientMtmAsyncFunctionL( KPOP3MTMConnect, iService ); // <qmail> 1 param removed
       
   333     SetActive();
       
   334     
       
   335     if ( iEventHandler )
       
   336         {
       
   337         iEventHandler->SetNewPropertyEvent( 
       
   338                 iService, KIpsSosEmailSyncStarted, KErrNone );
       
   339         } 
       
   340     }
       
   341 
       
   342 // ----------------------------------------------------------------------------
       
   343 // CIpsPlgPop3ConnectOp::DoPopulateL()
       
   344 // ----------------------------------------------------------------------------
       
   345 //
       
   346 void CIpsPlgPop3ConnectOp::DoPopulateL()
       
   347     {
       
   348     FUNC_LOG;
       
   349     // <qmail> unnecessary: iStatus = KRequestPending;
       
   350 
       
   351     // Prepare parameters and include filtering
       
   352     TImPop3PopulateOptions pop3GetMailInfo;
       
   353     pop3GetMailInfo.SetMaxEmailSize( KMaxTInt32 );
       
   354     pop3GetMailInfo.SetPopulationLimit( iPopulateLimit );
       
   355     TPckgBuf<TImPop3PopulateOptions> params( pop3GetMailInfo );
       
   356 
       
   357     iSelection->InsertL(0, iService);
       
   358     iBaseMtm->SwitchCurrentEntryL( iService );
       
   359     // Start the fetch operation
       
   360     InvokeClientMtmAsyncFunctionL( KPOP3MTMPopulateAll, *iSelection, params ); // <qmail> 1 param removed
       
   361 
       
   362     SetActive();
       
   363     }
       
   364 // <qmail> Connected() moved to baseclass
       
   365 
       
   366 // ----------------------------------------------------------------------------
       
   367 // ----------------------------------------------------------------------------
       
   368 // <qmail> return type
       
   369 TIpsOpType CIpsPlgPop3ConnectOp::IpsOpType() const
       
   370     {
       
   371     FUNC_LOG;
       
   372     return EIpsOpTypePop3SyncOp;
       
   373     }
       
   374 
       
   375 // <qmail> removed QueryUsrPassL() from here as unneeded
       
   376 // <qmail> ValidateL() removed (did nothing)
       
   377 
       
   378 // ----------------------------------------------------------------------------
       
   379 // ----------------------------------------------------------------------------    
       
   380 // 
       
   381 TInt CIpsPlgPop3ConnectOp::GetOperationErrorCodeL( )
       
   382     {
       
   383     FUNC_LOG;
       
   384     if ( !iSubOperation )
       
   385         {
       
   386         return KErrNotFound;
       
   387         }
       
   388     if ( !iSubOperation->IsActive() && iSubOperation->iStatus.Int() != KErrNone )
       
   389         {
       
   390         return iSubOperation->iStatus.Int();
       
   391         }
       
   392     
       
   393     TPckgBuf<TPop3Progress> paramPack;
       
   394     paramPack.Copy( iSubOperation->ProgressL() );
       
   395     const TPop3Progress& progress = paramPack();
       
   396     
       
   397     return progress.iErrorCode;
       
   398     }
       
   399 
       
   400 // <qmail> Removing CIpsPlgImap4ConnectOp::CredientialsSetL 
       
   401 
       
   402 //<qmail> new state
       
   403 // ----------------------------------------------------------------------------
       
   404 // ----------------------------------------------------------------------------
       
   405 void CIpsPlgPop3ConnectOp::DoDisconnect()
       
   406     {
       
   407     FUNC_LOG;
       
   408     // <qmail> unnecessary: iStatus = KRequestPending;
       
   409     InvokeClientMtmAsyncFunctionL( KPOP3MTMDisconnect, iService ); // <qmail> 1 param removed
       
   410     SetActive();
       
   411     }
       
   412 //</qmail>
   407 //</qmail>