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