/*=========================================================================== FUNCTION: ABR_DeleteContactRec DESCRIPTION: This function delete record whose id is wID PARAMETERS: pMe [in] - Pointer to the CAddrBookRuim structure. This structure contains information specific to this applet. wID[in] - record id which is want to be deleted DEPENDENCIES: None RETURN VALUE: AEE_SUCCESS - IADDRREC_RemoveRec operate successfully other - fail SIDE EFFECTS: None ===========================================================================*/ int32 ABR_DeleteContactRec( CAddrBookRuim *pMe, AEECLSID ContactCLS, uint16 wID) { int nRet = 0; IAddrBook *pb; IAddrRec *pR; if ( pMe==NULL || pMe->pIShell==NULL ) { return (-1); } if(!ISHELL_CreateInstance(pMe->pIShell, ContactCLS, (void **)&pb)) { pR = IADDRBOOK_GetRecByID(pb, wID); if(pR) { nRet = IADDRREC_RemoveRec(pR); } else { nRet = 2; // IADDRBOOK_GetRecByID fail } IADDRBOOK_Release(pb); } else { nRet = 1; } 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; }