|
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: CIAUpdateHistoryItem |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <ncdpurchasedetails.h> |
|
22 #include <ncdprovider.h> |
|
23 #include <ncdnode.h> |
|
24 #include <ncdnodeinstall.h> |
|
25 #include <ncdnodedownload.h> |
|
26 |
|
27 #include "iaupdatehistoryitemimpl.h" |
|
28 #include "iaupdatecontentoperationmanager.h" |
|
29 |
|
30 |
|
31 CIAUpdateHistoryItem* CIAUpdateHistoryItem::NewL( MNcdPurchaseDetails* aDetails, |
|
32 MNcdProvider& aProvider ) |
|
33 { |
|
34 CIAUpdateHistoryItem* self = |
|
35 CIAUpdateHistoryItem::NewLC( aDetails, aProvider ); |
|
36 CleanupStack::Pop( self ); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 CIAUpdateHistoryItem* CIAUpdateHistoryItem::NewLC( MNcdPurchaseDetails* aDetails, |
|
42 MNcdProvider& aProvider ) |
|
43 { |
|
44 CIAUpdateHistoryItem* self = |
|
45 new( ELeave ) CIAUpdateHistoryItem( aProvider ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL( aDetails ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 |
|
52 CIAUpdateHistoryItem::CIAUpdateHistoryItem( MNcdProvider& aProvider ) |
|
53 : CBase(), |
|
54 iProvider( aProvider ) |
|
55 { |
|
56 |
|
57 } |
|
58 |
|
59 |
|
60 void CIAUpdateHistoryItem::ConstructL( MNcdPurchaseDetails* aDetails ) |
|
61 { |
|
62 if ( !aDetails ) |
|
63 { |
|
64 User::Leave( KErrArgument ); |
|
65 } |
|
66 |
|
67 // The details is set here instead of in the constructor, because now |
|
68 // the details object ownership can be safely taken. If the ownership would be |
|
69 // transferred in constructor, a memory leak could happen if new( ELeave ) |
|
70 // function leaves. |
|
71 iDetails = aDetails; |
|
72 } |
|
73 |
|
74 |
|
75 CIAUpdateHistoryItem::~CIAUpdateHistoryItem() |
|
76 { |
|
77 delete iDetails; |
|
78 } |
|
79 |
|
80 |
|
81 MNcdPurchaseDetails& CIAUpdateHistoryItem::Details() const |
|
82 { |
|
83 return *iDetails; |
|
84 } |
|
85 |
|
86 |
|
87 MNcdProvider& CIAUpdateHistoryItem::Provider() const |
|
88 { |
|
89 return iProvider; |
|
90 } |
|
91 |
|
92 |
|
93 const TDesC& CIAUpdateHistoryItem::Name() const |
|
94 { |
|
95 return Details().ItemName(); |
|
96 } |
|
97 |
|
98 const TDesC& CIAUpdateHistoryItem::Version() const |
|
99 { |
|
100 return Details().Version(); |
|
101 } |
|
102 |
|
103 TTime CIAUpdateHistoryItem::LastOperationTime() const |
|
104 { |
|
105 return Details().LastOperationTime(); |
|
106 } |
|
107 |
|
108 |
|
109 TInt CIAUpdateHistoryItem::LastOperationErrorCode() const |
|
110 { |
|
111 // Make sure that error code does not contain possible |
|
112 // base error code value. |
|
113 return |
|
114 CIAUpdateContentOperationManager::CheckErrorCode( |
|
115 Details().LastOperationErrorCode() ); |
|
116 } |
|
117 |
|
118 |
|
119 CIAUpdateHistoryItem::TIAHistoryItemState CIAUpdateHistoryItem::StateL() const |
|
120 { |
|
121 // Set the preliminary state for the node. |
|
122 // Purchase state is the initial state of the purchase details. |
|
123 TIAHistoryItemState state( EPurchased ); |
|
124 |
|
125 // Notice, when node content has been installed, its purchase details state |
|
126 // will remain as EStateInstalled even if the content is uninstalled. |
|
127 // Also notice, that an error may occur during an operation or an error code |
|
128 // may be set by NCD API user because operations have been cancelled. |
|
129 // Thus, purchase details can not be used here for all the cases because |
|
130 // in some situations the update item content may have been uninstalled |
|
131 // and after that the operation can be cancelled. After that, purhcase details |
|
132 // still give EStateInstalled, but the error code may be set by NCD API user. So, |
|
133 // use purchase details for error code but use the node interfaces to get the |
|
134 // correct state information. |
|
135 |
|
136 |
|
137 // First check if the node is a service pack because then we need to |
|
138 // handle it differently. |
|
139 CIAUpdateContentOperationManager::TContentOperationType operationType( |
|
140 CIAUpdateContentOperationManager::ServicePackOperationType( Details() ) ); |
|
141 if ( operationType != CIAUpdateContentOperationManager::ENoContentOperation ) |
|
142 { |
|
143 // Because we come here, it means that the node is a service pack. |
|
144 // Now check what was the latest operation. |
|
145 switch ( operationType ) |
|
146 { |
|
147 case CIAUpdateContentOperationManager::EPurchaseOperation: |
|
148 state = EPurchased; |
|
149 break; |
|
150 |
|
151 case CIAUpdateContentOperationManager::EDownloadOperation: |
|
152 if ( LastOperationErrorCode() == KErrNone ) |
|
153 { |
|
154 // Because error code describe success in operation. |
|
155 state = EDownloaded; |
|
156 } |
|
157 else |
|
158 { |
|
159 // Error code says that download has not been success. |
|
160 // So, only purchase operation has been fully done. |
|
161 state = EPurchased; |
|
162 } |
|
163 break; |
|
164 |
|
165 case CIAUpdateContentOperationManager::EInstallOperation: |
|
166 if ( LastOperationErrorCode() == KErrNone ) |
|
167 { |
|
168 // Because error code describe success in operation. |
|
169 state = EInstalled; |
|
170 } |
|
171 else |
|
172 { |
|
173 // Error code says that install has not been success. |
|
174 // So, only download operation has been fully done. |
|
175 state = EDownloaded; |
|
176 } |
|
177 break; |
|
178 |
|
179 default: |
|
180 User::Leave( KErrNotSupported ); |
|
181 break; |
|
182 } |
|
183 |
|
184 return state; |
|
185 } |
|
186 |
|
187 |
|
188 // Get the node from the provider. The node can be gotten by using the |
|
189 // purchase details. |
|
190 MNcdNode* node( Provider().NodeL( Details() ) ); |
|
191 if ( !node ) |
|
192 { |
|
193 // Node should always be found if its purchase details can be found |
|
194 // from the purchase history. |
|
195 User::Leave( KErrNotFound ); |
|
196 } |
|
197 CleanupReleasePushL( *node ); |
|
198 |
|
199 // First check if the node has already been installed and it is still installed. |
|
200 MNcdNodeInstall* install( node->QueryInterfaceLC<MNcdNodeInstall>() ); |
|
201 if ( install ) |
|
202 { |
|
203 if ( install->IsInstalledL() ) |
|
204 { |
|
205 // Content has already been installed. |
|
206 // So, the whole process has been completed. |
|
207 // Notice, downloaded files are removed or |
|
208 // moved after installation. |
|
209 state = EInstalled; |
|
210 } |
|
211 CleanupStack::PopAndDestroy( install ); |
|
212 install = NULL; |
|
213 } |
|
214 |
|
215 if ( state != EInstalled ) |
|
216 { |
|
217 if ( LastOperationErrorCode() == KErrNone |
|
218 && Details().State() == MNcdPurchaseDetails::EStateInstalled ) |
|
219 { |
|
220 // This check is required for the cases where the node has been installed, |
|
221 // but it has been uninstalled after that. |
|
222 // If error code is KErrNone and purchase details value is EStateInstalled, |
|
223 // then the last operation has been an install-operation that was success. |
|
224 // Because the content is not in the phone anymore, it must have been |
|
225 // uninstalled. Anyways, the last history information should show |
|
226 // installed state. |
|
227 state = EInstalled; |
|
228 } |
|
229 else |
|
230 { |
|
231 // Node was not installed. So, check if it has been downloaded and it is |
|
232 // ready for installing. |
|
233 MNcdNodeDownload* download( node->QueryInterfaceLC<MNcdNodeDownload>() ); |
|
234 if ( download ) |
|
235 { |
|
236 if ( download->IsDownloadedL() ) |
|
237 { |
|
238 // Content has not been installed yet, but it has been |
|
239 // downloaded and it is available. |
|
240 state = EDownloaded; |
|
241 } |
|
242 CleanupStack::PopAndDestroy( download ); |
|
243 download = NULL; |
|
244 } |
|
245 } |
|
246 } |
|
247 |
|
248 CleanupStack::PopAndDestroy( node ); |
|
249 node = NULL; |
|
250 |
|
251 return state; |
|
252 } |