messagingappbase/msgerrorwatcher/src/MsgSentItemsObserver.cpp
branchRCL_3
changeset 77 da6ac9d688df
parent 0 72b543305e3a
equal deleted inserted replaced
71:17302fa075e1 77:da6ac9d688df
    23 #include <msvids.h>
    23 #include <msvids.h>
    24 
    24 
    25 #include <centralrepository.h>    // link against centralrepository.lib
    25 #include <centralrepository.h>    // link against centralrepository.lib
    26 #include <cenrepnotifyhandler.h>  // link against CenRepNotifHandler.lib
    26 #include <cenrepnotifyhandler.h>  // link against CenRepNotifHandler.lib
    27 #include <messaginginternalcrkeys.h> // for Central Repository keys
    27 #include <messaginginternalcrkeys.h> // for Central Repository keys
       
    28 #include <MSVIPC.h>
    28 
    29 
    29 #include "MsgSentItemsObserver.h"
    30 #include "MsgSentItemsObserver.h"
    30 
    31 
    31 #ifdef USE_LOGGER
    32 #ifdef USE_LOGGER
    32 #include "MsgErrorWatcherLogging.h"
    33 #include "MsgErrorWatcherLogging.h"
    33 #endif
    34 #endif
    34 
    35 
    35 // CONSTANTS
    36 // CONSTANTS
    36 //const TUid KUidMceApp = { 0x100058C5 }; //needed to request shared data notifications
    37 //const TUid KUidMceApp = { 0x100058C5 }; //needed to request shared data notifications
    37 const TMsvId KWatcherSentFolderId = KMsvSentEntryIdValue;
    38 const TMsvId KWatcherSentFolderId = KMsvSentEntryIdValue;
       
    39 
       
    40 // Entry deletion could fail with KErrInUse if it is being operated by MW while deleting
    38 const TUint KMaxRetries = 3;
    41 const TUint KMaxRetries = 3;
    39 const TInt KMaxNumOfItems = 20; //Deafult value in case of error reading CommsDb
    42 const TInt KMaxNumOfItems = 20; //Deafult value in case of error reading CommsDb
    40 //const TInt KMsgErrorDiskSpaceForDelete = ( 5 * 1024 ); // minimum disk space needed when deleting messages
    43 //const TInt KMsgErrorDiskSpaceForDelete = ( 5 * 1024 ); // minimum disk space needed when deleting messages
    41 //_LIT( KSentItemsInUseOff, "0" );
    44 //_LIT( KSentItemsInUseOff, "0" );
    42 
    45 
    97         iSentItemsFolder->RemoveObserver( *this );
   100         iSentItemsFolder->RemoveObserver( *this );
    98         }
   101         }
    99     delete iSentItemsFolder;
   102     delete iSentItemsFolder;
   100     delete iEntry;
   103     delete iEntry;
   101     delete iOp;
   104     delete iOp;
       
   105     
       
   106     delete iQudUPEntryBeingDeleted;
       
   107     delete iQueuedUPEntriesToBeDeleted;
       
   108     
   102     }
   109     }
   103 
   110 
   104 // ---------------------------------------------------------
   111 // ---------------------------------------------------------
   105 // CMsgSentItemsObserver::ConstructL
   112 // CMsgSentItemsObserver::ConstructL
   106 //
   113 //
   123 
   130 
   124     // Central Repository
   131     // Central Repository
   125     iRepository = CRepository::NewL( KCRUidMuiuSettings );
   132     iRepository = CRepository::NewL( KCRUidMuiuSettings );
   126     iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iRepository );
   133     iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iRepository );
   127     iNotifyHandler->StartListeningL();
   134     iNotifyHandler->StartListeningL();
   128 
   135     
       
   136     iQudUPEntryBeingDeleted = new(ELeave) CMsvEntrySelection;
       
   137     iQueuedUPEntriesToBeDeleted= new(ELeave) CMsvEntrySelection;
       
   138     
   129 #ifdef USE_LOGGER
   139 #ifdef USE_LOGGER
   130     MEWLOGGER_LEAVEFN( "SentItems: ConstructL" );
   140     MEWLOGGER_LEAVEFN( "SentItems: ConstructL" );
   131 #endif
   141 #endif
   132     }
   142     }
   133 
   143 
   138 // ---------------------------------------------------------
   148 // ---------------------------------------------------------
   139 //
   149 //
   140 void CMsgSentItemsObserver::RunL()
   150 void CMsgSentItemsObserver::RunL()
   141     {
   151     {
   142     //iSession->FileSession().ReleaseReserveAccess( iMsgStoreDrive );
   152     //iSession->FileSession().ReleaseReserveAccess( iMsgStoreDrive );
   143 #ifdef USE_LOGGER
       
   144     if( iStatus==KErrNone )
       
   145         {
       
   146         MEWLOGGER_WRITE( "SentItems: deletion successful" );
       
   147         }
       
   148     else
       
   149         {
       
   150         MEWLOGGER_WRITEF( _L("SentItems: deletion error %d"), iStatus.Int() );
       
   151         } 
       
   152 #endif
       
   153     //Check if new messages have appeared into Sent Items while deleting
   153     //Check if new messages have appeared into Sent Items while deleting
   154     //the previous one(s).
   154     //the previous one(s).
   155 #ifdef USE_LOGGER
   155 #ifdef USE_LOGGER
   156     MEWLOGGER_WRITEF( _L("SentItems: Retries: %d"), iRetryCounter );
   156     MEWLOGGER_WRITEF( _L("SentItems: Retries: %d"), iRetryCounter );
   157 #endif
   157 #endif
   158     if ( iRetryCounter < KMaxRetries )
   158     if ( iRetryCounter < KMaxRetries )
   159         {
   159         {
   160         iRetryCounter++;
   160         iRetryCounter++;
   161         TRAP_IGNORE( DeleteOldMessagesFromSentFolderL() );
   161         TRAP_IGNORE( DeleteOldMessagesFromSentFolderL() );
   162         }
   162         }
       
   163     
       
   164     
       
   165     const TDesC8& temp = iOp->ProgressL();
       
   166     TMsvLocalOperationProgress* prog = ( (TMsvLocalOperationProgress*) temp.Ptr());
       
   167 
       
   168 #ifdef USE_LOGGER
       
   169     MEWLOGGER_WRITEF( _L("SentItems: deletion iStatus %d"), iStatus.Int() );
       
   170 	// prog->iNumberFailed should be either 0(if successful) or 1(if failed) as we are deletingone entry at a time
       
   171     MEWLOGGER_WRITEF( _L("Failed Deletions: %d"), prog->iNumberFailed );
       
   172     MEWLOGGER_WRITEF( _L("Delete Error Code: %d"), prog->iError );
       
   173 #endif
       
   174     
       
   175     if(iStatus.Int() == KErrNone && prog->iNumberFailed && prog->iError == KErrInUse && iRetryCounterIfEntryDelFailed < KMaxRetries)
       
   176         {
       
   177         DeleteSingleEntryL(iQudUPEntryBeingDeleted);
       
   178         iRetryCounterIfEntryDelFailed ++;
       
   179 #ifdef USE_LOGGER
       
   180         MEWLOGGER_WRITEF( _L("iRetryCounterIfEntryDelFailed : %d"), iRetryCounterIfEntryDelFailed );
       
   181 #endif
       
   182         return;
       
   183         }
       
   184     iRetryCounterIfEntryDelFailed = 0;
       
   185     
       
   186     if( iQueuedUPEntriesToBeDeleted->Count() )
       
   187         {
       
   188         iQudUPEntryBeingDeleted->Reset();
       
   189         iQudUPEntryBeingDeleted->AppendL(iQueuedUPEntriesToBeDeleted->At(0));
       
   190         iQueuedUPEntriesToBeDeleted->Delete(0);
       
   191         
       
   192         DeleteSingleEntryL(iQudUPEntryBeingDeleted);
       
   193         }
       
   194     
   163     }
   195     }
   164 
   196 
   165 // ---------------------------------------------------------
   197 // ---------------------------------------------------------
   166 // CMsgSentItemsObserver::DoCancel
   198 // CMsgSentItemsObserver::DoCancel
   167 //
   199 //
   322 // Delete the messages specified by aSelection
   354 // Delete the messages specified by aSelection
   323 // ---------------------------------------------------------
   355 // ---------------------------------------------------------
   324 //
   356 //
   325 void CMsgSentItemsObserver::DeleteMessagesFromSentFolderL( CMsvEntrySelection* aSelection )
   357 void CMsgSentItemsObserver::DeleteMessagesFromSentFolderL( CMsvEntrySelection* aSelection )
   326     {
   358     {
       
   359     iQueuedUPEntriesToBeDeleted->AppendL(aSelection->Back(0), aSelection->Count());
   327     if ( !IsActive() )
   360     if ( !IsActive() )
   328         {
   361         {
       
   362         iQudUPEntryBeingDeleted->Reset();
       
   363         iQudUPEntryBeingDeleted->AppendL(iQueuedUPEntriesToBeDeleted->At(0));
       
   364         iQueuedUPEntriesToBeDeleted->Delete(0);
       
   365         
       
   366 		// If multiple entries are sent for deletion, then it won't be possible to track
       
   367 		// the entries that failed to delete
       
   368         DeleteSingleEntryL(iQudUPEntryBeingDeleted);
       
   369         }
       
   370     
       
   371     }
       
   372 
       
   373 
       
   374 void CMsgSentItemsObserver::DeleteSingleEntryL(CMsvEntrySelection* aSelection)
       
   375     {
       
   376 
   329 #ifdef USE_LOGGER
   377 #ifdef USE_LOGGER
   330         MEWLOGGER_WRITEF( _L("SentItems: deleting %d messages from sent folder"), aSelection->Count() );
   378         MEWLOGGER_WRITEF( _L("SentItems: deleting %d messages from sent folder"), aSelection->Count() );
   331 #endif
   379 #endif
       
   380         
   332         const TMsvId id = aSelection->At( 0 );
   381         const TMsvId id = aSelection->At( 0 );
   333         delete iEntry;
   382         delete iEntry;
   334         iEntry = 0;
   383         iEntry = 0;
   335         iEntry = iSession->GetEntryL( id );
   384         iEntry = iSession->GetEntryL( id );
   336         iEntry->SetEntryL( iEntry->Entry().Parent() );
   385         iEntry->SetEntryL( iEntry->Entry().Parent() );
   353         //    }
   402         //    }
   354         //else
   403         //else
   355         //    {
   404         //    {
   356             SetActive();
   405             SetActive();
   357         //    }
   406         //    }
   358         }
   407             
   359     }
   408         }
       
   409 
   360 
   410 
   361 //  End of File  
   411 //  End of File  
   362 
   412