|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 #include "conversationsengine_p.h" |
|
18 |
|
19 //SYSTEM INCLUDES |
|
20 #include <ccsconversationentry.h> |
|
21 #include <ccsclientconversation.h> |
|
22 //USER INCLUDES |
|
23 #include "conversationsenginedefines.h" |
|
24 #include "conversationmsgstorehandler.h" |
|
25 #include "conversationssummarymodel.h" |
|
26 #include "conversationsmodel.h" |
|
27 #include "conversationchangehandler.h" |
|
28 #include "conversationlistchangehandler.h" |
|
29 |
|
30 //--------------------------------------------------------------- |
|
31 // ConversationsEnginePrivate::ConversationsEnginePrivate |
|
32 // @see header |
|
33 //--------------------------------------------------------------- |
|
34 ConversationsEnginePrivate::ConversationsEnginePrivate( |
|
35 ConversationMsgStoreHandler* conversationMsgStoreHandler, |
|
36 ConversationsSummaryModel *conversationsSummaryModel, |
|
37 ConversationsModel *conversationsModel |
|
38 ):mServer(NULL), |
|
39 mClientConv(NULL), |
|
40 mConversationMsgStoreHandler(conversationMsgStoreHandler), |
|
41 mConversationsSummaryModel(conversationsSummaryModel), |
|
42 mConversationsModel(conversationsModel) |
|
43 { |
|
44 TRAP_IGNORE(initL()); |
|
45 } |
|
46 |
|
47 //--------------------------------------------------------------- |
|
48 // ConversationsEnginePrivate::~ConversationsEnginePrivate |
|
49 // @see header |
|
50 //--------------------------------------------------------------- |
|
51 ConversationsEnginePrivate::~ConversationsEnginePrivate() |
|
52 { |
|
53 delete mConvChangeHandler; |
|
54 |
|
55 delete mConvListChangeHandler; |
|
56 |
|
57 if( mClientConv ) |
|
58 { |
|
59 if(mServer) |
|
60 { |
|
61 mServer->RemoveConversationChangeEventL (mConvChangeHandler, |
|
62 mClientConv); |
|
63 } |
|
64 delete mClientConv; |
|
65 mClientConv = NULL; |
|
66 } |
|
67 if(mServer) |
|
68 { |
|
69 mServer->RemoveConversationListChangeEventL (mConvListChangeHandler); |
|
70 mServer->RemoveResultsEventL ( this ); |
|
71 mServer->Cancel(); |
|
72 delete mServer; |
|
73 mServer = NULL; |
|
74 } |
|
75 } |
|
76 |
|
77 //--------------------------------------------------------------- |
|
78 // ConversationsEnginePrivate::initL |
|
79 // @see header |
|
80 //--------------------------------------------------------------- |
|
81 void ConversationsEnginePrivate::initL() |
|
82 { |
|
83 mServer = CCSRequestHandler::NewL(); |
|
84 |
|
85 //Add results observer to the server |
|
86 mServer->RequestResultsEventL(this); |
|
87 |
|
88 //Fetch the conversation list from server |
|
89 mServer->GetConversationListL(); |
|
90 |
|
91 mConvChangeHandler = new ConversationsChangeHandler(this, |
|
92 mConversationsModel); |
|
93 |
|
94 mConvListChangeHandler = new ConversationsListChangeHandler(this, |
|
95 mConversationsSummaryModel); |
|
96 } |
|
97 |
|
98 //--------------------------------------------------------------- |
|
99 // ConversationsEnginePrivate::registerForConversationListUpdatesL |
|
100 // @see header |
|
101 //--------------------------------------------------------------- |
|
102 void ConversationsEnginePrivate::registerForConversationListUpdatesL() |
|
103 { |
|
104 //Add ConversationListChange Observer |
|
105 mServer->RequestConversationListChangeEventL (mConvListChangeHandler); |
|
106 } |
|
107 |
|
108 //--------------------------------------------------------------- |
|
109 // ConversationsEnginePrivate::getConversationsL |
|
110 // @see header |
|
111 //--------------------------------------------------------------- |
|
112 void ConversationsEnginePrivate::getConversationsL( TInt aConversationId) |
|
113 { |
|
114 if(!mClientConv) |
|
115 { |
|
116 //Clear the model before issueing fetch |
|
117 mConversationsModel->clear(); |
|
118 //create a client conversation |
|
119 mClientConv = CCsClientConversation::NewL(); |
|
120 mClientConv->SetConversationEntryId(aConversationId); |
|
121 //set dummy entry |
|
122 CCsConversationEntry *entry = CCsConversationEntry::NewL(); |
|
123 CleanupStack::PushL(entry); |
|
124 mClientConv->SetConversationEntryL(entry); |
|
125 CleanupStack::PopAndDestroy(entry); |
|
126 //Get the conversations for new conversationId |
|
127 mServer->GetConversationsL( mClientConv ); |
|
128 } |
|
129 } |
|
130 |
|
131 //--------------------------------------------------------------- |
|
132 // ConversationsEnginePrivate::deleteConversationL |
|
133 // @see header |
|
134 //--------------------------------------------------------------- |
|
135 void ConversationsEnginePrivate::deleteConversationL(TInt aConversationId) |
|
136 { |
|
137 mServer->DeleteConversationL(aConversationId); |
|
138 } |
|
139 |
|
140 //--------------------------------------------------------------- |
|
141 // ConversationsEnginePrivate::deleteMessages |
|
142 // @see header |
|
143 //--------------------------------------------------------------- |
|
144 void ConversationsEnginePrivate::deleteMessages(RArray<TInt>& aIdArray) |
|
145 { |
|
146 mConversationMsgStoreHandler->DeleteMessages(aIdArray); |
|
147 } |
|
148 |
|
149 //--------------------------------------------------------------- |
|
150 // ConversationsEnginePrivate::markConversationReadL |
|
151 // @see header |
|
152 //--------------------------------------------------------------- |
|
153 void ConversationsEnginePrivate::markConversationReadL(TInt aConversationId) |
|
154 { |
|
155 mServer->MarkConversationReadL(aConversationId); |
|
156 } |
|
157 |
|
158 //--------------------------------------------------------------- |
|
159 // ConversationsEnginePrivate::markMessagesReadL |
|
160 // @see header |
|
161 //--------------------------------------------------------------- |
|
162 void ConversationsEnginePrivate::markMessagesReadL(RArray<TInt>& aIdArray) |
|
163 { |
|
164 mConversationMsgStoreHandler->MarkMessagesReadL(aIdArray); |
|
165 } |
|
166 |
|
167 //--------------------------------------------------------------- |
|
168 // ConversationsEnginePrivate::getConversationCurrentId |
|
169 // @see header |
|
170 //--------------------------------------------------------------- |
|
171 TInt ConversationsEnginePrivate::getConversationCurrentId() |
|
172 { |
|
173 TInt convId = -1; |
|
174 if(mClientConv) |
|
175 { |
|
176 convId = mClientConv->GetConversationEntryId(); |
|
177 } |
|
178 return convId; |
|
179 } |
|
180 |
|
181 //--------------------------------------------------------------- |
|
182 // ConversationsEnginePrivate::getConversationIdFromContactId |
|
183 // @see header |
|
184 //--------------------------------------------------------------- |
|
185 TInt ConversationsEnginePrivate::getConversationIdFromContactIdL(TInt contactId) |
|
186 { |
|
187 TInt convId = -1; |
|
188 |
|
189 convId = mServer->GetConversationIdL(contactId); |
|
190 |
|
191 return convId; |
|
192 } |
|
193 |
|
194 //--------------------------------------------------------------- |
|
195 // ConversationsEnginePrivate::getConversationIdFromAddress |
|
196 // @see header |
|
197 //--------------------------------------------------------------- |
|
198 TInt ConversationsEnginePrivate::getConversationIdFromAddressL(TDesC& contactAddress) |
|
199 { |
|
200 TInt convId = -1; |
|
201 |
|
202 convId = mServer->GetConversationIdFromAddressL(contactAddress); |
|
203 |
|
204 return convId; |
|
205 } |
|
206 |
|
207 |
|
208 //--------------------------------------------------------------- |
|
209 // ConversationsEnginePrivate::clearConversationsL |
|
210 // @see header |
|
211 //--------------------------------------------------------------- |
|
212 void ConversationsEnginePrivate::clearConversationsL() |
|
213 { |
|
214 mConvChangeHandler->Cancel(); |
|
215 //Clear conversations model before populating with new data |
|
216 mConversationsModel->clear(); |
|
217 |
|
218 // Delete old CCsClientConversation object |
|
219 // Remove the old Conversation change observer |
|
220 if(mClientConv) |
|
221 { |
|
222 mServer->RemoveConversationChangeEventL (mConvChangeHandler ,mClientConv); |
|
223 delete mClientConv; |
|
224 mClientConv = NULL; |
|
225 } |
|
226 } |
|
227 |
|
228 //--------------------------------------------------------------- |
|
229 // ConversationsEnginePrivate::registerForConversationUpdatesL |
|
230 // @see header |
|
231 //--------------------------------------------------------------- |
|
232 void ConversationsEnginePrivate::registerForConversationUpdatesL() |
|
233 { |
|
234 //Add the Conversation Change for new conversationId |
|
235 if(mClientConv) |
|
236 { |
|
237 mServer->RequestConversationChangeEventL (mConvChangeHandler ,mClientConv); |
|
238 } |
|
239 } |
|
240 |
|
241 //--------------------------------------------------------------- |
|
242 // ConversationsEnginePrivate::ConversationList |
|
243 // @see header |
|
244 //--------------------------------------------------------------- |
|
245 void ConversationsEnginePrivate::ConversationList( |
|
246 RPointerArray<CCsClientConversation>& aClientConversationList) |
|
247 { |
|
248 int error; |
|
249 TRAP(error, |
|
250 mConvListChangeHandler->ConversationListL(aClientConversationList)); |
|
251 } |
|
252 |
|
253 //--------------------------------------------------------------- |
|
254 // ConversationsEnginePrivate::Conversations |
|
255 // @see header |
|
256 //--------------------------------------------------------------- |
|
257 void ConversationsEnginePrivate::Conversations( |
|
258 RPointerArray<CCsConversationEntry>& aConversationEntryList) |
|
259 { |
|
260 int error; |
|
261 if(mClientConv) |
|
262 { |
|
263 TRAP(error,mConvChangeHandler->ConversationsL(aConversationEntryList)); |
|
264 } |
|
265 } |
|
266 |
|
267 |
|
268 //--------------------------------------------------------------- |
|
269 // ConversationsEngine::fetchMoreConversations |
|
270 // @see header |
|
271 //--------------------------------------------------------------- |
|
272 void ConversationsEnginePrivate::fetchMoreConversations() |
|
273 { |
|
274 if(mClientConv) |
|
275 { |
|
276 mConvChangeHandler->restartHandleConversations(); |
|
277 } |
|
278 } |
|
279 |
|
280 //EOF |
|
281 |