|
1 /* |
|
2 * Copyright (c) 2009 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: Phonebook 2 delete mycard command. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cpbk2deletemycardcmd.h" |
|
21 #include <StringLoader.h> |
|
22 #include <AknQueryDialog.h> |
|
23 #include <Pbk2ExNamesListRes.rsg> |
|
24 |
|
25 // Phonebook2 |
|
26 #include <CPbk2ApplicationServices.h> |
|
27 #include <MPbk2CommandObserver.h> |
|
28 #include <Pbk2UIControls.rsg> |
|
29 #include <MPbk2ContactUiControl.h> |
|
30 #include <MPbk2ContactNameFormatter.h> |
|
31 #include <CPbk2GeneralConfirmationQuery.h> |
|
32 |
|
33 // Virtual Phonebook |
|
34 #include <CVPbkContactManager.h> |
|
35 #include <MVPbkContactLink.h> |
|
36 #include <MVPbkStoreContact.h> |
|
37 #include <MVPbkContactOperationBase.h> |
|
38 #include <CVPbkContactLinkArray.h> |
|
39 |
|
40 // Debugging headers |
|
41 #include <Pbk2Debug.h> |
|
42 |
|
43 |
|
44 /// Unnamed namespace for local definitions |
|
45 namespace { |
|
46 |
|
47 // LOCAL DEBUG CODE |
|
48 #ifdef _DEBUG |
|
49 enum TPanicCode |
|
50 { |
|
51 ERunL_InvalidState = 1, |
|
52 EPanicPreCond_Null_Pointer, |
|
53 EPanicInvalidArray |
|
54 }; |
|
55 |
|
56 void Panic(TPanicCode aReason) |
|
57 { |
|
58 _LIT(KPanicText, "CPbk2DeleteMyCardCmd"); |
|
59 User::Panic(KPanicText,aReason); |
|
60 } |
|
61 #endif // _DEBUG |
|
62 } |
|
63 |
|
64 // -------------------------------------------------------------------------- |
|
65 // CPbk2DeleteMyCardCmd::CPbk2DeleteMyCardCmd |
|
66 // -------------------------------------------------------------------------- |
|
67 // |
|
68 inline CPbk2DeleteMyCardCmd::CPbk2DeleteMyCardCmd( |
|
69 MPbk2ContactUiControl& aUiControl ) : |
|
70 CActive( EPriorityIdle ), |
|
71 iUiControl( &aUiControl ) |
|
72 { |
|
73 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
74 ("CPbk2DeleteMyCardCmd::CPbk2DeleteMyCardCmd(0x%x)"), this); |
|
75 |
|
76 CActiveScheduler::Add( this ); |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // CPbk2DeleteMyCardCmd::~CPbk2DeleteMyCardCmd |
|
81 // -------------------------------------------------------------------------- |
|
82 // |
|
83 CPbk2DeleteMyCardCmd::~CPbk2DeleteMyCardCmd() |
|
84 { |
|
85 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
86 ("CPbk2DeleteMyCardCmd::~CPbk2DeleteMyCardCmd(0x%x)"), this); |
|
87 |
|
88 Cancel(); |
|
89 if( iUiControl ) |
|
90 { |
|
91 iUiControl->RegisterCommand(NULL); |
|
92 } |
|
93 |
|
94 delete iContactsArray; |
|
95 delete iDeleteOperation; |
|
96 Release( iAppServices ); |
|
97 } |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // CPbk2DeleteMyCardCmd::ConstructL |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 inline void CPbk2DeleteMyCardCmd::ConstructL( |
|
104 const MVPbkContactLink& aLink ) |
|
105 { |
|
106 iContactsArray = CVPbkContactLinkArray::NewL(); |
|
107 iContactsArray->AppendL( aLink.CloneLC() ); |
|
108 CleanupStack::Pop(); // link |
|
109 |
|
110 iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
111 |
|
112 // register command to ui control |
|
113 iUiControl->RegisterCommand(this); |
|
114 } |
|
115 |
|
116 // -------------------------------------------------------------------------- |
|
117 // CPbk2DeleteMyCardCmd::NewL |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 CPbk2DeleteMyCardCmd* CPbk2DeleteMyCardCmd::NewL( |
|
121 MPbk2ContactUiControl& aUiControl, |
|
122 const MVPbkContactLink& aLink ) |
|
123 { |
|
124 CPbk2DeleteMyCardCmd* self = new(ELeave) CPbk2DeleteMyCardCmd( aUiControl ); |
|
125 CleanupStack::PushL( self ); |
|
126 self->ConstructL( aLink ); |
|
127 CleanupStack::Pop( self ); |
|
128 return self; |
|
129 } |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CPbk2DeleteMyCardCmd::ExecuteLD |
|
133 // -------------------------------------------------------------------------- |
|
134 // |
|
135 void CPbk2DeleteMyCardCmd::ExecuteLD() |
|
136 { |
|
137 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
138 ("CPbk2DeleteMyCardCmd::ExecuteLD(0x%x)"), this); |
|
139 |
|
140 IssueRequest( EConfirming ); |
|
141 } |
|
142 |
|
143 // -------------------------------------------------------------------------- |
|
144 // CPbk2DeleteMyCardCmd::AddObserver |
|
145 // -------------------------------------------------------------------------- |
|
146 // |
|
147 void CPbk2DeleteMyCardCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
148 { |
|
149 iCommandObserver = &aObserver; |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------------- |
|
153 // CPbk2DeleteMyCardCmd::ResetUiControl |
|
154 // -------------------------------------------------------------------------- |
|
155 // |
|
156 void CPbk2DeleteMyCardCmd::ResetUiControl( |
|
157 MPbk2ContactUiControl& aUiControl ) |
|
158 { |
|
159 if( iUiControl == &aUiControl ) |
|
160 { |
|
161 iUiControl = NULL; |
|
162 } |
|
163 } |
|
164 |
|
165 // -------------------------------------------------------------------------- |
|
166 // CPbk2DeleteMyCardCmd::DoCancel |
|
167 // -------------------------------------------------------------------------- |
|
168 // |
|
169 void CPbk2DeleteMyCardCmd::DoCancel() |
|
170 { |
|
171 } |
|
172 |
|
173 // -------------------------------------------------------------------------- |
|
174 // CPbk2DeleteMyCardCmd::RunL |
|
175 // -------------------------------------------------------------------------- |
|
176 // |
|
177 void CPbk2DeleteMyCardCmd::RunL() |
|
178 { |
|
179 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
180 ("CPbk2DeleteMyCardCmd::RunL(0x%x) start"), this); |
|
181 |
|
182 switch ( iState ) |
|
183 { |
|
184 case EConfirming: |
|
185 { |
|
186 ConfirmDeletionL(); |
|
187 break; |
|
188 } |
|
189 case EStarting: |
|
190 { |
|
191 DeleteContactL(); |
|
192 break; |
|
193 } |
|
194 case EStopping: |
|
195 { |
|
196 ProcessDismissed( KErrNone ); |
|
197 break; |
|
198 } |
|
199 case ECanceling: |
|
200 { |
|
201 ProcessDismissed( KErrCancel ); |
|
202 break; |
|
203 } |
|
204 default: |
|
205 { |
|
206 __ASSERT_DEBUG(EFalse, Panic(ERunL_InvalidState)); |
|
207 break; |
|
208 } |
|
209 } |
|
210 |
|
211 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING("CPbk2DeleteMyCardCmd::RunL end")); |
|
212 } |
|
213 |
|
214 // -------------------------------------------------------------------------- |
|
215 // CPbk2DeleteMyCardCmd::RunError |
|
216 // -------------------------------------------------------------------------- |
|
217 // |
|
218 TInt CPbk2DeleteMyCardCmd::RunError( TInt aError ) |
|
219 { |
|
220 ProcessDismissed( aError ); |
|
221 return aError; |
|
222 } |
|
223 |
|
224 // -------------------------------------------------------------------------- |
|
225 // CPbk2DeleteMyCardCmd::StepComplete |
|
226 // -------------------------------------------------------------------------- |
|
227 // |
|
228 void CPbk2DeleteMyCardCmd::StepComplete( |
|
229 MVPbkContactOperationBase& /*aOperation*/, TInt /*aStepSize*/ ) |
|
230 { |
|
231 // ignored |
|
232 } |
|
233 |
|
234 // -------------------------------------------------------------------------- |
|
235 // CPbk2DeleteMyCardCmd::StepFailed |
|
236 // -------------------------------------------------------------------------- |
|
237 // |
|
238 TBool CPbk2DeleteMyCardCmd::StepFailed( |
|
239 MVPbkContactOperationBase& /*aOperation*/, |
|
240 TInt /*aStepSize*/, |
|
241 TInt aError ) |
|
242 { |
|
243 ProcessDismissed( aError ); |
|
244 |
|
245 if ( aError == KErrInUse ) |
|
246 { |
|
247 CCoeEnv::Static()->HandleError( KErrInUse ); |
|
248 } |
|
249 |
|
250 return EFalse; |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // CPbk2DeleteMyCardCmd::OperationComplete |
|
255 // -------------------------------------------------------------------------- |
|
256 // |
|
257 void CPbk2DeleteMyCardCmd::OperationComplete( |
|
258 MVPbkContactOperationBase& aOperation ) |
|
259 { |
|
260 if ( &aOperation == iDeleteOperation ) |
|
261 { |
|
262 delete iDeleteOperation; |
|
263 iDeleteOperation = NULL; |
|
264 |
|
265 IssueRequest( EStopping ); |
|
266 } |
|
267 } |
|
268 |
|
269 // -------------------------------------------------------------------------- |
|
270 // CPbk2DeleteMyCardCmd::ProcessDismissed |
|
271 // -------------------------------------------------------------------------- |
|
272 // |
|
273 void CPbk2DeleteMyCardCmd::ProcessDismissed( TInt aCancelCode ) |
|
274 { |
|
275 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
276 ("CPbk2DeleteMyCardCmd::ProcessDismissed()")); |
|
277 |
|
278 __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_Null_Pointer)); |
|
279 |
|
280 Cancel(); |
|
281 delete iDeleteOperation; |
|
282 iDeleteOperation = NULL; |
|
283 |
|
284 if ( aCancelCode != KErrCancel && iUiControl) |
|
285 { |
|
286 // Don't remove list markings if user canceled |
|
287 iUiControl->SetBlank(EFalse); |
|
288 iUiControl->UpdateAfterCommandExecution(); |
|
289 } |
|
290 |
|
291 // Notify command owner that the command has finished |
|
292 iCommandObserver->CommandFinished( *this ); |
|
293 } |
|
294 |
|
295 // -------------------------------------------------------------------------- |
|
296 // CPbk2DeleteMyCardCmd::DeleteContactL |
|
297 // -------------------------------------------------------------------------- |
|
298 // |
|
299 void CPbk2DeleteMyCardCmd::DeleteContactL() |
|
300 { |
|
301 iDeleteOperation = iAppServices-> |
|
302 ContactManager().DeleteContactsL( *iContactsArray, *this ); |
|
303 |
|
304 if( iUiControl ) |
|
305 { |
|
306 // Blank UI control to avoid flicker |
|
307 iUiControl->SetBlank( ETrue ); |
|
308 } |
|
309 } |
|
310 |
|
311 // -------------------------------------------------------------------------- |
|
312 // CPbk2DeleteMyCardCmd::IssueRequest |
|
313 // -------------------------------------------------------------------------- |
|
314 // |
|
315 inline void CPbk2DeleteMyCardCmd::IssueRequest( TProcessState aState ) |
|
316 { |
|
317 iState = aState; |
|
318 if ( !IsActive() ) |
|
319 { |
|
320 TRequestStatus* status = &iStatus; |
|
321 User::RequestComplete( status, KErrNone ); |
|
322 SetActive(); |
|
323 } |
|
324 } |
|
325 |
|
326 // -------------------------------------------------------------------------- |
|
327 // CPbk2DeleteMyCardCmd::ConfirmDeletionL |
|
328 // -------------------------------------------------------------------------- |
|
329 // |
|
330 void CPbk2DeleteMyCardCmd::ConfirmDeletionL() |
|
331 { |
|
332 HBufC* prompt = |
|
333 StringLoader::LoadLC( R_QTN_PHOB_MY_CARD_CLEAR_CONFIRM ); |
|
334 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
335 if( dlg->ExecuteLD( R_PBK2_GENERAL_CONFIRMATION_QUERY, *prompt ) ) |
|
336 { |
|
337 // Continue with starting the deletion |
|
338 IssueRequest( EStarting ); |
|
339 } |
|
340 else |
|
341 { |
|
342 IssueRequest( ECanceling ); |
|
343 } |
|
344 CleanupStack::PopAndDestroy( prompt ); |
|
345 } |
|
346 |
|
347 // End of File |