|
1 /* |
|
2 * Copyright (c) 2007-2008 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: CIAUpdateFwPurchaseOperation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <ncdquery.h> |
|
21 #include <ncdprogress.h> |
|
22 #include <ncdoperation.h> |
|
23 #include <ncdpurchaseoperation.h> |
|
24 #include <ncdpurchaseoption.h> |
|
25 #include <ncdnodepurchase.h> |
|
26 #include <ncdnode.h> |
|
27 #include <catalogsutils.h> |
|
28 |
|
29 #include "iaupdatefwpurchaseoperation.h" |
|
30 #include "iaupdatefwnodeimpl.h" |
|
31 #include "iaupdatedebug.h" |
|
32 |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // CIAUpdateFwPurchaseOperation::NewL |
|
36 // |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CIAUpdateFwPurchaseOperation* CIAUpdateFwPurchaseOperation::NewL( |
|
40 CIAUpdateFwNode& aNode, |
|
41 MIAUpdateContentOperationObserver& aObserver ) |
|
42 { |
|
43 CIAUpdateFwPurchaseOperation* self = |
|
44 CIAUpdateFwPurchaseOperation::NewLC( aNode, aObserver ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CIAUpdateFwPurchaseOperation::NewLC |
|
52 // |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CIAUpdateFwPurchaseOperation* CIAUpdateFwPurchaseOperation::NewLC( |
|
56 CIAUpdateFwNode& aNode, |
|
57 MIAUpdateContentOperationObserver& aObserver ) |
|
58 { |
|
59 CIAUpdateFwPurchaseOperation* self = |
|
60 new( ELeave ) CIAUpdateFwPurchaseOperation( aNode, aObserver ); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CIAUpdateFwPurchaseOperation::CIAUpdateFwPurchaseOperation |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CIAUpdateFwPurchaseOperation::CIAUpdateFwPurchaseOperation( |
|
73 CIAUpdateFwNode& aNode, |
|
74 MIAUpdateContentOperationObserver& aObserver ) |
|
75 : CIAUpdateNormalContentOperation( aNode, aObserver ) |
|
76 { |
|
77 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::CIAUpdateFwPurchaseOperation"); |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CIAUpdateFwPurchaseOperation::ConstructL |
|
83 // |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CIAUpdateFwPurchaseOperation::ConstructL() |
|
87 { |
|
88 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::ConstructL begin"); |
|
89 |
|
90 CIAUpdateNormalContentOperation::ConstructL(); |
|
91 |
|
92 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::ConstructL end"); |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CIAUpdateFwPurchaseOperation::~CIAUpdateFwPurchaseOperation |
|
98 // |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CIAUpdateFwPurchaseOperation::~CIAUpdateFwPurchaseOperation() |
|
102 { |
|
103 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::~CIAUpdateFwPurchaseOperation begin"); |
|
104 |
|
105 // This will also reset and delete all the necessary data if needed. |
|
106 CancelOperation(); |
|
107 |
|
108 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::~CIAUpdateFwPurchaseOperation end"); |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CIAUpdateFwPurchaseOperation::PurchaseProgress |
|
114 // Content purchase functions |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 void CIAUpdateFwPurchaseOperation::PurchaseProgress( |
|
118 MNcdPurchaseOperation& /*aOperation*/, |
|
119 TNcdProgress /*aProgress*/ ) |
|
120 { |
|
121 // Purchase progress is not observed. |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CIAUpdateFwPurchaseOperation::QueryReceived |
|
127 // |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CIAUpdateFwPurchaseOperation::QueryReceived( |
|
131 MNcdPurchaseOperation& aOperation, |
|
132 MNcdQuery* aQuery ) |
|
133 { |
|
134 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::QueryReceived() begin"); |
|
135 |
|
136 ContentQueryReceived( aOperation, aQuery ); |
|
137 |
|
138 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::QueryReceived() end"); |
|
139 } |
|
140 |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CIAUpdateFwPurchaseOperation::OperationComplete |
|
144 // |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CIAUpdateFwPurchaseOperation::OperationComplete( |
|
148 MNcdPurchaseOperation& aOperation, |
|
149 TInt aError ) |
|
150 { |
|
151 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateFwPurchaseOperation::OperationComplete() begin: %d", |
|
152 aError); |
|
153 |
|
154 if ( aError != KErrNone ) |
|
155 { |
|
156 IAUPDATE_TRACE("[IAUPDATE] Purchase error. Update purchase history."); |
|
157 // In a purchase operation error case, NCD Engine does not update the |
|
158 // purchase history information. To make sure that purchase history |
|
159 // contains the error code for the operation, insert it here. |
|
160 TRAP_IGNORE( Node().SetIdleErrorToPurchaseHistoryL( aError, EFalse ) ); |
|
161 } |
|
162 |
|
163 ContentOperationComplete( aOperation, aError ); |
|
164 |
|
165 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::OperationComplete() end"); |
|
166 } |
|
167 |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CIAUpdateFwPurchaseOperation::HandleContentL |
|
171 // |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 MNcdOperation* CIAUpdateFwPurchaseOperation::HandleContentL() |
|
175 { |
|
176 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::HandleContentL begin"); |
|
177 |
|
178 MNcdOperation* operation( PurchaseL() ); |
|
179 |
|
180 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::HandleContentL end"); |
|
181 |
|
182 return operation; |
|
183 } |
|
184 |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CIAUpdateFwPurchaseOperation::PurchaseL |
|
188 // |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 MNcdOperation* CIAUpdateFwPurchaseOperation::PurchaseL() |
|
192 { |
|
193 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::PurchaseL() begin"); |
|
194 |
|
195 MNcdOperation* operation( NULL ); |
|
196 |
|
197 MNcdNodePurchase* purchase( |
|
198 Node().Node().QueryInterfaceLC< MNcdNodePurchase >() ); |
|
199 |
|
200 if ( purchase ) |
|
201 { |
|
202 // Purchase interface exists. So, we can do purchasing. |
|
203 if ( !purchase->IsPurchased() ) |
|
204 { |
|
205 IAUPDATE_TRACE("[IAUPDATE] Item was not purchased yet"); |
|
206 |
|
207 // Only do purchase operation if we have not already done purchasing |
|
208 // and the purchase option is usable and not obsolete. |
|
209 RCatalogsArray< MNcdPurchaseOption > options( |
|
210 purchase->PurchaseOptionsL() ); |
|
211 CleanupResetAndDestroyPushL( options ); |
|
212 |
|
213 // Notice, IsUsableL() will leave with KNcdErrorObsolete if the option |
|
214 // is obsolete. Let it leave then, because we could not purchase then |
|
215 // anyways. |
|
216 if( options.Count() == 1 |
|
217 && options[ 0 ]->IsFree() |
|
218 && options[ 0 ]->IsUsableL() ) |
|
219 { |
|
220 IAUPDATE_TRACE("[IAUPDATE] Purchase option was correct."); |
|
221 |
|
222 operation = purchase->PurchaseL( *options[ 0 ], *this ); |
|
223 |
|
224 if( !operation ) |
|
225 { |
|
226 // Could not create the operation for some reason. |
|
227 IAUPDATE_TRACE("[IAUPDATE] ERROR Could not create the operation."); |
|
228 User::Leave( KErrGeneral ); |
|
229 } |
|
230 } |
|
231 else |
|
232 { |
|
233 // Wrong kind of purchase information gotten from the server. |
|
234 IAUPDATE_TRACE("[IAUPDATE] ERROR Wrong purchase info from server."); |
|
235 User::Leave( KErrGeneral ); |
|
236 } |
|
237 CleanupStack::PopAndDestroy( &options ); |
|
238 } |
|
239 CleanupStack::PopAndDestroy( purchase ); |
|
240 } |
|
241 else |
|
242 { |
|
243 IAUPDATE_TRACE("[IAUPDATE] Purchase interface was not found."); |
|
244 User::Leave( KErrNotFound ); |
|
245 } |
|
246 |
|
247 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwPurchaseOperation::PurchaseL() end"); |
|
248 |
|
249 return operation; |
|
250 } |
|
251 |