|
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: CIAUpdateHistory |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // NCD headers: |
|
21 #include <ncdprovider.h> |
|
22 #include <ncdnode.h> |
|
23 #include <ncdnodecontentinfo.h> |
|
24 // Purchase history contains items |
|
25 #include <ncdpurchasehistory.h> |
|
26 // Contains CBase-class headers of the ncd purchase classes. |
|
27 #include <ncdutils.h> |
|
28 |
|
29 |
|
30 #include "iaupdatehistoryimpl.h" |
|
31 #include "iaupdatehistoryitemimpl.h" |
|
32 #include "iaupdatenodefactory.h" |
|
33 |
|
34 |
|
35 |
|
36 CIAUpdateHistory* CIAUpdateHistory::NewL( const TUid& aFamilyUid, |
|
37 MNcdProvider& aProvider ) |
|
38 { |
|
39 CIAUpdateHistory* self = |
|
40 CIAUpdateHistory::NewLC( aFamilyUid, aProvider ); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 |
|
46 CIAUpdateHistory* CIAUpdateHistory::NewLC( const TUid& aFamilyUid, |
|
47 MNcdProvider& aProvider ) |
|
48 { |
|
49 CIAUpdateHistory* self = |
|
50 new( ELeave ) CIAUpdateHistory( aFamilyUid, aProvider ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 CIAUpdateHistory::CIAUpdateHistory( const TUid& aFamilyUid, |
|
58 MNcdProvider& aProvider ) |
|
59 : CBase(), |
|
60 iFamilyUid( aFamilyUid ), |
|
61 iProvider( aProvider ) |
|
62 { |
|
63 |
|
64 } |
|
65 |
|
66 void CIAUpdateHistory::ConstructL() |
|
67 { |
|
68 // Get the purchase history from the provider. |
|
69 // Leave if it can not be gotten. |
|
70 iHistory = Provider().PurchaseHistoryL(); |
|
71 |
|
72 // The items from the NCD Engine purchase history |
|
73 // are not fetched here. |
|
74 // Instead the user of this class has to call RefreshL to |
|
75 // get and to update the list. |
|
76 } |
|
77 |
|
78 |
|
79 CIAUpdateHistory::~CIAUpdateHistory() |
|
80 { |
|
81 iItems.ResetAndDestroy(); |
|
82 History().Release(); |
|
83 } |
|
84 |
|
85 |
|
86 const RPointerArray< MIAUpdateHistoryItem >& CIAUpdateHistory::Items() const |
|
87 { |
|
88 return iItems; |
|
89 } |
|
90 |
|
91 |
|
92 void CIAUpdateHistory::RefreshL() |
|
93 { |
|
94 iItems.ResetAndDestroy(); |
|
95 |
|
96 // Create filter. So, we will get |
|
97 // all the purchase history items. |
|
98 CNcdPurchaseHistoryFilter* filter = |
|
99 CNcdPurchaseHistoryFilter::NewLC(); |
|
100 |
|
101 // Add family uid to the filter |
|
102 RArray< TUid > uids; |
|
103 CleanupClosePushL( uids ); |
|
104 uids.AppendL( FamilyUid() ); |
|
105 filter->SetClientUids( uids.Array() ); |
|
106 CleanupStack::PopAndDestroy( &uids ); |
|
107 |
|
108 // Get the ids. So, we can next get all the corresponding |
|
109 // details. |
|
110 RArray< TUint > ids = |
|
111 History().PurchaseIdsL( *filter ); |
|
112 CleanupStack::PopAndDestroy( filter ); |
|
113 CleanupClosePushL( ids ); |
|
114 |
|
115 // Get all the details and add corresponding history items |
|
116 // into the array. |
|
117 // Notice, that pruneSelfUpdates is not required anymore for |
|
118 // the current version of IAD but it is here just in case |
|
119 // purchase history contains old information and this kind |
|
120 // of checking is needed for them. pruneSelfUpdates flag |
|
121 // informs if other self update items in the list should |
|
122 // be skipped because IAD has already been inserted in the |
|
123 // list. |
|
124 TBool pruneSelfUpdates( EFalse ); |
|
125 for ( TInt i = 0; i < ids.Count(); ++i ) |
|
126 { |
|
127 // We do not want to load icons. So, use EFalse. |
|
128 // Ownership is transferred here. |
|
129 CNcdPurchaseDetails* details( |
|
130 History().PurchaseDetailsL( ids[ i ], EFalse ) ); |
|
131 |
|
132 |
|
133 // Purchase history detail contains the UID information. |
|
134 // So, use it here. |
|
135 TUid itemUid( |
|
136 TUid::Uid( |
|
137 details->AttributeInt32( |
|
138 MNcdPurchaseDetails::EPurchaseAttributeContentUid ) ) ); |
|
139 |
|
140 if ( IAUpdateNodeFactory::IsSelfUpdate( itemUid ) |
|
141 || IAUpdateNodeFactory::IsUpdater( itemUid ) |
|
142 || AcceptItem( *details ) ) |
|
143 { |
|
144 if ( !pruneSelfUpdates ) |
|
145 { |
|
146 // If pruning is not on, then all the items are accepted. |
|
147 // This takes the ownership of details. |
|
148 InsertItemL( details ); |
|
149 |
|
150 if ( IAUpdateNodeFactory::IsIad( itemUid ) ) |
|
151 { |
|
152 // IAD was found, but because pruning was not on yet, |
|
153 // set it on. |
|
154 pruneSelfUpdates = ETrue; |
|
155 } |
|
156 } |
|
157 else if ( !IAUpdateNodeFactory::IsSelfUpdate( itemUid ) |
|
158 && !IAUpdateNodeFactory::IsUpdater( itemUid ) ) |
|
159 { |
|
160 // If pruning is on, then accept only items that are not |
|
161 // self update related. This takes the ownership of details. |
|
162 InsertItemL( details ); |
|
163 } |
|
164 else |
|
165 { |
|
166 // Item was not inserted to the array. So, delete it. |
|
167 delete details; |
|
168 details = NULL; |
|
169 } |
|
170 } |
|
171 else |
|
172 { |
|
173 // Item was not accepted into the history. |
|
174 // So, just skip it. |
|
175 delete details; |
|
176 details = NULL; |
|
177 } |
|
178 } |
|
179 |
|
180 CleanupStack::PopAndDestroy( &ids ); |
|
181 } |
|
182 |
|
183 |
|
184 MNcdProvider& CIAUpdateHistory::Provider() |
|
185 { |
|
186 return iProvider; |
|
187 } |
|
188 |
|
189 |
|
190 MNcdPurchaseHistory& CIAUpdateHistory::History() |
|
191 { |
|
192 return *iHistory; |
|
193 } |
|
194 |
|
195 |
|
196 const TUid& CIAUpdateHistory::FamilyUid() const |
|
197 { |
|
198 return iFamilyUid; |
|
199 } |
|
200 |
|
201 |
|
202 void CIAUpdateHistory::InsertItemL( MNcdPurchaseDetails* aDetails ) |
|
203 { |
|
204 if ( !aDetails ) |
|
205 { |
|
206 // Nothing to do with NULL object. |
|
207 return; |
|
208 } |
|
209 |
|
210 CleanupStack::PushL( aDetails ); |
|
211 CIAUpdateHistoryItem* item( |
|
212 CIAUpdateHistoryItem::NewL( aDetails, Provider() ) ); |
|
213 CleanupStack::Pop( aDetails ); |
|
214 CleanupStack::PushL( item ); |
|
215 |
|
216 if ( iItems.Count() == 0 ) |
|
217 { |
|
218 // Array is empty. |
|
219 // So, just append new item. |
|
220 iItems.AppendL( item ); |
|
221 CleanupStack::Pop( item ); |
|
222 return; |
|
223 } |
|
224 |
|
225 // Check if there exists an older version of the item |
|
226 // in the array. |
|
227 for ( TInt i = 0; i < iItems.Count(); ++i ) |
|
228 { |
|
229 // Casting here is safe thing to do because this function |
|
230 // is the only one that creates the array items and the items |
|
231 // are created as CIAUpdateHistoryItem objects. |
|
232 CIAUpdateHistoryItem* arrayItem( |
|
233 static_cast< CIAUpdateHistoryItem* >( iItems[ i ] ) ); |
|
234 |
|
235 // Get the purchase detail object from the arrayItem. |
|
236 // So, we can check the detail identifications. |
|
237 const MNcdPurchaseDetails& arrayItemDetails( arrayItem->Details() ); |
|
238 |
|
239 if ( aDetails->EntityId() == arrayItemDetails.EntityId() |
|
240 && aDetails->Namespace() == arrayItemDetails.Namespace() |
|
241 && aDetails->ClientUid() == arrayItemDetails.ClientUid() ) |
|
242 { |
|
243 // We have two same items. So, compare their operation times. |
|
244 if ( aDetails->LastOperationTime() |
|
245 > arrayItemDetails.LastOperationTime() ) |
|
246 { |
|
247 // The array item was older for the same purhcase detail. |
|
248 // So, remove the old version. |
|
249 delete iItems[ i ]; |
|
250 iItems[ i ] = NULL; |
|
251 iItems.Remove( i ); |
|
252 |
|
253 // Continue to the phase were the current item will be |
|
254 // inserted to the correct place in the array. |
|
255 break; |
|
256 } |
|
257 else |
|
258 { |
|
259 // Let the array item be in the array because its newer. |
|
260 // Just delete the unnecessary new one. |
|
261 CleanupStack::PopAndDestroy( item ); |
|
262 |
|
263 // Nothing to do here anymore. |
|
264 return; |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 // Insert the item into a correct place in the array. |
|
270 for ( TInt i = 0; i < iItems.Count(); ++i ) |
|
271 { |
|
272 MIAUpdateHistoryItem* arrayItem( iItems[ i ] ); |
|
273 |
|
274 TTime itemTime( item->LastOperationTime() ); |
|
275 TDateTime itemDateTime( itemTime.DateTime() ); |
|
276 TTime arrayItemTime( arrayItem->LastOperationTime() ); |
|
277 TDateTime arrayItemDateTime( arrayItemTime.DateTime() ); |
|
278 |
|
279 // The right place to insert the item is |
|
280 // 1.1. Item in the array is from previous day than this item. |
|
281 // 1.2. Items are from the same day. |
|
282 // Item in the array is not error item, but this item is. |
|
283 // (Error items first) |
|
284 // 1.3. Items are from the same day. |
|
285 // If item in array and this are same type, but the time of |
|
286 // this item is later. (Latest ones first) |
|
287 |
|
288 TBool arrayItemPreviousDay( |
|
289 itemDateTime.Day() > arrayItemDateTime.Day() |
|
290 && itemDateTime.Month() == arrayItemDateTime.Month() |
|
291 && itemDateTime.Year() == arrayItemDateTime.Year() |
|
292 || itemDateTime.Month() > arrayItemDateTime.Month() |
|
293 && itemDateTime.Year() == arrayItemDateTime.Year() |
|
294 || itemDateTime.Year() > arrayItemDateTime.Year() ); |
|
295 |
|
296 TBool itemsSameDay( |
|
297 itemDateTime.Day() == arrayItemDateTime.Day() |
|
298 && itemDateTime.Month() == arrayItemDateTime.Month() |
|
299 && itemDateTime.Year() == arrayItemDateTime.Year() ); |
|
300 |
|
301 TBool itemSuccessfullyInstalled( |
|
302 item->LastOperationErrorCode() == KErrNone |
|
303 && item->StateL() == MIAUpdateHistoryItem::EInstalled ); |
|
304 |
|
305 TBool arrayItemSuccessfullyInstalled( |
|
306 arrayItem->LastOperationErrorCode() == KErrNone |
|
307 && arrayItem->StateL() == MIAUpdateHistoryItem::EInstalled ); |
|
308 |
|
309 if ( arrayItemPreviousDay |
|
310 || itemsSameDay |
|
311 && ( arrayItemSuccessfullyInstalled |
|
312 && !itemSuccessfullyInstalled |
|
313 || itemSuccessfullyInstalled == arrayItemSuccessfullyInstalled |
|
314 && itemTime > arrayItemTime ) ) |
|
315 { |
|
316 iItems.InsertL( item, i ); |
|
317 CleanupStack::Pop( item ); |
|
318 return; |
|
319 } |
|
320 } |
|
321 |
|
322 // If we came here, then the item should be appended to the end |
|
323 // of the array, because it was not inserted above. |
|
324 iItems.AppendL( item ); |
|
325 CleanupStack::Pop( item ); |
|
326 } |
|
327 |
|
328 |
|
329 TBool CIAUpdateHistory::AcceptItem( const CNcdPurchaseDetails& aItem ) const |
|
330 { |
|
331 TBool accept( ETrue ); |
|
332 |
|
333 const TDesC& mime( |
|
334 aItem.AttributeString( |
|
335 MNcdPurchaseDetails::EPurchaseAttributeContentMimeType ) ); |
|
336 |
|
337 if ( IAUpdateNodeFactory::IsFwUpdate( mime ) |
|
338 || IAUpdateNodeFactory::IsHidden( mime ) ) |
|
339 { |
|
340 // Do not accept firmwares into the history. |
|
341 // Do not accept hidden items into the history. |
|
342 accept = EFalse; |
|
343 } |
|
344 |
|
345 return accept; |
|
346 } |
|
347 |