X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FFScl_AddressbookImpl.cpp;h=911325388cefa9e65ee6a07c9133fcdb7ff4f80e;hb=ffcd54e9ed197243707038ab8866a4373240ed10;hp=30f371673f0cac754cad85e5484ca50b15449224;hpb=b7fd12f69738cd081111f73953c0c03afb11f95d;p=framework%2Fosp%2Fsocial.git diff --git a/src/FScl_AddressbookImpl.cpp b/src/FScl_AddressbookImpl.cpp index 30f3716..9113253 100644 --- a/src/FScl_AddressbookImpl.cpp +++ b/src/FScl_AddressbookImpl.cpp @@ -20,6 +20,7 @@ * This file contains definitions of @e _AddressbookImpl class. */ #include +#include #include #include #include @@ -48,6 +49,7 @@ #include "FScl_UserProfileImpl.h" #include "FScl_ContactDbConnector.h" +using namespace std; using namespace Tizen::App; using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -329,7 +331,7 @@ _AddressbookImpl::AddCategory(Category& category) int recordId = 0; contacts_record_h recordHandle = null; - std::unique_ptr > pList(null); + unique_ptr > pList(null); recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle(); @@ -375,7 +377,7 @@ _AddressbookImpl::AddCategory(Category& category) pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN()); if (pList != null && pList->GetCount() > 0) { - std::unique_ptr > pEnum(pList->GetEnumeratorN()); + unique_ptr > pEnum(pList->GetEnumeratorN()); while (pEnum->MoveNext() == E_SUCCESS) { @@ -394,28 +396,10 @@ _AddressbookImpl::AddCategory(Category& category) result _AddressbookImpl::RemoveContact(RecordId contactId) { - 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, 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())); - - int intValue = 0; - int ret = CONTACTS_ERROR_NONE; - contacts_record_h recordHandle = null; - - 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)); - - 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)); - - ret = contacts_db_delete_record(_contacts_contact._uri, contactId); - 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)); + result r = _AddressbookUtil::DeleteContactRecord(_contacts_contact._uri, contactId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); return E_SUCCESS; } @@ -440,29 +424,15 @@ _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())); - - int intValue = 0; - int ret = CONTACTS_ERROR_NONE; - contacts_record_h recordHandle = null; - - ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle); - SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The category is 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)); - - __ContactsRecordHandle categoryHandle(recordHandle); - - contacts_record_get_int(recordHandle, _contacts_group.id, &intValue); - SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND)); + 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(recordHandle, _contacts_group.is_read_only, &isReadOnly); + 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)); - ret = contacts_db_delete_record(_contacts_group._uri, categoryId); - 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, "[E_SYSTEM] Failed remove a category."); + result r = _AddressbookUtil::DeleteContactRecord(_contacts_group._uri, categoryId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); return E_SUCCESS; } @@ -1337,9 +1307,8 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile) { if (pExistingProfile != null) { - ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId); - 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)); + r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } contacts_record_h newRecordHandle = null; @@ -1376,9 +1345,8 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile) { if (pExistingProfile != null) { - ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId); - 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)); + r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } contacts_record_h newRecordHandle = null; @@ -1413,9 +1381,8 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile) { if (pExistingProfile != null) { - ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId); - 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)); + r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId); + SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); } }