author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 23 Jun 2010 18:09:17 +0300 | |
changeset 43 | 35b64624a9e7 |
parent 34 | 84197e66a4bd |
child 44 | 36f374c67aa8 |
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 |
||
18 |
#include "conversationssummarymodel.h" |
|
19 |
#include "conversationsenginedefines.h" |
|
20 |
#include "conversationsengineutility.h" |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
21 |
#include <xqconversions.h> |
31 | 22 |
#include "convergedmessage.h" |
23 |
#include "unidatamodelloader.h" |
|
24 |
#include "unidatamodelplugininterface.h" |
|
25 |
#include "ringbc.h" |
|
26 |
#include "msgcontacthandler.h" |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
27 |
#include "debugtraces.h" |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
28 |
|
31 | 29 |
#include <ccsclientconversation.h> |
30 |
#include <ccsconversationentry.h> |
|
31 |
#include <QFile> |
|
32 |
#include <QFileInfo> |
|
33 |
||
34 |
//--------------------------------------------------------------- |
|
35 |
// ConversationsSummaryModel::ConversationsSummaryModel |
|
36 |
// @see header |
|
37 |
//--------------------------------------------------------------- |
|
38 |
ConversationsSummaryModel::ConversationsSummaryModel(QObject* parent) |
|
39 |
:QStandardItemModel(parent) |
|
40 |
{ |
|
41 |
} |
|
42 |
||
43 |
//--------------------------------------------------------------- |
|
44 |
// ConversationsSummaryModel::~ConversationsSummaryModel |
|
45 |
// @see header |
|
46 |
//--------------------------------------------------------------- |
|
47 |
ConversationsSummaryModel::~ConversationsSummaryModel() |
|
48 |
{ |
|
49 |
||
50 |
} |
|
51 |
||
52 |
//--------------------------------------------------------------- |
|
53 |
// ConversationsSummaryModel::data |
|
54 |
// @see header |
|
55 |
//--------------------------------------------------------------- |
|
56 |
QVariant ConversationsSummaryModel::data(const QModelIndex & index , |
|
57 |
int role ) const |
|
58 |
{ |
|
59 |
QVariant value; |
|
60 |
QStandardItem* item = itemFromIndex(index); |
|
61 |
switch(role) |
|
62 |
{ |
|
63 |
case ConversationId: |
|
64 |
{ |
|
65 |
value = item->data(ConversationId); |
|
66 |
break; |
|
67 |
} |
|
68 |
case UnReadStatus: |
|
69 |
{ |
|
70 |
value = item->data(UnReadStatus); |
|
71 |
break; |
|
72 |
} |
|
73 |
case ContactId: |
|
74 |
{ |
|
75 |
value = item->data(ContactId); |
|
76 |
break; |
|
77 |
} |
|
78 |
case ConvergedMsgId: |
|
79 |
{ |
|
80 |
value = item->data(ConvergedMsgId); |
|
81 |
break; |
|
82 |
} |
|
83 |
case UnreadCount: |
|
84 |
{ |
|
85 |
value = item->data(UnreadCount); |
|
86 |
break; |
|
87 |
} |
|
88 |
case TimeStamp: |
|
89 |
{ |
|
90 |
value = item->data(TimeStamp); |
|
91 |
break; |
|
92 |
} |
|
93 |
case SendingState: |
|
94 |
{ |
|
95 |
value = item->data(SendingState); |
|
96 |
break; |
|
97 |
} |
|
98 |
case MessageProperty: |
|
99 |
{ |
|
100 |
value = item->data(MessageProperty); |
|
101 |
break; |
|
102 |
} |
|
103 |
case MessageType: |
|
104 |
{ |
|
105 |
value = item->data(MessageType); |
|
106 |
break; |
|
107 |
} |
|
108 |
case MessageSubType: |
|
109 |
{ |
|
110 |
value = item->data(MessageSubType); |
|
111 |
break; |
|
112 |
} |
|
113 |
case Subject: |
|
114 |
{ |
|
115 |
value = item->data(Subject); |
|
116 |
break; |
|
117 |
} |
|
118 |
case BodyText: |
|
119 |
{ |
|
120 |
value = item->data(BodyText); |
|
121 |
break; |
|
122 |
} |
|
123 |
case ConversationAddress: |
|
124 |
{ |
|
125 |
value = item->data(ConversationAddress); |
|
126 |
break; |
|
127 |
} |
|
128 |
case DisplayName: |
|
129 |
{ |
|
130 |
value = item->data(DisplayName); |
|
131 |
break; |
|
132 |
} |
|
133 |
case Avatar: |
|
134 |
{ |
|
135 |
value = item->data(Avatar); |
|
136 |
break; |
|
137 |
} |
|
138 |
case Direction: |
|
139 |
{ |
|
140 |
value = item->data(Direction); |
|
141 |
break; |
|
142 |
} |
|
143 |
default: |
|
144 |
{ |
|
145 |
//No matching role found, set invalid variant. |
|
146 |
value = QVariant(); |
|
147 |
break; |
|
148 |
} |
|
149 |
} |
|
150 |
return value; |
|
151 |
} |
|
152 |
||
153 |
||
154 |
//--------------------------------------------------------------- |
|
155 |
// ConversationsSummaryModel::addRow |
|
156 |
// @see header |
|
157 |
//--------------------------------------------------------------- |
|
158 |
void ConversationsSummaryModel::addRow( |
|
159 |
const CCsClientConversation& conversation) |
|
160 |
{ |
|
161 |
int convId = conversation.GetConversationEntryId(); |
|
162 |
||
163 |
//match convId in model, if found update else add item |
|
164 |
QModelIndexList indexList = this->match(index(0, 0), |
|
165 |
ConversationId, |
|
166 |
convId, 1, Qt::MatchExactly); |
|
167 |
||
168 |
// if not found, add new item |
|
169 |
if ( indexList.count() == 0 ) |
|
170 |
{ |
|
171 |
QStandardItem* item = new QStandardItem(); |
|
172 |
populateItem(*item,conversation); |
|
173 |
appendRow(item); |
|
174 |
} |
|
175 |
else |
|
176 |
{ |
|
177 |
// Update an existing item |
|
178 |
QModelIndex index = indexList[0]; |
|
179 |
QStandardItem* item = this->item(index.row(), 0); |
|
180 |
populateItem(*item,conversation); |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
//--------------------------------------------------------------- |
|
185 |
// ConversationsSummaryModel::deleteRow |
|
186 |
// @see header |
|
187 |
//--------------------------------------------------------------- |
|
188 |
void ConversationsSummaryModel::deleteRow(qint64 convId) |
|
189 |
{ |
|
190 |
//match, if found remove item |
|
191 |
QModelIndexList indexList = this->match(index(0, 0), |
|
192 |
ConversationId, |
|
193 |
convId, 1, Qt::MatchExactly); |
|
194 |
||
195 |
if( indexList.count() == 1 ) |
|
196 |
{ |
|
197 |
QModelIndex index = indexList[0]; |
|
198 |
this->removeRow(index.row()); |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
//--------------------------------------------------------------- |
|
203 |
// ConversationsSummaryModel::populateItem |
|
204 |
// @see header |
|
205 |
//--------------------------------------------------------------- |
|
206 |
void ConversationsSummaryModel::populateItem(QStandardItem& item, |
|
207 |
const CCsClientConversation& conversation) |
|
208 |
{ |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
209 |
QCRITICAL_WRITE("ConversationsSummaryModel::populateItem start."); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
210 |
|
31 | 211 |
//get entry |
212 |
CCsConversationEntry* conEntry = conversation.GetConversationEntry(); |
|
213 |
//error scenario |
|
214 |
if(conEntry == NULL) |
|
215 |
return; |
|
216 |
||
217 |
// message details |
|
218 |
// conversation-id |
|
219 |
item.setData(conversation.GetConversationEntryId(), ConversationId); |
|
220 |
// message-id |
|
221 |
item.setData(conEntry->EntryId(), ConvergedMsgId); |
|
222 |
// send status |
|
223 |
item.setData(conEntry->GetSendState(),SendingState); |
|
224 |
// direction |
|
225 |
item.setData(conEntry->ConversationDir(), Direction); |
|
226 |
//msg-type |
|
227 |
int msgType = ConversationsEngineUtility::messageType(conEntry->GetType()); |
|
228 |
item.setData(msgType, MessageType); |
|
229 |
//message sub-type |
|
230 |
item.setData(ConversationsEngineUtility::messageSubType(conEntry->GetType()), MessageSubType); |
|
231 |
||
232 |
//handle BT messages, needs to be revisited again, once vcal/vcard over BT issue is fixed |
|
233 |
if(ConvergedMessage::BT == msgType) |
|
234 |
{ |
|
235 |
handleBlueToothMessages(item, *conEntry); |
|
236 |
} |
|
237 |
else if(msgType == ConvergedMessage::BioMsg) |
|
238 |
{ |
|
239 |
handleBioMessages(item, *conEntry); |
|
240 |
} |
|
241 |
else |
|
242 |
{ |
|
243 |
// description |
|
244 |
HBufC* body = conEntry->Description(); |
|
245 |
if( body && body->Length()) |
|
246 |
{ |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
247 |
QString bodytext(XQConversions::s60DescToQString(*body)); |
31 | 248 |
item.setData(bodytext, BodyText); |
249 |
item.setData(bodytext, Subject ); |
|
250 |
} |
|
251 |
} |
|
252 |
||
253 |
||
254 |
// time stamp |
|
255 |
TTime unixEpoch(KUnixEpoch); |
|
256 |
TTimeIntervalSeconds seconds; |
|
257 |
TTime timeStamp(conEntry->TimeStamp() ); |
|
258 |
timeStamp.SecondsFrom(unixEpoch, seconds); |
|
259 |
item.setData(seconds.Int(), TimeStamp); |
|
260 |
||
261 |
// unread count |
|
262 |
item.setData(conversation.GetUnreadMessageCount(), UnreadCount); |
|
263 |
||
264 |
// contact details |
|
265 |
HBufC* disName = conversation.GetDisplayName(); |
|
266 |
QString displayName(""); |
|
267 |
//display name |
|
268 |
if(disName && disName->Length()) |
|
269 |
{ |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
270 |
displayName = XQConversions::s60DescToQString(*disName); |
31 | 271 |
item.setData(displayName,DisplayName); |
272 |
} |
|
273 |
||
274 |
// contact number |
|
275 |
HBufC* contactno = conEntry->Contact(); |
|
276 |
QString contactNumber(""); |
|
277 |
if ( contactno && contactno->Length() ) |
|
278 |
{ |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
279 |
contactNumber = XQConversions::s60DescToQString(*contactno); |
31 | 280 |
} |
281 |
item.setData(contactNumber, ConversationAddress); |
|
282 |
||
283 |
//set the contactId |
|
284 |
int contactId = conversation.GetContactId(); |
|
285 |
item.setData(contactId, ContactId); |
|
286 |
||
287 |
// unread status |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
288 |
item.setData(conEntry->IsAttributeSet(ECsAttributeUnread),UnReadStatus); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
289 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
290 |
QCRITICAL_WRITE("ConversationsSummaryModel::populateItem start."); |
31 | 291 |
} |
292 |
||
293 |
||
294 |
//--------------------------------------------------------------- |
|
295 |
// ConversationsModel::handleBlueToothMessages |
|
296 |
// @see header |
|
297 |
//--------------------------------------------------------------- |
|
298 |
void ConversationsSummaryModel::handleBlueToothMessages(QStandardItem& item, |
|
299 |
const CCsConversationEntry& entry) |
|
300 |
{ |
|
301 |
//TODO, needs to be revisited again, once BT team provides the solution for |
|
302 |
//BT received as Biomsg issue. |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
303 |
QString description = XQConversions::s60DescToQString(*(entry.Description())); |
31 | 304 |
|
305 |
if (description.contains(".vcf") || description.contains(".ics")) // "vCard" |
|
306 |
{ |
|
307 |
//message sub-type |
|
308 |
item.setData(ConvergedMessage::VCard, MessageSubType); |
|
309 |
||
310 |
//parse vcf file to get the details |
|
311 |
QString displayName = MsgContactHandler::getVCardDisplayName( |
|
312 |
description); |
|
313 |
item.setData(displayName, BodyText); |
|
314 |
} |
|
315 |
else |
|
316 |
{ |
|
317 |
if (description.contains(".vcs")) // "vCalendar" |
|
318 |
{ |
|
319 |
//message sub-type |
|
320 |
item.setData(ConvergedMessage::VCal, MessageSubType); |
|
321 |
} |
|
322 |
else |
|
323 |
{ |
|
324 |
//message sub-type |
|
325 |
item.setData(ConvergedMessage::None, MessageSubType); |
|
326 |
} |
|
327 |
//for BT messages we show filenames for all other (except vcard) messages |
|
328 |
//get filename and set as body |
|
329 |
QFileInfo fileinfo(description); |
|
330 |
QString filename = fileinfo.fileName(); |
|
331 |
item.setData(filename, BodyText); |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
//--------------------------------------------------------------- |
|
336 |
// ConversationsSummaryModel::handleBioMessages |
|
337 |
// @see header |
|
338 |
//--------------------------------------------------------------- |
|
339 |
void ConversationsSummaryModel::handleBioMessages(QStandardItem& item, const CCsConversationEntry& entry) |
|
340 |
{ |
|
341 |
UniDataModelLoader* pluginLoader = new UniDataModelLoader; |
|
342 |
UniDataModelPluginInterface* bioMsgPlugin = pluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg); |
|
343 |
bioMsgPlugin->setMessageId(entry.EntryId()); |
|
344 |
||
345 |
int msgSubType = ConversationsEngineUtility::messageSubType(entry.GetType()); |
|
346 |
if (ConvergedMessage::VCard == msgSubType) { |
|
347 |
if (bioMsgPlugin->attachmentCount() > 0) { |
|
348 |
UniMessageInfoList attList = bioMsgPlugin->attachmentList(); |
|
349 |
QString attachmentPath = attList[0]->path(); |
|
350 |
||
351 |
//get display-name and set as bodytext |
|
352 |
QString displayName = MsgContactHandler::getVCardDisplayName( |
|
353 |
attachmentPath); |
|
354 |
item.setData(displayName, BodyText); |
|
355 |
||
356 |
// clear attachement list : its allocated at data model |
|
357 |
while (!attList.isEmpty()) { |
|
358 |
delete attList.takeFirst(); |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
else if (ConvergedMessage::VCal == msgSubType) { |
|
363 |
//not supported |
|
364 |
} |
|
365 |
else if (ConvergedMessage::RingingTone == msgSubType) { |
|
366 |
if (bioMsgPlugin->attachmentCount() > 0) { |
|
367 |
UniMessageInfoList attList = bioMsgPlugin->attachmentList(); |
|
368 |
QString attachmentPath = attList[0]->path(); |
|
369 |
||
370 |
//get tone title, and set as bodytext |
|
371 |
RingBc ringBc; |
|
372 |
item.setData(ringBc.toneTitle(attachmentPath), BodyText); |
|
373 |
while (!attList.isEmpty()) { |
|
374 |
delete attList.takeFirst(); |
|
375 |
} |
|
376 |
} |
|
377 |
} |
|
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
378 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
379 |
else if(ConvergedMessage::NokiaService == msgSubType){ |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
380 |
// This is a bio message so lets parse it and see if it has a associated attachment .. |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
381 |
if (bioMsgPlugin->attachmentCount() > 0) { |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
382 |
// TODO : need to confirm if we need to read from attachment |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
383 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
384 |
else {// description |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
385 |
HBufC* description = entry.Description(); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
386 |
QString subject(""); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
387 |
if (description && description->Length()) { |
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
388 |
subject = (XQConversions::s60DescToQString(*description)); |
34
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
389 |
item.setData(subject, BodyText); |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
390 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
391 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
392 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
393 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
394 |
} |
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
395 |
|
84197e66a4bd
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
396 |
else { |
31 | 397 |
// description |
398 |
HBufC* description = entry.Description(); |
|
399 |
QString subject(""); |
|
400 |
if (description && description->Length()) { |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
401 |
subject = (XQConversions::s60DescToQString(*description)); |
31 | 402 |
item.setData(subject, BodyText); |
403 |
} |
|
404 |
} |
|
405 |
||
406 |
delete pluginLoader; |
|
407 |
} |
|
408 |
// EOF |