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