|
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 USIM UI Extension copy to SIM command. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPsu2CopyToSimCmd.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include "CPsu2CopyToSimFieldInfoArray.h" |
|
24 #include "CPsu2SimContactProcessor.h" |
|
25 #include "TPsu2SimCopyResults.h" |
|
26 #include "CPsu2ContactCopyInspector.h" |
|
27 #include <MPbk2ContactUiControl.h> |
|
28 #include <CPbk2FieldPropertyArray.h> |
|
29 #include <MPbk2ContactNameFormatter.h> |
|
30 #include <MPbk2CommandObserver.h> |
|
31 #include <Pbk2ProcessDecoratorFactory.h> |
|
32 #include <Pbk2USimUIRes.rsg> |
|
33 #include <CPbk2StorePropertyArray.h> |
|
34 #include <CPbk2StoreProperty.h> |
|
35 #include <CPbk2ApplicationServices.h> |
|
36 #include <MPbk2AppUi.h> |
|
37 #include <Pbk2CommonUi.rsg> |
|
38 |
|
39 // Virtual Phonebook |
|
40 #include <MVPbkContactStoreProperties.h> |
|
41 #include <CVPbkContactManager.h> |
|
42 #include <MVPbkContactStore.h> |
|
43 #include <MVPbkStoreContact.h> |
|
44 #include <MVPbkContactLink.h> |
|
45 #include <MVPbkContactOperationBase.h> |
|
46 #include <CVPbkContactLinkArray.h> |
|
47 #include <CVPbkFieldTypeRefsList.h> |
|
48 #include <MVPbkContactStoreInfo.h> |
|
49 |
|
50 // System includes |
|
51 #include <avkon.hrh> |
|
52 #include <exterror.h> |
|
53 #include <coemain.h> |
|
54 #include <StringLoader.h> |
|
55 #include <aknnotewrappers.h> |
|
56 |
|
57 // debug |
|
58 #include <Pbk2Debug.h> |
|
59 |
|
60 /// Unnamed namespace for local definitions |
|
61 namespace { |
|
62 |
|
63 const TInt KZero = 0; |
|
64 const TInt KOne = 1; |
|
65 |
|
66 enum TNextTask |
|
67 { |
|
68 EStartCommand, |
|
69 ERetrieveSourceContact, |
|
70 ECreateSimContacts, |
|
71 EStartCopy, |
|
72 ECopyContact, |
|
73 EShowResultsAndComplete, |
|
74 EComplete |
|
75 }; |
|
76 |
|
77 enum TTargetStoreStatus |
|
78 { |
|
79 EStoreNotOpen, |
|
80 EStoreOpen, |
|
81 EStoreNotAvailable |
|
82 }; |
|
83 #ifdef _DEBUG |
|
84 enum TPanicCode |
|
85 { |
|
86 ECopyToSimMenuItemMustNotBeInMenu, |
|
87 EPreCond_CopyCurrentContactL, |
|
88 }; |
|
89 |
|
90 void Panic(TInt aReason) |
|
91 { |
|
92 _LIT(KPanicText, "CPsu2CopyToSimCmd"); |
|
93 User::Panic(KPanicText, aReason); |
|
94 } |
|
95 #endif // _DEBUG |
|
96 |
|
97 } /// namespace |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // CPsu2CopyToSimCmd::CPsu2CopyToSimCmd |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 CPsu2CopyToSimCmd::CPsu2CopyToSimCmd( MPbk2ContactUiControl& aUiControl, |
|
104 MVPbkContactStore& aTargetStore ) : |
|
105 CActive( EPriorityStandard ), |
|
106 iUiControl( &aUiControl ), |
|
107 iTargetStore( aTargetStore ), |
|
108 iUpdateControl( ETrue ), |
|
109 iIsCopiedCompletely( ETrue ), |
|
110 iIsLastCopyFailedForSimIsFull( EFalse ) |
|
111 { |
|
112 } |
|
113 |
|
114 // -------------------------------------------------------------------------- |
|
115 // CPsu2CopyToSimCmd::~CPsu2CopyToSimCmd |
|
116 // -------------------------------------------------------------------------- |
|
117 // |
|
118 CPsu2CopyToSimCmd::~CPsu2CopyToSimCmd() |
|
119 { |
|
120 Cancel(); |
|
121 delete iContactInspector; |
|
122 delete iDecorator; |
|
123 delete iSimContactProcessor; |
|
124 delete iCopyToSimTypeInfos; |
|
125 delete iContactRetriever; |
|
126 delete iLinkArray; |
|
127 delete iCurrentSourceContact; |
|
128 delete iCurrentSimContact; |
|
129 iSimContacts.ResetAndDestroy(); |
|
130 // Deregister the observer to the target store. |
|
131 iTargetStore.Close( *this ); |
|
132 |
|
133 Release( iAppServices ); |
|
134 } |
|
135 |
|
136 // -------------------------------------------------------------------------- |
|
137 // CPsu2CopyToSimCmd::NewL |
|
138 // -------------------------------------------------------------------------- |
|
139 // |
|
140 CPsu2CopyToSimCmd* CPsu2CopyToSimCmd::NewL( |
|
141 MPbk2ContactUiControl& aUiControl, |
|
142 MVPbkContactStore& aTargetStore) |
|
143 { |
|
144 CPsu2CopyToSimCmd* self = |
|
145 new( ELeave ) CPsu2CopyToSimCmd(aUiControl, aTargetStore); |
|
146 CleanupStack::PushL( self ); |
|
147 self->ConstructL(); |
|
148 CleanupStack::Pop( self ); |
|
149 return self; |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------------- |
|
153 // CPsu2CopyToSimCmd::ConstructL |
|
154 // -------------------------------------------------------------------------- |
|
155 // |
|
156 void CPsu2CopyToSimCmd::ConstructL() |
|
157 { |
|
158 iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
159 |
|
160 CActiveScheduler::Add(this); |
|
161 |
|
162 iLinkArray = CVPbkContactLinkArray::NewL(); |
|
163 iContactInspector = CPsu2ContactCopyInspector::NewL |
|
164 ( iAppServices->NameFormatter() ); |
|
165 |
|
166 // The command can be called from the generic Copy starter |
|
167 // or straight using Copy To SIM menu command |
|
168 // -> iUiControl can be name list control or |
|
169 // it can be a store list control |
|
170 // safe since reference in contructor |
|
171 iNameListUiControl = iUiControl->ParentControl(); |
|
172 if (!iNameListUiControl) |
|
173 { |
|
174 iNameListUiControl = iUiControl; |
|
175 } |
|
176 |
|
177 iNameListUiControl->RegisterCommand( this ); |
|
178 |
|
179 MVPbkContactLinkArray* linkArray = |
|
180 iNameListUiControl->SelectedContactsOrFocusedContactL(); |
|
181 // There must be at least one item in the array, otherwise the menu |
|
182 // item shouldn't be there |
|
183 __ASSERT_DEBUG( linkArray && linkArray->Count() > 0, |
|
184 Panic( ECopyToSimMenuItemMustNotBeInMenu ) ); |
|
185 |
|
186 CleanupDeletePushL( linkArray ); |
|
187 // Copy links that belongs to the target store |
|
188 TVPbkContactStoreUriPtr targetUri = iTargetStore.StoreProperties().Uri(); |
|
189 const TInt count = linkArray->Count(); |
|
190 for (TInt i = 0; i < count; ++i) |
|
191 { |
|
192 TVPbkContactStoreUriPtr uri = |
|
193 (*linkArray)[i].ContactStore().StoreProperties().Uri(); |
|
194 if ( targetUri.Compare(uri, |
|
195 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) != 0) |
|
196 { |
|
197 iLinkArray->AppendL( (*linkArray)[i].CloneLC() ); |
|
198 CleanupStack::Pop(); // created link |
|
199 } |
|
200 } |
|
201 CleanupStack::PopAndDestroy(); // linkArray |
|
202 |
|
203 // Create source to SIM field type mapping infos |
|
204 iCopyToSimTypeInfos = CPsu2CopyToSimFieldInfoArray::NewL( |
|
205 iAppServices->ContactManager().FieldTypes(), |
|
206 iAppServices->ContactManager().FsSession() ); |
|
207 |
|
208 // Create a processor that knows how to build and split contacts |
|
209 iSimContactProcessor = CPsu2SimContactProcessor::NewL( |
|
210 iTargetStore, |
|
211 *iCopyToSimTypeInfos, |
|
212 iAppServices->NameFormatter(), |
|
213 iAppServices->ContactManager().FieldTypes(), |
|
214 iAppServices->ContactManager().FsSession() ); |
|
215 |
|
216 iDecorator = Pbk2ProcessDecoratorFactory::CreateProgressDialogDecoratorL( |
|
217 R_PSU2_COPY_PROGRESS_NOTE, ETrue ); |
|
218 iDecorator->SetObserver( *this ); |
|
219 |
|
220 iTargetStoreStatus = EStoreNotOpen; |
|
221 // Register as an observer of the store, to make sure could get the store state |
|
222 // change notification. |
|
223 iTargetStore.OpenL( *this ); |
|
224 } |
|
225 |
|
226 // -------------------------------------------------------------------------- |
|
227 // CPsu2CopyToSimCmd::RunL |
|
228 // -------------------------------------------------------------------------- |
|
229 // |
|
230 void CPsu2CopyToSimCmd::RunL() |
|
231 { |
|
232 switch (iNextTask) |
|
233 { |
|
234 case EStartCommand: |
|
235 { |
|
236 StartL(); |
|
237 break; |
|
238 } |
|
239 case ERetrieveSourceContact: |
|
240 { |
|
241 RetrieveSourceContactL(); |
|
242 break; |
|
243 } |
|
244 case ECreateSimContacts: |
|
245 { |
|
246 CreateSimContactsL(); |
|
247 break; |
|
248 } |
|
249 case EStartCopy: |
|
250 { |
|
251 StartCopyL(); |
|
252 break; |
|
253 } |
|
254 case ECopyContact: |
|
255 { |
|
256 CopyCurrentContactL(); |
|
257 break; |
|
258 } |
|
259 case EShowResultsAndComplete: |
|
260 { |
|
261 // If can't get the sim space here, and the former |
|
262 // copy is failed, just show that sim is full |
|
263 if ( (GetSimSpaceStatusL() == ESimSpaceUnknown) && |
|
264 iIsLastCopyFailedForSimIsFull ) |
|
265 { |
|
266 ShowSimIsFullNoteL(); |
|
267 } |
|
268 else |
|
269 { |
|
270 ShowResultsNoteL(); |
|
271 } |
|
272 |
|
273 CompleteL(); |
|
274 break; |
|
275 } |
|
276 case EComplete: // FALLTHROUGH |
|
277 default: |
|
278 { |
|
279 CompleteL(); |
|
280 break; |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 // -------------------------------------------------------------------------- |
|
286 // CPsu2CopyToSimCmd::DoCancel |
|
287 // -------------------------------------------------------------------------- |
|
288 // |
|
289 void CPsu2CopyToSimCmd::DoCancel() |
|
290 { |
|
291 } |
|
292 |
|
293 // -------------------------------------------------------------------------- |
|
294 // CPsu2CopyToSimCmd::RunError |
|
295 // -------------------------------------------------------------------------- |
|
296 // |
|
297 TInt CPsu2CopyToSimCmd::RunError(TInt aError) |
|
298 { |
|
299 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
300 ( "CPsu2CopyToSimCmd::RunError %d" ), aError ); |
|
301 CCoeEnv::Static()->HandleError(aError); |
|
302 if ( iCommandObserver ) |
|
303 { |
|
304 iCommandObserver->CommandFinished(*this); |
|
305 } |
|
306 return KErrNone; |
|
307 } |
|
308 |
|
309 // -------------------------------------------------------------------------- |
|
310 // CPsu2CopyToSimCmd::ExecuteLD |
|
311 // -------------------------------------------------------------------------- |
|
312 // |
|
313 void CPsu2CopyToSimCmd::ExecuteLD() |
|
314 { |
|
315 iNextTask = EStartCommand; |
|
316 IssueRequest(); |
|
317 } |
|
318 |
|
319 // -------------------------------------------------------------------------- |
|
320 // CPsu2CopyToSimCmd::AddObserver |
|
321 // -------------------------------------------------------------------------- |
|
322 // |
|
323 void CPsu2CopyToSimCmd::AddObserver(MPbk2CommandObserver& aObserver) |
|
324 { |
|
325 iCommandObserver = &aObserver; |
|
326 } |
|
327 |
|
328 // -------------------------------------------------------------------------- |
|
329 // CPsu2CopyToSimCmd::ResetUiControl |
|
330 // -------------------------------------------------------------------------- |
|
331 // |
|
332 void CPsu2CopyToSimCmd::ResetUiControl( |
|
333 MPbk2ContactUiControl& aUiControl) |
|
334 { |
|
335 if (iNameListUiControl == & aUiControl) |
|
336 { |
|
337 iUiControl = NULL; |
|
338 iNameListUiControl = NULL; |
|
339 } |
|
340 } |
|
341 |
|
342 // -------------------------------------------------------------------------- |
|
343 // CPsu2CopyToSimCmd::StoreReady |
|
344 // -------------------------------------------------------------------------- |
|
345 // |
|
346 void CPsu2CopyToSimCmd::StoreReady( MVPbkContactStore& /*aContactStore*/ ) |
|
347 { |
|
348 iTargetStoreStatus = EStoreOpen; |
|
349 } |
|
350 |
|
351 // -------------------------------------------------------------------------- |
|
352 // CPsu2CopyToSimCmd::StoreUnavailable |
|
353 // -------------------------------------------------------------------------- |
|
354 // |
|
355 void CPsu2CopyToSimCmd::StoreUnavailable( MVPbkContactStore& /*aContactStore*/, |
|
356 TInt /*aReason*/ ) |
|
357 { |
|
358 iTargetStoreStatus = EStoreNotAvailable; |
|
359 } |
|
360 |
|
361 // -------------------------------------------------------------------------- |
|
362 // CPsu2CopyToSimCmd::HandleStoreEventL |
|
363 // -------------------------------------------------------------------------- |
|
364 // |
|
365 void CPsu2CopyToSimCmd::HandleStoreEventL( |
|
366 MVPbkContactStore& /*aContactStore*/, |
|
367 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
368 { |
|
369 // do nothing. |
|
370 } |
|
371 |
|
372 // -------------------------------------------------------------------------- |
|
373 // CPsu2CopyToSimCmd::VPbkSingleContactOperationComplete |
|
374 // -------------------------------------------------------------------------- |
|
375 // |
|
376 void CPsu2CopyToSimCmd::VPbkSingleContactOperationComplete( |
|
377 MVPbkContactOperationBase& /*aOperation*/, |
|
378 MVPbkStoreContact* aContact) |
|
379 { |
|
380 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
381 ( "CPsu2CopyToSimCmd::VPbkSingleContactOperationComplete 0x%x" ), |
|
382 this ); |
|
383 // This is called when a new source contact is loaded |
|
384 |
|
385 delete iCurrentSourceContact; |
|
386 iCurrentSourceContact = aContact; |
|
387 |
|
388 // Create SIM contacts from the source next |
|
389 iNextTask = ECreateSimContacts; |
|
390 IssueRequest(); |
|
391 } |
|
392 |
|
393 // -------------------------------------------------------------------------- |
|
394 // CPsu2CopyToSimCmd::VPbkSingleContactOperationFailed |
|
395 // -------------------------------------------------------------------------- |
|
396 // |
|
397 void CPsu2CopyToSimCmd::VPbkSingleContactOperationFailed( |
|
398 MVPbkContactOperationBase& /*aOperation*/, TInt aError) |
|
399 { |
|
400 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
401 ( "CPsu2CopyToSimCmd::VPbkSingleContactOperationFailed 0x%x" ), |
|
402 this ); |
|
403 // This is called when a new source contact loading failed |
|
404 iDecorator->ProcessAdvance(KOne); |
|
405 HandleError(aError); |
|
406 } |
|
407 |
|
408 // -------------------------------------------------------------------------- |
|
409 // CPsu2CopyToSimCmd::ContactOperationCompleted |
|
410 // -------------------------------------------------------------------------- |
|
411 // |
|
412 void CPsu2CopyToSimCmd::ContactOperationCompleted |
|
413 (TContactOpResult /*aResult*/) |
|
414 { |
|
415 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
416 ( "CPsu2CopyToSimCmd::ContactOperationCompleted 0x%x" ), |
|
417 this ); |
|
418 // This called when one SIM contact has been copied |
|
419 // ( or deleted in additional number full case ) |
|
420 iIsLastCopyFailedForSimIsFull = ETrue; |
|
421 if (iSimContacts.Count() == 0) |
|
422 { |
|
423 // The source contact has been successfully copied |
|
424 ++iCopied; |
|
425 MoveToNextContact(); |
|
426 } |
|
427 else |
|
428 { |
|
429 // The source contact was splitted and all splitted sim contacts |
|
430 // are not yet copied |
|
431 CopyNextSimContact(); |
|
432 } |
|
433 } |
|
434 |
|
435 // -------------------------------------------------------------------------- |
|
436 // CPsu2CopyToSimCmd::ContactOperationFailed |
|
437 // -------------------------------------------------------------------------- |
|
438 // |
|
439 void CPsu2CopyToSimCmd::ContactOperationFailed |
|
440 (TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/) |
|
441 { |
|
442 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
443 ( "CPsu2CopyToSimCmd::ContactOperationFailed 0x%x ERROR: %d" ), |
|
444 this, aErrorCode ); |
|
445 |
|
446 // This called when copying of a SIM contact failed |
|
447 TInt res = KErrNone; |
|
448 TInt currentSimContactDeleted( EFalse ); |
|
449 iIsLastCopyFailedForSimIsFull = ETrue; |
|
450 if (iSimContactProcessor->HandleSimError(aErrorCode )) |
|
451 { |
|
452 // If the error was handled it means that the SIM contact |
|
453 // must be splitted and resulted contacts must be copied. |
|
454 TRAP(res, iSimContactProcessor->CreateFixedSimContactsL( |
|
455 *iCurrentSimContact, iSimContacts)); |
|
456 |
|
457 if ( res == KErrNone && iIsCopiedCompletely ) |
|
458 { |
|
459 iIsCopiedCompletely = !iSimContactProcessor->DetailsDropped(); |
|
460 if ( iIsCopiedCompletely ) |
|
461 { |
|
462 // Inspect that contact was copied completely |
|
463 // if sim contacts has created. |
|
464 if ( iIsCopiedCompletely && iSimContacts.Count() > 0 ) |
|
465 { |
|
466 iIsCopiedCompletely = iContactInspector->IsCopiedCompletelyL |
|
467 ( *iCurrentSimContact, iSimContacts ); |
|
468 } |
|
469 } |
|
470 } |
|
471 |
|
472 if ( res == KErrNone ) |
|
473 { |
|
474 // Current contact is partially saved so delete it |
|
475 // to prevent duplicate data |
|
476 TRAP( res, iCurrentSimContact->DeleteL( *this ) ); |
|
477 currentSimContactDeleted = ETrue; |
|
478 } |
|
479 } |
|
480 else |
|
481 { |
|
482 res = aErrorCode; |
|
483 } |
|
484 |
|
485 if (res != KErrNone) |
|
486 { |
|
487 // Stop command or move to next contact depending on the error |
|
488 HandleError(res); |
|
489 } |
|
490 else if (iSimContacts.Count() > 0) |
|
491 { |
|
492 // if delete contact is on, this will continue in |
|
493 // MVPbkContactObserver callback |
|
494 if ( !currentSimContactDeleted ) |
|
495 { |
|
496 // There are still SIM contacts to copy |
|
497 CopyNextSimContact(); |
|
498 } |
|
499 } |
|
500 else |
|
501 { |
|
502 // Current contact has been handled, move to next contact |
|
503 MoveToNextContact(); |
|
504 } |
|
505 |
|
506 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING( |
|
507 "CPsu2CopyToSimCmd::ContactOperationFailed 0x%x IsCopiedCompletely: %d" ), |
|
508 this, iIsCopiedCompletely ); |
|
509 } |
|
510 |
|
511 // -------------------------------------------------------------------------- |
|
512 // CPsu2CopyToSimCmd::ProcessDismissed |
|
513 // -------------------------------------------------------------------------- |
|
514 // |
|
515 void CPsu2CopyToSimCmd::ProcessDismissed(TInt aCancelCode) |
|
516 { |
|
517 if ( iNameListUiControl ) |
|
518 { |
|
519 iNameListUiControl->SetBlank( EFalse ); |
|
520 } |
|
521 |
|
522 if ( aCancelCode == KErrCancel || aCancelCode == EEikBidCancel ) |
|
523 { |
|
524 Cancel(); |
|
525 HandleCanceling(); |
|
526 iNextTask = EShowResultsAndComplete; |
|
527 } |
|
528 IssueRequest(); |
|
529 } |
|
530 |
|
531 // -------------------------------------------------------------------------- |
|
532 // CPsu2CopyToSimCmd::IssueRequest |
|
533 // -------------------------------------------------------------------------- |
|
534 // |
|
535 void CPsu2CopyToSimCmd::IssueRequest() |
|
536 { |
|
537 if ( !IsActive() ) |
|
538 { |
|
539 TRequestStatus* status = &iStatus; |
|
540 User::RequestComplete(status, KErrNone); |
|
541 SetActive(); |
|
542 } |
|
543 } |
|
544 |
|
545 // -------------------------------------------------------------------------- |
|
546 // CPsu2CopyToSimCmd::StartL |
|
547 // -------------------------------------------------------------------------- |
|
548 // |
|
549 void CPsu2CopyToSimCmd::StartL() |
|
550 { |
|
551 if ( GetSimSpaceStatusL() == ESimSpaceIsFull ) |
|
552 { |
|
553 ShowSimIsFullNoteL(); |
|
554 iNextTask = EComplete; |
|
555 IssueRequest(); |
|
556 } |
|
557 else |
|
558 { |
|
559 iCurrentIndex = 0; |
|
560 TInt contactCount = iLinkArray->Count(); |
|
561 switch ( contactCount ) |
|
562 { |
|
563 case KZero: |
|
564 { |
|
565 CompleteWithResults(); |
|
566 break; |
|
567 } |
|
568 default: |
|
569 { |
|
570 iDecorator->ProcessStartedL( contactCount ); |
|
571 iNextTask = ERetrieveSourceContact; |
|
572 IssueRequest(); |
|
573 break; |
|
574 } |
|
575 } |
|
576 } |
|
577 } |
|
578 |
|
579 // -------------------------------------------------------------------------- |
|
580 // CPsu2CopyToSimCmd::HandleCanceling |
|
581 // -------------------------------------------------------------------------- |
|
582 // |
|
583 void CPsu2CopyToSimCmd::HandleCanceling() |
|
584 { |
|
585 delete iContactRetriever; |
|
586 iContactRetriever = NULL; |
|
587 delete iCurrentSimContact; |
|
588 iCurrentSimContact = NULL; |
|
589 iSimContacts.ResetAndDestroy(); |
|
590 } |
|
591 |
|
592 // -------------------------------------------------------------------------- |
|
593 // CPsu2CopyToSimCmd::RetrieveSourceContactL |
|
594 // -------------------------------------------------------------------------- |
|
595 // |
|
596 void CPsu2CopyToSimCmd::RetrieveSourceContactL() |
|
597 { |
|
598 if (iCurrentIndex >= iLinkArray->Count()) |
|
599 { |
|
600 // End copying if all contacts have been read |
|
601 CompleteWithResults(); |
|
602 } |
|
603 else |
|
604 { |
|
605 delete iContactRetriever; |
|
606 iContactRetriever = NULL; |
|
607 |
|
608 iContactRetriever = iAppServices->ContactManager().RetrieveContactL( |
|
609 (*iLinkArray)[iCurrentIndex], *this); |
|
610 } |
|
611 } |
|
612 |
|
613 // -------------------------------------------------------------------------- |
|
614 // CPsu2CopyToSimCmd::CreateSimContactsL |
|
615 // -------------------------------------------------------------------------- |
|
616 // |
|
617 void CPsu2CopyToSimCmd::CreateSimContactsL() |
|
618 { |
|
619 iSimContacts.ResetAndDestroy(); |
|
620 iSimContactProcessor->CreateSimContactsL( |
|
621 *iCurrentSourceContact, iSimContacts ); |
|
622 // Inspect that contact was copied completely |
|
623 // if sim contacts has created. |
|
624 if ( iIsCopiedCompletely && iSimContacts.Count() > 0 ) |
|
625 { |
|
626 iIsCopiedCompletely = iContactInspector->IsCopiedCompletelyL |
|
627 ( *iCurrentSourceContact, iSimContacts ); |
|
628 } |
|
629 if ( iSimContacts.Count() == 0 ) |
|
630 { |
|
631 MoveToNextContact(); |
|
632 } |
|
633 else |
|
634 { |
|
635 iNextTask = EStartCopy; |
|
636 IssueRequest(); |
|
637 } |
|
638 } |
|
639 |
|
640 // -------------------------------------------------------------------------- |
|
641 // CPsu2CopyToSimCmd::StartCopyL() |
|
642 // -------------------------------------------------------------------------- |
|
643 // |
|
644 void CPsu2CopyToSimCmd::StartCopyL() |
|
645 { |
|
646 if ( iNameListUiControl ) |
|
647 { |
|
648 // Blank UI control to avoid names list view refreshing |
|
649 iNameListUiControl->SetBlank( ETrue ); |
|
650 } |
|
651 |
|
652 CopyNextSimContact(); |
|
653 } |
|
654 |
|
655 // -------------------------------------------------------------------------- |
|
656 // CPsu2CopyToSimCmd::CopyCurrentContactL |
|
657 // -------------------------------------------------------------------------- |
|
658 // |
|
659 void CPsu2CopyToSimCmd::CopyCurrentContactL() |
|
660 { |
|
661 delete iCurrentSimContact; |
|
662 iCurrentSimContact = NextSimContact(); |
|
663 |
|
664 __ASSERT_DEBUG(iCurrentSimContact, Panic(EPreCond_CopyCurrentContactL)); |
|
665 // If the store is not open, just complete the copy process. |
|
666 if( iTargetStoreStatus != EStoreOpen ) |
|
667 { |
|
668 CompleteWithResults(); |
|
669 } |
|
670 else |
|
671 { |
|
672 iCurrentSimContact->CommitL(*this); |
|
673 } |
|
674 } |
|
675 |
|
676 // -------------------------------------------------------------------------- |
|
677 // CPsu2CopyToSimCmd::ShowResultsNoteL |
|
678 // -------------------------------------------------------------------------- |
|
679 // |
|
680 void CPsu2CopyToSimCmd::ShowResultsNoteL() |
|
681 { |
|
682 if (iLinkArray->Count() == KOne) |
|
683 { |
|
684 if (iCurrentSourceContact) |
|
685 { |
|
686 HBufC* title = iAppServices->NameFormatter(). |
|
687 GetContactTitleL(iCurrentSourceContact->Fields(), |
|
688 MPbk2ContactNameFormatter::EPreserveLeadingSpaces); |
|
689 CleanupStack::PushL(title); |
|
690 TPsu2SimCopyResults results(iCopied, *title); |
|
691 // Show partly copied note if necessary |
|
692 if ( !iIsCopiedCompletely ) |
|
693 { |
|
694 results.ShowPartlyCopiedNoteL(); |
|
695 } |
|
696 else |
|
697 { |
|
698 results.ShowNoteL(); |
|
699 } |
|
700 CleanupStack::PopAndDestroy(title); |
|
701 } |
|
702 else |
|
703 { |
|
704 TPsu2SimCopyResults results; |
|
705 results.ShowErrorNoteL(); |
|
706 } |
|
707 } |
|
708 else |
|
709 { |
|
710 TPsu2SimCopyResults results(iCopied, iLinkArray->Count()); |
|
711 results.ShowNoteL(); |
|
712 // Show partly copied note if necessary |
|
713 if ( !iIsCopiedCompletely ) |
|
714 { |
|
715 results.ShowPartlyCopiedNoteL(); |
|
716 } |
|
717 } |
|
718 } |
|
719 |
|
720 // -------------------------------------------------------------------------- |
|
721 // CPsu2CopyToSimCmd::CompleteL |
|
722 // -------------------------------------------------------------------------- |
|
723 // |
|
724 void CPsu2CopyToSimCmd::CompleteL() |
|
725 { |
|
726 if ( iUpdateControl && iNameListUiControl ) |
|
727 { |
|
728 iNameListUiControl->SetBlank( EFalse ); |
|
729 // Reset find due to case that if contact was not really copied |
|
730 // (=the target contact had already all the same fields) then |
|
731 // UI control doesn't receive any events and find text is not |
|
732 // reset by the UI control. |
|
733 iNameListUiControl->ResetFindL(); |
|
734 if ( iCurrentSourceContact ) |
|
735 { |
|
736 // Maintain NamesList focus on the source contact |
|
737 iNameListUiControl->SetFocusedContactL( *iCurrentSourceContact ); |
|
738 } |
|
739 // If the copy has been cancelled we don't want to update control. |
|
740 // Markings are not removed after cancel. |
|
741 iNameListUiControl->UpdateAfterCommandExecution(); |
|
742 } |
|
743 if ( iCommandObserver ) |
|
744 { |
|
745 iCommandObserver->CommandFinished(*this); |
|
746 } |
|
747 } |
|
748 |
|
749 // -------------------------------------------------------------------------- |
|
750 // CPsu2CopyToSimCmd::NextSimContact |
|
751 // -------------------------------------------------------------------------- |
|
752 // |
|
753 MVPbkStoreContact* CPsu2CopyToSimCmd::NextSimContact() |
|
754 { |
|
755 if (iSimContacts.Count() > 0) |
|
756 { |
|
757 const TInt firstPos = 0; |
|
758 MVPbkStoreContact* contact = iSimContacts[firstPos]; |
|
759 iSimContacts.Remove(firstPos); |
|
760 return contact; |
|
761 } |
|
762 return NULL; |
|
763 } |
|
764 |
|
765 // -------------------------------------------------------------------------- |
|
766 // CPsu2CopyToSimCmd::HandleError |
|
767 // -------------------------------------------------------------------------- |
|
768 // |
|
769 void CPsu2CopyToSimCmd::HandleError(TInt aError) |
|
770 { |
|
771 switch (aError) |
|
772 { |
|
773 // Errors that can be ignored |
|
774 case KErrGsm0707InvalidCharsInTextString: // FALLTHROUGH |
|
775 case KErrGsm0707TextStringTooLong: // FALLTHROUGH |
|
776 case KErrGsm0707DialStringTooLong: // FALLTHROUGH |
|
777 case KErrGsmCCUnassignedNumber: |
|
778 { |
|
779 MoveToNextContact(); |
|
780 break; |
|
781 } |
|
782 default: |
|
783 { |
|
784 // If the copy was failed for memory full |
|
785 if (aError == KErrGsm0707MemoryFull) |
|
786 { |
|
787 iIsLastCopyFailedForSimIsFull = ETrue; |
|
788 } |
|
789 CompleteWithResults(); |
|
790 CCoeEnv::Static()->HandleError(aError); |
|
791 break; |
|
792 } |
|
793 } |
|
794 } |
|
795 |
|
796 // -------------------------------------------------------------------------- |
|
797 // CPsu2CopyToSimCmd::MoveToNextContact |
|
798 // -------------------------------------------------------------------------- |
|
799 // |
|
800 void CPsu2CopyToSimCmd::MoveToNextContact() |
|
801 { |
|
802 iDecorator->ProcessAdvance(KOne); |
|
803 ++iCurrentIndex; |
|
804 iNextTask = ERetrieveSourceContact; |
|
805 IssueRequest(); |
|
806 } |
|
807 |
|
808 // -------------------------------------------------------------------------- |
|
809 // CPsu2CopyToSimCmd::CopyNextSimContact |
|
810 // -------------------------------------------------------------------------- |
|
811 // |
|
812 void CPsu2CopyToSimCmd::CopyNextSimContact() |
|
813 { |
|
814 CPsu2CopyToSimCmd::TSimSpaceStatus simSpaceStatus = ESimSpaceUnknown; |
|
815 |
|
816 // Check always before copying that there is space for a new contact |
|
817 TRAPD( res, simSpaceStatus = GetSimSpaceStatusL() ) |
|
818 if ( res != KErrNone ) |
|
819 { |
|
820 HandleError( res ); |
|
821 } |
|
822 else |
|
823 { |
|
824 iNextTask = ECopyContact; |
|
825 if ( simSpaceStatus == ESimSpaceIsFull ) |
|
826 { |
|
827 CompleteWithResults(); |
|
828 } |
|
829 else |
|
830 { |
|
831 IssueRequest(); |
|
832 } |
|
833 } |
|
834 } |
|
835 |
|
836 // -------------------------------------------------------------------------- |
|
837 // CPsu2CopyToSimCmd::CompleteWithResults |
|
838 // -------------------------------------------------------------------------- |
|
839 // |
|
840 void CPsu2CopyToSimCmd::CompleteWithResults() |
|
841 { |
|
842 iNextTask = EShowResultsAndComplete; |
|
843 if ( iDecorator ) |
|
844 { |
|
845 // This will cause a callback to ProcessDismissed |
|
846 iDecorator->ProcessStopped(); |
|
847 } |
|
848 else |
|
849 { |
|
850 IssueRequest(); |
|
851 } |
|
852 } |
|
853 |
|
854 // -------------------------------------------------------------------------- |
|
855 // CPsu2CopyToSimCmd::ShowNoteIfSimIsFullL |
|
856 // -------------------------------------------------------------------------- |
|
857 // |
|
858 CPsu2CopyToSimCmd::TSimSpaceStatus CPsu2CopyToSimCmd::GetSimSpaceStatusL() |
|
859 { |
|
860 const MVPbkContactStoreInfo& info = iTargetStore.StoreInfo(); |
|
861 |
|
862 if ( info.MaxNumberOfContactsL() <= 0 ) |
|
863 { |
|
864 return ESimSpaceUnknown; |
|
865 } |
|
866 else if ( info.MaxNumberOfContactsL() == info.NumberOfContactsL() ) |
|
867 { |
|
868 return ESimSpaceIsFull; |
|
869 } |
|
870 |
|
871 return ESimSpaceIsNotFull; |
|
872 } |
|
873 |
|
874 // -------------------------------------------------------------------------- |
|
875 // CPsu2CopyToSimCmd::ShowSimIsFullNoteL |
|
876 // -------------------------------------------------------------------------- |
|
877 // |
|
878 void CPsu2CopyToSimCmd::ShowSimIsFullNoteL() |
|
879 { |
|
880 const CPbk2StoreProperty* storeProperty = |
|
881 iAppServices->StoreProperties().FindProperty( |
|
882 iTargetStore.StoreProperties().Uri() ); |
|
883 |
|
884 // R_QTN_PHOB_NOTE_STORE_FULL is from Pbk2Commands and it's |
|
885 // safe to use because commands resources are loaded in core pbk2 |
|
886 HBufC* fullText = StringLoader::LoadLC( |
|
887 R_QTN_PHOB_NOTE_STORE_FULL, |
|
888 storeProperty->StoreName() ); |
|
889 |
|
890 CAknInformationNote* noteDlg = |
|
891 new(ELeave) CAknInformationNote( ETrue ); |
|
892 noteDlg->ExecuteLD( *fullText ); |
|
893 CleanupStack::PopAndDestroy( fullText ); |
|
894 } |
|
895 |
|
896 // End of File |