fix N_SE-47241
authorGwangbok Kim <gwangbok.kim@samsung.com>
Mon, 29 Jul 2013 12:48:50 +0000 (21:48 +0900)
committerGwangbok Kim <gwangbok.kim@samsung.com>
Wed, 31 Jul 2013 12:06:21 +0000 (21:06 +0900)
Change-Id: Id88fb58035183e38ca05597f049e8e954a1adce3
Signed-off-by: Gwangbok Kim <gwangbok.kim@samsung.com>
src/FScl_AddressbookImpl.cpp
src/FScl_AddressbookManagerImpl.cpp
src/FScl_ContactImpl.cpp
src/inc/FScl_AddressbookImpl.h
src/inc/FScl_AddressbookManagerImpl.h

index 9113253..df37681 100644 (file)
@@ -447,26 +447,82 @@ _AddressbookImpl::UpdateContact(const Contact& contact)
 
        contacts_record_h recordHandle = null;
 
-       int intValue = 0;
        int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
+       int intValue = 0;
        contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
 
        contacts_record_destroy(recordHandle, true);
        SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
        recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
+       SysTryReturn(NID_SCL, recordHandle != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        ret = contacts_db_update_record(recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
+       if (ret == CONTACTS_ERROR_NO_DATA)
+       {
+               unsigned int count = 0;
+               unsigned int count2 = 0;
+
+               contacts_record_h newRecordHandle = null;
+               ret = contacts_db_get_record(_contacts_contact._uri, contactId, &newRecordHandle);
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+               contacts_record_get_child_record_count(newRecordHandle, _contacts_contact.image, &count);
+               contacts_record_get_child_record_count(recordHandle, _contacts_contact.image, &count2);
+
+               contacts_record_h imageHandle = null;
+               contacts_record_h imageHandle2 = null;
+
+               int imageId = -1;
+               int imageId2 = -1;
+
+               for (int i = count2 - 1; i >= 0; i--)
+               {
+                       contacts_record_get_child_record_at_p(recordHandle, _contacts_contact.image, i, &imageHandle);
+                       contacts_record_get_int(imageHandle, _contacts_image.id, &imageId);
+                       if (imageId == 0)
+                       {
+                               continue;
+                       }
+
+                       bool matchFound = false;
+
+                       for (int j = 0; j < count; j++)
+                       {
+                               contacts_record_get_child_record_at_p(newRecordHandle, _contacts_contact.image, i, &imageHandle2);
+                               contacts_record_get_int(imageHandle2, _contacts_image.id, &imageId2);
+                               if (imageId == imageId2)
+                               {
+                                       matchFound = true;
+                                       break;
+                               }
+                       }
+
+                       if (!matchFound)
+                       {
+                               contacts_record_remove_child_record(recordHandle, _contacts_contact.image, imageHandle);
+                       }
+               }
+
+               contacts_record_destroy(newRecordHandle, true);
+
+               contacts_record_h copyRecordHandle = CopyContactRecordHandle(recordHandle);
+               SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               ret = contacts_db_replace_record(copyRecordHandle, contactId);
+               contacts_record_destroy(copyRecordHandle, true);
+       }
+
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       ret = contacts_db_get_record(_contacts_contact._uri, contact.GetRecordId(), &recordHandle);
+       ret = contacts_db_get_record(_contacts_contact._uri, contactId, &recordHandle);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
@@ -1799,6 +1855,447 @@ _AddressbookImpl::CopyMyProfileContents(contacts_record_h srcHandle, contacts_re
        return E_SUCCESS;
 }
 
+contacts_record_h
+_AddressbookImpl::CopyContactRecordHandle(contacts_record_h srcHandle)
+{
+       ClearLastResult();
+
+       int ret = CONTACTS_ERROR_NONE;
+       unsigned int i = 0;
+       unsigned int count = 0;
+       char* pCharValue = null;
+       int intValue = 0;
+       bool boolValue = false;
+
+       contacts_record_h contactHandle = null;
+       contacts_record_h sourceRecordHandle = null;
+       contacts_record_h destRecordHandle = null;
+
+       ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
+       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       // favorite
+       contacts_record_get_bool(sourceRecordHandle, _contacts_contact.is_favorite, &boolValue);
+       contacts_record_set_bool(destRecordHandle, _contacts_contact.is_favorite, boolValue);
+
+       // uid
+       contacts_record_get_str_p(sourceRecordHandle, _contacts_contact.uid, &pCharValue);
+       contacts_record_set_str(destRecordHandle, _contacts_contact.uid, pCharValue);
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // name
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.name, &count);
+       if (count > 0)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.name, 0, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_name._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle nameHandle(destRecordHandle);
+
+               // 1. first
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.first, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.first, pCharValue);
+
+               // 2. last
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.last, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.last, pCharValue);
+
+               // 3. addition
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.addition, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.addition, pCharValue);
+
+               // 4. suffix
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.suffix, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.suffix, pCharValue);
+
+               // 5. prefix
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.prefix, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.prefix, pCharValue);
+
+               // 6. phonetic_first
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_first, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_first, pCharValue);
+
+               // 7. phonetic_last
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_last, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_last, pCharValue);
+
+               // 8. phonetic_middle
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_middle, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.name, destRecordHandle);
+
+               nameHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // image
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.image, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.image, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_image._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle imageHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_image.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_image.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_image.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_image.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_image.path, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_image.path, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.image, destRecordHandle);
+
+               imageHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // company
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.company, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.company, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_company._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle companyHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_company.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_company.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.name, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.department, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.department, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.job_title, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.job_title, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.assistant_name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.assistant_name, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.role, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.role, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.logo, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.logo, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.location, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.location, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.description, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.description, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.phonetic_name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.phonetic_name, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.company, destRecordHandle);
+
+               companyHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // note
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.note, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.note, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_note._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle noteHandle(destRecordHandle);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_note.note, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_note.note, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.note, destRecordHandle);
+
+               noteHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // phone number
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.number, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.number, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_number._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle numberHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_number.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_number.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_number.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_number.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_number.number, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_number.number, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.number, destRecordHandle);
+
+               numberHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // email
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.email, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.email, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_email._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle emailHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_email.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_email.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_email.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_email.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_email.email, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_email.email, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.email, destRecordHandle);
+
+               emailHandle.Release();
+
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // event
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.event, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.event, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_event._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle eventHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_event.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_event.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_event.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_event.label, pCharValue);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_event.date, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_event.date, intValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.event, destRecordHandle);
+
+               eventHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // im address
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.messenger, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.messenger, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_messenger._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle imAddressHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_messenger.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_messenger.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_messenger.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.im_id, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_messenger.im_id, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.messenger, destRecordHandle);
+
+               imAddressHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // address
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.address, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.address, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_address._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle addressHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_address.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_address.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postbox, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.postbox, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.extended, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.extended, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.street, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.street, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.locality, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.locality, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.region, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.region, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postal_code, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.postal_code, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.country, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.country, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.address, destRecordHandle);
+
+               addressHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // url
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.url, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.url, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_url._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle urlHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_url.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_url.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_url.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_url.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_url.url, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_url.url, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.url, destRecordHandle);
+
+               urlHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // nickname
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.nickname, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.nickname, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_nickname._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle nicknameHandle(destRecordHandle);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_nickname.name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_nickname.name, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.nickname, destRecordHandle);
+
+               nicknameHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // relationship
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.relationship, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.relationship, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_relationship._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle relationshipHandle(destRecordHandle);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_relationship.name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_relationship.name, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.relationship, destRecordHandle);
+
+               relationshipHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // app launch data
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.profile, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.profile, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_profile._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle profileHandle(destRecordHandle);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.text, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.text, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uid, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.uid, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.app_id, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.app_id, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.service_operation, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.service_operation, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uri, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.uri, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.category, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.category, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.mime, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.mime, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.extra_data, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.extra_data, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.profile, destRecordHandle);
+
+               profileHandle.Release();
+       }
+
+       return contactHandle;
+}
+
 void
 _AddressbookImpl::OnContactChanged(void)
 {
index 4bcf99c..bacc1e3 100644 (file)
@@ -485,8 +485,65 @@ _AddressbookManagerImpl::UpdateContact(const Contact& contact)
        SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
        contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
+       SysTryReturn(NID_SCL, recordHandle != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        int ret = contacts_db_update_record(recordHandle);
+       if (ret == CONTACTS_ERROR_NO_DATA)
+       {
+               unsigned int count = 0;
+               unsigned int count2 = 0;
+
+               contacts_record_h newRecordHandle = null;
+               ret = contacts_db_get_record(_contacts_contact._uri, contactId, &newRecordHandle);
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+               contacts_record_get_child_record_count(newRecordHandle, _contacts_contact.image, &count);
+               contacts_record_get_child_record_count(recordHandle, _contacts_contact.image, &count2);
+
+               contacts_record_h imageHandle = null;
+               contacts_record_h imageHandle2 = null;
+
+               int imageId = -1;
+               int imageId2 = -1;
+
+               for (int i = count2 - 1; i >= 0; i--)
+               {
+                       contacts_record_get_child_record_at_p(recordHandle, _contacts_contact.image, i, &imageHandle);
+                       contacts_record_get_int(imageHandle, _contacts_image.id, &imageId);
+                       if (imageId == 0)
+                       {
+                               continue;
+                       }
+
+                       bool matchFound = false;
+
+                       for (int j = 0; j < count; j++)
+                       {
+                               contacts_record_get_child_record_at_p(newRecordHandle, _contacts_contact.image, i, &imageHandle2);
+                               contacts_record_get_int(imageHandle2, _contacts_image.id, &imageId2);
+                               if (imageId == imageId2)
+                               {
+                                       matchFound = true;
+                                       break;
+                               }
+                       }
+
+                       if (!matchFound)
+                       {
+                               contacts_record_remove_child_record(recordHandle, _contacts_contact.image, imageHandle);
+                       }
+               }
+
+               contacts_record_destroy(newRecordHandle, true);
+
+               contacts_record_h copyRecordHandle = CopyContactRecordHandle(recordHandle);
+               SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               ret = contacts_db_replace_record(copyRecordHandle, contactId);
+               contacts_record_destroy(copyRecordHandle, true);
+       }
+
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed to update a contact.", GetErrorMessage(E_SYSTEM));
@@ -2748,6 +2805,447 @@ _AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
        return pProfile;
 }
 
+contacts_record_h
+_AddressbookManagerImpl::CopyContactRecordHandle(contacts_record_h srcHandle)
+{
+       ClearLastResult();
+
+       int ret = CONTACTS_ERROR_NONE;
+       unsigned int i = 0;
+       unsigned int count = 0;
+       char* pCharValue = null;
+       int intValue = 0;
+       bool boolValue = false;
+
+       contacts_record_h contactHandle = null;
+       contacts_record_h sourceRecordHandle = null;
+       contacts_record_h destRecordHandle = null;
+
+       ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
+       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       // favorite
+       contacts_record_get_bool(sourceRecordHandle, _contacts_contact.is_favorite, &boolValue);
+       contacts_record_set_bool(destRecordHandle, _contacts_contact.is_favorite, boolValue);
+
+       // uid
+       contacts_record_get_str_p(sourceRecordHandle, _contacts_contact.uid, &pCharValue);
+       contacts_record_set_str(destRecordHandle, _contacts_contact.uid, pCharValue);
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // name
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.name, &count);
+       if (count > 0)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.name, 0, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_name._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle nameHandle(destRecordHandle);
+
+               // 1. first
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.first, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.first, pCharValue);
+
+               // 2. last
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.last, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.last, pCharValue);
+
+               // 3. addition
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.addition, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.addition, pCharValue);
+
+               // 4. suffix
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.suffix, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.suffix, pCharValue);
+
+               // 5. prefix
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.prefix, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.prefix, pCharValue);
+
+               // 6. phonetic_first
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_first, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_first, pCharValue);
+
+               // 7. phonetic_last
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_last, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_last, pCharValue);
+
+               // 8. phonetic_middle
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_middle, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.name, destRecordHandle);
+
+               nameHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // image
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.image, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.image, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_image._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle imageHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_image.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_image.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_image.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_image.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_image.path, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_image.path, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.image, destRecordHandle);
+
+               imageHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // company
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.company, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.company, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_company._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle companyHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_company.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_company.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.name, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.department, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.department, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.job_title, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.job_title, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.assistant_name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.assistant_name, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.role, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.role, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.logo, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.logo, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.location, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.location, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.description, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.description, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_company.phonetic_name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_company.phonetic_name, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.company, destRecordHandle);
+
+               companyHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // note
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.note, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.note, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_note._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle noteHandle(destRecordHandle);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_note.note, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_note.note, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.note, destRecordHandle);
+
+               noteHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // phone number
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.number, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.number, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_number._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle numberHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_number.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_number.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_number.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_number.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_number.number, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_number.number, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.number, destRecordHandle);
+
+               numberHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // email
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.email, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.email, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_email._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle emailHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_email.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_email.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_email.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_email.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_email.email, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_email.email, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.email, destRecordHandle);
+
+               emailHandle.Release();
+
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // event
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.event, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.event, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_event._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle eventHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_event.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_event.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_event.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_event.label, pCharValue);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_event.date, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_event.date, intValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.event, destRecordHandle);
+
+               eventHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // im address
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.messenger, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.messenger, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_messenger._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle imAddressHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_messenger.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_messenger.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_messenger.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.im_id, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_messenger.im_id, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.messenger, destRecordHandle);
+
+               imAddressHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // address
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.address, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.address, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_address._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle addressHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_address.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_address.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postbox, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.postbox, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.extended, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.extended, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.street, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.street, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.locality, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.locality, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.region, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.region, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postal_code, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.postal_code, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_address.country, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_address.country, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.address, destRecordHandle);
+
+               addressHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // url
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.url, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.url, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_url._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle urlHandle(destRecordHandle);
+
+               contacts_record_get_int(sourceRecordHandle, _contacts_url.type, &intValue);
+               contacts_record_set_int(destRecordHandle, _contacts_url.type, intValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_url.label, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_url.label, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_url.url, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_url.url, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.url, destRecordHandle);
+
+               urlHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // nickname
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.nickname, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.nickname, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_nickname._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle nicknameHandle(destRecordHandle);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_nickname.name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_nickname.name, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.nickname, destRecordHandle);
+
+               nicknameHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // relationship
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.relationship, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.relationship, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_relationship._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle relationshipHandle(destRecordHandle);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_relationship.name, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_relationship.name, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.relationship, destRecordHandle);
+
+               relationshipHandle.Release();
+       }
+
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       // app launch data
+       /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+       contacts_record_get_child_record_count(srcHandle, _contacts_contact.profile, &count);
+       for (i = 0; i < count; i++)
+       {
+               contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.profile, i, &sourceRecordHandle);
+
+               ret = contacts_record_create(_contacts_profile._uri, &destRecordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               __ContactsRecordHandle profileHandle(destRecordHandle);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.text, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.text, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uid, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.uid, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.app_id, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.app_id, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.service_operation, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.service_operation, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uri, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.uri, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.category, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.category, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.mime, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.mime, pCharValue);
+
+               contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.extra_data, &pCharValue);
+               contacts_record_set_str(destRecordHandle, _contacts_profile.extra_data, pCharValue);
+
+               contacts_record_add_child_record(contactHandle, _contacts_contact.profile, destRecordHandle);
+
+               profileHandle.Release();
+       }
+
+       return contactHandle;
+}
+
 _AddressbookManagerImpl*
 _AddressbookManagerImpl::GetInstance(AddressbookManager& addressbookManager)
 {
index 331f331..7f59e6d 100644 (file)
@@ -4961,9 +4961,6 @@ _ContactImpl::Invalidate(void)
 
                __ContactsRecordHandle profileHandle(destRecordHandle);
 
-               contacts_record_get_str_p(sourceRecordHandle, _contacts_relationship.name, &pCharValue);
-               contacts_record_set_str(destRecordHandle, _contacts_relationship.name, pCharValue);
-
                contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.text, &pCharValue);
                contacts_record_set_str(destRecordHandle, _contacts_profile.text, pCharValue);
 
index ba87723..4cdb5ed 100644 (file)
@@ -169,6 +169,8 @@ public:
 
        virtual void OnRelationChanged(void);
 
+       contacts_record_h CopyContactRecordHandle(contacts_record_h srcHandle);
+
        static _AddressbookImpl* GetInstance(Addressbook& addressbook);
 
        static const _AddressbookImpl* GetInstance(const Addressbook& addressbook);
index 9010b52..88208b6 100644 (file)
@@ -205,6 +205,8 @@ public:
 
        static bool OnEachContact(contacts_record_h recordHandle, void* pUserData);
 
+       contacts_record_h CopyContactRecordHandle(contacts_record_h srcHandle);
+
        static _AddressbookManagerImpl* GetInstance(AddressbookManager& addressbookManager);
 
        static const _AddressbookManagerImpl* GetInstance(const AddressbookManager& addressbookManager);