messagingapp/msgappfw/server/src/ccsconversationdeletehandler.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     1 /*
       
     2 * Copyright (c) 2007 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:  CS Server Delete Handler
       
    15 *
       
    16 */
       
    17 // INCLUDES
       
    18 #include <ccsclientconversation.h>
       
    19 #include <ccsconversationentry.h>
       
    20 #include "ccsconversationcache.h"
       
    21 #include "ccsconversationdeletehandler.h"
       
    22 #include "mcsconversationdeleteobserver.h"
       
    23 
       
    24 // ----------------------------------------------------------------------------
       
    25 // CCsConversationDeleteHandler::NewL
       
    26 // Two Phase Construction
       
    27 // ----------------------------------------------------------------------------
       
    28 CCsConversationDeleteHandler* CCsConversationDeleteHandler::
       
    29 NewL(CCsConversationCache* aCache, MCsConversationDeleteObserver* aObserver)
       
    30     {
       
    31     CCsConversationDeleteHandler* self = 
       
    32             new (ELeave) CCsConversationDeleteHandler();
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL(aCache, aObserver);
       
    35     CleanupStack::Pop(self); // self
       
    36     return self;
       
    37     }
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // Constructor
       
    41 // ----------------------------------------------------------------------------
       
    42 CCsConversationDeleteHandler::CCsConversationDeleteHandler():
       
    43         CActive(CActive::EPriorityLow)
       
    44     {
       
    45     CActiveScheduler::Add( this );
       
    46     }
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // Constructor
       
    50 // ----------------------------------------------------------------------------
       
    51 void CCsConversationDeleteHandler::ConstructL(CCsConversationCache* aCache,
       
    52         MCsConversationDeleteObserver* aObserver)
       
    53     {
       
    54     iCache = aCache;
       
    55     iState = EIdle;
       
    56     iObserver = aObserver;
       
    57     
       
    58     iConversationEntryList = new (ELeave)RPointerArray<CCsConversationEntry> ();  
       
    59     iSession = CMsvSession::OpenSyncL(*this);
       
    60     }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // Destructor
       
    64 // ----------------------------------------------------------------------------
       
    65 CCsConversationDeleteHandler::~CCsConversationDeleteHandler()
       
    66     {
       
    67     if(iSession)
       
    68         {
       
    69         delete iSession;
       
    70         iSession = NULL;
       
    71         }
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // Delete set of messages
       
    76 // ----------------------------------------------------------------------------
       
    77 void CCsConversationDeleteHandler::DeleteL(TInt aConversationId)
       
    78     {
       
    79     // Check if delete in progress
       
    80     if ( iCache->IsDeleted(aConversationId) )
       
    81         {
       
    82         iObserver->DeleteInProgress(this);
       
    83         return;
       
    84         }
       
    85     
       
    86     // Store conversationId currently being deleted.
       
    87     iConversationId = aConversationId;
       
    88 
       
    89     // Temp client conversation object
       
    90     CCsClientConversation* clientConversation = CCsClientConversation::NewL();
       
    91     clientConversation->SetConversationEntryId(iConversationId);
       
    92     CleanupStack::PushL(clientConversation);
       
    93     
       
    94     // Create entry list
       
    95     iConversationEntryList = new (ELeave)RPointerArray<CCsConversationEntry> ();  
       
    96     
       
    97     // Get conversationlist for given client conversation
       
    98     iCache->GetConversationsL (clientConversation, iConversationEntryList);
       
    99     iCache->MarkConversationAsDeleted(iConversationId, ETrue);
       
   100     
       
   101     iDeletedCount = 0;
       
   102     
       
   103     // Cleanup  
       
   104     CleanupStack::PopAndDestroy(clientConversation);
       
   105         
       
   106     iState = EDeleteStart;
       
   107     IssueRequest();
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // Delete a message
       
   112 // ----------------------------------------------------------------------------
       
   113 void CCsConversationDeleteHandler::DeleteOneMessageL()
       
   114     {
       
   115     CCsConversationEntry* entry = 
       
   116             static_cast<CCsConversationEntry*>((*iConversationEntryList)[iDeletedCount]);
       
   117     TInt id = entry->EntryId();
       
   118     if ( ECsSendStateSending != entry->GetSendState() )
       
   119         {
       
   120         iSession->RemoveEntry(id);
       
   121         }
       
   122     }
       
   123 
       
   124 // ----------------------------------------------------------------------------
       
   125 // RunL
       
   126 // ----------------------------------------------------------------------------
       
   127 void CCsConversationDeleteHandler::RunL()
       
   128     {
       
   129     switch ( iState )
       
   130         {
       
   131         case EDeleteStart:
       
   132             if ( iConversationEntryList->Count() > 0 )
       
   133                 {
       
   134                 iDeletedCount = iConversationEntryList->Count();
       
   135                 iState = EDeleteNext;
       
   136                 IssueRequest();
       
   137                 }
       
   138             else
       
   139                 {
       
   140                 iState = EDeleteComplete;
       
   141                 IssueRequest();
       
   142                 }
       
   143             break;
       
   144         
       
   145         case EDeleteNext:
       
   146             iDeletedCount--;
       
   147             DeleteOneMessageL();
       
   148             if ( iDeletedCount > 0 )
       
   149                 {
       
   150                 iState = EDeleteNext;
       
   151                 IssueRequest();
       
   152                 }
       
   153             else
       
   154                 {
       
   155                 iState = EDeleteComplete;
       
   156                 IssueRequest();
       
   157                 }
       
   158             break;
       
   159             
       
   160         case EDeleteComplete:
       
   161             // Mark delete complete.
       
   162             iCache->MarkConversationAsDeleted(iConversationId, EFalse);
       
   163             // Cleanup
       
   164             iDeletedCount = 0;
       
   165             iConversationEntryList->ResetAndDestroy();
       
   166             iConversationEntryList->Close();
       
   167             delete iConversationEntryList;
       
   168             iConversationEntryList = NULL;  
       
   169             
       
   170             // Notify observers
       
   171             iObserver->DeleteComplete(this);
       
   172             break;
       
   173         }
       
   174     }
       
   175 
       
   176 // ----------------------------------------------------------------------------
       
   177 // DoCancel
       
   178 // ----------------------------------------------------------------------------
       
   179 void CCsConversationDeleteHandler::DoCancel()
       
   180     {
       
   181     // Not supported
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // Move to next state
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CCsConversationDeleteHandler::IssueRequest()
       
   189     {
       
   190     if( !IsActive() )
       
   191         {
       
   192         iStatus = KRequestPending;
       
   193         TRequestStatus* status = &iStatus;
       
   194         SetActive();
       
   195         User::RequestComplete(status, KErrNone);
       
   196         }
       
   197     }
       
   198 
       
   199 // EOF