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: Item decorator of the message list view.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// SYSTEM INCLUDES
|
|
19 |
#include "msglistviewitem.h"
|
|
20 |
|
|
21 |
#include <QDateTime>
|
|
22 |
#include <QFileInfo>
|
|
23 |
#include <hbframeitem.h>
|
|
24 |
#include <hbframedrawer.h>
|
|
25 |
#include <HbTextItem>
|
|
26 |
#include <HbFrameItem>
|
|
27 |
#include <HbIconItem>
|
|
28 |
|
|
29 |
#include "msgcommondefines.h"
|
|
30 |
#include "conversationsengine.h"
|
|
31 |
#include "conversationsenginedefines.h"
|
|
32 |
#include "msgutils.h"
|
|
33 |
#include "convergedmessage.h"
|
|
34 |
#include "debugtraces.h"
|
|
35 |
|
|
36 |
#define LOC_RINGING_TONE hbTrId("txt_messaging_dpopinfo_ringing_tone")
|
|
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");
|
|
46 |
const QString BT_ICON("qtg_large_bluetooth");
|
|
47 |
const QString MSG_OUTGOING_ICON("qtg_mono_outbox");
|
|
48 |
const QString MSG_FAILED_ICON("qtg_mono_failed");
|
|
49 |
|
|
50 |
//---------------------------------------------------------------
|
|
51 |
// MsgListViewItem::MsgListViewItem
|
|
52 |
// Constructor
|
|
53 |
//---------------------------------------------------------------
|
|
54 |
MsgListViewItem::MsgListViewItem(QGraphicsItem* parent) :
|
|
55 |
HbListViewItem(parent),
|
|
56 |
mUnReadMsg(false),
|
|
57 |
mNewMsgIndicatorItem(NULL),
|
|
58 |
mAddressLabelItem(NULL),
|
|
59 |
mTimestampItem(NULL),
|
|
60 |
mPreviewLabelItem(NULL),
|
|
61 |
mUnreadCountItem(NULL),
|
|
62 |
mPresenceIndicatorItem(NULL)
|
|
63 |
{
|
|
64 |
}
|
|
65 |
|
|
66 |
//---------------------------------------------------------------
|
|
67 |
// HbAbstractViewItem::createItem
|
|
68 |
// @see header
|
|
69 |
//---------------------------------------------------------------
|
|
70 |
HbAbstractViewItem* MsgListViewItem::createItem()
|
|
71 |
{
|
|
72 |
return new MsgListViewItem(*this);
|
|
73 |
}
|
|
74 |
|
|
75 |
//---------------------------------------------------------------
|
|
76 |
// MsgListViewItem::updateChildItems
|
|
77 |
// @see header
|
|
78 |
//---------------------------------------------------------------
|
|
79 |
void MsgListViewItem::updateChildItems()
|
|
80 |
{
|
|
81 |
if (!mAddressLabelItem)
|
|
82 |
{
|
|
83 |
mAddressLabelItem = new HbTextItem(this);
|
|
84 |
HbStyle::setItemName(mAddressLabelItem, "addressLabel");
|
|
85 |
}
|
|
86 |
if (!mTimestampItem)
|
|
87 |
{
|
|
88 |
mTimestampItem = new HbTextItem(this);
|
|
89 |
HbStyle::setItemName(mTimestampItem, "timeLabel");
|
|
90 |
}
|
|
91 |
if (!mPreviewLabelItem)
|
|
92 |
{
|
|
93 |
mPreviewLabelItem = new HbTextItem(this);
|
|
94 |
mPreviewLabelItem->setTextWrapping(Hb::TextWordWrap);
|
|
95 |
HbStyle::setItemName(mPreviewLabelItem, "previewLabel");
|
|
96 |
}
|
|
97 |
if (!mUnreadCountItem)
|
|
98 |
{
|
|
99 |
mUnreadCountItem = new HbTextItem(this);
|
|
100 |
HbStyle::setItemName(mUnreadCountItem, "unreadCount");
|
|
101 |
}
|
|
102 |
if (!mNewMsgIndicatorItem)
|
|
103 |
{
|
|
104 |
mNewMsgIndicatorItem = new HbFrameItem(this);
|
|
105 |
HbStyle::setItemName(mNewMsgIndicatorItem, "newMsgIndicator");
|
|
106 |
|
|
107 |
mNewMsgIndicatorItem->frameDrawer().setFrameType(
|
|
108 |
HbFrameDrawer::ThreePiecesVertical);
|
|
109 |
}
|
|
110 |
|
|
111 |
// Set the message text depending upon the message type
|
|
112 |
int messageType = modelIndex().data(MessageType).toInt();
|
|
113 |
int messageSubType = modelIndex().data(MessageSubType).toInt();
|
|
114 |
int messageState = modelIndex().data(SendingState).toInt();
|
|
115 |
int messageDirection = modelIndex().data(Direction).toInt();
|
|
116 |
QString prevText;
|
|
117 |
prevText = previewText(messageType, messageSubType, messageState,messageDirection);
|
|
118 |
prevText.replace(QChar::ParagraphSeparator, QChar::LineSeparator);
|
|
119 |
prevText.replace('\r', QChar::LineSeparator);
|
|
120 |
mPreviewLabelItem->setText(prevText);
|
|
121 |
|
|
122 |
// Address label
|
|
123 |
QString contactName;
|
|
124 |
if(messageType == ConvergedMessage::BT)
|
|
125 |
{
|
|
126 |
contactName = LOC_RECEIVED_FILES;
|
|
127 |
}
|
|
128 |
else
|
|
129 |
{
|
|
130 |
QString displayName = modelIndex().data(DisplayName).toString();
|
|
131 |
QString contactAddress = modelIndex().data(ConversationAddress).toString();
|
|
132 |
|
|
133 |
if (displayName.isEmpty())
|
|
134 |
{
|
|
135 |
contactName.append(contactAddress);
|
|
136 |
}
|
|
137 |
else
|
|
138 |
{
|
|
139 |
contactName.append(displayName);
|
|
140 |
}
|
|
141 |
}
|
|
142 |
mAddressLabelItem->setText(contactName);
|
|
143 |
|
|
144 |
// Unread message count
|
|
145 |
int unreadCount = modelIndex().data(UnreadCount).toInt();
|
|
146 |
|
|
147 |
if (unreadCount > 0)
|
|
148 |
{
|
|
149 |
QString unRead(tr("(%n)", "", unreadCount));
|
|
150 |
mUnreadCountItem->setText(unRead);
|
|
151 |
mUnReadMsg = true;
|
|
152 |
mNewMsgIndicatorItem->frameDrawer().setFrameGraphicsName(NEW_ITEM_FRAME);
|
|
153 |
}
|
|
154 |
else
|
|
155 |
{
|
|
156 |
mUnreadCountItem->setText(QString());
|
|
157 |
mNewMsgIndicatorItem->frameDrawer().setFrameGraphicsName(QString());
|
|
158 |
mUnReadMsg = false;
|
|
159 |
repolish();
|
|
160 |
}
|
|
161 |
|
|
162 |
HbListViewItem::updateChildItems();
|
|
163 |
}
|
|
164 |
|
|
165 |
//---------------------------------------------------------------
|
|
166 |
// MsgListViewItem::previewText
|
|
167 |
// @see header
|
|
168 |
//---------------------------------------------------------------
|
|
169 |
QString MsgListViewItem::previewText(int msgType,
|
|
170 |
int msgSubType,
|
|
171 |
int msgState,
|
|
172 |
int msgDirection)
|
|
173 |
{
|
|
174 |
QString bodyText(modelIndex().data(BodyText).toString());
|
|
175 |
QString previewText;
|
|
176 |
// Set the message text & icons, depending upon the message type
|
|
177 |
if (msgType == ConvergedMessage::BioMsg) {
|
|
178 |
if (msgSubType == ConvergedMessage::RingingTone) {
|
|
179 |
previewText = LOC_RINGING_TONE;
|
|
180 |
}
|
|
181 |
else if (msgSubType == ConvergedMessage::VCard) {
|
|
182 |
previewText = LOC_BUSINESS_CARD;
|
|
183 |
previewText.append(QChar::LineSeparator);
|
|
184 |
previewText.append(bodyText);
|
|
185 |
}
|
|
186 |
else if (msgSubType == ConvergedMessage::Provisioning) {
|
|
187 |
previewText = bodyText;
|
|
188 |
}
|
|
189 |
else {
|
|
190 |
previewText = LOC_UNSUPPORTED_MSG_TYPE;
|
|
191 |
}
|
|
192 |
}
|
|
193 |
else if (msgType == ConvergedMessage::BT) {
|
|
194 |
|
|
195 |
if (msgSubType == ConvergedMessage::VCard) {
|
|
196 |
previewText = LOC_BUSINESS_CARD;
|
|
197 |
previewText.append(QChar::LineSeparator);
|
|
198 |
previewText.append(bodyText);
|
|
199 |
}
|
|
200 |
else {
|
|
201 |
previewText = bodyText;
|
|
202 |
}
|
|
203 |
if (!mPresenceIndicatorItem) {
|
|
204 |
mPresenceIndicatorItem = new HbIconItem(this);
|
|
205 |
HbStyle::setItemName(mPresenceIndicatorItem, "presenceIndicator");
|
|
206 |
mPresenceIndicatorItem->setIconName(BT_ICON);
|
|
207 |
}
|
|
208 |
}
|
|
209 |
else {
|
|
210 |
previewText = textBySendState(msgState,msgDirection);
|
|
211 |
}
|
|
212 |
return previewText;
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
//---------------------------------------------------------------
|
|
217 |
// MsgListViewItem::textBySendState
|
|
218 |
// @see header
|
|
219 |
//---------------------------------------------------------------
|
|
220 |
QString MsgListViewItem::textBySendState(int sendState,int msgDirection)
|
|
221 |
{
|
|
222 |
QString previewText;
|
|
223 |
QDateTime dateTime;
|
|
224 |
dateTime.setTime_t(modelIndex().data(TimeStamp).toUInt());
|
|
225 |
QString dateString;
|
|
226 |
if (dateTime.date() == QDateTime::currentDateTime().date()) {
|
|
227 |
dateString = MsgUtils::dateTimeToString(dateTime, TIME_FORMAT);
|
|
228 |
}
|
|
229 |
else {
|
|
230 |
dateString = MsgUtils::dateTimeToString(dateTime, DATE_FORMAT);
|
|
231 |
}
|
|
232 |
|
|
233 |
if (msgDirection == ConvergedMessage::Outgoing)
|
|
234 |
{
|
|
235 |
switch (sendState)
|
|
236 |
{
|
|
237 |
case ConvergedMessage::Resend:
|
|
238 |
{
|
|
239 |
|
|
240 |
QString resendString = LOC_MSG_RESEND_AT + dateString;
|
|
241 |
previewText = resendString;
|
|
242 |
dateString = QString("");
|
|
243 |
if (!mPresenceIndicatorItem)
|
|
244 |
{
|
|
245 |
mPresenceIndicatorItem = new HbIconItem(this);
|
|
246 |
}
|
|
247 |
HbStyle::setItemName(mPresenceIndicatorItem,
|
|
248 |
"presenceIndicator");
|
|
249 |
mPresenceIndicatorItem->setIconName(MSG_OUTGOING_ICON);
|
|
250 |
mPresenceIndicatorItem->setVisible(true);
|
|
251 |
break;
|
|
252 |
}
|
|
253 |
|
|
254 |
case ConvergedMessage::Sending:
|
|
255 |
case ConvergedMessage::Suspended:
|
|
256 |
case ConvergedMessage::Scheduled:
|
|
257 |
case ConvergedMessage::Waiting:
|
|
258 |
{
|
|
259 |
previewText = QString(LOC_MSG_OUTGOING);
|
|
260 |
if (!mPresenceIndicatorItem)
|
|
261 |
{
|
|
262 |
mPresenceIndicatorItem = new HbIconItem(this);
|
|
263 |
}
|
|
264 |
HbStyle::setItemName(mPresenceIndicatorItem,
|
|
265 |
"presenceIndicator");
|
|
266 |
mPresenceIndicatorItem->setIconName(MSG_OUTGOING_ICON);
|
|
267 |
mPresenceIndicatorItem->setVisible(true);
|
|
268 |
break;
|
|
269 |
}
|
|
270 |
case ConvergedMessage::Failed:
|
|
271 |
{
|
|
272 |
previewText = QString(LOC_MSG_SEND_FAILED);
|
|
273 |
if (!mPresenceIndicatorItem)
|
|
274 |
{
|
|
275 |
mPresenceIndicatorItem = new HbIconItem(this);
|
|
276 |
}
|
|
277 |
HbStyle::setItemName(mPresenceIndicatorItem,
|
|
278 |
"presenceIndicator");
|
|
279 |
mPresenceIndicatorItem->setIconName(MSG_FAILED_ICON);
|
|
280 |
mPresenceIndicatorItem->setVisible(true);
|
|
281 |
break;
|
|
282 |
}
|
|
283 |
default:
|
|
284 |
QString postFix = QString("");
|
|
285 |
previewText = modelIndex().data(BodyText).toString();
|
|
286 |
previewText += (QChar(QChar::LineSeparator) + postFix);
|
|
287 |
|
|
288 |
if (!mPresenceIndicatorItem)
|
|
289 |
{
|
|
290 |
mPresenceIndicatorItem = new HbIconItem(this);
|
|
291 |
}
|
|
292 |
|
|
293 |
HbStyle::setItemName(mPresenceIndicatorItem,
|
|
294 |
"presenceIndicator");
|
|
295 |
mPresenceIndicatorItem->setIconName(MSG_FAILED_ICON);
|
|
296 |
mPresenceIndicatorItem->setVisible(false);
|
|
297 |
|
|
298 |
break;
|
|
299 |
}
|
|
300 |
}
|
|
301 |
else
|
|
302 |
{
|
|
303 |
previewText = modelIndex().data(BodyText).toString();
|
|
304 |
}
|
|
305 |
mTimestampItem->setText(dateString);
|
|
306 |
return previewText;
|
|
307 |
}
|
|
308 |
|
|
309 |
//---------------------------------------------------------------
|
|
310 |
// MsgListViewItem::paint.
|
|
311 |
// @see header
|
|
312 |
//---------------------------------------------------------------
|
|
313 |
/*void MsgListViewItem::paint(QPainter *painter,
|
|
314 |
const QStyleOptionGraphicsItem *option,
|
|
315 |
QWidget *widget)
|
|
316 |
{
|
|
317 |
|
|
318 |
}
|
|
319 |
*/
|
|
320 |
|
|
321 |
//---------------------------------------------------------------
|
|
322 |
// MsgListViewItem::setWidgetContent
|
|
323 |
// @see header file
|
|
324 |
//---------------------------------------------------------------
|
|
325 |
void MsgListViewItem::setHasUnReadMsg(bool unread)
|
|
326 |
{
|
|
327 |
mUnReadMsg = unread;
|
|
328 |
}
|
|
329 |
|
|
330 |
//---------------------------------------------------------------
|
|
331 |
// MsgListViewItem::setWidgetContent
|
|
332 |
// @see header file
|
|
333 |
//---------------------------------------------------------------
|
|
334 |
bool MsgListViewItem::hasUnReadMsg()
|
|
335 |
{
|
|
336 |
return mUnReadMsg;
|
|
337 |
}
|
|
338 |
|
|
339 |
//EOF
|