|
1 /* |
|
2 * Copyright (c) 2005-2007 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 Group UI Extension delete group command. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPguDeleteGroupCmd.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include <MPbk2ProcessDecorator.h> |
|
24 #include <Pbk2ProcessDecoratorFactory.h> |
|
25 #include <MPbk2CommandObserver.h> |
|
26 #include <Pbk2GroupUIRes.rsg> |
|
27 #include <Pbk2Commands.rsg> |
|
28 #include <Pbk2UIControls.rsg> |
|
29 #include <MPbk2ContactUiControl.h> |
|
30 #include <MPbk2ContactNameFormatter.h> |
|
31 #include <CPbk2GeneralConfirmationQuery.h> |
|
32 #include <CPbk2SortOrderManager.h> |
|
33 #include <MPbk2ApplicationServices.h> |
|
34 #include <MPbk2AppUi.h> |
|
35 |
|
36 // Virtual Phonebook |
|
37 #include <CVPbkContactManager.h> |
|
38 #include <MVPbkContactLink.h> |
|
39 #include <MVPbkStoreContact.h> |
|
40 #include <MVPbkContactOperationBase.h> |
|
41 #include <MVPbkContactGroup.h> |
|
42 |
|
43 // System includes |
|
44 #include <AknQueryDialog.h> |
|
45 #include <StringLoader.h> |
|
46 |
|
47 // Debugging headers |
|
48 #include <Pbk2Debug.h> |
|
49 |
|
50 /// Unnamed namespace for local definitions |
|
51 namespace { |
|
52 |
|
53 const TInt KFirstContact = 0; |
|
54 const TInt KOneContact = 1; |
|
55 |
|
56 #ifdef _DEBUG |
|
57 enum TPanicCode |
|
58 { |
|
59 EPanicPreCond_ResetWhenDestroyed = 1, |
|
60 ERunL_InvalidState, |
|
61 VPbkSingleContactOperationComplete_Logic |
|
62 }; |
|
63 |
|
64 void Panic(TPanicCode aReason) |
|
65 { |
|
66 _LIT(KPanicText, "CPguDeleteGroupCmd"); |
|
67 User::Panic(KPanicText,aReason); |
|
68 } |
|
69 #endif // _DEBUG |
|
70 |
|
71 } /// namespace |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // CPguDeleteGroupCmd::CPguDeleteGroupCmd |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 inline CPguDeleteGroupCmd::CPguDeleteGroupCmd( |
|
78 MPbk2ContactUiControl& aUiControl ) : |
|
79 CActive( EPriorityIdle ), |
|
80 iUiControl( &aUiControl ) |
|
81 { |
|
82 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
83 ("CPguDeleteGroupCmd::CPguDeleteGroupCmd(0x%x)"), this); |
|
84 |
|
85 CActiveScheduler::Add( this ); |
|
86 } |
|
87 |
|
88 // -------------------------------------------------------------------------- |
|
89 // CPguDeleteGroupCmd::~CPguDeleteGroupCmd |
|
90 // -------------------------------------------------------------------------- |
|
91 // |
|
92 CPguDeleteGroupCmd::~CPguDeleteGroupCmd() |
|
93 { |
|
94 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
95 ("CPguDeleteGroupCmd::~CPguDeleteGroupCmd(0x%x)"), this); |
|
96 |
|
97 Cancel(); |
|
98 if( iUiControl ) |
|
99 { |
|
100 iUiControl->RegisterCommand( NULL ); |
|
101 } |
|
102 delete iDecorator; |
|
103 delete iContactLinkArray; |
|
104 delete iRetrieveOperation; |
|
105 delete iDeleteOperation; |
|
106 delete iContactGroup; |
|
107 } |
|
108 |
|
109 // -------------------------------------------------------------------------- |
|
110 // CPguDeleteGroupCmd::NewL |
|
111 // -------------------------------------------------------------------------- |
|
112 // |
|
113 CPguDeleteGroupCmd* CPguDeleteGroupCmd::NewL( |
|
114 MPbk2ContactUiControl& aUiControl ) |
|
115 { |
|
116 CPguDeleteGroupCmd* self = new (ELeave) CPguDeleteGroupCmd( aUiControl ); |
|
117 CleanupStack::PushL( self ); |
|
118 self->ConstructL(); |
|
119 CleanupStack::Pop( self ); |
|
120 return self; |
|
121 } |
|
122 // -------------------------------------------------------------------------- |
|
123 // CPguDeleteGroupCmd::ConstructL |
|
124 // -------------------------------------------------------------------------- |
|
125 // |
|
126 inline void CPguDeleteGroupCmd::ConstructL() |
|
127 { |
|
128 iContactLinkArray = iUiControl->SelectedContactsOrFocusedContactL(); |
|
129 |
|
130 TBool visibilityDelay = EFalse; |
|
131 if ( iContactLinkArray && iContactLinkArray->Count() == KOneContact ) |
|
132 { |
|
133 // When deleting only one contact, the progress dialog |
|
134 // is not (immediately) wanted |
|
135 visibilityDelay = ETrue; |
|
136 } |
|
137 iDecorator = Pbk2ProcessDecoratorFactory::CreateProgressDialogDecoratorL( |
|
138 R_QTN_PHOB_NOTE_CLEARING_PB, visibilityDelay ); |
|
139 |
|
140 iDecorator->SetObserver( *this ); |
|
141 iUiControl->RegisterCommand( this ); |
|
142 } |
|
143 |
|
144 // -------------------------------------------------------------------------- |
|
145 // CPguDeleteGroupCmd::ExecuteLD |
|
146 // -------------------------------------------------------------------------- |
|
147 // |
|
148 void CPguDeleteGroupCmd::ExecuteLD() |
|
149 { |
|
150 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
151 ("CPguDeleteGroupCmd::ExecuteLD(0x%x)"), this); |
|
152 |
|
153 CleanupStack::PushL( this ); |
|
154 |
|
155 if ( iContactLinkArray ) |
|
156 { |
|
157 TInt count = iContactLinkArray->Count(); |
|
158 if ( count > KOneContact ) |
|
159 { |
|
160 // Move straight to confirm phase |
|
161 iState = EConfirming; |
|
162 IssueRequest(); |
|
163 } |
|
164 else if ( count == KOneContact ) |
|
165 { |
|
166 // If the array contains only one contact, we have to retrieve it |
|
167 // to get its name for the confirmation query |
|
168 iState = ERetrieving; |
|
169 IssueRequest(); |
|
170 } |
|
171 } |
|
172 |
|
173 CleanupStack::Pop( this ); |
|
174 } |
|
175 |
|
176 // -------------------------------------------------------------------------- |
|
177 // CPguDeleteGroupCmd::AddObserver |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 void CPguDeleteGroupCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
181 { |
|
182 iCommandObserver = &aObserver; |
|
183 } |
|
184 |
|
185 // -------------------------------------------------------------------------- |
|
186 // CPguDeleteGroupCmd::ResetUiControl |
|
187 // -------------------------------------------------------------------------- |
|
188 // |
|
189 void CPguDeleteGroupCmd::ResetUiControl( |
|
190 MPbk2ContactUiControl& aUiControl) |
|
191 { |
|
192 if (iUiControl == &aUiControl) |
|
193 { |
|
194 iUiControl = NULL; |
|
195 } |
|
196 } |
|
197 |
|
198 // -------------------------------------------------------------------------- |
|
199 // CPguDeleteGroupCmd::DoCancel |
|
200 // -------------------------------------------------------------------------- |
|
201 // |
|
202 void CPguDeleteGroupCmd::DoCancel() |
|
203 { |
|
204 // Do nothing |
|
205 } |
|
206 |
|
207 // -------------------------------------------------------------------------- |
|
208 // CPguDeleteGroupCmd::RunL |
|
209 // -------------------------------------------------------------------------- |
|
210 // |
|
211 void CPguDeleteGroupCmd::RunL() |
|
212 { |
|
213 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
214 ("CPguDeleteGroupCmd::RunL() start"), this); |
|
215 |
|
216 switch ( iState ) |
|
217 { |
|
218 case ERetrieving: |
|
219 { |
|
220 const MVPbkContactLink& link = |
|
221 iContactLinkArray->At( KFirstContact ); |
|
222 RetrieveContactL( link ); |
|
223 break; |
|
224 } |
|
225 case EConfirming: |
|
226 { |
|
227 ConfirmDeletionL(); |
|
228 break; |
|
229 } |
|
230 case EStarting: |
|
231 { |
|
232 DoDeleteContactsL(); |
|
233 break; |
|
234 } |
|
235 case EDeleting: |
|
236 { |
|
237 // Do nothing |
|
238 break; |
|
239 } |
|
240 case EStopping: |
|
241 { |
|
242 // decorator calls ProcessDismissed |
|
243 iDecorator->ProcessStopped(); |
|
244 break; |
|
245 } |
|
246 case ECanceling: |
|
247 { |
|
248 ProcessDismissed( KErrCancel ); |
|
249 break; |
|
250 } |
|
251 default: |
|
252 { |
|
253 __ASSERT_DEBUG( EFalse, Panic(ERunL_InvalidState) ); |
|
254 break; |
|
255 } |
|
256 } |
|
257 |
|
258 PBK2_DEBUG_PRINT |
|
259 (PBK2_DEBUG_STRING("CPguDeleteGroupCmd::RunL end")); |
|
260 } |
|
261 |
|
262 // -------------------------------------------------------------------------- |
|
263 // CPguDeleteGroupCmd::RunError |
|
264 // -------------------------------------------------------------------------- |
|
265 // |
|
266 TInt CPguDeleteGroupCmd::RunError( TInt aError ) |
|
267 { |
|
268 return FilterErrors( aError ); |
|
269 } |
|
270 |
|
271 // -------------------------------------------------------------------------- |
|
272 // CPguDeleteGroupCmd::VPbkSingleContactOperationComplete |
|
273 // -------------------------------------------------------------------------- |
|
274 // |
|
275 void CPguDeleteGroupCmd::VPbkSingleContactOperationComplete( |
|
276 MVPbkContactOperationBase& aOperation, |
|
277 MVPbkStoreContact* aContact ) |
|
278 { |
|
279 if ( &aOperation == iRetrieveOperation ) |
|
280 { |
|
281 delete iRetrieveOperation; |
|
282 iRetrieveOperation = NULL; |
|
283 |
|
284 iContactGroup = aContact->Group(); |
|
285 __ASSERT_DEBUG( iContactGroup, |
|
286 Panic(VPbkSingleContactOperationComplete_Logic) ); |
|
287 |
|
288 // We now have a group and we can issue a confirmation |
|
289 iState = EConfirming; |
|
290 IssueRequest(); |
|
291 } |
|
292 } |
|
293 |
|
294 // -------------------------------------------------------------------------- |
|
295 // CPguDeleteGroupCmd::VPbkSingleContactOperationFailed |
|
296 // -------------------------------------------------------------------------- |
|
297 // |
|
298 void CPguDeleteGroupCmd::VPbkSingleContactOperationFailed |
|
299 ( MVPbkContactOperationBase& aOperation, TInt /*aError*/ ) |
|
300 { |
|
301 if ( &aOperation == iRetrieveOperation ) |
|
302 { |
|
303 delete iRetrieveOperation; |
|
304 iRetrieveOperation = NULL; |
|
305 |
|
306 // We cannot get the contact, so we have to |
|
307 // fail. We cannot continue, since this operation |
|
308 // was executed only in case of one contact. |
|
309 iDecorator->ProcessStopped(); |
|
310 } |
|
311 } |
|
312 |
|
313 // -------------------------------------------------------------------------- |
|
314 // CPguDeleteGroupCmd::StepComplete |
|
315 // -------------------------------------------------------------------------- |
|
316 // |
|
317 void CPguDeleteGroupCmd::StepComplete |
|
318 ( MVPbkContactOperationBase& aOperation, TInt aStepSize ) |
|
319 { |
|
320 if ( &aOperation == iDeleteOperation ) |
|
321 { |
|
322 // Indicate process advancement to the decorator |
|
323 iDecorator->ProcessAdvance( aStepSize ); |
|
324 } |
|
325 } |
|
326 |
|
327 // -------------------------------------------------------------------------- |
|
328 // CPguDeleteGroupCmd::StepFailed |
|
329 // -------------------------------------------------------------------------- |
|
330 // |
|
331 TBool CPguDeleteGroupCmd::StepFailed( |
|
332 MVPbkContactOperationBase& aOperation, |
|
333 TInt /*aStepSize*/, TInt aError ) |
|
334 { |
|
335 TBool result = ETrue; |
|
336 if ( &aOperation == iDeleteOperation ) |
|
337 { |
|
338 // Check whether the error is a serious one |
|
339 TInt err = FilterErrors( aError ); |
|
340 if ( err != KErrNone ) |
|
341 { |
|
342 Cancel(); |
|
343 result = EFalse; |
|
344 } |
|
345 } |
|
346 return result; |
|
347 } |
|
348 |
|
349 // -------------------------------------------------------------------------- |
|
350 // CPguDeleteGroupCmd::OperationComplete |
|
351 // -------------------------------------------------------------------------- |
|
352 // |
|
353 void CPguDeleteGroupCmd::OperationComplete( |
|
354 MVPbkContactOperationBase& aOperation ) |
|
355 { |
|
356 if ( &aOperation == iDeleteOperation ) |
|
357 { |
|
358 delete iDeleteOperation; |
|
359 iDeleteOperation = NULL; |
|
360 IssueStopRequest( EStopping ); |
|
361 } |
|
362 } |
|
363 |
|
364 // -------------------------------------------------------------------------- |
|
365 // CPguDeleteGroupCmd::ProcessDismissed |
|
366 // -------------------------------------------------------------------------- |
|
367 // |
|
368 void CPguDeleteGroupCmd::ProcessDismissed( TInt aCancelCode ) |
|
369 { |
|
370 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
371 ("CPguDeleteGroupCmd::ProcessDismissed()")); |
|
372 |
|
373 if ( aCancelCode != KErrCancel && iUiControl) |
|
374 { |
|
375 // Don't remove list markings if user canceled |
|
376 iUiControl->SetBlank( EFalse ); |
|
377 iUiControl->UpdateAfterCommandExecution(); |
|
378 } |
|
379 |
|
380 // Notify command owner that the command has finished |
|
381 iCommandObserver->CommandFinished( *this ); |
|
382 } |
|
383 |
|
384 // -------------------------------------------------------------------------- |
|
385 // CPguDeleteGroupCmd::RetrieveContactL |
|
386 // -------------------------------------------------------------------------- |
|
387 // |
|
388 void CPguDeleteGroupCmd::RetrieveContactL |
|
389 (const MVPbkContactLink& aContactLink ) |
|
390 { |
|
391 // Retrieve the actual store contact from the given link |
|
392 iRetrieveOperation = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
393 ContactManager().RetrieveContactL( aContactLink, *this ); |
|
394 } |
|
395 |
|
396 // -------------------------------------------------------------------------- |
|
397 // CPguDeleteGroupCmd::FilterErrors |
|
398 // -------------------------------------------------------------------------- |
|
399 // |
|
400 inline TInt CPguDeleteGroupCmd::FilterErrors( TInt aErrorCode ) |
|
401 { |
|
402 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
403 ("CPguDeleteGroupCmd::FilterErrors(%d) start"), aErrorCode); |
|
404 |
|
405 TInt result = aErrorCode; |
|
406 switch ( aErrorCode ) |
|
407 { |
|
408 case KErrNotFound: // FALLTHROUGH |
|
409 case KErrInUse: // FALLTHROUGH |
|
410 { |
|
411 // Ignore these errors |
|
412 // KErrNotFound means that somebody got the contact first |
|
413 // KErrInUse means that the contact is open |
|
414 result = KErrNone; |
|
415 break; |
|
416 } |
|
417 |
|
418 default: // Something more serious happened -> give up |
|
419 { |
|
420 Cancel(); |
|
421 // Decorator calls processdismissed |
|
422 iDecorator->ProcessStopped(); |
|
423 break; |
|
424 } |
|
425 } |
|
426 |
|
427 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
428 ("CPguDeleteGroupCmd::FilterErrors(%d) end"), result); |
|
429 |
|
430 return result; |
|
431 } |
|
432 |
|
433 // -------------------------------------------------------------------------- |
|
434 // CPguDeleteGroupCmd::IssueRequest |
|
435 // -------------------------------------------------------------------------- |
|
436 // |
|
437 void CPguDeleteGroupCmd::IssueRequest() |
|
438 { |
|
439 if ( !IsActive() ) |
|
440 { |
|
441 TRequestStatus* status = &iStatus; |
|
442 User::RequestComplete( status, KErrNone ); |
|
443 SetActive(); |
|
444 } |
|
445 } |
|
446 |
|
447 // -------------------------------------------------------------------------- |
|
448 // CPguDeleteGroupCmd::IssueStopRequest |
|
449 // -------------------------------------------------------------------------- |
|
450 // |
|
451 void CPguDeleteGroupCmd::IssueStopRequest( TProcessState aState ) |
|
452 { |
|
453 iState = aState; |
|
454 if ( !IsActive() ) |
|
455 { |
|
456 IssueRequest(); |
|
457 } |
|
458 } |
|
459 |
|
460 // -------------------------------------------------------------------------- |
|
461 // CPguDeleteGroupCmd::ConfirmDeletionL |
|
462 // -------------------------------------------------------------------------- |
|
463 // |
|
464 void CPguDeleteGroupCmd::ConfirmDeletionL() |
|
465 { |
|
466 TInt queryResult = 0; |
|
467 MVPbkContactLinkArray* items = iContactGroup->ItemsContainedLC(); |
|
468 |
|
469 // Show the query "Delete X” "( X is the group name ). |
|
470 CPbk2GeneralConfirmationQuery* query = |
|
471 CPbk2GeneralConfirmationQuery::NewL(); |
|
472 queryResult = query->ExecuteLD( |
|
473 *iContactGroup, R_QTN_QUERY_COMMON_CONF_DELETE, MPbk2ContactNameFormatter::EPreserveAllOriginalSpaces ); |
|
474 |
|
475 if ( queryResult ) |
|
476 { |
|
477 // Continue with starting the deletion |
|
478 iState = EStarting; |
|
479 IssueRequest(); |
|
480 } |
|
481 else |
|
482 { |
|
483 IssueStopRequest( ECanceling ); |
|
484 } |
|
485 CleanupStack::PopAndDestroy(); // items |
|
486 } |
|
487 |
|
488 // -------------------------------------------------------------------------- |
|
489 // CPguDeleteGroupCmd::DoDeleteContactsL |
|
490 // -------------------------------------------------------------------------- |
|
491 // |
|
492 void CPguDeleteGroupCmd::DoDeleteContactsL() |
|
493 { |
|
494 iDeleteOperation = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
495 ContactManager().DeleteContactsL( *iContactLinkArray, *this ); |
|
496 |
|
497 iDecorator->ProcessStartedL( iContactLinkArray->Count() ); |
|
498 |
|
499 if (iUiControl) |
|
500 { |
|
501 // Blank UI control to avoid flicker |
|
502 iUiControl->SetBlank( ETrue ); |
|
503 } |
|
504 |
|
505 iState = EDeleting; |
|
506 IssueRequest(); |
|
507 } |
|
508 |
|
509 // End of File |