|
1 /* |
|
2 * Copyright (c) 2002-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 copy "new SIM" contacts to phone memory. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPsu2CopySimContactsCmd.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include <MPbk2CommandObserver.h> |
|
24 #include <MPbk2StartupMonitor.h> |
|
25 #include <CPbk2StoreConfiguration.h> |
|
26 #include <CPbk2StorePropertyArray.h> |
|
27 #include <CPbk2StoreProperty.h> |
|
28 #include <CPbk2StoreViewDefinition.h> |
|
29 #include <CPbk2SortOrderManager.h> |
|
30 #include <Pbk2ProcessDecoratorFactory.h> |
|
31 #include <TPbk2CopyContactsResults.h> |
|
32 #include <Phonebook2PrivatePSKeys.h> |
|
33 #include <Pbk2UID.h> |
|
34 #include <Pbk2USimThinUIRes.rsg> |
|
35 /// Use R_PBK2_GENERAL_CONFIRMATION_QUERY from UI controls |
|
36 /// As a core components UiControl's resource file is loaded in core Pbk2 |
|
37 #include <Pbk2UIControls.rsg> |
|
38 /// Use R_GENERAL_COPY_PROGRESS_NOTE from Commands |
|
39 /// As a core components Command's resource file is loaded in core Pbk2 |
|
40 #include <Pbk2Commands.rsg> |
|
41 #include <Pbk2DataCaging.hrh> |
|
42 #include <MPbk2AppUi.h> |
|
43 #include <MPbk2ApplicationServices.h> |
|
44 #include <MPbk2StoreValidityInformer.h> |
|
45 |
|
46 // Virtual Phonebook |
|
47 #include <MVPbkContactStoreProperties.h> |
|
48 #include <CVPbkContactManager.h> |
|
49 #include <MVPbkContactStore.h> |
|
50 #include <MVPbkStoreContact.h> |
|
51 #include <MVPbkFieldType.h> |
|
52 #include <VPbkContactStoreUris.h> |
|
53 #include <CVPbkContactStoreUriArray.h> |
|
54 #include <VPbkSimStoreFactory.h> |
|
55 #include <MVPbkSimStateInformation.h> |
|
56 #include <MVPbkContactStoreList.h> |
|
57 #include <MVPbkContactStoreInfo.h> |
|
58 #include <MVPbkContactView.h> |
|
59 #include <CVPbkContactLinkArray.h> |
|
60 #include <MVPbkContactOperationBase.h> |
|
61 #include <CVPbkContactCopier.h> |
|
62 |
|
63 // System includes |
|
64 #include <AknQueryDialog.h> |
|
65 #include <e32property.h> |
|
66 #include <StringLoader.h> |
|
67 #include <e32cmn.h> |
|
68 #include <e32capability.h> |
|
69 |
|
70 // Debugging headers |
|
71 #include <Pbk2Debug.h> |
|
72 |
|
73 /// Unnamed namespace for local definitions |
|
74 namespace { |
|
75 |
|
76 // CONSTANTS |
|
77 const TInt KSimNotChecked = 0; |
|
78 const TInt KSimChecked = 1; |
|
79 _LIT( KPsu2ThinUiExtResourceFile, "Pbk2USimThinUIRes.rsc" ); |
|
80 |
|
81 |
|
82 #ifdef _DEBUG |
|
83 enum TPanicCode |
|
84 { |
|
85 EPreCond_ValidStoreConfigurationL, |
|
86 EStorePropertyNotFound_CreateSimViewsL, |
|
87 ENullTarget_CopyContactsL |
|
88 }; |
|
89 |
|
90 void Panic(TInt aReason) |
|
91 { |
|
92 _LIT(KPanicText, "CPsu2CopySimContactsCmd"); |
|
93 User::Panic(KPanicText, aReason); |
|
94 } |
|
95 #endif // _DEBUG |
|
96 |
|
97 /// Tasks |
|
98 enum TNextTask |
|
99 { |
|
100 ECheckCopyPrerequisites, |
|
101 EOpenSimStores, |
|
102 ECheckSimStorePrerequisites, |
|
103 ELaunchNewSIMInsertedQuery, |
|
104 ECreateSimViews, |
|
105 ECopyContacts, |
|
106 EShowResults, |
|
107 EComplete |
|
108 }; |
|
109 |
|
110 } /// namespace |
|
111 |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // CPsu2CopySimContactsCmd::CPsu2CopySimContactsCmd |
|
115 // -------------------------------------------------------------------------- |
|
116 // |
|
117 CPsu2CopySimContactsCmd::CPsu2CopySimContactsCmd |
|
118 ( MPbk2StartupMonitor& aStartupMonitor ) : |
|
119 CActive( EPriorityStandard ), |
|
120 iStartupMonitor( aStartupMonitor ), |
|
121 iResourceFile( *CCoeEnv::Static() ) |
|
122 { |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // CPsu2CopySimContactsCmd::~CPsu2CopySimContactsCmd |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 CPsu2CopySimContactsCmd::~CPsu2CopySimContactsCmd() |
|
130 { |
|
131 Cancel(); |
|
132 delete iDecorator; |
|
133 delete iCopyOperation; |
|
134 delete iCopier; |
|
135 delete iCopiedContacts; |
|
136 delete iValidSourceStoreUris; |
|
137 iSourceViews.ResetAndDestroy(); |
|
138 CloseStores(); |
|
139 delete iSourceContactLinks; |
|
140 iSourceStores.Close(); |
|
141 iResourceFile.Close(); |
|
142 } |
|
143 |
|
144 // -------------------------------------------------------------------------- |
|
145 // CPsu2CopySimContactsCmd::NewL |
|
146 // -------------------------------------------------------------------------- |
|
147 // |
|
148 CPsu2CopySimContactsCmd* CPsu2CopySimContactsCmd::NewL |
|
149 ( MPbk2StartupMonitor& aStartupMonitor ) |
|
150 { |
|
151 CPsu2CopySimContactsCmd* self = |
|
152 new( ELeave ) CPsu2CopySimContactsCmd( aStartupMonitor ); |
|
153 CleanupStack::PushL( self ); |
|
154 self->ConstructL(); |
|
155 CleanupStack::Pop( self ); |
|
156 return self; |
|
157 } |
|
158 |
|
159 // -------------------------------------------------------------------------- |
|
160 // CPsu2CopySimContactsCmd::ConstructL |
|
161 // Symbian 2nd phase constructor can leave. |
|
162 // -------------------------------------------------------------------------- |
|
163 // |
|
164 void CPsu2CopySimContactsCmd::ConstructL() |
|
165 { |
|
166 CActiveScheduler::Add(this); |
|
167 |
|
168 iDecorator = Pbk2ProcessDecoratorFactory::CreateProgressDialogDecoratorL |
|
169 ( R_GENERAL_COPY_PROGRESS_NOTE, EFalse ); |
|
170 iDecorator->SetObserver( *this ); |
|
171 } |
|
172 |
|
173 // -------------------------------------------------------------------------- |
|
174 // CPsu2CopySimContactsCmd::RunL |
|
175 // -------------------------------------------------------------------------- |
|
176 // |
|
177 void CPsu2CopySimContactsCmd::RunL() |
|
178 { |
|
179 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
180 ("CPsu2CopySimContactsCmd::RunL res %d task %d"), |
|
181 iStatus.Int(), iNextTask); |
|
182 |
|
183 if ( iStatus.Int() == KErrNone ) |
|
184 { |
|
185 switch ( iNextTask ) |
|
186 { |
|
187 case ECheckCopyPrerequisites: |
|
188 { |
|
189 CheckCopyPrerequisitesL(); |
|
190 break; |
|
191 } |
|
192 case EOpenSimStores: |
|
193 { |
|
194 OpenSimStoresL(); |
|
195 break; |
|
196 } |
|
197 case ECheckSimStorePrerequisites: |
|
198 { |
|
199 CheckSimStorePrerequisitesL(); |
|
200 break; |
|
201 } |
|
202 case ELaunchNewSIMInsertedQuery: |
|
203 { |
|
204 LaunchNewSIMInsertedQueryL(); |
|
205 break; |
|
206 } |
|
207 case ECreateSimViews: |
|
208 { |
|
209 CreateSimViewsL(); |
|
210 break; |
|
211 } |
|
212 case ECopyContacts: |
|
213 { |
|
214 CopyContactsL(); |
|
215 break; |
|
216 } |
|
217 case EShowResults: |
|
218 { |
|
219 ShowResultsL(); |
|
220 break; |
|
221 } |
|
222 case EComplete: // FALLTHROUGH |
|
223 default: |
|
224 { |
|
225 CompleteL(); |
|
226 break; |
|
227 } |
|
228 } |
|
229 } |
|
230 else |
|
231 { |
|
232 CompleteWithError( iStatus.Int() ); |
|
233 } |
|
234 } |
|
235 |
|
236 // -------------------------------------------------------------------------- |
|
237 // CPsu2CopySimContactsCmd::DoCancel |
|
238 // -------------------------------------------------------------------------- |
|
239 // |
|
240 void CPsu2CopySimContactsCmd::DoCancel() |
|
241 { |
|
242 // Nothing to do here |
|
243 } |
|
244 |
|
245 // -------------------------------------------------------------------------- |
|
246 // CPsu2CopySimContactsCmd::RunError |
|
247 // -------------------------------------------------------------------------- |
|
248 // |
|
249 TInt CPsu2CopySimContactsCmd::RunError( TInt aError ) |
|
250 { |
|
251 iStartupMonitor.HandleStartupFailed( aError ); |
|
252 iCommandObserver->CommandFinished(*this); |
|
253 return KErrNone; |
|
254 } |
|
255 |
|
256 // -------------------------------------------------------------------------- |
|
257 // CPsu2CopySimContactsCmd::ExecuteLD |
|
258 // -------------------------------------------------------------------------- |
|
259 // |
|
260 void CPsu2CopySimContactsCmd::ExecuteLD() |
|
261 { |
|
262 iNextTask = ECheckCopyPrerequisites; |
|
263 IssueRequest(); |
|
264 } |
|
265 |
|
266 // -------------------------------------------------------------------------- |
|
267 // CPsu2CopySimContactsCmd::AddObserver |
|
268 // -------------------------------------------------------------------------- |
|
269 // |
|
270 void CPsu2CopySimContactsCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
271 { |
|
272 iCommandObserver = &aObserver; |
|
273 } |
|
274 |
|
275 // -------------------------------------------------------------------------- |
|
276 // CPsu2CopySimContactsCmd::ResetUiControl |
|
277 // -------------------------------------------------------------------------- |
|
278 // |
|
279 void CPsu2CopySimContactsCmd::ResetUiControl |
|
280 ( MPbk2ContactUiControl& /*aUiControl*/ ) |
|
281 { |
|
282 // Do nothing |
|
283 } |
|
284 |
|
285 // -------------------------------------------------------------------------- |
|
286 // CPsu2CopySimContactsCmd::StoreReady |
|
287 // -------------------------------------------------------------------------- |
|
288 // |
|
289 void CPsu2CopySimContactsCmd::StoreReady |
|
290 ( MVPbkContactStore& /*aContactStore*/) |
|
291 { |
|
292 ++iCounter; |
|
293 if ( iSourceStores.Count() == iCounter ) |
|
294 { |
|
295 iNextTask = ECheckSimStorePrerequisites; |
|
296 IssueRequest(); |
|
297 } |
|
298 } |
|
299 |
|
300 // -------------------------------------------------------------------------- |
|
301 // CPsu2CopySimContactsCmd::StoreUnavailable |
|
302 // -------------------------------------------------------------------------- |
|
303 // |
|
304 void CPsu2CopySimContactsCmd::StoreUnavailable |
|
305 ( MVPbkContactStore& aContactStore, TInt /*aReason*/ ) |
|
306 { |
|
307 // Remove URI |
|
308 iValidSourceStoreUris->Remove( aContactStore.StoreProperties().Uri() ); |
|
309 |
|
310 // Remove store |
|
311 const TInt count = iSourceStores.Count(); |
|
312 TBool storeRemoved = EFalse; |
|
313 for ( TInt i = 0; i < count && !storeRemoved; ++i ) |
|
314 { |
|
315 if ( iSourceStores[i] == &aContactStore ) |
|
316 { |
|
317 iSourceStores[i]->Close( *this ); |
|
318 iSourceStores.Remove( i ); |
|
319 storeRemoved = ETrue; |
|
320 } |
|
321 } |
|
322 |
|
323 // If all source stores failed to open -> complete command |
|
324 if ( iSourceStores.Count() == 0 ) |
|
325 { |
|
326 iNextTask = EComplete; |
|
327 IssueRequest(); |
|
328 } |
|
329 // All available stores are open |
|
330 else if ( iSourceStores.Count() == iCounter ) |
|
331 { |
|
332 iNextTask = ECheckSimStorePrerequisites; |
|
333 IssueRequest(); |
|
334 } |
|
335 } |
|
336 |
|
337 // -------------------------------------------------------------------------- |
|
338 // CPsu2CopySimContactsCmd::HandleStoreEventL |
|
339 // -------------------------------------------------------------------------- |
|
340 // |
|
341 void CPsu2CopySimContactsCmd::HandleStoreEventL |
|
342 ( MVPbkContactStore& /*aContactStore*/, |
|
343 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
344 { |
|
345 // Nothing to be done here |
|
346 } |
|
347 |
|
348 // -------------------------------------------------------------------------- |
|
349 // CPsu2CopySimContactsCmd::ContactViewReady |
|
350 // -------------------------------------------------------------------------- |
|
351 // |
|
352 void CPsu2CopySimContactsCmd::ContactViewReady |
|
353 ( MVPbkContactViewBase& /*aView*/) |
|
354 { |
|
355 ++iCounter; |
|
356 if ( iSourceViews.Count() == iCounter ) |
|
357 { |
|
358 iNextTask = ECopyContacts; |
|
359 IssueRequest(); |
|
360 } |
|
361 } |
|
362 |
|
363 // -------------------------------------------------------------------------- |
|
364 // CPsu2CopySimContactsCmd::ContactViewUnavailable |
|
365 // -------------------------------------------------------------------------- |
|
366 // |
|
367 void CPsu2CopySimContactsCmd::ContactViewUnavailable |
|
368 ( MVPbkContactViewBase& /*aView*/ ) |
|
369 { |
|
370 // Nothing to be done here, wait view ready events |
|
371 } |
|
372 |
|
373 // -------------------------------------------------------------------------- |
|
374 // CPsu2CopySimContactsCmd::ContactAddedToView |
|
375 // -------------------------------------------------------------------------- |
|
376 // |
|
377 void CPsu2CopySimContactsCmd::ContactAddedToView |
|
378 ( MVPbkContactViewBase& /*aView*/, TInt /*aIndex*/, |
|
379 const MVPbkContactLink& /*aContactLink*/ ) |
|
380 { |
|
381 // Nothing to be done here |
|
382 } |
|
383 |
|
384 // -------------------------------------------------------------------------- |
|
385 // CPsu2CopySimContactsCmd::ContactRemovedFromView |
|
386 // -------------------------------------------------------------------------- |
|
387 // |
|
388 void CPsu2CopySimContactsCmd::ContactRemovedFromView |
|
389 ( MVPbkContactViewBase& /*aView*/, TInt /*aIndex*/, |
|
390 const MVPbkContactLink& /*aContactLink*/ ) |
|
391 { |
|
392 // Nothing to be done here |
|
393 } |
|
394 |
|
395 // -------------------------------------------------------------------------- |
|
396 // CPsu2CopySimContactsCmd::ContactViewError |
|
397 // -------------------------------------------------------------------------- |
|
398 // |
|
399 void CPsu2CopySimContactsCmd::ContactViewError |
|
400 ( MVPbkContactViewBase& /*aView*/, TInt aError, |
|
401 TBool /*aErrorNotified*/ ) |
|
402 { |
|
403 IssueRequest( aError ); |
|
404 } |
|
405 |
|
406 // -------------------------------------------------------------------------- |
|
407 // CPsu2CopySimContactsCmd::StepComplete |
|
408 // -------------------------------------------------------------------------- |
|
409 // |
|
410 void CPsu2CopySimContactsCmd::StepComplete |
|
411 ( MVPbkContactOperationBase& /*aOperation*/, TInt aStepSize ) |
|
412 { |
|
413 iCopiedSuccessfully += aStepSize; |
|
414 iDecorator->ProcessAdvance( aStepSize ); |
|
415 } |
|
416 |
|
417 // -------------------------------------------------------------------------- |
|
418 // CPsu2CopySimContactsCmd::StepFailed |
|
419 // -------------------------------------------------------------------------- |
|
420 // |
|
421 TBool CPsu2CopySimContactsCmd::StepFailed |
|
422 ( MVPbkContactOperationBase& /*aOperation*/, TInt /*aStepSize*/, |
|
423 TInt aError ) |
|
424 { |
|
425 CCoeEnv::Static()->HandleError(aError); |
|
426 if( aError == KErrDiskFull ) |
|
427 { |
|
428 // When disk get full during copy, show the results |
|
429 Cancel(); |
|
430 delete iCopyOperation; |
|
431 iCopyOperation = NULL; |
|
432 iNextTask = EShowResults; |
|
433 IssueRequest(); |
|
434 } |
|
435 else |
|
436 { |
|
437 IssueRequest( aError ); |
|
438 } |
|
439 return EFalse; |
|
440 } |
|
441 |
|
442 // -------------------------------------------------------------------------- |
|
443 // CPsu2CopySimContactsCmd::OperationComplete |
|
444 // -------------------------------------------------------------------------- |
|
445 // |
|
446 void CPsu2CopySimContactsCmd::OperationComplete |
|
447 ( MVPbkContactOperationBase& /*aOperation*/ ) |
|
448 { |
|
449 // Decorator calls ProcessDismissed |
|
450 iDecorator->ProcessStopped(); |
|
451 } |
|
452 |
|
453 // -------------------------------------------------------------------------- |
|
454 // CPsu2CopySimContactsCmd::ProcessDismissed |
|
455 // -------------------------------------------------------------------------- |
|
456 // |
|
457 void CPsu2CopySimContactsCmd::ProcessDismissed( TInt /*aCancelCode*/ ) |
|
458 { |
|
459 Cancel(); |
|
460 delete iCopyOperation; |
|
461 iCopyOperation = NULL; |
|
462 iNextTask = EShowResults; |
|
463 IssueRequest(); |
|
464 } |
|
465 |
|
466 // -------------------------------------------------------------------------- |
|
467 // CPsu2CopySimContactsCmd::IssueRequest |
|
468 // -------------------------------------------------------------------------- |
|
469 // |
|
470 void CPsu2CopySimContactsCmd::IssueRequest() |
|
471 { |
|
472 IssueRequest( KErrNone ); |
|
473 } |
|
474 |
|
475 // -------------------------------------------------------------------------- |
|
476 // CPsu2CopySimContactsCmd::IssueRequest |
|
477 // -------------------------------------------------------------------------- |
|
478 // |
|
479 void CPsu2CopySimContactsCmd::IssueRequest( TInt aResult ) |
|
480 { |
|
481 TRequestStatus* status = &iStatus; |
|
482 User::RequestComplete( status, aResult ); |
|
483 SetActive(); |
|
484 } |
|
485 |
|
486 // -------------------------------------------------------------------------- |
|
487 // CPsu2CopySimContactsCmd::CheckCopyPrerequisitesL |
|
488 // -------------------------------------------------------------------------- |
|
489 // |
|
490 void CPsu2CopySimContactsCmd::CheckCopyPrerequisitesL() |
|
491 { |
|
492 if ( ValidStoreConfigurationL() && |
|
493 NewSimCardForPhonebook2AppL() ) |
|
494 { |
|
495 iNextTask = EOpenSimStores; |
|
496 } |
|
497 else |
|
498 { |
|
499 iNextTask = EComplete; |
|
500 } |
|
501 IssueRequest(); |
|
502 } |
|
503 |
|
504 // -------------------------------------------------------------------------- |
|
505 // CPsu2CopySimContactsCmd::OpenSimStoresL |
|
506 // -------------------------------------------------------------------------- |
|
507 // |
|
508 void CPsu2CopySimContactsCmd::OpenSimStoresL() |
|
509 { |
|
510 // Load and open source stores to contact manager |
|
511 const TInt count = iValidSourceStoreUris->Count(); |
|
512 for ( TInt i = 0; i < count; ++i ) |
|
513 { |
|
514 Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(). |
|
515 LoadContactStoreL( (*iValidSourceStoreUris)[i] ); |
|
516 MVPbkContactStore* source = |
|
517 Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(). |
|
518 ContactStoresL().Find( (*iValidSourceStoreUris)[i] ); |
|
519 iSourceStores.AppendL( source ); |
|
520 source->OpenL( *this ); |
|
521 } |
|
522 } |
|
523 |
|
524 // -------------------------------------------------------------------------- |
|
525 // CPsu2CopySimContactsCmd::CheckSimStorePrerequisitesL |
|
526 // -------------------------------------------------------------------------- |
|
527 // |
|
528 void CPsu2CopySimContactsCmd::CheckSimStorePrerequisitesL() |
|
529 { |
|
530 // If there are no contacts to copy then do nothing |
|
531 TInt sourceContactCount = 0; |
|
532 const TInt count = iSourceStores.Count(); |
|
533 for ( TInt i = 0; i < count; ++i ) |
|
534 { |
|
535 sourceContactCount += |
|
536 iSourceStores[i]->StoreInfo().NumberOfContactsL(); |
|
537 } |
|
538 |
|
539 iNextTask = EComplete; |
|
540 if ( sourceContactCount > 0 ) |
|
541 { |
|
542 iNextTask = ELaunchNewSIMInsertedQuery; |
|
543 } |
|
544 else |
|
545 { |
|
546 SetNewSimCardKeyL(); |
|
547 } |
|
548 |
|
549 IssueRequest(); |
|
550 } |
|
551 |
|
552 // -------------------------------------------------------------------------- |
|
553 // CPsu2CopySimContactsCmd::LaunchNewSIMInsertedQueryL |
|
554 // -------------------------------------------------------------------------- |
|
555 // |
|
556 void CPsu2CopySimContactsCmd::LaunchNewSIMInsertedQueryL() |
|
557 { |
|
558 // Open resource as late as possible so that it's not opened in start-up |
|
559 // if not needed |
|
560 iResourceFile.OpenL( KPbk2RomFileDrive, |
|
561 KDC_RESOURCE_FILES_DIR, KPsu2ThinUiExtResourceFile ); |
|
562 |
|
563 HBufC* text = StringLoader::LoadLC( R_QTN_SIMP_NOTE_NEW_SIM_COPY ); |
|
564 |
|
565 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
566 TInt ret = dlg->ExecuteLD( R_PBK2_GENERAL_CONFIRMATION_QUERY, *text ); |
|
567 if ( iAvkonAppUi->IsForeground() ) |
|
568 { |
|
569 // Despite of user answer set P&S key |
|
570 SetNewSimCardKeyL(); |
|
571 SetShowSIMContactsL( ret ); |
|
572 iNextTask = ret ? ECreateSimViews : EComplete; |
|
573 } |
|
574 else |
|
575 { |
|
576 iNextTask = EComplete; |
|
577 } |
|
578 |
|
579 CleanupStack::PopAndDestroy( text ); |
|
580 IssueRequest(); |
|
581 } |
|
582 |
|
583 |
|
584 // -------------------------------------------------------------------------- |
|
585 // CPsu2CopySimContactsCmd::SetShowSIMContactsL |
|
586 // -------------------------------------------------------------------------- |
|
587 // |
|
588 void CPsu2CopySimContactsCmd::SetShowSIMContactsL( TBool aShow ) |
|
589 { |
|
590 const TDesC& adnUri = VPbkContactStoreUris::SimGlobalAdnUri(); |
|
591 |
|
592 CVPbkContactStoreUriArray* uriArray = |
|
593 Phonebook2::Pbk2AppUi()->ApplicationServices().StoreConfiguration(). |
|
594 CurrentConfigurationL(); |
|
595 CleanupStack::PushL( uriArray ); |
|
596 |
|
597 if ( iAvkonAppUi->IsForeground() ) |
|
598 { |
|
599 if ( aShow ) |
|
600 { |
|
601 if ( !uriArray->IsIncluded(adnUri) ) |
|
602 { |
|
603 // Show SIM contact also in names list: |
|
604 Phonebook2::Pbk2AppUi()->ApplicationServices().StoreConfiguration(). |
|
605 AddContactStoreURIL( adnUri ); |
|
606 } |
|
607 } |
|
608 else |
|
609 { |
|
610 if ( uriArray->IsIncluded(adnUri) ) |
|
611 { |
|
612 // Do not show SIM contacts: |
|
613 Phonebook2::Pbk2AppUi()->ApplicationServices().StoreConfiguration(). |
|
614 RemoveContactStoreURIL( adnUri ); |
|
615 } |
|
616 } |
|
617 |
|
618 iNextTask = EComplete; |
|
619 } |
|
620 |
|
621 CleanupStack::PopAndDestroy( uriArray ); |
|
622 } |
|
623 |
|
624 |
|
625 // -------------------------------------------------------------------------- |
|
626 // CPsu2CopySimContactsCmd::CreateSimViewsL |
|
627 // -------------------------------------------------------------------------- |
|
628 // |
|
629 void CPsu2CopySimContactsCmd::CreateSimViewsL() |
|
630 { |
|
631 // Set views ready counter to zero |
|
632 iCounter = 0; |
|
633 |
|
634 const TInt count = iSourceStores.Count(); |
|
635 for ( TInt i = 0; i < count; ++i ) |
|
636 { |
|
637 // Find store property |
|
638 const CPbk2StoreProperty* prop = |
|
639 Phonebook2::Pbk2AppUi()->ApplicationServices().StoreProperties(). |
|
640 FindProperty( iSourceStores[i]->StoreProperties().Uri() ); |
|
641 __ASSERT_DEBUG( prop, |
|
642 Panic( EStorePropertyNotFound_CreateSimViewsL ) ); |
|
643 // Get Virtual Phonebook view definition |
|
644 // There is only one view defintion for SIM stores |
|
645 // -> take the first one |
|
646 const CVPbkContactViewDefinition& viewDef = |
|
647 (prop->Views())[0]->ViewDefinition(); |
|
648 MVPbkContactView* view = iSourceStores[i]->CreateViewLC( |
|
649 viewDef, |
|
650 *this, |
|
651 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
652 SortOrderManager().SortOrder() ); |
|
653 iSourceViews.AppendL( view ); |
|
654 CleanupStack::Pop(); // view |
|
655 } |
|
656 } |
|
657 |
|
658 // -------------------------------------------------------------------------- |
|
659 // CPsu2CopySimContactsCmd::CopyContactsL |
|
660 // -------------------------------------------------------------------------- |
|
661 // |
|
662 void CPsu2CopySimContactsCmd::CopyContactsL() |
|
663 { |
|
664 if ( !iCopier ) |
|
665 { |
|
666 iCopier = CVPbkContactCopier::NewL |
|
667 ( Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager() ); |
|
668 } |
|
669 |
|
670 // Create an array for source contact links |
|
671 if ( !iSourceContactLinks ) |
|
672 { |
|
673 iSourceContactLinks = CVPbkContactLinkArray::NewL(); |
|
674 } |
|
675 |
|
676 if ( !iCopiedContacts ) |
|
677 { |
|
678 iCopiedContacts = CVPbkContactLinkArray::NewL(); |
|
679 } |
|
680 |
|
681 // Create links to the contacts that are copied |
|
682 const TInt viewCount = iSourceViews.Count(); |
|
683 for ( TInt i = 0; i < viewCount; ++i ) |
|
684 { |
|
685 const TInt contactCount = iSourceViews[i]->ContactCountL(); |
|
686 for( TInt j = 0; j < contactCount; ++j ) |
|
687 { |
|
688 MVPbkContactLink* link = |
|
689 iSourceViews[i]->ContactAtL(j).CreateLinkLC(); |
|
690 iSourceContactLinks->AppendL( link ); |
|
691 CleanupStack::Pop(); // link |
|
692 } |
|
693 } |
|
694 |
|
695 // Views can be destroyed now because links have been created |
|
696 iSourceViews.ResetAndDestroy(); |
|
697 |
|
698 // Get target store |
|
699 MVPbkContactStore* targetStore = |
|
700 Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(). |
|
701 ContactStoresL().Find( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
702 // Target store must exist as cheked in ValidStoreConfigurationL |
|
703 __ASSERT_DEBUG( targetStore, Panic( ENullTarget_CopyContactsL )); |
|
704 |
|
705 // Start copying |
|
706 iCopiedContacts->ResetAndDestroy(); |
|
707 iCopyOperation = iCopier->CopyContactsL( |
|
708 CVPbkContactCopier::EVPbkUsePlatformSpecificDuplicatePolicy, |
|
709 *iSourceContactLinks, targetStore, *iCopiedContacts, *this ); |
|
710 |
|
711 |
|
712 // Show progress note |
|
713 iDecorator->ProcessStartedL( iSourceContactLinks->Count() ); |
|
714 } |
|
715 |
|
716 // -------------------------------------------------------------------------- |
|
717 // CPsu2CopySimContactsCmd::ShowResultsL |
|
718 // -------------------------------------------------------------------------- |
|
719 // |
|
720 void CPsu2CopySimContactsCmd::ShowResultsL() |
|
721 { |
|
722 TPbk2CopyContactsResults results( |
|
723 iCopiedSuccessfully, iSourceContactLinks->Count() ); |
|
724 results.ShowNoteL(); |
|
725 |
|
726 iNextTask = EComplete; |
|
727 IssueRequest(); |
|
728 } |
|
729 |
|
730 // -------------------------------------------------------------------------- |
|
731 // CPsu2CopySimContactsCmd::CompleteL |
|
732 // -------------------------------------------------------------------------- |
|
733 // |
|
734 void CPsu2CopySimContactsCmd::CompleteL() |
|
735 { |
|
736 iStartupMonitor.HandleStartupComplete(); |
|
737 iCommandObserver->CommandFinished( *this ); |
|
738 } |
|
739 |
|
740 // -------------------------------------------------------------------------- |
|
741 // CPsu2CopySimContactsCmd::CompleteWithError |
|
742 // -------------------------------------------------------------------------- |
|
743 // |
|
744 void CPsu2CopySimContactsCmd::CompleteWithError( TInt aError ) |
|
745 { |
|
746 iStartupMonitor.HandleStartupFailed( aError ); |
|
747 iCommandObserver->CommandFinished( *this ); |
|
748 } |
|
749 |
|
750 // -------------------------------------------------------------------------- |
|
751 // CPsu2CopySimContactsCmd::ValidStoreConfigurationL |
|
752 // -------------------------------------------------------------------------- |
|
753 // |
|
754 TBool CPsu2CopySimContactsCmd::ValidStoreConfigurationL() |
|
755 { |
|
756 __ASSERT_DEBUG( !iValidSourceStoreUris, |
|
757 Panic(EPreCond_ValidStoreConfigurationL)); |
|
758 |
|
759 CVPbkContactStoreUriArray* currentConfig = |
|
760 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
761 StoreConfiguration().CurrentConfigurationL(); |
|
762 CleanupStack::PushL( currentConfig ); |
|
763 CVPbkContactStoreUriArray* validConfig = |
|
764 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
765 StoreValidityInformer().CurrentlyValidStoresL(); |
|
766 CleanupStack::PushL( validConfig ); |
|
767 |
|
768 // ADN/SDN is valid source if it's not in current configuration |
|
769 iValidSourceStoreUris = CVPbkContactStoreUriArray::NewL(); |
|
770 const TDesC& adnUri = VPbkContactStoreUris::SimGlobalAdnUri(); |
|
771 const TDesC& sdnUri = VPbkContactStoreUris::SimGlobalSdnUri(); |
|
772 if ( !currentConfig->IsIncluded( adnUri )) |
|
773 { |
|
774 iValidSourceStoreUris->AppendL( adnUri ); |
|
775 } |
|
776 if ( !currentConfig->IsIncluded( sdnUri )) |
|
777 { |
|
778 iValidSourceStoreUris->AppendL( sdnUri ); |
|
779 } |
|
780 |
|
781 // No sim store needs to be handled in this command, |
|
782 // directly set the flag. |
|
783 if ( iValidSourceStoreUris->Count() == 0 ) |
|
784 { |
|
785 SetNewSimCardKeyL(); |
|
786 } |
|
787 |
|
788 TBool result = EFalse; |
|
789 // If there are source stores and contact model is valid |
|
790 // then configuration is valid |
|
791 if ( iValidSourceStoreUris->Count() > 0 && |
|
792 validConfig->IsIncluded( |
|
793 VPbkContactStoreUris::DefaultCntDbUri() )) |
|
794 { |
|
795 result = ETrue; |
|
796 } |
|
797 |
|
798 CleanupStack::PopAndDestroy( 2 ); |
|
799 return result; |
|
800 } |
|
801 |
|
802 // -------------------------------------------------------------------------- |
|
803 // CPsu2CopySimContactsCmd::NewSimCardForPhonebook2AppL |
|
804 // -------------------------------------------------------------------------- |
|
805 // |
|
806 TBool CPsu2CopySimContactsCmd::NewSimCardForPhonebook2AppL() |
|
807 { |
|
808 MVPbkSimStateInformation* simStateInfo = |
|
809 VPbkSimStoreFactory::GetSimStateInformationL(); |
|
810 CleanupDeletePushL( simStateInfo ); |
|
811 TBool newSimCard = simStateInfo->NewSimCardL(); |
|
812 CleanupStack::PopAndDestroy(); // simStateInfo |
|
813 |
|
814 if ( newSimCard ) |
|
815 { |
|
816 RProperty queryProperty; |
|
817 TInt queryDone = KSimNotChecked; |
|
818 TInt result = queryProperty.Get( |
|
819 TUid::Uid( KPbk2UID3 ), KPhonebookSimCopyAsked, queryDone ); |
|
820 queryProperty.Close(); |
|
821 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
822 ("CPsu2CopySimContactsCmd::NewSimCardForPhonebook2AppL res %d status %d"), |
|
823 result, queryDone); |
|
824 // If result is KErrNone it means that the key has been set |
|
825 // and query has been asked before, KErrNotFound means that key |
|
826 // is not set and query hasn't been asked |
|
827 if ( result == KErrNotFound ) |
|
828 { |
|
829 return ETrue; |
|
830 } |
|
831 } |
|
832 return EFalse; |
|
833 } |
|
834 |
|
835 // -------------------------------------------------------------------------- |
|
836 // CPsu2CopySimContactsCmd::CloseStores |
|
837 // -------------------------------------------------------------------------- |
|
838 // |
|
839 void CPsu2CopySimContactsCmd::CloseStores() |
|
840 { |
|
841 const TInt count = iSourceStores.Count(); |
|
842 for ( TInt i = 0; i < count; ++i ) |
|
843 { |
|
844 iSourceStores[i]->Close( *this ); |
|
845 } |
|
846 } |
|
847 |
|
848 // -------------------------------------------------------------------------- |
|
849 // CPsu2CopySimContactsCmd::SetNewSimCardKeyL |
|
850 // -------------------------------------------------------------------------- |
|
851 // |
|
852 void CPsu2CopySimContactsCmd::SetNewSimCardKeyL() |
|
853 { |
|
854 RProperty queryProperty; |
|
855 CleanupClosePushL( queryProperty ); |
|
856 |
|
857 // Check if the key has been defined |
|
858 TInt queryDone = KSimNotChecked; |
|
859 TInt result = queryProperty.Get( |
|
860 TUid::Uid( KPbk2UID3 ), KPhonebookSimCopyAsked, queryDone ); |
|
861 |
|
862 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
863 ("CPsu2CopySimContactsCmd::SetNewSimCardKeyL res %d status %d"), |
|
864 result, queryDone); |
|
865 |
|
866 if ( result == KErrNotFound ) |
|
867 { |
|
868 _LIT_SECURITY_POLICY_C1( newSimCardQueryReadPolicy, |
|
869 ECapabilityReadUserData ); |
|
870 _LIT_SECURITY_POLICY_S0( newSimCardQueryWritePolicy, KPbk2UID3 ); |
|
871 |
|
872 // Define a property for query done flag |
|
873 User::LeaveIfError( queryProperty.Define( |
|
874 TUid::Uid( KPbk2UID3 ), |
|
875 KPhonebookSimCopyAsked, |
|
876 RProperty::EInt, |
|
877 newSimCardQueryReadPolicy, |
|
878 newSimCardQueryWritePolicy )); |
|
879 } |
|
880 |
|
881 // Set the value to KSimChecked |
|
882 User::LeaveIfError( queryProperty.Set( |
|
883 TUid::Uid( KPbk2UID3 ), |
|
884 KPhonebookSimCopyAsked, |
|
885 KSimChecked )); |
|
886 |
|
887 CleanupStack::PopAndDestroy(); // queryProperty |
|
888 } |
|
889 |
|
890 // End of File |