ipsservices/ipssosplugin/src/ipsplgimap4populateop.cpp
branchRCL_3
changeset 63 d189ee25cf9d
parent 61 dcf0eedfc1a3
child 64 3533d4323edc
--- a/ipsservices/ipssosplugin/src/ipsplgimap4populateop.cpp	Thu Aug 19 09:38:05 2010 +0300
+++ b/ipsservices/ipssosplugin/src/ipsplgimap4populateop.cpp	Tue Aug 31 15:04:17 2010 +0300
@@ -18,22 +18,21 @@
 #include "emailtrace.h"
 #include "ipsplgheaders.h"
 
-// Constants and defines
-const TInt KFetchOpPriority = CActive::EPriorityStandard;
-const TInt KIpsPlgSelectionGra = 16;
+// <qmail> priority const has been removed
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
+// <qmail> priority parameter has been removed
+// <qmail> MFSMailRequestObserver& changed to pointer
 EXPORT_C CIpsPlgImap4PopulateOp* CIpsPlgImap4PopulateOp::NewL(
     CMsvSession& aMsvSession,
     TRequestStatus& aObserverRequestStatus,
-    TInt aPriority,
     TMsvId aService,
     CIpsPlgTimerOperation& aActivityTimer,
     const TImImap4GetPartialMailInfo& aPartialMailInfo,
     const CMsvEntrySelection& aSel,
     TFSMailMsgId aFSMailBoxId,
-    MFSMailRequestObserver& aFSOperationObserver,
+    MFSMailRequestObserver* aFSOperationObserver,
     TInt aFSRequestId,
     CIpsPlgEventHandler* aEventHandler,
     TBool aDoFilterSelection )
@@ -42,7 +41,6 @@
     CIpsPlgImap4PopulateOp* op = new (ELeave) CIpsPlgImap4PopulateOp(
         aMsvSession,
         aObserverRequestStatus,
-        aPriority,
         aService,
         aActivityTimer,
         aPartialMailInfo,
@@ -59,29 +57,31 @@
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
+// <qmail> priority parameter has been removed
 CIpsPlgImap4PopulateOp::CIpsPlgImap4PopulateOp(
     CMsvSession& aMsvSession,
     TRequestStatus& aObserverRequestStatus,
-    TInt aPriority,
     TMsvId aService,
     CIpsPlgTimerOperation& aActivityTimer,
     const TImImap4GetPartialMailInfo& aPartialMailInfo,
     TFSMailMsgId aFSMailBoxId,
-    MFSMailRequestObserver& aFSOperationObserver,
+    MFSMailRequestObserver* aFSOperationObserver,
     TInt aFSRequestId,
     CIpsPlgEventHandler* aEventHandler )
     :
     CIpsPlgOnlineOperation(
-    aMsvSession,
-    aPriority,
-    aObserverRequestStatus,
-    aActivityTimer,
-    aFSMailBoxId,
-    aFSOperationObserver,
-    aFSRequestId),
+        aMsvSession,
+        aObserverRequestStatus,
+        aActivityTimer,
+        aFSMailBoxId,
+        aFSOperationObserver,
+        aFSRequestId ),
+    iState( EStateIdle ),
     iPartialMailInfo(aPartialMailInfo),
-    iSelection( KIpsPlgSelectionGra ),
-    iEventHandler( aEventHandler )
+    iSelection( NULL ),
+    iTempSelection( NULL ),
+    iEventHandler( aEventHandler ),
+    iFetchErrorProgress( NULL )
     {
     FUNC_LOG;
     iService = aService;
@@ -92,14 +92,12 @@
 CIpsPlgImap4PopulateOp::~CIpsPlgImap4PopulateOp()
     {
     FUNC_LOG;
-    
-    Cancel();
-    iSelection.Close();
+    delete iSelection;
 
     if ( iTempSelection )
     	{
     	iTempSelection->Reset();
-   	delete iTempSelection;
+   		delete iTempSelection;
     	}
     }
 
@@ -112,27 +110,32 @@
     FUNC_LOG;
     BaseConstructL( KUidMsgTypeIMAP4 );
     
+    // <qmail> instantiation moved here
+    iSelection = new ( ELeave ) CMsvEntrySelection();
+    iTempSelection = new ( ELeave ) CMsvEntrySelection();
+
     if ( aDoFilterSelection )
         {
         FilterSelectionL( aSel );
         }
-    else
+    else // no filtering; populate all
         {
+        // first entry in selection is serviceId
         for ( TInt i = 1; i < aSel.Count(); i++ )
             {
             if ( aSel[i] != iService )
                 {
-                iSelection.AppendL( aSel.At(i) );
+                iSelection->AppendL( aSel.At(i) );
                 }
             }
         }
-    iTempSelection = new ( ELeave ) CMsvEntrySelection();
     DoConnectL();
     }
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-TInt CIpsPlgImap4PopulateOp::IpsOpType() const
+// <qmail> return type changed: TInt -> TIpsOpType
+TIpsOpType CIpsPlgImap4PopulateOp::IpsOpType() const
     {
     FUNC_LOG;
     return EIpsOpTypeImap4PopulateOp;
@@ -146,21 +149,20 @@
     iState = EStateConnecting;
     iStatus = KRequestPending;
 
+    // <qmail> priority parameter has been removed
     CIpsPlgImap4ConnectOp* connOp = CIpsPlgImap4ConnectOp::NewL(
         iMsvSession,
-        KFetchOpPriority,
         iStatus, 
         iService,
         *iActivityTimer,
         iFSMailboxId,
-        iFSOperationObserver,
-        iFSRequestId,
+        NULL, // no observer for suboperations
+        0,    // requestId not needed
         iEventHandler,
-        ETrue, // Do plain connect
-        EFalse );
+        ETrue ); // Do plain connect
         
-    delete iOperation;
-    iOperation = connOp;
+    delete iSubOperation;
+    iSubOperation = connOp;
 
     SetActive();
     }
@@ -184,8 +186,8 @@
     {
     FUNC_LOG;
     TInt err = iStatus.Int();
-    delete iOperation;
-    iOperation = NULL;
+    delete iSubOperation;
+    iSubOperation = NULL;
     
     switch( iState )
         {
@@ -204,33 +206,17 @@
             }
         case EStateFetching:         
             {
-            if( err != KErrNone && iOperation )
+            if( err != KErrNone && iSubOperation )
                 {
-                iFetchErrorProgress = iOperation->ProgressL().AllocL();
+                iFetchErrorProgress = iSubOperation->ProgressL().AllocL();
                 iState = EStateIdle;
                 Complete();
                 }
-            else
-                {
-                
-                }
             break;
             }
         case EStateInfoEntryChange:
             {
-            TMsvEntry tentry;
-            TMsvId service;
-            iMsvSession.GetEntry( iService, service, tentry );
-          
-            if( err == KErrNone && tentry.Connected() )
-            	{
-            	DoPopulateL();  
-            	}  
-            else
-            	{
-            	iState = EStateIdle;
-            	CompleteObserver( err );
-            	}            
+            DoPopulateL();
             break;
             }
         case EStateIdle:
@@ -244,9 +230,9 @@
 void CIpsPlgImap4PopulateOp::DoCancel()
     {
     FUNC_LOG;
-    if( iOperation )
+    if( iSubOperation )
         {
-        iOperation->Cancel();
+        iSubOperation->Cancel();
         }
     CompleteObserver( KErrCancel );
     }
@@ -260,13 +246,16 @@
         {
         // Completed, but with an error during fetch.
         return *iFetchErrorProgress;
-        }        
-    TImap4SyncProgress progg;
-    progg.iFoldersNotFound = 0;
-    progg.iErrorCode = KErrNone;
-    TPckgBuf<TImap4SyncProgress> param(progg);
-    iSyncProgress.Copy(param);
-    return iSyncProgress; 
+        }
+    else
+        {
+        TImap4SyncProgress progg;
+    	progg.iFoldersNotFound = 0;
+        progg.iErrorCode = KErrNone;
+        TPckgBuf<TImap4SyncProgress> param(progg);
+        iSyncProgress.Copy(param);
+        return iSyncProgress;
+        }
     }
 
 // ----------------------------------------------------------------------------
@@ -304,23 +293,7 @@
     return result;
     }
 
-// ----------------------------------------------------------------------------
-// ----------------------------------------------------------------------------    
-TInt CIpsPlgImap4PopulateOp::GetEngineProgress( const TDesC8& aProgress )
-    {
-    FUNC_LOG;
-    if( !aProgress.Length() )
-        {
-        return KErrNone;
-        }
-    else
-        {
-        TPckgBuf<TImap4CompoundProgress> paramPack;
-        paramPack.Copy( aProgress );
-        const TImap4GenericProgress& progress = paramPack().iGenericProgress;
-        return progress.iErrorCode;        
-        }    
-    }    
+// <qmail> removed CIpsPlgImap4PopulateOp::GetEngineProgress( const TDesC8& aProgress )
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
@@ -333,11 +306,10 @@
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-void CIpsPlgImap4PopulateOp::FilterSelectionL( 
-        const CMsvEntrySelection& aSelection )
+void CIpsPlgImap4PopulateOp::FilterSelectionL( const CMsvEntrySelection& aSelection )
     {
     FUNC_LOG;
-    iSelection.Reset();
+    iSelection->Reset();
     TMsvId messageId;
     // NOTE: this code is taken from symbian os source IMPCMTM.CPP
     // filter selection is in here because messages are
@@ -349,7 +321,7 @@
         messageId = (aSelection)[i];
         if ( messageId == iService )
             {
-            continue;
+            continue; // ignore serviceId
             }
         TMsvEmailEntry entry;
         TMsvId service = KMsvNullIndexEntryId;          
@@ -369,11 +341,11 @@
               && !isComplete
               && entry.iType == KUidMsvMessageEntry )
             {
-            iSelection.AppendL(messageId); 
+            iSelection->AppendL( messageId ); 
             }
         else if ( isMsgEntry && isSizeUnderMax && !isParentComp )
             {
-            iSelection.AppendL(messageId);
+            iSelection->AppendL( messageId );
             }
         }
     }
@@ -382,20 +354,15 @@
 // ----------------------------------------------------------------------------
 TBool CIpsPlgImap4PopulateOp::IsPartialPopulate( )
     {
+    // <qmail> cleaned up code and took one "always true" condition out from the if statement
     FUNC_LOG;
     // NOTE: this code is taken from symbian os source IMPCMTM.CPP
     // code is modified to this class purpose 
-    
-    TBool isPartialPopulate = EFalse;
-    if(iPartialMailInfo.iPartialMailOptions == ENoSizeLimits &&
-       iPartialMailInfo.iTotalSizeLimit == KMaxTInt &&
-       iPartialMailInfo.iBodyTextSizeLimit == KMaxTInt && 
-       iPartialMailInfo.iAttachmentSizeLimit == KMaxTInt && 
-        (iPartialMailInfo.iGetMailBodyParts == EGetImap4EmailHeaders || 
-         iPartialMailInfo.iGetMailBodyParts == EGetImap4EmailBodyText ||
-         iPartialMailInfo.iGetMailBodyParts == EGetImap4EmailBodyTextAndAttachments ||
-         iPartialMailInfo.iGetMailBodyParts == EGetImap4EmailAttachments ||
-         iPartialMailInfo.iGetMailBodyParts == EGetImap4EmailBodyAlternativeText) )
+    TBool isPartialPopulate( EFalse );
+    if ( iPartialMailInfo.iPartialMailOptions == ENoSizeLimits &&
+         iPartialMailInfo.iTotalSizeLimit == KMaxTInt &&
+         iPartialMailInfo.iBodyTextSizeLimit == KMaxTInt && 
+         iPartialMailInfo.iAttachmentSizeLimit == KMaxTInt )
         {
         isPartialPopulate = EFalse;
         }
@@ -403,7 +370,6 @@
         {
         isPartialPopulate = ETrue;
         }
-
     return isPartialPopulate;
     }
 
@@ -412,50 +378,34 @@
 void CIpsPlgImap4PopulateOp::DoPopulateL( )
     {
     FUNC_LOG;
-    if ( iSelection.Count() > 0 )
+    if ( iSelection->Count() > 0 )
         {
         TMsvEmailEntry tEntry;
         TMsvId dummy;
-        TInt lastIndex = iSelection.Count()-1;
-        User::LeaveIfError( iMsvSession.GetEntry(
-                iSelection[lastIndex], dummy, tEntry ) );
+        TInt lastIndex = iSelection->Count()-1;
+        User::LeaveIfError( iMsvSession.GetEntry( iSelection->At(lastIndex), dummy, tEntry ) );
         
         iState = EStateFetching;
 
         iTempSelection->Reset();
         iTempSelection->AppendL( iService );
-        iTempSelection->AppendL( iSelection[lastIndex] );
-        iSelection.Remove(lastIndex);
-        
-        
-        iStatus = KRequestPending;
-    
+        iTempSelection->AppendL( iSelection->At( lastIndex ) );
+        iSelection->Delete( lastIndex );
+            
         // Filters are not used when performing 'fetch'
         // operation, use normal getmail info instead
-        TPckg<TImImap4GetPartialMailInfo> param(iPartialMailInfo);
+        TPckg<TImImap4GetPartialMailInfo> param( iPartialMailInfo );
         iBaseMtm->SwitchCurrentEntryL( iService );
-        iOperation = iBaseMtm->InvokeAsyncFunctionL(
-                KIMAP4MTMPopulateMailSelectionWhenAlreadyConnected, 
-                *iTempSelection, param, this->iStatus);
+        iSubOperation = iBaseMtm->InvokeAsyncFunctionL(
+            KIMAP4MTMPopulateMailSelectionWhenAlreadyConnected, 
+            *iTempSelection, param, iStatus );
         iState = EStateInfoEntryChange;
         SetActive();
-        
-        if ( iEventHandler )
-              {
-              iEventHandler->SetNewPropertyEvent( 
-                      iService, KIpsSosEmailSyncStarted, KErrNone );
-              } 
         }
     else
         {
         iState = EStateIdle;
         CompleteObserver();
-        
-        if ( iEventHandler )
-            {
-            iEventHandler->SetNewPropertyEvent( 
-                iService, KIpsSosEmailSyncCompleted, KErrNone );
-            }               
         }
     }