+//
+// Open Service Platform
+// 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_ContactImpl.cpp
+ * @brief This is the implementation for _ContactImpl class.
+ *
+ * This file contains definitions of _ContactImpl class.
+ */
+#include <FBaseString.h>
+#include <FBaseColArrayList.h>
+#include <FBaseSysLog.h>
+#include <FIoFile.h>
+#include <FMediaImage.h>
+#include <FSclAddress.h>
+#include <FSclPhoneNumber.h>
+#include <FSclEmail.h>
+#include <FSclUrl.h>
+#include <FSclImAddress.h>
+#include <FSclOrganization.h>
+#include <FSclContactEvent.h>
+#include <FSclRelationship.h>
+#include <FSclContact.h>
+#include <FApp_AppInfo.h>
+#include <FBase_StringConverter.h>
+#include "FScl_ContactDbConnector.h"
+#include "FScl_PhoneNumberImpl.h"
+#include "FScl_ContactImpl.h"
+#include "FScl_AddressbookUtil.h"
+#include "FScl_UrlImpl.h"
+#include "FScl_EmailImpl.h"
+#include "FScl_AddressImpl.h"
+#include "FScl_ImAddressImpl.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Graphics;
+using namespace Tizen::Media;
+using namespace Tizen::Io;
+
+namespace Tizen { namespace Social
+{
+
+extern const wchar_t OTHER_LABEL[] = L"Other";
+
+const int __CONTACT_CHANGED_TIME_YEAR_OFFSET = 1900;
+const int __CONTACT_CHANGED_TIME_MONTH_OFFSET = 1;
+
+const int __CONTACT_MOD_YEAR = 10000;
+const int __CONTACT_MOD_MONTH = 100;
+
+#define __PARSE_DATE(date, year, month, day) \
+ do \
+ { \
+ int temp = date; \
+ year = temp/__CONTACT_MOD_YEAR; \
+ temp -= year*__CONTACT_MOD_YEAR; \
+ month = temp/__CONTACT_MOD_MONTH; \
+ day = temp - month*__CONTACT_MOD_MONTH; \
+ }while(0)
+
+#define __CONVERT_DATE_TO_DATETIME(date, dateTime) \
+ do \
+ { \
+ int temp = date; \
+ int year = 0; \
+ int month = 0; \
+ int day = 0; \
+ year = temp/__CONTACT_MOD_YEAR; \
+ temp -= year*__CONTACT_MOD_YEAR; \
+ month = temp/__CONTACT_MOD_MONTH; \
+ day = temp - month*__CONTACT_MOD_MONTH; \
+ dateTime.SetValue(year, month, day, 0, 0, 0); \
+ }while(0)
+
+
+#define __CONVERT_DATETIME_TO_DATE(dateTime, date) \
+ do \
+ { \
+ date = dateTime.GetYear()*__CONTACT_MOD_YEAR + dateTime.GetMonth()*__CONTACT_MOD_MONTH + dateTime.GetDay(); \
+ }while(0)
+
+_ContactImpl::_ContactImpl(void)
+ : __contactHandle(null)
+ , __isRemoved(false)
+{
+ contacts_record_h contactHandle = null;
+
+ SysTryReturnVoidResult(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+ int ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
+ SysTryReturnVoidResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ __contactHandle = contactHandle;
+}
+
+_ContactImpl::_ContactImpl(const _ContactImpl& rhs)
+ : __contactHandle(null)
+{
+ contacts_record_h contactHandle = null;
+
+ SysTryReturnVoidResult(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+ int ret = contacts_record_clone(rhs.__contactHandle, &contactHandle);
+ SysTryReturnVoidResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ __contactHandle = contactHandle;
+ __isRemoved = rhs.__isRemoved;
+}
+
+_ContactImpl::~_ContactImpl(void)
+{
+ if (__contactHandle != null)
+ {
+ contacts_record_destroy(__contactHandle, true);
+ }
+}
+
+_ContactImpl&
+_ContactImpl::operator =(const _ContactImpl& rhs)
+{
+ if (this == &rhs)
+ {
+ return *this;
+ }
+
+ contacts_record_h contactHandle = null;
+
+ int ret = contacts_record_clone(rhs.__contactHandle, &contactHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_destroy(__contactHandle, true);
+ __contactHandle = contactHandle;
+
+ __isRemoved = rhs.__isRemoved;
+
+ return *this;
+}
+
+void
+_ContactImpl::SetContactRecordHandle(contacts_record_h contactHandle)
+{
+ contacts_record_destroy(__contactHandle, true);
+
+ __contactHandle = contactHandle;
+}
+
+contacts_record_h
+_ContactImpl::GetContactRecordHandle(void) const
+{
+ return __contactHandle;
+}
+
+result
+_ContactImpl::SetThumbnailPath(const Tizen::Base::String& filePath)
+{
+ SysTryReturn(NID_SCL, filePath.IsEmpty() || File::IsFileExist(filePath), E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[%s] The specified file is not found.", GetErrorMessage(E_FILE_NOT_FOUND));
+
+ unsigned int count = 0;
+ contacts_record_h imageHandle = null;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &imageHandle);
+
+ if (!filePath.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(filePath));
+ SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(imageHandle, _contacts_image.path, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.image, imageHandle);
+ }
+ }
+ else
+ {
+ if (!filePath.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(filePath));
+ SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int ret = contacts_record_create(_contacts_image._uri, &imageHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(imageHandle, _contacts_image.path, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.image, imageHandle);
+ }
+ }
+
+ return E_SUCCESS;
+}
+
+String
+_ContactImpl::GetThumbnailPath(void) const
+{
+ unsigned int count = 0;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
+ if (count == 0)
+ {
+ return String(L"");
+ }
+
+ char* pCharValue = null;
+ contacts_record_h imageHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &imageHandle);
+ contacts_record_get_str_p(imageHandle, _contacts_image.path, &pCharValue);
+
+ return String(pCharValue);
+}
+
+Bitmap*
+_ContactImpl::GetThumbnailN(void) const
+{
+ unsigned int count = 0;
+ char* pCharValue = null;
+ contacts_record_h imageHandle = null;
+
+ ClearLastResult();
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
+ if (count == 0)
+ {
+ return null;
+ }
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &imageHandle);
+ contacts_record_get_str_p(imageHandle, _contacts_image.path, &pCharValue);
+
+ String thumbnailPath(pCharValue);
+
+ Image image;
+ result r = image.Construct();
+ SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] Failed to construct Image.", GetErrorMessage(E_SYSTEM));
+
+ ImageFormat imageFormat = image.GetImageFormat(thumbnailPath);
+ SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_SYSTEM, "[%s] Failed to get the format of the thumbnail image.", GetErrorMessage(E_SYSTEM));
+
+ BitmapPixelFormat bitmapPixelFormat = BITMAP_PIXEL_FORMAT_RGB565;
+
+ switch (imageFormat)
+ {
+ case IMG_FORMAT_JPG:
+ //fall through
+ case IMG_FORMAT_GIF:
+ //fall through
+ case IMG_FORMAT_BMP:
+ bitmapPixelFormat = BITMAP_PIXEL_FORMAT_RGB565;
+ break;
+ case IMG_FORMAT_PNG:
+ bitmapPixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
+ break;
+ default:
+ SysLogException(NID_SCL, E_SYSTEM, "[%s] Unsupported image format.", GetErrorMessage(E_SYSTEM));
+ return null;
+ }
+
+ Bitmap* pBitmap = image.DecodeN(thumbnailPath, bitmapPixelFormat);
+ SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed. ", GetErrorMessage(E_OUT_OF_MEMORY));
+ SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred. ", GetErrorMessage(E_SYSTEM));
+
+ return pBitmap;
+}
+
+result
+_ContactImpl::GetValue(const ContactPropertyId id, String& value) const
+{
+ unsigned int count = 0;
+ char* pCharValue = null;
+
+ switch (id)
+ {
+ case CONTACT_PROPERTY_ID_FIRST_NAME:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_h nameHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+ contacts_record_get_str_p(nameHandle, _contacts_name.first, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_LAST_NAME:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_h nameHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+ contacts_record_get_str_p(nameHandle, _contacts_name.last, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_DISPLAY_NAME:
+ contacts_record_get_str_p(__contactHandle, _contacts_contact.display_name, &pCharValue);
+ value = pCharValue;
+ break;
+ case CONTACT_PROPERTY_ID_NICK_NAME:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
+ if (count > 0)
+ {
+ contacts_record_h nicknameHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, 0, &nicknameHandle);
+ contacts_record_get_str_p(nicknameHandle, _contacts_nickname.name, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_MIDDLE_NAME:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_h nameHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+ contacts_record_get_str_p(nameHandle, _contacts_name.addition, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_NAME_PREFIX:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_h nameHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+ contacts_record_get_str_p(nameHandle, _contacts_name.prefix, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_NAME_SUFFIX:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_h nameHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+ contacts_record_get_str_p(nameHandle, _contacts_name.suffix, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_JOB_TITLE:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
+ if (count > 0)
+ {
+ contacts_record_h companyHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
+ contacts_record_get_str_p(companyHandle, _contacts_company.job_title, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_COMPANY:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
+ if (count > 0)
+ {
+ contacts_record_h companyHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
+ contacts_record_get_str_p(companyHandle, _contacts_company.name, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_NOTE:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
+ if (count > 0)
+ {
+ contacts_record_h noteHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, 0, ¬eHandle);
+ contacts_record_get_str_p(noteHandle, _contacts_note.note, &pCharValue);
+ }
+
+ value = pCharValue;
+ }
+ break;
+ case CONTACT_PROPERTY_ID_RINGTONE:
+ contacts_record_get_str_p(__contactHandle, _contacts_contact.ringtone_path, &pCharValue);
+ value = pCharValue;
+ break;
+ case CONTACT_PROPERTY_ID_THUMBNAIL:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
+ if (count > 0)
+ {
+ contacts_record_h imageHandle = null;
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &imageHandle);
+ contacts_record_get_str_p(imageHandle, _contacts_image.path, &pCharValue);
+ }
+ }
+ value = pCharValue;
+ break;
+ default:
+ value = String(L"");
+ SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d", GetErrorMessage(E_INVALID_ARG), id);
+ return E_INVALID_ARG;
+ }
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::GetValue(const ContactPropertyId id, DateTime& value) const
+{
+ int intValue = 0;
+ DateTime dataTime;
+ unsigned int count = 0;
+
+ value = DateTime::GetMinValue();
+
+ switch (id)
+ {
+ case CONTACT_PROPERTY_ID_BIRTHDAY:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
+ if (count > 0)
+ {
+ int year = 0;
+ int month = 0;
+ int day = 0;
+
+ contacts_record_h eventHandle = null;
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
+ contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
+ if (intValue == CONTACTS_EVENT_TYPE_BIRTH)
+ {
+ contacts_record_get_int(eventHandle, _contacts_event.date, &intValue);
+
+ __PARSE_DATE(intValue, year, month, day);
+
+ value.SetValue(year, month, day, 0, 0, 0);
+ break;
+ }
+ }
+ }
+ }
+ break;
+
+ case CONTACT_PROPERTY_ID_ANNIVERSARY:
+ {
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
+ if (count > 0)
+ {
+ int year = 0;
+ int month = 0;
+ int day = 0;
+
+ contacts_record_h eventHandle = null;
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
+ contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
+ if (intValue == CONTACTS_EVENT_TYPE_ANNIVERSARY)
+ {
+ contacts_record_get_int(eventHandle, _contacts_event.date, &intValue);
+
+ __PARSE_DATE(intValue, year, month, day);
+
+ value.SetValue(year, month, day, 0, 0, 0);
+ break;
+ }
+ }
+ }
+ }
+ break;
+
+ case CONTACT_PROPERTY_ID_LAST_REVISION:
+ {
+ struct tm ts;
+ int intValue = 0;
+
+ contacts_record_get_int(__contactHandle, _contacts_contact.changed_time, &intValue);
+ gmtime_r((time_t *)intValue, &ts);
+
+ value.SetValue(ts.tm_year + __CONTACT_CHANGED_TIME_YEAR_OFFSET, ts.tm_mon + __CONTACT_CHANGED_TIME_MONTH_OFFSET, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
+ }
+ break;
+
+ default:
+ SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
+ return E_INVALID_ARG;
+ }
+
+ return E_SUCCESS;
+}
+
+bool
+_ContactImpl::IsEmptyCompany(contacts_record_h companyHandle)
+{
+ char* pCharValue = null;
+
+ contacts_record_get_str_p(companyHandle, _contacts_company.name, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ contacts_record_get_str_p(companyHandle, _contacts_company.job_title, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+
+ contacts_record_get_str_p(companyHandle, _contacts_company.department, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ contacts_record_get_str_p(companyHandle, _contacts_company.role, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ contacts_record_get_str_p(companyHandle, _contacts_company.assistant_name, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool
+_ContactImpl::IsEmptyName(contacts_record_h nameHandle)
+{
+ char* pCharValue = null;
+
+ contacts_record_get_str_p(nameHandle, _contacts_name.first, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ contacts_record_get_str_p(nameHandle, _contacts_name.last, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ contacts_record_get_str_p(nameHandle, _contacts_name.addition, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ contacts_record_get_str_p(nameHandle, _contacts_name.prefix, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ contacts_record_get_str_p(nameHandle, _contacts_name.suffix, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+result
+_ContactImpl::SetValue(ContactPropertyId id, const String& value)
+{
+ SysTryReturn(NID_SCL, id != CONTACT_PROPERTY_ID_THUMBNAIL, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. Thumbnail cannot be set using this.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, id != CONTACT_PROPERTY_ID_DISPLAY_NAME, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. Display cannot be set using this.", GetErrorMessage(E_INVALID_ARG));
+
+ int ret = CONTACTS_ERROR_NONE;
+ unsigned int count = 0;
+
+ if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+ {
+ int maxLength = GetMaxLength(id);
+ SysTryReturn(NID_SCL, value.GetLength() <= maxLength || maxLength == -1 , E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value=%ls exceeds the maximum length.", GetErrorMessage(E_INVALID_ARG), value.GetPointer());
+ }
+
+ switch (id)
+ {
+ case CONTACT_PROPERTY_ID_FIRST_NAME:
+ {
+ contacts_record_h nameHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.first, pCharArray.get());
+
+ if (value.IsEmpty() && IsEmptyName(nameHandle))
+ {
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_name._uri, &nameHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.first, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+ }
+ break;
+
+ case CONTACT_PROPERTY_ID_MIDDLE_NAME:
+ {
+ contacts_record_h nameHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.addition, pCharArray.get());
+
+ if (value.IsEmpty() && IsEmptyName(nameHandle))
+ {
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_name._uri, &nameHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.addition, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+
+ }
+
+ break;
+
+ case CONTACT_PROPERTY_ID_LAST_NAME:
+ {
+ contacts_record_h nameHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.last, pCharArray.get());
+
+ if (value.IsEmpty() && IsEmptyName(nameHandle))
+ {
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_name._uri, &nameHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.last, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+
+ }
+
+ break;
+ case CONTACT_PROPERTY_ID_NAME_SUFFIX:
+ {
+ contacts_record_h nameHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.suffix, pCharArray.get());
+
+ if (value.IsEmpty() && IsEmptyName(nameHandle))
+ {
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_name._uri, &nameHandle);
+
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.suffix, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+
+ }
+
+ break;
+
+ case CONTACT_PROPERTY_ID_NAME_PREFIX:
+ {
+ contacts_record_h nameHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
+
+ if (value.IsEmpty() && IsEmptyName(nameHandle))
+ {
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_name._uri, &nameHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
+ }
+ }
+
+ }
+
+ break;
+
+ case CONTACT_PROPERTY_ID_NICK_NAME:
+ {
+ contacts_record_h nicknameHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, 0, &nicknameHandle);
+ if (!value.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
+ }
+ else
+ {
+ while (true)
+ {
+ ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, 0, &nicknameHandle);
+ if (ret != CONTACTS_ERROR_NONE)
+ {
+ break;
+ }
+
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.nickname, nicknameHandle);
+ }
+ }
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_nickname._uri, &nicknameHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.nickname, nicknameHandle);
+ }
+ }
+
+ }
+
+ break;
+
+ case CONTACT_PROPERTY_ID_JOB_TITLE:
+ {
+ contacts_record_h companyHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(companyHandle, _contacts_company.job_title, pCharArray.get());
+
+ if (value.IsEmpty() && IsEmptyCompany(companyHandle))
+ {
+ while (true)
+ {
+ ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
+ if (ret != CONTACTS_ERROR_NONE)
+ {
+ break;
+ }
+
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.company, companyHandle);
+ }
+ }
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_company._uri, &companyHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(companyHandle, _contacts_company.job_title, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.company, companyHandle);
+ }
+ }
+
+ }
+ break;
+
+ case CONTACT_PROPERTY_ID_COMPANY:
+ {
+ contacts_record_h companyHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
+
+ std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(companyHandle, _contacts_company.name, pCharArray.get());
+
+ if (value.IsEmpty() && IsEmptyCompany(companyHandle))
+ {
+ while (true)
+ {
+ ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
+ if (ret != CONTACTS_ERROR_NONE)
+ {
+ break;
+ }
+
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.company, companyHandle);
+ }
+
+ }
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_company._uri, &companyHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(companyHandle, _contacts_company.name, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.company, companyHandle);
+ }
+ }
+
+ }
+ break;
+
+ case CONTACT_PROPERTY_ID_NOTE:
+ {
+ contacts_record_h noteHandle = null;
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
+ if (count > 0)
+ {
+ if (!value.IsEmpty())
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, 0, ¬eHandle);
+
+ std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
+ }
+ else
+ {
+ while (true)
+ {
+ ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, 0, ¬eHandle);
+ if (ret != CONTACTS_ERROR_NONE)
+ {
+ break;
+ }
+
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.note, noteHandle);
+ }
+ }
+ }
+ else
+ {
+ if (!value.IsEmpty())
+ {
+ ret = contacts_record_create(_contacts_note._uri, ¬eHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
+ contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.note, noteHandle);
+ }
+ }
+ }
+ break;
+
+ case CONTACT_PROPERTY_ID_RINGTONE:
+ {
+ if (!value.IsEmpty() && !File::IsFileExist(value))
+ {
+ SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The specified ringtone file does not exist.", GetErrorMessage(E_INVALID_ARG));
+ return E_INVALID_ARG;
+ }
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
+
+ contacts_record_set_str(__contactHandle, _contacts_contact.ringtone_path, pCharArray.get());
+ }
+ break;
+
+ default:
+ SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
+ return E_INVALID_ARG;
+ }
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetValue(ContactPropertyId id, const DateTime& value)
+{
+ SysTryReturn(NID_SCL, id != CONTACT_PROPERTY_ID_LAST_REVISION, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. Thumbnail cannot be set using this.", GetErrorMessage(E_INVALID_ARG));
+
+ unsigned int count = 0;
+ int intValue = 0;
+ int ret = CONTACTS_ERROR_NONE;
+
+ switch (id)
+ {
+ case CONTACT_PROPERTY_ID_BIRTHDAY:
+ {
+ bool found = false;
+ int date = 0;
+ contacts_record_h eventHandle = null;
+
+ __CONVERT_DATETIME_TO_DATE(value, date);
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
+ if (count > 0)
+ {
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
+ contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
+ if (intValue == CONTACTS_EVENT_TYPE_BIRTH)
+ {
+ contacts_record_set_int(eventHandle, _contacts_event.date, date);
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if (!found)
+ {
+ ret = contacts_record_create(_contacts_event._uri, &eventHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_int(eventHandle, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
+ contacts_record_set_int(eventHandle, _contacts_event.date, date);
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.event, eventHandle);
+ }
+ }
+
+ break;
+
+ case CONTACT_PROPERTY_ID_ANNIVERSARY:
+ {
+ bool found = false;
+ int date = 0;
+ contacts_record_h eventHandle = null;
+
+ __CONVERT_DATETIME_TO_DATE(value, date);
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
+ if (count > 0)
+ {
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
+ contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
+ if (intValue == CONTACTS_EVENT_TYPE_ANNIVERSARY)
+ {
+ contacts_record_set_int(eventHandle, _contacts_event.date, date);
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if (!found)
+ {
+ ret = contacts_record_create(_contacts_event._uri, &eventHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_int(eventHandle, _contacts_event.type, CONTACTS_EVENT_TYPE_ANNIVERSARY);
+ contacts_record_set_int(eventHandle, _contacts_event.date, date);
+
+ contacts_record_add_child_record(__contactHandle, _contacts_contact.event, eventHandle);
+ }
+ }
+
+ break;
+
+ default:
+ SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
+ return E_INVALID_ARG;
+ }
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::AddPhoneNumber(const PhoneNumber& phoneNumber)
+{
+ SysTryReturn(NID_SCL, !phoneNumber.GetPhoneNumber().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The phoneNumber is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int type = 0;
+ String stringValue;
+ contacts_record_h numberHandle = null;
+
+ int ret = contacts_record_create(_contacts_number._uri, &numberHandle);
+ 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 recordHandle(numberHandle);
+
+ switch (_PhoneNumberImpl::GetInstance(phoneNumber)->GetType())
+ {
+ case PHONENUMBER_TYPE_HOME:
+ type = CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE;
+ break;
+ case PHONENUMBER_TYPE_WORK:
+ type = CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE;
+ break;
+ case PHONENUMBER_TYPE_MOBILE:
+ type = CONTACTS_NUMBER_TYPE_CELL;
+ break;
+ case PHONENUMBER_TYPE_HOME_FAX:
+ type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME;
+ break;
+ case PHONENUMBER_TYPE_WORK_FAX:
+ type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK;
+ break;
+ case PHONENUMBER_TYPE_PAGER:
+ type = CONTACTS_NUMBER_TYPE_PAGER;
+ break;
+ case PHONENUMBER_TYPE_CUSTOM:
+ type = CONTACTS_NUMBER_TYPE_CUSTOM;
+ break;
+ case PHONENUMBER_TYPE_OTHER:
+ default:
+ type = CONTACTS_NUMBER_TYPE_OTHER;
+ break;
+ }
+
+ contacts_record_set_int(numberHandle, _contacts_number.type, type);
+
+ stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetLabel();
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(numberHandle, _contacts_number.label, pCharArray.get());
+
+ stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetPhoneNumber();
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(numberHandle, _contacts_number.number, pCharArray.get());
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.number, numberHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::AddNickname(const String& nickname)
+{
+ SysTryReturn(NID_SCL, !nickname.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The nickname is an empty string.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ contacts_record_h nicknameHandle = null;
+
+ int ret = contacts_record_create(_contacts_nickname._uri, &nicknameHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(nickname));
+ SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.nickname, nicknameHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::AddNote(const String& note)
+{
+ SysTryReturn(NID_SCL, !note.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The note is an empty string.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ contacts_record_h noteHandle = null;
+
+ int ret = contacts_record_create(_contacts_note._uri, ¬eHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(note));
+ SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.note, noteHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::AddEmail(const Email& email)
+{
+ SysTryReturn(NID_SCL, !email.GetEmail().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The email is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int type = 0;
+ String stringValue;
+ contacts_record_h emailHandle = null;
+
+ int ret = contacts_record_create(_contacts_email._uri, &emailHandle);
+ 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 recordHandle(emailHandle);
+
+ switch (_EmailImpl::GetInstance(email)->GetType())
+ {
+ case EMAIL_TYPE_PERSONAL:
+ type = CONTACTS_EMAIL_TYPE_HOME;
+ break;
+ case EMAIL_TYPE_WORK:
+ type = CONTACTS_EMAIL_TYPE_WORK;
+ break;
+ case EMAIL_TYPE_CUSTOM:
+ type = CONTACTS_EMAIL_TYPE_CUSTOM;
+ break;
+ case EMAIL_TYPE_OTHER:
+ // fall through
+ default:
+ type = CONTACTS_EMAIL_TYPE_OTHER;
+ break;
+ }
+
+ contacts_record_set_int(emailHandle, _contacts_email.type, type);
+
+ stringValue = _EmailImpl::GetInstance(email)->GetLabel();
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(emailHandle, _contacts_email.label, pCharArray.get());
+
+ stringValue = _EmailImpl::GetInstance(email)->GetEmail();
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(emailHandle, _contacts_email.email, pCharArray.get());
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.email, emailHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::AddUrl(const Url& url)
+{
+ SysTryReturn(NID_SCL, !url.GetUrl().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The url is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int type = 0;
+ String stringValue;
+ contacts_record_h urlHandle = null;
+
+ int ret = contacts_record_create(_contacts_url._uri, &urlHandle);
+ 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 recordHandle(urlHandle);
+
+ switch (_UrlImpl::GetInstance(url)->GetType())
+ {
+ case URL_TYPE_PERSONAL:
+ type = CONTACTS_URL_TYPE_HOME;
+ break;
+ case URL_TYPE_WORK:
+ type = CONTACTS_URL_TYPE_WORK;
+ break;
+ case URL_TYPE_CUSTOM:
+ type = CONTACTS_URL_TYPE_CUSTOM;
+ break;
+ case URL_TYPE_OTHER:
+ // fall through
+ default:
+ type = CONTACTS_URL_TYPE_OTHER;
+ break;
+ }
+
+ // set type
+ contacts_record_set_int(urlHandle, _contacts_url.type, type);
+
+ // set label
+ stringValue = _UrlImpl::GetInstance(url)->GetLabel();
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(urlHandle, _contacts_url.label, pCharArray.get());
+
+ // set url
+ stringValue = _UrlImpl::GetInstance(url)->GetUrl();
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(urlHandle, _contacts_url.url, pCharArray.get());
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.url, urlHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::AddAddress(const Address& address)
+{
+ SysTryReturn(NID_SCL, !_AddressImpl::GetInstance(address)->IsEmpty() ,E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The address is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int type = 0;
+ String stringValue;
+ contacts_record_h addressHandle = null;
+
+ int ret = contacts_record_create(_contacts_address._uri, &addressHandle);
+ 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 recordHandle(addressHandle);
+
+ switch (_AddressImpl::GetInstance(address)->GetType())
+ {
+ case ADDRESS_TYPE_HOME:
+ type = CONTACTS_ADDRESS_TYPE_HOME;
+ break;
+ case ADDRESS_TYPE_WORK:
+ type = CONTACTS_ADDRESS_TYPE_WORK;
+ break;
+ case ADDRESS_TYPE_CUSTOM:
+ type = CONTACTS_ADDRESS_TYPE_CUSTOM;
+ break;
+ case ADDRESS_TYPE_OTHER:
+ // fall through
+ default:
+ type = CONTACTS_ADDRESS_TYPE_OTHER;
+ break;
+ }
+
+ contacts_record_set_int(addressHandle, _contacts_address.type, type);
+
+ stringValue = _AddressImpl::GetInstance(address)->GetLabel();
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(addressHandle, _contacts_address.label, pCharArray.get());
+
+ stringValue = _AddressImpl::GetInstance(address)->GetCity();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(addressHandle, _contacts_address.locality, pCharArray.get());
+ }
+
+
+ stringValue = _AddressImpl::GetInstance(address)->GetCountry();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(addressHandle, _contacts_address.country, pCharArray.get());
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetExtended();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(addressHandle, _contacts_address.extended, pCharArray.get());
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetPostalCode();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(addressHandle, _contacts_address.postal_code, pCharArray.get());
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetPostOfficeBoxNumber();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(addressHandle, _contacts_address.postbox, pCharArray.get());
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetState();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(addressHandle, _contacts_address.region, pCharArray.get());
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetStreet();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(addressHandle, _contacts_address.street, pCharArray.get());
+ }
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.address, addressHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::AddImAddress(const ImAddress& imAddress)
+{
+ SysTryReturn(NID_SCL, !imAddress.GetImAddress().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%] Invalid argument is used. The imAddress is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int type = 0;
+ String stringValue;
+ contacts_record_h messengerHandle = null;
+
+ std::unique_ptr<char[]> pCharArray(null);
+
+ int ret = contacts_record_create(_contacts_messenger._uri, &messengerHandle);
+ 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 recordHandle(messengerHandle);
+
+ stringValue = _ImAddressImpl::GetInstance(imAddress)->GetServiceProviderName();
+
+ if (stringValue == IM_ADDRESS_GOOGLE_TALK)
+ {
+ type = CONTACTS_MESSENGER_TYPE_GOOGLE;
+ }
+ else if (stringValue == IM_ADDRESS_MSN)
+ {
+ type = CONTACTS_MESSENGER_TYPE_WLM;
+ }
+ else if (stringValue == IM_ADDRESS_ICQ)
+ {
+ type = CONTACTS_MESSENGER_TYPE_ICQ;
+ }
+ else if (stringValue == IM_ADDRESS_AIM)
+ {
+ type = CONTACTS_MESSENGER_TYPE_AIM;
+ }
+ else if (stringValue == IM_ADDRESS_YAHOO)
+ {
+ type = CONTACTS_MESSENGER_TYPE_YAHOO;
+ }
+ else if (stringValue == IM_ADDRESS_QQ)
+ {
+ type = CONTACTS_MESSENGER_TYPE_QQ;
+ }
+ else if (stringValue == IM_ADDRESS_SKYPE)
+ {
+ type = CONTACTS_MESSENGER_TYPE_SKYPE;
+ }
+ else if (stringValue == IM_ADDRESS_JABBER)
+ {
+ type = CONTACTS_MESSENGER_TYPE_JABBER;
+ }
+ else
+ {
+ type = CONTACTS_MESSENGER_TYPE_CUSTOM;
+ }
+
+ contacts_record_set_int(messengerHandle, _contacts_messenger.type, type);
+ if (type == CONTACTS_MESSENGER_TYPE_CUSTOM)
+ {
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(messengerHandle, _contacts_messenger.label, pCharArray.get());
+ }
+
+ stringValue = _ImAddressImpl::GetInstance(imAddress)->GetImAddress();
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(messengerHandle, _contacts_messenger.im_id, pCharArray.get());
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.messenger, messengerHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+}
+result
+_ContactImpl::AddRelationship(const Relationship& relationship)
+{
+ SysTryReturn(NID_SCL, !relationship.GetRelativeName().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%] Invalid argument is used. The relationship is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int intValue = 0;
+ contacts_record_h relationshipHandle = null;
+
+ int ret = contacts_record_create(_contacts_relationship._uri, &relationshipHandle);
+ 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 recordHandle(relationshipHandle);
+
+ switch (relationship.GetType())
+ {
+ case CONTACT_RELATIONSHIP_TYPE_ASSISTANT:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_BROTHER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_BROTHER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_CHILD:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_CHILD;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_FATHER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_FATHER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_FRIEND:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_FRIEND;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_MANAGER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_MANAGER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_MOTHER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_MOTHER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_PARENT:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_PARENT;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_PARTNER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_PARTNER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_REFERRED_BY:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_RELATIVE:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_RELATIVE;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_SISTER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_SISTER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_SPOUSE:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_SPOUSE;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_CUSTOM:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_CUSTOM;
+ break;
+ default:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_OTHER;
+ break;
+ }
+
+ // type
+ contacts_record_set_int(relationshipHandle, _contacts_relationship.type, intValue);
+
+ // label
+ String stringValue = relationship.GetLabel();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(relationshipHandle, _contacts_relationship.label, pCharArray.get());
+ }
+
+ // name
+ stringValue = relationship.GetRelativeName();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(relationshipHandle, _contacts_relationship.name, pCharArray.get());
+ }
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.relationship, relationshipHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+
+}
+
+result
+_ContactImpl::AddEvent(const ContactEvent& event)
+{
+ SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int type = 0;
+ int intValue = 0;
+ String stringValue;
+ contacts_record_h eventHandle = null;
+
+ int ret = contacts_record_create(_contacts_event._uri, &eventHandle);
+ 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 recordHandle(eventHandle);
+
+ switch (event.GetType())
+ {
+ case CONTACT_EVENT_TYPE_ANNIVERSARY:
+ type = CONTACTS_EVENT_TYPE_ANNIVERSARY;
+ break;
+ case CONTACT_EVENT_TYPE_BIRTHDAY:
+ type = CONTACTS_EVENT_TYPE_BIRTH;
+ break;
+ case CONTACT_EVENT_TYPE_CUSTOM:
+ type = CONTACTS_EVENT_TYPE_CUSTOM;
+ break;
+ case CONTACT_EVENT_TYPE_OTHER:
+ // fall through
+ default:
+ type = CONTACTS_EVENT_TYPE_OTHER;
+ break;
+ }
+
+ // type
+ contacts_record_set_int(eventHandle, _contacts_event.type, type);
+
+ // label
+ stringValue = event.GetLabel();
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(eventHandle, _contacts_event.label, pCharArray.get());
+
+ // date
+ DateTime dateValue = event.GetDate();
+ intValue = dateValue.GetYear()*10000 + dateValue.GetMonth()*100 + dateValue.GetDay();
+ contacts_record_set_int(eventHandle, _contacts_event.date, intValue);
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.event, eventHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::AddOrganization(const Organization& organization)
+{
+ SysTryReturn(NID_SCL
+ , !organization.GetName().IsEmpty() ||
+ !organization.GetJobTitle().IsEmpty() ||
+ !organization.GetDepartment().IsEmpty() ||
+ !organization.GetRole().IsEmpty() ||
+ !organization.GetAgent().IsEmpty()
+ ,E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The organization is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_h organizationHandle = null;
+
+ int ret = contacts_record_create(_contacts_company._uri, &organizationHandle);
+ 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 recordHandle(organizationHandle);
+
+ // name
+ String stringValue = organization.GetName();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.name, pCharArray.get());
+ }
+
+ // job title
+ stringValue = organization.GetJobTitle();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.job_title, pCharArray.get());
+ }
+
+ // department
+ stringValue = organization.GetDepartment();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.department, pCharArray.get());
+ }
+
+ // role
+ stringValue = organization.GetRole();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.role, pCharArray.get());
+ }
+
+ // agent
+ stringValue = organization.GetAgent();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, pCharArray.get());
+ }
+
+ ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.company, organizationHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::RemoveAt(ContactMultiPropertyId id, int index)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+
+ unsigned int count = 0;
+ contacts_record_h recordHandle = null;
+
+ switch (id)
+ {
+ case CONTACT_MPROPERTY_ID_PHONE_NUMBERS:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of phone numbers %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.number, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.number, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_EMAILS:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of emails %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.email, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.email, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_URLS:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of urls %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.url, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.url, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_ADDRESSES:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of addresses %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.address, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.address, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_IMADDRESSES:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of IM addresses %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.messenger, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.messenger, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_ORGANIZATIONS:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of organizations %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.company, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_EVENTS:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of events %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.event, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_RELATIONSHIPS:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.relationship, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of relationships %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.relationship, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.relationship, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_NOTES:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of notes %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.note, recordHandle);
+
+ break;
+ case CONTACT_MPROPERTY_ID_NICKNAMES:
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of nicknames %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, index, &recordHandle);
+ contacts_record_remove_child_record(__contactHandle, _contacts_contact.nickname, recordHandle);
+
+ break;
+ default:
+ SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
+ return E_INVALID_ARG;
+ }
+
+ return E_SUCCESS;
+}
+
+IList*
+_ContactImpl::GetValuesN(const ContactMultiPropertyId id)
+{
+ IList* pList = null;
+
+ SetLastResult(E_SUCCESS);
+
+ switch (id)
+ {
+ case CONTACT_MPROPERTY_ID_PHONE_NUMBERS:
+ pList = GetPhoneNumbersN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_EMAILS:
+ pList = GetEmailsN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_URLS:
+ pList = GetUrlsN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_ADDRESSES:
+ pList = GetAddressesN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_IMADDRESSES:
+ pList = GetImAddressesN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_ORGANIZATIONS:
+ pList = GetOrganizationsN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_EVENTS:
+ pList = GetEventsN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_RELATIONSHIPS:
+ pList = GetRelationshipsN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_NOTES:
+ pList = GetNotesN();
+ break;
+
+ case CONTACT_MPROPERTY_ID_NICKNAMES:
+ pList = GetNicknamesN();
+ break;
+ default:
+ SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
+ return null;
+ }
+
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ return pList;
+}
+
+result
+_ContactImpl::SetPhoneNumberAt(int index, const PhoneNumber& phoneNumber)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL, !phoneNumber.GetPhoneNumber().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The phoneNumber is string.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unsigned int count = 0;
+ contacts_record_h recordHandle = null;
+ String stringValue;
+ int type = 0;
+ int oriType = 0;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of phone numbers.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.number, index, &recordHandle);
+
+
+ stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetLabel();
+
+ switch (_PhoneNumberImpl::GetInstance(phoneNumber)->GetType())
+ {
+ case PHONENUMBER_TYPE_HOME:
+ type = CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE;
+ break;
+ case PHONENUMBER_TYPE_WORK:
+ type = CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE;
+ break;
+ case PHONENUMBER_TYPE_MOBILE:
+ type = CONTACTS_NUMBER_TYPE_CELL;
+ break;
+ case PHONENUMBER_TYPE_HOME_FAX:
+ type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME;
+ break;
+ case PHONENUMBER_TYPE_WORK_FAX:
+ type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK;
+ break;
+ case PHONENUMBER_TYPE_PAGER:
+ type = CONTACTS_NUMBER_TYPE_PAGER;
+ break;
+ case PHONENUMBER_TYPE_CUSTOM:
+ type = CONTACTS_NUMBER_TYPE_CUSTOM;
+ break;
+ case PHONENUMBER_TYPE_OTHER:
+ contacts_record_get_int(recordHandle, _contacts_number.type, &oriType);
+
+ if (oriType == (CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE)
+ || oriType == (CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE)
+ || oriType == CONTACTS_NUMBER_TYPE_CELL
+ || oriType == (CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME)
+ || oriType == (CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK)
+ || oriType == CONTACTS_NUMBER_TYPE_PAGER)
+ {
+ type = CONTACTS_NUMBER_TYPE_OTHER;
+ }
+ else if (oriType == CONTACTS_NUMBER_TYPE_CUSTOM)
+ {
+ if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+ {
+ char* pCharValue = null;
+
+ contacts_record_get_str_p(recordHandle, _contacts_number.label, &pCharValue);
+
+ stringValue = pCharValue;
+ type = CONTACTS_NUMBER_TYPE_CUSTOM;
+
+ }
+ else
+ {
+ type = CONTACTS_NUMBER_TYPE_OTHER;
+ }
+ }
+ else
+ {
+ type = oriType;
+ }
+ break;
+ default:
+ type = CONTACTS_NUMBER_TYPE_OTHER;
+ break;
+ }
+
+ // set type
+ contacts_record_set_int(recordHandle, _contacts_number.type, type);
+
+ // set label
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_number.label, pCharArray.get());
+
+ // set phone number
+ stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetPhoneNumber();
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_number.number, pCharArray.get());
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetNicknameAt(int index, const String& nickname)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL, !nickname.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The nickname is an empty string.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unsigned int count = 0;
+ contacts_record_h nicknameHandle = null;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of nicknames.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, index, &nicknameHandle);
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(nickname));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetNoteAt(int index, const String& note)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL, !note.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The note is an empty string.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unsigned int count = 0;
+ contacts_record_h noteHandle = null;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of notes.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, index, ¬eHandle);
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(note));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetOrganizationAt(int index, const Organization& organization)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL
+ , !organization.GetName().IsEmpty() ||
+ !organization.GetJobTitle().IsEmpty() ||
+ !organization.GetDepartment().IsEmpty() ||
+ !organization.GetRole().IsEmpty() ||
+ !organization.GetAgent().IsEmpty()
+ ,E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The organization is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unsigned int count = 0;
+ contacts_record_h organizationHandle = null;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of organizations.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, index, &organizationHandle);
+
+ // name
+ String stringValue = organization.GetName();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.name, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(organizationHandle, _contacts_company.name, null);
+ }
+
+ // job title
+ stringValue = organization.GetJobTitle();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.job_title, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(organizationHandle, _contacts_company.job_title, null);
+ }
+
+ // department
+ stringValue = organization.GetDepartment();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.department, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(organizationHandle, _contacts_company.department, null);
+ }
+
+ // role
+ stringValue = organization.GetRole();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.role, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(organizationHandle, _contacts_company.role, null);
+ }
+
+ // agent
+ stringValue = organization.GetAgent();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, null);
+ }
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetEventAt(int index, const ContactEvent& event)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int type = 0;
+ int intValue = 0;
+ unsigned int count = 0;
+ String stringValue;
+ contacts_record_h eventHandle = null;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of events.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, index, &eventHandle);
+
+ switch (event.GetType())
+ {
+ case CONTACT_EVENT_TYPE_ANNIVERSARY:
+ type = CONTACTS_EVENT_TYPE_ANNIVERSARY;
+ break;
+ case CONTACT_EVENT_TYPE_BIRTHDAY:
+ type = CONTACTS_EVENT_TYPE_BIRTH;
+ break;
+ case CONTACT_EVENT_TYPE_CUSTOM:
+ type = CONTACTS_EVENT_TYPE_CUSTOM;
+ break;
+ case CONTACT_EVENT_TYPE_OTHER:
+ // fall through
+ default:
+ type = CONTACTS_EVENT_TYPE_OTHER;
+ break;
+ }
+
+ // type
+ contacts_record_set_int(eventHandle, _contacts_event.type, type);
+
+ // label
+ stringValue = event.GetLabel();
+
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(eventHandle, _contacts_event.label, pCharArray.get());
+
+ // date
+ DateTime dateValue = event.GetDate();
+ intValue = dateValue.GetYear()*10000 + dateValue.GetMonth()*100 + dateValue.GetDay();
+ contacts_record_set_int(eventHandle, _contacts_event.date, intValue);
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetRelationshipAt(int index, const Relationship& relationship)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL, !relationship.GetRelativeName().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The relationship is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int intValue = 0;
+ unsigned int count = 0;
+ contacts_record_h relationshipHandle = null;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.relationship, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int)index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of relationships.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.relationship, index, &relationshipHandle);
+
+ switch (relationship.GetType())
+ {
+ case CONTACT_RELATIONSHIP_TYPE_ASSISTANT:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_BROTHER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_BROTHER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_CHILD:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_CHILD;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_FATHER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_FATHER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_FRIEND:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_FRIEND;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_MANAGER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_MANAGER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_MOTHER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_MOTHER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_PARENT:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_PARENT;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_PARTNER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_PARTNER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_REFERRED_BY:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_RELATIVE:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_RELATIVE;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_SISTER:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_SISTER;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_SPOUSE:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_SPOUSE;
+ break;
+ case CONTACT_RELATIONSHIP_TYPE_CUSTOM:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_CUSTOM;
+ break;
+ default:
+ intValue = CONTACTS_RELATIONSHIP_TYPE_OTHER;
+ break;
+ }
+
+ // type
+ contacts_record_set_int(relationshipHandle, _contacts_relationship.type, intValue);
+
+ // label
+ String stringValue = relationship.GetLabel();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(relationshipHandle, _contacts_relationship.label, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(relationshipHandle, _contacts_relationship.label, null);
+ }
+
+ // name
+ stringValue = relationship.GetRelativeName();
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(relationshipHandle, _contacts_relationship.name, pCharArray.get());
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetEmailAt(int index, const Email& email)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL, !email.GetEmail().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The email is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unsigned int count = 0;
+ contacts_record_h emailHandle = null;
+ String stringValue;
+ int type = 0;
+ int oriType = 0;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int) index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of emails.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.email, index, &emailHandle);
+
+ stringValue = _EmailImpl::GetInstance(email)->GetLabel();
+
+ switch (_EmailImpl::GetInstance(email)->GetType())
+ {
+ case EMAIL_TYPE_PERSONAL:
+ type = CONTACTS_EMAIL_TYPE_HOME;
+ break;
+ case EMAIL_TYPE_WORK:
+ type = CONTACTS_EMAIL_TYPE_WORK;
+ break;
+ case EMAIL_TYPE_CUSTOM:
+ type = CONTACTS_EMAIL_TYPE_CUSTOM;
+ break;
+ case EMAIL_TYPE_OTHER:
+ contacts_record_get_int(emailHandle, _contacts_email.type, &oriType);
+ if (oriType == CONTACTS_EMAIL_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
+ {
+ char* pCharValue = null;
+
+ contacts_record_get_str_p(emailHandle, _contacts_email.label, &pCharValue);
+
+ stringValue = pCharValue;
+ type = CONTACTS_EMAIL_TYPE_CUSTOM;
+
+ }
+ else
+ {
+ type = CONTACTS_EMAIL_TYPE_OTHER;
+ }
+ break;
+ default:
+ type = CONTACTS_EMAIL_TYPE_OTHER;
+ break;
+ }
+
+ // set type
+ contacts_record_set_int(emailHandle, _contacts_email.type, type);
+
+ // set label
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(emailHandle, _contacts_email.label, pCharArray.get());
+
+ // set email
+ stringValue = _EmailImpl::GetInstance(email)->GetEmail();
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(emailHandle, _contacts_email.email, pCharArray.get());
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetUrlAt(int index, const Url& url)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL, !url.GetUrl().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The url is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unsigned int count = 0;
+ contacts_record_h recordHandle = null;
+ String stringValue;
+ int type = 0;
+ int oriType = 0;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int)index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of urls.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.url, index, &recordHandle);
+
+
+ stringValue = _UrlImpl::GetInstance(url)->GetLabel();
+
+ switch (_UrlImpl::GetInstance(url)->GetType())
+ {
+ case URL_TYPE_PERSONAL:
+ type = CONTACTS_URL_TYPE_HOME;
+ break;
+ case URL_TYPE_WORK:
+ type = CONTACTS_URL_TYPE_WORK;
+ break;
+ case URL_TYPE_CUSTOM:
+ type = CONTACTS_URL_TYPE_CUSTOM;
+ break;
+ case URL_TYPE_OTHER:
+ contacts_record_get_int(recordHandle, _contacts_url.type, &oriType);
+
+ if (oriType == CONTACTS_URL_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
+ {
+ char* pCharValue = null;
+
+ contacts_record_get_str_p(recordHandle, _contacts_url.label, &pCharValue);
+
+ stringValue = pCharValue;
+ type = CONTACTS_URL_TYPE_CUSTOM;
+ }
+ else
+ {
+ type = CONTACTS_URL_TYPE_OTHER;
+ }
+ break;
+ default:
+ type = CONTACTS_URL_TYPE_OTHER;
+ break;
+ }
+
+ // set type
+ contacts_record_set_int(recordHandle, _contacts_url.type, type);
+
+ // set label
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_url.label, pCharArray.get());
+
+ // set url
+ stringValue = _UrlImpl::GetInstance(url)->GetUrl();
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_url.url, pCharArray.get());
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetAddressAt(int index, const Address& address)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_MEMORY, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL,
+ !address.GetCity().IsEmpty() ||
+ !address.GetCountry().IsEmpty() ||
+ !address.GetExtended().IsEmpty() ||
+ !address.GetPostalCode().IsEmpty() ||
+ !address.GetPostOfficeBoxNumber().IsEmpty() ||
+ !address.GetState().IsEmpty() ||
+ !address.GetStreet().IsEmpty(),
+ E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The address is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unsigned int count = 0;
+ contacts_record_h recordHandle = null;
+ int type = 0;
+ int oriType = 0;
+ String stringValue;
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int)index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be less than the current count of addresses %d.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.address, index, &recordHandle);
+
+ stringValue = _AddressImpl::GetInstance(address)->GetLabel();
+
+ switch (_AddressImpl::GetInstance(address)->GetType())
+ {
+ case ADDRESS_TYPE_HOME:
+ type = CONTACTS_ADDRESS_TYPE_HOME;
+ break;
+ case ADDRESS_TYPE_WORK:
+ type = CONTACTS_ADDRESS_TYPE_WORK;
+ break;
+ case ADDRESS_TYPE_CUSTOM:
+ type = CONTACTS_ADDRESS_TYPE_CUSTOM;
+ break;
+ case ADDRESS_TYPE_OTHER:
+ contacts_record_get_int(recordHandle, _contacts_address.type, &oriType);
+
+ if (oriType == CONTACTS_ADDRESS_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
+ {
+ char* pCharValue = null;
+
+ contacts_record_get_str_p(recordHandle, _contacts_address.label, &pCharValue);
+
+ stringValue = pCharValue;
+ type = CONTACTS_ADDRESS_TYPE_CUSTOM;
+ }
+ else
+ {
+ type = CONTACTS_ADDRESS_TYPE_OTHER;
+ }
+ break;
+ default:
+ type = CONTACTS_ADDRESS_TYPE_OTHER;
+ break;
+ }
+
+ // set type
+ contacts_record_set_int(recordHandle, _contacts_address.type, type);
+
+ // set label
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_address.label, pCharArray.get());
+
+ // address
+ stringValue = _AddressImpl::GetInstance(address)->GetCity();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_address.locality, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(recordHandle, _contacts_address.locality, null);
+ }
+
+
+ stringValue = _AddressImpl::GetInstance(address)->GetCountry();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_address.country, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(recordHandle, _contacts_address.country, null);
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetExtended();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_address.extended, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(recordHandle, _contacts_address.extended, null);
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetPostalCode();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_address.postal_code, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(recordHandle, _contacts_address.postal_code, null);
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetPostOfficeBoxNumber();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_address.postbox, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(recordHandle, _contacts_address.postbox, null);
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetState();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_address.region, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(recordHandle, _contacts_address.region, null);
+ }
+
+ stringValue = _AddressImpl::GetInstance(address)->GetStreet();
+ if (!stringValue.IsEmpty())
+ {
+ std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(recordHandle, _contacts_address.street, pCharArray.get());
+ }
+ else
+ {
+ contacts_record_set_str(recordHandle, _contacts_address.street, null);
+ }
+
+ return E_SUCCESS;
+}
+
+result
+_ContactImpl::SetImAddressAt(int index, const ImAddress& imAddress)
+{
+ SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
+ SysTryReturn(NID_SCL, !imAddress.GetImAddress().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The imAddress is empty.", GetErrorMessage(E_INVALID_ARG));
+ SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unsigned int count = 0;
+ contacts_record_h messengerHandle = null;
+ String stringValue;
+ int type = 0;
+ std::unique_ptr<char[]> pCharArray(null);
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
+ SysTryReturn(NID_SCL, count > (unsigned int)index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of IM addresses.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
+
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.messenger, index, &messengerHandle);
+
+ stringValue = _ImAddressImpl::GetInstance(imAddress)->GetServiceProviderName();
+
+ if (stringValue == IM_ADDRESS_GOOGLE_TALK)
+ {
+ type = CONTACTS_MESSENGER_TYPE_GOOGLE;
+ }
+ else if (stringValue == IM_ADDRESS_MSN)
+ {
+ type = CONTACTS_MESSENGER_TYPE_WLM;
+ }
+ else if (stringValue == IM_ADDRESS_ICQ)
+ {
+ type = CONTACTS_MESSENGER_TYPE_ICQ;
+ }
+ else if (stringValue == IM_ADDRESS_AIM)
+ {
+ type = CONTACTS_MESSENGER_TYPE_AIM;
+ }
+ else if (stringValue == IM_ADDRESS_YAHOO)
+ {
+ type = CONTACTS_MESSENGER_TYPE_YAHOO;
+ }
+ else if (stringValue == IM_ADDRESS_QQ)
+ {
+ type = CONTACTS_MESSENGER_TYPE_QQ;
+ }
+ else if (stringValue == IM_ADDRESS_SKYPE)
+ {
+ type = CONTACTS_MESSENGER_TYPE_SKYPE;
+ }
+ else if (stringValue == IM_ADDRESS_JABBER)
+ {
+ type = CONTACTS_MESSENGER_TYPE_JABBER;
+ }
+ else
+ {
+ type = CONTACTS_MESSENGER_TYPE_CUSTOM;
+ }
+
+ contacts_record_set_int(messengerHandle, _contacts_messenger.type, type);
+ if (type == CONTACTS_MESSENGER_TYPE_CUSTOM)
+ {
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(messengerHandle, _contacts_messenger.label, pCharArray.get());
+ }
+
+ stringValue = _ImAddressImpl::GetInstance(imAddress)->GetImAddress();
+ pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
+ SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_set_str(messengerHandle, _contacts_messenger.im_id, pCharArray.get());
+
+ return E_SUCCESS;
+}
+
+int
+_ContactImpl::GetMaxLength(ContactPropertyId id)
+{
+ switch (id)
+ {
+ case CONTACT_PROPERTY_ID_FIRST_NAME:
+ //fall through
+ case CONTACT_PROPERTY_ID_LAST_NAME:
+ //fall through
+ case CONTACT_PROPERTY_ID_DISPLAY_NAME:
+ //fall through
+ case CONTACT_PROPERTY_ID_NICK_NAME:
+ //fall through
+ case CONTACT_PROPERTY_ID_MIDDLE_NAME:
+ return MAX_CONTACT_NAME_LENGTH;
+
+ case CONTACT_PROPERTY_ID_THUMBNAIL:
+ return -1;
+
+ case CONTACT_PROPERTY_ID_JOB_TITLE:
+ return MAX_CONTACT_JOB_TITLE_LENGTH;
+
+ case CONTACT_PROPERTY_ID_COMPANY:
+ return MAX_CONTACT_COMPANY_LENGTH;
+
+ case CONTACT_PROPERTY_ID_NOTE:
+ return MAX_CONTACT_NOTE_LENGTH;
+
+ case CONTACT_PROPERTY_ID_RINGTONE:
+ return -1;
+
+ default:
+ return -1;
+ }
+}
+
+IList*
+_ContactImpl::GetOrganizationsN(void) const
+{
+ result r = E_SUCCESS;
+ contacts_record_h organizationHandle = null;
+ int ret = CONTACTS_ERROR_NONE;
+ char* pCharValue = null;
+ unsigned int count = 0;
+ std::unique_ptr<Organization> pOrganization(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, i, &organizationHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+ pOrganization.reset(new (std::nothrow) Organization());
+ SysTryReturn(NID_SCL, pOrganization != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ // name
+ contacts_record_get_str_p(organizationHandle, _contacts_company.name, &pCharValue);
+ pOrganization->SetName(pCharValue);
+
+ // job title
+ contacts_record_get_str_p(organizationHandle, _contacts_company.job_title, &pCharValue);
+ pOrganization->SetJobTitle(pCharValue);
+
+ // department
+ contacts_record_get_str_p(organizationHandle, _contacts_company.department, &pCharValue);
+ pOrganization->SetDepartment(pCharValue);
+
+ // role
+ contacts_record_get_str_p(organizationHandle, _contacts_company.role, &pCharValue);
+ pOrganization->SetRole(pCharValue);
+
+ // agent
+ contacts_record_get_str_p(organizationHandle, _contacts_company.assistant_name, &pCharValue);
+ pOrganization->SetAgent(pCharValue);
+
+ r = pList->Add(*pOrganization);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pOrganization.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetRelationshipsN(void) const
+{
+ result r = E_SUCCESS;
+ contacts_record_h relationshipHandle = null;
+ int ret = CONTACTS_ERROR_NONE;
+ int intValue = 0;
+ char* pCharValue = null;
+ unsigned int count = 0;
+ std::unique_ptr<Relationship> pRelationship(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.relationship, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.relationship, i, &relationshipHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+ pRelationship.reset(new (std::nothrow) Relationship());
+ SysTryReturn(NID_SCL, pRelationship != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ // type
+ contacts_record_get_int(relationshipHandle, _contacts_relationship.type, &intValue);
+ switch (intValue)
+ {
+ case CONTACTS_RELATIONSHIP_TYPE_ASSISTANT:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_ASSISTANT);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_BROTHER:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_BROTHER);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_CHILD:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_CHILD);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_FATHER:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_FATHER);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_FRIEND:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_FRIEND);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_MANAGER:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_MANAGER);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_MOTHER:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_MOTHER);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_PARENT:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_PARENT);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_PARTNER:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_PARTNER);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_REFERRED_BY);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_RELATIVE:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_RELATIVE);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_SISTER:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_SISTER);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_SPOUSE:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_SPOUSE);
+ break;
+ case CONTACTS_RELATIONSHIP_TYPE_CUSTOM:
+ // fall through
+ default:
+ pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_CUSTOM);
+ break;
+ }
+
+ // label
+ contacts_record_get_str_p(relationshipHandle, _contacts_relationship.label, &pCharValue);
+ pRelationship->SetLabel(pCharValue);
+
+ // name
+ contacts_record_get_str_p(relationshipHandle, _contacts_relationship.name, &pCharValue);
+ pRelationship->SetRelativeName(pCharValue);
+
+ r = pList->Add(*pRelationship);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pRelationship.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetEventsN(void) const
+{
+ result r = E_SUCCESS;
+ char* pCharValue = null;
+ int intValue = 0;
+ unsigned int count = 0;
+ contacts_record_h eventHandle = null;
+ std::unique_ptr<ContactEvent> pEvent(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
+
+ pEvent.reset(new (std::nothrow) ContactEvent());
+ SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ // label
+ contacts_record_get_str_p(eventHandle, _contacts_event.label, &pCharValue);
+ pEvent->SetLabel(pCharValue);
+
+ // type
+ contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
+ switch (intValue)
+ {
+ case CONTACTS_EVENT_TYPE_BIRTH:
+ pEvent->SetType(CONTACT_EVENT_TYPE_BIRTHDAY);
+ break;
+ case CONTACTS_EVENT_TYPE_ANNIVERSARY:
+ pEvent->SetType(CONTACT_EVENT_TYPE_ANNIVERSARY);
+ break;
+ case CONTACTS_URL_TYPE_CUSTOM:
+ pEvent->SetType(CONTACT_EVENT_TYPE_CUSTOM);
+ break;
+ default:
+ pEvent->SetType(CONTACT_EVENT_TYPE_OTHER);
+ break;
+ }
+
+ DateTime dateTime;
+
+ contacts_record_get_int(eventHandle, _contacts_event.date, &intValue);
+ __CONVERT_DATE_TO_DATETIME(intValue, dateTime);
+ pEvent->SetDate(dateTime);
+
+ pList->Add(*pEvent);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pEvent.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetNotesN(void) const
+{
+ result r = E_SUCCESS;
+ char* pCharValue = null;
+ unsigned int count = 0;
+ contacts_record_h noteHandle = null;
+ std::unique_ptr<String> pNote(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, i, ¬eHandle);
+
+ contacts_record_get_str_p(noteHandle, _contacts_note.note, &pCharValue);
+
+ pNote.reset(new (std::nothrow) String(pCharValue));
+ SysTryReturn(NID_SCL, pNote != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pList->Add(*pNote);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pNote.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetNicknamesN(void) const
+{
+ result r = E_SUCCESS;
+ char* pCharValue = null;
+ unsigned int count = 0;
+ contacts_record_h nicknameHandle = null;
+ std::unique_ptr<String> pNickname(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, i, &nicknameHandle);
+
+ contacts_record_get_str_p(nicknameHandle, _contacts_nickname.name, &pCharValue);
+
+ pNickname.reset(new (std::nothrow) String(pCharValue));
+ SysTryReturn(NID_SCL, pNickname != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pList->Add(*pNickname);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pNickname.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetPhoneNumbersN(void) const
+{
+ result r = E_SUCCESS;
+ unsigned int count = 0;
+ contacts_record_h numberHandle = null;
+ int intValue = 0;
+ char* pCharValue = null;
+ PhoneNumberType type = PHONENUMBER_TYPE_HOME;
+ std::unique_ptr<PhoneNumber> pPhoneNumber(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
+
+ contacts_record_get_int(__contactHandle, _contacts_contact.id, &intValue);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.number, i, &numberHandle);
+
+ pPhoneNumber.reset(new (std::nothrow) PhoneNumber());
+ SysTryReturn(NID_SCL, pPhoneNumber != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_int(numberHandle, _contacts_number.id, &intValue);
+ _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetRecordId(intValue);
+
+ contacts_record_get_str_p(numberHandle, _contacts_number.label, &pCharValue);
+ _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetLabel(pCharValue);
+
+ contacts_record_get_int(numberHandle, _contacts_number.type, &intValue);
+
+ switch (intValue)
+ {
+ case CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE:
+ type = PHONENUMBER_TYPE_HOME;
+ break;
+ case CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE:
+ type = PHONENUMBER_TYPE_WORK;
+ break;
+ case CONTACTS_NUMBER_TYPE_CELL:
+ type = PHONENUMBER_TYPE_MOBILE;
+ break;
+ case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME:
+ type = PHONENUMBER_TYPE_HOME_FAX;
+ break;
+ case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK:
+ type = PHONENUMBER_TYPE_WORK_FAX;
+ break;
+ case CONTACTS_NUMBER_TYPE_PAGER:
+ type = PHONENUMBER_TYPE_PAGER;
+ break;
+ case CONTACTS_NUMBER_TYPE_CUSTOM:
+ type = PHONENUMBER_TYPE_CUSTOM;
+ break;
+ case CONTACTS_NUMBER_TYPE_ASSISTANT:
+ // fall through
+ default:
+ type = PHONENUMBER_TYPE_OTHER;
+ break;
+ }
+
+ _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetType(type);
+
+ contacts_record_get_str_p(numberHandle, _contacts_number.number, &pCharValue);
+ _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetPhoneNumber(pCharValue);
+
+ r = pList->Add(*pPhoneNumber);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pPhoneNumber.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetEmailsN(void) const
+{
+ result r = E_SUCCESS;
+ contacts_record_h currentHandle = null;
+ int ret = CONTACTS_ERROR_NONE;
+ int intValue = 0;
+ unsigned int count = 0;
+ char* pCharValue = null;
+ EmailType type = EMAIL_TYPE_PERSONAL;
+ std::unique_ptr<Email> pEmail(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.email, i, ¤tHandle);
+ SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM))
+
+ pEmail.reset(new (std::nothrow) Email());
+ SysTryReturn(NID_SCL, pEmail != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_int(currentHandle, _contacts_email.id, &intValue);
+ _EmailImpl::GetInstance(*pEmail)->SetRecordId(intValue);
+
+ contacts_record_get_str_p(currentHandle, _contacts_email.label, &pCharValue);
+ _EmailImpl::GetInstance(*pEmail)->SetLabel(pCharValue);
+
+ contacts_record_get_int(currentHandle, _contacts_email.type, &intValue);
+ switch (intValue)
+ {
+ case CONTACTS_EMAIL_TYPE_HOME:
+ type = EMAIL_TYPE_PERSONAL;
+ break;
+ case CONTACTS_EMAIL_TYPE_WORK:
+ type = EMAIL_TYPE_WORK;
+ break;
+ case CONTACTS_EMAIL_TYPE_CUSTOM:
+ type = EMAIL_TYPE_CUSTOM;
+ break;
+ default:
+ type = EMAIL_TYPE_OTHER;
+ break;
+ }
+
+ _EmailImpl::GetInstance(*pEmail)->SetType(type);
+
+ contacts_record_get_str_p(currentHandle, _contacts_email.email, &pCharValue);
+ _EmailImpl::GetInstance(*pEmail)->SetEmail(pCharValue);
+
+ r = pList->Add(*pEmail);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pEmail.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetUrlsN(void) const
+{
+ result r = E_SUCCESS;
+ char* pCharValue = null;
+ int intValue = 0;
+ unsigned int count = 0;
+ UrlType type = URL_TYPE_PERSONAL;
+ contacts_record_h urlHandle = null;
+ std::unique_ptr<Url> pUrl(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.url, i, &urlHandle);
+
+ pUrl.reset(new (std::nothrow) Url());
+ SysTryReturn(NID_SCL, pUrl != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_str_p(urlHandle, _contacts_url.label, &pCharValue);
+ pUrl->SetLabel(pCharValue);
+
+ contacts_record_get_int(urlHandle, _contacts_url.type, &intValue);
+ switch (intValue)
+ {
+ case CONTACTS_URL_TYPE_HOME:
+ type = URL_TYPE_PERSONAL;
+ break;
+ case CONTACTS_URL_TYPE_WORK:
+ type = URL_TYPE_WORK;
+ break;
+ case CONTACTS_URL_TYPE_CUSTOM:
+ type = URL_TYPE_CUSTOM;
+ break;
+ default:
+ type = URL_TYPE_OTHER;
+ break;
+ }
+
+ pUrl->SetType(type);
+
+ contacts_record_get_str_p(urlHandle, _contacts_url.url, &pCharValue);
+ _UrlImpl::GetInstance(*pUrl)->SetUrl(pCharValue);
+
+ pList->Add(*pUrl);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pUrl.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetAddressesN(void) const
+{
+ result r = E_SUCCESS;
+ char* pCharValue = null;
+ int intValue = 0;
+ unsigned int count = 0;
+ contacts_record_h addressHandle = 0;
+ std::unique_ptr<Address> pAddress(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.address, i, &addressHandle);
+
+ pAddress.reset(new (std::nothrow) Address());
+ SysTryReturn(NID_SCL, pAddress != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_str_p(addressHandle, _contacts_address.label, &pCharValue);
+ pAddress->SetLabel(pCharValue);
+
+ contacts_record_get_int(addressHandle, _contacts_address.type, &intValue);
+ switch (intValue)
+ {
+ case CONTACTS_ADDRESS_TYPE_HOME:
+ pAddress->SetType(ADDRESS_TYPE_HOME);
+ break;
+ case CONTACTS_ADDRESS_TYPE_WORK:
+ pAddress->SetType(ADDRESS_TYPE_WORK);
+ break;
+ case CONTACTS_ADDRESS_TYPE_CUSTOM:
+ pAddress->SetType(ADDRESS_TYPE_CUSTOM);
+ break;
+ default:
+ pAddress->SetType(ADDRESS_TYPE_OTHER);
+ break;
+ }
+
+ // 1. country
+ contacts_record_get_str_p(addressHandle, _contacts_address.country, &pCharValue);
+ _AddressImpl::GetInstance(*pAddress)->SetCountry(pCharValue);
+
+ // 2. region
+ contacts_record_get_str_p(addressHandle, _contacts_address.region, &pCharValue);
+ _AddressImpl::GetInstance(*pAddress)->SetState(pCharValue);
+
+ // 3. city
+ contacts_record_get_str_p(addressHandle, _contacts_address.locality, &pCharValue);
+ _AddressImpl::GetInstance(*pAddress)->SetCity(pCharValue);
+
+ // 4. street
+ contacts_record_get_str_p(addressHandle, _contacts_address.street, &pCharValue);
+ _AddressImpl::GetInstance(*pAddress)->SetStreet(pCharValue);
+
+ // 5. extended
+ contacts_record_get_str_p(addressHandle, _contacts_address.extended, &pCharValue);
+ _AddressImpl::GetInstance(*pAddress)->SetExtended(pCharValue);
+
+ // 6. postbox
+ contacts_record_get_str_p(addressHandle, _contacts_address.postbox, &pCharValue);
+ _AddressImpl::GetInstance(*pAddress)->SetPostOfficeBoxNumber(pCharValue);
+
+ // 7. postal code
+ contacts_record_get_str_p(addressHandle, _contacts_address.postal_code, &pCharValue);
+ _AddressImpl::GetInstance(*pAddress)->SetPostalCode(pCharValue);
+
+ r = pList->Add(*pAddress);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pAddress.release();
+ }
+
+ return pList.release();
+}
+
+IList*
+_ContactImpl::GetImAddressesN(void) const
+{
+ result r = E_SUCCESS;
+ char* pCharValue = null;
+ int intValue = 0;
+ contacts_record_h messengerHandle = null;
+ unsigned int count = 0;
+ std::unique_ptr<ImAddress> pImAddress(null);
+
+ std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
+
+ r = pList->Construct(count);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+
+ for (unsigned int i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.messenger, i, &messengerHandle);
+
+ pImAddress.reset(new (std::nothrow) ImAddress());
+ SysTryReturn(NID_SCL, pImAddress != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ contacts_record_get_int(messengerHandle, _contacts_messenger.type, &intValue);
+ switch (intValue)
+ {
+ case CONTACTS_MESSENGER_TYPE_GOOGLE:
+ pImAddress->SetServiceProviderName(IM_ADDRESS_GOOGLE_TALK);
+ break;
+ case CONTACTS_MESSENGER_TYPE_WLM:
+ pImAddress->SetServiceProviderName(IM_ADDRESS_MSN);
+ break;
+ case CONTACTS_MESSENGER_TYPE_ICQ:
+ pImAddress->SetServiceProviderName(IM_ADDRESS_ICQ);
+ break;
+ case CONTACTS_MESSENGER_TYPE_AIM:
+ pImAddress->SetServiceProviderName(IM_ADDRESS_AIM);
+ break;
+ case CONTACTS_MESSENGER_TYPE_YAHOO:
+ pImAddress->SetServiceProviderName(IM_ADDRESS_YAHOO);
+ break;
+ case CONTACTS_MESSENGER_TYPE_QQ:
+ pImAddress->SetServiceProviderName(IM_ADDRESS_QQ);
+ break;
+ case CONTACTS_MESSENGER_TYPE_SKYPE:
+ pImAddress->SetServiceProviderName(IM_ADDRESS_SKYPE);
+ break;
+ case CONTACTS_MESSENGER_TYPE_JABBER:
+ pImAddress->SetServiceProviderName(IM_ADDRESS_JABBER);
+ break;
+ case CONTACTS_MESSENGER_TYPE_CUSTOM:
+ // fall through
+ default:
+ contacts_record_get_str_p(messengerHandle, _contacts_messenger.label, &pCharValue);
+ pImAddress->SetServiceProviderName(pCharValue);
+ break;
+ }
+
+ contacts_record_get_str_p(messengerHandle, _contacts_messenger.im_id, &pCharValue);
+ _ImAddressImpl::GetInstance(*pImAddress)->SetImAddress(pCharValue);
+
+ r = pList->Add(*pImAddress);
+ SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pImAddress.release();
+ }
+
+ return pList.release();
+}
+
+bool
+_ContactImpl::IsEmpty(void) const
+{
+ char* pCharValue = null;
+ unsigned int count = 0;
+
+ contacts_record_get_str_p(__contactHandle, _contacts_contact.ringtone_path, &pCharValue);
+ if (pCharValue != null)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
+ if (count > 0)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+AddressbookId
+_ContactImpl::GetAddressbookId(void) const
+{
+ int addressbookId = 0;
+
+ contacts_record_get_int(__contactHandle, _contacts_contact.address_book_id, &addressbookId);
+
+ return addressbookId;
+}
+
+PersonId
+_ContactImpl::GetPersonId(void) const
+{
+ int personId = 0;
+
+ contacts_record_get_int(__contactHandle, _contacts_contact.person_id, &personId);
+
+ return personId;
+}
+
+void
+_ContactImpl::SetAsRemoved(void)
+{
+ __isRemoved = true;
+}
+
+bool
+_ContactImpl::IsRemoved(void) const
+{
+ return __isRemoved;
+}
+
+result
+_ContactImpl::Invalidate(void)
+{
+ int ret = CONTACTS_ERROR_NONE;
+ unsigned int i = 0;
+ unsigned int count = 0;
+ char* pCharValue = null;
+ int intValue = 0;
+
+ 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, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ __ContactsRecordHandle recordHandle(contactHandle);
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // name
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_name._uri, &destRecordHandle);
+ 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(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);
+
+ contacts_record_add_child_record(contactHandle, _contacts_contact.name, destRecordHandle);
+
+ nameHandle.Release();
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // image
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
+ if (count > 0)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_image._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.company, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_company._uri, &destRecordHandle);
+ 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(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_add_child_record(contactHandle, _contacts_contact.company, destRecordHandle);
+
+ companyHandle.Release();
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // note
+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_note._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.number, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.number, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_number._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.email, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.email, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_email._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.event, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_event._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.messenger, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.messenger, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_messenger._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.address, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.address, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_address._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.url, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.url, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_url._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.nickname, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_nickname._uri, &destRecordHandle);
+ 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(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(__contactHandle, _contacts_contact.relationship, &count);
+ for (i = 0; i < count; i++)
+ {
+ contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.relationship, i, &sourceRecordHandle);
+
+ ret = contacts_record_create(_contacts_relationship._uri, &destRecordHandle);
+ 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(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();
+ }
+
+ contacts_record_destroy(__contactHandle, true);
+ __contactHandle = contactHandle;
+
+ __isRemoved = false;
+
+ recordHandle.Release();
+
+ return E_SUCCESS;
+}
+
+const _ContactImpl*
+_ContactImpl::GetInstance(const Contact& contact)
+{
+ return contact.__pContactImpl;
+}
+
+_ContactImpl*
+_ContactImpl::GetInstance(Contact& contact)
+{
+ return contact.__pContactImpl;
+}
+
+}} // Tizen::Social