77
|
1 |
/*
|
|
2 |
* Copyright (c) 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: This module contains the implementation of IAUpdateAppListModel
|
|
15 |
* class member functions.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include <QStringList>
|
|
20 |
#include <hbtranslator.h>
|
|
21 |
#include <xqconversions.h>
|
|
22 |
|
|
23 |
#include "iaupdateapplistmodel.h"
|
|
24 |
#include "iaupdatefwnode.h"
|
|
25 |
#include "iaupdatebasenode.h"
|
|
26 |
#include "iaupdatedebug.h"
|
|
27 |
|
|
28 |
|
|
29 |
const int KKiloByte = 1024;
|
|
30 |
const int KMegaByte = 1024 * 1024;
|
|
31 |
const int KMaxShownInKiloBytes = 10 * KMegaByte;
|
|
32 |
|
|
33 |
IAUpdateAppListModel::IAUpdateAppListModel() :
|
|
34 |
QAbstractListModel()
|
|
35 |
{
|
|
36 |
mRefreshedCount = 0;
|
|
37 |
mFwNode = NULL;
|
|
38 |
}
|
|
39 |
|
|
40 |
|
|
41 |
QVariant IAUpdateAppListModel::data(const QModelIndex &index, int role) const
|
|
42 |
{
|
|
43 |
if (index.row() < rowCount())
|
|
44 |
{
|
|
45 |
if (role == Qt::DisplayRole)
|
|
46 |
{
|
|
47 |
QString name;
|
|
48 |
QString importanceDescription;
|
|
49 |
if (mFwNode)
|
|
50 |
{
|
|
51 |
MIAUpdateFwNode::TUIUpdateState fwUiState = mFwNode->UiState();
|
|
52 |
if (fwUiState == MIAUpdateFwNode::EPreparing)
|
|
53 |
{
|
|
54 |
name = QString("Preparing ");
|
|
55 |
}
|
|
56 |
else
|
|
57 |
{
|
|
58 |
name = XQConversions::s60DescToQString(mFwNode->Base().Name());
|
|
59 |
name.append(" DEVICE SOFTWARE");
|
|
60 |
}
|
|
61 |
setImportance(mFwNode,importanceDescription);
|
|
62 |
}
|
|
63 |
else
|
|
64 |
{
|
|
65 |
MIAUpdateNode *node = mNodes[index.row()];
|
|
66 |
|
|
67 |
MIAUpdateNode::TUIUpdateState uiState = node->UiState();
|
|
68 |
|
|
69 |
|
|
70 |
if (uiState == MIAUpdateNode::EDownloading)
|
|
71 |
{
|
|
72 |
name = QString("Downloading ");
|
|
73 |
}
|
|
74 |
else if (uiState == MIAUpdateNode::EInstalling)
|
|
75 |
{
|
|
76 |
name = QString("Installing ");
|
|
77 |
}
|
|
78 |
name.append(XQConversions::s60DescToQString(node->Base().Name()));
|
|
79 |
|
|
80 |
|
|
81 |
if (uiState == MIAUpdateNode::ENormal)
|
|
82 |
{
|
|
83 |
setImportance(node,importanceDescription);
|
|
84 |
}
|
|
85 |
else if (uiState == MIAUpdateNode::EUpdated)
|
|
86 |
{
|
80
|
87 |
importanceDescription =
|
|
88 |
hbTrId("txt_software_dblist_1_val_updated");
|
77
|
89 |
}
|
|
90 |
else if (uiState == MIAUpdateNode::EFailed)
|
|
91 |
{
|
80
|
92 |
importanceDescription =
|
|
93 |
hbTrId("txt_software_dblist_1_val_failed");
|
77
|
94 |
}
|
|
95 |
else if (uiState == MIAUpdateNode::EDownloaded)
|
|
96 |
{
|
80
|
97 |
importanceDescription =
|
|
98 |
hbTrId("txt_software_dblist_1_val_downloaded");
|
77
|
99 |
}
|
|
100 |
}
|
|
101 |
QStringList stringList;
|
|
102 |
stringList << name << importanceDescription;
|
|
103 |
return stringList;
|
|
104 |
}
|
|
105 |
else if (role == ProgressRole)
|
|
106 |
{
|
|
107 |
if (mFwNode)
|
|
108 |
{
|
|
109 |
return (mFwNode->UiState() == MIAUpdateFwNode::EPreparing);
|
|
110 |
}
|
|
111 |
else
|
|
112 |
{
|
|
113 |
return (mNodes[index.row()]->UiState() == MIAUpdateNode::EDownloading ||
|
|
114 |
mNodes[index.row()]->UiState() == MIAUpdateNode::EInstalling);
|
|
115 |
}
|
|
116 |
}
|
|
117 |
else if (role == ProgressValueRole)
|
|
118 |
{
|
|
119 |
QList<QVariant> list;
|
|
120 |
if (mFwNode)
|
|
121 |
{
|
|
122 |
list << 0 << 0;
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
list << mNodes[index.row()]->Progress() << mNodes[index.row()]->Total();
|
|
127 |
}
|
|
128 |
return list;
|
|
129 |
}
|
|
130 |
}
|
|
131 |
return QVariant();
|
|
132 |
}
|
|
133 |
|
|
134 |
|
|
135 |
int IAUpdateAppListModel::rowCount(const QModelIndex &parent) const
|
|
136 |
{
|
|
137 |
Q_UNUSED(parent)
|
|
138 |
int nodeCount = mNodes.Count();
|
|
139 |
if (nodeCount == 0 && mFwNode)
|
|
140 |
{
|
|
141 |
nodeCount = 1;
|
|
142 |
}
|
|
143 |
return nodeCount;
|
|
144 |
}
|
|
145 |
|
|
146 |
void IAUpdateAppListModel::setNodeArray(const RPointerArray<MIAUpdateNode> &nodes)
|
|
147 |
{
|
|
148 |
mNodes = nodes;
|
|
149 |
}
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
void IAUpdateAppListModel::setFwNode(MIAUpdateFwNode *fwNode)
|
|
154 |
{
|
|
155 |
mFwNode = fwNode;
|
|
156 |
}
|
|
157 |
|
|
158 |
bool IAUpdateAppListModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
159 |
{
|
|
160 |
int lastRow = row + count - 1;
|
|
161 |
|
|
162 |
for (int i = lastRow; i >= row; --i)
|
|
163 |
{
|
|
164 |
beginRemoveRows(parent, i, i);
|
|
165 |
endRemoveRows();
|
|
166 |
}
|
|
167 |
return true;
|
|
168 |
}
|
|
169 |
|
|
170 |
void IAUpdateAppListModel::refresh()
|
|
171 |
{
|
|
172 |
if (!mFwNode)
|
|
173 |
{
|
|
174 |
if (mRefreshedCount > mNodes.Count())
|
|
175 |
{
|
|
176 |
removeRows(mNodes.Count(), mRefreshedCount - mNodes.Count());
|
|
177 |
}
|
|
178 |
}
|
|
179 |
emit dataChanged(index(0,0),index(rowCount() -1, 0));
|
|
180 |
mRefreshedCount = mNodes.Count();
|
|
181 |
}
|
|
182 |
|
|
183 |
void IAUpdateAppListModel::refreshProgress()
|
|
184 |
{
|
|
185 |
emit layoutChanged();
|
|
186 |
emit dataChanged(index(0,0), index(0,0));
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
void IAUpdateAppListModel::setImportance(MIAUpdateAnyNode *node, QString &importanceDescription) const
|
|
191 |
{
|
|
192 |
IAUPDATE_TRACE("[IAUPDATE] IAUpdateAppListModel::setImportance() begin");
|
|
193 |
int sizeInBytes = node->Base().ContentSizeL();
|
|
194 |
int size = 0;
|
|
195 |
bool shownInMegabytes = false;
|
|
196 |
if (sizeInBytes >= KMaxShownInKiloBytes)
|
|
197 |
{
|
|
198 |
shownInMegabytes = true;
|
|
199 |
size = sizeInBytes / KMegaByte;
|
|
200 |
if (sizeInBytes % KMegaByte != 0)
|
|
201 |
{
|
|
202 |
size++;
|
|
203 |
}
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
size = sizeInBytes / KKiloByte;
|
|
208 |
if (sizeInBytes % KKiloByte != 0)
|
|
209 |
{
|
|
210 |
size++;
|
|
211 |
}
|
|
212 |
}
|
|
213 |
QString sizeString;
|
|
214 |
sizeString.setNum(size);
|
|
215 |
switch(node->Base().Importance())
|
|
216 |
{
|
|
217 |
case MIAUpdateBaseNode::EMandatory:
|
|
218 |
{
|
|
219 |
if (shownInMegabytes)
|
|
220 |
{
|
|
221 |
importanceDescription =
|
|
222 |
hbTrId("txt_software_dblist_update_1_val_required_mb").arg(size);
|
|
223 |
}
|
|
224 |
else
|
|
225 |
{
|
|
226 |
importanceDescription =
|
|
227 |
hbTrId("txt_software_dblist_update_1_val_required_kb").arg(size);
|
|
228 |
}
|
|
229 |
break;
|
|
230 |
}
|
|
231 |
|
|
232 |
case MIAUpdateBaseNode::ECritical:
|
|
233 |
{
|
|
234 |
bool isNSU = false;
|
|
235 |
if(node->NodeType() == MIAUpdateAnyNode::ENodeTypeFw)
|
|
236 |
{
|
|
237 |
MIAUpdateFwNode *fwnode = static_cast<MIAUpdateFwNode*>(node);
|
|
238 |
if (fwnode->FwType() == MIAUpdateFwNode::EFotiNsu)
|
|
239 |
{
|
|
240 |
isNSU = true;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
if (!size || isNSU)
|
|
244 |
{
|
|
245 |
//for firmware when size info is not provided by server
|
|
246 |
}
|
|
247 |
else
|
|
248 |
{
|
|
249 |
if (shownInMegabytes)
|
|
250 |
{
|
|
251 |
|
|
252 |
importanceDescription =
|
|
253 |
hbTrId("txt_software_dblist_update_1_val_important_mb").arg(size);
|
|
254 |
}
|
|
255 |
else
|
|
256 |
{
|
|
257 |
importanceDescription =
|
|
258 |
hbTrId("txt_software_dblist_update_1_val_important_kb").arg(size);
|
|
259 |
}
|
|
260 |
}
|
|
261 |
break;
|
|
262 |
}
|
|
263 |
|
|
264 |
case MIAUpdateBaseNode::ERecommended:
|
|
265 |
{
|
|
266 |
if (shownInMegabytes)
|
|
267 |
{
|
|
268 |
importanceDescription =
|
|
269 |
hbTrId("txt_software_dblist_update_1_val_recommended_mb").arg(size);
|
|
270 |
}
|
|
271 |
else
|
|
272 |
{
|
|
273 |
importanceDescription =
|
|
274 |
hbTrId("txt_software_dblist_update_1_val_recommended_kb").arg(size);
|
|
275 |
}
|
|
276 |
break;
|
|
277 |
}
|
|
278 |
|
|
279 |
case MIAUpdateBaseNode::ENormal:
|
|
280 |
{
|
|
281 |
if (shownInMegabytes)
|
|
282 |
{
|
|
283 |
importanceDescription =
|
|
284 |
hbTrId("txt_software_dblist_update_1_val_optional_mb").arg(size);
|
|
285 |
}
|
|
286 |
else
|
|
287 |
{
|
|
288 |
importanceDescription =
|
|
289 |
hbTrId("txt_software_dblist_update_1_val_optional_kb").arg(size);
|
|
290 |
}
|
|
291 |
break;
|
|
292 |
}
|
|
293 |
|
|
294 |
default:
|
|
295 |
{
|
|
296 |
break;
|
|
297 |
}
|
|
298 |
}
|
|
299 |
IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::setImportance() end");
|
|
300 |
}
|