|
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: model for drafts view. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "draftsmodel.h" |
|
19 #include "conversationsenginedefines.h" |
|
20 #include "conversationsengineutility.h" |
|
21 #include "conversationsengineutility.h" |
|
22 |
|
23 #include <ccsclientconversation.h> |
|
24 #include <ccsconversationentry.h> |
|
25 #include <msvstd.h> |
|
26 #include <QDateTime> |
|
27 #include <HbExtendedLocale> |
|
28 #include <hbicon.h> |
|
29 #include <xqconversions.h> |
|
30 //CONSTANTS |
|
31 // @see hbi18ndef.h |
|
32 static const char DATE_FORMAT[] = r_qtn_date_short_with_zero; |
|
33 static const char TIME_FORMAT[] = r_qtn_time_usual_with_zero; |
|
34 //priority icons |
|
35 const QString MSG_HIGH_PRIORITY_ICON("qtg_small_priority_high"); |
|
36 const QString MSG_LOW_PRIORITY_ICON("qtg_small_priority_low"); |
|
37 // Localization |
|
38 #define LOC_NO_RECIPIENTS hbTrId("txt_messaging_list_no_recipients") |
|
39 |
|
40 //--------------------------------------------------------------- |
|
41 // DraftsModel::DraftsModel |
|
42 // @see header |
|
43 //--------------------------------------------------------------- |
|
44 DraftsModel::DraftsModel(QObject* parent) : |
|
45 QStandardItemModel(parent), mReady(false) |
|
46 { |
|
47 } |
|
48 |
|
49 //--------------------------------------------------------------- |
|
50 // DraftsModel::~DraftsModel |
|
51 // @see header |
|
52 //--------------------------------------------------------------- |
|
53 DraftsModel::~DraftsModel() |
|
54 { |
|
55 } |
|
56 |
|
57 //--------------------------------------------------------------- |
|
58 // DraftsModel::data |
|
59 // @see header |
|
60 //--------------------------------------------------------------- |
|
61 QVariant DraftsModel::data(const QModelIndex & index, int role) const |
|
62 { |
|
63 QVariant value; |
|
64 QStandardItem* item = itemFromIndex(index); |
|
65 switch (role) { |
|
66 case Qt::DisplayRole: |
|
67 { |
|
68 QStringList displayList; |
|
69 //timestamp conversion |
|
70 QDateTime dateTime; |
|
71 dateTime.setTime_t(item->data(TimeStamp).toUInt()); |
|
72 |
|
73 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
74 QString dateString; |
|
75 if (dateTime.date() == QDateTime::currentDateTime().date()) { |
|
76 dateString = locale.format(dateTime.time(), TIME_FORMAT); |
|
77 } |
|
78 else { |
|
79 dateString = locale.format(dateTime.date(), DATE_FORMAT); |
|
80 } |
|
81 //display name |
|
82 QString contactName = item->data(DisplayName).toString(); |
|
83 if (contactName.isEmpty()) { |
|
84 contactName = LOC_NO_RECIPIENTS; |
|
85 } |
|
86 //description |
|
87 QString description = item->data(Subject).toString(); |
|
88 if(description.isEmpty()) |
|
89 { |
|
90 description = QString(" "); |
|
91 } |
|
92 displayList << contactName << description << dateString; |
|
93 |
|
94 value = displayList; |
|
95 break; |
|
96 } |
|
97 case Qt::DecorationRole: |
|
98 { |
|
99 QVariant icon; |
|
100 int priority = item->data(MessagePriority).toInt(); |
|
101 |
|
102 if(priority == ConvergedMessage::Low) |
|
103 { |
|
104 icon = HbIcon(MSG_LOW_PRIORITY_ICON); |
|
105 } |
|
106 else if (priority == ConvergedMessage::High) |
|
107 { |
|
108 icon = HbIcon(MSG_HIGH_PRIORITY_ICON); |
|
109 } |
|
110 |
|
111 QList<QVariant> decorationList; |
|
112 decorationList << QVariant() << icon; |
|
113 value = decorationList; |
|
114 |
|
115 break; |
|
116 } |
|
117 case TimeStamp: |
|
118 { |
|
119 value = item->data(TimeStamp); |
|
120 break; |
|
121 } |
|
122 case ConvergedMsgId: |
|
123 { |
|
124 value = item->data(ConvergedMsgId); |
|
125 break; |
|
126 } |
|
127 case MessageType: |
|
128 { |
|
129 value = item->data(MessageType); |
|
130 break; |
|
131 } |
|
132 case Subject: |
|
133 { |
|
134 value = item->data(Subject); |
|
135 break; |
|
136 } |
|
137 case DisplayName: |
|
138 { |
|
139 value = item->data(DisplayName); |
|
140 break; |
|
141 } |
|
142 case MessageProperty: |
|
143 { |
|
144 value = item->data(MessageProperty); |
|
145 break; |
|
146 } |
|
147 case MessagePriority: |
|
148 { |
|
149 value = item->data(MessagePriority); |
|
150 break; |
|
151 } |
|
152 } |
|
153 return value; |
|
154 } |
|
155 |
|
156 //--------------------------------------------------------------- |
|
157 // DraftsModel::addRow |
|
158 // @see header |
|
159 //--------------------------------------------------------------- |
|
160 void DraftsModel::addRow(const TMsvEntry& entry) |
|
161 { |
|
162 int msgId = entry.Id(); |
|
163 |
|
164 //match msgId in model, if found update else add item |
|
165 QModelIndexList indexList = |
|
166 this->match(index(0, 0), ConvergedMsgId, msgId, 1, Qt::MatchExactly); |
|
167 |
|
168 // if not found, add new item |
|
169 if (indexList.count() == 0) { |
|
170 QStandardItem* item = new QStandardItem(); |
|
171 populateItem(*item, entry); |
|
172 appendRow(item); |
|
173 } |
|
174 else { |
|
175 // Update an existing item |
|
176 QModelIndex index = indexList[0]; |
|
177 QStandardItem* item = this->item(index.row(), 0); |
|
178 populateItem(*item, entry); |
|
179 } |
|
180 } |
|
181 |
|
182 //--------------------------------------------------------------- |
|
183 // DraftsModel::deleteRow |
|
184 // @see header |
|
185 //--------------------------------------------------------------- |
|
186 void DraftsModel::deleteRow(int msgId) |
|
187 { |
|
188 //match, if found remove item |
|
189 QModelIndexList indexList = |
|
190 this->match(index(0, 0), ConvergedMsgId, msgId, 1, Qt::MatchExactly); |
|
191 |
|
192 if (indexList.count() == 1) { |
|
193 QModelIndex index = indexList[0]; |
|
194 this->removeRow(index.row()); |
|
195 } |
|
196 } |
|
197 |
|
198 //--------------------------------------------------------------- |
|
199 // DraftsModel::setReady |
|
200 // @see header |
|
201 //--------------------------------------------------------------- |
|
202 void DraftsModel::setReady() |
|
203 { |
|
204 mReady = true; |
|
205 } |
|
206 |
|
207 //--------------------------------------------------------------- |
|
208 // DraftsModel::isReady |
|
209 // @see header |
|
210 //--------------------------------------------------------------- |
|
211 bool DraftsModel::isReady() |
|
212 { |
|
213 return mReady; |
|
214 } |
|
215 |
|
216 //--------------------------------------------------------------- |
|
217 // DraftsModel::populateItem |
|
218 // @see header |
|
219 //--------------------------------------------------------------- |
|
220 void DraftsModel::populateItem(QStandardItem& item, const TMsvEntry& entry) |
|
221 { |
|
222 // id |
|
223 item.setData((int) entry.Id(), ConvergedMsgId); |
|
224 |
|
225 //message type |
|
226 item.setData(ConversationsEngineUtility::messageType(entry.iMtm.iUid), MessageType); |
|
227 |
|
228 // description |
|
229 QString Description(XQConversions::s60DescToQString(entry.iDescription)); |
|
230 item.setData(Description, Subject); |
|
231 |
|
232 // time stamp |
|
233 TTime unixEpoch(KUnixEpoch); |
|
234 TTimeIntervalSeconds seconds; |
|
235 TTime timeStamp(entry.iDate.Int64()); |
|
236 timeStamp.SecondsFrom(unixEpoch, seconds); |
|
237 item.setData(seconds.Int(), TimeStamp); |
|
238 |
|
239 // contact details |
|
240 QString contact(XQConversions::s60DescToQString(entry.iDetails)); |
|
241 item.setData(contact, DisplayName); |
|
242 |
|
243 // Attachments |
|
244 if (entry.Attachment()) { |
|
245 item.setData(ConvergedMessage::Attachment, MessageProperty); |
|
246 } |
|
247 |
|
248 // Priority |
|
249 TMsvPriority priority = entry.Priority(); |
|
250 if (EMsvHighPriority == priority) { |
|
251 item.setData(ConvergedMessage::High, MessagePriority); |
|
252 } |
|
253 else if (EMsvLowPriority == priority) { |
|
254 item.setData(ConvergedMessage::Low, MessagePriority); |
|
255 } |
|
256 } |
|
257 |
|
258 // EOF |