ipsservices/ipssosplugin/src/ipsplgimap4populateop.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 23 2dc6caa42ec3
--- a/ipsservices/ipssosplugin/src/ipsplgimap4populateop.cpp	Fri Apr 16 14:51:52 2010 +0300
+++ b/ipsservices/ipssosplugin/src/ipsplgimap4populateop.cpp	Mon May 03 12:23:15 2010 +0300
@@ -18,22 +18,18 @@
 #include "emailtrace.h"
 #include "ipsplgheaders.h"
 
-// Constants and defines
-const TInt KFetchOpPriority = CActive::EPriorityStandard;
-const TInt KIpsPlgSelectionGra = 16;
-
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
+// <qmail> priority parameter has been removed
 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 +38,6 @@
     CIpsPlgImap4PopulateOp* op = new (ELeave) CIpsPlgImap4PopulateOp(
         aMsvSession,
         aObserverRequestStatus,
-        aPriority,
         aService,
         aActivityTimer,
         aPartialMailInfo,
@@ -59,29 +54,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,45 +89,43 @@
 CIpsPlgImap4PopulateOp::~CIpsPlgImap4PopulateOp()
     {
     FUNC_LOG;
-    iSelection.Close();
-
-    if ( iTempSelection )
-    	{
-    	iTempSelection->Reset();
+    delete iSelection;
    	delete iTempSelection;
-    	}
     }
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-void CIpsPlgImap4PopulateOp::ConstructL( 
-        const CMsvEntrySelection& aSel,
-        TBool aDoFilterSelection )
+void CIpsPlgImap4PopulateOp::ConstructL( const CMsvEntrySelection& aSel, TBool aDoFilterSelection )
     {
     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
+TIpsOpType CIpsPlgImap4PopulateOp::IpsOpType() const
     {
     FUNC_LOG;
     return EIpsOpTypeImap4PopulateOp;
@@ -144,21 +139,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();
     }
@@ -182,8 +176,8 @@
     {
     FUNC_LOG;
     TInt err = iStatus.Int();
-    delete iOperation;
-    iOperation = NULL;
+    delete iSubOperation;
+    iSubOperation = NULL;
     
     switch( iState )
         {
@@ -191,7 +185,7 @@
             {
             TMsvEntry tentry;
             TMsvId service;
-            iMsvSession.GetEntry(iService, service, tentry );
+            iMsvSession.GetEntry( iService, service, tentry );
             if( !tentry.Connected() )
                 {
                 CompleteObserver( KErrCouldNotConnect );
@@ -202,16 +196,12 @@
             }
         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:
@@ -230,9 +220,9 @@
 void CIpsPlgImap4PopulateOp::DoCancel()
     {
     FUNC_LOG;
-    if( iOperation )
+    if( iSubOperation )
         {
-        iOperation->Cancel();
+        iSubOperation->Cancel();
         }
     CompleteObserver( KErrCancel );
     }
@@ -246,12 +236,15 @@
         {
         // Completed, but with an error during fetch.
         return *iFetchErrorProgress;
-        }        
-    TImap4SyncProgress progg;
-    progg.iErrorCode = KErrNone;
-    TPckgBuf<TImap4SyncProgress> param(progg);
-    iSyncProgress.Copy(param);
-    return iSyncProgress; 
+        }
+    else
+        {
+        TImap4SyncProgress progg;
+        progg.iErrorCode = KErrNone;
+        TPckgBuf<TImap4SyncProgress> param(progg);
+        iSyncProgress.Copy(param);
+        return iSyncProgress;
+        }
     }
 
 // ----------------------------------------------------------------------------
@@ -289,23 +282,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 )
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
@@ -318,27 +295,22 @@
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-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
-    // fetched separately then we dont have to make unneccessery imap 
-    // client mtm calls
 
-    for (TInt i=0; i<aSelection.Count(); i++)
+    for ( TInt i = 0; i < aSelection.Count(); i++ )
         {
-        messageId = (aSelection)[i];
+        messageId  = (aSelection)[i];
         if ( messageId == iService )
             {
-            continue;
+            continue; // ignore serviceId
             }
         TMsvEmailEntry entry;
-        TMsvId service = KMsvNullIndexEntryId;          
-        User::LeaveIfError(iMsvSession.GetEntry(messageId, service, entry));
+        TMsvId service( KMsvNullIndexEntryId );          
+        User::LeaveIfError( iMsvSession.GetEntry( messageId, service, entry ) );
         
         TBool isComplete = !(   ( entry.Complete() && entry.PartialDownloaded() ) 
                              || ( !entry.Complete() && ( !entry.BodyTextComplete() 
@@ -347,18 +319,15 @@
 
         TBool isMsgEntry = entry.iType == KUidMsvMessageEntry;
         TBool isSizeUnderMax = entry.iSize <= iPartialMailInfo.iMaxEmailSize;
-        TBool isParentComp = entry.Parent() == 
-            iPartialMailInfo.iDestinationFolder && isComplete;
+        TBool isParentComp = entry.Parent() == iPartialMailInfo.iDestinationFolder && isComplete;
         
-        if( IsPartialPopulate( )
-              && !isComplete
-              && entry.iType == KUidMsvMessageEntry )
+        if( isMsgEntry && IsPartialPopulate() && !isComplete )
             {
-            iSelection.AppendL(messageId); 
+            iSelection->AppendL( messageId ); 
             }
         else if ( isMsgEntry && isSizeUnderMax && !isParentComp )
             {
-            iSelection.AppendL(messageId);
+            iSelection->AppendL( messageId );
             }
         }
     }
@@ -367,20 +336,13 @@
 // ----------------------------------------------------------------------------
 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;
         }
@@ -388,7 +350,6 @@
         {
         isPartialPopulate = ETrue;
         }
-
     return isPartialPopulate;
     }
 
@@ -397,31 +358,27 @@
 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();
         }
@@ -431,5 +388,3 @@
         CompleteObserver();
         }
     }
-
-// End of File