|
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 create new contact command object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2CreateNewContactCmd.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include <TPbk2ContactEditorParams.h> |
|
24 #include <CPbk2ContactEditorDlg.h> |
|
25 #include <MPbk2CommandObserver.h> |
|
26 #include <CPbk2StoreConfiguration.h> |
|
27 #include <CPbk2FieldPropertyArray.h> |
|
28 #include <MPbk2FieldProperty.h> |
|
29 #include <Pbk2UIControls.rsg> |
|
30 #include <Pbk2CommonUi.rsg> |
|
31 #include <Pbk2CmdExtRes.rsg> |
|
32 #include <MPbk2ContactUiControl.h> |
|
33 #include <CPbk2StoreProperty.h> |
|
34 #include <CPbk2StorePropertyArray.h> |
|
35 #include <CPbk2DriveSpaceCheck.h> |
|
36 #include <CPbk2AppUiBase.h> |
|
37 #include <MPbk2StoreValidityInformer.h> |
|
38 #include <CPbk2ApplicationServices.h> |
|
39 |
|
40 // Virtual Phonebook |
|
41 #include <CVPbkContactManager.h> |
|
42 #include <TVPbkContactStoreUriPtr.h> |
|
43 #include <MVPbkContactStoreList.h> |
|
44 #include <MVPbkContactStore.h> |
|
45 #include <MVPbkStoreContact.h> |
|
46 #include <CVPbkFieldTypeSelector.h> |
|
47 #include <MVPbkFieldType.h> |
|
48 #include <MVPbkContactFieldData.h> |
|
49 #include <MVPbkContactFieldTextData.h> |
|
50 #include <MVPbkContactStore.h> |
|
51 #include <MVPbkContactStoreInfo.h> |
|
52 #include <MVPbkContactStoreProperties.h> |
|
53 #include <VPbkUtils.h> |
|
54 #include <CVPbkContactStoreUriArray.h> |
|
55 #include <VPbkContactStoreUris.h> |
|
56 |
|
57 // System includes |
|
58 #include <barsread.h> |
|
59 #include <coemain.h> |
|
60 #include <StringLoader.h> |
|
61 #include <aknnotewrappers.h> |
|
62 |
|
63 /// Unnamed namespace for local definitions |
|
64 namespace { |
|
65 |
|
66 #ifdef _DEBUG |
|
67 |
|
68 enum TPanicCode |
|
69 { |
|
70 EExecuteLD_PreCond = 1, |
|
71 EAddFindTextL_Logic, |
|
72 EPanicPreCond_Null_Pointer, |
|
73 EPanicIncorrectState, |
|
74 EPanicPreCond_OpenContactStoreL, |
|
75 EPanicPreCond_ValidateStoreL, |
|
76 EPanicPreCond_CreateNewContactL |
|
77 }; |
|
78 |
|
79 void Panic(TInt aReason) |
|
80 { |
|
81 _LIT(KPanicText, "CPbk2CreateNewContactCmd"); |
|
82 User::Panic(KPanicText, aReason); |
|
83 } |
|
84 #endif // _DEBUG |
|
85 |
|
86 /** |
|
87 * Checks is the given field type included in |
|
88 * the given selection. |
|
89 * |
|
90 * @param aFieldType The field type to check. |
|
91 * @param aManager Virtual Phonebook contact manager. |
|
92 * @param aResourceId Selector's resource id. |
|
93 * @return ETrue if field type is included. |
|
94 */ |
|
95 TBool IsFieldTypeIncludedL( const MVPbkFieldType& aFieldType, |
|
96 const CVPbkContactManager& aManager, const TInt aResourceId ) |
|
97 { |
|
98 // Get the field type |
|
99 TResourceReader resReader; |
|
100 CCoeEnv::Static()->CreateResourceReaderLC |
|
101 (resReader, aResourceId); |
|
102 |
|
103 CVPbkFieldTypeSelector* selector = |
|
104 CVPbkFieldTypeSelector::NewL(resReader, aManager.FieldTypes()); |
|
105 CleanupStack::PopAndDestroy(); // resReader |
|
106 |
|
107 TBool ret = selector->IsFieldTypeIncluded(aFieldType); |
|
108 delete selector; |
|
109 return ret; |
|
110 } |
|
111 |
|
112 /** |
|
113 * Displays a note. |
|
114 * |
|
115 * @param aResourceId Note resource id. |
|
116 * @param aString Note parameter. |
|
117 */ |
|
118 void ShowNoteL( TInt aResourceId, const TDesC& aString ) |
|
119 { |
|
120 HBufC* prompt = NULL; |
|
121 |
|
122 if( aString.Length() ) |
|
123 { |
|
124 prompt = StringLoader::LoadLC( aResourceId, aString ); |
|
125 } |
|
126 else |
|
127 { |
|
128 prompt = StringLoader::LoadLC( aResourceId ); |
|
129 } |
|
130 CAknInformationNote* dlg = new(ELeave) CAknInformationNote(ETrue); |
|
131 dlg->ExecuteLD(*prompt); |
|
132 CleanupStack::PopAndDestroy(); // prompt |
|
133 } |
|
134 |
|
135 /** |
|
136 * Checks is the given contact store full. |
|
137 * |
|
138 * @param aTargetStore Store to inspect. |
|
139 * @return ETrue if store is full. |
|
140 */ |
|
141 TBool StoreFullL( const MVPbkContactStore& aTargetStore ) |
|
142 { |
|
143 TBool ret( EFalse ); |
|
144 const MVPbkContactStoreInfo& storeInfo = aTargetStore.StoreInfo(); |
|
145 if ( storeInfo.MaxNumberOfContactsL() != KVPbkStoreInfoUnlimitedNumber && |
|
146 storeInfo.MaxNumberOfContactsL() <= storeInfo.NumberOfContactsL() ) |
|
147 { |
|
148 ret = ETrue; |
|
149 } |
|
150 return ret; |
|
151 } |
|
152 |
|
153 /** |
|
154 * Displays store not available note. |
|
155 * |
|
156 * @param aStoreProperties Phonebook store properties. |
|
157 */ |
|
158 void ShowStoreNotAvailableNoteL( CPbk2StorePropertyArray& aStoreProperties ) |
|
159 { |
|
160 CPbk2StoreConfiguration* storeConfig = CPbk2StoreConfiguration::NewL(); |
|
161 CleanupStack::PushL( storeConfig ); |
|
162 const TDesC& uri = storeConfig->DefaultSavingStoreL().UriDes(); |
|
163 |
|
164 // Get the property of the default saving store |
|
165 const CPbk2StoreProperty* prop = |
|
166 aStoreProperties.FindProperty( uri ); |
|
167 if ( prop && prop->StoreName().Length() > 0 ) |
|
168 { |
|
169 HBufC* text = StringLoader::LoadLC( R_QTN_PHOB_STORE_NOT_AVAILABLE, |
|
170 prop->StoreName() ); |
|
171 CAknInformationNote* note = new(ELeave) CAknInformationNote( ETrue ); |
|
172 // Show "not available" note |
|
173 note->ExecuteLD( *text ); |
|
174 CleanupStack::PopAndDestroy( text ); |
|
175 } |
|
176 |
|
177 CleanupStack::PopAndDestroy( storeConfig ); |
|
178 } |
|
179 |
|
180 /** |
|
181 * Checks is the store valid. |
|
182 * |
|
183 * @param aInformer Store validity informer. |
|
184 * @param aStore Store to inspect. |
|
185 * @return ETrue if store is valid. |
|
186 */ |
|
187 TBool IsValidStoreL |
|
188 ( MPbk2StoreValidityInformer& aInformer, MVPbkContactStore* aStore ) |
|
189 { |
|
190 TBool isValid ( EFalse ); |
|
191 if ( aStore ) |
|
192 { |
|
193 CVPbkContactStoreUriArray* currentlyValidStores = |
|
194 aInformer.CurrentlyValidStoresL(); |
|
195 TVPbkContactStoreUriPtr uri = |
|
196 aStore->StoreProperties().Uri(); |
|
197 isValid = currentlyValidStores->IsIncluded( uri ); |
|
198 delete currentlyValidStores; |
|
199 } |
|
200 |
|
201 return isValid; |
|
202 } |
|
203 |
|
204 } /// namespace |
|
205 |
|
206 // -------------------------------------------------------------------------- |
|
207 // CPbk2CreateNewContactCmd::CPbk2CreateNewContactCmd |
|
208 // -------------------------------------------------------------------------- |
|
209 // |
|
210 CPbk2CreateNewContactCmd::CPbk2CreateNewContactCmd( |
|
211 MPbk2ContactUiControl& aUiControl ) : |
|
212 CActive( EPriorityIdle ), |
|
213 iUiControl( &aUiControl ) |
|
214 { |
|
215 CActiveScheduler::Add( this ); |
|
216 } |
|
217 |
|
218 // -------------------------------------------------------------------------- |
|
219 // CPbk2CreateNewContactCmd::~CPbk2CreateNewContactCmd |
|
220 // -------------------------------------------------------------------------- |
|
221 // |
|
222 CPbk2CreateNewContactCmd::~CPbk2CreateNewContactCmd() |
|
223 { |
|
224 Cancel(); |
|
225 if( iUiControl ) |
|
226 { |
|
227 iUiControl->RegisterCommand( NULL ); |
|
228 } |
|
229 if ( iTargetStore ) |
|
230 { |
|
231 iTargetStore->Close( *this ); |
|
232 } |
|
233 Release( iAppServices ); |
|
234 } |
|
235 |
|
236 // -------------------------------------------------------------------------- |
|
237 // CPbk2CreateNewContactCmd::NewL |
|
238 // -------------------------------------------------------------------------- |
|
239 // |
|
240 CPbk2CreateNewContactCmd* CPbk2CreateNewContactCmd::NewL |
|
241 ( MPbk2ContactUiControl& aUiControl ) |
|
242 { |
|
243 CPbk2CreateNewContactCmd* self = |
|
244 new(ELeave) CPbk2CreateNewContactCmd(aUiControl); |
|
245 CleanupStack::PushL(self); |
|
246 self->ConstructL(); |
|
247 CleanupStack::Pop(self); |
|
248 return self; |
|
249 } |
|
250 |
|
251 // -------------------------------------------------------------------------- |
|
252 // CPbk2CreateNewContactCmd::ConstructL |
|
253 // -------------------------------------------------------------------------- |
|
254 // |
|
255 inline void CPbk2CreateNewContactCmd::ConstructL() |
|
256 { |
|
257 // check drive space |
|
258 CPbk2DriveSpaceCheck* driveSpaceCheck = CPbk2DriveSpaceCheck::NewL |
|
259 ( CCoeEnv::Static()->FsSession() ); |
|
260 CleanupStack::PushL( driveSpaceCheck ); |
|
261 // check FFS situation |
|
262 driveSpaceCheck->DriveSpaceCheckL(); |
|
263 CleanupStack::PopAndDestroy( driveSpaceCheck ); |
|
264 |
|
265 iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
266 |
|
267 CPbk2StoreConfiguration* storeConfig = CPbk2StoreConfiguration::NewL(); |
|
268 CleanupStack::PushL(storeConfig); |
|
269 iTargetStore = iAppServices->ContactManager().ContactStoresL().Find |
|
270 ( storeConfig->DefaultSavingStoreL() ); |
|
271 CleanupStack::PopAndDestroy(storeConfig); |
|
272 if( iUiControl ) |
|
273 { |
|
274 iUiControl->RegisterCommand( this ); |
|
275 } |
|
276 } |
|
277 |
|
278 // -------------------------------------------------------------------------- |
|
279 // CPbk2CreateNewContactCmd::RunL |
|
280 // -------------------------------------------------------------------------- |
|
281 // |
|
282 void CPbk2CreateNewContactCmd::RunL() |
|
283 { |
|
284 switch( iState ) |
|
285 { |
|
286 case ELoadContactStore: |
|
287 { |
|
288 LoadContactStoreL(); |
|
289 break; |
|
290 } |
|
291 case EOpenContactStore: |
|
292 { |
|
293 OpenContactStoreL(); |
|
294 break; |
|
295 } |
|
296 case EValidateStore: |
|
297 { |
|
298 ValidateStoreL(); |
|
299 break; |
|
300 } |
|
301 case ECreateNewContact: |
|
302 { |
|
303 CreateNewContactL(); |
|
304 break; |
|
305 } |
|
306 case EFinishCommand: |
|
307 { |
|
308 iCommandObserver->CommandFinished(*this); |
|
309 break; |
|
310 } |
|
311 default: |
|
312 { |
|
313 __ASSERT_DEBUG( EFalse, Panic( EPanicIncorrectState ) ); |
|
314 } |
|
315 }; |
|
316 } |
|
317 |
|
318 // -------------------------------------------------------------------------- |
|
319 // CPbk2CreateNewContactCmd::DoCancel |
|
320 // -------------------------------------------------------------------------- |
|
321 // |
|
322 void CPbk2CreateNewContactCmd::DoCancel() |
|
323 { |
|
324 // Do nothing |
|
325 } |
|
326 |
|
327 // -------------------------------------------------------------------------- |
|
328 // CPbk2CreateNewContactCmd::RunError |
|
329 // -------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CPbk2CreateNewContactCmd::RunError( TInt aError ) |
|
332 { |
|
333 HandleError( aError ); |
|
334 return KErrNone; |
|
335 } |
|
336 |
|
337 // -------------------------------------------------------------------------- |
|
338 // CPbk2CreateNewContactCmd::HandleError |
|
339 // -------------------------------------------------------------------------- |
|
340 // |
|
341 void CPbk2CreateNewContactCmd::HandleError( TInt aError ) |
|
342 { |
|
343 CCoeEnv::Static()->HandleError( aError ); |
|
344 iState = EFinishCommand; |
|
345 IssueRequest(); |
|
346 } |
|
347 |
|
348 // -------------------------------------------------------------------------- |
|
349 // CPbk2CreateNewContactCmd::ExecuteLD |
|
350 // -------------------------------------------------------------------------- |
|
351 // |
|
352 void CPbk2CreateNewContactCmd::ExecuteLD() |
|
353 { |
|
354 __ASSERT_DEBUG( iCommandObserver, Panic( EExecuteLD_PreCond ) ); |
|
355 |
|
356 CleanupStack::PushL(this); |
|
357 |
|
358 if ( !iTargetStore || !IsValidStoreL |
|
359 ( iAppServices->StoreValidityInformer(), iTargetStore ) ) |
|
360 { |
|
361 // if target store not available finish command |
|
362 ShowStoreNotAvailableNoteL( iAppServices->StoreProperties() ); |
|
363 |
|
364 iTargetStore = NULL; |
|
365 if ( ShowCreateNewToPhoneQueryL() ) |
|
366 { |
|
367 iTargetStore = iAppServices->ContactManager().ContactStoresL(). |
|
368 Find( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
369 |
|
370 if ( iTargetStore ) |
|
371 { |
|
372 if ( !IsValidStoreL( |
|
373 iAppServices->StoreValidityInformer(), iTargetStore ) ) |
|
374 { |
|
375 // Store is loaded, but not opened |
|
376 iState = EOpenContactStore; |
|
377 } |
|
378 else |
|
379 { |
|
380 // Store is loaded and opened |
|
381 iState = EValidateStore; |
|
382 } |
|
383 } |
|
384 else |
|
385 { |
|
386 // Store is neither loaded nor opened |
|
387 iState = ELoadContactStore; |
|
388 } |
|
389 } |
|
390 else |
|
391 { |
|
392 // Canceled |
|
393 iState = EFinishCommand; |
|
394 } |
|
395 } |
|
396 else |
|
397 { |
|
398 iState = EValidateStore; |
|
399 } |
|
400 |
|
401 IssueRequest(); |
|
402 CleanupStack::Pop(this); |
|
403 } |
|
404 |
|
405 // -------------------------------------------------------------------------- |
|
406 // CPbk2CreateNewContactCmd::AddObserver |
|
407 // -------------------------------------------------------------------------- |
|
408 // |
|
409 void CPbk2CreateNewContactCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
410 { |
|
411 iCommandObserver = &aObserver; |
|
412 } |
|
413 |
|
414 // -------------------------------------------------------------------------- |
|
415 // CPbk2CreateNewContactCmd::ContactEditingComplete |
|
416 // -------------------------------------------------------------------------- |
|
417 // |
|
418 void CPbk2CreateNewContactCmd::ResetUiControl( |
|
419 MPbk2ContactUiControl& aUiControl) |
|
420 { |
|
421 if (iUiControl == &aUiControl) |
|
422 { |
|
423 iUiControl = NULL; |
|
424 } |
|
425 } |
|
426 |
|
427 // -------------------------------------------------------------------------- |
|
428 // CPbk2CreateNewContactCmd::ContactEditingComplete |
|
429 // -------------------------------------------------------------------------- |
|
430 // |
|
431 void CPbk2CreateNewContactCmd::ContactEditingComplete |
|
432 ( MVPbkStoreContact* aEditedContact ) |
|
433 { |
|
434 TRAPD( error, HandleContactEditingCompleteL( aEditedContact ) ); |
|
435 if ( error != KErrNone ) |
|
436 { |
|
437 CCoeEnv::Static()->HandleError( error ); |
|
438 } |
|
439 } |
|
440 |
|
441 // -------------------------------------------------------------------------- |
|
442 // CPbk2CreateNewContactCmd::ContactEditingDeletedContact |
|
443 // -------------------------------------------------------------------------- |
|
444 // |
|
445 void CPbk2CreateNewContactCmd::ContactEditingDeletedContact |
|
446 ( MVPbkStoreContact* aEditedContact ) |
|
447 { |
|
448 delete aEditedContact; // not needed anymore |
|
449 if (iUiControl) |
|
450 { |
|
451 // reset find if control exists |
|
452 TRAP_IGNORE( iUiControl->ResetFindL() ); |
|
453 } |
|
454 iState = EFinishCommand; |
|
455 IssueRequest(); |
|
456 } |
|
457 |
|
458 // -------------------------------------------------------------------------- |
|
459 // CPbk2CreateNewContactCmd::ContactEditingAborted |
|
460 // -------------------------------------------------------------------------- |
|
461 // |
|
462 void CPbk2CreateNewContactCmd::ContactEditingAborted() |
|
463 { |
|
464 if (iUiControl) |
|
465 { |
|
466 // reset find if control exists |
|
467 TRAP_IGNORE( iUiControl->ResetFindL() ); |
|
468 } |
|
469 iState = EFinishCommand; |
|
470 IssueRequest(); |
|
471 } |
|
472 |
|
473 // -------------------------------------------------------------------------- |
|
474 // CPbk2CreateNewContactCmd::StoreReady |
|
475 // -------------------------------------------------------------------------- |
|
476 // |
|
477 void CPbk2CreateNewContactCmd::StoreReady( |
|
478 MVPbkContactStore& aContactStore ) |
|
479 { |
|
480 iTargetStore = &aContactStore; |
|
481 iState = EValidateStore; |
|
482 IssueRequest(); |
|
483 } |
|
484 // -------------------------------------------------------------------------- |
|
485 // CPbk2CreateNewContactCmd::StoreUnavailable |
|
486 // -------------------------------------------------------------------------- |
|
487 // |
|
488 void CPbk2CreateNewContactCmd::StoreUnavailable( |
|
489 MVPbkContactStore& /*aContactStore*/, |
|
490 TInt /*aReason*/ ) |
|
491 { |
|
492 iState = EFinishCommand; |
|
493 IssueRequest(); |
|
494 } |
|
495 |
|
496 // -------------------------------------------------------------------------- |
|
497 // CPbk2CreateNewContactCmd::HandleStoreEventL |
|
498 // -------------------------------------------------------------------------- |
|
499 // |
|
500 void CPbk2CreateNewContactCmd::HandleStoreEventL( |
|
501 MVPbkContactStore& /*aContactStore*/, |
|
502 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
503 { |
|
504 // Do nothing |
|
505 } |
|
506 |
|
507 // -------------------------------------------------------------------------- |
|
508 // CPbk2CreateNewContactCmd::AddFindTextL |
|
509 // -------------------------------------------------------------------------- |
|
510 // |
|
511 TInt CPbk2CreateNewContactCmd::AddFindTextL( MVPbkStoreContact& aContact ) |
|
512 { |
|
513 TInt index = KErrNotFound; |
|
514 if (iUiControl) |
|
515 { |
|
516 const TDesC& findText = iUiControl->FindTextL(); |
|
517 if (findText != KNullDesC) |
|
518 { |
|
519 CPbk2FieldPropertyArray& fieldProperties = |
|
520 iAppServices->FieldProperties(); |
|
521 |
|
522 const TInt count( fieldProperties.Count() ); |
|
523 for (TInt i=0; i < count ; ++i) |
|
524 { |
|
525 const MPbk2FieldProperty& prop = fieldProperties.At(i); |
|
526 |
|
527 if ( IsFieldTypeIncludedL( prop.FieldType(), |
|
528 iAppServices->ContactManager(), |
|
529 R_PHONEBOOK2_LAST_NAME_SELECTOR ) ) |
|
530 { |
|
531 MVPbkStoreContactField* field = aContact.CreateFieldLC |
|
532 ( prop.FieldType() ); |
|
533 |
|
534 __ASSERT_DEBUG(field->FieldData().DataType() == |
|
535 EVPbkFieldStorageTypeText, Panic(EAddFindTextL_Logic)); |
|
536 |
|
537 MVPbkContactFieldTextData* fieldData = |
|
538 &MVPbkContactFieldTextData::Cast(field->FieldData()); |
|
539 fieldData->SetTextL(findText); |
|
540 |
|
541 index = aContact.AddFieldL(field); |
|
542 CleanupStack::Pop(); // field |
|
543 break; |
|
544 } |
|
545 } |
|
546 } |
|
547 } |
|
548 return index; |
|
549 } |
|
550 |
|
551 // -------------------------------------------------------------------------- |
|
552 // CPbk2CreateNewContactCmd::ShowStoreFullNoteL |
|
553 // -------------------------------------------------------------------------- |
|
554 // |
|
555 void CPbk2CreateNewContactCmd::ShowStoreFullNoteL( |
|
556 const MVPbkContactStore& aTargetStore ) |
|
557 { |
|
558 // Fetch store name |
|
559 TVPbkContactStoreUriPtr uri = |
|
560 aTargetStore.StoreProperties().Uri(); |
|
561 const CPbk2StoreProperty* storeProperty = |
|
562 iAppServices->StoreProperties().FindProperty(uri); |
|
563 |
|
564 const TDesC* storeName = NULL; |
|
565 if (storeProperty) |
|
566 { |
|
567 storeName = &storeProperty->StoreName(); |
|
568 } |
|
569 else |
|
570 { |
|
571 storeName = &uri.UriDes(); |
|
572 } |
|
573 ShowNoteL( R_QTN_PHOB_NOTE_STORE_FULL, *storeName ); |
|
574 } |
|
575 |
|
576 // -------------------------------------------------------------------------- |
|
577 // CPbk2CreateNewContactCmd::HandleContactEditingCompleteL |
|
578 // -------------------------------------------------------------------------- |
|
579 // |
|
580 void CPbk2CreateNewContactCmd::HandleContactEditingCompleteL( |
|
581 MVPbkStoreContact* aEditedContact ) |
|
582 { |
|
583 __ASSERT_DEBUG( iCommandObserver, Panic(EPanicPreCond_Null_Pointer)); |
|
584 |
|
585 CleanupDeletePushL( aEditedContact ); |
|
586 |
|
587 // Reset Find before setting the focus because if new contact is created |
|
588 // through find box, ResetFindL corrupts the focus. |
|
589 if ( iUiControl ) |
|
590 { |
|
591 iUiControl->ResetFindL(); |
|
592 if ( aEditedContact ) |
|
593 { |
|
594 // Focus the created contact if the contact is shown in the list |
|
595 CVPbkContactStoreUriArray* shownStores = |
|
596 iAppServices-> |
|
597 StoreValidityInformer().CurrentlyValidShownStoresL(); |
|
598 TVPbkContactStoreUriPtr uri = |
|
599 aEditedContact->ParentStore().StoreProperties().Uri(); |
|
600 TBool valid = shownStores->IsIncluded( uri ); |
|
601 delete shownStores; |
|
602 |
|
603 if ( valid ) |
|
604 { |
|
605 iUiControl->SetFocusedContactL( *aEditedContact ); |
|
606 } |
|
607 } |
|
608 } |
|
609 CleanupStack::PopAndDestroy(); // aEditedContact |
|
610 iState = EFinishCommand; |
|
611 IssueRequest(); |
|
612 } |
|
613 |
|
614 // -------------------------------------------------------------------------- |
|
615 // CPbk2CreateNewContactCmd::ShowCreateNewToPhoneQueryL |
|
616 // -------------------------------------------------------------------------- |
|
617 // |
|
618 TInt CPbk2CreateNewContactCmd::ShowCreateNewToPhoneQueryL() const |
|
619 { |
|
620 TInt ret = 0; |
|
621 |
|
622 // Do not ask the question if phone memory itself is unavailable |
|
623 if ( iAppServices-> |
|
624 StoreConfiguration().DefaultSavingStoreL().Compare |
|
625 ( VPbkContactStoreUris::DefaultCntDbUri(), |
|
626 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents ) != 0 ) |
|
627 { |
|
628 HBufC* prompt = |
|
629 StringLoader::LoadLC( R_QTN_PHOB_QUERY_CREATE_NEW_TO_STORE ); |
|
630 |
|
631 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
632 ret = dlg->ExecuteLD( R_PBK2_GENERAL_CONFIRMATION_QUERY, *prompt ); |
|
633 CleanupStack::PopAndDestroy( prompt ); |
|
634 } |
|
635 |
|
636 return ret; |
|
637 } |
|
638 |
|
639 // -------------------------------------------------------------------------- |
|
640 // CPbk2CreateNewContactCmd::LoadContactStoreL |
|
641 // -------------------------------------------------------------------------- |
|
642 // |
|
643 void CPbk2CreateNewContactCmd::LoadContactStoreL() |
|
644 { |
|
645 CVPbkContactManager& manager = iAppServices->ContactManager(); |
|
646 |
|
647 manager.LoadContactStoreL( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
648 iTargetStore = manager.ContactStoresL(). |
|
649 Find( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
650 |
|
651 if ( iTargetStore ) |
|
652 { |
|
653 if ( IsValidStoreL( |
|
654 iAppServices->StoreValidityInformer(), iTargetStore ) ) |
|
655 { |
|
656 iState = EValidateStore; |
|
657 } |
|
658 else |
|
659 { |
|
660 iState = EOpenContactStore; |
|
661 } |
|
662 } |
|
663 else |
|
664 { |
|
665 iState = EFinishCommand; |
|
666 } |
|
667 IssueRequest(); |
|
668 } |
|
669 |
|
670 // -------------------------------------------------------------------------- |
|
671 // CPbk2CreateNewContactCmd::OpenContactStoreL |
|
672 // -------------------------------------------------------------------------- |
|
673 // |
|
674 void CPbk2CreateNewContactCmd::OpenContactStoreL() |
|
675 { |
|
676 __ASSERT_DEBUG( iTargetStore, |
|
677 Panic( EPanicPreCond_OpenContactStoreL ) ); |
|
678 |
|
679 iTargetStore->OpenL( *this ); |
|
680 } |
|
681 |
|
682 // -------------------------------------------------------------------------- |
|
683 // CPbk2CreateNewContactCmd::ValidateStoreL |
|
684 // -------------------------------------------------------------------------- |
|
685 // |
|
686 void CPbk2CreateNewContactCmd::ValidateStoreL() |
|
687 { |
|
688 __ASSERT_DEBUG( iTargetStore, |
|
689 Panic( EPanicPreCond_ValidateStoreL ) ); |
|
690 |
|
691 if ( StoreFullL( *iTargetStore ) ) |
|
692 { |
|
693 ShowStoreFullNoteL( *iTargetStore ); |
|
694 iState = EFinishCommand; |
|
695 } |
|
696 else |
|
697 { |
|
698 iState = ECreateNewContact; |
|
699 } |
|
700 |
|
701 IssueRequest(); |
|
702 } |
|
703 |
|
704 // -------------------------------------------------------------------------- |
|
705 // CPbk2CreateNewContactCmd::CreateNewContactL |
|
706 // -------------------------------------------------------------------------- |
|
707 // |
|
708 void CPbk2CreateNewContactCmd::CreateNewContactL() |
|
709 { |
|
710 __ASSERT_DEBUG( iTargetStore, |
|
711 Panic( EPanicPreCond_CreateNewContactL ) ); |
|
712 |
|
713 MVPbkStoreContact* contact = iTargetStore->CreateNewContactLC(); |
|
714 |
|
715 // verify syncronization field existance and content |
|
716 VPbkUtils::VerifySyncronizationFieldL |
|
717 ( CCoeEnv::Static()->FsSession(), |
|
718 iTargetStore->StoreProperties().SupportedFields(), *contact ); |
|
719 |
|
720 TUint32 flags = TPbk2ContactEditorParams::ENewContact; |
|
721 TPbk2ContactEditorParams params( flags ); |
|
722 |
|
723 CPbk2ContactEditorDlg* dlg = |
|
724 CPbk2ContactEditorDlg::NewL(params, contact, *this); |
|
725 CleanupStack::Pop(); // contact, whose ownership was taken away |
|
726 dlg->ExecuteLD(); |
|
727 } |
|
728 |
|
729 // -------------------------------------------------------------------------- |
|
730 // CPbk2CreateNewContactCmd::IssueRequest |
|
731 // -------------------------------------------------------------------------- |
|
732 // |
|
733 void CPbk2CreateNewContactCmd::IssueRequest() |
|
734 { |
|
735 TRequestStatus* status = &iStatus; |
|
736 User::RequestComplete( status, KErrNone ); |
|
737 SetActive(); |
|
738 } |
|
739 |
|
740 // End of File |