ipsservices/ipssosplugin/src/ipsplgonlineoperation.cpp
branchRCL_3
changeset 24 d189ee25cf9d
parent 8 e1b6206813b4
child 25 3533d4323edc
--- a/ipsservices/ipssosplugin/src/ipsplgonlineoperation.cpp	Thu Aug 19 09:38:05 2010 +0300
+++ b/ipsservices/ipssosplugin/src/ipsplgonlineoperation.cpp	Tue Aug 31 15:04:17 2010 +0300
@@ -15,12 +15,9 @@
 *
 */
 
-
-
 #include "emailtrace.h"
 #include "ipsplgheaders.h"
 
-
 // ----------------------------------------------------------------------------
 // CIpsPlgOnlineOperation::~CIpsPlgOnlineOperation()
 // ----------------------------------------------------------------------------
@@ -29,7 +26,7 @@
     {
     FUNC_LOG;
     Cancel();   
-    delete iOperation;
+    delete iSubOperation;
     delete iBaseMtm;
     delete iMtmReg;
     }
@@ -37,26 +34,30 @@
 // ----------------------------------------------------------------------------
 // CIpsPlgOnlineOperation::CIpsPlgOnlineOperation()
 // ----------------------------------------------------------------------------
-//
+// <qmail> priority parameter has been removed
+// <qmail> MFSMailRequestObserver& changed to pointer
+// <qmail> aSignallingAllowed parameter has been returned
 CIpsPlgOnlineOperation::CIpsPlgOnlineOperation(
     CMsvSession& aMsvSession,
-    TInt aPriority,
     TRequestStatus& aObserverRequestStatus,
     CIpsPlgTimerOperation& aActivityTimer,
     TFSMailMsgId aFSMailBoxId,
-    MFSMailRequestObserver& aFSOperationObserver,
+    MFSMailRequestObserver* aFSOperationObserver,
     TInt aFSRequestId,
     TBool aSignallingAllowed )
     :
-    CIpsPlgBaseOperation( aMsvSession, aPriority, aObserverRequestStatus,
-        aFSRequestId, aFSMailBoxId ), 
-        iActivityTimer( &aActivityTimer ),
-        iBaseMtm( NULL ),
-        iMtmReg( NULL ), 
-        iOperation( NULL ),
-        iError( KErrNone ),
-        iSignallingAllowed( aSignallingAllowed ),
-        iFSOperationObserver( aFSOperationObserver )
+    CIpsPlgBaseOperation(
+        aMsvSession, 
+        aObserverRequestStatus,
+        aFSRequestId, 
+        aFSMailBoxId ), 
+    iActivityTimer( &aActivityTimer ),
+    iBaseMtm( NULL ),
+    iMtmReg( NULL ), 
+    iSubOperation( NULL ),
+    iError( KErrNone ),
+    iSignallingAllowed( aSignallingAllowed ),
+    iFSOperationObserver( aFSOperationObserver )
     {
     FUNC_LOG;
     }
@@ -65,20 +66,19 @@
 // CIpsPlgOnlineOperation::BaseConstructL()
 // ----------------------------------------------------------------------------
 //
-void CIpsPlgOnlineOperation::BaseConstructL(TUid aMtmType)
+void CIpsPlgOnlineOperation::BaseConstructL( TUid aMtmType )
     {
     FUNC_LOG;
     // reset timer, if operation not completed after timer fires causes
     // disconnection
-    if( iActivityTimer )
+    // <qmail> remove cheking of existence of this reference member
+    if (iActivityTimer)
         {
         iActivityTimer->ResetTimerOperation();
         }
 
     iMtmReg = CClientMtmRegistry::NewL( iMsvSession );
-    
     iBaseMtm = iMtmReg->NewMtmL( aMtmType );
-    
     iObserverRequestStatus = KRequestPending;
     CActiveScheduler::Add(this);
     }
@@ -90,9 +90,9 @@
 void CIpsPlgOnlineOperation::DoCancel()
     {
     FUNC_LOG;
-    if( iOperation )
+    if( iSubOperation )
         {
-        iOperation->Cancel();
+        iSubOperation->Cancel();
         }
     CompleteObserver( KErrCancel );
     }
@@ -104,31 +104,21 @@
 void CIpsPlgOnlineOperation::RunL()
     {
     FUNC_LOG;
-    
-    TInt err = KErrNone;
+    TInt err( KErrNone );
     TRAP( err, DoRunL() );
     
     // Just end the operation, if something has gone wrong
-    if ( err != KErrNone )
+    if ( err )
         {
         CompleteObserver( err );
         }
-    else if ( iError != KErrNone )
+    else if ( iError )
         {
         CompleteObserver( iError );
         }
     }
 
-// ----------------------------------------------------------------------------
-// CIpsPlgOnlineOperation::RunError()
-// ----------------------------------------------------------------------------
-//
-TInt CIpsPlgOnlineOperation::RunError( TInt aError )
-    {
-    FUNC_LOG;
-    CompleteObserver( aError );
-    return KErrNone; // RunError must return KErrNone to active sheduler.
-    }
+// <qmail> removing TInt CIpsPlgOnlineOperation::RunError( TInt aError )
 
 // ----------------------------------------------------------------------------
 // CIpsPlgOnlineOperation::CompleteObserver()
@@ -137,17 +127,24 @@
 void CIpsPlgOnlineOperation::CompleteObserver( TInt aStatus )
     {
     FUNC_LOG;
+    NM_COMMENT("CIpsPlgOnlineOperation::CompleteObserver");
     TRequestStatus* status = &iObserverRequestStatus;
     if (status && status->Int() == KRequestPending)
         {
-    
         SignalFSObserver( aStatus );
+        // <qmail>
         // removed checks to prevent unwanted disconnections
-        //if we're connected, reset activitytimer. if not, there is no reason to.
-        if( iActivityTimer )
+        //if connected, reset activitytimer. if not, there is no reason to.
+        if ( Connected() )
             {
+            NM_COMMENT("CIpsPlgOnlineOperation::reseting activitytimer");
             iActivityTimer->ResetTimerOperation();
             }
+        else
+            {
+            iActivityTimer->Cancel();
+            }
+        // </qmail>
         User::RequestComplete(status, aStatus);
         }
     }
@@ -159,7 +156,7 @@
 void CIpsPlgOnlineOperation::CompleteThis()
     {
     FUNC_LOG;
-    
+    SetActive();
     TRequestStatus* status = &iStatus;
     User::RequestComplete(status, KErrNone);
     }
@@ -167,11 +164,10 @@
 // ----------------------------------------------------------------------------
 // CIpsPlgOnlineOperation::InvokeClientMtmAsyncFunctionL()
 // ----------------------------------------------------------------------------
-//
+// <qmail> remove contextId as not needed
 void CIpsPlgOnlineOperation::InvokeClientMtmAsyncFunctionL(
     TInt aFunctionId,
     TMsvId aEntryId,
-    TMsvId aContextId,
     const TDesC8& aParams)
     {
     FUNC_LOG;
@@ -179,19 +175,18 @@
     CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection;
     CleanupStack::PushL( sel );
     sel->AppendL( aEntryId );
-    InvokeClientMtmAsyncFunctionL(aFunctionId, *sel, aContextId, aParams);
+    InvokeClientMtmAsyncFunctionL(aFunctionId, *sel, aParams);
     CleanupStack::PopAndDestroy( sel ); 
     }
 
 // ----------------------------------------------------------------------------
 // CIpsPlgOnlineOperation::InvokeClientMtmAsyncFunctionL()
 // ----------------------------------------------------------------------------
-//
+// <qmail> remove contextId as not needed
 void CIpsPlgOnlineOperation::InvokeClientMtmAsyncFunctionL(
     TInt aFunctionId,
     const CMsvEntrySelection& aSel,
-    TMsvId aContextId,
-    const TDesC8& aParams)
+    const TDesC8& aParams )
     {
     FUNC_LOG;
     
@@ -202,24 +197,18 @@
         iMsvSession.GetEntry( aSel.At(0), service, tEntry );
         }
 
-    if( aContextId != tEntry.iServiceId )
-        {
-        // Client context must be service for FetchL().
-        iBaseMtm->SwitchCurrentEntryL( tEntry.iServiceId );
-        }
-    else
-        {                
-        iBaseMtm->SwitchCurrentEntryL( aContextId );
-        }
-    HBufC8* params = aParams.AllocLC();
+    // setting our context to serviceId
+    iBaseMtm->SwitchCurrentEntryL( tEntry.iServiceId );
+
+    HBufC8* params = aParams.AllocLC(); // can not pass const parameter to InvokeAsyncFunctionL
     TPtr8 ptr(params->Des());
     // Delete previous operation if it exist
-    if ( iOperation )
+    if ( iSubOperation )
         {
-        delete iOperation;
-        iOperation = NULL;
+        delete iSubOperation;
+        iSubOperation = NULL;
         }
-    iOperation = iBaseMtm->InvokeAsyncFunctionL(aFunctionId, aSel, ptr, iStatus);
+    iSubOperation = iBaseMtm->InvokeAsyncFunctionL( aFunctionId, aSel, ptr, iStatus );
     CleanupStack::PopAndDestroy( params ); 
     }
 
@@ -230,45 +219,40 @@
 void CIpsPlgOnlineOperation::SignalFSObserver( TInt aStatus )
     {
     FUNC_LOG;
-    if ( iSignallingAllowed )
+    // <qmail> clean up this function
+    // <qmail>
+    if( iSignallingAllowed )
+    // </qmail>    
         {
-        TFSProgress prog;
         // Initialize the progress data
+        TFSProgress prog = { TFSProgress::EFSStatus_RequestComplete, 1, 1, aStatus, NULL };
         // it would be better to get fs progress from inherited class
         // by calling FSProgressL method??
         if ( aStatus == KErrCancel )
             {
-            prog.iError = KErrNone;
-            prog.iProgressStatus = TFSProgress::EFSStatus_RequestCancelled;
-            }
-        else if ( aStatus == KErrImapBadLogon )
-            {
-            prog.iError = aStatus;
             prog.iProgressStatus = TFSProgress::EFSStatus_RequestCancelled;
             }
-        else
+        // <qmail>
+        if( iFSOperationObserver )
             {
-            prog.iError = aStatus;
-            prog.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
+            // do the actual signalling
+            TRAP_IGNORE( iFSOperationObserver->RequestResponseL( prog, iFSRequestId ) );
             }
-        // At least in the attachment download, FS UI assumes that
-        // the counter fields are greater than 0
-        prog.iMaxCount = 1;  
-        prog.iCounter = 1;
-
-        //in case of autoconnect, we don't have valid observer
-        if ( &iFSOperationObserver )
-            {            
-            TRAP_IGNORE( iFSOperationObserver.RequestResponseL( prog, iFSRequestId ) );
-            }
+        // </qmail>
         }
     }
 
+// <qmail> removed IpsOpType()
+
+// <qmail> makes more sence to have this method here in "base" online op than in every derived class
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-TInt CIpsPlgOnlineOperation::IpsOpType() const
+TBool CIpsPlgOnlineOperation::Connected() const
     {
     FUNC_LOG;
-    return EIpsOpTypeOnlineOp;
+    TMsvEntry tentry;
+    TMsvId service;
+    iMsvSession.GetEntry(iService, service, tentry );
+    return tentry.Connected();
     }
-
+// </qmail>