ipsservices/ipssosplugin/src/ipsplgpop3fetchoperation.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 30 759dc5235cdb
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    16 */
    16 */
    17 
    17 
    18 #include "emailtrace.h"
    18 #include "emailtrace.h"
    19 #include "ipsplgheaders.h"
    19 #include "ipsplgheaders.h"
    20 
    20 
    21 // ----------------------------------------------------------------------------
    21 // <qmail> priority const has been removed
    22 // ----------------------------------------------------------------------------
    22 // ----------------------------------------------------------------------------
       
    23 // ----------------------------------------------------------------------------
       
    24 // <qmail> MFSMailRequestObserver& changed to pointer
    23 CIpsPlgPop3FetchOperation* CIpsPlgPop3FetchOperation::NewL(
    25 CIpsPlgPop3FetchOperation* CIpsPlgPop3FetchOperation::NewL(
    24     CMsvSession& aMsvSession,
    26     CMsvSession& aMsvSession,
    25     TRequestStatus& aObserverRequestStatus,
    27     TRequestStatus& aObserverRequestStatus,
    26     TInt aFunctionId,
       
    27     TMsvId aService,
    28     TMsvId aService,
    28     CIpsPlgTimerOperation& aActivityTimer,
    29     CIpsPlgTimerOperation& aActivityTimer,
    29     const TImPop3GetMailInfo& aGetMailInfo,
    30     const TImPop3GetMailInfo& aGetMailInfo,
    30     const CMsvEntrySelection& aSel,
    31     CMsvEntrySelection* aSelection,
    31     TFSMailMsgId aFSMailBoxId,
    32     TFSMailMsgId aFSMailBoxId,
    32     MFSMailRequestObserver* aFSOperationObserver,
    33     MFSMailRequestObserver* aFSOperationObserver,
    33     TInt aFSRequestId,
    34     TInt aFSRequestId,
    34     CIpsPlgEventHandler* aEventHandler )
    35     CIpsPlgEventHandler* aEventHandler )
    35     {
    36     {
    36     FUNC_LOG;
    37     FUNC_LOG;
    37     CIpsPlgPop3FetchOperation* op = new(ELeave) CIpsPlgPop3FetchOperation(
    38     CIpsPlgPop3FetchOperation* op = new(ELeave) CIpsPlgPop3FetchOperation(
    38         aMsvSession, aObserverRequestStatus, aFunctionId, aService,
    39         aMsvSession,
    39         aActivityTimer, aGetMailInfo, aFSMailBoxId, aFSOperationObserver,
    40         aObserverRequestStatus, 
    40         aFSRequestId, aEventHandler );
    41         aService,
       
    42         aActivityTimer, 
       
    43         aGetMailInfo,
       
    44         aSelection,
       
    45         aFSMailBoxId, 
       
    46         aFSOperationObserver,
       
    47         aFSRequestId, 
       
    48         aEventHandler );
    41         
    49         
    42     CleanupStack::PushL(op);
    50     CleanupStack::PushL(op);
    43     op->ConstructL(aSel);
    51     op->ConstructL();
    44     CleanupStack::Pop( op );
    52     CleanupStack::Pop( op );
    45     return op;
    53     return op;
    46     }
    54     }
    47 
    55 
    48 // ----------------------------------------------------------------------------
    56 // ----------------------------------------------------------------------------
    51 CIpsPlgPop3FetchOperation::~CIpsPlgPop3FetchOperation()
    59 CIpsPlgPop3FetchOperation::~CIpsPlgPop3FetchOperation()
    52     {
    60     {
    53     FUNC_LOG;
    61     FUNC_LOG;
    54     delete iFetchErrorProgress;
    62     delete iFetchErrorProgress;
    55     delete iSelection;
    63     delete iSelection;
       
    64     
       
    65     delete iEntry;
    56     }
    66     }
    57 
    67 
    58 // ----------------------------------------------------------------------------
    68 // ----------------------------------------------------------------------------
    59 // ProgressL
    69 // ProgressL
    60 // ----------------------------------------------------------------------------
    70 // ----------------------------------------------------------------------------
    68         return *iFetchErrorProgress;
    78         return *iFetchErrorProgress;
    69         }
    79         }
    70     else
    80     else
    71         {
    81         {
    72         TPop3Progress progg;
    82         TPop3Progress progg;
       
    83         progg.iTotalSize = 0;
    73         progg.iErrorCode = KErrNone;
    84         progg.iErrorCode = KErrNone;
    74         TPckgBuf<TPop3Progress> param(progg);
    85         TPckgBuf<TPop3Progress> param(progg);
    75         iProgressBuf.Copy(param);
    86         iProgressBuf.Copy(param);
    76         return iProgressBuf;   
    87         return iProgressBuf;   
    77         }
    88         }
    78     }
    89     }
    79 
    90 
    80 // ----------------------------------------------------------------------------
    91 // ----------------------------------------------------------------------------
    81 // ConstructL
    92 // ConstructL
    82 // ----------------------------------------------------------------------------
    93 // ----------------------------------------------------------------------------
    83 void CIpsPlgPop3FetchOperation::ConstructL(const CMsvEntrySelection& aSel)
    94 void CIpsPlgPop3FetchOperation::ConstructL()
    84     {
    95     {
    85     FUNC_LOG;
    96     FUNC_LOG;
       
    97 
    86     BaseConstructL( KUidMsgTypePOP3 );
    98     BaseConstructL( KUidMsgTypePOP3 );
    87     iSelection = aSel.CopyL();
    99     // <qmail> 1st entry must be serviceId
    88     iSelection->InsertL( 0, iService );
   100     iSelection->InsertL( 0, iService );
    89     // For Get Mail API, first selection element must be service.
   101     // For Get Mail API, first selection element must be service.
    90     DoConnectL();
   102 
       
   103     // It is possible that the complete flag is on and we want to
       
   104     // download the attachment. In these cases we need to clear the
       
   105     // complete flag.
       
   106 
       
   107     TInt count = iSelection->Count();
       
   108 
       
   109     for ( ; iEntryIndex < count && !iSubOperation; iEntryIndex++ )
       
   110         {
       
   111         delete iEntry;
       
   112         iEntry = NULL;
       
   113         
       
   114         iEntry = iMsvSession.GetEntryL( iSelection->At( iEntryIndex ) );
       
   115 
       
   116         TMsvEntry entry = iEntry->Entry();
       
   117         
       
   118         TBool complete = entry.Complete();
       
   119 
       
   120         if ( complete )
       
   121             {
       
   122             entry.SetComplete( EFalse );
       
   123 
       
   124             iSubOperation = iEntry->ChangeL( entry, iStatus );
       
   125 
       
   126             SetActive();
       
   127             
       
   128             iState = EStateClearCompleteFlag;
       
   129             }
       
   130         }
       
   131 
       
   132     if ( !iSubOperation )
       
   133         {
       
   134         DoConnectL();
       
   135         }
    91     }
   136     }
    92 
   137 
    93 // ----------------------------------------------------------------------------
   138 // ----------------------------------------------------------------------------
    94 // DoConnectL
   139 // DoConnectL
    95 // ----------------------------------------------------------------------------
   140 // ----------------------------------------------------------------------------
   106     CIpsPlgPop3ConnectOp* connOp = CIpsPlgPop3ConnectOp::NewL(
   151     CIpsPlgPop3ConnectOp* connOp = CIpsPlgPop3ConnectOp::NewL(
   107         iMsvSession,
   152         iMsvSession,
   108         iStatus, 
   153         iStatus, 
   109         iService, 
   154         iService, 
   110         EFalse, 
   155         EFalse, 
   111         iActivityTimer,
   156         *iActivityTimer,
   112         iFSMailboxId, 
   157         iFSMailboxId, 
   113         iFSOperationObserver, 
   158         iFSOperationObserver, 
   114         iFSRequestId, 
   159         iFSRequestId, 
   115         NULL );
   160         NULL );
   116         
   161         
   127     {
   172     {
   128     FUNC_LOG;
   173     FUNC_LOG;
   129 
   174 
   130     iState = EStateFetching;
   175     iState = EStateFetching;
   131 
   176 
   132     // Switch operations.
   177     // <qmail> deletion of possible previous iSubOperaiton is handled in InvokeClientMtmAsyncFunctionL
   133     delete iSubOperation;
   178     // <qmail> delete iSubOperation;
   134     iSubOperation = NULL;
   179     // <qmail> iSubOperation = NULL;
       
   180     iStatus = KRequestPending;
   135 
   181 
   136     // Filters are not used when performing 'fetch' operation, use normal 
   182     // Filters are not used when performing 'fetch' operation, use normal 
   137     // getmail info instead
   183     // getmail info instead
   138     TPckg<TImPop3GetMailInfo> param( iGetMailInfo );
   184     TPckg<TImPop3GetMailInfo> param( iGetMailInfo );
   139     InvokeClientMtmAsyncFunctionL( iFunctionId, *iSelection, param );
   185     // <qmail> using constant functionId as its always the same
       
   186     InvokeClientMtmAsyncFunctionL( KPOP3MTMCopyMailSelectionWhenAlreadyConnected, *iSelection, param );
   140     SetActive();
   187     SetActive();
       
   188     
       
   189     if ( iEventHandler )
       
   190         {
       
   191         iEventHandler->SetNewPropertyEvent( 
       
   192             iService, KIpsSosEmailSyncStarted, KErrNone );
       
   193         } 
       
   194     
   141     }
   195     }
   142 
   196 
   143 // ----------------------------------------------------------------------------
   197 // ----------------------------------------------------------------------------
   144 // ----------------------------------------------------------------------------
   198 // ----------------------------------------------------------------------------
   145 // <qmail> priority parameter has been removed
   199 // <qmail> priority parameter has been removed
       
   200 // <qmail> MFSMailRequestObserver& changed to pointer
       
   201 // <qmail> aFunctionId parameter has been removed
       
   202 // <qmail> aSelection parameter has been added
   146 CIpsPlgPop3FetchOperation::CIpsPlgPop3FetchOperation(
   203 CIpsPlgPop3FetchOperation::CIpsPlgPop3FetchOperation(
   147     CMsvSession& aMsvSession,
   204     CMsvSession& aMsvSession,
   148     TRequestStatus& aObserverRequestStatus,
   205     TRequestStatus& aObserverRequestStatus,
   149     TInt aFunctionId,
       
   150     TMsvId aService,
   206     TMsvId aService,
   151     CIpsPlgTimerOperation& aActivityTimer,
   207     CIpsPlgTimerOperation& aActivityTimer,
   152     const TImPop3GetMailInfo& aGetMailInfo,
   208     const TImPop3GetMailInfo& aGetMailInfo,
       
   209     CMsvEntrySelection* aSelection,
   153     TFSMailMsgId aFSMailBoxId,
   210     TFSMailMsgId aFSMailBoxId,
   154     MFSMailRequestObserver* aFSOperationObserver,
   211     MFSMailRequestObserver* aFSOperationObserver,
   155     TInt aFSRequestId,
   212     TInt aFSRequestId,
   156     CIpsPlgEventHandler* aEventHandler )
   213     CIpsPlgEventHandler* aEventHandler )
   157     : 
   214     : 
   160         aObserverRequestStatus, 
   217         aObserverRequestStatus, 
   161         aActivityTimer, 
   218         aActivityTimer, 
   162         aFSMailBoxId,
   219         aFSMailBoxId,
   163         aFSOperationObserver, 
   220         aFSOperationObserver, 
   164         aFSRequestId ),
   221         aFSRequestId ),
   165     iFunctionId( aFunctionId ),
       
   166     iGetMailInfo( aGetMailInfo ), 
   222     iGetMailInfo( aGetMailInfo ), 
       
   223     iSelection( aSelection ),
   167     iEventHandler( aEventHandler )
   224     iEventHandler( aEventHandler )
   168     {
   225     {
   169     FUNC_LOG;
   226     FUNC_LOG;
   170     iService = aService;
   227     iService = aService;
   171     }
   228     }
   192     FUNC_LOG;
   249     FUNC_LOG;
   193 
   250 
   194     CIpsPlgOnlineOperation::DoCancel();
   251     CIpsPlgOnlineOperation::DoCancel();
   195     if(iState == EStateFetching)
   252     if(iState == EStateFetching)
   196         {
   253         {
   197         // Cancelled while fetching. Need to disconnect.
   254         // Stops any operations that a Server-side MTM for the specified service is running,
       
   255         // and then unloads the Server-side MTM.
       
   256         // The current operation and any queued operations are cancelled.
   198         iMsvSession.StopService( iService );
   257         iMsvSession.StopService( iService );
   199         // Ignore return value, nothing we can do.
       
   200         }
   258         }
   201     if ( iEventHandler )
   259     if ( iEventHandler )
   202         {
   260         {
   203         iEventHandler->SetNewPropertyEvent( 
   261         // <qmail>
   204                 iService, KIpsSosEmailSyncCompleted, KErrCancel );
   262         iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncCompleted, KErrCancel );
       
   263 		// </qmail>
   205         }
   264         }
   206     }
   265     }
   207 
   266 
   208 // ----------------------------------------------------------------------------
   267 // ----------------------------------------------------------------------------
   209 // DoRunL
   268 // DoRunL
   212     {
   271     {
   213     FUNC_LOG;
   272     FUNC_LOG;
   214 
   273 
   215     switch(iState)
   274     switch(iState)
   216         {
   275         {
       
   276         case EStateClearCompleteFlag:
       
   277             {
       
   278             // First clean things
       
   279             delete iSubOperation;
       
   280             iSubOperation = NULL;
       
   281 
       
   282             delete iEntry;
       
   283             iEntry = NULL;
       
   284             
       
   285             // Leave if setting the complete flag was a failure.
       
   286             User::LeaveIfError( iStatus.Int() );
       
   287             
       
   288             TInt count = iSelection->Count();
       
   289 
       
   290             for ( ; iEntryIndex < count && !iSubOperation; iEntryIndex++ )
       
   291                 {
       
   292                 delete iEntry;
       
   293                 iEntry = NULL;
       
   294                 
       
   295                 iEntry = iMsvSession.GetEntryL(
       
   296                     iSelection->At( iEntryIndex ) );
       
   297 
       
   298                 TMsvEntry entry = iEntry->Entry();
       
   299                 
       
   300                 TBool complete = entry.Complete();
       
   301 
       
   302                 if ( complete )
       
   303                     {
       
   304                     entry.SetComplete( EFalse );
       
   305 
       
   306                     iSubOperation = iEntry->ChangeL( entry, iStatus );
       
   307 
       
   308                     SetActive();
       
   309                     }
       
   310                 }
       
   311 
       
   312             if ( !iSubOperation )
       
   313                 {
       
   314                 DoConnectL();
       
   315                 }
       
   316             
       
   317             break;
       
   318             }
   217         case EStateConnecting:
   319         case EStateConnecting:
   218             {
   320             {
   219             // Connect complete.
   321             // Connect complete.
   220             // <qmail> Connected() usage
   322             // <qmail> Connected() usage
   221             if ( !Connected() )
   323             if ( !Connected() )
   227             }
   329             }
   228             break;
   330             break;
   229         case EStateFetching:         
   331         case EStateFetching:         
   230             {
   332             {
   231             TInt err = iStatus.Int();
   333             TInt err = iStatus.Int();
   232 
   334 			// <qmail>
   233             if( KErrNone != err )
   335             if( err )
       
   336 			// </qmail>
   234                 {
   337                 {
   235                 TPckgBuf<TPop3Progress> paramPack;
   338                 TPckgBuf<TPop3Progress> paramPack;
   236                 if ( iSubOperation )
   339                 if ( iSubOperation )
   237                     {
   340                     {
   238                 paramPack.Copy( iSubOperation->ProgressL() );
   341                     paramPack.Copy( iSubOperation->ProgressL() );
   239                     }
   342                     }
   240                 TPop3Progress& progress = paramPack();
   343                 TPop3Progress& progress = paramPack();
   241                 progress.iErrorCode = err;
   344                 progress.iErrorCode = err;
   242                 iFetchErrorProgress = paramPack.AllocL();
   345                 iFetchErrorProgress = paramPack.AllocL();
   243                 }
   346                 }
   244             
   347             
   245             iState = EStateIdle;
   348             iState = EStateIdle;
   246             CompleteObserver( err );
   349             CompleteObserver( err );
   247             if ( iEventHandler )
   350             if ( iEventHandler )
   248                 {
   351                 {
   249                 iEventHandler->SetNewPropertyEvent( 
   352 				// <qmail>
   250                         iService, KIpsSosEmailSyncCompleted, err );
   353                 iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncCompleted, err );
       
   354 				// </qmail>
   251                 }
   355                 }
   252             }
   356             }
   253             break;
   357             break;
   254             
   358             
   255         default:
   359         default:
   271 TFSProgress CIpsPlgPop3FetchOperation::GetFSProgressL() const
   375 TFSProgress CIpsPlgPop3FetchOperation::GetFSProgressL() const
   272     {
   376     {
   273     FUNC_LOG;
   377     FUNC_LOG;
   274     // might not never called, but gives something reasonable if called
   378     // might not never called, but gives something reasonable if called
   275     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   379     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   276     result.iError = KErrNone;
   380     // <qmail> removed result.iError = KErrNone;
   277     switch( iState )
   381     switch( iState )
   278         {
   382         {
   279         case EStateConnecting:
   383         case EStateConnecting:
   280             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   384             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   281             break;
   385             break;
   301 TIpsOpType CIpsPlgPop3FetchOperation::IpsOpType() const
   405 TIpsOpType CIpsPlgPop3FetchOperation::IpsOpType() const
   302     {
   406     {
   303     FUNC_LOG;
   407     FUNC_LOG;
   304     return EIpsOpTypePop3FetchOp;
   408     return EIpsOpTypePop3FetchOp;
   305     }
   409     }
       
   410 // </qmail>
       
   411