// // Copyright (c) 2012 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @file FScl_AddressbookImpl.cpp * @brief This is the implementation for _AddressbookImpl class. * * This file contains definitions of @e _AddressbookImpl class. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "FScl_AddressbookImpl.h" #include "FScl_AddressbookUtil.h" #include "FScl_CategoryChangeInfoImpl.h" #include "FScl_CategoryImpl.h" #include "FScl_ContactChangeInfoImpl.h" #include "FScl_ContactDbMonitor.h" #include "FScl_ContactImpl.h" #include "FScl_RecordImpl.h" #include "FScl_UserProfileImpl.h" #include "FScl_ContactDbConnector.h" using namespace std; using namespace Tizen::App; using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Graphics; using namespace Tizen::Io; namespace Tizen { namespace Social { _AddressbookImpl::_AddressbookImpl(void) : __pIRecordEventListener(null) , __pIAddressbookEventListener(null) , __pIAddressbookChangeEventListener(null) , __dbVersionForContact(0) , __dbVersionForGroup(0) , __dbVersionForRelation(0) , __addressbookId(INVALID_ADDRESSBOOK_ID) , __accountId(-1) { // empty body. } _AddressbookImpl::~_AddressbookImpl(void) { if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null) { _ContactDbMonitor* pDbMonitor = _ContactDbMonitor::GetInstance(); if (pDbMonitor != null) { pDbMonitor->RemoveListener(*this); } } } result _AddressbookImpl::Construct(void) { static AccountId accountId = 0; static String name; if (name.IsEmpty()) { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); char* pName = null; contacts_record_h recordHandle = null; int ret = contacts_db_get_record(_contacts_address_book._uri, DEFAULT_ADDRESSBOOK_ID, &recordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred. Addressbook Id(%d)", GetErrorMessage(E_SYSTEM), DEFAULT_ADDRESSBOOK_ID); contacts_record_get_str_p(recordHandle, _contacts_address_book.name, &pName); contacts_record_get_int(recordHandle, _contacts_address_book.account_id, &accountId); name = pName; contacts_record_destroy(recordHandle, true); } __addressbookId = DEFAULT_ADDRESSBOOK_ID; __accountId = accountId; __name = name; return E_SUCCESS; } result _AddressbookImpl::SetRecordEventListener(IRecordEventListener* pListener) { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); result r = E_SUCCESS; if (pListener != null) { if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null) { _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance(); SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); r = pContactDbMonitor->AddListener(*this); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } __dbVersionForContact = GetLatestVersion(); SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); __dbVersionForGroup = __dbVersionForContact; __dbVersionForRelation = __dbVersionForContact; __pIAddressbookEventListener = null; __pIAddressbookChangeEventListener = null; __pIRecordEventListener = pListener; } else { if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null) { _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance(); SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())) pContactDbMonitor->RemoveListener(*this); } __pIAddressbookEventListener = null; __pIAddressbookChangeEventListener = null; __pIRecordEventListener = null; } return E_SUCCESS; } result _AddressbookImpl::SetAddressbookEventListener(IAddressbookEventListener* pListener) { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); result r = E_SUCCESS; if (pListener != null) { if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null) { _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance(); SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); r = pContactDbMonitor->AddListener(*this); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } __dbVersionForContact = GetLatestVersion(); SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); __dbVersionForGroup = __dbVersionForContact; __dbVersionForRelation = __dbVersionForContact; __pIRecordEventListener = null; __pIAddressbookChangeEventListener = null; __pIAddressbookEventListener = pListener; } else { if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null) { _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance(); SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); pContactDbMonitor->RemoveListener(*this); } __pIAddressbookEventListener = null; __pIAddressbookChangeEventListener = null; __pIRecordEventListener = null; } return E_SUCCESS; } result _AddressbookImpl::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener) { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); result r = E_SUCCESS; if (pListener != null) { if (__pIAddressbookEventListener == null && __pIAddressbookChangeEventListener == null && __pIRecordEventListener == null) { _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance(); SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); r = pContactDbMonitor->AddListener(*this); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } __dbVersionForContact = GetLatestVersion(); SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); __dbVersionForGroup = __dbVersionForContact; __dbVersionForRelation = __dbVersionForContact; __pIRecordEventListener = null; __pIAddressbookEventListener = null; __pIAddressbookChangeEventListener = pListener; } else { if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null || __pIRecordEventListener != null) { _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance(); SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); pContactDbMonitor->RemoveListener(*this); } __pIAddressbookEventListener = null; __pIAddressbookChangeEventListener = null; __pIRecordEventListener = null; } return E_SUCCESS; } void _AddressbookImpl::SetId(AddressbookId addressbookId) { __addressbookId = addressbookId; } void _AddressbookImpl::SetAccountId(AccountId accountId) { __accountId = accountId; } void _AddressbookImpl::SetName(const String& name) { __name = name; } AddressbookId _AddressbookImpl::GetId(void) const { return __addressbookId; } AccountId _AddressbookImpl::GetAccountId(void) const { return __accountId; } String _AddressbookImpl::GetName(void) const { return __name; } result _AddressbookImpl::AddContact(Contact& contact) { if (_ContactImpl::GetInstance(contact)->IsRemoved()) { result r = _ContactImpl::GetInstance(contact)->Invalidate(); SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } SysTryReturn(NID_SCL, contact.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The ID of specified contact is not INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, !_ContactImpl::GetInstance(contact)->IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact does not have any property.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int recordId = 0; contacts_record_h recordHandle = null; recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle(); contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId); int ret = contacts_db_insert_record(recordHandle, &recordId); 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, recordId, &recordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The contact is not found."); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OBJ_NOT_FOUND, 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)); _ContactImpl::GetInstance(contact)->SetContactRecordHandle(recordHandle); _RecordImpl::GetInstance(contact)->SetRecordId(recordId); return E_SUCCESS; } result _AddressbookImpl::AddCategory(Category& category) { SysTryReturn(NID_SCL, category.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified categoryId is not INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int recordId = 0; contacts_record_h recordHandle = null; unique_ptr > pList(null); recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle(); if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { // It is not allowed to have a same name with other. int count = 0; char* pCharValue = null; contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue); __Filter<__ContactsGroup> filter; filter.Construct(); filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND); filter.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue); __Query<__ContactsGroup> query; query.Construct(); query.SetFilter(filter); count = _AddressbookUtil::GetCountWithQuery(query); SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); SysTryReturn(NID_SCL, count == 0, E_OBJ_ALREADY_EXIST, E_OBJ_ALREADY_EXIST, "[%s] The category name is already being used by other category.", GetErrorMessage(E_OBJ_ALREADY_EXIST)); } recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle(); contacts_record_set_int(recordHandle, _contacts_group.address_book_id, __addressbookId); int ret = contacts_db_insert_record(recordHandle, &recordId); 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_group._uri, recordId, &recordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category 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, "[%d] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _CategoryImpl::GetInstance(category)->SetRecordHandle(recordHandle); _RecordImpl::GetInstance(category)->SetRecordId(recordId); pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN()); if (pList != null && pList->GetCount() > 0) { unique_ptr > pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { int tableId = -1; pEnum->GetCurrent(tableId); AddMemberToCategory(category.GetRecordId(), tableId); } _CategoryImpl::GetInstance(category)->ClearAddedMemberList(); } return E_SUCCESS; } result _AddressbookImpl::RemoveContact(RecordId contactId) { SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contactId is invalid", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); result r = _AddressbookUtil::DeleteContactRecord(_contacts_contact._uri, contactId); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); return E_SUCCESS; } result _AddressbookImpl::RemoveContact(Contact& contact) { SysTryReturn(NID_SCL, contact.GetRecordId() != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The ID of specified contact is not INVALID_RECORD_ID", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); result r = RemoveContact(contact.GetRecordId()); SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r)); _ContactImpl::GetInstance(contact)->SetAsRemoved(); _RecordImpl::GetInstance(contact)->SetRecordId(INVALID_RECORD_ID); return E_SUCCESS; } result _AddressbookImpl::RemoveCategory(RecordId categoryId) { SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); unique_ptr pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId)); SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); bool isReadOnly = false; contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly); SysTryReturn(NID_SCL, !isReadOnly, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is a default category.", GetErrorMessage(E_INVALID_ARG)); result r = _AddressbookUtil::DeleteContactRecord(_contacts_group._uri, categoryId); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); return E_SUCCESS; } result _AddressbookImpl::UpdateContact(const Contact& contact) { RecordId contactId = contact.GetRecordId(); SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, !_ContactImpl::GetInstance(contact)->IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact does not have any property.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); contacts_record_h recordHandle = null; 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); 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 = (int)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 (unsigned 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)); contacts_record_h tempHandle = null; contacts_record_get_child_record_count(copyRecordHandle, _contacts_contact.image, &count); char* pCharValue = null; String tempPath; for (unsigned int i = 0; i < count; i++) { contacts_record_get_child_record_at_p(copyRecordHandle, _contacts_contact.image, i, &tempHandle); contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue); tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp"; tempPath.Append((int)i); tempPath.Append(L".jpg"); String servicePath(pCharValue); File::Copy(servicePath, tempPath, true); std::unique_ptr pCharArray( _StringConverter::CopyToCharArrayN(tempPath)); SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); contacts_record_set_str(tempHandle, _contacts_image.path, pCharArray.get()); contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue); tempPath.Clear(); } ret = contacts_db_replace_record(copyRecordHandle, contactId); contacts_record_destroy(copyRecordHandle, true); for (unsigned int i = 0; i < count; i++) { tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp"; tempPath.Append((int)i); tempPath.Append(L".jpg"); File::Remove(tempPath); tempPath.Clear(); } } 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, 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)); _ContactImpl::GetInstance(*const_cast(&contact))->SetContactRecordHandle(recordHandle); return E_SUCCESS; } result _AddressbookImpl::UpdateCategory(const Category& category) { RecordId categoryId = category.GetRecordId(); SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is invalid.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, !category.GetName().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category does not have name.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); contacts_record_h recordHandle = null; int intValue = 0; int ret = CONTACTS_ERROR_NONE; ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle); 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_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); contacts_record_get_int(recordHandle, _contacts_group.id, &intValue); contacts_record_destroy(recordHandle, true); SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle(); if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { int count = 0; char* pCharValue = null; contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue); contacts_record_get_int(recordHandle, _contacts_group.id, &intValue); __Filter<__ContactsGroup> filter1; filter1.Construct(); filter1.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND); filter1.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue); __Filter<__ContactsGroup> filter2; filter2.Construct(); filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_LESS_THAN, intValue); filter2.AddOperator(CONTACTS_FILTER_OPERATOR_OR); filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_GREATER_THAN, intValue); filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND); filter1.AddFilter(filter2); __Query<__ContactsGroup> query; query.Construct(); query.SetFilter(filter1); count = _AddressbookUtil::GetCountWithQuery(query); SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); SysTryReturn(NID_SCL, count == 0, E_OBJ_ALREADY_EXIST, E_OBJ_ALREADY_EXIST, "[%s] The category name is alread being used by other category.", GetErrorMessage(E_OBJ_ALREADY_EXIST)); } 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)); 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_group._uri, category.GetRecordId(), &recordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category 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)); _CategoryImpl::GetInstance(*const_cast(&category))->SetRecordHandle(recordHandle); std::unique_ptr > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN()); if (pList != null && pList->GetCount() > 0) { int tableId = -1; std::unique_ptr > pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { pEnum->GetCurrent(tableId); AddMemberToCategory(category.GetRecordId(), tableId); } const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList(); } pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN()); if (pList != null && pList->GetCount() > 0) { int tableId = -1; std::unique_ptr > pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { pEnum->GetCurrent(tableId); RemoveMemberFromCategory(category.GetRecordId(), tableId); } const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList(); } return E_SUCCESS; } result _AddressbookImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId) { SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId); SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); contacts_record_h recordHandle = null; int addressbookId = 0; int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist.", GetErrorMessage(E_INVALID_ARG)); 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_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId); contacts_record_destroy(recordHandle, true); SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG)); ret = contacts_group_add_contact(categoryId, contactId); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG)); 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)); return E_SUCCESS; } result _AddressbookImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId) { SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId); SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); contacts_record_h recordHandle = null; int addressbookId = 0; int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist.", GetErrorMessage(E_INVALID_ARG)); 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_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId); contacts_record_destroy(recordHandle, true); SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG)); ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The category does not exist.", GetErrorMessage(E_INVALID_ARG)); 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_int(recordHandle, _contacts_group.address_book_id, &addressbookId); contacts_record_destroy(recordHandle, true); SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The category does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG)); ret = contacts_group_remove_contact(categoryId, contactId); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG)); 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)); return E_SUCCESS; } IList* _AddressbookImpl::GetAllCategoriesN(void) const { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); __Filter<__ContactsGroup> filter; filter.Construct(); filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); __Query<__ContactsGroup> query; query.Construct(); query.SetFilter(filter); query.SetSort(_contacts_group.name, true); IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query); SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pCategories; } IList* _AddressbookImpl::GetCategoriesByContactN(RecordId contactId) const { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact is invalid.", GetErrorMessage(E_INVALID_ARG)); ClearLastResult(); __Filter<__ContactsGroupRelation> filter; filter.Construct(); filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId); __Query<__ContactsGroupRelation> query; query.Construct(); query.SetFilter(filter); query.SetSort(_contacts_group_relation.name, true); IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query); SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pCategories; } IList* _AddressbookImpl::GetAllContactsN(void) const { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); __Filter<__ContactsContact> filter; filter.Construct(); filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); __Query<__ContactsContact> query; query.Construct(); query.SetFilter(filter); query.SetSort(_contacts_contact.display_name, true); IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query); SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pContacts; } IList* _AddressbookImpl::GetContactsByCategoryN(RecordId categoryId) const { SysTryReturn(NID_SCL, categoryId >= INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. The category ID must be greater than or equal to INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); __Filter<__ContactsContactGroupRel> filter; filter.Construct(); if (categoryId != INVALID_RECORD_ID) { filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId); } else { filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0); } __Query<__ContactsContactGroupRel> query; query.Construct(); query.SetFilter(filter); query.SetSort(_contacts_contact_grouprel.display_name, true); IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query); SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pContacts; } IList* _AddressbookImpl::GetContactsN(int pageNo, int countPerPage) const { SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_OUT_OF_RANGE, "[%s] pageNo(%d) or countPerPage(%d) is less than 1.", GetErrorMessage(E_OUT_OF_RANGE), pageNo, countPerPage); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int offset = (pageNo - 1)*countPerPage; int limit = countPerPage; ClearLastResult(); __Filter<__ContactsContact> filter; filter.Construct(); filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); __Query<__ContactsContact> query; query.Construct(); query.SetFilter(filter); query.SetSort(_contacts_contact.display_name, true); IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, limit); SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pContacts; } IList* _AddressbookImpl::GetContactsInN(const Category& category, int pageNo, int countPerPage) const { SysTryReturn(NID_SCL, category.GetRecordId() != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is invalid.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_OUT_OF_RANGE, "[%s] pageNo(%d) or countPerPage(%d) is less than 1.", GetErrorMessage(E_OUT_OF_RANGE), pageNo, countPerPage); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int offset = (pageNo - 1)*countPerPage; int limit = countPerPage; ClearLastResult(); __Filter<__ContactsContactGroupRel> filter; filter.Construct(); filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, category.GetRecordId()); __Query<__ContactsContactGroupRel> query; query.Construct(); query.SetFilter(filter); query.SetSort(_contacts_contact_grouprel.display_name, true); IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query, offset, limit); SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pContacts; } IList* _AddressbookImpl::SearchContactsByEmailN(const String& email) const { SysTryReturn(NID_SCL, !email.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified email is an empty string.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { SysTryReturn(NID_SCL, email.GetLength() <= MAX_EMAIL_LENGTH, null, E_INVALID_ARG, "[%s] Invalid argument is used. The length of email is greater than MAX_EMAIL_LENGTH.", GetErrorMessage(E_INVALID_ARG)); } ClearLastResult(); std::unique_ptr pCharArray(_StringConverter::CopyToCharArrayN(email)); SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __Filter<__ContactsContactEmail> filter; filter.Construct(); filter.AddInt(_contacts_contact_email.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND); filter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get()); unsigned int projectionIds[1]; projectionIds[0] = _contacts_contact_email.contact_id; __Query<__ContactsContactEmail> query; query.Construct(); query.SetProjection(projectionIds, 1); query.SetFilter(filter); query.SetDistinct(true); query.SetSort(_contacts_contact_email.display_name, true); IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query); SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pContacts; } IList* _AddressbookImpl::SearchContactsByNameN(const String& name) const { SysTryReturn(NID_SCL, !name.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified email is an empty string.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { SysTryReturn(NID_SCL, name.GetLength() <= MAX_CONTACT_NAME_LENGTH, null, E_INVALID_ARG, "[%s] Invalid argument is used. The length of name is greater than MAX_CONTACT_NAME_LENGTH.", GetErrorMessage(E_INVALID_ARG)); } ClearLastResult(); std::unique_ptr pCharArray(_StringConverter::CopyToCharArrayN(name)); SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __Filter<__ContactsContact> filter; filter.Construct(); filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND); filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get()); __Query<__ContactsContact> query; query.Construct(); query.SetFilter(filter); query.SetSort(_contacts_contact.display_name, true); query.SetDistinct(true); IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query); SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pContacts; } IList* _AddressbookImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const { SysTryReturn(NID_SCL, !phoneNumber.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified phoneNumber is an empty string.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { int count = phoneNumber.GetLength(); SysTryReturn(NID_SCL, count >= MIN_PHONENUMBER_QUERY_LENGTH && count <= MAX_PHONE_NUMBER_LENGTH, null, E_INVALID_ARG, "[%s] Invalid argument is used. The length of phoneNumber is shorter than MIN_PHONENUMBER_QUERY_LENGTH or greater than MAX_PHONE_NUMBER_LENGTH.", GetErrorMessage(E_INVALID_ARG)); } ClearLastResult(); std::unique_ptr pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber)); SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __Filter<__ContactsContactNumber> subFilter; subFilter.Construct(); subFilter.AddString(_contacts_contact_number.normalized_number, CONTACTS_MATCH_CONTAINS, pCharArray.get()); subFilter.AddOperator(CONTACTS_FILTER_OPERATOR_OR); subFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get()); __Filter<__ContactsContactNumber> filter; filter.Construct(); filter.AddInt(_contacts_contact_number.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND); filter.AddFilter(subFilter); unsigned int projectionIds[1]; projectionIds[0] = _contacts_contact_number.contact_id; __Query<__ContactsContactNumber> query; query.Construct(); query.SetProjection(projectionIds, 1); query.SetFilter(filter); query.SetDistinct(true); query.SetSort(_contacts_contact_number.display_name, true); IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query); SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pContacts; } int _AddressbookImpl::GetCategoryCount(void) const { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int count = -1; ClearLastResult(); __Filter<__ContactsGroup> filter; filter.Construct(); filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); __Query<__ContactsGroup> query; query.Construct(); query.SetFilter(filter); count = _AddressbookUtil::GetCountWithQuery(query); SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return count; } int _AddressbookImpl::GetContactCount(void) const { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int count = -1; ClearLastResult(); __Filter<__ContactsContact> filter; filter.Construct(); filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); __Query<__ContactsContact> query; query.Construct(); query.SetFilter(filter); count = _AddressbookUtil::GetCountWithQuery(query); SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return count; } Contact* _AddressbookImpl::GetContactN(RecordId contactId) const { SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int intValue = 0; contacts_record_h contactHandle = null; ClearLastResult(); std::unique_ptr pContact(new (std::nothrow) Contact()); SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &contactHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle); contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue); SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue); return pContact.release(); } Category* _AddressbookImpl::GetCategoryN(RecordId categoryId) const { SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); contacts_record_h recordHandle = null; ClearLastResult(); int intValue = 0; int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); std::unique_ptr pCategory(new (std::nothrow) Category()); SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); contacts_record_get_int(recordHandle, _contacts_group.id, &intValue); SysTryReturn(NID_SCL, intValue == categoryId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); __Filter<__ContactsGroupRelation> filter; filter.Construct(); filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId); __Query<__ContactsGroupRelation> query; query.Construct(); query.SetFilter(filter); int count = _AddressbookUtil::GetCountWithQuery(query); SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(recordHandle); _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count); _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId); return pCategory.release(); } int _AddressbookImpl::GetLatestVersion(void) const { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int latestVersion = -1; ClearLastResult(); int ret = contacts_db_get_current_version(&latestVersion); SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, -1, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return latestVersion; } IList* _AddressbookImpl::GetChangedContactsAfterN(int version, int& latestVersion) const { SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion); SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pChangedContacts; } IList* _AddressbookImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const { SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); int latestVersion1 = 0; int latestVersion2 = 0; std::unique_ptr pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion1)); SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); std::unique_ptr pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion2)); SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); std::unique_ptr pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList()); SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pChangeList->AddItems(*pChangedGroups); SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); r = pChangeList->AddItems(*pChangedRelations); SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r)); pChangedGroups->RemoveAll(false); pChangedRelations->RemoveAll(false); latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1; return pChangeList.release(); } IList* _AddressbookImpl::GetChangedContactInfoListN(int version, int& latestVersion) const { SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion); SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pChangedContacts; } IList* _AddressbookImpl::GetChangedCategoryInfoListN(int version, int& latestVersion) const { return GetChangedGroupsAfterN(version, latestVersion); } IList* _AddressbookImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const { SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); IList* pChangedGroups = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion); SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pChangedGroups; } IList* _AddressbookImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const { SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion); SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); return pChangedRelations; } result _AddressbookImpl::AddContacts(const Tizen::Base::Collection::IList& contactList, Tizen::Base::Collection::IListT* pContactIdList) { SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); std::unique_ptr pContactEnum(contactList.GetEnumeratorN()); SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); Contact* pContact = null; int ret = CONTACTS_ERROR_NONE; int* pContactIds = null; unsigned int contactsCount = 0; contacts_record_h recordHandle = null; contacts_list_h listHandle = null; ret = contacts_list_create(&listHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); while (pContactEnum->MoveNext() == E_SUCCESS) { pContact = static_cast(pContactEnum->GetCurrent()); if (_ContactImpl::GetInstance(*pContact)->IsEmpty()) { contacts_list_destroy(listHandle, false); SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG)); return E_INVALID_ARG; } if (pContact->GetRecordId() != INVALID_RECORD_ID) { contacts_list_destroy(listHandle, false); SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG)); return E_INVALID_ARG; } recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle(); contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId); contacts_list_add(listHandle, recordHandle); } ret = contacts_db_insert_records(listHandle, &pContactIds, &contactsCount); contacts_list_destroy(listHandle, false); 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_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); SysTryReturn(NID_SCL, pContactIds, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); int* pTemp = pContactIds; if (pContactIdList != null) { for (unsigned int i = 0; i < contactsCount; i++) { pContactIdList->Add(*pTemp); pTemp++; } } free(pContactIds); return E_SUCCESS; } result _AddressbookImpl::UpdateContacts(const Tizen::Base::Collection::IList& contactList) { SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); std::unique_ptr pContactEnum(contactList.GetEnumeratorN()); SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); Contact* pContact = null; int ret = CONTACTS_ERROR_NONE; contacts_record_h recordHandle = null; contacts_list_h listHandle = null; ret = contacts_list_create(&listHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); while (pContactEnum->MoveNext() == E_SUCCESS) { pContact = static_cast(pContactEnum->GetCurrent()); if (_ContactImpl::GetInstance(*pContact)->IsEmpty()) { contacts_list_destroy(listHandle, false); SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG)); return E_INVALID_ARG; } if (pContact->GetRecordId() == INVALID_RECORD_ID) { contacts_list_destroy(listHandle, false); SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG)); return E_INVALID_ARG; } recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle(); contacts_list_add(listHandle, recordHandle); } ret = contacts_db_update_records(listHandle); contacts_list_destroy(listHandle, false); 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_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG)); 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)); return E_SUCCESS; } result _AddressbookImpl::RemoveContacts(const Tizen::Base::Collection::IListT& contactIdList) { SysTryReturn(NID_SCL, contactIdList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactIdList is empty.", GetErrorMessage(E_INVALID_ARG)); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); std::unique_ptr > pContactIdEnum(contactIdList.GetEnumeratorN()); SysTryReturnResult(NID_SCL, pContactIdEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); RecordId contactId = INVALID_RECORD_ID; int ret = CONTACTS_ERROR_NONE; int count = contactIdList.GetCount(); std::unique_ptr pRecordIds(new (std::nothrow) int[count]); int* pInt = pRecordIds.get(); int* pTmp = pInt; while (pContactIdEnum->MoveNext() == E_SUCCESS) { pContactIdEnum->GetCurrent(contactId); SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. Contact id is invalid record id.", GetErrorMessage(E_INVALID_ARG)); *pTmp = contactId; pTmp++; } ret = contacts_db_delete_records(_contacts_contact._uri, pInt, count); 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 || ret == CONTACTS_ERROR_NO_DATA, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return E_SUCCESS; } result _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile) { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); int recordId = 0; int existingRecordId = 0; int ret = CONTACTS_ERROR_NONE; result r = E_SUCCESS; contacts_record_h recordHandle = null; std::unique_ptr pExistingProfile(GetUserProfileN()); SysTryReturn(NID_SCL, pExistingProfile != null || GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); if (pExistingProfile != null) { recordHandle = _UserProfileImpl::GetInstance(*pExistingProfile)->GetUserProfileHandle(); contacts_record_get_int(recordHandle, _contacts_my_profile.id, &existingRecordId); } if (pUserProfile != null) { SysTryReturn(NID_SCL, !((_UserProfileImpl::GetInstance(*pUserProfile))->IsEmpty()), E_SYSTEM, E_SYSTEM, "[%s] UserProfile is Empty.", GetErrorMessage(E_SYSTEM)); recordHandle = _UserProfileImpl::GetInstance(*pUserProfile)->GetUserProfileHandle(); contacts_record_get_int(recordHandle, _contacts_my_profile.id, &recordId); if (recordId == 0) { if (pExistingProfile != null) { r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } contacts_record_h newRecordHandle = null; ret = contacts_record_clone(recordHandle, &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)); ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId); if (ret != CONTACTS_ERROR_NONE) { contacts_record_destroy(newRecordHandle, true); SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return E_SYSTEM; } ret = contacts_db_insert_record(newRecordHandle, &recordId); contacts_record_destroy(newRecordHandle, 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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); } else if (recordId > 0) { if (recordId == existingRecordId) { contacts_record_h newRecordHandle = null; ret = contacts_record_clone(recordHandle, &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)); ret = contacts_db_update_record(newRecordHandle); contacts_record_destroy(newRecordHandle, 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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); } else { if (pExistingProfile != null) { r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } contacts_record_h newRecordHandle = null; ret = contacts_record_create(_contacts_my_profile._uri, &newRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = CopyMyProfileContents(recordHandle, newRecordHandle); if (r != E_SUCCESS) { contacts_record_destroy(newRecordHandle, true); SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); return E_OUT_OF_MEMORY; } ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId); if (ret != CONTACTS_ERROR_NONE) { contacts_record_destroy(newRecordHandle, true); SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); return E_SYSTEM; } ret = contacts_db_insert_record(newRecordHandle, &recordId); contacts_record_destroy(newRecordHandle, 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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM)); } } } else { if (pExistingProfile != null) { r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } } return E_SUCCESS; } UserProfile* _AddressbookImpl::GetUserProfileN(void) const { SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); ClearLastResult(); __Filter<__ContactsUserProfile> filter; filter.Construct(); filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId); __Query<__ContactsUserProfile> query; query.Construct(); query.SetFilter(filter); std::unique_ptr pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query)); SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook."); SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM)); UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast(pUserProfilesList->GetAt(0)))); SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY)); return pProfile; } bool _AddressbookImpl::IsUserProfileChangedAfter(int version) const { SysTryReturn(NID_SCL, version >= 0, false, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version); SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); UserProfile* pExistingProfile = GetUserProfileN(); if (pExistingProfile == null) { return false; } delete pExistingProfile; ClearLastResult(); int latestVersion = 0; int count = _AddressbookUtil::GetChangedItemCountByVersion<__ContactsMyProfileUpdatedInfo>(__addressbookId, version, latestVersion); SysTryReturn(NID_SCL, count >= 0, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); if (count > 0) { return true; } return false; } result _AddressbookImpl::CopyMyProfileContents(contacts_record_h srcHandle, contacts_record_h dstHandle) { int ret = CONTACTS_ERROR_NONE; int intValue = 0; unsigned int count = 0; unsigned int i = 0; char* pCharValue = null; contacts_record_h srcRecordHandle = null; contacts_record_h dstRecordHandle = null; // name contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.name, &count); if (count > 0) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.name, 0, &srcRecordHandle); ret = contacts_record_create(_contacts_name._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle nameHandle(dstRecordHandle); contacts_record_get_str(srcRecordHandle, _contacts_name.first, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_name.first, pCharValue); contacts_record_get_str(srcRecordHandle, _contacts_name.last, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_name.last, pCharValue); contacts_record_get_str(srcRecordHandle, _contacts_name.addition, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_name.addition, pCharValue); contacts_record_get_str(srcRecordHandle, _contacts_name.suffix, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_name.suffix, pCharValue); contacts_record_get_str(srcRecordHandle, _contacts_name.prefix, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_name.prefix, pCharValue); contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_first, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_first, pCharValue); contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_middle, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_middle, pCharValue); contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_last, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_last, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.name, dstRecordHandle); nameHandle.Release(); } // company contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.company, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.company, i, &srcRecordHandle); ret = contacts_record_create(_contacts_company._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle companyHandle(dstRecordHandle); contacts_record_get_int(srcRecordHandle, _contacts_company.type, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_company.type, intValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.name, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.name, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.department, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.department, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.job_title, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.job_title, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.assistant_name, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.assistant_name, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.role, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.role, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.logo, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.logo, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.location, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.location, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.description, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.description, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_company.phonetic_name, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_company.phonetic_name, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.company, dstRecordHandle); companyHandle.Release(); } // note contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.note, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.note, i, &srcRecordHandle); ret = contacts_record_create(_contacts_note._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle noteHandle(dstRecordHandle); contacts_record_get_str_p(srcRecordHandle, _contacts_note.note, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_note.note, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.note, dstRecordHandle); noteHandle.Release(); } // number contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.number, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.number, i, &srcRecordHandle); ret = contacts_record_create(_contacts_number._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle numberHandle(dstRecordHandle); contacts_record_get_int(srcRecordHandle, _contacts_number.type, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_number.type, intValue); contacts_record_get_str_p(srcRecordHandle, _contacts_number.label, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_number.label, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_number.number, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_number.number, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.number, dstRecordHandle); numberHandle.Release(); } // email contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.email, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.email, i, &srcRecordHandle); ret = contacts_record_create(_contacts_email._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle emailHandle(dstRecordHandle); contacts_record_get_int(srcRecordHandle, _contacts_email.type, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_email.type, intValue); contacts_record_get_str_p(srcRecordHandle, _contacts_email.label, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_email.label, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_email.email, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_email.email, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.email, dstRecordHandle); emailHandle.Release(); } // event contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.event, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.event, i, &srcRecordHandle); ret = contacts_record_create(_contacts_event._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle eventHandle(dstRecordHandle); contacts_record_get_int(srcRecordHandle, _contacts_event.type, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_event.type, intValue); contacts_record_get_str_p(srcRecordHandle, _contacts_event.label, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_event.label, pCharValue); contacts_record_get_int(srcRecordHandle, _contacts_event.date, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_event.date, intValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.event, dstRecordHandle); eventHandle.Release(); } // im address contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.messenger, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.messenger, i, &srcRecordHandle); ret = contacts_record_create(_contacts_messenger._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle imAddressHandle(dstRecordHandle); contacts_record_get_int(srcRecordHandle, _contacts_messenger.type, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_messenger.type, intValue); contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.label, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_messenger.label, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.im_id, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_messenger.im_id, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.messenger, dstRecordHandle); imAddressHandle.Release(); } // address contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.address, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.address, i, &srcRecordHandle); ret = contacts_record_create(_contacts_address._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle addressHandle(dstRecordHandle); contacts_record_get_int(srcRecordHandle, _contacts_address.type, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_address.type, intValue); contacts_record_get_str_p(srcRecordHandle, _contacts_address.label, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_address.label, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_address.postbox, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_address.postbox, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_address.extended, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_address.extended, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_address.street, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_address.street, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_address.locality, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_address.locality, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_address.region, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_address.region, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_address.postal_code, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_address.postal_code, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_address.country, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_address.country, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.address, dstRecordHandle); addressHandle.Release(); } // url contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.url, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.url, i, &srcRecordHandle); ret = contacts_record_create(_contacts_url._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle urlHandle(dstRecordHandle); contacts_record_get_int(srcRecordHandle, _contacts_url.type, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_url.type, intValue); contacts_record_get_str_p(srcRecordHandle, _contacts_url.label, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_url.label, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_url.url, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_url.url, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.url, dstRecordHandle); urlHandle.Release(); } // nickname contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.nickname, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.nickname, i, &srcRecordHandle); ret = contacts_record_create(_contacts_nickname._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle nicknameHandle(dstRecordHandle); contacts_record_get_str_p(srcRecordHandle, _contacts_nickname.name, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_nickname.name, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.nickname, dstRecordHandle); nicknameHandle.Release(); } // relationship contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.relationship, &count); for (i = 0; i < count; i++) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.relationship, i, &srcRecordHandle); ret = contacts_record_create(_contacts_relationship._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle relationshipHandle(dstRecordHandle); contacts_record_get_str_p(srcRecordHandle, _contacts_relationship.name, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_relationship.name, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_my_profile.relationship, dstRecordHandle); relationshipHandle.Release(); } // image contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.image, &count); int recordId = 0; contacts_record_get_int(srcHandle, _contacts_my_profile.id, &recordId); if (count > 0 && recordId == 0) { contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.image, 0, &srcRecordHandle); ret = contacts_record_create(_contacts_image._uri, &dstRecordHandle); SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); __ContactsRecordHandle imageHandle(dstRecordHandle); contacts_record_get_int(srcRecordHandle, _contacts_image.type, &intValue); contacts_record_set_int(dstRecordHandle, _contacts_image.type, intValue); contacts_record_get_str_p(srcRecordHandle, _contacts_image.label, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_image.label, pCharValue); contacts_record_get_str_p(srcRecordHandle, _contacts_image.path, &pCharValue); contacts_record_set_str(dstRecordHandle, _contacts_image.path, pCharValue); contacts_record_add_child_record(dstHandle, _contacts_contact.image, dstRecordHandle); imageHandle.Release(); } 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(srcHandle, _contacts_contact.is_favorite, &boolValue); contacts_record_set_bool(contactHandle, _contacts_contact.is_favorite, boolValue); // uid contacts_record_get_str_p(srcHandle, _contacts_contact.uid, &pCharValue); contacts_record_set_str(contactHandle, _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) { if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null) { return; } std::unique_ptr pChangedContactList(GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact)); SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); if (pChangedContactList->GetCount() > 0) { if (__pIAddressbookEventListener != null) { __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList); } else if (__pIAddressbookChangeEventListener != null) { __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList); } else { RecordEventType recordEventType = RECORD_ADDED; std::unique_ptr pEnum(pChangedContactList->GetEnumeratorN()); std::unique_ptr pContact(null); while (pEnum->MoveNext() == E_SUCCESS) { ContactChangeInfo* pContactChagneInfo = static_cast(pEnum->GetCurrent()); if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED) { recordEventType = RECORD_ADDED; pContact.reset(GetContactN(pContactChagneInfo->GetContactId())); if (pContact == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } } else if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED) { recordEventType = RECORD_UPDATED; pContact.reset(GetContactN(pContactChagneInfo->GetContactId())); if (pContact == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } } else { recordEventType = RECORD_REMOVED; pContact.reset(new (std::nothrow) Contact()); if (pContact == null) { SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); break; } _RecordImpl::GetInstance(*pContact)->SetRecordId(pContactChagneInfo->GetContactId()); } __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CONTACT, *pContact, null, null); } } } } void _AddressbookImpl::OnCategoryChanged(void) { if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null) { return; } std::unique_ptr pChangedCategoryList(GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup)); SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); if (pChangedCategoryList->GetCount() > 0) { if (__pIAddressbookEventListener != null) { __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList); } else if (__pIAddressbookChangeEventListener != null) { __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList); } else { RecordEventType recordEventType = RECORD_ADDED; std::unique_ptr pEnum(pChangedCategoryList->GetEnumeratorN()); std::unique_ptr pCategory(null); while (pEnum->MoveNext() == E_SUCCESS) { CategoryChangeInfo* pCategoryChagneInfo = static_cast(pEnum->GetCurrent()); if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED) { recordEventType = RECORD_ADDED; pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId())); if (pCategory == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } } else if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED) { recordEventType = RECORD_UPDATED; pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId())); if (pCategory == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } } else { recordEventType = RECORD_REMOVED; pCategory.reset(new (std::nothrow) Category()); if (pCategory == null) { SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); break; } _RecordImpl::GetInstance(*pCategory)->SetRecordId(pCategoryChagneInfo->GetCategoryId()); } __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null); } } } } void _AddressbookImpl::OnRelationChanged(void) { if (__pIAddressbookEventListener == null && __pIRecordEventListener == null) { return; } std::unique_ptr pChangedCategoryList(GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation)); SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); if (pChangedCategoryList->GetCount() > 0) { if (__pIAddressbookEventListener != null) { __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList); } else { RecordEventType recordEventType = RECORD_ADDED; std::unique_ptr pEnum(pChangedCategoryList->GetEnumeratorN()); std::unique_ptr pCategory(null); while (pEnum->MoveNext() == E_SUCCESS) { CategoryChangeInfo* pCategoryChagneInfo = static_cast(pEnum->GetCurrent()); recordEventType = RECORD_UPDATED; pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId())); if (pCategory == null) { if (GetLastResult() == E_OBJ_NOT_FOUND) { continue; } else { break; } } __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null); } } } } _AddressbookImpl* _AddressbookImpl::GetInstance(Addressbook& addressbook) { return addressbook.__pAddressbookImpl; } const _AddressbookImpl* _AddressbookImpl::GetInstance(const Addressbook& addressbook) { return addressbook.__pAddressbookImpl; } }} // Tizen::Social