1 /* |
|
2 * Copyright (c) 2002-2006 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: Helper class for saving Provisioning settings. |
|
15 * Provides a progress note. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <AknQueryDialog.h> |
|
23 #include <eikprogi.h> |
|
24 #include <PnpProvisioning.rsg> |
|
25 #include <commdb.h> |
|
26 #include <CWPEngine.h> |
|
27 #include <CWPAdapter.h> |
|
28 #include <ActiveFavouritesDbNotifier.h> |
|
29 |
|
30 #include "PnpProvisioningSaver.h" |
|
31 #include "PnpLogger.h" |
|
32 #include "cwaitdialogmonitor.h" |
|
33 |
|
34 // CONSTANTS |
|
35 const TInt KMaxWaitTime = 1000000; |
|
36 |
|
37 // CLASS DECLARATION |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 // C++ default constructor. |
|
42 CPnpProvisioningSaver::CPnpProvisioningSaver( CWPEngine& aEngine, TBool aSetAsDefault, TBool aWaitNote ) |
|
43 : CActive( EPriorityStandard ), iEngine( aEngine ), |
|
44 iSetAsDefault( aSetAsDefault ), |
|
45 iCurrentItem( 0 ), iResult( KErrNone ),iEndKeyPressed(EFalse), iShowWaitNote(aWaitNote) |
|
46 { |
|
47 CActiveScheduler::Add( this ); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------- |
|
51 // CPnpProvisioningSaver::ExecuteLD |
|
52 // --------------------------------------------------------- |
|
53 // |
|
54 void CPnpProvisioningSaver::PrepareLC() |
|
55 { |
|
56 // Assume ownership of this. |
|
57 CleanupStack::PushL( this ); |
|
58 |
|
59 iApDbNotifier = CActiveApDb::NewL( EDatabaseTypeIAP ); |
|
60 iApDbNotifier->AddObserverL( this ); |
|
61 |
|
62 iRetryTimer = CPeriodic::NewL( EPriorityStandard ); |
|
63 |
|
64 LOGSTRING("Constructing dialog"); |
|
65 |
|
66 // Set up the dialog and callback mechanism. |
|
67 if(iSetAsDefault && iShowWaitNote) |
|
68 ShowWaitNoteL(); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------- |
|
72 // CPnpProvisioningSaver::ExecuteLD |
|
73 // --------------------------------------------------------- |
|
74 // |
|
75 TInt CPnpProvisioningSaver::ExecuteLD( TInt& aNumSaved ) |
|
76 { |
|
77 LOGSTRING( "ExecuteLD" ); |
|
78 PrepareLC(); |
|
79 |
|
80 // make sure RunL() gets called. |
|
81 CompleteRequest(); |
|
82 iWait.Start(); |
|
83 |
|
84 LOGSTRING("iWait.Start done"); |
|
85 // Progress note has been finished/cancelled. Cache the result |
|
86 // and delete this. |
|
87 TInt result( iResult ); |
|
88 aNumSaved = iCurrentItem; |
|
89 CleanupStack::PopAndDestroy( this ); // this |
|
90 LOGSTRING( "PopAndDestroy( this ), done" ); |
|
91 |
|
92 return result; |
|
93 } |
|
94 |
|
95 // Destructor |
|
96 // --------------------------------------------------------- |
|
97 // CPnpProvisioningSaver::~CPnpProvisioningSaver |
|
98 // --------------------------------------------------------- |
|
99 // |
|
100 CPnpProvisioningSaver::~CPnpProvisioningSaver() |
|
101 { |
|
102 LOGSTRING( "~CPnpProvisioningSaver" ); |
|
103 |
|
104 if( IsActive() ) |
|
105 { |
|
106 Cancel(); |
|
107 } |
|
108 |
|
109 if( iApDbNotifier ) |
|
110 { |
|
111 iApDbNotifier->RemoveObserver( this ); |
|
112 delete iApDbNotifier; |
|
113 } |
|
114 |
|
115 if( iRetryTimer ) |
|
116 { |
|
117 if( iRetryTimer->IsActive() ) |
|
118 { |
|
119 iRetryTimer->Cancel(); |
|
120 } |
|
121 delete iRetryTimer; |
|
122 } |
|
123 |
|
124 |
|
125 if( iGlobalWaitNote ) |
|
126 { |
|
127 delete iGlobalWaitNote; |
|
128 } |
|
129 |
|
130 if( iWaitDialogMonitor ) |
|
131 { |
|
132 iWaitDialogMonitor->Cancel(); |
|
133 delete iWaitDialogMonitor; |
|
134 } |
|
135 |
|
136 LOGSTRING( "~CPnpProvisioningSaver - done" ); |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------- |
|
140 // CPnpProvisioningSaver::DoCancel |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 void CPnpProvisioningSaver::DoCancel() |
|
144 { |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------- |
|
148 // CPnpProvisioningSaver::RunL |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 void CPnpProvisioningSaver::RunL() |
|
152 { |
|
153 // Choose whether to save or set as default |
|
154 TInt err( KErrNone ); |
|
155 if( iSetAsDefault ) |
|
156 { |
|
157 TRAP( err, |
|
158 if( iEngine.CanSetAsDefault( iCurrentItem ) ) |
|
159 { |
|
160 iEngine.SetAsDefaultL( iCurrentItem ); |
|
161 } ); |
|
162 } |
|
163 else |
|
164 { |
|
165 |
|
166 LOGSTRING2("Saving item: %i", iCurrentItem ); |
|
167 TRAP( err, iEngine.SaveL( iCurrentItem ) ); |
|
168 |
|
169 } |
|
170 |
|
171 // If CommsDB or BookmarkDB are locked, schedule a retry |
|
172 if( err == EWPCommsDBLocked ) |
|
173 { |
|
174 LOGSTRING( "CPnpProvisioningSaver: EWPCommsDBLocked" ); |
|
175 iWaitCommsDb = ETrue; |
|
176 DelayedCompleteRequest(); |
|
177 return; |
|
178 } |
|
179 else if( err == EWPBookmarksLocked ) |
|
180 { |
|
181 LOGSTRING( "CPnpProvisioningSaver: EWPBookmarksLocked" ); |
|
182 iWaitFavourites = ETrue; |
|
183 DelayedCompleteRequest(); |
|
184 return; |
|
185 } |
|
186 else if( err == KErrLocked ) |
|
187 { |
|
188 LOGSTRING( "CPnpProvisioningSaver: KErrLocked" ); |
|
189 // Assume that commsdb caused the error |
|
190 iWaitCommsDb = ETrue; |
|
191 DelayedCompleteRequest(); |
|
192 return; |
|
193 } |
|
194 // For all other errors, pass them through. |
|
195 User::LeaveIfError( err ); |
|
196 |
|
197 // Normal progress |
|
198 if( iCurrentItem == iEngine.ItemCount()-1 ) |
|
199 { |
|
200 LOGSTRING("All saved"); |
|
201 //LOGSTRING2( "Saver RunL iWaitDialogMonitor->iStatus %i", iWaitDialogMonitor->iStatus.Int() ); |
|
202 ProcessFinishedL(); |
|
203 } |
|
204 else |
|
205 { |
|
206 //LOGSTRING2( "Saver RunL 2nd iWaitDialogMonitor->iStatus %i", iWaitDialogMonitor->iStatus.Int() ); |
|
207 iCurrentItem++; |
|
208 CompleteRequest(); |
|
209 } |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------- |
|
213 // CPnpProvisioningSaver::ProcessFinishedL |
|
214 // --------------------------------------------------------- |
|
215 // |
|
216 void CPnpProvisioningSaver::ProcessFinishedL() |
|
217 { |
|
218 //LOGSTRING2( "Saver iWaitDialogMonitor->iStatus %i", iWaitDialogMonitor->iStatus.Int() ); |
|
219 iWait.AsyncStop(); |
|
220 if(iWaitDialogMonitor) |
|
221 { |
|
222 //End key or cancel pressed after saving settings |
|
223 if(iWaitDialogMonitor->iStatus == KErrCancel) |
|
224 { |
|
225 iEndKeyPressed = ETrue; |
|
226 } |
|
227 if( iGlobalWaitNote ) |
|
228 { |
|
229 delete iGlobalWaitNote; |
|
230 iGlobalWaitNote = NULL; |
|
231 } |
|
232 } |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------- |
|
236 // CPnpProvisioningSaver::RunError |
|
237 // --------------------------------------------------------- |
|
238 // |
|
239 TInt CPnpProvisioningSaver::RunError( TInt aError ) |
|
240 { |
|
241 LOGSTRING2( "RunError: %i", aError ); |
|
242 // There was a leave in RunL(). Store the error and |
|
243 // stop the dialog. |
|
244 iResult = aError; |
|
245 TInt err(KErrNone); |
|
246 TRAP( err, ProcessFinishedL() ); |
|
247 |
|
248 return KErrNone; |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CPnpProvisioningSaver::ShowWaitNoteL |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 void CPnpProvisioningSaver::ShowWaitNoteL() |
|
256 { |
|
257 HBufC* msgText = CEikonEnv::Static()-> |
|
258 AllocReadResourceLC( R_TEXT_WAIT_SAVING ); |
|
259 |
|
260 if (iWaitDialogMonitor) |
|
261 { |
|
262 iWaitDialogMonitor->Cancel(); |
|
263 delete iWaitDialogMonitor; |
|
264 iWaitDialogMonitor = NULL; |
|
265 } |
|
266 // instantiate the active object CGlobalConfirmationObserver |
|
267 iWaitDialogMonitor = CWaitDialogMonitor::NewL( *this ); |
|
268 |
|
269 // SetActive |
|
270 iWaitDialogMonitor->Start(); |
|
271 |
|
272 if (!iGlobalWaitNote) |
|
273 { |
|
274 iGlobalWaitNote = CAknGlobalNote::NewL(); |
|
275 } |
|
276 |
|
277 iGlobalWaitNote->SetSoftkeys( R_AVKON_SOFTKEYS_EMPTY); |
|
278 |
|
279 iGlobalWaitNote->ShowNoteL( |
|
280 iWaitDialogMonitor->iStatus, |
|
281 EAknGlobalWaitNote, |
|
282 *msgText ); |
|
283 |
|
284 CleanupStack::PopAndDestroy( msgText ); |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------- |
|
288 // CPnpProvisioningSaver::WaitDialogDismissedL |
|
289 // --------------------------------------------------------- |
|
290 // |
|
291 void CPnpProvisioningSaver::WaitDialogDismissedL( const TInt aStatusCode ) |
|
292 { |
|
293 LOGSTRING( "DialogDismissedL" ); |
|
294 if( aStatusCode == EAknSoftkeyCancel || aStatusCode == EAknSoftkeyExit ) |
|
295 { |
|
296 LOGSTRING( "setting to KErrCancel" ); |
|
297 iResult = KErrCancel; |
|
298 } |
|
299 //pressed end key and not all settings saved |
|
300 if( aStatusCode== KErrCancel && iEndKeyPressed ) |
|
301 { |
|
302 LOGSTRING( "End key pressed" ); |
|
303 iResult = KErrCancel; |
|
304 } |
|
305 |
|
306 iWait.AsyncStop(); |
|
307 } |
|
308 |
|
309 |
|
310 // --------------------------------------------------------- |
|
311 // CPnpProvisioningSaver::CompleteRequest |
|
312 // --------------------------------------------------------- |
|
313 // |
|
314 void CPnpProvisioningSaver::CompleteRequest() |
|
315 { |
|
316 // Schedule an immediate complete. Make sure that there |
|
317 // is no timer alive first |
|
318 if( IsActive() ) |
|
319 { |
|
320 Cancel(); |
|
321 } |
|
322 if( iRetryTimer->IsActive() ) |
|
323 { |
|
324 iRetryTimer->Cancel(); |
|
325 } |
|
326 SetActive(); |
|
327 TRequestStatus* sp = &iStatus; |
|
328 User::RequestComplete( sp, KErrNone ); |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------- |
|
332 // CPnpProvisioningSaver::DelayedCompleteRequest |
|
333 // --------------------------------------------------------- |
|
334 // |
|
335 void CPnpProvisioningSaver::DelayedCompleteRequest() |
|
336 { |
|
337 // Schedule a delayed complete. Cancel first in case |
|
338 // an immediate request was scheduled. |
|
339 if( IsActive() ) |
|
340 { |
|
341 Cancel(); |
|
342 } |
|
343 if( iRetryTimer->IsActive() ) |
|
344 { |
|
345 iRetryTimer->Cancel(); |
|
346 } |
|
347 |
|
348 iRetryTimer->Start( KMaxWaitTime, 0, TCallBack( Timeout, this ) ); |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------- |
|
352 // CPnpProvisioningSaver::Retry |
|
353 // --------------------------------------------------------- |
|
354 // |
|
355 void CPnpProvisioningSaver::Retry() |
|
356 { |
|
357 // Immediate retry. Mark that we're not waiting |
|
358 // for an event and complete request. |
|
359 iWaitCommsDb = EFalse; |
|
360 iWaitFavourites = EFalse; |
|
361 CompleteRequest(); |
|
362 } |
|
363 |
|
364 // --------------------------------------------------------- |
|
365 // CPnpProvisioningSaver::Timeout |
|
366 // --------------------------------------------------------- |
|
367 // |
|
368 TInt CPnpProvisioningSaver::Timeout(TAny* aSelf) |
|
369 { |
|
370 // There was a time-out. Retry saving even though we |
|
371 // didn't get a notify from database. |
|
372 CPnpProvisioningSaver* self = STATIC_CAST(CPnpProvisioningSaver*, aSelf); |
|
373 self->Retry(); |
|
374 |
|
375 return KErrNone; |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------- |
|
379 // CPnpProvisioningSaver::HandleApDbEventL |
|
380 // --------------------------------------------------------- |
|
381 // |
|
382 void CPnpProvisioningSaver::HandleApDbEventL( TEvent aEvent ) |
|
383 { |
|
384 // We received an event from CommsDB. Retry if we're |
|
385 // waiting for it. |
|
386 if( iWaitCommsDb && aEvent == EDbAvailable ) |
|
387 { |
|
388 Retry(); |
|
389 } |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------- |
|
393 // CPnpProvisioningSaver::HandleFavouritesDbEventL |
|
394 // --------------------------------------------------------- |
|
395 // |
|
396 void CPnpProvisioningSaver::HandleFavouritesDbEventL( RDbNotifier::TEvent /*aEvent*/ ) |
|
397 { |
|
398 // We received an event from BookmarkDB. Retry if we're |
|
399 // waiting for it. |
|
400 if( iWaitFavourites ) |
|
401 { |
|
402 Retry(); |
|
403 } |
|
404 } |
|
405 |
|
406 // End of File |
|
407 |
|