17 |
17 |
18 // SYSTEM INCLUDES |
18 // SYSTEM INCLUDES |
19 #include "msglistviewitem.h" |
19 #include "msglistviewitem.h" |
20 |
20 |
21 #include <QDateTime> |
21 #include <QDateTime> |
|
22 #include <QFileInfo> |
22 #include <hbframeitem.h> |
23 #include <hbframeitem.h> |
23 #include <hbframedrawer.h> |
24 #include <hbframedrawer.h> |
24 #include <HbTextItem> |
25 #include <HbTextItem> |
25 #include <HbFrameItem> |
26 #include <HbFrameItem> |
|
27 #include <HbIconItem> |
26 |
28 |
27 #include "msgcommondefines.h" |
29 #include "msgcommondefines.h" |
28 #include "conversationsengine.h" |
30 #include "conversationsengine.h" |
29 #include "conversationsenginedefines.h" |
31 #include "conversationsenginedefines.h" |
30 #include "msgutils.h" |
32 #include "msgutils.h" |
31 #include "convergedmessage.h" |
33 #include "convergedmessage.h" |
32 #include "debugtraces.h" |
34 #include "debugtraces.h" |
33 |
35 |
34 #define NEW_ITEM_FRAME ":/newitem/qtg_fr_list_new_item" |
|
35 #define LOC_RINGING_TONE hbTrId("txt_messaging_dpopinfo_ringing_tone") |
36 #define LOC_RINGING_TONE hbTrId("txt_messaging_dpopinfo_ringing_tone") |
36 |
37 #define LOC_MSG_SEND_FAILED hbTrId("txt_messaging_list_message_sending_failed") |
|
38 #define LOC_MSG_OUTGOING hbTrId("txt_messaging_list_outgoing_message") |
|
39 #define LOC_MSG_RESEND_AT hbTrId("Resend at ") |
|
40 #define LOC_BUSINESS_CARD hbTrId("txt_messaging_list_business_card") |
|
41 #define LOC_CALENDAR_EVENT hbTrId("txt_messaging_list_calendar_event") |
|
42 #define LOC_UNSUPPORTED_MSG_TYPE hbTrId("txt_messaging_list_unsupported_message_type") |
|
43 #define LOC_RECEIVED_FILES hbTrId("txt_messaging_list_received_files") |
|
44 |
|
45 const QString NEW_ITEM_FRAME("qtg_fr_list_new_item"); |
37 const QString LIST_ITEM_BG_FRAME("qtg_fr_list_normal"); |
46 const QString LIST_ITEM_BG_FRAME("qtg_fr_list_normal"); |
|
47 const QString BT_ICON("qtg_large_bluetooth"); |
|
48 const QString MSG_OUTGOING_ICON("qtg_mono_outbox"); |
|
49 const QString MSG_FAILED_ICON("qtg_mono_failed"); |
38 |
50 |
39 //--------------------------------------------------------------- |
51 //--------------------------------------------------------------- |
40 // MsgListViewItem::MsgListViewItem |
52 // MsgListViewItem::MsgListViewItem |
41 // Constructor |
53 // Constructor |
42 //--------------------------------------------------------------- |
54 //--------------------------------------------------------------- |
105 |
117 |
106 mBgFrameItem->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME); |
118 mBgFrameItem->frameDrawer().setFrameGraphicsName(LIST_ITEM_BG_FRAME); |
107 mBgFrameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
119 mBgFrameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
108 } |
120 } |
109 |
121 |
110 // Time Stamp. |
122 // Set the message text depending upon the message type |
|
123 int messageType = modelIndex().data(MessageType).toInt(); |
|
124 int messageSubType = modelIndex().data(MessageSubType).toInt(); |
|
125 int messageState = modelIndex().data(SendingState).toInt(); |
|
126 int messageDirection = modelIndex().data(Direction).toInt(); |
|
127 QString prevText; |
|
128 prevText = previewText(messageType, messageSubType, messageState,messageDirection); |
|
129 prevText.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
|
130 prevText.replace('\r', QChar::LineSeparator); |
|
131 mPreviewLabelItem->setText(prevText); |
|
132 |
|
133 // Address label |
|
134 QString contactName; |
|
135 if(messageType == ConvergedMessage::BT) |
|
136 { |
|
137 contactName = LOC_RECEIVED_FILES; |
|
138 } |
|
139 else |
|
140 { |
|
141 QString displayName = modelIndex().data(DisplayName).toString(); |
|
142 QString contactAddress = modelIndex().data(ConversationAddress).toString(); |
|
143 |
|
144 if (displayName.isEmpty()) |
|
145 { |
|
146 contactName.append(contactAddress); |
|
147 } |
|
148 else |
|
149 { |
|
150 contactName.append(displayName); |
|
151 } |
|
152 } |
|
153 mAddressLabelItem->setText(contactName); |
|
154 |
|
155 // Unread message count |
|
156 int unreadCount = modelIndex().data(UnreadCount).toInt(); |
|
157 |
|
158 if (unreadCount > 0) |
|
159 { |
|
160 QString unRead(tr("(%n)", "", unreadCount)); |
|
161 mUnreadCountItem->setText(unRead); |
|
162 mUnReadMsg = true; |
|
163 mNewMsgIndicatorItem->frameDrawer().setFrameGraphicsName(NEW_ITEM_FRAME); |
|
164 } |
|
165 else |
|
166 { |
|
167 mUnreadCountItem->setText(QString()); |
|
168 mNewMsgIndicatorItem->frameDrawer().setFrameGraphicsName(QString()); |
|
169 mUnReadMsg = false; |
|
170 repolish(); |
|
171 } |
|
172 |
|
173 HbListViewItem::updateChildItems(); |
|
174 } |
|
175 |
|
176 //--------------------------------------------------------------- |
|
177 // MsgListViewItem::previewText |
|
178 // @see header |
|
179 //--------------------------------------------------------------- |
|
180 QString MsgListViewItem::previewText(int msgType, |
|
181 int msgSubType, |
|
182 int msgState, |
|
183 int msgDirection) |
|
184 { |
|
185 QString bodyText(modelIndex().data(BodyText).toString()); |
|
186 QString previewText; |
|
187 // Set the message text & icons, depending upon the message type |
|
188 if (msgType == ConvergedMessage::BioMsg) { |
|
189 if (msgSubType == ConvergedMessage::RingingTone) { |
|
190 previewText = LOC_RINGING_TONE; |
|
191 } |
|
192 else if (msgSubType == ConvergedMessage::VCard) { |
|
193 previewText = LOC_BUSINESS_CARD; |
|
194 previewText.append(QChar::LineSeparator); |
|
195 previewText.append(bodyText); |
|
196 } |
|
197 else { |
|
198 previewText = LOC_UNSUPPORTED_MSG_TYPE; |
|
199 } |
|
200 } |
|
201 else if (msgType == ConvergedMessage::BT) { |
|
202 |
|
203 if (msgSubType == ConvergedMessage::VCard) { |
|
204 previewText = LOC_BUSINESS_CARD; |
|
205 previewText.append(QChar::LineSeparator); |
|
206 previewText.append(bodyText); |
|
207 } |
|
208 else { |
|
209 previewText = bodyText; |
|
210 } |
|
211 if (!mPresenceIndicatorItem) { |
|
212 mPresenceIndicatorItem = new HbIconItem(this); |
|
213 HbStyle::setItemName(mPresenceIndicatorItem, "presenceIndicator"); |
|
214 mPresenceIndicatorItem->setIconName(BT_ICON); |
|
215 } |
|
216 } |
|
217 else { |
|
218 previewText = textBySendState(msgState,msgDirection); |
|
219 } |
|
220 return previewText; |
|
221 } |
|
222 |
|
223 |
|
224 //--------------------------------------------------------------- |
|
225 // MsgListViewItem::textBySendState |
|
226 // @see header |
|
227 //--------------------------------------------------------------- |
|
228 QString MsgListViewItem::textBySendState(int sendState,int msgDirection) |
|
229 { |
|
230 QString previewText; |
111 QDateTime dateTime; |
231 QDateTime dateTime; |
112 dateTime.setTime_t(modelIndex().data(TimeStamp).toUInt()); |
232 dateTime.setTime_t(modelIndex().data(TimeStamp).toUInt()); |
113 QString dateString; |
233 QString dateString; |
114 if (dateTime.date() == QDateTime::currentDateTime().date()) |
234 if (dateTime.date() == QDateTime::currentDateTime().date()) { |
115 { |
|
116 dateString = MsgUtils::dateTimeToString(dateTime, TIME_FORMAT); |
235 dateString = MsgUtils::dateTimeToString(dateTime, TIME_FORMAT); |
117 } |
236 } |
|
237 else { |
|
238 dateString = MsgUtils::dateTimeToString(dateTime, DATE_FORMAT); |
|
239 } |
|
240 |
|
241 if (msgDirection == ConvergedMessage::Outgoing) |
|
242 { |
|
243 switch (sendState) |
|
244 { |
|
245 case ConvergedMessage::Resend: |
|
246 { |
|
247 |
|
248 QString resendString = LOC_MSG_RESEND_AT + dateString; |
|
249 previewText = resendString; |
|
250 dateString = QString(""); |
|
251 if (!mPresenceIndicatorItem) |
|
252 { |
|
253 mPresenceIndicatorItem = new HbIconItem(this); |
|
254 } |
|
255 HbStyle::setItemName(mPresenceIndicatorItem, |
|
256 "presenceIndicator"); |
|
257 mPresenceIndicatorItem->setIconName(MSG_OUTGOING_ICON); |
|
258 mPresenceIndicatorItem->setVisible(true); |
|
259 break; |
|
260 } |
|
261 |
|
262 case ConvergedMessage::Sending: |
|
263 case ConvergedMessage::Suspended: |
|
264 case ConvergedMessage::Scheduled: |
|
265 case ConvergedMessage::Waiting: |
|
266 { |
|
267 previewText = QString(LOC_MSG_OUTGOING); |
|
268 if (!mPresenceIndicatorItem) |
|
269 { |
|
270 mPresenceIndicatorItem = new HbIconItem(this); |
|
271 } |
|
272 HbStyle::setItemName(mPresenceIndicatorItem, |
|
273 "presenceIndicator"); |
|
274 mPresenceIndicatorItem->setIconName(MSG_OUTGOING_ICON); |
|
275 mPresenceIndicatorItem->setVisible(true); |
|
276 break; |
|
277 } |
|
278 case ConvergedMessage::Failed: |
|
279 { |
|
280 previewText = QString(LOC_MSG_SEND_FAILED); |
|
281 if (!mPresenceIndicatorItem) |
|
282 { |
|
283 mPresenceIndicatorItem = new HbIconItem(this); |
|
284 } |
|
285 HbStyle::setItemName(mPresenceIndicatorItem, |
|
286 "presenceIndicator"); |
|
287 mPresenceIndicatorItem->setIconName(MSG_FAILED_ICON); |
|
288 mPresenceIndicatorItem->setVisible(true); |
|
289 break; |
|
290 } |
|
291 default: |
|
292 QString postFix = QString(""); |
|
293 previewText = modelIndex().data(BodyText).toString(); |
|
294 previewText += (QChar(QChar::LineSeparator) + postFix); |
|
295 |
|
296 if (!mPresenceIndicatorItem) |
|
297 { |
|
298 mPresenceIndicatorItem = new HbIconItem(this); |
|
299 } |
|
300 |
|
301 HbStyle::setItemName(mPresenceIndicatorItem, |
|
302 "presenceIndicator"); |
|
303 mPresenceIndicatorItem->setIconName(MSG_FAILED_ICON); |
|
304 mPresenceIndicatorItem->setVisible(false); |
|
305 |
|
306 break; |
|
307 } |
|
308 } |
118 else |
309 else |
119 { |
310 { |
120 dateString = MsgUtils::dateTimeToString(dateTime, DATE_FORMAT); |
311 previewText = modelIndex().data(BodyText).toString(); |
121 } |
312 } |
122 |
|
123 mTimestampItem->setText(dateString); |
313 mTimestampItem->setText(dateString); |
124 |
314 return previewText; |
125 //Sender |
|
126 QString firstName = modelIndex().data(FirstName).toString(); |
|
127 QString lastName = modelIndex().data(LastName).toString(); |
|
128 QString nickName = modelIndex().data(NickName).toString(); |
|
129 QString contactAddress = modelIndex().data(ConversationAddress).toString(); |
|
130 QString contactName; |
|
131 |
|
132 if (!nickName.isEmpty()) |
|
133 { |
|
134 contactName.append(nickName); |
|
135 } |
|
136 else if (firstName.isEmpty() && lastName.isEmpty()) |
|
137 { |
|
138 contactName.append(contactAddress); |
|
139 } |
|
140 else if (lastName.isEmpty()) |
|
141 { |
|
142 contactName.append(firstName); |
|
143 } |
|
144 else if (firstName.isEmpty()) |
|
145 { |
|
146 contactName.append(lastName); |
|
147 } |
|
148 else |
|
149 { |
|
150 // If both first Name and last name are present |
|
151 contactName.append(firstName); |
|
152 contactName.append(" "); |
|
153 contactName.append(lastName); |
|
154 } |
|
155 mAddressLabelItem->setText(contactName); |
|
156 |
|
157 // Latest Message |
|
158 int messageType = modelIndex().data(MessageType).toInt(); |
|
159 QString previewText; |
|
160 // Set the message text depending upon the message type |
|
161 if (messageType == ConvergedMessage::Mms) |
|
162 { |
|
163 QDEBUG_WRITE("MsgListViewItem::updateChildItems Mms block") |
|
164 previewText = modelIndex().data(Subject).toString(); |
|
165 } |
|
166 else if(messageType == ConvergedMessage::RingingTone) |
|
167 { |
|
168 QDEBUG_WRITE("MsgListViewItem::updateChildItems RingingTone block") |
|
169 previewText = LOC_RINGING_TONE; |
|
170 } |
|
171 else if (messageType == ConvergedMessage::VCard) |
|
172 { |
|
173 previewText = QString("Business Card"); |
|
174 } |
|
175 else if (messageType == ConvergedMessage::VCal) |
|
176 { |
|
177 previewText = QString("Calender Event"); |
|
178 } |
|
179 else if(messageType == ConvergedMessage::BioMsg) |
|
180 { |
|
181 previewText = QString("Unsupported Type"); |
|
182 } |
|
183 else |
|
184 { |
|
185 QDEBUG_WRITE("MsgListViewItem::updateChildItems default block") |
|
186 previewText = modelIndex().data(BodyText).toString(); |
|
187 } |
|
188 mPreviewLabelItem->setText(previewText); |
|
189 |
|
190 // Unread message count |
|
191 int unreadCount = modelIndex().data(UnreadCount).toInt(); |
|
192 QString unRead; |
|
193 if (unreadCount > 0) |
|
194 { |
|
195 unRead.append(tr("(%n)", "", unreadCount)); |
|
196 mUnreadCountItem->setText(unRead); |
|
197 mUnReadMsg = true; |
|
198 mNewMsgIndicatorItem->frameDrawer().setFrameGraphicsName(NEW_ITEM_FRAME); |
|
199 } |
|
200 else |
|
201 { |
|
202 mUnreadCountItem->setText(""); |
|
203 mNewMsgIndicatorItem->frameDrawer().setFrameGraphicsName(QString()); |
|
204 mUnReadMsg = false; |
|
205 repolish(); |
|
206 } |
|
207 |
|
208 HbListViewItem::updateChildItems(); |
|
209 } |
315 } |
210 |
316 |
211 //--------------------------------------------------------------- |
317 //--------------------------------------------------------------- |
212 // MsgListViewItem::paint. |
318 // MsgListViewItem::paint. |
213 // @see header |
319 // @see header |