ipsservices/ipssosplugin/src/ipsplgdeleteoperation.cpp
changeset 23 2dc6caa42ec3
child 30 759dc5235cdb
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
       
     1 /*
       
     2 * Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 //<qmail>
       
    15 * Description: This file implements class CIpsPlgDeleteOperation.
       
    16 //</qmail>
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include "emailtrace.h"
       
    25 #include "ipsplgheaders.h"
       
    26 
       
    27 //<qmail> comment removed
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // CIpsPlgDeleteOperation::CIpsPlgDeleteOperation
       
    33 // ----------------------------------------------------------------------------
       
    34 //
       
    35 //<qmail>
       
    36 CIpsPlgDeleteOperation::CIpsPlgDeleteOperation(
       
    37     CMsvSession& aMsvSession,
       
    38     TRequestStatus& aObserverRequestStatus )
       
    39     :
       
    40     CMsvOperation( 
       
    41         aMsvSession, 
       
    42         CActive::EPriorityStandard, 
       
    43         aObserverRequestStatus),
       
    44     iState( ESetFlags ) // <qmail>
       
    45     //</qmail> iBlank removed    
       
    46     {
       
    47     FUNC_LOG;
       
    48     CActiveScheduler::Add(this);
       
    49     }
       
    50 //</qmail>
       
    51 
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CIpsPlgDeleteOperation::ConstructL
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 // <qmail>
       
    58 void CIpsPlgDeleteOperation::ConstructL(
       
    59     CMsvEntrySelection* aEntriesToDelete ) //<qmail> param name changed
       
    60     {
       
    61     FUNC_LOG;
       
    62     //<qmail>
       
    63     iEntrySelection = new (ELeave) CMsvEntrySelection();
       
    64     
       
    65     for ( TInt i=0; i<aEntriesToDelete->Count(); i++ )
       
    66         {
       
    67         iEntrySelection->AppendL( aEntriesToDelete->At(i) );
       
    68         }
       
    69     
       
    70     if ( !iEntrySelection->Count() )
       
    71         {
       
    72         User::Leave( KErrNotSupported );
       
    73         }
       
    74     //</qmail>
       
    75 
       
    76     //<qmail>
       
    77     // Messages will be deleted from one specific folder at a time
       
    78     TMsvId serviceId;
       
    79     TMsvEntry entry;
       
    80     User::LeaveIfError(
       
    81         iMsvSession.GetEntry(
       
    82             (*iEntrySelection)[0], serviceId, entry ) );
       
    83     iEntry = CMsvEntry::NewL(
       
    84         iMsvSession, entry.Parent(), TMsvSelectionOrdering() );
       
    85     
       
    86     // For CMsvOperation
       
    87     iMtm = iEntry->Entry().iMtm;
       
    88     //</qmail>
       
    89     iStatus = KRequestPending;
       
    90 
       
    91     // It is known that there is at least one entry -> no return value check
       
    92     SetNextLocallyDeletedFlagL();
       
    93 
       
    94     SetActive();
       
    95     }
       
    96 // </qmail>
       
    97 
       
    98 // ----------------------------------------------------------------------------
       
    99 // CIpsPlgDeleteOperation::NewL
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 CIpsPlgDeleteOperation* CIpsPlgDeleteOperation::NewL(
       
   103     CMsvSession& aMsvSession,
       
   104     TRequestStatus& aObserverRequestStatus,
       
   105     CMsvEntrySelection* aEntriesToDelete ) //<qmail> param name changed
       
   106     {
       
   107     FUNC_LOG;
       
   108     CIpsPlgDeleteOperation* self=new (ELeave) CIpsPlgDeleteOperation(
       
   109         aMsvSession, aObserverRequestStatus );
       
   110     CleanupStack::PushL(self);
       
   111     //<qmail>
       
   112     self->ConstructL( aEntriesToDelete );
       
   113     //</qmail>
       
   114     CleanupStack::Pop( self ); 
       
   115     return self;
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CIpsPlgDeleteOperation::~CIpsPlgDeleteOperation
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 CIpsPlgDeleteOperation::~CIpsPlgDeleteOperation()
       
   123     {
       
   124     FUNC_LOG;
       
   125     Cancel();
       
   126 
       
   127     delete iOperation;
       
   128     delete iEntry;
       
   129     delete iEntrySelection;
       
   130 	// <qmail>    
       
   131     delete iSetFlagEntry;
       
   132 	// </qmail>    
       
   133     }
       
   134 
       
   135 // ----------------------------------------------------------------------------
       
   136 // CIpsPlgDeleteOperation::DoCancel
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void CIpsPlgDeleteOperation::DoCancel()
       
   140     {
       
   141     FUNC_LOG;
       
   142     if (iOperation)
       
   143         {
       
   144         iOperation->Cancel();
       
   145         }
       
   146     TRequestStatus* status = &iObserverRequestStatus;
       
   147     if ( status && status->Int() == KRequestPending )
       
   148         {
       
   149         User::RequestComplete(status, iStatus.Int());
       
   150         }
       
   151     }
       
   152 
       
   153 // ----------------------------------------------------------------------------
       
   154 // CIpsPlgDeleteOperation::RunL
       
   155 // ----------------------------------------------------------------------------
       
   156 //
       
   157 void CIpsPlgDeleteOperation::RunL()
       
   158     {
       
   159     FUNC_LOG;
       
   160     // Make first a check, that nothing has failed
       
   161     if ( iStatus.Int() != KErrNone )
       
   162         {
       
   163         // something failed, just complete
       
   164         TRequestStatus* status = &iObserverRequestStatus;
       
   165         User::RequestComplete(status, iStatus.Int());
       
   166         return;
       
   167         }
       
   168 
       
   169 	// <qmail>    
       
   170     if ( iState == ESetFlags )
       
   171     //</qmail>    
       
   172         {
       
   173         // cleanup is handled by SetNextLocallyDeletedFlagL
       
   174         TBool ret = EFalse;
       
   175         
       
   176         TRAPD( err, ret = SetNextLocallyDeletedFlagL() );
       
   177         
       
   178         if ( err != KErrNone )
       
   179             {
       
   180             TRequestStatus* status = &iObserverRequestStatus;
       
   181             User::RequestComplete(status, iStatus.Int());
       
   182             }
       
   183         else if ( ret )
       
   184             {
       
   185             SetActive();
       
   186             }
       
   187         else
       
   188             { // setting the flags is ready, start local deletion
       
   189             StartNextDeleteLocally();
       
   190             }
       
   191         }
       
   192     //<qmail>
       
   193     else if ( iState == ELocally )
       
   194     //</qmail>
       
   195         {
       
   196         // local delete completed, start deleting from server
       
   197         StartDeleteFromServer();
       
   198         }
       
   199     else
       
   200         {
       
   201         // nothing left to process, so complete the observer
       
   202         TRequestStatus* status = &iObserverRequestStatus;
       
   203         User::RequestComplete(status, iStatus.Int());
       
   204         }
       
   205     // </qmail>    
       
   206 	}
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CIpsPlgDeleteOperation::ProgressL
       
   210 // ----------------------------------------------------------------------------
       
   211 //
       
   212 //<qmail>
       
   213 const TDesC8& CIpsPlgDeleteOperation::ProgressL()
       
   214     {
       
   215     FUNC_LOG;
       
   216     // Make sure that operation is active
       
   217     if ( IsActive() )
       
   218         {
       
   219         // Get progress
       
   220         if ( iOperation )
       
   221             {
       
   222             return iOperation->ProgressL();
       
   223             }
       
   224         }
       
   225     //<qmail>
       
   226     return KNullDesC8;
       
   227     //</qmail>
       
   228     }
       
   229 //</qmail>
       
   230 // ----------------------------------------------------------------------------
       
   231 // CIpsPlgDeleteOperation::StartNextDeleteLocally
       
   232 // ----------------------------------------------------------------------------
       
   233 //
       
   234 void CIpsPlgDeleteOperation::StartNextDeleteLocally()
       
   235     {
       
   236     //<qmail>
       
   237     FUNC_LOG;
       
   238     iState = ELocally;
       
   239     //</qmail>
       
   240     iStatus = KRequestPending;
       
   241     
       
   242     TRAPD( err, MakeNextDeleteLocallyL() );
       
   243     SetActive();
       
   244     // if error then complete this pass with the error code
       
   245     if ( err )
       
   246         {
       
   247         TRequestStatus* status = &iStatus;
       
   248         User::RequestComplete(status, err);
       
   249         }
       
   250     }
       
   251 
       
   252 // ----------------------------------------------------------------------------
       
   253 // CIpsPlgDeleteOperation::MakeNextDeleteLocallyL
       
   254 // ----------------------------------------------------------------------------
       
   255 //
       
   256 void CIpsPlgDeleteOperation::MakeNextDeleteLocallyL()
       
   257     {
       
   258     FUNC_LOG;
       
   259     delete iOperation;
       
   260     iOperation = NULL;
       
   261     iOperation = CIpsPlgDeleteLocal::NewL(
       
   262         iEntrySelection, iMsvSession, iStatus );
       
   263     }
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CIpsPlgDeleteOperation::StartDeleteFromServer
       
   267 // ----------------------------------------------------------------------------
       
   268 //
       
   269 void CIpsPlgDeleteOperation::StartDeleteFromServer()
       
   270     {
       
   271     FUNC_LOG;
       
   272     //<qmail>
       
   273     iState = EFromServer;
       
   274     //</qmail>
       
   275     iStatus = KRequestPending;
       
   276     TRAPD( err, MakeDeleteFromServerL() );
       
   277 
       
   278     SetActive();
       
   279     // if error then complete this pass with the error code
       
   280     if ( err )
       
   281         {
       
   282         TRequestStatus* status = &iStatus;
       
   283         User::RequestComplete( status, err );
       
   284         }
       
   285     }
       
   286 
       
   287 // ----------------------------------------------------------------------------
       
   288 // CIpsPlgDeleteOperation::MakeDeleteFromServerL
       
   289 // ----------------------------------------------------------------------------
       
   290 //
       
   291 void CIpsPlgDeleteOperation::MakeDeleteFromServerL()
       
   292     {
       
   293     FUNC_LOG;
       
   294     delete iOperation;
       
   295     iOperation = NULL;
       
   296     iOperation = iEntry->DeleteL( *iEntrySelection, iStatus );
       
   297     }
       
   298 
       
   299 
       
   300 // <qmail>    
       
   301 // ----------------------------------------------------------------------------
       
   302 // CIpsPlgDeleteOperation::SetNextLocallyDeletedFlagL
       
   303 // ----------------------------------------------------------------------------
       
   304 //
       
   305 TBool CIpsPlgDeleteOperation::SetNextLocallyDeletedFlagL()
       
   306     {
       
   307     FUNC_LOG;
       
   308     
       
   309     delete iOperation;
       
   310     iOperation = NULL;
       
   311     
       
   312     delete iSetFlagEntry;
       
   313     iSetFlagEntry = NULL;
       
   314 
       
   315     TBool ret = EFalse;
       
   316     //<qmail>
       
   317     if ( iSetFlagIndex < iEntrySelection->Count() )
       
   318     //</qmail>    
       
   319         {
       
   320         TMsvId entryId = ( *iEntrySelection )[ iSetFlagIndex++ ];
       
   321         
       
   322         iSetFlagEntry = CMsvEntry::NewL( 
       
   323             iMsvSession, entryId, TMsvSelectionOrdering() );
       
   324         
       
   325         TMsvEntry tEntry = iSetFlagEntry->Entry();
       
   326 
       
   327         // Sets bit 32 of iMtmData1, used when msg deleted in Offline
       
   328         // and status hasn't updated to server (client entry still exists)
       
   329         tEntry.SetLocallyDeleted( ETrue );
       
   330 
       
   331         iOperation = iSetFlagEntry->ChangeL( tEntry, iStatus );
       
   332         
       
   333         ret = ETrue;
       
   334         }
       
   335     
       
   336     return ret;
       
   337     }
       
   338 // </qmail>    
       
   339 
       
   340 //  End of File
       
   341 
       
   342