emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp
branchRCL_3
changeset 35 e64954c2c8e2
parent 8 e1b6206813b4
child 24 b5fbb9b25d57
equal deleted inserted replaced
34:cd2816114bd1 35:e64954c2c8e2
    16 */
    16 */
    17 #include "msgstorewritablepropertycontainer.h"
    17 #include "msgstorewritablepropertycontainer.h"
    18 
    18 
    19 #include "baseplugindelayedops.h"
    19 #include "baseplugindelayedops.h"
    20 #include "baseplugindelayedopsprivate.h"
    20 #include "baseplugindelayedopsprivate.h"
    21 
    21 #include "NestedAO.h"
    22 
    22 
    23 ///////////////////////////////////////////////////
    23 ///////////////////////////////////////////////////
    24 // CDelayedOp                                    //
    24 // CDelayedOp                                    //
    25 ///////////////////////////////////////////////////
    25 ///////////////////////////////////////////////////
    26 
    26 
   226     {
   226     {
   227     iMessages.Close();
   227     iMessages.Close();
   228     __LOG_DESTRUCT
   228     __LOG_DESTRUCT
   229     }
   229     }
   230 
   230 
   231 
   231 /**
   232 /**
   232  * 
   233  * 
   233  */
   234  */
   234 /*public virtual*/TBool CDelayedDeleteMessagesOp::DeleteMessagesInChunksL( TInt aStartIndex )
   235 /*private*/
   235     {
   236 void CDelayedDeleteMessagesOp::ConstructL(
   236     __LOG_ENTER( "DeleteMessagesInChunksL" );
   237     const RArray<TFSMailMsgId>& aMessages )
   237     TBool done=EFalse;
   238     {
   238     TInt endIndex;
   239     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
   239     if( aStartIndex + KSizeOfChunk < iMessages.Count() )
   240             
   240         {
   241     TInt count = aMessages.Count();
   241             endIndex = aStartIndex + KSizeOfChunk;
   242     for ( TInt i = 0; i < count; ++i )
   242         }
   243         {
   243     else
   244         iMessages.AppendL( aMessages[i].Id() );
   244         {
   245         }
   245         endIndex = iMessages.Count();   
   246     }
   246         done=ETrue;
   247 
   247         }
   248 /**
       
   249  * 
       
   250  */
       
   251 /*private*/
       
   252 void CDelayedDeleteMessagesOp::ConstructL(
       
   253     TMsgStoreId aMsgId )
       
   254     {
       
   255     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   256     iImmediateDelete = ETrue;
       
   257     iMessages.AppendL( aMsgId );
       
   258     }
       
   259 
       
   260 /**
       
   261  * 
       
   262  */
       
   263 /*private*/ CDelayedDeleteMessagesOp::CDelayedDeleteMessagesOp(
       
   264     TMsgStoreId aMailBoxId,
       
   265     TMsgStoreId aFolderId )
       
   266     :
       
   267     iMailBoxId( aMailBoxId ), iFolderId( aFolderId ),
       
   268     iImmediateDelete( EFalse )
       
   269     {
       
   270     }
       
   271 
       
   272 /**
       
   273  * 
       
   274  */
       
   275 /*private*/ void CDelayedDeleteMessagesOp::ExecuteOpL()
       
   276     {
       
   277     __LOG_ENTER( "ExecuteOpL" );
       
   278     
       
   279     CMailboxInfo& mailBoxInfo
   248     CMailboxInfo& mailBoxInfo
   280         = GetPlugin().GetMailboxInfoL( iMailBoxId );
   249         = GetPlugin().GetMailboxInfoL( iMailBoxId );
   281     CMsgStoreMailBox& mailBox = mailBoxInfo();
   250     CMsgStoreMailBox& mailBox = mailBoxInfo();
   282 
   251 
   283     TInt count = iMessages.Count();
   252     for ( TInt i = aStartIndex; i < endIndex; ++i )
   284     for ( TInt i = 0; i < count; ++i )
       
   285         {
   253         {
   286         TMsgStoreId msgId = iMessages[i];
   254         TMsgStoreId msgId = iMessages[i];
   287         
   255         
   288         if ( EFalse == iImmediateDelete )
   256         if ( EFalse == iImmediateDelete )
   289             {
   257             {
   293               msgId, mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ) );
   261               msgId, mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ) );
   294             
   262             
   295             if ( NULL == theMessage )
   263             if ( NULL == theMessage )
   296                 {
   264                 {
   297                 //if not in deleted items then move it there.
   265                 //if not in deleted items then move it there.
   298                 __LOG_WRITE8_FORMAT1_INFO(
   266                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   299                      "Moving message 0x%X to the deleted items.", msgId );
       
   300                 mailBox.MoveMessageL(
   267                 mailBox.MoveMessageL(
   301                    msgId, KMsgStoreInvalidId,
   268                    msgId, KMsgStoreInvalidId,
   302                    mailBoxInfo.iRootFolders.iFolders[EFSDeleted] );
   269                    mailBoxInfo.iRootFolders.iFolders[EFSDeleted] );
   303                 }
   270                 }
   304             else
   271             else
   313         else
   280         else
   314             {
   281             {
   315             mailBox.DeleteMessageL( msgId, iFolderId );
   282             mailBox.DeleteMessageL( msgId, iFolderId );
   316             }
   283             }
   317         }
   284         }
   318 
   285     __LOG_EXIT;
       
   286     return done;    
       
   287     }
       
   288 /**
       
   289  * 
       
   290  */
       
   291 /*private*/
       
   292 void CDelayedDeleteMessagesOp::ConstructL(
       
   293     const RArray<TFSMailMsgId>& aMessages )
       
   294     {
       
   295     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   296             
       
   297     TInt count = aMessages.Count();
       
   298     for ( TInt i = 0; i < count; ++i )
       
   299         {
       
   300         iMessages.AppendL( aMessages[i].Id() );
       
   301         }
       
   302     }
       
   303 
       
   304 /**
       
   305  * 
       
   306  */
       
   307 /*private*/
       
   308 void CDelayedDeleteMessagesOp::ConstructL(
       
   309     TMsgStoreId aMsgId )
       
   310     {
       
   311     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   312     iImmediateDelete = ETrue;
       
   313     iMessages.AppendL( aMsgId );
       
   314     }
       
   315 
       
   316 /**
       
   317  * 
       
   318  */
       
   319 /*private*/ CDelayedDeleteMessagesOp::CDelayedDeleteMessagesOp(
       
   320     TMsgStoreId aMailBoxId,
       
   321     TMsgStoreId aFolderId )
       
   322     :
       
   323     iMailBoxId( aMailBoxId ), iFolderId( aFolderId ),
       
   324     iImmediateDelete( EFalse ), iState ( EFree )
       
   325     {
       
   326     }
       
   327 
       
   328 /**
       
   329  * 
       
   330  */
       
   331 /*private*/ void CDelayedDeleteMessagesOp::ExecuteOpL()
       
   332     {
       
   333     __LOG_ENTER( "ExecuteOpL" );
       
   334     if ( iState != EFree )
       
   335         {
       
   336         //this code becomes re-entrant now because we use nested AS.
       
   337         // so if we are already authenticating, return right away.
       
   338         return;
       
   339         }
       
   340     iState=EInProgress;
       
   341     CNestedAO* nestedAO = CNestedAO::NewL( *this );
       
   342     //this is a blocking call with nested active scheduler
       
   343     //This method makes a callback periodically to DeleteMessagesInChunks
       
   344     //to delete the messages one chunk at a time
       
   345     nestedAO->DeleteMessagesAsync();
       
   346     //continue execution here
       
   347     delete nestedAO;
       
   348     iState = EFree;
   319     __LOG_EXIT;
   349     __LOG_EXIT;
   320     }
   350     }
   321 
   351 
   322 
   352 
   323 ///////////////////////////////////////////////////
   353 ///////////////////////////////////////////////////