ipsservices/ipssosplugin/src/ipsplgdeleteremote.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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 * Description: This file implements class CIpsPlgDeleteRemote.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "emailtrace.h"
       
    23 #include "ipsplgheaders.h"
       
    24 
       
    25 // LOCAL CONSTANTS AND MACROS
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // CIpsPlgDeleteRemote::CIpsPlgDeleteRemote
       
    31 // ----------------------------------------------------------------------------
       
    32 //
       
    33 CIpsPlgDeleteRemote::CIpsPlgDeleteRemote(
       
    34     CMsvSession& aMsvSession,
       
    35     TRequestStatus& aObserverRequestStatus )
       
    36     :
       
    37     CMsvOperation( 
       
    38         aMsvSession, 
       
    39         CActive::EPriorityStandard, 
       
    40         aObserverRequestStatus),
       
    41         
       
    42     iBlank( KNullDesC8 )
       
    43             {
       
    44     FUNC_LOG;
       
    45     CActiveScheduler::Add(this);
       
    46             }
       
    47 
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // CIpsPlgDeleteRemote::ConstructL
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 void CIpsPlgDeleteRemote::ConstructL(
       
    54     CMsvEntrySelection& aDeletedEntries )
       
    55     {
       
    56     FUNC_LOG;
       
    57     iEntrySelection = aDeletedEntries.CopyL();
       
    58     iEntryCount = iEntrySelection->Count();
       
    59     if ( iEntryCount == 0 )
       
    60         {
       
    61         User::Leave( KErrNotSupported );
       
    62         }
       
    63 
       
    64     TMsvId serviceId;
       
    65     TMsvEntry entry;
       
    66     User::LeaveIfError(
       
    67         iMsvSession.GetEntry(
       
    68             (*iEntrySelection)[0], serviceId, entry ) );
       
    69     iEntry = CMsvEntry::NewL(
       
    70         iMsvSession, entry.Parent(), TMsvSelectionOrdering() );
       
    71     iMtm = iEntry->Entry().iMtm;
       
    72 
       
    73     iStatus=KRequestPending;
       
    74     StartNextDeleteLocally();
       
    75     }
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // CIpsPlgDeleteRemote::NewL
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 CIpsPlgDeleteRemote* CIpsPlgDeleteRemote::NewL(
       
    82     CMsvSession& aMsvSession,
       
    83     TRequestStatus& aObserverRequestStatus,
       
    84     CMsvEntrySelection& aDeletedEntries )
       
    85     {
       
    86     FUNC_LOG;
       
    87     CIpsPlgDeleteRemote* self=new (ELeave) CIpsPlgDeleteRemote(
       
    88         aMsvSession, aObserverRequestStatus );
       
    89     CleanupStack::PushL(self);
       
    90     self->ConstructL( aDeletedEntries );
       
    91     CleanupStack::Pop( self ); 
       
    92     return self;
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 // CIpsPlgDeleteRemote::~CIpsPlgDeleteRemote
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 CIpsPlgDeleteRemote::~CIpsPlgDeleteRemote()
       
   100     {
       
   101     FUNC_LOG;
       
   102     Cancel();
       
   103 
       
   104     delete iOperation;
       
   105     delete iEntry;
       
   106     delete iEntrySelection;
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CIpsPlgDeleteRemote::DoCancel
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 void CIpsPlgDeleteRemote::DoCancel()
       
   114     {
       
   115     FUNC_LOG;
       
   116     if (iOperation)
       
   117         {
       
   118         iOperation->Cancel();
       
   119         }
       
   120     TRequestStatus* status = &iObserverRequestStatus;
       
   121     if ( status && status->Int() == KRequestPending )
       
   122         {
       
   123         User::RequestComplete(status, iStatus.Int());
       
   124         }
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // CIpsPlgDeleteRemote::RunL
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 void CIpsPlgDeleteRemote::RunL()
       
   132     {
       
   133     FUNC_LOG;
       
   134     // Make first a check, that nothing has failed
       
   135     if ( iStatus.Int() != KErrNone )
       
   136         {
       
   137         // something failed, just complete
       
   138         TRequestStatus* status = &iObserverRequestStatus;
       
   139         User::RequestComplete(status, iStatus.Int());
       
   140         return;
       
   141         }
       
   142 
       
   143     if ( iState == EDeletingMessagesStateLocally )
       
   144         {
       
   145         // local delete completed, start deleting from server
       
   146         StartDeleteFromServer();
       
   147         }
       
   148     else
       
   149         {
       
   150         // nothing left to process, so complete the observer
       
   151         TRequestStatus* status = &iObserverRequestStatus;
       
   152         User::RequestComplete(status, iStatus.Int());
       
   153         }
       
   154     }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CIpsPlgDeleteRemote::ProgressL
       
   158 // ----------------------------------------------------------------------------
       
   159 //
       
   160 const TDesC8& CIpsPlgDeleteRemote::ProgressL()
       
   161     {
       
   162     FUNC_LOG;
       
   163     // Make sure that operation is active
       
   164     if ( IsActive() )
       
   165         {
       
   166         // Get progress
       
   167         if ( iOperation )
       
   168             {
       
   169             return iOperation->ProgressL();
       
   170             }
       
   171         }
       
   172 
       
   173     return iBlank;
       
   174     }
       
   175 
       
   176 // ----------------------------------------------------------------------------
       
   177 // CIpsPlgDeleteRemote::StartNextDeleteLocally
       
   178 // ----------------------------------------------------------------------------
       
   179 //
       
   180 void CIpsPlgDeleteRemote::StartNextDeleteLocally()
       
   181     {
       
   182     FUNC_LOG;
       
   183     iState = EDeletingMessagesStateLocally;
       
   184     iStatus = KRequestPending;
       
   185     
       
   186     TRAPD( err, MakeNextDeleteLocallyL() );
       
   187     SetActive();
       
   188     // if error then complete this pass with the error code
       
   189     if ( err )
       
   190         {
       
   191         TRequestStatus* status = &iStatus;
       
   192         User::RequestComplete(status, err);
       
   193         }
       
   194     }
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // CIpsPlgDeleteRemote::MakeNextDeleteLocallyL
       
   198 // ----------------------------------------------------------------------------
       
   199 //
       
   200 void CIpsPlgDeleteRemote::MakeNextDeleteLocallyL()
       
   201     {
       
   202     FUNC_LOG;
       
   203     delete iOperation;
       
   204     iOperation = NULL;
       
   205     iOperation = CIpsPlgDeleteLocal::NewL(
       
   206         *iEntrySelection, iMsvSession, iStatus );
       
   207     }
       
   208 
       
   209 // ----------------------------------------------------------------------------
       
   210 // CIpsPlgDeleteRemote::StartDeleteFromServer
       
   211 // ----------------------------------------------------------------------------
       
   212 //
       
   213 void CIpsPlgDeleteRemote::StartDeleteFromServer()
       
   214     {
       
   215     FUNC_LOG;
       
   216     iState = EDeletingMessagesStateFromServer;
       
   217     iStatus = KRequestPending;
       
   218     TRAPD( err, MakeDeleteFromServerL() );
       
   219 
       
   220     SetActive();
       
   221     // if error then complete this pass with the error code
       
   222     if ( err )
       
   223         {
       
   224         TRequestStatus* status = &iStatus;
       
   225         User::RequestComplete( status, err );
       
   226         }
       
   227     }
       
   228 
       
   229 // ----------------------------------------------------------------------------
       
   230 // CIpsPlgDeleteRemote::MakeDeleteFromServerL
       
   231 // ----------------------------------------------------------------------------
       
   232 //
       
   233 void CIpsPlgDeleteRemote::MakeDeleteFromServerL()
       
   234     {
       
   235     FUNC_LOG;
       
   236     delete iOperation;
       
   237     iOperation = NULL;
       
   238     iOperation = iEntry->DeleteL( *iEntrySelection, iStatus );
       
   239     }
       
   240 
       
   241 //  End of File
       
   242 
       
   243