diff -r 578830873419 -r ecc8def7944a ipsservices/ipssosplugin/src/ipsplgimap4connectop.cpp --- a/ipsservices/ipssosplugin/src/ipsplgimap4connectop.cpp Fri Apr 16 14:51:52 2010 +0300 +++ b/ipsservices/ipssosplugin/src/ipsplgimap4connectop.cpp Mon May 03 12:23:15 2010 +0300 @@ -16,7 +16,6 @@ * */ - #include "emailtrace.h" #include "ipsplgheaders.h" @@ -26,29 +25,24 @@ const TInt KIpsSetDataFullBodyOnly = -3; // -_LIT( KIpsPlgIpsConnPanic, "IpsConn" ); - // ---------------------------------------------------------------------------- -// CIpsPlgImap4ConnectOp::NewL() +// CIpsPlgImap4ConnOp::NewL() // ---------------------------------------------------------------------------- -// +// priority parameter has been removed CIpsPlgImap4ConnectOp* CIpsPlgImap4ConnectOp::NewL( CMsvSession& aMsvSession, - TInt aPriority, TRequestStatus& aObserverRequestStatus, TMsvId aService, CIpsPlgTimerOperation& aActivityTimer, TFSMailMsgId aFSMailBoxId, - MFSMailRequestObserver& aFSOperationObserver, + MFSMailRequestObserver* aFSOperationObserver, TInt aFSRequestId, CIpsPlgEventHandler* aEventHandler, - TBool aDoPlainConnect, - TBool aSignallingAllowed ) + TBool aDoPlainConnect ) { FUNC_LOG; CIpsPlgImap4ConnectOp* self = new (ELeave) CIpsPlgImap4ConnectOp( aMsvSession, - aPriority, aObserverRequestStatus, aService, aActivityTimer, @@ -56,7 +50,6 @@ aFSOperationObserver, aFSRequestId, aDoPlainConnect, - aSignallingAllowed, aEventHandler ); CleanupStack::PushL( self ); @@ -68,29 +61,27 @@ // ---------------------------------------------------------------------------- // CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp() // ---------------------------------------------------------------------------- -// +// priority parameter has been removed CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp( CMsvSession& aMsvSession, - TInt aPriority, TRequestStatus& aObserverRequestStatus, TMsvId aService, CIpsPlgTimerOperation& aActivityTimer, TFSMailMsgId aFSMailBoxId, - MFSMailRequestObserver& aFSOperationObserver, + MFSMailRequestObserver* aFSOperationObserver, TInt aFSRequestId, TBool aDoPlainConnect, - TBool aSignallingAllowed, CIpsPlgEventHandler* aEventHandler) : CIpsPlgOnlineOperation( aMsvSession, - aPriority, aObserverRequestStatus, aActivityTimer, aFSMailBoxId, aFSOperationObserver, - aFSRequestId, - aSignallingAllowed ), + aFSRequestId ), + iState( EStateIdle ), + iSelection( NULL ), iDoPlainConnect( aDoPlainConnect ), iEventHandler( aEventHandler ), iIsSyncStartedSignaled( EFalse ) @@ -108,7 +99,7 @@ FUNC_LOG; Cancel(); delete iSelection; - iState = EStateIdle; + // setting state in destructor makes no sense } // ---------------------------------------------------------------------------- @@ -130,9 +121,19 @@ User::Panic( KIpsPlgIpsConnPanic, KErrNotSupported ); } - iState = EStateStartConnect; + // moved here from StartL which was removed + if ( Connected() && iDoPlainConnect ) + { + // trivial case: connect requested, but already connected + // (sync is done automatically on background) + iState = EStateIdle; + } + else + { + iState = EStateStartConnect; + } iStatus = KRequestPending; - SetActive(); + // SetActive(); moved inside CompleteThis(); CompleteThis(); } @@ -147,9 +148,9 @@ { return GetErrorProgressL( iError ); } - else if(iOperation) + else if( iSubOperation ) { - return iOperation->ProgressL(); + return iSubOperation->ProgressL(); } TImap4CompoundProgress& prog = iProgressBuf(); @@ -181,9 +182,7 @@ result.iError = KErrNone; switch( iState ) { - case EStateQueryingDetails: - result.iProgressStatus = TFSProgress::EFSStatus_Authenticating; - break; + // case EStateQueryingDetails removed case EStateStartConnect: result.iProgressStatus = TFSProgress::EFSStatus_Started; break; @@ -206,8 +205,8 @@ // ---------------------------------------------------------------------------- // CIpsPlgImap4ConnectOp::IpsOpType() // ---------------------------------------------------------------------------- -// -TInt CIpsPlgImap4ConnectOp::IpsOpType() const +// return type +TIpsOpType CIpsPlgImap4ConnectOp::IpsOpType() const { FUNC_LOG; return EIpsOpTypeImap4SyncOp; @@ -221,9 +220,9 @@ void CIpsPlgImap4ConnectOp::DoCancel() { FUNC_LOG; - if( iOperation ) + if( iSubOperation ) { - iOperation->Cancel(); + iSubOperation->Cancel(); } SignalSyncCompleted( KErrCancel ); CompleteObserver( KErrCancel ); @@ -236,48 +235,34 @@ void CIpsPlgImap4ConnectOp::DoRunL() { FUNC_LOG; - TInt err = KErrNone; - __ASSERT_DEBUG( !(iOperation && iOperation->IsActive()), - User::Panic( KIpsPlgPanicCategory, KErrGeneral ) ); - if ( iOperation ) + TInt err( KErrNone ); + __ASSERT_DEBUG( !(iSubOperation && iSubOperation->IsActive()), + User::Panic( KIpsPlgPanicCategory, KErrGeneral ) ); + if ( iSubOperation ) { - err = iOperation->iStatus.Int(); - delete iOperation; - iOperation = NULL; + err = iSubOperation->iStatus.Int(); + delete iSubOperation; + iSubOperation = NULL; } switch( iState ) { - case EStateQueryingDetails: - - if ( KErrNone != err ) - { - // user might be cancelled query - // or it IS EMPTY - iError = err; - iState = EStateIdle; - } - else - { - // Retry connect. - DoConnectOpL(); - } + // removing case EStateQueryingDetails + case EStateStartConnect: + // remove StartL() func and replace it directly with DoConnectOpL + DoConnectOpL(); break; - case EStateStartConnect: - StartL(); - break; case EStateConnectAndSync: // Connection completed - if( err == KErrImapBadLogon ) + // all errors should fail the op + if( err ) { - // Login details are wrong. - QueryUserPwdL(); - iState = EStateQueryingDetails; - - err = KErrNone; + iState = EStateIdle; + // SetActive(); moved inside CompleteThis(); + CompleteThis(); } - else if ( err == KErrNone ) + else { // no errors in connection if( !iDoPlainConnect ) @@ -288,29 +273,28 @@ { // Get on with others using this class for connection only iState = EStateIdle; - SetActive(); + // SetActive(); moved inside CompleteThis(); CompleteThis(); } } break; case EStatePopulateAllCompleted: - CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( - iMsvSession, iService ); + CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( iMsvSession, iService ); // break command is intentially left out case EStateCompleted: if ( err == KErrNone ) { iState = EStateIdle; - SetActive(); + // SetActive(); moved inside CompleteThis(); CompleteThis(); } break; case EStateIdle: default: - if ( iOperation ) + if ( iSubOperation ) { - delete iOperation; - iOperation = NULL; + delete iSubOperation; + iSubOperation = NULL; } CompleteObserver(); break; @@ -324,15 +308,7 @@ } } -// ---------------------------------------------------------------------------- -// CIpsPlgImap4ConnectOp::HandleImapConnectionEvent() -// ---------------------------------------------------------------------------- -// -void CIpsPlgImap4ConnectOp::HandleImapConnectionEvent( - TImapConnectionEvent /*aConnectionEvent*/ ) - { - //not used at the moment - } +// CIpsPlgImap4ConnectOp::HandleImapConnectionEvent() removed // ---------------------------------------------------------------------------- // CIpsPlgImap4ConnectOp::RequestResponseL() @@ -355,44 +331,36 @@ iSelection->ResizeL(0); iSelection->AppendL(iService); - + + // + iStatus = KRequestPending; if ( iDoPlainConnect && !Connected() ) { TBuf8<1> parameter; - iStatus = KRequestPending; // connect and synchronise starts background sync or idle - iOperation = iBaseMtm->InvokeAsyncFunctionL( - KIMAP4MTMConnect, *iSelection, parameter, iStatus); - // also set sync started - SignalSyncStarted(); - iState = EStateConnectAndSync; - SetActive(); + iSubOperation = iBaseMtm->InvokeAsyncFunctionL( + KIMAP4MTMConnect, *iSelection, parameter, iStatus); } else if ( Connected() ) { // in this point cant use "connect and do something" commands, // use regular sync, when new mails is populated elsewhere. TBuf8<1> parameter; - iStatus = KRequestPending; - iOperation = iBaseMtm->InvokeAsyncFunctionL( - KIMAP4MTMFullSync, *iSelection, parameter, iStatus); - // also set sync started - SignalSyncStarted(); - iState = EStateConnectAndSync; - SetActive(); + iSubOperation = iBaseMtm->InvokeAsyncFunctionL( + KIMAP4MTMFullSync, *iSelection, parameter, iStatus); } else { - TPckg parameter(this); - // connect and synchronise starts background sync or idle - iStatus = KRequestPending; - iOperation = iBaseMtm->InvokeAsyncFunctionL( - KIMAP4MTMConnectAndSyncCompleteAfterFullSync, - *iSelection, parameter, iStatus); - SignalSyncStarted(); - iState = EStateConnectAndSync; - SetActive(); + // the used command requires an observer to be given even though we're not using it + TPckg parameter( NULL ); + iSubOperation = iBaseMtm->InvokeAsyncFunctionL( + KIMAP4MTMConnectAndSyncCompleteAfterFullSync, + *iSelection, parameter, iStatus ); } + SignalSyncStarted(); + iState = EStateConnectAndSync; + SetActive(); + // } // ---------------------------------------------------------------------------- @@ -403,116 +371,53 @@ FUNC_LOG; // construct partial fetch info according to imap settings - CImImap4Settings* settings = new ( ELeave ) CImImap4Settings(); - CleanupStack::PushL( settings ); - CEmailAccounts* accounts = CEmailAccounts::NewLC(); - TImapAccount imapAcc; - accounts->GetImapAccountL(iService, imapAcc ); - accounts->LoadImapSettingsL( imapAcc, *settings ); + // new function to wrap settings loading + CImImap4Settings* settings = GetImapSettingsLC(); TImImap4GetPartialMailInfo info; ConstructImapPartialFetchInfo( info, *settings ); TPckgBuf package(info); - CleanupStack::PopAndDestroy( 2, settings ); + CleanupStack::PopAndDestroy( settings ); + settings = NULL; + // do populate operation unless only headers should be fetched if ( info.iTotalSizeLimit != KIpsSetDataHeadersOnly ) { - SignalSyncStarted(); - CMsvEntry* cEntry = iMsvSession.GetEntryL( iService ); - CleanupStack::PushL( cEntry ); - CMsvEntrySelection* childrenSelection = cEntry->ChildrenL(); - CleanupStack::PushL( childrenSelection ); - if ( childrenSelection->Count() ) - { - // only inbox is set, do we have to populate other folders also - TMsvId id = (*childrenSelection)[0]; - CMsvEntry* cEntry2 = iMsvSession.GetEntryL( id ); - CleanupStack::PushL( cEntry2 ); - delete iSelection; - iSelection = NULL; - iSelection = cEntry2->ChildrenWithTypeL( KUidMsvMessageEntry ); - CleanupStack::PopAndDestroy( cEntry2 ); - - } - CleanupStack::PopAndDestroy( childrenSelection ); - + // Update iSelection (which will be given to populate op) + // new function to wrap iSelection populating + CreateInboxMessagesSelectionL(); + iStatus = KRequestPending; - CIpsPlgTimerOperation* dummy = NULL; iBaseMtm->SwitchCurrentEntryL( iService ); - iOperation = CIpsPlgImap4PopulateOp::NewL( - iMsvSession, - this->iStatus, - CActive::EPriorityLow, - iService, - *dummy, - info, - *iSelection, - iFSMailboxId, - *this, - 0, - iEventHandler ); + // priority parameter has been removed + iSubOperation = CIpsPlgImap4PopulateOp::NewL( + iMsvSession, + iStatus, + iService, + // passing in activity timer; only place where NULL "reference" was used + // -> can get rid of checking existence of a reference memeber... + iActivityTimer, + info, + *iSelection, + iFSMailboxId, + NULL, // no observer for suboperation + 0, // requestId can be 0 + iEventHandler ); SetActive(); - CleanupStack::PopAndDestroy( cEntry ); + // SignalSyncStarted signal moved to happen later in case something goes wrong + SignalSyncStarted(); } else { - SetActive(); + // SetActive(); moved inside CompleteThis(); CompleteThis(); } iState = EStatePopulateAllCompleted; } -// ---------------------------------------------------------------------------- -// CIpsPlgImap4ConnectOp::StartL() -// ---------------------------------------------------------------------------- -// -void CIpsPlgImap4ConnectOp::StartL() - { - FUNC_LOG; - if ( Connected() && iDoPlainConnect ) - { - // sync is done background, no explicit supported - iState = EStateIdle; - SetActive(); - CompleteThis(); - } - else - { - DoConnectOpL(); - } - } - -// ---------------------------------------------------------------------------- -// CIpsPlgImap4ConnectOp::QueryUserPwdL() -// ---------------------------------------------------------------------------- -// -void CIpsPlgImap4ConnectOp::QueryUserPwdL() - { - iEventHandler->QueryUsrPassL( iService, this ); - } - - -// ---------------------------------------------------------------------------- -// CIpsPlgImap4ConnectOp::GetOperationErrorCodeL() -// ---------------------------------------------------------------------------- -// -/*TInt CIpsPlgImap4ConnectOp::GetOperationErrorCodeL( ) - { - if ( !iOperation ) - { - return KErrNotFound; - } - if ( !iOperation->IsActive() && iOperation->iStatus.Int() != KErrNone ) - { - return iOperation->iStatus.Int(); - } - - TPckgBuf paramPack; - paramPack.Copy( iOperation->ProgressL() ); - const TImap4CompoundProgress& comProgg = paramPack(); - - return comProgg.iGenericProgress.iErrorCode; - }*/ +// remove CIpsPlgImap4ConnectOp::StartL() +// remove CIpsPlgImap4ConnectOp::QueryUserPwdL() +// remove CIpsPlgImap4ConnectOp::GetOperationErrorCodeL() // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- @@ -524,8 +429,7 @@ // mark that sync is signaled to prevent // sending necessary event iIsSyncStartedSignaled = ETrue; - iEventHandler->SetNewPropertyEvent( - iService, KIpsSosEmailSyncStarted, KErrNone ); + iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncStarted, KErrNone ); } } @@ -534,36 +438,22 @@ void CIpsPlgImap4ConnectOp::SignalSyncCompleted( TInt aError ) { FUNC_LOG; - if ( iEventHandler && aError == KErrImapBadLogon ) + // don't test for aError code; all situations should complete op + if ( iEventHandler ) { - iEventHandler->SetNewPropertyEvent( - iService, KIpsSosEmailSyncCompleted, aError ); + iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncCompleted, aError ); iIsSyncStartedSignaled = EFalse; } } - -// ---------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -void CIpsPlgImap4ConnectOp::CredientialsSetL( TInt aEvent ) - { - FUNC_LOG; - if ( aEvent == EIPSSosCredientialsCancelled ) - { - CompleteObserver( KErrCancel ); - } - //password has been set, continue with operation - - SetActive(); - CompleteThis(); - } +// Removing CIpsPlgImap4ConnectOp::CredientialsSetL // // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- void CIpsPlgImap4ConnectOp::ConstructImapPartialFetchInfo( - TImImap4GetPartialMailInfo& aInfo, CImImap4Settings& aImap4Settings ) - + TImImap4GetPartialMailInfo& aInfo, + const CImImap4Settings& aImap4Settings ) { FUNC_LOG; TInt sizeLimit = aImap4Settings.BodyTextSizeLimit(); @@ -593,7 +483,6 @@ else { aInfo.iTotalSizeLimit = sizeLimit*1024; - // set zero when it not documentated does total size overrides these aInfo.iAttachmentSizeLimit = 0; aInfo.iMaxEmailSize = sizeLimit*1024; aInfo.iBodyTextSizeLimit = sizeLimit*1024; @@ -601,6 +490,47 @@ aInfo.iGetMailBodyParts = EGetImap4EmailBodyAlternativeText; } } + +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +CImImap4Settings* CIpsPlgImap4ConnectOp::GetImapSettingsLC() + { + FUNC_LOG; + CImImap4Settings* settings = new ( ELeave ) CImImap4Settings(); + CleanupStack::PushL( settings ); + CEmailAccounts* accounts = CEmailAccounts::NewLC(); + TImapAccount imapAcc; + accounts->GetImapAccountL(iService, imapAcc ); + accounts->LoadImapSettingsL( imapAcc, *settings ); + CleanupStack::PopAndDestroy( accounts ); + return settings; + } + +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +void CIpsPlgImap4ConnectOp::CreateInboxMessagesSelectionL() + { + FUNC_LOG; + // get children of service entry + CMsvEntry* cEntry = iMsvSession.GetEntryL( iService ); + CleanupStack::PushL( cEntry ); + CMsvEntrySelection* childrenSelection = cEntry->ChildrenL(); + CleanupStack::PopAndDestroy( cEntry ); + cEntry = NULL; + CleanupStack::PushL( childrenSelection ); + + if ( childrenSelection->Count() ) + { + TMsvId id = (*childrenSelection)[0]; // index 0 == inbox + cEntry = iMsvSession.GetEntryL( id ); // reusing cEntry pointer for Inbox entry + CleanupStack::PushL( cEntry ); + delete iSelection; + iSelection = NULL; + // get message-type children of inbox + iSelection = cEntry->ChildrenWithTypeL( KUidMsvMessageEntry ); + CleanupStack::PopAndDestroy( cEntry ); + } + CleanupStack::PopAndDestroy( childrenSelection ); + } + // -// End of File -