author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 13:35:48 +0300 | |
changeset 34 | 84197e66a4bd |
parent 31 | ebfee66fde93 |
child 43 | 35b64624a9e7 |
permissions | -rw-r--r-- |
31 | 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 "conversationsenginedefines.h" |
|
20 |
#include "convergedmessage.h" |
|
21 |
#include "conversationmsgstorehandler.h" |
|
22 |
#include "conversationssummarymodel.h" |
|
23 |
#include "conversationsmodel.h" |
|
24 |
#include "draftsmodel.h" |
|
25 |
#include "conversationsengine_p.h" |
|
26 |
#include "debugtraces.h" |
|
27 |
#include "s60qconversions.h" |
|
28 |
||
29 |
//--------------------------------------------------------------- |
|
30 |
// ConversationsEngine::instance |
|
31 |
// @see header |
|
32 |
//--------------------------------------------------------------- |
|
33 |
ConversationsEngine* ConversationsEngine::instance() |
|
34 |
{ |
|
35 |
static ConversationsEngine* conversationsEngine = |
|
36 |
new ConversationsEngine(); |
|
37 |
return conversationsEngine; |
|
38 |
} |
|
39 |
||
40 |
//--------------------------------------------------------------- |
|
41 |
// ConversationsEngine::ConversationsEngine |
|
42 |
// @see header |
|
43 |
//--------------------------------------------------------------- |
|
44 |
ConversationsEngine::ConversationsEngine(QObject* parent): |
|
45 |
QObject(parent), mDraftsModel(NULL) |
|
46 |
{ |
|
47 |
mConversationMsgStoreHandler = new ConversationMsgStoreHandler; |
|
48 |
mConversationsSummaryModel = new ConversationsSummaryModel(this); |
|
49 |
mConversationsModel = new ConversationsModel(mConversationMsgStoreHandler, |
|
50 |
this); |
|
51 |
||
52 |
d_ptr = new ConversationsEnginePrivate(mConversationMsgStoreHandler, |
|
53 |
mConversationsSummaryModel, |
|
54 |
mConversationsModel); |
|
55 |
} |
|
56 |
||
57 |
//--------------------------------------------------------------- |
|
58 |
// ConversationsEngine::~ConversationsEngine |
|
59 |
// @see header |
|
60 |
//--------------------------------------------------------------- |
|
61 |
ConversationsEngine::~ConversationsEngine() |
|
62 |
{ |
|
63 |
if(mConversationMsgStoreHandler) |
|
64 |
{ |
|
65 |
delete mConversationMsgStoreHandler; |
|
66 |
mConversationMsgStoreHandler = NULL; |
|
67 |
} |
|
68 |
if(d_ptr) |
|
69 |
{ |
|
70 |
delete d_ptr; |
|
71 |
d_ptr = NULL; |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
//--------------------------------------------------------------- |
|
76 |
// ConversationsEngine::getConversationsSummaryModel |
|
77 |
// @see header |
|
78 |
//--------------------------------------------------------------- |
|
79 |
QStandardItemModel* ConversationsEngine::getConversationsSummaryModel() |
|
80 |
{ |
|
81 |
return mConversationsSummaryModel; |
|
82 |
} |
|
83 |
||
84 |
//--------------------------------------------------------------- |
|
85 |
// ConversationsEngine::getConversationsModel |
|
86 |
// @see header |
|
87 |
//--------------------------------------------------------------- |
|
88 |
QStandardItemModel* ConversationsEngine::getConversationsModel() |
|
89 |
{ |
|
90 |
return mConversationsModel; |
|
91 |
} |
|
92 |
||
93 |
//--------------------------------------------------------------- |
|
94 |
// ConversationsEngine::getDraftsModel |
|
95 |
// @see header |
|
96 |
//--------------------------------------------------------------- |
|
97 |
QStandardItemModel* ConversationsEngine::getDraftsModel() |
|
98 |
{ |
|
99 |
if(!mDraftsModel) |
|
100 |
{ |
|
101 |
mDraftsModel = new DraftsModel(this); |
|
102 |
mConversationMsgStoreHandler->FetchDraftMessages(mDraftsModel); |
|
103 |
} |
|
104 |
return mDraftsModel; |
|
105 |
} |
|
106 |
//--------------------------------------------------------------- |
|
107 |
// ConversationsEngine::getConversations |
|
108 |
// @see header |
|
109 |
//--------------------------------------------------------------- |
|
110 |
bool ConversationsEngine::getConversations(qint64 conversationId) |
|
111 |
{ |
|
112 |
int error; |
|
113 |
TRAP(error,d_ptr->getConversationsL(conversationId)); |
|
114 |
return (error!=KErrNone) ? false : true; |
|
115 |
} |
|
116 |
||
117 |
//--------------------------------------------------------------- |
|
118 |
// ConversationsEngine::clearConversations |
|
119 |
// @see header |
|
120 |
//--------------------------------------------------------------- |
|
121 |
bool ConversationsEngine::clearConversations() |
|
122 |
{ |
|
123 |
int error; |
|
124 |
TRAP(error,d_ptr->clearConversationsL()); |
|
125 |
return (error!=KErrNone) ? false : true; |
|
126 |
} |
|
127 |
||
128 |
//--------------------------------------------------------------- |
|
129 |
// ConversationsEngine::deleteConversations |
|
130 |
// @see header |
|
131 |
//--------------------------------------------------------------- |
|
132 |
bool ConversationsEngine::deleteConversations(qint64 conversationId) |
|
133 |
{ |
|
134 |
int error; |
|
135 |
TRAP(error,d_ptr->deleteConversationL(conversationId)); |
|
136 |
return (error!=KErrNone) ? false : true; |
|
137 |
} |
|
138 |
||
139 |
//--------------------------------------------------------------- |
|
140 |
// ConversationsEngine::deleteMessages |
|
141 |
// @see header |
|
142 |
//--------------------------------------------------------------- |
|
143 |
void ConversationsEngine::deleteMessages(QList<int>& msgIdList) |
|
144 |
{ |
|
145 |
RArray<TInt> idArray; |
|
146 |
for(int i=0; i < msgIdList.count(); ++i) |
|
147 |
{ |
|
148 |
idArray.Append(msgIdList[i]); |
|
149 |
} |
|
150 |
if(msgIdList.count()>0) |
|
151 |
{ |
|
152 |
d_ptr->deleteMessages(idArray); |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
//--------------------------------------------------------------- |
|
157 |
// ConversationsEngine::deleteAllDraftMessages |
|
158 |
// @see header |
|
159 |
//--------------------------------------------------------------- |
|
160 |
void ConversationsEngine::deleteAllDraftMessages() |
|
161 |
{ |
|
162 |
int error; |
|
163 |
TRAP(error, d_ptr->deleteAllDraftMessagesL()); |
|
164 |
} |
|
165 |
||
166 |
//--------------------------------------------------------------- |
|
167 |
// ConversationsEngine::markConversationRead |
|
168 |
// @see header |
|
169 |
//--------------------------------------------------------------- |
|
170 |
bool ConversationsEngine::markConversationRead(qint64 conversationId) |
|
171 |
{ |
|
172 |
int error; |
|
173 |
TRAP(error,d_ptr->markConversationReadL(conversationId)); |
|
174 |
return (error!=KErrNone) ? false : true; |
|
175 |
} |
|
176 |
||
177 |
//--------------------------------------------------------------- |
|
178 |
// ConversationsEngine::markMessagesRead |
|
179 |
// @see header |
|
180 |
//--------------------------------------------------------------- |
|
181 |
bool ConversationsEngine::markMessagesRead(QList<int>& msgIdList) |
|
182 |
{ |
|
183 |
RArray<TInt> idArray; |
|
184 |
int error; |
|
185 |
for(int i=0; i < msgIdList.count(); ++i) |
|
186 |
{ |
|
187 |
idArray.Append(msgIdList[i]); |
|
188 |
} |
|
189 |
if(msgIdList.count()>0) |
|
190 |
{ |
|
191 |
TRAP(error,d_ptr->markMessagesReadL(idArray)); |
|
192 |
} |
|
193 |
return (error!=KErrNone) ? false : true; |
|
194 |
} |
|
195 |
||
196 |
//--------------------------------------------------------------- |
|
197 |
// ConversationsEngine::getContactDetails |
|
198 |
// @see header |
|
199 |
//--------------------------------------------------------------- |
|
200 |
void ConversationsEngine::getContactDetails(qint64 conversationId, |
|
201 |
QString& displayName, |
|
202 |
QString& address) |
|
203 |
{ |
|
204 |
QModelIndexList indexList = mConversationsSummaryModel->match( |
|
205 |
mConversationsSummaryModel->index(0, 0), |
|
206 |
ConversationId, |
|
207 |
conversationId, |
|
208 |
1, // One match |
|
209 |
Qt::MatchExactly); |
|
210 |
||
211 |
if(indexList.count() > 0) |
|
212 |
{ |
|
213 |
displayName = indexList[0].data(DisplayName).toString(); |
|
214 |
address = indexList[0].data(ConversationAddress).toString(); |
|
215 |
} |
|
216 |
} |
|
217 |
||
218 |
//--------------------------------------------------------------- |
|
219 |
// ConversationsEngine::getConversationIdFromAddress |
|
220 |
// @see header |
|
221 |
//--------------------------------------------------------------- |
|
222 |
qint64 ConversationsEngine::getConversationIdFromAddress(QString address) |
|
223 |
{ |
|
224 |
qint64 conversationId = -1; |
|
225 |
||
226 |
int error; |
|
227 |
HBufC* number = S60QConversions::qStringToS60Desc(address); |
|
228 |
TRAP(error,conversationId = |
|
229 |
d_ptr->getConversationIdFromAddressL(*number)); |
|
230 |
||
231 |
delete number; |
|
232 |
||
233 |
return conversationId; |
|
234 |
} |
|
235 |
||
236 |
//--------------------------------------------------------------- |
|
237 |
// ConversationsEngine::getCurrentConversationId |
|
238 |
// @see header |
|
239 |
//--------------------------------------------------------------- |
|
240 |
qint64 ConversationsEngine::getCurrentConversationId() |
|
241 |
{ |
|
242 |
return d_ptr->getConversationCurrentId(); |
|
243 |
} |
|
244 |
||
245 |
//--------------------------------------------------------------- |
|
246 |
// ConversationsEngine::getConversationIdFromContactId |
|
247 |
// @see header |
|
248 |
//--------------------------------------------------------------- |
|
249 |
qint64 ConversationsEngine::getConversationIdFromContactId(qint32 contactId) |
|
250 |
{ |
|
251 |
qint64 conversationId = -1; |
|
252 |
int error; |
|
253 |
TRAP(error,conversationId = |
|
254 |
d_ptr->getConversationIdFromContactIdL(contactId)); |
|
255 |
||
256 |
return conversationId; |
|
257 |
} |
|
258 |
||
259 |
//--------------------------------------------------------------- |
|
260 |
// ConversationsEngine::emitConversationModelPopulated |
|
261 |
// @see header |
|
262 |
//--------------------------------------------------------------- |
|
263 |
void ConversationsEngine::emitConversationModelPopulated() |
|
264 |
{ |
|
265 |
emit conversationModelPopulated(); |
|
266 |
} |
|
267 |
||
268 |
//--------------------------------------------------------------- |
|
269 |
// ConversationsEngine::emitConversationModelUpdated |
|
270 |
// @see header |
|
271 |
//--------------------------------------------------------------- |
|
272 |
void ConversationsEngine::emitConversationModelUpdated() |
|
273 |
{ |
|
274 |
emit conversationModelUpdated(); |
|
275 |
} |
|
276 |
||
277 |
//--------------------------------------------------------------- |
|
278 |
// ConversationsEngine::emitConversationListModelPopulated |
|
279 |
// @see header |
|
280 |
//--------------------------------------------------------------- |
|
281 |
void ConversationsEngine::emitConversationListModelPopulated() |
|
282 |
{ |
|
283 |
emit conversationListModelPopulated(); |
|
284 |
} |
|
285 |
||
286 |
//--------------------------------------------------------------- |
|
287 |
// ConversationsEngine::fetchMoreConversations |
|
288 |
// @see header |
|
289 |
//--------------------------------------------------------------- |
|
290 |
void ConversationsEngine::fetchMoreConversations() |
|
291 |
{ |
|
292 |
d_ptr->fetchMoreConversations(); |
|
293 |
} |
|
294 |
||
295 |
//--------------------------------------------------------------- |
|
296 |
// ConversationsEngine::resendMessage() |
|
297 |
// @see header |
|
298 |
//--------------------------------------------------------------- |
|
299 |
||
300 |
bool ConversationsEngine::resendMessage(qint32 messageId) |
|
301 |
{ |
|
302 |
return d_ptr->resendMessage(messageId); |
|
303 |
} |
|
304 |
||
305 |
//--------------------------------------------------------------- |
|
306 |
// ConversationsEngine::downloadMessage() |
|
307 |
// @see header |
|
308 |
//--------------------------------------------------------------- |
|
309 |
||
310 |
int ConversationsEngine::downloadMessage(qint32 messageId) |
|
311 |
{ |
|
312 |
return d_ptr->downloadMessage(messageId); |
|
313 |
} |
|
314 |
||
315 |
//--------------------------------------------------------------- |
|
316 |
// ConversationsEngine::downloadOperationSupported() |
|
317 |
// @see header |
|
318 |
//--------------------------------------------------------------- |
|
319 |
bool ConversationsEngine::downloadOperationSupported(qint32 messageId) |
|
320 |
{ |
|
321 |
return d_ptr->downloadOperationSupported(messageId); |
|
322 |
} |
|
323 |
||
324 |
//--------------------------------------------------------------- |
|
325 |
// ConversationsEngine::markAsReadAndGetType() |
|
326 |
// @see header |
|
327 |
//--------------------------------------------------------------- |
|
328 |
||
329 |
void ConversationsEngine::markAsReadAndGetType(qint32 messageId, |
|
330 |
int& msgType, |
|
331 |
int& msgSubType) |
|
332 |
{ |
|
333 |
mConversationMsgStoreHandler->markAsReadAndGetType(messageId, |
|
334 |
msgType, |
|
335 |
msgSubType); |
|
336 |
} |
|
337 |
||
338 |
//--------------------------------------------------------------- |
|
339 |
// ConversationsEngine::getDBHandle() |
|
340 |
// @see header |
|
341 |
//--------------------------------------------------------------- |
|
342 |
RSqlDatabase& ConversationsEngine::getDBHandle(TBool& isOpen) |
|
343 |
{ |
|
344 |
return mConversationsModel->getDBHandle(isOpen); |
|
345 |
} |
|
346 |
||
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
347 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
348 |
//--------------------------------------------------------------- |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
349 |
// ConversationsEngine::getMsgSubType() |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
350 |
// @see header |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
351 |
//--------------------------------------------------------------- |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
352 |
int ConversationsEngine::getMsgSubType(int messageId) |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
353 |
{ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
354 |
return mConversationMsgStoreHandler->getMsgSubType(messageId); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
355 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
356 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
357 |
|
31 | 358 |
//EOF |
359 |