|
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 "msgconversationviewitem.h" |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <QDateTime> |
|
22 #include "debugtraces.h" |
|
23 #include <QDir> |
|
24 #include <QChar> |
|
25 #include <HbTextItem> |
|
26 #include <HbIconItem> |
|
27 #include <HbIconAnimationManager> |
|
28 #include <HbIconAnimator> |
|
29 #include <ccsdefs.h> |
|
30 |
|
31 // USER INCLUDES |
|
32 #include "msgconversationwidget.h" |
|
33 #include "msgviewdefines.h" |
|
34 #include "msgviewutils.h" |
|
35 #include "convergedmessage.h" |
|
36 #include "conversationsenginedefines.h" |
|
37 |
|
38 // LOCAL CONSTANTS |
|
39 const QString MSG_OUTBOX_ICON("qtg_small_outbox"); |
|
40 const QString MSG_FAIL_ICON("qtg_small_fail"); |
|
41 const QString ANIMATION_FILE(":/qtg_anim_loading.axml"); |
|
42 const QString ANIMATION_ICON_NAME("qtg_anim_loading"); |
|
43 const QString VCARD_ICON("qtg_large_mycard"); |
|
44 |
|
45 // LOCALIZATION |
|
46 #define LOC_RINGING_TONE hbTrId("txt_messaging_dpopinfo_ringing_tone") |
|
47 #define LOC_BUSINESS_CARD hbTrId("txt_messaging_list_business_card") |
|
48 #define LOC_CALENDAR_EVENT hbTrId("txt_messaging_list_calendar_event") |
|
49 #define LOC_UNSUPPORTED_MSG_TYPE hbTrId("txt_messaging_list_listview_unsupported_message_type") |
|
50 #define LOC_RESEND_AT hbTrId("Resend at ") |
|
51 |
|
52 //--------------------------------------------------------------- |
|
53 // MsgConversationViewItem::MsgConversationViewItem |
|
54 // Constructor |
|
55 //--------------------------------------------------------------- |
|
56 MsgConversationViewItem::MsgConversationViewItem(QGraphicsItem* parent) : |
|
57 HbListViewItem(parent), mIncoming(false), mConversation(0), |
|
58 mMessageStateIconItem(0) |
|
59 { |
|
60 } |
|
61 |
|
62 //--------------------------------------------------------------- |
|
63 // MsgConversationViewItem::MsgConversationViewItem |
|
64 // Destructor |
|
65 //--------------------------------------------------------------- |
|
66 MsgConversationViewItem::~MsgConversationViewItem() |
|
67 { |
|
68 } |
|
69 |
|
70 //--------------------------------------------------------------- |
|
71 // MsgConversationViewItem::createItem |
|
72 // Create a new decorator item. |
|
73 //--------------------------------------------------------------- |
|
74 MsgConversationViewItem* MsgConversationViewItem::createItem() |
|
75 { |
|
76 return new MsgConversationViewItem(*this); |
|
77 } |
|
78 |
|
79 //--------------------------------------------------------------- |
|
80 // MsgConversationViewItem::updateChildItems |
|
81 // |
|
82 //--------------------------------------------------------------- |
|
83 void MsgConversationViewItem::updateChildItems() |
|
84 { |
|
85 |
|
86 if (!mMessageStateIconItem) |
|
87 { |
|
88 mMessageStateIconItem = new HbIconItem(this); |
|
89 HbStyle::setItemName(mMessageStateIconItem, "msgStateIcon"); |
|
90 } |
|
91 |
|
92 QModelIndex index = modelIndex(); |
|
93 |
|
94 #ifdef _DEBUG_TRACES_ |
|
95 qCritical() << "START MsgConversationViewItem::updateChildItems: " |
|
96 << index.data(ConvergedMsgId).toInt(); |
|
97 #endif |
|
98 |
|
99 int messageType = index.data(MessageType).toInt(); |
|
100 int messageSubType = index.data(MessageSubType).toInt(); |
|
101 |
|
102 |
|
103 if (messageType == ConvergedMessage::Sms) |
|
104 { |
|
105 updateSmsTypeItem(index); |
|
106 } |
|
107 else if (messageType == ConvergedMessage::Mms || messageType |
|
108 == ConvergedMessage::MmsNotification || messageType |
|
109 == ConvergedMessage::BT) |
|
110 { |
|
111 updateMmsTypeItem(index, messageType, messageSubType); |
|
112 } |
|
113 else if (messageType == ConvergedMessage::BioMsg) |
|
114 { |
|
115 if (messageSubType == ConvergedMessage::VCard || messageSubType |
|
116 == ConvergedMessage::RingingTone) |
|
117 { |
|
118 updateMmsTypeItem(index, messageType, messageSubType); |
|
119 } |
|
120 else |
|
121 { |
|
122 updateSmsTypeItem(index, messageSubType); |
|
123 } |
|
124 } |
|
125 |
|
126 #ifdef _DEBUG_TRACES_ |
|
127 qCritical() << "END MsgConversationViewItem::updateChildItems: " |
|
128 << index.data(ConvergedMsgId).toInt(); |
|
129 #endif |
|
130 |
|
131 repolish(); |
|
132 HbListViewItem::updateChildItems(); |
|
133 } |
|
134 |
|
135 //--------------------------------------------------------------- |
|
136 // MsgConversationViewItem::updateSmsTypeItem |
|
137 // @see header file |
|
138 //--------------------------------------------------------------- |
|
139 void MsgConversationViewItem::updateSmsTypeItem(const QModelIndex& index, int messageSubType) |
|
140 { |
|
141 |
|
142 if (!mConversation) |
|
143 { |
|
144 mConversation = new MsgConversationWidget(this); |
|
145 HbStyle::setItemName(mConversation, "msgconvwidget"); |
|
146 } |
|
147 mIncoming = false; |
|
148 mConversation->resetProperties(); |
|
149 |
|
150 int direction = index.data(Direction).toInt(); |
|
151 |
|
152 if (direction == ConvergedMessage::Incoming) |
|
153 { |
|
154 setIncoming(true); |
|
155 mConversation->setIncoming(true); |
|
156 |
|
157 mMessageStateIconItem->setVisible(false); |
|
158 } |
|
159 else if (direction == ConvergedMessage::Outgoing) |
|
160 { |
|
161 setIncoming(false); |
|
162 mConversation->setIncoming(false); |
|
163 |
|
164 int sendingState = index.data(SendingState).toInt(); |
|
165 mConversation->setSendingState(sendingState); |
|
166 setMessageStateIcon(sendingState); |
|
167 } |
|
168 |
|
169 bool unreadStatus = index.data(UnReadStatus).toBool(); |
|
170 mConversation->setUnread(unreadStatus); |
|
171 |
|
172 mConversation->drawBubbleFrame(); |
|
173 mConversation->drawNewItemFrame(); |
|
174 |
|
175 QDateTime dateTime; |
|
176 dateTime.setTime_t(index.data(TimeStamp).toUInt()); |
|
177 QString resendStateNote((index.data(SendingState).toInt() |
|
178 == ConvergedMessage::Resend) ? LOC_RESEND_AT : ""); |
|
179 if (dateTime.date() == QDateTime::currentDateTime().date()) |
|
180 { |
|
181 |
|
182 mConversation->setTimeStamp(resendStateNote + dateTime.toString( |
|
183 TIME_FORMAT)); |
|
184 } |
|
185 else |
|
186 { |
|
187 mConversation->setTimeStamp(resendStateNote + dateTime.toString( |
|
188 DATE_FORMAT)); |
|
189 } |
|
190 |
|
191 if (messageSubType == ConvergedMessage::VCal) |
|
192 { |
|
193 mConversation->setSubject(LOC_UNSUPPORTED_MSG_TYPE); |
|
194 } |
|
195 else |
|
196 { |
|
197 QString bodyText = index.data(BodyText).toString(); |
|
198 bodyText.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
|
199 bodyText.replace('\r', QChar::LineSeparator); |
|
200 mConversation->setSubject(bodyText); |
|
201 } |
|
202 |
|
203 //repolish |
|
204 mConversation->repolishWidget(); |
|
205 } |
|
206 |
|
207 //--------------------------------------------------------------- |
|
208 // MsgConversationViewItem::updateMmsTypeItem |
|
209 // @see header file |
|
210 //--------------------------------------------------------------- |
|
211 void MsgConversationViewItem::updateMmsTypeItem(const QModelIndex& index, |
|
212 int messageType, int messageSubType) |
|
213 { |
|
214 // create widget |
|
215 if (!mConversation) |
|
216 { |
|
217 mConversation = new MsgConversationWidget(this); |
|
218 HbStyle::setItemName(mConversation, "msgconvwidget"); |
|
219 } |
|
220 mIncoming = false; |
|
221 mConversation->resetProperties(); |
|
222 |
|
223 mConversation->setMMS(true); |
|
224 int direction = index.data(Direction).toInt(); |
|
225 QString bodyText = index.data(BodyText).toString(); |
|
226 |
|
227 if (direction == ConvergedMessage::Incoming) |
|
228 { |
|
229 setIncoming(true); |
|
230 mConversation->setIncoming(true); |
|
231 |
|
232 if (messageType == ConvergedMessage::MmsNotification) |
|
233 { |
|
234 mConversation->setMMSNotification(true); |
|
235 int notificationState = index.data(NotificationStatus).toInt(); |
|
236 mConversation->setNotificationState(notificationState); |
|
237 setNotificationStateIcon(notificationState); |
|
238 } |
|
239 else |
|
240 { |
|
241 mMessageStateIconItem->setVisible(false); |
|
242 } |
|
243 } |
|
244 else if (direction == ConvergedMessage::Outgoing) |
|
245 { |
|
246 setIncoming(false); |
|
247 mConversation->setIncoming(false); |
|
248 |
|
249 int sendingState = index.data(SendingState).toInt(); |
|
250 mConversation->setSendingState(sendingState); |
|
251 setMessageStateIcon(sendingState); |
|
252 } |
|
253 |
|
254 bool unreadStatus = index.data(UnReadStatus).toBool(); |
|
255 mConversation->setUnread(unreadStatus); |
|
256 |
|
257 mConversation->drawBubbleFrame(); |
|
258 mConversation->drawNewItemFrame(); |
|
259 |
|
260 QDateTime dateTime; |
|
261 dateTime.setTime_t(index.data(TimeStamp).toUInt()); |
|
262 QString resendStateNote((index.data(SendingState).toInt() |
|
263 == ConvergedMessage::Resend) ? LOC_RESEND_AT : ""); |
|
264 if (dateTime.date() == QDateTime::currentDateTime().date()) |
|
265 { |
|
266 |
|
267 mConversation->setTimeStamp(resendStateNote + dateTime.toString( |
|
268 TIME_FORMAT)); |
|
269 } |
|
270 else |
|
271 { |
|
272 mConversation->setTimeStamp(resendStateNote + dateTime.toString( |
|
273 DATE_FORMAT)); |
|
274 } |
|
275 |
|
276 if (messageType == ConvergedMessage::Mms) |
|
277 { |
|
278 //preview path |
|
279 QString previewPath = index.data(Attachments).toString(); |
|
280 QString subject = index.data(Subject).toString(); |
|
281 |
|
282 int msgProperty = index.data(MessageProperty).toInt(); |
|
283 bool hasAttachments = (msgProperty & EPreviewAttachment) ? true : false; |
|
284 |
|
285 if (hasAttachments) |
|
286 { |
|
287 mConversation->setAttachment(); |
|
288 } |
|
289 else |
|
290 { |
|
291 mConversation->setAttachment(false); |
|
292 } |
|
293 |
|
294 // Now set the media contents |
|
295 |
|
296 //preview image |
|
297 bool hasImage = (msgProperty & EPreviewImage) ? true : false; |
|
298 |
|
299 if (hasImage) |
|
300 { |
|
301 int msgId = index.data(ConvergedMsgId).toInt(); |
|
302 mConversation->setPreviewIconPath(previewPath, msgId); |
|
303 mConversation->setImage(true); |
|
304 } |
|
305 |
|
306 bool hasVideo = (msgProperty & EPreviewVideo) ? true : false; |
|
307 |
|
308 if (hasVideo) |
|
309 { |
|
310 mConversation->setVideo(true); |
|
311 } |
|
312 |
|
313 bool hasAudio = (msgProperty & EPreviewAudio) ? true : false; |
|
314 if (hasAudio) |
|
315 { |
|
316 mConversation->setAudio(true); |
|
317 } |
|
318 |
|
319 mConversation->displayAudioIcon(); |
|
320 |
|
321 int priority = index.data(MessagePriority).toInt(); |
|
322 mConversation->setPriority(priority); |
|
323 mConversation->setSubject(subject); |
|
324 mConversation->setBodyText(bodyText); |
|
325 } |
|
326 else if (messageType == ConvergedMessage::BioMsg) |
|
327 { |
|
328 if (messageSubType == ConvergedMessage::RingingTone) |
|
329 { |
|
330 mConversation->setImage(false); |
|
331 mConversation->setAudio(true); |
|
332 mConversation->displayAudioIcon(); |
|
333 mConversation->setSubject(LOC_RINGING_TONE); |
|
334 } |
|
335 else if (messageSubType == ConvergedMessage::VCard) |
|
336 { |
|
337 mConversation->setImage(false); |
|
338 mConversation->setAudio(true); |
|
339 mConversation->displayAudioIcon(VCARD_ICON); |
|
340 mConversation->setSubject(LOC_BUSINESS_CARD); |
|
341 mConversation->setBodyText(bodyText); |
|
342 } |
|
343 } |
|
344 else if (messageType == ConvergedMessage::BT) |
|
345 { |
|
346 QString deviceName = index.data(ConversationAddress).toString(); |
|
347 mConversation->setSubject(deviceName); |
|
348 QString blueToothBody; |
|
349 if (messageSubType == ConvergedMessage::VCard) |
|
350 { |
|
351 mConversation->setImage(false); |
|
352 mConversation->setAudio(true); |
|
353 mConversation->displayAudioIcon(VCARD_ICON); |
|
354 blueToothBody.append(LOC_BUSINESS_CARD); |
|
355 blueToothBody.append(QChar::LineSeparator); |
|
356 blueToothBody.append(bodyText); |
|
357 } |
|
358 else |
|
359 { |
|
360 blueToothBody.append(bodyText); |
|
361 } |
|
362 mConversation->setBodyText(blueToothBody); |
|
363 } |
|
364 else if (messageType == ConvergedMessage::MmsNotification) |
|
365 { |
|
366 QString subject = index.data(Subject).toString(); |
|
367 int priority = index.data(MessagePriority).toInt(); |
|
368 mConversation->setPriority(priority); |
|
369 mConversation->setSubject(subject); |
|
370 mConversation->setBodyText(bodyText); |
|
371 } |
|
372 |
|
373 //repolish widget |
|
374 mConversation->repolishWidget(); |
|
375 } |
|
376 |
|
377 //--------------------------------------------------------------- |
|
378 // MsgConversationViewItem::containsPoint |
|
379 // |
|
380 //--------------------------------------------------------------- |
|
381 bool MsgConversationViewItem::containsPoint(const QPointF& point) |
|
382 { |
|
383 return mConversation->boundingRect(). |
|
384 contains(mConversation->mapFromScene(point)); |
|
385 } |
|
386 |
|
387 //--------------------------------------------------------------- |
|
388 // MsgConversationViewItem::setIncoming |
|
389 // @see header file |
|
390 //--------------------------------------------------------------- |
|
391 void MsgConversationViewItem::setIncoming(bool incoming) |
|
392 { |
|
393 mIncoming = incoming; |
|
394 } |
|
395 |
|
396 //--------------------------------------------------------------- |
|
397 // MsgConversationViewItem::isIncoming |
|
398 // @see header file |
|
399 //--------------------------------------------------------------- |
|
400 bool MsgConversationViewItem::isIncoming() |
|
401 { |
|
402 return mIncoming; |
|
403 } |
|
404 |
|
405 //--------------------------------------------------------------- |
|
406 // MsgConversationViewItem::setMessageStateIcon |
|
407 // @see header file |
|
408 //--------------------------------------------------------------- |
|
409 void MsgConversationViewItem::setMessageStateIcon(int messageState) |
|
410 { |
|
411 HbIconAnimator& iconAnimator = mMessageStateIconItem->animator(); |
|
412 HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global(); |
|
413 switch (messageState) |
|
414 { |
|
415 case ConvergedMessage::Waiting: |
|
416 case ConvergedMessage::Scheduled: |
|
417 case ConvergedMessage::Sending: |
|
418 { |
|
419 bool defined = iconAnimationManager->addDefinitionFile(ANIMATION_FILE); |
|
420 HbIcon animIcon; |
|
421 animIcon.setIconName(ANIMATION_ICON_NAME); |
|
422 QSizeF size = mMessageStateIconItem->size(); |
|
423 mMessageStateIconItem->setIcon(animIcon); |
|
424 mMessageStateIconItem->setVisible(true); |
|
425 iconAnimator.startAnimation(); |
|
426 repolish(); |
|
427 break; |
|
428 } |
|
429 case ConvergedMessage::Suspended: |
|
430 { |
|
431 iconAnimator.stopAnimation(); |
|
432 mMessageStateIconItem->setIcon(MSG_OUTBOX_ICON); |
|
433 mMessageStateIconItem->setVisible(true); |
|
434 break; |
|
435 |
|
436 } |
|
437 case ConvergedMessage::Resend: |
|
438 { |
|
439 iconAnimator.stopAnimation(); |
|
440 mMessageStateIconItem->setIcon(MSG_OUTBOX_ICON); |
|
441 mMessageStateIconItem->setVisible(true); |
|
442 break; |
|
443 } |
|
444 case ConvergedMessage::Failed: |
|
445 { |
|
446 iconAnimator.stopAnimation(); |
|
447 mMessageStateIconItem->setIcon(MSG_FAIL_ICON); |
|
448 mMessageStateIconItem->setVisible(true); |
|
449 break; |
|
450 } |
|
451 case ConvergedMessage::Unknown: |
|
452 default: |
|
453 { |
|
454 iconAnimator.stopAnimation(); |
|
455 mMessageStateIconItem->setVisible(false); |
|
456 break; |
|
457 } |
|
458 } |
|
459 } |
|
460 |
|
461 //--------------------------------------------------------------- |
|
462 // MsgConversationViewItem::setNotificationStateIcon |
|
463 // @see header file |
|
464 //--------------------------------------------------------------- |
|
465 |
|
466 void MsgConversationViewItem::setNotificationStateIcon(int notificationState) |
|
467 { |
|
468 HbIconAnimator& iconAnimator = mMessageStateIconItem->animator(); |
|
469 HbIconAnimationManager* iconAnimationManager = HbIconAnimationManager::global(); |
|
470 switch (notificationState) |
|
471 { |
|
472 case ConvergedMessage::NotifRetrieving: |
|
473 case ConvergedMessage::NotifWaiting: |
|
474 { |
|
475 //TODO: Temp icon until official icons are received |
|
476 bool defined = iconAnimationManager->addDefinitionFile(ANIMATION_FILE); |
|
477 HbIcon animIcon; |
|
478 animIcon.setIconName(ANIMATION_ICON_NAME); |
|
479 QSizeF size = mMessageStateIconItem->size(); |
|
480 mMessageStateIconItem->setIcon(animIcon); |
|
481 mMessageStateIconItem->setVisible(true); |
|
482 iconAnimator.startAnimation(); |
|
483 repolish(); |
|
484 break; |
|
485 } |
|
486 default: |
|
487 { |
|
488 iconAnimator.stopAnimation(); |
|
489 mMessageStateIconItem->setVisible(false); |
|
490 break; |
|
491 } |
|
492 } |
|
493 } |
|
494 |
|
495 //--------------------------------------------------------------- |
|
496 // MsgConversationViewItem::pressStateChanged |
|
497 // @see header file |
|
498 //--------------------------------------------------------------- |
|
499 void MsgConversationViewItem::pressStateChanged (bool pressed, bool animate) |
|
500 { |
|
501 mConversation->pressStateChanged(pressed, animate); |
|
502 } |
|
503 |
|
504 // EOF |