TBool CVoIPForm::SaveFormDataL() { CVoIPAppUi* iAppUi = static_cast<CVoIPAppUi*> (iEikonEnv->EikAppUi()); CVoIPDocument* iDocument = static_cast<CVoIPDocument*> (iAppUi->Document()); TInt iModifyIndex = iDocument->ModifyIndex(); RPointerArray<CContact> contacts = iAppUi->GetPhoneBook()->GetContactsL(); if (iModifyIndex >= 0) { CContact* contact = contacts[iModifyIndex]; if (contact) { iAppUi->GetPhoneBook()->DeleteContactItem(contact->GetEntryId()); TContactItemId contactItemId = iAppUi->GetPhoneBook()->CreateDefaultContactItem(); contact->SetEntryId(contactItemId); CPbkContactItem* contactItem = iAppUi->GetPhoneBook()->OpenContactItemLCX(contactItemId); TInt pageId = ActivePageId(); RArray<CEikCaptionedControl*> aControls; ControlsOnPage(aControls, pageId); for (TInt i = 0; i < aControls.Count(); i++) { CEikCaptionedControl* control = ((CEikCaptionedControl*) aControls[i]); TPbkContactItemField* field = contactItem->FindField( control->iId); if (field == NULL) { CPbkFieldInfo* fieldInfo = iAppUi->GetPhoneBook()->GetFieldsInfo().Find( control->iId); contactItem->AddFieldL(*fieldInfo); field = contactItem->FindField(control->iId); } field->SetLabelL(control->GetFullCaptionText()); CPbkFieldInfo& fieldInfo = field->FieldInfo(); if (fieldInfo.CtrlType() == EPbkFieldCtrlTypeDateEditor) { CEikDateEditor* nEditor = static_cast<CEikDateEditor*> (ControlOrNull( control->iId)); TTime time = nEditor->Date(); field->DateTimeStorage()->SetTime(time); } else { CEikEdwin* nEditor = static_cast<CEikEdwin*> (ControlOrNull( control->iId)); HBufC* text = nEditor->GetTextInHBufL(); field->TextStorage()->SetText(text); } } aControls.Reset(); iAppUi->GetPhoneBook()->CommitContactItem(contactItem); CleanupStack::PopAndDestroy(2); //OpenContactItemLCX } } return ETrue; }
void CVoIPForm::LoadFormValuesFromDataL() { TInt pageId = ActivePageId(); // Delete all controls not saved. RArray<CEikCaptionedControl*> aControls; ControlsOnPage(aControls, pageId); for (TInt i = 0; i < aControls.Count(); i++) { CEikCaptionedControl* control = ((CEikCaptionedControl*) aControls[i]); DeleteLine(control->iId, EFalse); } aControls.Reset(); // Create controls based on PhoneBook contact item. CVoIPAppUi* iAppUi = static_cast<CVoIPAppUi*> (iEikonEnv->EikAppUi()); CVoIPDocument* iDocument = static_cast<CVoIPDocument*> (iAppUi->Document()); TInt iModifyIndex = iDocument->ModifyIndex(); RPointerArray<CContact> contacts = iAppUi->GetPhoneBook()->GetContactsL(); if (iModifyIndex >= 0) { CContact* contact = contacts[iModifyIndex]; if (contact) { CPbkContactItem* contactItem = iAppUi->GetPhoneBook()->ReadContactItemLC( contact->GetEntryId()); CPbkFieldArray& fieldArray = contactItem->CardFields(); for (TInt i = 0; i < fieldArray.Count(); i++) { TPbkContactItemField field = fieldArray[i]; if (field.IsEmpty() == EFalse) { CPbkFieldInfo& fieldInfo = field.FieldInfo(); TInt id = fieldInfo.FieldId(); TAny* unused = 0; if (fieldInfo.CtrlType() == EPbkFieldCtrlTypeTextEditor) { TInt type = EEikCtEdwin; CEikEdwin * nEditor = static_cast<CEikEdwin*> (ControlOrNull(id)); if (!nEditor) { CEikEdwin* edwin = (CEikEdwin*) CreateLineByTypeL( field.Label(), pageId, id, type, unused); edwin->ConstructL(EEikEdwinNoHorizScrolling | EEikEdwinResizable, 10, 100, 1); edwin->SetTextL(&(field.Text())); } } else if (fieldInfo.CtrlType() == EPbkFieldCtrlTypeNumberEditor) { TInt type = EAknCtIntegerEdwin; CAknNumericEdwin * nEditor = static_cast<CAknNumericEdwin*> (ControlOrNull( id)); if (!nEditor) { CAknNumericEdwin* edwin = (CAknNumericEdwin*) CreateLineByTypeL( field.Label(), pageId, id, type, unused); edwin->ConstructL(EEikEdwinNoHorizScrolling | EEikEdwinResizable, 10, 100, 1); edwin->SetTextL(&(field.Text())); } } else if (fieldInfo.CtrlType() == EPbkFieldCtrlTypeDateEditor) { TInt type = EEikCtDateEditor; CEikDateEditor * nEditor = static_cast<CEikDateEditor*> (ControlOrNull( id)); if (!nEditor) { CEikDateEditor* editor = (CEikDateEditor*) CreateLineByTypeL( field.Label(), pageId, id, type, unused); editor->ConstructL(TTime(mindateTime), TTime( maxdateTime), field.DateTimeStorage()->Time(), ETrue); } Line(id)->ActivateL(); } } } SetChangesPending(ETrue); UpdatePageL(ETrue); CleanupStack::PopAndDestroy(); //contactItem } } }