author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:54:53 +0300 | |
branch | RCL_3 |
changeset 68 | 9da50d567e3c |
parent 63 | f4a778e096c2 |
child 74 | 6b5524b4f673 |
permissions | -rw-r--r-- |
63 | 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 add to group command object. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// INCLUDE FILES |
|
19 |
#include "CPguAddMembersCmd.h" |
|
20 |
||
21 |
// Phonebook 2 |
|
68
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
22 |
#include <pbk2groupuires.rsg> |
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
23 |
#include <pbk2commands.rsg> |
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
24 |
#include <pbk2uicontrols.rsg> |
63 | 25 |
#include <CPbk2FetchDlg.h> |
26 |
#include <MPbk2CommandObserver.h> |
|
27 |
#include <MPbk2ContactUiControl.h> |
|
28 |
#include <CPbk2ContactRelocator.h> |
|
29 |
#include <Pbk2ProcessDecoratorFactory.h> |
|
30 |
#include <CPbk2ViewState.h> |
|
31 |
#include <MPbk2AppUi.h> |
|
32 |
#include <MPbk2ApplicationServices.h> |
|
33 |
#include <MPbk2ContactViewSupplier.h> |
|
34 |
||
35 |
// Virtual Phonebook |
|
36 |
#include <CVPbkFilteredContactView.h> |
|
37 |
#include <CVPbkContactManager.h> |
|
38 |
#include <MVPbkContactLink.h> |
|
39 |
#include <CVPbkContactLinkArray.h> |
|
40 |
#include <MVPbkContactGroup.h> |
|
41 |
#include <MVPbkContactOperationBase.h> |
|
42 |
#include <MVPbkContactStore.h> |
|
43 |
#include <MVPbkContactStoreProperties.h> |
|
44 |
#include <VPbkContactStoreUris.h> |
|
45 |
||
46 |
// System includes |
|
47 |
#include <coemain.h> |
|
48 |
#include <eikenv.h> |
|
49 |
||
50 |
// Debugging headers |
|
51 |
#include <Pbk2Debug.h> |
|
52 |
||
53 |
/// Unnamed namespace for local definitions |
|
54 |
namespace { |
|
55 |
||
56 |
const TInt KOneContact = 1; |
|
57 |
const TInt KFirstElement = 0; |
|
58 |
// This is used in progress bar tweaking |
|
59 |
const TInt KCertainContactAmount = 3; |
|
60 |
||
61 |
#ifdef _DEBUG |
|
62 |
||
63 |
enum TPanicCode |
|
64 |
{ |
|
65 |
EPanicPreCond_NewL = 1, |
|
66 |
EPanicPreCond_ExecuteLD, |
|
67 |
EPanicPreCond_RelocateContactsL, |
|
68 |
EPanicContactNotGroup, |
|
69 |
EInvalidView |
|
70 |
}; |
|
71 |
||
72 |
void Panic(TPanicCode aReason) |
|
73 |
{ |
|
74 |
_LIT(KPanicText, "CPguAddMembersCmd"); |
|
75 |
User::Panic(KPanicText,aReason); |
|
76 |
} |
|
77 |
||
78 |
#endif // _DEBUG |
|
79 |
||
80 |
} /// namespace |
|
81 |
||
82 |
// -------------------------------------------------------------------------- |
|
83 |
// CPguAddMembersCmd::CPguAddMembersCmd |
|
84 |
// -------------------------------------------------------------------------- |
|
85 |
// |
|
86 |
CPguAddMembersCmd::CPguAddMembersCmd |
|
87 |
( MVPbkContactLink& aContactGroup, |
|
88 |
MPbk2ContactUiControl& aUiControl ) : |
|
89 |
CActive( CActive::EPriorityStandard ), |
|
90 |
iUiControl( &aUiControl ), |
|
91 |
iGroupLink( aContactGroup ), |
|
92 |
iAddedContactsCount( 0 ) |
|
93 |
{ |
|
94 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
95 |
("CPguAddMembersCmd::CPguAddMembersCmd(0x%x)"), this); |
|
96 |
||
97 |
CActiveScheduler::Add( this ); |
|
98 |
||
99 |
if( iUiControl ) |
|
100 |
{ |
|
101 |
iUiControl->RegisterCommand( this ); |
|
102 |
} |
|
103 |
} |
|
104 |
||
105 |
// -------------------------------------------------------------------------- |
|
106 |
// CPguAddMembersCmd::~CPguAddMembersCmd |
|
107 |
// -------------------------------------------------------------------------- |
|
108 |
// |
|
109 |
CPguAddMembersCmd::~CPguAddMembersCmd() |
|
110 |
{ |
|
111 |
Cancel(); |
|
112 |
if ( iFilteredView ) |
|
113 |
{ |
|
114 |
iFilteredView->RemoveObserver( *this ); |
|
115 |
delete iFilteredView; |
|
116 |
} |
|
117 |
else |
|
118 |
{ |
|
119 |
Phonebook2::Pbk2AppUi()-> |
|
120 |
ApplicationServices().ViewSupplier(). |
|
121 |
AllContactsViewL()->RemoveObserver( *this ); |
|
122 |
} |
|
123 |
if( iUiControl ) |
|
124 |
{ |
|
125 |
iUiControl->RegisterCommand( NULL ); |
|
126 |
} |
|
127 |
||
128 |
delete iContact; |
|
129 |
delete iRetrieveContactOperation; |
|
130 |
delete iRetrieveGroupOperation; |
|
131 |
delete iContactGroup; |
|
132 |
delete iEntriesToAdd; |
|
133 |
delete iEntriesToRelocate; |
|
134 |
delete iContactRelocator; |
|
135 |
delete iDecorator; |
|
136 |
delete iContactsInGroup; |
|
137 |
} |
|
138 |
||
139 |
// -------------------------------------------------------------------------- |
|
140 |
// CPguAddMembersCmd::ConstructL |
|
141 |
// -------------------------------------------------------------------------- |
|
142 |
// |
|
143 |
inline void CPguAddMembersCmd::ConstructL() |
|
144 |
{ |
|
145 |
iState = ERetrievingContact; |
|
146 |
iContactsCounter = 0; |
|
147 |
} |
|
148 |
// -------------------------------------------------------------------------- |
|
149 |
// CPguAddMembersCmd::NewLC |
|
150 |
// -------------------------------------------------------------------------- |
|
151 |
// |
|
152 |
CPguAddMembersCmd* CPguAddMembersCmd::NewLC |
|
153 |
( MVPbkContactLink& aContactGroup, |
|
154 |
MPbk2ContactUiControl& aUiControl ) |
|
155 |
{ |
|
156 |
CPguAddMembersCmd* self = new ( ELeave ) CPguAddMembersCmd |
|
157 |
( aContactGroup, aUiControl ); |
|
158 |
CleanupStack::PushL( self ); |
|
159 |
self->ConstructL(); |
|
160 |
return self; |
|
161 |
} |
|
162 |
||
163 |
// -------------------------------------------------------------------------- |
|
164 |
// CPguAddMembersCmd::ExecuteLD |
|
165 |
// -------------------------------------------------------------------------- |
|
166 |
// |
|
167 |
void CPguAddMembersCmd::ExecuteLD() |
|
168 |
{ |
|
169 |
__ASSERT_DEBUG( iCommandObserver, Panic( EPanicPreCond_ExecuteLD ) ); |
|
170 |
||
171 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
172 |
( "CPguAddMembersCmd::ExecuteLD(0x%x)"), this ); |
|
173 |
||
174 |
IssueRequest(); |
|
175 |
} |
|
176 |
||
177 |
// -------------------------------------------------------------------------- |
|
178 |
// CPguAddMembersCmd::AddObserver |
|
179 |
// -------------------------------------------------------------------------- |
|
180 |
// |
|
181 |
void CPguAddMembersCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
182 |
{ |
|
183 |
iCommandObserver = &aObserver; |
|
184 |
} |
|
185 |
||
186 |
// -------------------------------------------------------------------------- |
|
187 |
// CPguAddMembersCmd::ResetUiControl |
|
188 |
// -------------------------------------------------------------------------- |
|
189 |
// |
|
190 |
void CPguAddMembersCmd::ResetUiControl |
|
191 |
( MPbk2ContactUiControl& aUiControl ) |
|
192 |
{ |
|
193 |
if ( iUiControl == &aUiControl ) |
|
194 |
{ |
|
195 |
iUiControl = NULL; |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
// -------------------------------------------------------------------------- |
|
200 |
// CPguAddMembersCmd::RunL |
|
201 |
// -------------------------------------------------------------------------- |
|
202 |
// |
|
203 |
void CPguAddMembersCmd::RunL() |
|
204 |
{ |
|
205 |
switch( iState ) |
|
206 |
{ |
|
207 |
case ERetrievingContact: |
|
208 |
{ |
|
209 |
iRetrieveGroupOperation = Phonebook2::Pbk2AppUi()-> |
|
210 |
ApplicationServices().ContactManager(). |
|
211 |
RetrieveContactL( iGroupLink, *this ); |
|
212 |
break; |
|
213 |
} |
|
214 |
case EHandleContactLockedEvent: |
|
215 |
{ |
|
216 |
HandleContactLockedEventL(); |
|
217 |
break; |
|
218 |
} |
|
219 |
case ECheckContacts: |
|
220 |
{ |
|
221 |
CheckContactsL(); |
|
222 |
break; |
|
223 |
} |
|
224 |
case ERelocateContacts: |
|
225 |
{ |
|
226 |
BeginRelocationL(); |
|
227 |
break; |
|
228 |
} |
|
229 |
case EShowingProgressNote: |
|
230 |
{ |
|
231 |
ShowProgressNoteL(); |
|
232 |
break; |
|
233 |
} |
|
234 |
case EAddingContactsToGroup: |
|
235 |
{ |
|
236 |
AddContactsToGroupL(); |
|
237 |
break; |
|
238 |
} |
|
239 |
case ECommitingTransaction: |
|
240 |
{ |
|
241 |
CommitTransactionL(); |
|
242 |
break; |
|
243 |
} |
|
244 |
case EStopping: |
|
245 |
{ |
|
246 |
ProcessDismissed( KErrNone ); |
|
247 |
break; |
|
248 |
} |
|
249 |
||
250 |
default: |
|
251 |
{ |
|
252 |
// Do nothing |
|
253 |
break; |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
// -------------------------------------------------------------------------- |
|
259 |
// CPguAddMembersCmd::DoCancel |
|
260 |
// -------------------------------------------------------------------------- |
|
261 |
// |
|
262 |
void CPguAddMembersCmd::DoCancel() |
|
263 |
{ |
|
264 |
} |
|
265 |
||
266 |
// -------------------------------------------------------------------------- |
|
267 |
// CPguAddMembersCmd::RunError |
|
268 |
// -------------------------------------------------------------------------- |
|
269 |
// |
|
270 |
TInt CPguAddMembersCmd::RunError( TInt aError ) |
|
271 |
{ |
|
272 |
FinishCommand( aError ); |
|
273 |
return KErrNone; |
|
274 |
} |
|
275 |
||
276 |
// -------------------------------------------------------------------------- |
|
277 |
// CPguAddMembersCmd::VPbkSingleContactOperationComplete |
|
278 |
// -------------------------------------------------------------------------- |
|
279 |
// |
|
280 |
void CPguAddMembersCmd::VPbkSingleContactOperationComplete |
|
281 |
( MVPbkContactOperationBase& aOperation, |
|
282 |
MVPbkStoreContact* aContact ) |
|
283 |
{ |
|
284 |
TInt error = KErrNone; |
|
285 |
||
286 |
if ( &aOperation == iRetrieveGroupOperation ) |
|
287 |
{ |
|
288 |
delete iRetrieveGroupOperation; |
|
289 |
iRetrieveGroupOperation = NULL; |
|
290 |
||
291 |
iContactGroup = aContact->Group(); |
|
292 |
||
293 |
__ASSERT_DEBUG( iContactGroup, Panic( EPanicContactNotGroup ) ); |
|
294 |
||
295 |
TRAP( error, iContactGroup->LockL( *this ) ); |
|
296 |
} |
|
297 |
else if ( &aOperation == iRetrieveContactOperation && iState == ERelocateContacts ) |
|
298 |
{ |
|
299 |
TRAP( error, RelocateContactL( aContact ) ); |
|
300 |
} |
|
301 |
else if ( &aOperation == iRetrieveContactOperation && iState == ECheckContacts ) |
|
302 |
{ |
|
303 |
iContact = aContact; |
|
304 |
// try to lock to check if contact is being modified by another application |
|
305 |
TRAP( error, iContact->LockL( *this ) ); |
|
306 |
} |
|
307 |
||
308 |
if ( error != KErrNone ) |
|
309 |
{ |
|
310 |
FinishCommand( error ); |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
// -------------------------------------------------------------------------- |
|
315 |
// CPguAddMembersCmd::VPbkSingleContactOperationFailed |
|
316 |
// -------------------------------------------------------------------------- |
|
317 |
// |
|
318 |
void CPguAddMembersCmd::VPbkSingleContactOperationFailed |
|
319 |
( MVPbkContactOperationBase& /*aOperation*/, TInt aError ) |
|
320 |
{ |
|
321 |
FinishCommand( aError ); |
|
322 |
} |
|
323 |
||
324 |
// -------------------------------------------------------------------------- |
|
325 |
// CPguAddMembersCmd::ContactOperationCompleted |
|
326 |
// -------------------------------------------------------------------------- |
|
327 |
// |
|
328 |
void CPguAddMembersCmd::ContactOperationCompleted( TContactOpResult aResult ) |
|
329 |
{ |
|
330 |
if ( aResult.iOpCode == MVPbkContactObserver::EContactLock && |
|
331 |
iState == ERetrievingContact ) |
|
332 |
{ |
|
333 |
iState = EHandleContactLockedEvent; |
|
334 |
IssueRequest(); |
|
335 |
} |
|
336 |
else if ( aResult.iOpCode == MVPbkContactObserver::EContactLock && |
|
337 |
iState == ECheckContacts ) |
|
338 |
{ |
|
339 |
iContactsCounter++; |
|
340 |
// delete to release the lock of contact |
|
341 |
delete iContact; |
|
342 |
iContact = NULL; |
|
343 |
IssueRequest(); |
|
344 |
} |
|
345 |
else if ( aResult.iOpCode == MVPbkContactObserver::EContactCommit ) |
|
346 |
{ |
|
347 |
FinishCommand( KErrNone ); |
|
348 |
} |
|
349 |
} |
|
350 |
||
351 |
// -------------------------------------------------------------------------- |
|
352 |
// CPguAddMembersCmd::ContactOperationFailed |
|
353 |
// -------------------------------------------------------------------------- |
|
354 |
// |
|
355 |
||
356 |
void CPguAddMembersCmd::ContactOperationFailed |
|
357 |
( TContactOp aOpCode, TInt aErrorCode, TBool aErrorNotified ) |
|
358 |
{ |
|
359 |
if ( aOpCode == MVPbkContactObserver::EContactLock && |
|
360 |
iState == ECheckContacts ) |
|
361 |
{ |
|
362 |
delete iContact; |
|
363 |
iContact = NULL; |
|
364 |
FinishCommand( aErrorCode ); |
|
365 |
} |
|
366 |
else if ( !aErrorNotified ) |
|
367 |
{ |
|
368 |
FinishCommand( aErrorCode ); |
|
369 |
} |
|
370 |
else |
|
371 |
{ |
|
372 |
FinishCommand( KErrNone ); |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
// -------------------------------------------------------------------------- |
|
377 |
// CPguAddMembersCmd::ContactViewReady |
|
378 |
// -------------------------------------------------------------------------- |
|
379 |
// |
|
380 |
void CPguAddMembersCmd::ContactViewReady |
|
381 |
( MVPbkContactViewBase& /*aView*/ ) |
|
382 |
{ |
|
383 |
// Do nothing |
|
384 |
} |
|
385 |
||
386 |
// -------------------------------------------------------------------------- |
|
387 |
// CPguAddMembersCmd::ContactViewUnavailable |
|
388 |
// -------------------------------------------------------------------------- |
|
389 |
// |
|
390 |
||
391 |
void CPguAddMembersCmd::ContactViewUnavailable |
|
392 |
( MVPbkContactViewBase& /*aView*/ ) |
|
393 |
{ |
|
394 |
// Do nothing |
|
395 |
} |
|
396 |
||
397 |
// -------------------------------------------------------------------------- |
|
398 |
// CPguAddMembersCmd::ContactAddedToView |
|
399 |
// -------------------------------------------------------------------------- |
|
400 |
// |
|
401 |
void CPguAddMembersCmd::ContactAddedToView |
|
402 |
( MVPbkContactViewBase& /*aView*/, TInt /*aIndex*/, |
|
403 |
const MVPbkContactLink& /*aContactLink*/ ) |
|
404 |
{ |
|
405 |
// Do nothing |
|
406 |
} |
|
407 |
||
408 |
// -------------------------------------------------------------------------- |
|
409 |
// CPguAddMembersCmd::ContactRemovedFromView |
|
410 |
// -------------------------------------------------------------------------- |
|
411 |
// |
|
412 |
void CPguAddMembersCmd::ContactRemovedFromView |
|
413 |
( MVPbkContactViewBase& /*aView*/, TInt /*aIndex*/, |
|
414 |
const MVPbkContactLink& /*aContactLink*/ ) |
|
415 |
{ |
|
416 |
// Do nothing |
|
417 |
} |
|
418 |
||
419 |
// -------------------------------------------------------------------------- |
|
420 |
// CPguAddMembersCmd::ContactViewError |
|
421 |
// -------------------------------------------------------------------------- |
|
422 |
// |
|
423 |
void CPguAddMembersCmd::ContactViewError |
|
424 |
( MVPbkContactViewBase&/*aView */, |
|
425 |
TInt aError, TBool /*aErrorNotified*/ ) |
|
426 |
{ |
|
427 |
FinishCommand( aError ); |
|
428 |
} |
|
429 |
||
430 |
// -------------------------------------------------------------------------- |
|
431 |
// CPguAddMembersCmd::IsContactIncluded |
|
432 |
// |
|
433 |
// This function should be as efficient as possible because it's called |
|
434 |
// as many times as there are contacts in all contacts view. |
|
435 |
// -------------------------------------------------------------------------- |
|
436 |
// |
|
437 |
TBool CPguAddMembersCmd::IsContactIncluded |
|
438 |
( const MVPbkBaseContact& aContact ) |
|
439 |
{ |
|
440 |
TBool result = ETrue; |
|
441 |
TRAPD ( err, |
|
442 |
{ |
|
443 |
// Contacts that already belongs to the group are NOT included |
|
444 |
// to the fetch dialog. |
|
445 |
if ( !iContactsInGroup ) |
|
446 |
{ |
|
447 |
iContactsInGroup = iContactGroup->ItemsContainedLC(); |
|
448 |
CleanupStack::Pop(); // iContactsInGroup |
|
449 |
} |
|
450 |
||
451 |
const TInt count( iContactsInGroup->Count() ); |
|
452 |
for ( TInt i(0); i < count; ++i) |
|
453 |
{ |
|
454 |
if ( iContactsInGroup->At( i ).RefersTo( aContact ) ) |
|
455 |
{ |
|
456 |
result = EFalse; |
|
457 |
break; |
|
458 |
} |
|
459 |
} |
|
460 |
}); |
|
461 |
||
462 |
if ( err != KErrNone ) |
|
463 |
{ |
|
464 |
CCoeEnv::Static()->HandleError( err ); |
|
465 |
} |
|
466 |
||
467 |
return result; |
|
468 |
} |
|
469 |
||
470 |
// -------------------------------------------------------------------------- |
|
471 |
// CPguAddMembersCmd::AcceptFetchSelectionL |
|
472 |
// -------------------------------------------------------------------------- |
|
473 |
// |
|
474 |
MPbk2FetchDlgObserver::TPbk2FetchAcceptSelection |
|
475 |
CPguAddMembersCmd::AcceptFetchSelectionL |
|
476 |
( TInt /*aNumMarkedEntries*/, |
|
477 |
MVPbkContactLink& /*aLastSelection*/ ) |
|
478 |
{ |
|
479 |
return MPbk2FetchDlgObserver::EFetchYes; |
|
480 |
} |
|
481 |
||
482 |
// -------------------------------------------------------------------------- |
|
483 |
// CPguAddMembersCmd::FetchCompletedL |
|
484 |
// -------------------------------------------------------------------------- |
|
485 |
// |
|
486 |
void CPguAddMembersCmd::FetchCompletedL |
|
487 |
( MVPbkContactLinkArray* aMarkedEntries ) |
|
488 |
{ |
|
489 |
if ( aMarkedEntries ) |
|
490 |
{ |
|
491 |
PrepareFetchResultsL( aMarkedEntries ); |
|
492 |
} |
|
493 |
else |
|
494 |
{ |
|
495 |
FinishCommand( KErrNone ); |
|
496 |
} |
|
497 |
} |
|
498 |
||
499 |
// -------------------------------------------------------------------------- |
|
500 |
// CPguAddMembersCmd::FetchCanceled |
|
501 |
// -------------------------------------------------------------------------- |
|
502 |
// |
|
503 |
void CPguAddMembersCmd::FetchCanceled() |
|
504 |
{ |
|
505 |
FinishCommand( KErrNone ); |
|
506 |
} |
|
507 |
||
508 |
// -------------------------------------------------------------------------- |
|
509 |
// CPguAddMembersCmd::FetchAborted |
|
510 |
// -------------------------------------------------------------------------- |
|
511 |
// |
|
512 |
void CPguAddMembersCmd::FetchAborted() |
|
513 |
{ |
|
514 |
FinishCommand( KErrNone ); |
|
515 |
} |
|
516 |
||
517 |
// -------------------------------------------------------------------------- |
|
518 |
// CPguAddMembersCmd::FetchOkToExit |
|
519 |
// -------------------------------------------------------------------------- |
|
520 |
// |
|
521 |
TBool CPguAddMembersCmd::FetchOkToExit() |
|
522 |
{ |
|
523 |
return ETrue; |
|
524 |
} |
|
525 |
||
526 |
// -------------------------------------------------------------------------- |
|
527 |
// CPguAddMembersCmd::ContactRelocatedL |
|
528 |
// -------------------------------------------------------------------------- |
|
529 |
// |
|
530 |
void CPguAddMembersCmd::ContactRelocatedL |
|
531 |
( MVPbkStoreContact* aRelocatedContact ) |
|
532 |
{ |
|
533 |
MVPbkContactLink* contactLink = aRelocatedContact->CreateLinkLC(); |
|
534 |
if ( contactLink ) |
|
535 |
{ |
|
536 |
if ( iEntriesToAdd ) |
|
537 |
{ |
|
538 |
CleanupStack::Pop(); // contactLink |
|
539 |
iEntriesToAdd->AppendL( contactLink ); |
|
540 |
} |
|
541 |
else |
|
542 |
{ |
|
543 |
CleanupStack::PopAndDestroy(); // contactLink |
|
544 |
} |
|
545 |
} |
|
546 |
||
547 |
delete aRelocatedContact; |
|
548 |
||
549 |
// Advance the relocation progress note |
|
550 |
if ( iDecorator ) |
|
551 |
{ |
|
552 |
iDecorator->ProcessAdvance( 1 ); |
|
553 |
} |
|
554 |
} |
|
555 |
||
556 |
// -------------------------------------------------------------------------- |
|
557 |
// CPguAddMembersCmd::ContactRelocationFailed |
|
558 |
// -------------------------------------------------------------------------- |
|
559 |
// |
|
560 |
void CPguAddMembersCmd::ContactRelocationFailed |
|
561 |
( TInt aReason, MVPbkStoreContact* aContact ) |
|
562 |
{ |
|
563 |
// Can't do much than just delete the contact we were given ownership, |
|
564 |
// it can not be added to the group |
|
565 |
delete aContact; |
|
566 |
||
567 |
if ( aReason == KErrCancel |
|
568 |
&& iEntriesToAdd |
|
569 |
&& iEntriesToAdd->Count() > 0 ) |
|
570 |
{ |
|
571 |
// Although user discards relocation we have to add other entries |
|
572 |
// to the group if them exists. First show the progress note. |
|
573 |
iState = EShowingProgressNote; |
|
574 |
IssueRequest(); |
|
575 |
} |
|
576 |
else |
|
577 |
{ |
|
578 |
FinishCommand( aReason ); |
|
579 |
} |
|
580 |
} |
|
581 |
||
582 |
// -------------------------------------------------------------------------- |
|
583 |
// CPguAddMembersCmd::ContactsRelocationFailed |
|
584 |
// -------------------------------------------------------------------------- |
|
585 |
// |
|
586 |
void CPguAddMembersCmd::ContactsRelocationFailed |
|
587 |
( TInt aReason, CVPbkContactLinkArray* aContacts ) |
|
588 |
{ |
|
589 |
// Can't do much than just delete the contacts we were given ownership, |
|
590 |
// they can not be added to the group |
|
591 |
delete aContacts; |
|
592 |
||
593 |
if ( aReason == KErrCancel |
|
594 |
&& iEntriesToAdd |
|
595 |
&& iEntriesToAdd->Count() > 0 ) |
|
596 |
{ |
|
597 |
// Although user discards relocation we have to add other entries |
|
598 |
// to the group if them exists. First show the progress note. |
|
599 |
iState = EShowingProgressNote; |
|
600 |
IssueRequest(); |
|
601 |
} |
|
602 |
else |
|
603 |
{ |
|
604 |
FinishCommand( aReason ); |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
// -------------------------------------------------------------------------- |
|
609 |
// CPguAddMembersCmd::RelocationProcessComplete |
|
610 |
// -------------------------------------------------------------------------- |
|
611 |
// |
|
612 |
void CPguAddMembersCmd::RelocationProcessComplete() |
|
613 |
{ |
|
614 |
iState = EShowingProgressNote; |
|
615 |
IssueRequest(); |
|
616 |
} |
|
617 |
||
618 |
// -------------------------------------------------------------------------- |
|
619 |
// CPguAddMembersCmd::ProcessDismissed |
|
620 |
// -------------------------------------------------------------------------- |
|
621 |
// |
|
622 |
void CPguAddMembersCmd::ProcessDismissed( TInt /*aCancelCode*/ ) |
|
623 |
{ |
|
624 |
if ( iUiControl ) |
|
625 |
{ |
|
626 |
iUiControl->UpdateAfterCommandExecution(); |
|
627 |
} |
|
628 |
if ( iCommandObserver ) |
|
629 |
{ |
|
630 |
iCommandObserver->CommandFinished( *this ); |
|
631 |
} |
|
632 |
} |
|
633 |
||
634 |
// -------------------------------------------------------------------------- |
|
635 |
// CPguAddMembersCmd::HandleContactLockedEventL |
|
636 |
// -------------------------------------------------------------------------- |
|
637 |
// |
|
638 |
void CPguAddMembersCmd::HandleContactLockedEventL() |
|
639 |
{ |
|
640 |
delete iFilteredView; |
|
641 |
iFilteredView = NULL; |
|
642 |
MPbk2ApplicationServices& appServices = Phonebook2::Pbk2AppUi()->ApplicationServices(); |
|
643 |
TInt count = KErrNotFound; |
|
644 |
if ( !iContactsInGroup && iContactGroup ) |
|
645 |
{ |
|
646 |
iContactsInGroup = iContactGroup->ItemsContainedLC(); |
|
647 |
CleanupStack::Pop(); // iContactsInGroup |
|
648 |
} |
|
649 |
if ( iContactsInGroup ) |
|
650 |
{ |
|
651 |
count = iContactsInGroup->Count(); |
|
652 |
} |
|
653 |
if ( count > 0 || count == KErrNotFound ) |
|
654 |
{ |
|
655 |
iFilteredView = CVPbkFilteredContactView::NewL |
|
656 |
( *appServices.ViewSupplier().AllContactsViewL(), *this, *this, |
|
657 |
appServices.ContactManager().FieldTypes() ); |
|
658 |
} |
|
659 |
||
660 |
DoLaunchFetchDialogL(); |
|
661 |
} |
|
662 |
||
663 |
// -------------------------------------------------------------------------- |
|
664 |
// CPguAddMembersCmd::DoLaunchFetchDialogL |
|
665 |
// -------------------------------------------------------------------------- |
|
666 |
// |
|
667 |
void CPguAddMembersCmd::DoLaunchFetchDialogL() |
|
668 |
{ |
|
669 |
CPbk2FetchDlg::TParams params; |
|
670 |
params.iResId = R_PBK2_MULTIPLE_ENTRY_FETCH_NO_GROUPS_DLG; |
|
671 |
if ( iFilteredView ) |
|
672 |
{ |
|
673 |
// Fetch dlg uses this view instead of AllNameslistView |
|
674 |
params.iNamesListView = iFilteredView; |
|
675 |
} |
|
676 |
else |
|
677 |
{ |
|
678 |
MVPbkContactViewBase* view = Phonebook2::Pbk2AppUi() |
|
679 |
->ApplicationServices().ViewSupplier().AllContactsViewL(); |
|
680 |
view->AddObserverL( *this ); |
|
681 |
params.iNamesListView = view; |
|
682 |
} |
|
683 |
params.iFlags = CPbk2FetchDlg::EFetchMultiple; |
|
684 |
params.iNaviPaneId = R_PBK2_GROUP_MEMBER_FETCH_NAVILABEL; |
|
685 |
||
686 |
CPbk2FetchDlg* dlg = CPbk2FetchDlg::NewL( params, *this ); |
|
687 |
// Fetch dialog is not waiting dialog, so we just launch it |
|
688 |
dlg->ExecuteLD(); |
|
689 |
} |
|
690 |
||
691 |
// -------------------------------------------------------------------------- |
|
692 |
// CPguAddMembersCmd::PrepareFetchResultsL |
|
693 |
// -------------------------------------------------------------------------- |
|
694 |
// |
|
695 |
void CPguAddMembersCmd::PrepareFetchResultsL |
|
696 |
( MVPbkContactLinkArray* aMarkedEntries ) |
|
697 |
{ |
|
698 |
if ( aMarkedEntries ) |
|
699 |
{ |
|
700 |
const TInt count = aMarkedEntries->Count(); |
|
701 |
||
702 |
delete iEntriesToAdd; |
|
703 |
iEntriesToAdd = NULL; |
|
704 |
iEntriesToAdd = CVPbkContactLinkArray::NewL(); |
|
705 |
||
706 |
delete iEntriesToRelocate; |
|
707 |
iEntriesToRelocate = NULL; |
|
708 |
iEntriesToRelocate = CVPbkContactLinkArray::NewL(); |
|
709 |
||
710 |
for ( TInt i = 0; i < count; ++ i ) |
|
711 |
{ |
|
712 |
MVPbkContactLink* contactLink = |
|
713 |
aMarkedEntries->At( i ).CloneLC(); |
|
714 |
CleanupStack::Pop(); // contactLink |
|
715 |
||
716 |
TVPbkContactStoreUriPtr uri = |
|
717 |
contactLink->ContactStore().StoreProperties().Uri(); |
|
718 |
TVPbkContactStoreUriPtr phoneMemoryUri( |
|
719 |
VPbkContactStoreUris::DefaultCntDbUri() ); |
|
720 |
||
721 |
if ( uri.Compare( phoneMemoryUri, |
|
722 |
TVPbkContactStoreUriPtr::EContactStoreUriStoreType ) |
|
723 |
== 0 ) |
|
724 |
{ |
|
725 |
// Phone memory contact can be added to group directly |
|
726 |
iEntriesToAdd->AppendL( contactLink ); |
|
727 |
} |
|
728 |
else |
|
729 |
{ |
|
730 |
// We must first relocate the contact |
|
731 |
iEntriesToRelocate->AppendL( contactLink ); |
|
732 |
} |
|
733 |
} |
|
734 |
||
735 |
iState = ECheckContacts; |
|
736 |
IssueRequest(); |
|
737 |
} |
|
738 |
} |
|
739 |
||
740 |
// -------------------------------------------------------------------------- |
|
741 |
// CPguAddMembersCmd::RelocateContactL |
|
742 |
// -------------------------------------------------------------------------- |
|
743 |
// |
|
744 |
void CPguAddMembersCmd::RelocateContactL( MVPbkStoreContact* aStoreContact ) |
|
745 |
{ |
|
746 |
delete iContactRelocator; |
|
747 |
iContactRelocator = NULL; |
|
748 |
iContactRelocator = CPbk2ContactRelocator::NewL(); |
|
749 |
||
750 |
// Asynchronously relocate the contact |
|
751 |
// One contact doesn't need waiting note |
|
752 |
iContactRelocator->RelocateContactL( aStoreContact, *this, |
|
753 |
Pbk2ContactRelocator::EPbk2DisplayBasicQuery, |
|
754 |
CPbk2ContactRelocator::EPbk2RelocatorExistingContact ); |
|
755 |
} |
|
756 |
// -------------------------------------------------------------------------- |
|
757 |
// CPguAddMembersCmd::RelocateContactsL |
|
758 |
// -------------------------------------------------------------------------- |
|
759 |
// |
|
760 |
void CPguAddMembersCmd::RelocateContactsL() |
|
761 |
{ |
|
762 |
__ASSERT_DEBUG( iEntriesToRelocate->Count() > KOneContact, |
|
763 |
Panic( EPanicPreCond_RelocateContactsL ) ); |
|
764 |
||
765 |
TInt count = iEntriesToRelocate->Count(); |
|
766 |
delete iContactRelocator; |
|
767 |
iContactRelocator = NULL; |
|
768 |
iContactRelocator = CPbk2ContactRelocator::NewL(); |
|
769 |
||
770 |
// Asynchronously relocate contacts |
|
771 |
TBool result = iContactRelocator->RelocateContactsL( iEntriesToRelocate, |
|
772 |
*this, Pbk2ContactRelocator::EPbk2DisplayBasicQuery ); |
|
773 |
iEntriesToRelocate = NULL; // Ownership was taken |
|
774 |
if ( result ) |
|
775 |
{ |
|
776 |
// User has accepted relocation, show "Retrieving" progress note |
|
777 |
ShowRelocationNoteL( count ); |
|
778 |
} |
|
779 |
} |
|
780 |
||
781 |
// -------------------------------------------------------------------------- |
|
782 |
// CPguAddMembersCmd::AddContactsToGroupL |
|
783 |
// -------------------------------------------------------------------------- |
|
784 |
// |
|
785 |
void CPguAddMembersCmd::AddContactsToGroupL() |
|
786 |
{ |
|
787 |
if (iEntriesToAdd && |
|
788 |
iAddedContactsCount < iEntriesToAdd->Count() ) |
|
789 |
{ |
|
790 |
const MVPbkContactLink& contactToAdd = iEntriesToAdd->At( iAddedContactsCount ); |
|
791 |
iAddedContactsCount++; |
|
792 |
||
793 |
// If leaves, RunError called |
|
794 |
iContactGroup->AddContactL( contactToAdd ); |
|
795 |
||
796 |
if ( iDecorator ) |
|
797 |
{ |
|
798 |
iDecorator->ProcessAdvance( 1 ); |
|
799 |
} |
|
800 |
iState = EAddingContactsToGroup; |
|
801 |
} |
|
802 |
else |
|
803 |
{ |
|
804 |
iState = ECommitingTransaction; |
|
805 |
} |
|
806 |
||
807 |
IssueRequest(); |
|
808 |
} |
|
809 |
||
810 |
// -------------------------------------------------------------------------- |
|
811 |
// CPguAddMembersCmd::CommitTransactionL |
|
812 |
// -------------------------------------------------------------------------- |
|
813 |
// |
|
814 |
void CPguAddMembersCmd::CommitTransactionL() |
|
815 |
{ |
|
816 |
iContactGroup->CommitL( *this ); |
|
817 |
} |
|
818 |
||
819 |
// -------------------------------------------------------------------------- |
|
820 |
// CPguAddMembersCmd::FinishCommand |
|
821 |
// -------------------------------------------------------------------------- |
|
822 |
// |
|
823 |
void CPguAddMembersCmd::FinishCommand( TInt aResult ) |
|
824 |
{ |
|
825 |
if ( iUiControl ) |
|
826 |
{ |
|
827 |
iUiControl->SetBlank( EFalse ); |
|
828 |
TRAPD(err, SetFocusToLastAddedL() ); |
|
829 |
if ( KErrNone != err ) |
|
830 |
{ |
|
831 |
CCoeEnv::Static()->HandleError( aResult ); |
|
832 |
} |
|
833 |
} |
|
834 |
||
835 |
if ( aResult != KErrNone && aResult != KErrCancel ) |
|
836 |
{ |
|
837 |
CCoeEnv::Static()->HandleError( aResult ); |
|
838 |
} |
|
839 |
||
840 |
if ( iDecorator ) |
|
841 |
{ |
|
842 |
// iDecorator calls ProcessStopped to end this cmd |
|
843 |
iDecorator->ProcessStopped(); |
|
844 |
} |
|
845 |
else |
|
846 |
{ |
|
847 |
if ( iUiControl ) |
|
848 |
{ |
|
849 |
iUiControl->UpdateAfterCommandExecution(); |
|
850 |
} |
|
851 |
if ( iCommandObserver ) |
|
852 |
{ |
|
853 |
iCommandObserver->CommandFinished( *this ); |
|
854 |
} |
|
855 |
} |
|
856 |
} |
|
857 |
||
858 |
// -------------------------------------------------------------------------- |
|
859 |
// CPguAddMembersCmd::ShowRelocationNoteL |
|
860 |
// -------------------------------------------------------------------------- |
|
861 |
// |
|
862 |
void CPguAddMembersCmd::ShowRelocationNoteL( TInt aCount ) |
|
863 |
{ |
|
864 |
if ( iUiControl ) |
|
865 |
{ |
|
866 |
iUiControl->SetBlank( ETrue ); |
|
867 |
} |
|
868 |
||
869 |
if ( !iDecorator ) |
|
870 |
{ |
|
871 |
// Show relocation note only if there are enough contacts |
|
872 |
// You can't use here the TBool-delay switch, |
|
873 |
// it just doesn't progress |
|
874 |
if ( aCount > KCertainContactAmount ) |
|
875 |
{ |
|
876 |
iDecorator = Pbk2ProcessDecoratorFactory:: |
|
877 |
CreateProgressDialogDecoratorL |
|
878 |
( R_QTN_GEN_NOTE_RETRIEVING_PROGRESS, EFalse ); |
|
879 |
iDecorator->SetObserver( *this ); |
|
880 |
iDecorator->ProcessStartedL( aCount + 1 ); |
|
881 |
} |
|
882 |
else |
|
883 |
{ |
|
884 |
// There are few contacts, so omit the whole note |
|
885 |
iDecorator = Pbk2ProcessDecoratorFactory:: |
|
886 |
CreateProgressDialogDecoratorL |
|
887 |
( R_QTN_GEN_NOTE_RETRIEVING_PROGRESS, ETrue ); |
|
888 |
iDecorator->SetObserver( *this ); |
|
889 |
iDecorator->ProcessStartedL( 0 ); |
|
890 |
} |
|
891 |
} |
|
892 |
} |
|
893 |
||
894 |
||
895 |
// -------------------------------------------------------------------------- |
|
896 |
// CPguAddMembersCmd::ShowProgressNoteL |
|
897 |
// -------------------------------------------------------------------------- |
|
898 |
// |
|
899 |
void CPguAddMembersCmd::ShowProgressNoteL() |
|
900 |
{ |
|
901 |
if ( iUiControl ) |
|
902 |
{ |
|
903 |
iUiControl->SetBlank( ETrue ); |
|
904 |
} |
|
905 |
||
906 |
if ( !iDecorator && iEntriesToAdd ) |
|
907 |
{ |
|
908 |
// Show relocation note only if there are enough contacts |
|
909 |
// You can't use here the TBool-delay switch, it just doesn't |
|
910 |
// progress |
|
911 |
if ( iEntriesToAdd->Count() > KCertainContactAmount ) |
|
912 |
{ |
|
913 |
iDecorator = Pbk2ProcessDecoratorFactory:: |
|
914 |
CreateProgressDialogDecoratorL |
|
915 |
( R_QTN_GEN_NOTE_RETRIEVING_PROGRESS, EFalse ); |
|
916 |
iDecorator->SetObserver( *this ); |
|
917 |
iDecorator->ProcessStartedL( iEntriesToAdd->Count() + 1 ); |
|
918 |
} |
|
919 |
else |
|
920 |
{ |
|
921 |
// There are few contacts, so omit the whole note |
|
922 |
iDecorator = Pbk2ProcessDecoratorFactory:: |
|
923 |
CreateProgressDialogDecoratorL |
|
924 |
( R_QTN_GEN_NOTE_RETRIEVING_PROGRESS, ETrue ); |
|
925 |
iDecorator->SetObserver( *this ); |
|
926 |
iDecorator->ProcessStartedL( 0 ); |
|
927 |
} |
|
928 |
} |
|
929 |
iState = EAddingContactsToGroup; |
|
930 |
IssueRequest(); |
|
931 |
} |
|
932 |
||
933 |
// -------------------------------------------------------------------------- |
|
934 |
// CPguAddMembersCmd::IssueRequest |
|
935 |
// -------------------------------------------------------------------------- |
|
936 |
// |
|
937 |
void CPguAddMembersCmd::IssueRequest() |
|
938 |
{ |
|
939 |
TRequestStatus* status = &iStatus; |
|
940 |
User::RequestComplete( status, KErrNone ); |
|
941 |
SetActive(); |
|
942 |
} |
|
943 |
||
944 |
// -------------------------------------------------------------------------- |
|
945 |
// CPguAddMembersCmd::IssueStopRequest |
|
946 |
// -------------------------------------------------------------------------- |
|
947 |
// |
|
948 |
void CPguAddMembersCmd::IssueStopRequest() |
|
949 |
{ |
|
950 |
iState = EStopping; |
|
951 |
if ( !IsActive() ) |
|
952 |
{ |
|
953 |
IssueRequest(); |
|
954 |
} |
|
955 |
} |
|
956 |
||
957 |
// -------------------------------------------------------------------------- |
|
958 |
// CPguAddMembersCmd::SetFocusToLastAddedL |
|
959 |
// -------------------------------------------------------------------------- |
|
960 |
// |
|
961 |
void CPguAddMembersCmd::SetFocusToLastAddedL() |
|
962 |
{ |
|
963 |
if ( iUiControl && iEntriesToAdd && iEntriesToAdd->Count() ) |
|
964 |
{ |
|
965 |
// Sets the focus to last added contactlink |
|
966 |
TInt focusedIndex( iEntriesToAdd->Count() - 1 ); |
|
967 |
CPbk2ViewState* viewState = iUiControl->ControlStateL(); |
|
968 |
CleanupStack::PushL( viewState ); |
|
969 |
||
970 |
viewState->SetFocusedContact( |
|
971 |
iEntriesToAdd->At( focusedIndex ).CloneLC() ); |
|
972 |
CleanupStack::Pop(); // iEntriesToAdd->At(focusedIndex).CloneLC |
|
973 |
||
974 |
iUiControl->RestoreControlStateL( viewState ); |
|
975 |
CleanupStack::PopAndDestroy(); // viewState |
|
976 |
} |
|
977 |
} |
|
978 |
||
979 |
void CPguAddMembersCmd::BeginRelocationL() |
|
980 |
{ |
|
981 |
if ( iEntriesToRelocate->Count() > KOneContact ) |
|
982 |
{ |
|
983 |
RelocateContactsL(); |
|
984 |
} |
|
985 |
else if ( iEntriesToRelocate->Count() == KOneContact ) |
|
986 |
{ |
|
987 |
// We'll have to retrieve the one single contact and |
|
988 |
// use single contact relocator |
|
989 |
delete iRetrieveContactOperation; |
|
990 |
iRetrieveContactOperation = NULL; |
|
991 |
iRetrieveContactOperation = |
|
992 |
Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
993 |
ContactManager().RetrieveContactL( |
|
994 |
iEntriesToRelocate->At( KFirstElement ), *this ); |
|
995 |
} |
|
996 |
else |
|
997 |
{ |
|
998 |
// Contacts will be added to group. First show |
|
999 |
// the progress note. |
|
1000 |
iState = EShowingProgressNote; |
|
1001 |
IssueRequest(); |
|
1002 |
} |
|
1003 |
} |
|
1004 |
||
1005 |
void CPguAddMembersCmd::CheckContactsL() |
|
1006 |
{ |
|
1007 |
if ( iContactsCounter < iEntriesToAdd->Count() ) |
|
1008 |
{ |
|
1009 |
delete iRetrieveContactOperation; |
|
1010 |
iRetrieveContactOperation = NULL; |
|
1011 |
iRetrieveContactOperation = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
1012 |
ContactManager().RetrieveContactL( iEntriesToAdd->At( iContactsCounter ), *this ); |
|
1013 |
} |
|
1014 |
else |
|
1015 |
{ |
|
1016 |
iState = ERelocateContacts; |
|
1017 |
IssueRequest(); |
|
1018 |
} |
|
1019 |
} |
|
1020 |
// End of File |