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. Provides a progress note. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CWPCxDeleter.h" |
|
21 #include <aknquerydialog.h> |
|
22 #include <eikprogi.h> |
|
23 #include <ProvisioningCx.rsg> |
|
24 #include <commdb.h> |
|
25 #include <CWPEngine.h> |
|
26 #include <CWPAdapter.h> |
|
27 #include <ActiveFavouritesDbNotifier.h> |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KMaxWaitTime = 2000000; |
|
31 const TInt KRetryCount = 5; |
|
32 |
|
33 // CLASS DECLARATION |
|
34 |
|
35 // ================= MEMBER FUNCTIONS ======================= |
|
36 |
|
37 // C++ default constructor. |
|
38 CWPCxDeleter::CWPCxDeleter( CWPEngine& aEngine, TUint32 aContext ) |
|
39 : CActive( EPriorityStandard ), iEngine( aEngine ), |
|
40 iContext( aContext ), |
|
41 iCurrentItem( 0 ), iResult( KErrNone ) |
|
42 { |
|
43 } |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // CWPCxDeleter::ExecuteLD |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 void CWPCxDeleter::PrepareLC() |
|
50 { |
|
51 // Assume ownership of this. |
|
52 CleanupStack::PushL( this ); |
|
53 |
|
54 iApDbNotifier = CActiveApDb::NewL( EDatabaseTypeIAP ); |
|
55 iApDbNotifier->AddObserverL( this ); |
|
56 |
|
57 User::LeaveIfError( iSession.Connect() ); |
|
58 User::LeaveIfError( iBookmarkDb.Open( iSession, KBrowserBookmarks ) ); |
|
59 iFavouritesNotifier = new(ELeave) CActiveFavouritesDbNotifier( iBookmarkDb, *this ); |
|
60 |
|
61 iFavouritesNotifier->Start(); |
|
62 |
|
63 iRetryTimer = CPeriodic::NewL( EPriorityStandard ); |
|
64 |
|
65 // Set up the dialog and callback mechanism. |
|
66 iDialog = new(ELeave)CAknProgressDialog( |
|
67 reinterpret_cast<CEikDialog**>(&iDialog), EFalse ); |
|
68 iDialog->SetCallback( this ); |
|
69 iDialog->ExecuteLD(R_WAITNOTE_DELETE); |
|
70 CEikProgressInfo* progressInfo = iDialog->GetProgressInfoL(); |
|
71 progressInfo->SetAndDraw(iCurrentItem); |
|
72 progressInfo->SetFinalValue(iEngine.ContextDataCountL(iContext)); |
|
73 } |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // CWPCxDeleter::ExecuteLD |
|
77 // ---------------------------------------------------------------------------- |
|
78 // |
|
79 TInt CWPCxDeleter::ExecuteLD( TInt& aNumDeleted ) |
|
80 { |
|
81 PrepareLC(); |
|
82 |
|
83 // Add us to active scheduler and make sure RunL() gets called. |
|
84 CActiveScheduler::Add( this ); |
|
85 CompleteRequest(); |
|
86 iWait.Start(); |
|
87 |
|
88 // Progress note has been finished/cancelled. Cache the result |
|
89 // and delete this. |
|
90 TInt result( iResult ); |
|
91 aNumDeleted = iCurrentItem; |
|
92 CleanupStack::PopAndDestroy(); // this |
|
93 |
|
94 return result; |
|
95 } |
|
96 |
|
97 // Destructor |
|
98 CWPCxDeleter::~CWPCxDeleter() |
|
99 { |
|
100 Cancel(); |
|
101 |
|
102 delete iApDbNotifier; |
|
103 |
|
104 if( iFavouritesNotifier ) |
|
105 { |
|
106 iFavouritesNotifier->Cancel(); |
|
107 delete iFavouritesNotifier; |
|
108 } |
|
109 |
|
110 iBookmarkDb.Close(); |
|
111 iSession.Close(); |
|
112 |
|
113 delete iRetryTimer; |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------- |
|
117 // CWPCxDeleter::DoCancel |
|
118 // ---------------------------------------------------------------------------- |
|
119 // |
|
120 void CWPCxDeleter::DoCancel() |
|
121 { |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CWPCxDeleter::RunL |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 void CWPCxDeleter::RunL() |
|
129 { |
|
130 // Choose whether to save or set as default |
|
131 TBool more( EFalse ); |
|
132 TRAPD( err, more = iEngine.DeleteContextDataL( iContext ) ); |
|
133 |
|
134 // If CommsDB or BookmarkDB are locked, schedule a retry |
|
135 if( err == EWPCommsDBLocked ) |
|
136 { |
|
137 iWaitCommsDb = ETrue; |
|
138 DelayedCompleteRequestL(); |
|
139 return; |
|
140 } |
|
141 else if( err == EWPBookmarksLocked ) |
|
142 { |
|
143 iWaitFavourites = ETrue; |
|
144 DelayedCompleteRequestL(); |
|
145 return; |
|
146 } |
|
147 else if( err != KErrNone ) |
|
148 { |
|
149 // For all other errors, pass them through. |
|
150 User::LeaveIfError( err ); |
|
151 } |
|
152 // Succesful save, so reset retry count |
|
153 iRetryCount = 0; |
|
154 |
|
155 // Normal progress |
|
156 if( !more ) |
|
157 { |
|
158 iDialog->ProcessFinishedL(); |
|
159 } |
|
160 else |
|
161 { |
|
162 CEikProgressInfo* progressInfo = iDialog->GetProgressInfoL(); |
|
163 iCurrentItem++; |
|
164 progressInfo->SetAndDraw(iCurrentItem); |
|
165 CompleteRequest(); |
|
166 } |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------- |
|
170 // CWPCxDeleter::RunError |
|
171 // --------------------------------------------------------- |
|
172 // |
|
173 TInt CWPCxDeleter::RunError( TInt aError ) |
|
174 { |
|
175 // There was a leave in RunL(). Store the error and |
|
176 // stop the dialog. |
|
177 iResult = aError; |
|
178 iWait.AsyncStop(); |
|
179 delete iDialog; |
|
180 iDialog = NULL; |
|
181 |
|
182 return KErrNone; |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CWPCxDeleter::DialogDismissedL |
|
187 // --------------------------------------------------------- |
|
188 // |
|
189 void CWPCxDeleter::DialogDismissedL( TInt aButtonId ) |
|
190 { |
|
191 if( aButtonId < 0 ) |
|
192 { |
|
193 iResult = KErrCancel; |
|
194 } |
|
195 |
|
196 iWait.AsyncStop(); |
|
197 } |
|
198 |
|
199 // ---------------------------------------------------------------------------- |
|
200 // CWPCxDeleter::CompleteRequest |
|
201 // ---------------------------------------------------------------------------- |
|
202 // |
|
203 void CWPCxDeleter::CompleteRequest() |
|
204 { |
|
205 // Schedule an immediate complete. Make sure that there |
|
206 // is no timer alive first |
|
207 Cancel(); |
|
208 iRetryTimer->Cancel(); |
|
209 |
|
210 SetActive(); |
|
211 TRequestStatus* sp = &iStatus; |
|
212 User::RequestComplete( sp, KErrNone ); |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------------------------------- |
|
216 // CWPCxDeleter::DelayedCompleteRequestL |
|
217 // ---------------------------------------------------------------------------- |
|
218 // |
|
219 void CWPCxDeleter::DelayedCompleteRequestL() |
|
220 { |
|
221 if( iRetryCount < KRetryCount ) |
|
222 { |
|
223 // Schedule a delayed complete. |
|
224 iRetryTimer->Cancel(); |
|
225 iRetryTimer->Start( KMaxWaitTime, KMaxTInt32, TCallBack( Timeout, this ) ); |
|
226 iRetryCount++; |
|
227 } |
|
228 else |
|
229 { |
|
230 User::Leave( KErrTimedOut ); |
|
231 } |
|
232 } |
|
233 |
|
234 // ---------------------------------------------------------------------------- |
|
235 // CWPCxDeleter::Retry |
|
236 // ---------------------------------------------------------------------------- |
|
237 // |
|
238 void CWPCxDeleter::Retry() |
|
239 { |
|
240 // Immediate retry. Mark that we're not waiting |
|
241 // for an event and complete request. |
|
242 |
|
243 iWaitCommsDb = EFalse; |
|
244 iWaitFavourites = EFalse; |
|
245 CompleteRequest(); |
|
246 } |
|
247 |
|
248 // ---------------------------------------------------------------------------- |
|
249 // CWPCxDeleter::Timeout |
|
250 // ---------------------------------------------------------------------------- |
|
251 // |
|
252 TInt CWPCxDeleter::Timeout(TAny* aSelf) |
|
253 { |
|
254 // There was a time-out. Retry saving even though we |
|
255 // didn't get a notify from database. |
|
256 CWPCxDeleter* self = STATIC_CAST(CWPCxDeleter*, aSelf); |
|
257 self->Retry(); |
|
258 |
|
259 return KErrNone; |
|
260 } |
|
261 |
|
262 // ---------------------------------------------------------------------------- |
|
263 // CWPCxDeleter::HandleApDbEventL |
|
264 // ---------------------------------------------------------------------------- |
|
265 // |
|
266 void CWPCxDeleter::HandleApDbEventL( TEvent aEvent ) |
|
267 { |
|
268 // We received an event from CommsDB. Retry if we're |
|
269 // waiting for it. |
|
270 if( iWaitCommsDb && aEvent == EDbAvailable ) |
|
271 { |
|
272 Retry(); |
|
273 } |
|
274 } |
|
275 |
|
276 // ---------------------------------------------------------------------------- |
|
277 // CWPCxDeleter::HandleFavouritesDbEventL |
|
278 // ---------------------------------------------------------------------------- |
|
279 // |
|
280 void CWPCxDeleter::HandleFavouritesDbEventL( RDbNotifier::TEvent /*aEvent*/ ) |
|
281 { |
|
282 // We received an event from BookmarkDB. Retry if we're |
|
283 // waiting for it. |
|
284 if( iWaitFavourites ) |
|
285 { |
|
286 Retry(); |
|
287 } |
|
288 } |
|
289 |
|
290 // End of File |
|
291 |
|