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