* This file contains definitions of @e _AddressbookImpl class.
*/
#include <contacts.h>
+#include <unique_ptr.h>
#include <FBaseColIListT.h>
#include <FBaseColArrayListT.h>
#include <FBaseResult.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;
int recordId = 0;
contacts_record_h recordHandle = null;
- std::unique_ptr<IListT<int> > pList(null);
+ unique_ptr<IListT<int> > pList(null);
recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
if (pList != null && pList->GetCount() > 0)
{
- std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
+ unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
while (pEnum->MoveNext() == 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. 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;
}
{
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<ContactRecord, ContactRecordDeleter> 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;
}
{
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;
{
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;
{
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));
}
}