author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 09:45:25 +0300 | |
changeset 52 | 12db4185673b |
parent 44 | 36f374c67aa8 |
child 47 | 5b14749788d7 |
permissions | -rw-r--r-- |
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(): |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
42 |
CActive(CActive::EPriorityLow), |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
43 |
iState(EIdle), |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
44 |
iConversationEntryList(NULL) |
31 | 45 |
{ |
46 |
CActiveScheduler::Add( this ); |
|
47 |
} |
|
48 |
||
49 |
// ---------------------------------------------------------------------------- |
|
50 |
// Constructor |
|
51 |
// ---------------------------------------------------------------------------- |
|
52 |
void CCsConversationDeleteHandler::ConstructL(CCsConversationCache* aCache) |
|
53 |
{ |
|
54 |
iCache = aCache; |
|
55 |
iSession = CMsvSession::OpenSyncL(*this); |
|
56 |
} |
|
57 |
||
58 |
// ---------------------------------------------------------------------------- |
|
59 |
// Destructor |
|
60 |
// ---------------------------------------------------------------------------- |
|
61 |
CCsConversationDeleteHandler::~CCsConversationDeleteHandler() |
|
62 |
{ |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
63 |
// Make sure Aync request cancel. |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
64 |
Cancel(); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
65 |
|
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
66 |
if(iSession) |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
67 |
{ |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
68 |
delete iSession; |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
69 |
iSession = NULL; |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
70 |
} |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
71 |
|
31 | 72 |
if (iConversationEntryList) |
73 |
{ |
|
74 |
iConversationEntryList->ResetAndDestroy(); |
|
75 |
iConversationEntryList->Close(); |
|
76 |
delete iConversationEntryList; |
|
77 |
iConversationEntryList = NULL; |
|
78 |
} |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
79 |
} |
31 | 80 |
|
81 |
// ---------------------------------------------------------------------------- |
|
82 |
// Delete set of messages |
|
83 |
// ---------------------------------------------------------------------------- |
|
84 |
void CCsConversationDeleteHandler::DeleteL(TInt aConversationId) |
|
85 |
{ |
|
86 |
// Check if delete in progress |
|
87 |
if ( iCache->IsDeleted(aConversationId) ) |
|
88 |
{ |
|
89 |
// Deletion is in progress for this conversation, so clean up this AO |
|
90 |
delete this; |
|
91 |
return; |
|
92 |
} |
|
93 |
||
94 |
// Store conversationId currently being deleted. |
|
95 |
iConversationId = aConversationId; |
|
96 |
||
97 |
// Temp client conversation object |
|
98 |
CCsClientConversation* clientConversation = CCsClientConversation::NewL(); |
|
99 |
clientConversation->SetConversationEntryId(iConversationId); |
|
100 |
CleanupStack::PushL(clientConversation); |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
101 |
|
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
102 |
// Create entry list |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
103 |
iConversationEntryList = new (ELeave)RPointerArray<CCsConversationEntry> (); |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
104 |
|
31 | 105 |
// Get conversationlist for given client conversation |
106 |
iCache->GetConversationsL (clientConversation, iConversationEntryList); |
|
107 |
iCache->MarkConversationAsDeleted(iConversationId, ETrue); |
|
108 |
||
109 |
iDeletedCount = 0; |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
110 |
iSendStateMsgs = 0; |
31 | 111 |
|
112 |
// Cleanup |
|
113 |
CleanupStack::PopAndDestroy(clientConversation); |
|
114 |
||
115 |
iState = EDeleteStart; |
|
116 |
IssueRequest(); |
|
117 |
} |
|
118 |
||
119 |
// ---------------------------------------------------------------------------- |
|
120 |
// Delete a message |
|
121 |
// ---------------------------------------------------------------------------- |
|
122 |
void CCsConversationDeleteHandler::DeleteOneMessage() |
|
123 |
{ |
|
124 |
CCsConversationEntry* entry = |
|
125 |
static_cast<CCsConversationEntry*>((*iConversationEntryList)[iDeletedCount]); |
|
126 |
||
127 |
TInt id = entry->EntryId(); |
|
128 |
||
129 |
if ( ECsSendStateSending != entry->GetSendState() ) |
|
130 |
{ |
|
131 |
iSession->RemoveEntry(id); |
|
132 |
} |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
133 |
else |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
134 |
{ |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
135 |
iSendStateMsgs++; |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
136 |
} |
31 | 137 |
} |
138 |
||
139 |
// ---------------------------------------------------------------------------- |
|
140 |
// RunL |
|
141 |
// ---------------------------------------------------------------------------- |
|
142 |
void CCsConversationDeleteHandler::RunL() |
|
143 |
{ |
|
144 |
switch ( iState ) |
|
145 |
{ |
|
146 |
case EDeleteStart: |
|
147 |
if ( iConversationEntryList->Count() > 0 ) |
|
148 |
{ |
|
149 |
iDeletedCount = iConversationEntryList->Count(); |
|
150 |
iState = EDeleteNext; |
|
151 |
IssueRequest(); |
|
152 |
} |
|
153 |
else |
|
154 |
{ |
|
155 |
iState = EDeleteComplete; |
|
156 |
IssueRequest(); |
|
157 |
} |
|
158 |
break; |
|
159 |
||
160 |
case EDeleteNext: |
|
161 |
iDeletedCount--; |
|
162 |
DeleteOneMessage(); |
|
163 |
if ( iDeletedCount > 0 ) |
|
164 |
{ |
|
165 |
iState = EDeleteNext; |
|
166 |
IssueRequest(); |
|
167 |
} |
|
168 |
else |
|
169 |
{ |
|
170 |
iState = EDeleteComplete; |
|
171 |
IssueRequest(); |
|
172 |
} |
|
173 |
break; |
|
174 |
||
175 |
case EDeleteComplete: |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
176 |
iCache->MarkConversationAsDeleted(iConversationId, EFalse, iSendStateMsgs ); |
31 | 177 |
delete this; |
178 |
break; |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
// ---------------------------------------------------------------------------- |
|
183 |
// DoCancel |
|
184 |
// ---------------------------------------------------------------------------- |
|
185 |
void CCsConversationDeleteHandler::DoCancel() |
|
186 |
{ |
|
187 |
// Not supported |
|
188 |
} |
|
189 |
||
190 |
// --------------------------------------------------------------------------- |
|
191 |
// Move to next state |
|
192 |
// --------------------------------------------------------------------------- |
|
193 |
// |
|
194 |
void CCsConversationDeleteHandler::IssueRequest() |
|
195 |
{ |
|
196 |
if( !IsActive() ) |
|
197 |
{ |
|
198 |
iStatus = KRequestPending; |
|
199 |
TRequestStatus* status = &iStatus; |
|
200 |
SetActive(); |
|
201 |
User::RequestComplete(status, KErrNone); |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
// EOF |