|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Application class for Mce. |
|
16 * |
|
17 */ |
|
18 |
|
19 // system include files go here: |
|
20 |
|
21 #include <iaupdate.h> |
|
22 #include <iaupdateparameters.h> |
|
23 #include <iaupdateresult.h> |
|
24 #include <featmgr.h> |
|
25 |
|
26 // user include files go here: |
|
27 #include "mceui.h" |
|
28 #include "mceiaupdateutils.h" |
|
29 #include "MceLogText.h" |
|
30 |
|
31 // CONSTANT |
|
32 |
|
33 // Defines the time span in hours for the next IAD update check event |
|
34 // which will be trigered. |
|
35 const TInt KMceIADUpdateCheckRetryInterval = 24; |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // C++ default constructor. |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CMceIAUpdateUtils::CMceIAUpdateUtils(CMceUi& aMceUi) |
|
44 : CActive(EPriorityStandard),iUpdate( NULL ), iParameters( NULL ),iMceUi( aMceUi ) |
|
45 { |
|
46 CActiveScheduler::Add(this); |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Symbian 2nd phase constructor. |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CMceIAUpdateUtils::ConstructL() |
|
55 { |
|
56 iUpdate = NULL; |
|
57 iParameters = NULL; |
|
58 // set it to current time. |
|
59 iPrevIADUpdateCheckTry.UniversalTime(); |
|
60 } |
|
61 |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // Two-phased constructor. |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CMceIAUpdateUtils* CMceIAUpdateUtils::NewL(CMceUi& aMceUi) |
|
68 { |
|
69 CMceIAUpdateUtils* self = new( ELeave ) CMceIAUpdateUtils(aMceUi); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // Destructor |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CMceIAUpdateUtils::~CMceIAUpdateUtils() |
|
81 { |
|
82 Delete(); |
|
83 Cancel(); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Start IA update process. |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void CMceIAUpdateUtils::DoStartL( const TUid aAppUid ) |
|
91 { |
|
92 if(!iUpdate) |
|
93 { |
|
94 iUpdate = CIAUpdate::NewL( *this ); |
|
95 } |
|
96 |
|
97 if( !iParameters ) |
|
98 { |
|
99 iParameters = CIAUpdateParameters::NewL(); |
|
100 } |
|
101 |
|
102 if( iUpdate && iParameters ) |
|
103 { |
|
104 iParameters->SetUid( aAppUid ); |
|
105 |
|
106 // Don't want any wait dialog. |
|
107 iParameters->SetShowProgress( EFalse ); |
|
108 |
|
109 // Check the updates |
|
110 MCELOGGER_WRITE("StartL --- check updates"); |
|
111 iUpdate->CheckUpdates( *iParameters ); |
|
112 } |
|
113 else |
|
114 { |
|
115 Delete(); //Delete session with IAD server |
|
116 } |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Cleanup function. |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 void CMceIAUpdateUtils::Delete() |
|
124 { |
|
125 if( iUpdate ) |
|
126 { |
|
127 delete iUpdate; |
|
128 iUpdate = NULL; |
|
129 } |
|
130 if( iParameters ) |
|
131 { |
|
132 delete iParameters; |
|
133 iParameters = NULL; |
|
134 } |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // From class MIAUpdateObserver. |
|
139 // This callback function is called when the update checking operation has |
|
140 // completed. |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CMceIAUpdateUtils::CheckUpdatesComplete( TInt aErrorCode, |
|
144 TInt aAvailableUpdates ) |
|
145 { |
|
146 TBool bContinue = EFalse; |
|
147 |
|
148 if ( aErrorCode == KErrNone ) |
|
149 { |
|
150 if ( aAvailableUpdates > 0 ) |
|
151 { |
|
152 if((iMceUi.IsForeground())&&(iMceUi.MceViewActive(EMceMainViewActive))) |
|
153 { |
|
154 // There were some updates available. |
|
155 MCELOGGER_WRITE("CheckUpdatesComplete --- updates available"); |
|
156 iUpdate->UpdateQuery(); |
|
157 bContinue = ETrue; |
|
158 } |
|
159 else |
|
160 { |
|
161 MCELOGGER_WRITE("CheckUpdatesComplete --- But MessageView or Delivery Reports View is active"); |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 // No updates available. |
|
167 MCELOGGER_WRITE("CheckUpdatesComplete --- no updates available"); |
|
168 } |
|
169 } |
|
170 if(!bContinue) |
|
171 { |
|
172 Delete(); //Delete session with IAD server |
|
173 } |
|
174 |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // From class MIAUpdateObserver. |
|
179 // This callback function is called when an update operation has completed. |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CMceIAUpdateUtils::UpdateComplete( TInt aErrorCode, CIAUpdateResult* aResult ) |
|
183 { |
|
184 if ( aErrorCode == KErrNone ) |
|
185 { |
|
186 // The update process that the user started from IAUpdate UI is now |
|
187 // completed. |
|
188 // If the client application itself was updated in the update process, |
|
189 // this callback is never called, since the client is not running anymore. |
|
190 MCELOGGER_WRITE("UpdateComplete ---"); |
|
191 TInt successCount = aResult->SuccessCount(); |
|
192 } |
|
193 |
|
194 if( aResult ) |
|
195 { |
|
196 // Ownership was transferred, so this must be deleted by the client. |
|
197 delete aResult; |
|
198 } |
|
199 |
|
200 // We do not need the client-server session anymore. |
|
201 Delete(); |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // From class MIAUpdateObserver. |
|
206 // This callback function is called when an update query operation has completed. |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CMceIAUpdateUtils::UpdateQueryComplete( TInt aErrorCode, TBool aUpdateNow ) |
|
210 { |
|
211 TBool bContinue = EFalse; |
|
212 if ( aErrorCode == KErrNone ) |
|
213 { |
|
214 if ( aUpdateNow ) |
|
215 { |
|
216 // User choosed to update now, so let's launch the IAUpdate UI. |
|
217 MCELOGGER_WRITE("UpdateQueryComplete --- now"); |
|
218 iUpdate->ShowUpdates( *iParameters ); |
|
219 bContinue = ETrue; |
|
220 } |
|
221 else |
|
222 { |
|
223 // The answer was 'Later'. |
|
224 MCELOGGER_WRITE("UpdateQueryComplete --- later"); |
|
225 } |
|
226 } |
|
227 if(!bContinue) |
|
228 { |
|
229 Delete(); //Delete session with IAD server |
|
230 } |
|
231 } |
|
232 // ----------------------------------------------------------------------------- |
|
233 // From class MIAUpdateObserver. |
|
234 // This callback function is called when an update query operation has completed. |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CMceIAUpdateUtils::StartL(const TUid aAppUid) |
|
238 { |
|
239 if (IsActive()) |
|
240 { |
|
241 return; |
|
242 } |
|
243 iAppUid = aAppUid; |
|
244 CompleteSelf(); |
|
245 } |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 // For Setting the Active Object Active |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 void CMceIAUpdateUtils::CompleteSelf() |
|
252 { |
|
253 iStatus = KRequestPending; |
|
254 TRequestStatus* pStatus = &iStatus; |
|
255 SetActive(); |
|
256 User::RequestComplete( pStatus, KErrNone ); |
|
257 } |
|
258 // ----------------------------------------------------------------------------- |
|
259 // From class CActive. |
|
260 // For Starting the update in a seperate Thread |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 void CMceIAUpdateUtils::RunL() |
|
264 { |
|
265 DoStartL( iAppUid ); |
|
266 } |
|
267 // ----------------------------------------------------------------------------- |
|
268 // From class CActive. |
|
269 // Nothing to do here |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CMceIAUpdateUtils::DoCancel() |
|
273 { |
|
274 |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // Is IAD Update requried to do now |
|
279 // YES, If the KMceIADUpdateCheckRetryInterval is over after the previous try |
|
280 // NO, If the KMceIADUpdateCheckRetryInterval is not over after the previous retry |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 TBool CMceIAUpdateUtils::IsUpdateRequired() |
|
284 { |
|
285 TBool required = EFalse; |
|
286 TTime currTime; |
|
287 TTimeIntervalHours hourInterval; |
|
288 TInt err = KErrNone; |
|
289 |
|
290 currTime.UniversalTime(); |
|
291 |
|
292 err = currTime.HoursFrom(iPrevIADUpdateCheckTry,hourInterval); |
|
293 |
|
294 // KErrNone-> successful case, |
|
295 // reset the iPrevIADUpdateCheckTry to current time, |
|
296 // start IAD check update |
|
297 |
|
298 // KErrOverflow -> if the calculated interval |
|
299 // is too large for a 32-bit integer |
|
300 // reset the iPrevIADUpdateCheckTry to current time |
|
301 // start IAD check update |
|
302 |
|
303 // in all other cases don't do any thing. |
|
304 |
|
305 if(((err == KErrNone)&& |
|
306 (hourInterval.Int() >= KMceIADUpdateCheckRetryInterval )) |
|
307 ||(err == KErrOverflow)) |
|
308 { |
|
309 iPrevIADUpdateCheckTry.UniversalTime(); |
|
310 required = ETrue; |
|
311 } |
|
312 |
|
313 return required; |
|
314 } |
|
315 // EOF |