|
1 /* |
|
2 * Copyright (c) 2009-2010 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 "nmuiheaders.h" |
|
19 |
|
20 /*! |
|
21 \class NmMessageListViewItem |
|
22 \brief List view item for message list view. |
|
23 */ |
|
24 |
|
25 static const int NmFolderTypeRole = Qt::UserRole+1; |
|
26 |
|
27 /*! |
|
28 Constructor. |
|
29 */ |
|
30 NmMessageListViewItem::NmMessageListViewItem(QGraphicsItem *parent) |
|
31 : HbTreeViewItem(parent), |
|
32 mSender(NULL), |
|
33 mSubject(NULL), |
|
34 mTime(NULL), |
|
35 mDividerTitle(NULL), |
|
36 mNewMsgIcon(NULL), |
|
37 mIcon1(NULL), |
|
38 mIcon2(NULL), |
|
39 mPrimarySize(0), |
|
40 mSecondarySize(0) |
|
41 { |
|
42 } |
|
43 |
|
44 /*! |
|
45 Destructor. |
|
46 */ |
|
47 NmMessageListViewItem::~NmMessageListViewItem() |
|
48 { |
|
49 } |
|
50 |
|
51 /*! |
|
52 Create item. |
|
53 */ |
|
54 HbTreeViewItem *NmMessageListViewItem::createItem() |
|
55 { |
|
56 return new NmMessageListViewItem(*this); |
|
57 } |
|
58 |
|
59 /*! |
|
60 Boolean value indicating model index availability. Always true since |
|
61 this item prototype is used for both divider and message. |
|
62 */ |
|
63 bool NmMessageListViewItem::canSetModelIndex(const QModelIndex &index) const |
|
64 { |
|
65 Q_UNUSED(index); |
|
66 // This item class can handle all items in message list. |
|
67 return true; |
|
68 } |
|
69 |
|
70 /*! |
|
71 Update child items. List calls this function whenever item is needed |
|
72 to be updated. |
|
73 */ |
|
74 void NmMessageListViewItem::updateChildItems() |
|
75 { |
|
76 // Get model pointer |
|
77 NmMessageListModelItem *msgModelItem = modelIndex().data( |
|
78 Qt::DisplayRole).value<NmMessageListModelItem*>(); |
|
79 // Check whether item is message item or title divider |
|
80 // and set the layout accordingly. Dividers are not currently used. |
|
81 if (msgModelItem && msgModelItem->itemType() == |
|
82 NmMessageListModelItem::NmMessageItemMessage){ |
|
83 NmMessageListModel *model = static_cast<NmMessageListModel*>(msgModelItem->model()); |
|
84 if (model){ |
|
85 // First set item layout. |
|
86 createMessageItemLayout(); |
|
87 // Set content data to item after layout is created. |
|
88 setContentsToMessageItem(msgModelItem->envelope(), model->dividersActive()); |
|
89 } |
|
90 } |
|
91 HbTreeViewItem::updateChildItems(); |
|
92 } |
|
93 |
|
94 /*! |
|
95 Set item layout. |
|
96 Function does not take ownership of model or model item. |
|
97 */ |
|
98 void NmMessageListViewItem::createMessageItemLayout() |
|
99 { |
|
100 getFontSizes(); |
|
101 // Create sender label and set name from widgetml. |
|
102 if (!mSender) { |
|
103 mSender = new HbTextItem(this); |
|
104 HbStyle::setItemName(mSender, "sender"); |
|
105 mSender->setObjectName("ListViewItemMessageSender"); |
|
106 } |
|
107 // Create time label and set name from widgetml. |
|
108 if (!mTime) { |
|
109 mTime = new HbTextItem(this); |
|
110 HbStyle::setItemName(mTime, "time"); |
|
111 mTime->setObjectName("ListViewItemMessageTime"); |
|
112 } |
|
113 // Create subject label and set name from widgetml. |
|
114 if (!mSubject) { |
|
115 mSubject = new HbTextItem(this); |
|
116 HbStyle::setItemName(mSubject, "subject"); |
|
117 mSubject->setObjectName("ListViewItemMessageSubject"); |
|
118 } |
|
119 // Set new message icon. |
|
120 if (!mNewMsgIcon) { |
|
121 mNewMsgIcon = new HbFrameItem(this); |
|
122 } |
|
123 // Create priority icon and set name from widgetml. |
|
124 if (!mIcon1) { |
|
125 mIcon1 = new HbIconItem(this); |
|
126 HbStyle::setItemName(mIcon1, "icon1"); |
|
127 } |
|
128 // Create attachment icon and set name from widgetml. |
|
129 if (!mIcon2) { |
|
130 mIcon2 = new HbIconItem(this); |
|
131 HbStyle::setItemName(mIcon2, "icon2"); |
|
132 } |
|
133 setObjectName("ListViewItemMessage"); |
|
134 } |
|
135 |
|
136 /*! |
|
137 Sets the item text label contents, icons, etc. The method does not take |
|
138 ownership of model or model item. |
|
139 |
|
140 \param envelope The message envelope. |
|
141 \param dividersActive |
|
142 */ |
|
143 void NmMessageListViewItem::setContentsToMessageItem(const NmMessageEnvelope &envelope, |
|
144 bool dividersActive) |
|
145 { |
|
146 // Member variables are created in previous function. |
|
147 // Sender. |
|
148 mSender->setText(senderFieldText(envelope)); |
|
149 |
|
150 // Time. |
|
151 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
152 QDateTime localTime = envelope.sentTime().addSecs(locale.universalTimeOffset()); |
|
153 QDate sentLocalDate = localTime.date(); |
|
154 QDate currentdate = QDate::currentDate(); |
|
155 |
|
156 if (dividersActive || sentLocalDate == currentdate) { |
|
157 QString shortTimeSpec = r_qtn_time_usual; |
|
158 QTime time = localTime.time(); |
|
159 mTime->setText(locale.format(time, shortTimeSpec)); |
|
160 } else { |
|
161 QString shortDateSpec = r_qtn_date_without_year; |
|
162 mTime->setText(locale.format(sentLocalDate, shortDateSpec)); |
|
163 } |
|
164 |
|
165 // Subject. |
|
166 QString subjectText = envelope.subject(); |
|
167 |
|
168 if (subjectText.length()) { |
|
169 mSubject->setText(subjectText); |
|
170 } else { |
|
171 mSubject->setText(hbTrId("txt_mail_dblist_val_no_subject")); |
|
172 } |
|
173 |
|
174 // Priority. |
|
175 bool priorityIs(false); |
|
176 |
|
177 mIcon1->setIcon(HbIcon()); |
|
178 mIcon1->setObjectName(QString()); |
|
179 mIcon1->hide(); |
|
180 mIcon2->setIcon(HbIcon()); |
|
181 mIcon2->setObjectName(QString()); |
|
182 mIcon2->hide(); |
|
183 |
|
184 switch (envelope.priority()) { |
|
185 case NmMessagePriorityLow: { |
|
186 priorityIs = true; |
|
187 mIcon1->setObjectName("ListViewItemMessageIconPriorityLow"); |
|
188 mIcon1->setIcon(NmIcons::getIcon(NmIcons::NmIconPriorityLow)); |
|
189 mIcon1->show(); |
|
190 break; |
|
191 } |
|
192 case NmMessagePriorityHigh: { |
|
193 priorityIs = true; |
|
194 mIcon1->setObjectName("ListViewItemMessageIconPriorityHigh"); |
|
195 mIcon1->setIcon(NmIcons::getIcon(NmIcons::NmIconPriorityHigh)); |
|
196 mIcon1->show(); |
|
197 break; |
|
198 } |
|
199 case NmMessagePriorityNormal: { |
|
200 break; |
|
201 } |
|
202 default: |
|
203 break; |
|
204 } |
|
205 // Attachments. |
|
206 HbIconItem *attaIcon = (priorityIs ? mIcon2 : mIcon1); |
|
207 |
|
208 if (envelope.hasAttachments()) { |
|
209 HbIcon &icon = NmIcons::getIcon(NmIcons::NmIconAttachment); |
|
210 attaIcon->setIcon(icon); |
|
211 attaIcon->setObjectName("ListViewItemMessageIconAttachment"); |
|
212 attaIcon->show(); |
|
213 } |
|
214 else { |
|
215 attaIcon->setIcon(HbIcon()); |
|
216 attaIcon->setObjectName(QString()); |
|
217 } |
|
218 |
|
219 // Message read status. |
|
220 bool msgReadStatus(envelope.isRead()); |
|
221 HbFrameDrawer *drawer(NULL); |
|
222 HbStyle::setItemName(mNewMsgIcon, "msgicon"); |
|
223 |
|
224 if (!msgReadStatus) { |
|
225 setFontsUnread(); |
|
226 mNewMsgIcon->setObjectName("ListViewItemMessageIconUnread"); |
|
227 drawer = new HbFrameDrawer("qtg_fr_list_new_item", |
|
228 HbFrameDrawer::ThreePiecesVertical); |
|
229 drawer->setFillWholeRect(false); |
|
230 // Set drawer. Takes ownership of the drawer and deletes previous drawer. |
|
231 mNewMsgIcon->setFrameDrawer(drawer); |
|
232 mNewMsgIcon->show(); |
|
233 } else { |
|
234 setFontsRead(); |
|
235 mNewMsgIcon->setObjectName("ListViewItemMessageIconRead"); |
|
236 drawer = new HbFrameDrawer(); // Create empty drawer. |
|
237 drawer->setFillWholeRect(false); |
|
238 // Set drawer. Takes ownership of the drawer and deletes previous drawer. |
|
239 mNewMsgIcon->setFrameDrawer(drawer); |
|
240 mNewMsgIcon->hide(); |
|
241 } |
|
242 } |
|
243 |
|
244 /*! |
|
245 Set fonts unread. |
|
246 */ |
|
247 void NmMessageListViewItem::setFontsUnread() |
|
248 { |
|
249 static QColor colorRole = HbColorScheme::color("qtc_list_item_title_normal"); |
|
250 HbFontSpec fontSpec(HbFontSpec::Primary); |
|
251 setFonts(colorRole, fontSpec); |
|
252 } |
|
253 |
|
254 /*! |
|
255 Set fonts read. |
|
256 */ |
|
257 void NmMessageListViewItem::setFontsRead() |
|
258 { |
|
259 static QColor colorRole = HbColorScheme::color("qtc_list_item_content_normal"); |
|
260 HbFontSpec fontSpec(HbFontSpec::Secondary); |
|
261 setFonts(colorRole, fontSpec); |
|
262 } |
|
263 |
|
264 /*! |
|
265 Get font sizes. |
|
266 */ |
|
267 void NmMessageListViewItem::getFontSizes() |
|
268 { |
|
269 // Get font sizes from style. |
|
270 qreal currentSize; |
|
271 bool found = style()->parameter(QString("hb-param-text-height-primary"), currentSize ); |
|
272 if (found) { |
|
273 mPrimarySize = currentSize; |
|
274 } |
|
275 found = style()->parameter(QString("hb-param-text-height-secondary"), currentSize ); |
|
276 if (found) { |
|
277 mSecondarySize = currentSize; |
|
278 } |
|
279 } |
|
280 |
|
281 /*! |
|
282 Set fonts. |
|
283 */ |
|
284 void NmMessageListViewItem::setFonts(const QColor &colorRole, |
|
285 HbFontSpec &fontSpec) |
|
286 { |
|
287 // Change sizes explicitly since css is overwritten in polish now. |
|
288 if (mSender && mSubject && mTime) { |
|
289 if (mPrimarySize) { |
|
290 fontSpec.setTextHeight(mPrimarySize); |
|
291 } |
|
292 mSender->setFontSpec(fontSpec); |
|
293 mSender->setTextColor(colorRole); |
|
294 if (mSecondarySize) { |
|
295 fontSpec.setTextHeight(mSecondarySize); |
|
296 } |
|
297 mSubject->setFontSpec(fontSpec); |
|
298 mSubject->setTextColor(colorRole); |
|
299 mTime->setFontSpec(fontSpec); |
|
300 mTime->setTextColor(colorRole); |
|
301 } |
|
302 } |
|
303 |
|
304 /*! |
|
305 Get sender field text. Function returns sender field text from |
|
306 envelope based on currently used function. |
|
307 */ |
|
308 QString NmMessageListViewItem::senderFieldText(const NmMessageEnvelope &envelope) |
|
309 { |
|
310 QString ret; |
|
311 QVariant folderType = modelIndex().data( |
|
312 NmFolderTypeRole).value<QVariant>(); |
|
313 switch (folderType.toInt()) { |
|
314 // Outbox, drafts and sent folder, sender name is |
|
315 // replaced with first recipient from to/cc list. |
|
316 case NmFolderOutbox: |
|
317 case NmFolderDrafts: |
|
318 case NmFolderSent: |
|
319 { |
|
320 QList<NmAddress>& toRecipients = envelope.toRecipients(); |
|
321 QList<NmAddress>& ccRecipients = envelope.ccRecipients(); |
|
322 NmAddress addressToUse; |
|
323 bool foundAddress(false); |
|
324 if (toRecipients.count()){ |
|
325 addressToUse=toRecipients[0]; |
|
326 foundAddress=true; |
|
327 } |
|
328 else if (ccRecipients.count()) { |
|
329 addressToUse=ccRecipients[0]; |
|
330 foundAddress=true; |
|
331 } |
|
332 if (foundAddress){ |
|
333 QString displayName = addressToUse.displayName(); |
|
334 if (displayName.length()) { |
|
335 ret += NmUtilities::cleanupDisplayName(displayName); |
|
336 } |
|
337 else { |
|
338 ret += addressToUse.address(); |
|
339 } |
|
340 } |
|
341 } |
|
342 break; |
|
343 // All other folders will show sender display name. |
|
344 default: |
|
345 { |
|
346 QString displayName = envelope.sender().displayName(); |
|
347 if (displayName.length()) { |
|
348 ret += NmUtilities::cleanupDisplayName(displayName); |
|
349 } |
|
350 else { |
|
351 ret += envelope.sender().address(); |
|
352 } |
|
353 } |
|
354 break; |
|
355 } |
|
356 return ret; |
|
357 } |