ipsservices/ipssosplugin/src/ipsplgimap4fetchattachmentop.cpp
branchRCL_3
changeset 64 3533d4323edc
parent 63 d189ee25cf9d
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
    18 
    18 
    19 
    19 
    20 #include "emailtrace.h"
    20 #include "emailtrace.h"
    21 #include "ipsplgheaders.h"
    21 #include "ipsplgheaders.h"
    22 
    22 
    23 // <qmail> priority const has been removed, interval changed to 0.2 sec
    23 // Constants and defines
    24 const TInt KIpsAttaFetchProgressReportInterval = 200000; // 0.2 sec
    24 const TInt KFetchOpPriority = CActive::EPriorityStandard;
       
    25 const TInt KIpsAttaFetchProgressReportInterval = 1000000; // 1 sec
    25 const TInt KIpsAttaFetchRetryInterval = 1000000; // 1 sec
    26 const TInt KIpsAttaFetchRetryInterval = 1000000; // 1 sec
    26 const TInt KIpsAttaFetchRetryCount = 30;
    27 const TInt KIpsAttaFetchRetryCount = 30;
    27 
    28 
    28 // ----------------------------------------------------------------------------
    29 // ----------------------------------------------------------------------------
    29 // ----------------------------------------------------------------------------
    30 // ----------------------------------------------------------------------------
    96     iAttaOp.ReportProgressL();
    97     iAttaOp.ReportProgressL();
    97     AdjustTimer();
    98     AdjustTimer();
    98     }
    99     }
    99 
   100 
   100 // ----------------------------------------------------------------------------
   101 // ----------------------------------------------------------------------------
   101 // CIpsPlgImap4FetchAttachmentOp
   102 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
       
   103 // <qmail> aFunctionId removed, CMsvEntrySelection& changed to pointer
       
   104 // <qmail> MFSMailRequestObserver& changed to pointer
       
   105 CIpsPlgImap4FetchAttachmentOp* CIpsPlgImap4FetchAttachmentOp::NewL(
   103 CIpsPlgImap4FetchAttachmentOp* CIpsPlgImap4FetchAttachmentOp::NewL(
   106     CMsvSession& aMsvSession,
   104     CMsvSession& aMsvSession,
   107     TRequestStatus& aObserverRequestStatus,
   105     TRequestStatus& aObserverRequestStatus,
       
   106     TInt aFunctionId,
   108     TMsvId aService,
   107     TMsvId aService,
   109     CIpsPlgTimerOperation& aActivityTimer,
   108     CIpsPlgTimerOperation& aActivityTimer,
   110     const CMsvEntrySelection* aSelection,
   109     const TImImap4GetMailInfo& aGetMailInfo,
       
   110     const CMsvEntrySelection& aSel,
   111     TFSMailMsgId aFSMailBoxId,
   111     TFSMailMsgId aFSMailBoxId,
   112     MFSMailRequestObserver* aFSOperationObserver,
   112     MFSMailRequestObserver& aFSOperationObserver,
   113     TInt aFSRequestId )
   113     TInt aFSRequestId )
   114     {
   114     {
   115     FUNC_LOG;
   115     FUNC_LOG;
   116     CIpsPlgImap4FetchAttachmentOp* op = new (
   116     CIpsPlgImap4FetchAttachmentOp* op = new (
   117         ELeave) CIpsPlgImap4FetchAttachmentOp(
   117         ELeave) CIpsPlgImap4FetchAttachmentOp(
   118         aMsvSession,
   118         aMsvSession,
   119         aObserverRequestStatus,
   119         aObserverRequestStatus,
       
   120         aFunctionId,
   120         aService,
   121         aService,
   121         aActivityTimer,
   122         aActivityTimer,
   122         aSelection,
   123         aGetMailInfo,
   123         aFSMailBoxId,
   124         aFSMailBoxId,
   124         aFSOperationObserver,
   125         aFSOperationObserver,
   125         aFSRequestId );
   126         aFSRequestId );
   126         
   127         
   127     CleanupStack::PushL( op );
   128     CleanupStack::PushL( op );
   128     op->ConstructL();
   129     op->ConstructL( aSel );
   129     CleanupStack::Pop( op );
   130     CleanupStack::Pop( op );
   130     return op;
   131     return op;
   131     }
   132     }
   132 
   133 
   133 // ----------------------------------------------------------------------------
   134 // ----------------------------------------------------------------------------
   134 // ----------------------------------------------------------------------------
   135 // ----------------------------------------------------------------------------
   135 // <qmail> priority parameter has been removed
       
   136 // <qmail> MFSMailRequestObserver& changed to pointer
       
   137 CIpsPlgImap4FetchAttachmentOp::CIpsPlgImap4FetchAttachmentOp(
   136 CIpsPlgImap4FetchAttachmentOp::CIpsPlgImap4FetchAttachmentOp(
   138     CMsvSession& aMsvSession,
   137     CMsvSession& aMsvSession,
   139     TRequestStatus& aObserverRequestStatus,
   138     TRequestStatus& aObserverRequestStatus,
       
   139     TInt aFunctionId,
   140     TMsvId aService,
   140     TMsvId aService,
   141     CIpsPlgTimerOperation& aActivityTimer,
   141     CIpsPlgTimerOperation& aActivityTimer,
   142     const CMsvEntrySelection* aSelection,
   142     const TImImap4GetMailInfo& aGetMailInfo,
   143     TFSMailMsgId aFSMailBoxId,
   143     TFSMailMsgId aFSMailBoxId,
   144     MFSMailRequestObserver* aFSOperationObserver,
   144     MFSMailRequestObserver& aFSOperationObserver,
   145     TInt aFSRequestId )
   145     TInt aFSRequestId )
   146     :
   146     :
   147     CIpsPlgOnlineOperation(
   147     CIpsPlgOnlineOperation(
   148         aMsvSession,
   148     aMsvSession,
   149         aObserverRequestStatus,
   149     KFetchOpPriority,
   150         aActivityTimer,
   150     aObserverRequestStatus,
   151         aFSMailBoxId,
   151     aActivityTimer,
   152         aFSOperationObserver,
   152     aFSMailBoxId,
   153         aFSRequestId ),
   153     aFSOperationObserver,
   154     	iSelection( aSelection ),
   154     aFSRequestId),
   155     	iRetryCount( 0 )
   155     iSelection( NULL ),
       
   156     iGetMailInfo(aGetMailInfo),
       
   157     iFunctionId(aFunctionId),
       
   158     iRetryCount( 0 )
   156     {
   159     {
   157     FUNC_LOG;
   160     FUNC_LOG;
   158     iService = aService;
   161     iService = aService;
   159     iRetryTimer.CreateLocal();
   162     iRetryTimer.CreateLocal();
   160     }
   163     }
   165     {
   168     {
   166     FUNC_LOG;
   169     FUNC_LOG;
   167     iRetryTimer.Close();
   170     iRetryTimer.Close();
   168     delete iSelection;
   171     delete iSelection;
   169     delete iProgReport;
   172     delete iProgReport;
   170     delete iFetchErrorProgress;
   173     }
   171     }
   174 
   172 
   175 // ----------------------------------------------------------------------------
   173 // ----------------------------------------------------------------------------
   176 // ----------------------------------------------------------------------------
   174 // ----------------------------------------------------------------------------
   177 void CIpsPlgImap4FetchAttachmentOp::ConstructL( const CMsvEntrySelection& aSel )
   175 void CIpsPlgImap4FetchAttachmentOp::ConstructL()
       
   176     {
   178     {
   177     FUNC_LOG;
   179     FUNC_LOG;
   178     BaseConstructL( KUidMsgTypeIMAP4 );
   180     BaseConstructL( KUidMsgTypeIMAP4 );
       
   181     iSelection = aSel.CopyL();
   179     DoConnectL();
   182     DoConnectL();
   180     }
   183     }
   181 
   184 
   182 // ----------------------------------------------------------------------------
   185 // ----------------------------------------------------------------------------
   183 // ----------------------------------------------------------------------------
   186 // ----------------------------------------------------------------------------
   185     {
   188     {
   186     FUNC_LOG;
   189     FUNC_LOG;
   187     iState = EStateConnecting;
   190     iState = EStateConnecting;
   188     iStatus = KRequestPending;
   191     iStatus = KRequestPending;
   189 
   192 
   190     // <qmail> priority parameter has been removed
       
   191     CIpsPlgImap4ConnectOp* connOp = CIpsPlgImap4ConnectOp::NewL(
   193     CIpsPlgImap4ConnectOp* connOp = CIpsPlgImap4ConnectOp::NewL(
   192         iMsvSession,
   194         iMsvSession,
       
   195         KFetchOpPriority,
   193         iStatus, 
   196         iStatus, 
   194         iService,
   197         iService,
   195         *iActivityTimer,
   198         *iActivityTimer,
   196         iFSMailboxId,
   199         iFSMailboxId,
   197         NULL, // no observer for subopertaion
   200         iFSOperationObserver,
   198         0,    // no requestId needed
   201         iFSRequestId,
   199         NULL, // event handler not needed whin plain connect
   202         NULL, // event handler not needed whin plain connect
   200         ETrue );
   203         ETrue,
       
   204         EFalse );
   201         
   205         
   202     delete iSubOperation;
   206     delete iOperation;
   203     iSubOperation = connOp;
   207     iOperation = connOp;
   204 
   208 
   205     SetActive();
   209     SetActive();
   206     }
   210     }
   207     
   211     
   208 // ----------------------------------------------------------------------------
   212 // ----------------------------------------------------------------------------
   225     FUNC_LOG;
   229     FUNC_LOG;
   226     switch( iState )
   230     switch( iState )
   227         {
   231         {
   228         case EStateConnecting:
   232         case EStateConnecting:
   229             {
   233             {
   230             // <qmail> Connected() usage
   234             // get result of connect operation
   231             if ( !Connected() )
   235             TInt err = iStatus.Int();
       
   236 
       
   237             if( err != KErrNone )
   232                 {
   238                 {
   233                 CompleteObserver( KErrCouldNotConnect );
   239                 CompleteObserver( err == KErrCancel ? err : KErrCouldNotConnect );
   234                 return;
   240                 return;
   235                 }
   241                 }
   236             iRetryCount = 0;
   242             iRetryCount = 0;
   237             DoFetchAttachmentL();
   243             DoFetchAttachmentL();
   238             break;
   244             break;
   260                 iRetryTimer.After( iStatus, KIpsAttaFetchRetryInterval );
   266                 iRetryTimer.After( iStatus, KIpsAttaFetchRetryInterval );
   261                 SetActive();
   267                 SetActive();
   262                 }
   268                 }
   263             else
   269             else
   264                 {
   270                 {
   265                 if( err != KErrNone && iSubOperation )
   271                 if( err != KErrNone && iOperation )
   266                     {
   272                     {
   267                     iFetchErrorProgress = iSubOperation->ProgressL().AllocL();
   273                     iFetchErrorProgress = iOperation->ProgressL().AllocL();
   268                     }
   274                     }
   269                 
   275                 
   270                 iState = EStateIdle;
   276                 iState = EStateIdle;
   271                 CompleteObserver( err );
   277                 CompleteObserver( err );
   272                 }
   278                 }
   286         {
   292         {
   287         // Completed, but with an error during fetch.
   293         // Completed, but with an error during fetch.
   288         return *iFetchErrorProgress;
   294         return *iFetchErrorProgress;
   289         }
   295         }
   290     
   296     
   291     if ( iSubOperation )
   297     if ( iOperation )
   292         {
   298         {
   293         iProgress.Copy( iSubOperation->ProgressL() );
   299         iProgress.Copy( iOperation->ProgressL() );
   294         }
   300         }
   295     else
   301     else
   296         {
   302         {
   297         TImap4CompoundProgress progg;
   303         TImap4CompoundProgress progg;
   298         progg.iGenericProgress.iErrorCode = KErrNone;
   304         progg.iGenericProgress.iErrorCode = KErrNone;
   308 void CIpsPlgImap4FetchAttachmentOp::ReportProgressL()
   314 void CIpsPlgImap4FetchAttachmentOp::ReportProgressL()
   309     {
   315     {
   310     FUNC_LOG;
   316     FUNC_LOG;
   311     TInt error = KErrNone;
   317     TInt error = KErrNone;
   312     TFSProgress fsProgress = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   318     TFSProgress fsProgress = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   313     if ( iSubOperation && iState == EStateFetching )
   319     if ( iOperation && iState == EStateFetching )
   314         {
   320         {
   315         TRAP(error, iProgress.Copy( iSubOperation->ProgressL() ) );
   321         TRAP(error, iProgress.Copy( iOperation->ProgressL() ) );
   316         }
   322         }
   317     
   323     
   318     if ( error == KErrNone )
   324     if ( error == KErrNone )
   319         {
   325         {
   320         const TImap4GenericProgress& progg = iProgress().iGenericProgress;
   326         const TImap4GenericProgress& progg = iProgress().iGenericProgress;
   334         }
   340         }
   335     else
   341     else
   336         {
   342         {
   337         User::Leave( error );
   343         User::Leave( error );
   338         }
   344         }
   339 
   345     
   340 // <qmail>
   346     iFSOperationObserver.RequestResponseL( fsProgress, iFSRequestId );
   341     // signal observer if it exists
       
   342     if ( iFSOperationObserver )
       
   343         {
       
   344         iFSOperationObserver->RequestResponseL( fsProgress, iFSRequestId );
       
   345         }
       
   346 // </qmail>
       
   347     }
   347     }
   348 
   348 
   349 // ----------------------------------------------------------------------------
   349 // ----------------------------------------------------------------------------
   350 // ----------------------------------------------------------------------------
   350 // ----------------------------------------------------------------------------
   351 const TDesC8& CIpsPlgImap4FetchAttachmentOp::GetErrorProgressL(TInt /*aError*/ )
   351 const TDesC8& CIpsPlgImap4FetchAttachmentOp::GetErrorProgressL(TInt /*aError*/ )
   397     {
   397     {
   398     FUNC_LOG;
   398     FUNC_LOG;
   399     iState = EStateFetching;
   399     iState = EStateFetching;
   400 
   400 
   401     // Switch operations.
   401     // Switch operations.
   402     delete iSubOperation;
   402     delete iOperation;
   403     iSubOperation = NULL;
   403     iOperation = NULL;
   404     iStatus = KRequestPending;
   404     iStatus = KRequestPending;
   405 
   405 
   406     iProgReport = CIpsFetchProgReport::NewL( *this );
   406     iProgReport = CIpsFetchProgReport::NewL( *this );
   407 
   407 
   408     // Filters are not used when performing 'fetch' operation, 
   408     // Filters are not used when performing 'fetch' operation, 
   409     // use normal getmail info instead
   409     // use normal getmail info instead
   410 // <qmail>
   410     TPckg<TImImap4GetMailInfo> param(iGetMailInfo);
   411     TPckgBuf<TImImap4GetMailInfo> param;
   411     InvokeClientMtmAsyncFunctionL( iFunctionId, *iSelection, iService, param );
   412     TImImap4GetMailInfo& options = param();
       
   413     options.iMaxEmailSize = KMaxTInt32;
       
   414     options.iGetMailBodyParts = EGetImap4EmailAttachments;
       
   415     options.iDestinationFolder = 0; // not used
       
   416 
       
   417     InvokeClientMtmAsyncFunctionL( KIMAP4MTMPopulate, *iSelection, param ); // <qmail> 1 param removed
       
   418 // </qmail>
       
   419     SetActive();
   412     SetActive();
   420     }
   413     }
   421     
   414     
   422 // <qmail> GetEngineProgress function removed
       
   423 
       
   424 // <qmail> new func to this op
       
   425 // ----------------------------------------------------------------------------
   415 // ----------------------------------------------------------------------------
   426 // ----------------------------------------------------------------------------    
   416 // ----------------------------------------------------------------------------    
   427 TIpsOpType CIpsPlgImap4FetchAttachmentOp::IpsOpType() const
   417 TInt CIpsPlgImap4FetchAttachmentOp::GetEngineProgress( const TDesC8& aProgress )
   428     {
   418     {
   429     FUNC_LOG;
   419     FUNC_LOG;
   430     return EIpsOpTypeFetchAttachmentOp;
   420     if( !aProgress.Length() )
   431     }
   421         {
   432 // </qmail>
   422         return KErrNone;
       
   423         }
       
   424     else
       
   425         {
       
   426         TPckgBuf<TImap4CompoundProgress> paramPack;
       
   427         paramPack.Copy( aProgress );
       
   428         const TImap4GenericProgress& progress = paramPack().iGenericProgress;
       
   429 
       
   430         return progress.iErrorCode;
       
   431         }    
       
   432     }        
   433 
   433 
   434 
   434 
   435 // End of File
   435 // End of File
   436 
   436