/*=========================================================================== FUNCTION: ABR_AddContactRec DESCRIPTION: This function add a record to address book PARAMETERS: pMe [in] - Pointer to the CAddrBookRuim structure. This structure contains information specific to this applet. pTextName[in]- name field of record pTextNum[in]- telephone number field of record DEPENDENCIES: None RETURN VALUE: AEE_SUCCESS - IADDRBOOK_CreateRec () invocation was successful other - fail SIDE EFFECTS: None ===========================================================================*/ int32 ABR_AddContactRec( CAddrBookRuim *pMe, AEECLSID ContactCLS, AECHAR *pTextName, AECHAR *pTextNum) { AEEAddrField field[2]; // fields of a record int32 nRet = 0; // return code IAddrBook *pAddrBook; // check point if(pMe==NULL || pMe->pIShell==NULL || pTextName==NULL || pTextNum==NULL) { return -1; } // create instance of ADDRESS BOOK for RUIM if(!ISHELL_CreateInstance(pMe->pIShell, ContactCLS, (void **)&pAddrBook)) { IAddrRec *pRec; //Num field[0].fID = (ContactCLS==AEECLSID_ADDRBOOK_RUIM)? AEE_ADDRFIELD_PHONE_GENERIC:AEE_ADDRFIELD_PHONE_WORK; field[0].fType = AEEDB_FT_PHONE; field[0].pBuffer= pTextNum; field[0].wDataLen = (WSTRLEN(pTextNum)+1)*sizeof(AECHAR); //Name field[1].fID = AEE_ADDRFIELD_NAME; field[1].fType = AEEDB_FT_STRING; field[1].pBuffer= pTextName; field[1].wDataLen = (WSTRLEN(pTextName)+1)*sizeof(AECHAR); // create a record with 2 fields pRec = IADDRBOOK_CreateRec(pAddrBook, AEE_ADDR_CAT_NONE, (AEEAddrField*)field, 2); if(pRec) { IADDRREC_Release(pRec); nRet=0; // success } else { nRet=2; // IADDRBOOK_CreateRec fail; } IADDRBOOK_Release(pAddrBook); } else { nRet=1; // error : ISHELL_CreateInstance fail } DBGPRINTF("Add contact nRet = %d", nRet); return nRet; }
// ================================================================================ // FUNCTION : UpdateAddrBook // DESCRIPTION : Update phone addressbook. // ================================================================================ bool CDbHandler::UpdateAddrBook(CContactInfo *pContactAr, int nSize) { int nState=0; IAddrBook *pAddrBook=NULL; IAddrRec *pRec=NULL; AEEAddrField *field=NULL; int nCount=0; int nRet=0; uint16 wId=0; AECHAR* pwsGlobalId=NULL; if(SUCCESS!=ISHELL_CreateInstance(m_pIShell, AEECLSID_ADDRBOOK, (void **)&pAddrBook)) return false; for (int i=0; i<nSize; i++) { nState = pContactAr[i].GetState(); if ( pContactAr[i].FillAddrFields(&field, nCount)) { switch (nState) { case SM_RECORD_ADD: pRec = IADDRBOOK_CreateRec(pAddrBook,AEE_ADDR_CAT_NONE, (AEEAddrField*)field, nCount); if (NULL==pRec) { IADDRBOOK_Release(pAddrBook); delete [] field; return false; } //set contact id of record. pContactAr[i].SetContactId( IADDRREC_GetRecID(pRec)); IADDRREC_Release(pRec); pRec=NULL; break; case SM_RECORD_UPDATE: wId = pContactAr[i].GetContactId(); pRec = IADDRBOOK_GetRecByID(pAddrBook, wId); if ( NULL!=pRec ) { if ( AEE_SUCCESS != IADDRREC_UpdateAllFields(pRec,field,nCount)) { IADDRREC_Release(pRec); IADDRBOOK_Release(pAddrBook); delete [] field; return false; } //set contact id of record. //pContactAr[i].SetContactId( IADDRREC_GetRecID(pRec)); IADDRREC_Release(pRec); pRec=NULL; } break; case SM_RECORD_DELETE: wId = pContactAr[i].GetContactId(); DBGPRINTF("Deleted rec id= %u", wId); pRec = IADDRBOOK_GetRecByID(pAddrBook, wId); if ( NULL!=pRec ) { //set contact id of record. pContactAr[i].SetContactId( IADDRREC_GetRecID(pRec)); if(AEE_SUCCESS !=IADDRREC_RemoveRec(pRec)) { IADDRBOOK_Release(pAddrBook); delete [] field; return false; } DBGPRINTF("deleted record"); //no need to relase the address record after deleting it. } break; default: break; } if ( NULL!=field ) { delete [] field; field=NULL; } } } IADDRBOOK_Release(pAddrBook); return true; }