|
1 /* |
|
2 * Copyright (c) 2009 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.h" |
|
18 |
|
19 #include <ccsconversationentry.h> |
|
20 #include <ccsclientconversation.h> |
|
21 |
|
22 #include "conversationsenginedefines.h" |
|
23 #include "convergedmessage.h" |
|
24 #include "conversationmsgstorehandler.h" |
|
25 #include "conversationssummarymodel.h" |
|
26 #include "conversationsmodel.h" |
|
27 #include "draftsmodel.h" |
|
28 #include "conversationsengine_p.h" |
|
29 #include "debugtraces.h" |
|
30 #include <xqconversions.h> |
|
31 |
|
32 //--------------------------------------------------------------- |
|
33 // ConversationsEngine::instance |
|
34 // @see header |
|
35 //--------------------------------------------------------------- |
|
36 ConversationsEngine* ConversationsEngine::instance() |
|
37 { |
|
38 static ConversationsEngine* conversationsEngine = |
|
39 new ConversationsEngine(); |
|
40 return conversationsEngine; |
|
41 } |
|
42 |
|
43 //--------------------------------------------------------------- |
|
44 // ConversationsEngine::ConversationsEngine |
|
45 // @see header |
|
46 //--------------------------------------------------------------- |
|
47 ConversationsEngine::ConversationsEngine(QObject* parent): |
|
48 QObject(parent), mDraftsModel(NULL) |
|
49 { |
|
50 mConversationMsgStoreHandler = q_check_ptr(new ConversationMsgStoreHandler); |
|
51 |
|
52 mConversationsSummaryModel = new ConversationsSummaryModel(this); |
|
53 mConversationsModel = new ConversationsModel(mConversationMsgStoreHandler, |
|
54 this); |
|
55 |
|
56 d_ptr = q_check_ptr( new ConversationsEnginePrivate(mConversationMsgStoreHandler, |
|
57 mConversationsSummaryModel, |
|
58 mConversationsModel)); |
|
59 |
|
60 connect (mConversationsModel, |
|
61 SIGNAL(conversationViewEmpty()), |
|
62 this, |
|
63 SIGNAL(conversationViewEmpty())); |
|
64 |
|
65 } |
|
66 |
|
67 //--------------------------------------------------------------- |
|
68 // ConversationsEngine::~ConversationsEngine |
|
69 // @see header |
|
70 //--------------------------------------------------------------- |
|
71 ConversationsEngine::~ConversationsEngine() |
|
72 { |
|
73 if(mConversationMsgStoreHandler) |
|
74 { |
|
75 delete mConversationMsgStoreHandler; |
|
76 mConversationMsgStoreHandler = NULL; |
|
77 } |
|
78 if(d_ptr) |
|
79 { |
|
80 delete d_ptr; |
|
81 d_ptr = NULL; |
|
82 } |
|
83 } |
|
84 |
|
85 //--------------------------------------------------------------- |
|
86 // ConversationsEngine::getConversationsSummaryModel |
|
87 // @see header |
|
88 //--------------------------------------------------------------- |
|
89 QStandardItemModel* ConversationsEngine::getConversationsSummaryModel() |
|
90 { |
|
91 return mConversationsSummaryModel; |
|
92 } |
|
93 |
|
94 //--------------------------------------------------------------- |
|
95 // ConversationsEngine::getConversationsModel |
|
96 // @see header |
|
97 //--------------------------------------------------------------- |
|
98 QStandardItemModel* ConversationsEngine::getConversationsModel() |
|
99 { |
|
100 return mConversationsModel; |
|
101 } |
|
102 |
|
103 //--------------------------------------------------------------- |
|
104 // ConversationsEngine::getDraftsModel |
|
105 // @see header |
|
106 //--------------------------------------------------------------- |
|
107 QStandardItemModel* ConversationsEngine::getDraftsModel() |
|
108 { |
|
109 if(!mDraftsModel) |
|
110 { |
|
111 mDraftsModel = new DraftsModel(this); |
|
112 mConversationMsgStoreHandler->FetchDraftMessages(mDraftsModel); |
|
113 } |
|
114 return mDraftsModel; |
|
115 } |
|
116 //--------------------------------------------------------------- |
|
117 // ConversationsEngine::getConversations |
|
118 // @see header |
|
119 //--------------------------------------------------------------- |
|
120 bool ConversationsEngine::getConversations(qint64 conversationId) |
|
121 { |
|
122 int error; |
|
123 TRAP(error,d_ptr->getConversationsL(conversationId)); |
|
124 return (error!=KErrNone) ? false : true; |
|
125 } |
|
126 |
|
127 //--------------------------------------------------------------- |
|
128 // ConversationsEngine::clearConversations |
|
129 // @see header |
|
130 //--------------------------------------------------------------- |
|
131 bool ConversationsEngine::clearConversations() |
|
132 { |
|
133 int error; |
|
134 TRAP(error,d_ptr->clearConversationsL()); |
|
135 return (error!=KErrNone) ? false : true; |
|
136 } |
|
137 |
|
138 //--------------------------------------------------------------- |
|
139 // ConversationsEngine::deleteConversations |
|
140 // @see header |
|
141 //--------------------------------------------------------------- |
|
142 bool ConversationsEngine::deleteConversations(qint64 conversationId) |
|
143 { |
|
144 int error; |
|
145 TRAP(error,d_ptr->deleteConversationL(conversationId)); |
|
146 return (error!=KErrNone) ? false : true; |
|
147 } |
|
148 |
|
149 //--------------------------------------------------------------- |
|
150 // ConversationsEngine::deleteMessages |
|
151 // @see header |
|
152 //--------------------------------------------------------------- |
|
153 void ConversationsEngine::deleteMessages(QList<int>& msgIdList) |
|
154 { |
|
155 RArray<TInt> idArray; |
|
156 for(int i=0; i < msgIdList.count(); ++i) |
|
157 { |
|
158 idArray.Append(msgIdList[i]); |
|
159 } |
|
160 if(msgIdList.count()>0) |
|
161 { |
|
162 d_ptr->deleteMessages(idArray); |
|
163 } |
|
164 } |
|
165 |
|
166 //--------------------------------------------------------------- |
|
167 // ConversationsEngine::deleteAllDraftMessages |
|
168 // @see header |
|
169 //--------------------------------------------------------------- |
|
170 void ConversationsEngine::deleteAllDraftMessages() |
|
171 { |
|
172 int error; |
|
173 TRAP(error, d_ptr->deleteAllDraftMessagesL()); |
|
174 qt_symbian_throwIfError(error); |
|
175 } |
|
176 |
|
177 //--------------------------------------------------------------- |
|
178 // ConversationsEngine::markConversationRead |
|
179 // @see header |
|
180 //--------------------------------------------------------------- |
|
181 bool ConversationsEngine::markConversationRead(qint64 conversationId) |
|
182 { |
|
183 int error; |
|
184 TRAP(error,d_ptr->markConversationReadL(conversationId)); |
|
185 return (error!=KErrNone) ? false : true; |
|
186 } |
|
187 |
|
188 //--------------------------------------------------------------- |
|
189 // ConversationsEngine::markMessagesRead |
|
190 // @see header |
|
191 //--------------------------------------------------------------- |
|
192 bool ConversationsEngine::markMessagesRead(QList<int>& msgIdList) |
|
193 { |
|
194 RArray<TInt> idArray; |
|
195 int error; |
|
196 for(int i=0; i < msgIdList.count(); ++i) |
|
197 { |
|
198 idArray.Append(msgIdList[i]); |
|
199 } |
|
200 if(msgIdList.count()>0) |
|
201 { |
|
202 TRAP(error,d_ptr->markMessagesReadL(idArray)); |
|
203 } |
|
204 return (error!=KErrNone) ? false : true; |
|
205 } |
|
206 |
|
207 //--------------------------------------------------------------- |
|
208 // ConversationsEngine::getContactDetails |
|
209 // @see header |
|
210 //--------------------------------------------------------------- |
|
211 void ConversationsEngine::getContactDetails(qint64 conversationId, |
|
212 QString& displayName, |
|
213 QString& address) |
|
214 { |
|
215 QModelIndexList indexList = mConversationsSummaryModel->match( |
|
216 mConversationsSummaryModel->index(0, 0), |
|
217 ConversationId, |
|
218 conversationId, |
|
219 1, // One match |
|
220 Qt::MatchExactly); |
|
221 |
|
222 if(indexList.count() > 0) |
|
223 { |
|
224 displayName = indexList[0].data(DisplayName).toString(); |
|
225 address = indexList[0].data(ConversationAddress).toString(); |
|
226 } |
|
227 else |
|
228 { |
|
229 int error; |
|
230 CCsClientConversation* clientConv = NULL; |
|
231 TRAP(error, clientConv = d_ptr->getConversationFromConversationIdL(conversationId)); |
|
232 |
|
233 qt_symbian_throwIfError(error); |
|
234 |
|
235 HBufC *name = clientConv->GetDisplayName(); |
|
236 if (name && name->Length()) |
|
237 { |
|
238 displayName = XQConversions::s60DescToQString(*name); |
|
239 } |
|
240 |
|
241 HBufC *addr = clientConv->GetConversationEntry()->Contact(); |
|
242 if (addr && addr->Length()) |
|
243 { |
|
244 address = XQConversions::s60DescToQString(*addr); |
|
245 } |
|
246 |
|
247 delete clientConv; |
|
248 } |
|
249 } |
|
250 |
|
251 //--------------------------------------------------------------- |
|
252 // ConversationsEngine::getConversationIdFromAddress |
|
253 // @see header |
|
254 //--------------------------------------------------------------- |
|
255 qint64 ConversationsEngine::getConversationIdFromAddress(QString address) |
|
256 { |
|
257 qint64 conversationId = -1; |
|
258 |
|
259 int error; |
|
260 HBufC* number = XQConversions::qStringToS60Desc(address); |
|
261 TRAP(error,conversationId = |
|
262 d_ptr->getConversationIdFromAddressL(*number)); |
|
263 |
|
264 delete number; |
|
265 |
|
266 return conversationId; |
|
267 } |
|
268 |
|
269 //--------------------------------------------------------------- |
|
270 // ConversationsEngine::getCurrentConversationId |
|
271 // @see header |
|
272 //--------------------------------------------------------------- |
|
273 qint64 ConversationsEngine::getCurrentConversationId() |
|
274 { |
|
275 return d_ptr->getConversationCurrentId(); |
|
276 } |
|
277 |
|
278 //--------------------------------------------------------------- |
|
279 // ConversationsEngine::getConversationIdFromContactId |
|
280 // @see header |
|
281 //--------------------------------------------------------------- |
|
282 qint64 ConversationsEngine::getConversationIdFromContactId(qint32 contactId) |
|
283 { |
|
284 qint64 conversationId = -1; |
|
285 int error; |
|
286 TRAP(error,conversationId = |
|
287 d_ptr->getConversationIdFromContactIdL(contactId)); |
|
288 |
|
289 return conversationId; |
|
290 } |
|
291 |
|
292 //--------------------------------------------------------------- |
|
293 // ConversationsEngine::emitConversationModelPopulated |
|
294 // @see header |
|
295 //--------------------------------------------------------------- |
|
296 void ConversationsEngine::emitConversationModelPopulated() |
|
297 { |
|
298 emit conversationModelPopulated(); |
|
299 } |
|
300 |
|
301 //--------------------------------------------------------------- |
|
302 // ConversationsEngine::emitConversationModelUpdated |
|
303 // @see header |
|
304 //--------------------------------------------------------------- |
|
305 void ConversationsEngine::emitConversationModelUpdated() |
|
306 { |
|
307 emit conversationModelUpdated(); |
|
308 } |
|
309 |
|
310 //--------------------------------------------------------------- |
|
311 // ConversationsEngine::emitConversationListModelPopulated |
|
312 // @see header |
|
313 //--------------------------------------------------------------- |
|
314 void ConversationsEngine::emitConversationListModelPopulated() |
|
315 { |
|
316 emit conversationListModelPopulated(); |
|
317 } |
|
318 |
|
319 //--------------------------------------------------------------- |
|
320 // ConversationsEngine::emitConversationListModelEntryDeleted |
|
321 // @see header |
|
322 //--------------------------------------------------------------- |
|
323 void ConversationsEngine::emitConversationListModelEntryDeleted( int conversationId ) |
|
324 { |
|
325 emit conversationListEntryDeleted( conversationId ); |
|
326 } |
|
327 |
|
328 //--------------------------------------------------------------- |
|
329 // ConversationsEngine::emitOpenConversationViewIdUpdate |
|
330 // @see header |
|
331 //--------------------------------------------------------------- |
|
332 void ConversationsEngine::emitOpenConversationViewIdUpdate( |
|
333 int newConversationId) |
|
334 { |
|
335 //also register for subscription now |
|
336 QT_TRAP_THROWING(d_ptr->registerAgainForConversationUpdatesL(newConversationId)); |
|
337 } |
|
338 |
|
339 //--------------------------------------------------------------- |
|
340 // ConversationsEngine::disableRegisterationForCVEvents |
|
341 // @see header |
|
342 //--------------------------------------------------------------- |
|
343 void ConversationsEngine::disableRegisterationForCVEvents() |
|
344 { |
|
345 d_ptr->deRegisterCVUpdatesTemporary(); |
|
346 } |
|
347 |
|
348 //--------------------------------------------------------------- |
|
349 // ConversationsEngine::fetchMoreConversations |
|
350 // @see header |
|
351 //--------------------------------------------------------------- |
|
352 void ConversationsEngine::fetchMoreConversations() |
|
353 { |
|
354 d_ptr->fetchMoreConversations(); |
|
355 } |
|
356 |
|
357 //--------------------------------------------------------------- |
|
358 // ConversationsEngine::resendMessage() |
|
359 // @see header |
|
360 //--------------------------------------------------------------- |
|
361 |
|
362 bool ConversationsEngine::resendMessage(qint32 messageId) |
|
363 { |
|
364 return d_ptr->resendMessage(messageId); |
|
365 } |
|
366 |
|
367 //--------------------------------------------------------------- |
|
368 // ConversationsEngine::downloadMessage() |
|
369 // @see header |
|
370 //--------------------------------------------------------------- |
|
371 |
|
372 int ConversationsEngine::downloadMessage(qint32 messageId) |
|
373 { |
|
374 return d_ptr->downloadMessage(messageId); |
|
375 } |
|
376 |
|
377 //--------------------------------------------------------------- |
|
378 // ConversationsEngine::downloadOperationSupported() |
|
379 // @see header |
|
380 //--------------------------------------------------------------- |
|
381 bool ConversationsEngine::downloadOperationSupported(qint32 messageId) |
|
382 { |
|
383 return d_ptr->downloadOperationSupported(messageId); |
|
384 } |
|
385 |
|
386 //--------------------------------------------------------------- |
|
387 // ConversationsEngine::markAsReadAndGetType() |
|
388 // @see header |
|
389 //--------------------------------------------------------------- |
|
390 |
|
391 void ConversationsEngine::markAsReadAndGetType(qint32 messageId, |
|
392 int& msgType, |
|
393 int& msgSubType) |
|
394 { |
|
395 mConversationMsgStoreHandler->markAsReadAndGetType(messageId, |
|
396 msgType, |
|
397 msgSubType); |
|
398 } |
|
399 |
|
400 //--------------------------------------------------------------- |
|
401 // ConversationsEngine::getDBHandle() |
|
402 // @see header |
|
403 //--------------------------------------------------------------- |
|
404 RSqlDatabase& ConversationsEngine::getDBHandle(TBool& isOpen) |
|
405 { |
|
406 return mConversationsModel->getDBHandle(isOpen); |
|
407 } |
|
408 |
|
409 |
|
410 //--------------------------------------------------------------- |
|
411 // ConversationsEngine::getMsgSubType() |
|
412 // @see header |
|
413 //--------------------------------------------------------------- |
|
414 int ConversationsEngine::getMsgSubType(int messageId) |
|
415 { |
|
416 return mConversationMsgStoreHandler->getMsgSubType(messageId); |
|
417 } |
|
418 |
|
419 |
|
420 //EOF |
|
421 |