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