[DCM-1245] fix codes for mem leak
[framework/osp/social.git] / src / FScl_UserProfileImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FScl_UserProfileImpl.cpp
19  * @brief               This is the implementation for _UserProfileImpl class.
20  *
21  * This file contains definitions of _UserProfileImpl class.
22  */
23 #include <FBaseString.h>
24 #include <FBaseColArrayList.h>
25 #include <FBaseSysLog.h>
26 #include <FIoFile.h>
27 #include <FMediaImage.h>
28 #include <FSclAddress.h>
29 #include <FSclPhoneNumber.h>
30 #include <FSclEmail.h>
31 #include <FSclUrl.h>
32 #include <FSclImAddress.h>
33 #include <FSclOrganization.h>
34 #include <FSclContactEvent.h>
35 #include <FSclRelationship.h>
36 #include <FSclContact.h>
37 #include <FSclUserProfile.h>
38 #include <FBase_StringConverter.h>
39 #include "FScl_ContactDbConnector.h"
40 #include "FScl_PhoneNumberImpl.h"
41 #include "FScl_AddressbookUtil.h"
42 #include "FScl_UrlImpl.h"
43 #include "FScl_EmailImpl.h"
44 #include "FScl_AddressImpl.h"
45 #include "FScl_ImAddressImpl.h"
46 #include "FScl_UserProfileImpl.h"
47 #include "FScl_OrganizationImpl.h"
48
49 using namespace Tizen::Base;
50 using namespace Tizen::Base::Collection;
51 using namespace Tizen::Graphics;
52 using namespace Tizen::Media;
53 using namespace Tizen::Io;
54
55 namespace Tizen { namespace Social
56 {
57
58 const int __CONTACT_MOD_YEAR = 10000;
59 const int __CONTACT_MOD_MONTH = 100;
60
61 #define __CONVERT_DATE_TO_DATETIME(date, dateTime)              \
62         do                                                      \
63         {                                                       \
64                 int temp = date;                                \
65                 int year = 0;                                   \
66                 int month = 0;                                  \
67                 int day = 0;                                    \
68                 year = temp/__CONTACT_MOD_YEAR;                 \
69                 temp -= year*__CONTACT_MOD_YEAR;                \
70                 month = temp/__CONTACT_MOD_MONTH;               \
71                 day = temp - month*__CONTACT_MOD_MONTH;         \
72                 dateTime.SetValue(year, month, day, 0, 0, 0);   \
73         }while(0)
74
75 _UserProfileImpl::_UserProfileImpl(void)
76         : __profileHandle(null)
77 {
78         contacts_record_h profileHandle = null;
79
80         SysTryReturnVoidResult(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
81
82         int ret = contacts_record_create(_contacts_my_profile._uri, &profileHandle);
83         SysTryReturnVoidResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
84
85         __profileHandle = profileHandle;
86 }
87
88 _UserProfileImpl::_UserProfileImpl(const _UserProfileImpl& rhs)
89         : __profileHandle(null)
90 {
91         contacts_record_h profileHandle = null;
92
93         SysTryReturnVoidResult(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
94
95         int ret = contacts_record_clone(rhs.__profileHandle, &profileHandle);
96         SysTryReturnVoidResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
97
98         __profileHandle = profileHandle;
99 }
100
101 _UserProfileImpl::~_UserProfileImpl(void)
102 {
103         if (__profileHandle != null)
104         {
105                 contacts_record_destroy(__profileHandle, true);
106         }
107 }
108
109 _UserProfileImpl&
110 _UserProfileImpl::operator =(const _UserProfileImpl& rhs)
111 {
112         if (this == &rhs)
113         {
114                 return *this;
115         }
116
117         contacts_record_h profileHandle = null;
118
119         int ret = contacts_record_clone(rhs.__profileHandle, &profileHandle);
120         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
121
122         contacts_record_destroy(__profileHandle, true);
123         __profileHandle = profileHandle;
124
125         //__isRemoved = rhs.__isRemoved;
126
127         return *this;
128 }
129
130 bool
131 _UserProfileImpl::Equals(const Object& rhs) const
132 {
133         const _UserProfileImpl* pRhs = dynamic_cast<const _UserProfileImpl*>(&rhs);
134
135         if (pRhs == null)
136         {
137                 return false;
138         }
139
140         //compare single value properties
141         if (this->GetValue(USER_PROFILE_PROPERTY_ID_FIRST_NAME) != pRhs->GetValue(USER_PROFILE_PROPERTY_ID_FIRST_NAME))
142         {
143                 return false;
144         }
145
146         if (this->GetValue(USER_PROFILE_PROPERTY_ID_LAST_NAME) !=  pRhs->GetValue(USER_PROFILE_PROPERTY_ID_LAST_NAME))
147         {
148                 return false;
149         }
150
151         if (this->GetValue(USER_PROFILE_PROPERTY_ID_MIDDLE_NAME) !=  pRhs->GetValue(USER_PROFILE_PROPERTY_ID_MIDDLE_NAME))
152         {
153                 return false;
154         }
155
156         if (this->GetValue(USER_PROFILE_PROPERTY_ID_NAME_PREFIX) !=  pRhs->GetValue(USER_PROFILE_PROPERTY_ID_NAME_PREFIX))
157         {
158                 return false;
159         }
160
161         if (this->GetValue(USER_PROFILE_PROPERTY_ID_NAME_SUFFIX) !=  pRhs->GetValue(USER_PROFILE_PROPERTY_ID_NAME_SUFFIX))
162         {
163                 return false;
164         }
165
166         if (this->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_FIRST_NAME) !=  pRhs->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_FIRST_NAME))
167         {
168                 return false;
169         }
170
171         if (this->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_LAST_NAME) !=  pRhs->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_LAST_NAME))
172         {
173                 return false;
174         }
175
176         if (this->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_MIDDLE_NAME) !=  pRhs->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_MIDDLE_NAME))
177         {
178                 return false;
179         }
180
181         //compare multivalue properties
182         std::unique_ptr<ArrayList, AllElementsDeleter> pCurrentObjectList(null);
183         std::unique_ptr<ArrayList, AllElementsDeleter> pRhsObjectList(null);
184
185         pCurrentObjectList = std::unique_ptr<ArrayList, AllElementsDeleter> (static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_PHONE_NUMBERS)));
186         pRhsObjectList = std::unique_ptr<ArrayList, AllElementsDeleter> (static_cast<ArrayList*>(pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_PHONE_NUMBERS)));
187
188         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
189         {
190                 return false;
191         }
192
193         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_EMAILS))));
194         pRhsObjectList.reset((static_cast<ArrayList*>(pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_EMAILS))));
195
196         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
197         {
198                 return false;
199         }
200
201         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_URLS))));
202         pRhsObjectList.reset((static_cast<ArrayList*>( pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_URLS))));
203
204         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
205         {
206                 return false;
207         }
208
209         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_ADDRESSES))));
210         pRhsObjectList.reset((static_cast<ArrayList*>( pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_ADDRESSES))));
211
212         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
213         {
214                 return false;
215         }
216
217         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_IMADDRESSES))));
218         pRhsObjectList.reset((static_cast<ArrayList*>( pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_IMADDRESSES))));
219
220         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
221         {
222                 return false;
223         }
224
225         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_EVENTS))));
226         pRhsObjectList.reset((static_cast<ArrayList*>( pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_EVENTS))));
227
228         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
229         {
230                 return false;
231         }
232
233         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_ORGANIZATIONS))));
234         pRhsObjectList.reset((static_cast<ArrayList*>(pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_ORGANIZATIONS))));
235
236         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
237         {
238                 return false;
239         }
240
241         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_NOTES))));
242         pRhsObjectList.reset((static_cast<ArrayList*>( pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_NOTES))));
243
244         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
245         {
246                 return false;
247         }
248
249         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_NICKNAMES))));
250         pRhsObjectList.reset((static_cast<ArrayList*>( pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_NICKNAMES))));
251
252         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
253         {
254                 return false;
255         }
256
257         pCurrentObjectList.reset((static_cast<ArrayList*>(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_RELATIONSHIPS))));
258         pRhsObjectList.reset((static_cast<ArrayList*>( pRhs->GetValuesN(USER_PROFILE_MPROPERTY_ID_RELATIONSHIPS))));
259
260         if (!pCurrentObjectList->Equals(*(pRhsObjectList.get())))
261         {
262                 return false;
263         }
264
265         return true;
266 }
267
268 int
269 _UserProfileImpl::GetHashCode(void) const
270 {
271         int hashCode = 17;
272         std::unique_ptr<IList, AllElementsDeleter> pMultiPropertyList(null);
273
274         //calculate single value properties
275         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetValue(USER_PROFILE_PROPERTY_ID_FIRST_NAME).GetHashCode();
276         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetValue(USER_PROFILE_PROPERTY_ID_LAST_NAME).GetHashCode();
277         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetValue(USER_PROFILE_PROPERTY_ID_MIDDLE_NAME).GetHashCode();
278         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetValue(USER_PROFILE_PROPERTY_ID_NAME_PREFIX).GetHashCode();
279         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetValue(USER_PROFILE_PROPERTY_ID_NAME_SUFFIX).GetHashCode();
280         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_FIRST_NAME).GetHashCode();
281         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_LAST_NAME).GetHashCode();
282         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetValue(USER_PROFILE_PROPERTY_ID_PHONETIC_MIDDLE_NAME).GetHashCode();
283         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ this->GetThumbnailPath().GetHashCode();
284
285         //calculate multi value properties
286         PhoneNumber* pPhoneNumber = null;
287         pMultiPropertyList = std::unique_ptr<IList, AllElementsDeleter> (this->GetValuesN(USER_PROFILE_MPROPERTY_ID_PHONE_NUMBERS));
288         std::unique_ptr<IEnumerator> pEnum(pMultiPropertyList->GetEnumeratorN());
289         while (pEnum->MoveNext() == E_SUCCESS)
290         {
291                 pPhoneNumber = static_cast<PhoneNumber*>(pEnum->GetCurrent());
292                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pPhoneNumber->GetHashCode();
293         }
294
295         Email* pEmail = null;
296         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_EMAILS));
297         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
298         while (pEnum->MoveNext() == E_SUCCESS)
299         {
300                 pEmail = static_cast<Email*>(pEnum->GetCurrent());
301                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pEmail->GetHashCode();
302         }
303
304         Url* pUrl = null;
305         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_URLS));
306         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
307         while (pEnum->MoveNext() == E_SUCCESS)
308         {
309                 pUrl = static_cast<Url*>(pEnum->GetCurrent());
310                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pUrl->GetHashCode();
311         }
312
313         Address* pAddress = null;
314         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_ADDRESSES));
315         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
316         while (pEnum->MoveNext() == E_SUCCESS)
317         {
318                 pAddress = static_cast<Address*>(pEnum->GetCurrent());
319                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pAddress->GetHashCode();
320         }
321
322         ImAddress* pImAddress = null;
323         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_IMADDRESSES));
324         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
325         while (pEnum->MoveNext() == E_SUCCESS)
326         {
327                 pImAddress = static_cast<ImAddress*>(pEnum->GetCurrent());
328                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pImAddress->GetHashCode();
329         }
330
331         ContactEvent* pEvent = null;
332         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_EVENTS));
333         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
334         while (pEnum->MoveNext() == E_SUCCESS)
335         {
336                 pEvent = static_cast<ContactEvent*>(pEnum->GetCurrent());
337                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pEvent->GetHashCode();
338         }
339
340         Organization* pOrganization = null;
341         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_ORGANIZATIONS));
342         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
343         while (pEnum->MoveNext() == E_SUCCESS)
344         {
345                 pOrganization = static_cast<Organization*>(pEnum->GetCurrent());
346                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pOrganization->GetHashCode();
347         }
348
349         String* pNote = null;
350         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_NOTES));
351         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
352         while (pEnum->MoveNext() == E_SUCCESS)
353         {
354                 pNote = static_cast<String*>(pEnum->GetCurrent());
355                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pNote->GetHashCode();
356         }
357
358         String* pNickname = null;
359         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_NICKNAMES));
360         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
361         while (pEnum->MoveNext() == E_SUCCESS)
362         {
363                 pNickname = static_cast<String*>(pEnum->GetCurrent());
364                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pNickname->GetHashCode();
365         }
366
367         Relationship* pRelationship = null;
368         pMultiPropertyList.reset(this->GetValuesN(USER_PROFILE_MPROPERTY_ID_RELATIONSHIPS));
369         pEnum.reset(pMultiPropertyList->GetEnumeratorN());
370         while (pEnum->MoveNext() == E_SUCCESS)
371         {
372                 pRelationship = static_cast<Relationship*>(pEnum->GetCurrent());
373                 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ pRelationship->GetHashCode();
374         }
375
376         return hashCode;
377 }
378
379 String
380 _UserProfileImpl::GetThumbnailPath(void) const
381 {
382         unsigned int count = 0;
383
384         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.image, &count);
385         if (count == 0)
386         {
387                 return String(L"");
388         }
389
390         char* pCharValue = null;
391         contacts_record_h imageHandle = null;
392
393         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.image, 0, &imageHandle);
394         contacts_record_get_str_p(imageHandle, _contacts_image.path, &pCharValue);
395
396         return String(pCharValue);
397 }
398
399 result
400 _UserProfileImpl::SetThumbnail(const String& filePath)
401 {
402         unsigned int count = 0;
403         contacts_record_h imageHandle = null;
404         int errCode = 0;
405         bool fileExist = true;
406
407         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.image, &count);
408         if (count > 0)
409         {
410                 errCode = contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.image, 0, &imageHandle);
411                 SysTryReturn(NID_SCL, errCode != CONTACTS_ERROR_INVALID_PARAMETER, E_SYSTEM, E_SYSTEM,
412                                                         "[%s] An Invalid Paramenter has been passed", GetErrorMessage(E_SYSTEM));
413
414                 if (!filePath.IsEmpty())
415                 {
416                         fileExist = File::IsFileExist(filePath);
417                         SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG,
418                                         "[%s] Invalid file path.", GetErrorMessage(E_INVALID_ARG));
419                         SysTryReturn(NID_SCL, fileExist != false, E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
420                                         "[%s] The specified file is not found.", GetErrorMessage(E_FILE_NOT_FOUND));
421
422                         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(filePath));
423                         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
424
425                         errCode = contacts_record_set_str(imageHandle, _contacts_image.path, pCharArray.get());
426                         SysTryReturn(NID_SCL, errCode != CONTACTS_ERROR_INVALID_PARAMETER, E_SYSTEM, E_SYSTEM,
427                                         "[%s] An Invalid Paramenter has been passed", GetErrorMessage(E_SYSTEM));
428                 }
429                 else
430                 {
431                         errCode = contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.image, imageHandle);
432                         contacts_record_destroy(imageHandle, true);
433                         SysTryReturn(NID_SCL, errCode != CONTACTS_ERROR_INVALID_PARAMETER, E_SYSTEM, E_SYSTEM,
434                                                                 "[%s] An Invalid Paramenter has been passed", GetErrorMessage(E_SYSTEM));
435                 }
436         }
437         else
438         {
439                 if (!filePath.IsEmpty())
440                 {
441                         fileExist = File::IsFileExist(filePath);
442                         SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG,
443                                         "[%s] Invalid file path.", GetErrorMessage(E_INVALID_ARG));
444                         SysTryReturn(NID_SCL, fileExist != false, E_FILE_NOT_FOUND, E_FILE_NOT_FOUND,
445                                         "[%s] The specified file is not found.", GetErrorMessage(E_FILE_NOT_FOUND));
446
447                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(filePath));
448                         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
449
450                         errCode = contacts_record_create(_contacts_image._uri, &imageHandle);
451                         SysTryReturn(NID_SCL, errCode != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
452                                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
453
454                         errCode = contacts_record_set_str(imageHandle, _contacts_image.path, pCharArray.get());
455                         SysTryReturn(NID_SCL, errCode != CONTACTS_ERROR_INVALID_PARAMETER, E_SYSTEM, E_SYSTEM,
456                                         "[%s] An Invalid Paramenter has been passed", GetErrorMessage(E_SYSTEM));
457
458                         errCode = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.image, imageHandle);
459                         SysTryReturn(NID_SCL, errCode != CONTACTS_ERROR_INVALID_PARAMETER, E_SYSTEM, E_SYSTEM,
460                                         "[%s] An Invalid Paramenter has been passed", GetErrorMessage(E_SYSTEM));
461                 }
462         }
463
464         return E_SUCCESS;
465
466 }
467
468 result
469 _UserProfileImpl::SetValue(UserProfilePropertyId id, const String& value)
470 {
471         SysTryReturn(NID_SCL, id != USER_PROFILE_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));
472
473         int ret = CONTACTS_ERROR_NONE;
474         unsigned int count = 0;
475
476         switch (id)
477         {
478         case USER_PROFILE_PROPERTY_ID_FIRST_NAME:
479                 {
480                         contacts_record_h nameHandle = null;
481                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
482
483                         if (count > 0)
484                         {
485                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
486
487                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
488                                 contacts_record_set_str(nameHandle, _contacts_name.first, pCharArray.get());
489
490                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
491                                 {
492                                         contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
493                                         contacts_record_destroy(nameHandle, true);
494                                 }
495                         }
496                         else
497                         {
498                                 if (!value.IsEmpty())
499                                 {
500                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
501                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
502
503                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
504                                         contacts_record_set_str(nameHandle, _contacts_name.first, pCharArray.get());
505
506                                         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
507                                 }
508                         }
509                 }
510                 break;
511
512         case USER_PROFILE_PROPERTY_ID_MIDDLE_NAME:
513                 {
514                         contacts_record_h nameHandle = null;
515                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
516
517                         if (count > 0)
518                         {
519                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
520
521                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
522                                 ret = contacts_record_set_str(nameHandle, _contacts_name.addition, pCharArray.get());
523
524                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
525                                 {
526                                         contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
527                                         contacts_record_destroy(nameHandle, true);
528                                 }
529                         }
530                         else
531                         {
532                                 if (!value.IsEmpty())
533                                 {
534                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
535                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
536
537                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
538                                         contacts_record_set_str(nameHandle, _contacts_name.addition, pCharArray.get());
539
540                                         contacts_record_add_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
541                                 }
542                         }
543
544                 }
545
546                 break;
547
548         case USER_PROFILE_PROPERTY_ID_LAST_NAME:
549                 {
550                         contacts_record_h nameHandle = null;
551                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
552
553                         if (count > 0)
554                         {
555                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
556
557                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
558                                 contacts_record_set_str(nameHandle, _contacts_name.last, pCharArray.get());
559
560                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
561                                 {
562                                         contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
563                                         contacts_record_destroy(nameHandle, true);
564                                 }
565                         }
566                         else
567                         {
568                                 if (!value.IsEmpty())
569                                 {
570                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
571                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
572
573                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
574                                         contacts_record_set_str(nameHandle, _contacts_name.last, pCharArray.get());
575
576                                         contacts_record_add_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
577                                 }
578                         }
579
580                 }
581
582                 break;
583         case USER_PROFILE_PROPERTY_ID_NAME_SUFFIX:
584                 {
585                         contacts_record_h nameHandle = null;
586                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
587
588                         if (count > 0)
589                         {
590                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
591
592                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
593                                 contacts_record_set_str(nameHandle, _contacts_name.suffix, pCharArray.get());
594
595                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
596                                 {
597                                         contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
598                                         contacts_record_destroy(nameHandle, true);
599                                 }
600
601                         }
602                         else
603                         {
604                                 if (!value.IsEmpty())
605                                 {
606                                         contacts_record_create(_contacts_name._uri, &nameHandle);
607                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
608
609                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
610                                         contacts_record_set_str(nameHandle, _contacts_name.suffix, pCharArray.get());
611
612                                         contacts_record_add_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
613                                 }
614                         }
615
616                 }
617
618                 break;
619
620         case USER_PROFILE_PROPERTY_ID_NAME_PREFIX:
621                 {
622                         contacts_record_h nameHandle = null;
623                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
624
625                         if (count > 0)
626                         {
627                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
628
629                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
630                                 contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
631
632                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
633                                 {
634                                         contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
635                                         contacts_record_destroy(nameHandle, true);
636                                 }
637                         }
638                         else
639                         {
640                                 if (!value.IsEmpty())
641                                 {
642                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
643                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
644
645                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
646                                         contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
647
648                                         contacts_record_add_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
649                                 }
650                         }
651
652                 }
653
654                 break;
655
656         case USER_PROFILE_PROPERTY_ID_PHONETIC_FIRST_NAME:
657                 {
658                         contacts_record_h nameHandle = null;
659                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
660
661                         if (count > 0)
662                         {
663                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
664
665                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
666                                 contacts_record_set_str(nameHandle, _contacts_name.phonetic_first, pCharArray.get());
667
668                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
669                                 {
670                                         contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
671                                         contacts_record_destroy(nameHandle, true);
672                                 }
673                         }
674                         else
675                         {
676                                 if (!value.IsEmpty())
677                                 {
678                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
679                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
680
681                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
682                                         contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
683
684                                         contacts_record_add_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
685                                 }
686                         }
687
688                 }
689
690                 break;
691
692         case USER_PROFILE_PROPERTY_ID_PHONETIC_LAST_NAME:
693                 {
694                         contacts_record_h nameHandle = null;
695                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
696
697                         if (count > 0)
698                         {
699                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
700
701                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
702                                 contacts_record_set_str(nameHandle, _contacts_name.phonetic_last, pCharArray.get());
703
704                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
705                                 {
706                                         contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
707                                         contacts_record_destroy(nameHandle, true);
708                                 }
709                         }
710                         else
711                         {
712                                 if (!value.IsEmpty())
713                                 {
714                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
715                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
716
717                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
718                                         contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
719
720                                         contacts_record_add_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
721                                 }
722                         }
723
724                 }
725
726                 break;
727
728         case USER_PROFILE_PROPERTY_ID_PHONETIC_MIDDLE_NAME:
729                 {
730                         contacts_record_h nameHandle = null;
731                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
732
733                         if (count > 0)
734                         {
735                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
736
737                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
738                                 contacts_record_set_str(nameHandle, _contacts_name.phonetic_middle, pCharArray.get());
739
740                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
741                                 {
742                                         contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
743                                         contacts_record_destroy(nameHandle, true);
744                                 }
745                         }
746                         else
747                         {
748                                 if (!value.IsEmpty())
749                                 {
750                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
751                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
752
753                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
754                                         contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
755
756                                         contacts_record_add_child_record(__profileHandle, _contacts_my_profile.name, nameHandle);
757                                 }
758                         }
759
760                 }
761
762                 break;
763
764         default:
765                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
766                 return E_INVALID_ARG;
767         }
768
769         return E_SUCCESS;
770 }
771
772 String
773 _UserProfileImpl::GetValue(UserProfilePropertyId id) const
774 {
775         unsigned int count = 0;
776         char* pCharValue = null;
777         String value = "";
778
779         switch (id)
780         {
781         case USER_PROFILE_PROPERTY_ID_FIRST_NAME:
782                 {
783                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
784                         if (count > 0)
785                         {
786                                 contacts_record_h nameHandle = null;
787
788                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
789                                 contacts_record_get_str_p(nameHandle, _contacts_name.first, &pCharValue);
790                         }
791
792                         value = pCharValue;
793                 }
794                 break;
795         case USER_PROFILE_PROPERTY_ID_LAST_NAME:
796                 {
797                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
798                         if (count > 0)
799                         {
800                                 contacts_record_h nameHandle = null;
801
802                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
803                                 contacts_record_get_str_p(nameHandle, _contacts_name.last, &pCharValue);
804                         }
805
806                         value = pCharValue;
807                 }
808                 break;
809         case USER_PROFILE_PROPERTY_ID_MIDDLE_NAME:
810                 {
811                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
812                         if (count > 0)
813                         {
814                                 contacts_record_h nameHandle = null;
815
816                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
817                                 contacts_record_get_str_p(nameHandle, _contacts_name.addition, &pCharValue);
818                         }
819
820                         value = pCharValue;
821                 }
822                 break;
823         case USER_PROFILE_PROPERTY_ID_NAME_PREFIX:
824                 {
825                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
826                         if (count > 0)
827                         {
828                                 contacts_record_h nameHandle = null;
829
830                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
831                                 contacts_record_get_str_p(nameHandle, _contacts_name.prefix, &pCharValue);
832                         }
833
834                         value = pCharValue;
835                 }
836                 break;
837         case USER_PROFILE_PROPERTY_ID_NAME_SUFFIX:
838                 {
839                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
840                         if (count > 0)
841                         {
842                                 contacts_record_h nameHandle = null;
843
844                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
845                                 contacts_record_get_str_p(nameHandle, _contacts_name.suffix, &pCharValue);
846                         }
847
848                         value = pCharValue;
849                 }
850                 break;
851         case USER_PROFILE_PROPERTY_ID_DISPLAY_NAME:
852                         contacts_record_get_str_p(__profileHandle, _contacts_my_profile.display_name, &pCharValue);
853                         value = pCharValue;
854                 break;
855         case USER_PROFILE_PROPERTY_ID_PHONETIC_FIRST_NAME:
856                 {
857                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
858                         if (count > 0)
859                         {
860                                 contacts_record_h nameHandle = null;
861
862                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
863                                 contacts_record_get_str_p(nameHandle, _contacts_name.phonetic_first, &pCharValue);
864                         }
865
866                         value = pCharValue;
867                 }
868                 break;
869         case USER_PROFILE_PROPERTY_ID_PHONETIC_LAST_NAME:
870                 {
871                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
872                         if (count > 0)
873                         {
874                                 contacts_record_h nameHandle = null;
875
876                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
877                                 contacts_record_get_str_p(nameHandle, _contacts_name.phonetic_last, &pCharValue);
878                         }
879
880                         value = pCharValue;
881                 }
882                 break;
883         case USER_PROFILE_PROPERTY_ID_PHONETIC_MIDDLE_NAME:
884                 {
885                         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
886                         if (count > 0)
887                         {
888                                 contacts_record_h nameHandle = null;
889
890                                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.name, 0, &nameHandle);
891                                 contacts_record_get_str_p(nameHandle, _contacts_name.phonetic_middle, &pCharValue);
892                         }
893
894                         value = pCharValue;
895                 }
896                 break;
897         default:
898                 value = String(L"");
899                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d", GetErrorMessage(E_INVALID_ARG), id);
900                 return value;
901         }
902
903         return value;
904 }
905
906 result
907 _UserProfileImpl::SetPhoneNumberAt(int index, const PhoneNumber& phoneNumber)
908 {
909         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);
910         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));
911
912         unsigned int count = 0;
913         contacts_record_h recordHandle = null;
914         String stringValue;
915         int type = 0;
916         int oriType = 0;
917
918         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.number, &count);
919         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);
920
921         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.number, index, &recordHandle);
922
923         stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetLabel();
924
925         switch (_PhoneNumberImpl::GetInstance(phoneNumber)->GetType())
926         {
927                 case PHONENUMBER_TYPE_HOME:
928                         type = CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE;
929                         break;
930                 case PHONENUMBER_TYPE_WORK:
931                         type = CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE;
932                         break;
933                 case PHONENUMBER_TYPE_MOBILE:
934                         type = CONTACTS_NUMBER_TYPE_CELL;
935                         break;
936                 case PHONENUMBER_TYPE_HOME_FAX:
937                         type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME;
938                         break;
939                 case PHONENUMBER_TYPE_WORK_FAX:
940                         type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK;
941                         break;
942                 case PHONENUMBER_TYPE_PAGER:
943                         type = CONTACTS_NUMBER_TYPE_PAGER;
944                         break;
945                 case PHONENUMBER_TYPE_CUSTOM:
946                         type = CONTACTS_NUMBER_TYPE_CUSTOM;
947                         break;
948                 case PHONENUMBER_TYPE_ASSISTANT:
949                         type = CONTACTS_NUMBER_TYPE_ASSISTANT;
950                         break;
951                 case PHONENUMBER_TYPE_OTHER:
952                         contacts_record_get_int(recordHandle, _contacts_number.type, &oriType);
953
954                         if (oriType == (CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE)
955                                 || oriType == (CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE)
956                                 || oriType == CONTACTS_NUMBER_TYPE_CELL
957                                 || oriType == (CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME)
958                                 || oriType == (CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK)
959                                 || oriType == CONTACTS_NUMBER_TYPE_PAGER
960                                 || oriType == CONTACTS_NUMBER_TYPE_CUSTOM)
961                         {
962                                 type = CONTACTS_NUMBER_TYPE_OTHER;
963                         }
964                         else
965                         {
966                                 type = oriType;
967                         }
968                         break;
969                 default:
970                         type = CONTACTS_NUMBER_TYPE_OTHER;
971                         break;
972         }
973
974         // set type
975         contacts_record_set_int(recordHandle, _contacts_number.type, type);
976
977         // set label
978         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
979         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
980
981         contacts_record_set_str(recordHandle, _contacts_number.label, pCharArray.get());
982
983         // set phone number
984         stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetPhoneNumber();
985         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
986         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
987
988         contacts_record_set_str(recordHandle, _contacts_number.number, pCharArray.get());
989
990         return E_SUCCESS;
991
992 }
993
994 result
995 _UserProfileImpl::SetEmailAt(int index, const Email& email)
996 {
997         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);
998         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));
999
1000         unsigned int count = 0;
1001         contacts_record_h emailHandle = null;
1002         String stringValue;
1003         int type = 0;
1004
1005         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.email, &count);
1006         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);
1007
1008         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.email, index, &emailHandle);
1009
1010         stringValue = _EmailImpl::GetInstance(email)->GetLabel();
1011
1012         switch (_EmailImpl::GetInstance(email)->GetType())
1013         {
1014                 case EMAIL_TYPE_PERSONAL:
1015                         type = CONTACTS_EMAIL_TYPE_HOME;
1016                         break;
1017                 case EMAIL_TYPE_WORK:
1018                         type = CONTACTS_EMAIL_TYPE_WORK;
1019                         break;
1020                 case EMAIL_TYPE_CUSTOM:
1021                         type = CONTACTS_EMAIL_TYPE_CUSTOM;
1022                         break;
1023                 case EMAIL_TYPE_MOBILE:
1024                         type = CONTACTS_EMAIL_TYPE_MOBILE;
1025                         break;
1026                 case EMAIL_TYPE_OTHER:
1027                         //fallthrough
1028                 default:
1029                         type = CONTACTS_EMAIL_TYPE_OTHER;
1030                         break;
1031         }
1032
1033         // set type
1034         contacts_record_set_int(emailHandle, _contacts_email.type, type);
1035
1036         // set label
1037         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1038         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1039
1040         contacts_record_set_str(emailHandle, _contacts_email.label, pCharArray.get());
1041
1042         // set email
1043         stringValue = _EmailImpl::GetInstance(email)->GetEmail();
1044         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1045         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1046
1047         contacts_record_set_str(emailHandle, _contacts_email.email, pCharArray.get());
1048
1049         return E_SUCCESS;
1050 }
1051
1052 result
1053 _UserProfileImpl::SetUrlAt(int index, const Url& url)
1054 {
1055         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);
1056         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));
1057         //SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1058
1059         unsigned int count = 0;
1060         contacts_record_h urlHandle = null;
1061         String stringValue;
1062         int type = 0;
1063
1064         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.url, &count);
1065         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);
1066
1067         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.url, index, &urlHandle);
1068
1069
1070         stringValue = _UrlImpl::GetInstance(url)->GetLabel();
1071
1072         switch (_UrlImpl::GetInstance(url)->GetType())
1073         {
1074                 case URL_TYPE_PERSONAL:
1075                         type = CONTACTS_URL_TYPE_HOME;
1076                         break;
1077                 case URL_TYPE_WORK:
1078                         type = CONTACTS_URL_TYPE_WORK;
1079                         break;
1080                 case URL_TYPE_CUSTOM:
1081                         type = CONTACTS_URL_TYPE_CUSTOM;
1082                         break;
1083                 case URL_TYPE_OTHER:
1084                         //fallthrough
1085                 default:
1086                         type = CONTACTS_URL_TYPE_OTHER;
1087                         break;
1088         }
1089
1090         // set type
1091         contacts_record_set_int(urlHandle, _contacts_url.type, type);
1092
1093         // set label
1094         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1095         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1096
1097         contacts_record_set_str(urlHandle, _contacts_url.label, pCharArray.get());
1098
1099         // set url
1100         stringValue = _UrlImpl::GetInstance(url)->GetUrl();
1101         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1102         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1103
1104         contacts_record_set_str(urlHandle, _contacts_url.url, pCharArray.get());
1105
1106         return E_SUCCESS;
1107
1108 }
1109
1110 result
1111 _UserProfileImpl::SetAddressAt(int index, const Address& address)
1112 {
1113         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);
1114         SysTryReturn(NID_SCL,
1115                                           !address.GetCity().IsEmpty() ||
1116                                           !address.GetCountry().IsEmpty() ||
1117                                           !address.GetExtended().IsEmpty() ||
1118                                           !address.GetPostalCode().IsEmpty() ||
1119                                           !address.GetPostOfficeBoxNumber().IsEmpty() ||
1120                                           !address.GetState().IsEmpty() ||
1121                                           !address.GetStreet().IsEmpty(),
1122                                           E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The address is empty.", GetErrorMessage(E_INVALID_ARG));
1123
1124         unsigned int count = 0;
1125         contacts_record_h addressHandle = null;
1126         int type = 0;
1127         String stringValue;
1128
1129         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.address, &count);
1130         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);
1131
1132         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.address, index, &addressHandle);
1133
1134         stringValue = _AddressImpl::GetInstance(address)->GetLabel();
1135
1136         switch (_AddressImpl::GetInstance(address)->GetType())
1137         {
1138                 case ADDRESS_TYPE_HOME:
1139                         type = CONTACTS_ADDRESS_TYPE_HOME;
1140                         break;
1141                 case ADDRESS_TYPE_WORK:
1142                         type = CONTACTS_ADDRESS_TYPE_WORK;
1143                         break;
1144                 case ADDRESS_TYPE_CUSTOM:
1145                         type = CONTACTS_ADDRESS_TYPE_CUSTOM;
1146                         break;
1147                 case ADDRESS_TYPE_OTHER:
1148                         //fallthrough
1149                 default:
1150                         type = CONTACTS_ADDRESS_TYPE_OTHER;
1151                         break;
1152         }
1153
1154         // set type
1155         contacts_record_set_int(addressHandle, _contacts_address.type, type);
1156
1157         // set label
1158         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1159         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1160
1161         contacts_record_set_str(addressHandle, _contacts_address.label, pCharArray.get());
1162
1163         // address
1164         stringValue = _AddressImpl::GetInstance(address)->GetCity();
1165         if (!stringValue.IsEmpty())
1166         {
1167                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1168                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1169
1170                 contacts_record_set_str(addressHandle, _contacts_address.locality, pCharArray.get());
1171         }
1172         else
1173         {
1174                 contacts_record_set_str(addressHandle, _contacts_address.locality, null);
1175         }
1176
1177         stringValue = _AddressImpl::GetInstance(address)->GetCountry();
1178         if (!stringValue.IsEmpty())
1179         {
1180                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1181                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1182
1183                 contacts_record_set_str(addressHandle, _contacts_address.country, pCharArray.get());
1184         }
1185         else
1186         {
1187                 contacts_record_set_str(addressHandle, _contacts_address.country, null);
1188         }
1189
1190         stringValue = _AddressImpl::GetInstance(address)->GetExtended();
1191         if (!stringValue.IsEmpty())
1192         {
1193                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1194                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1195
1196                 contacts_record_set_str(addressHandle, _contacts_address.extended, pCharArray.get());
1197         }
1198         else
1199         {
1200                 contacts_record_set_str(addressHandle, _contacts_address.extended, null);
1201         }
1202
1203         stringValue = _AddressImpl::GetInstance(address)->GetPostalCode();
1204         if (!stringValue.IsEmpty())
1205         {
1206                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1207                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1208
1209                 contacts_record_set_str(addressHandle, _contacts_address.postal_code, pCharArray.get());
1210         }
1211         else
1212         {
1213                 contacts_record_set_str(addressHandle, _contacts_address.postal_code, null);
1214         }
1215
1216         stringValue = _AddressImpl::GetInstance(address)->GetPostOfficeBoxNumber();
1217         if (!stringValue.IsEmpty())
1218         {
1219                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1220                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1221
1222                 contacts_record_set_str(addressHandle, _contacts_address.postbox, pCharArray.get());
1223         }
1224         else
1225         {
1226                 contacts_record_set_str(addressHandle, _contacts_address.postbox, null);
1227         }
1228
1229         stringValue = _AddressImpl::GetInstance(address)->GetState();
1230         if (!stringValue.IsEmpty())
1231         {
1232                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1233                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1234
1235                 contacts_record_set_str(addressHandle, _contacts_address.region, pCharArray.get());
1236         }
1237         else
1238         {
1239                 contacts_record_set_str(addressHandle, _contacts_address.region, null);
1240         }
1241
1242         stringValue = _AddressImpl::GetInstance(address)->GetStreet();
1243         if (!stringValue.IsEmpty())
1244         {
1245                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1246                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1247
1248                 contacts_record_set_str(addressHandle, _contacts_address.street, pCharArray.get());
1249         }
1250         else
1251         {
1252                 contacts_record_set_str(addressHandle, _contacts_address.street, null);
1253         }
1254
1255         return E_SUCCESS;
1256 }
1257
1258 result
1259 _UserProfileImpl::SetImAddressAt(int index, const ImAddress& imAddress)
1260 {
1261         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);
1262         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));
1263         //SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1264
1265         unsigned int count = 0;
1266         contacts_record_h messengerHandle = null;
1267         String stringValue;
1268         int type = 0;
1269         std::unique_ptr<char[]> pCharArray(null);
1270
1271         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.messenger, &count);
1272         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);
1273
1274         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.messenger, index, &messengerHandle);
1275
1276         stringValue = _ImAddressImpl::GetInstance(imAddress)->GetServiceProviderName();
1277
1278         if (stringValue == IM_ADDRESS_GOOGLE_TALK)
1279         {
1280                 type = CONTACTS_MESSENGER_TYPE_GOOGLE;
1281         }
1282         else if (stringValue == IM_ADDRESS_MSN)
1283         {
1284                 type = CONTACTS_MESSENGER_TYPE_WLM;
1285         }
1286         else if (stringValue == IM_ADDRESS_ICQ)
1287         {
1288                 type = CONTACTS_MESSENGER_TYPE_ICQ;
1289         }
1290         else if (stringValue == IM_ADDRESS_AIM)
1291         {
1292                 type = CONTACTS_MESSENGER_TYPE_AIM;
1293         }
1294         else if (stringValue == IM_ADDRESS_YAHOO)
1295         {
1296                 type = CONTACTS_MESSENGER_TYPE_YAHOO;
1297         }
1298         else if (stringValue == IM_ADDRESS_QQ)
1299         {
1300                 type = CONTACTS_MESSENGER_TYPE_QQ;
1301         }
1302         else if (stringValue == IM_ADDRESS_SKYPE)
1303         {
1304                 type = CONTACTS_MESSENGER_TYPE_SKYPE;
1305         }
1306         else if (stringValue == IM_ADDRESS_JABBER)
1307         {
1308                 type = CONTACTS_MESSENGER_TYPE_JABBER;
1309         }
1310         else
1311         {
1312                 type = CONTACTS_MESSENGER_TYPE_CUSTOM;
1313         }
1314
1315         contacts_record_set_int(messengerHandle, _contacts_messenger.type, type);
1316         if (type == CONTACTS_MESSENGER_TYPE_CUSTOM)
1317         {
1318                 pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1319                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1320
1321                 contacts_record_set_str(messengerHandle, _contacts_messenger.label, pCharArray.get());
1322         }
1323
1324         stringValue = _ImAddressImpl::GetInstance(imAddress)->GetImAddress();
1325         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1326         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1327
1328         contacts_record_set_str(messengerHandle, _contacts_messenger.im_id, pCharArray.get());
1329
1330         return E_SUCCESS;
1331
1332 }
1333
1334 result
1335 _UserProfileImpl::SetNoteAt(int index, const String& note)
1336 {
1337         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);
1338         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));
1339         //SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1340
1341         unsigned int count = 0;
1342         contacts_record_h noteHandle = null;
1343
1344         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.note, &count);
1345         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);
1346
1347         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.note, index, &noteHandle);
1348
1349         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(note));
1350         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1351
1352         contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
1353
1354         return E_SUCCESS;
1355 }
1356
1357 result
1358 _UserProfileImpl::SetNicknameAt(int index, const String& nickname)
1359 {
1360         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);
1361         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));
1362         //SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1363
1364         unsigned int count = 0;
1365         contacts_record_h nicknameHandle = null;
1366
1367         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.nickname, &count);
1368         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);
1369
1370         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.nickname, index, &nicknameHandle);
1371
1372         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(nickname));
1373         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1374
1375         contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
1376
1377         return E_SUCCESS;
1378 }
1379
1380 result
1381 _UserProfileImpl::SetEventAt(int index, const ContactEvent& event)
1382 {
1383         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);
1384         //SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1385
1386         int type = 0;
1387         int intValue = 0;
1388         unsigned int count = 0;
1389         String stringValue;
1390         contacts_record_h eventHandle = null;
1391
1392         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.event, &count);
1393         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);
1394
1395         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.event, index, &eventHandle);
1396
1397         switch (event.GetType())
1398         {
1399                 case CONTACT_EVENT_TYPE_ANNIVERSARY:
1400                         type = CONTACTS_EVENT_TYPE_ANNIVERSARY;
1401                         break;
1402                 case CONTACT_EVENT_TYPE_BIRTHDAY:
1403                         type = CONTACTS_EVENT_TYPE_BIRTH;
1404                         break;
1405                 case CONTACT_EVENT_TYPE_CUSTOM:
1406                         type = CONTACTS_EVENT_TYPE_CUSTOM;
1407                         break;
1408                 case CONTACT_EVENT_TYPE_OTHER:
1409                         // fall through
1410                 default:
1411                         type = CONTACTS_EVENT_TYPE_OTHER;
1412                         break;
1413         }
1414
1415         // type
1416         contacts_record_set_int(eventHandle, _contacts_event.type, type);
1417
1418         // label
1419         stringValue = event.GetLabel();
1420
1421         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1422         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1423
1424         contacts_record_set_str(eventHandle, _contacts_event.label, pCharArray.get());
1425
1426         // date
1427         DateTime dateValue = event.GetDate();
1428         intValue = dateValue.GetYear()*10000 + dateValue.GetMonth()*100 + dateValue.GetDay();
1429         contacts_record_set_int(eventHandle, _contacts_event.date, intValue);
1430
1431         return E_SUCCESS;
1432 }
1433
1434
1435 result
1436 _UserProfileImpl::SetOrganizationAt(int index, const Organization& organization)
1437 {
1438         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);
1439         SysTryReturn(NID_SCL
1440                                           ,     !organization.GetName().IsEmpty() ||
1441                                                 !organization.GetJobTitle().IsEmpty() ||
1442                                                 !organization.GetDepartment().IsEmpty() ||
1443                                                 !organization.GetRole().IsEmpty() ||
1444                                                 !organization.GetAgent().IsEmpty() ||
1445                                                 !organization.GetLocation().IsEmpty() ||
1446                                                 !organization.GetDescription().IsEmpty() ||
1447                                                 !organization.GetPhoneticName().IsEmpty() ||
1448                                                 !organization.GetLogoPath().IsEmpty()
1449                                           ,E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The organization is empty.", GetErrorMessage(E_INVALID_ARG));
1450
1451         unsigned int count = 0;
1452         contacts_record_h organizationHandle = null;
1453
1454         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.company, &count);
1455         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);
1456
1457
1458         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.company, index, &organizationHandle);
1459
1460         // name
1461         String stringValue = organization.GetName();
1462         if (!stringValue.IsEmpty())
1463         {
1464                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1465                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1466
1467                 contacts_record_set_str(organizationHandle, _contacts_company.name, pCharArray.get());
1468         }
1469         else
1470         {
1471                 contacts_record_set_str(organizationHandle, _contacts_company.name, null);
1472         }
1473
1474         // job title
1475         stringValue = organization.GetJobTitle();
1476         if (!stringValue.IsEmpty())
1477         {
1478                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1479                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1480
1481                 contacts_record_set_str(organizationHandle, _contacts_company.job_title, pCharArray.get());
1482         }
1483         else
1484         {
1485                 contacts_record_set_str(organizationHandle, _contacts_company.job_title, null);
1486         }
1487
1488         // department
1489         stringValue = organization.GetDepartment();
1490         if (!stringValue.IsEmpty())
1491         {
1492                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1493                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1494
1495                 contacts_record_set_str(organizationHandle, _contacts_company.department, pCharArray.get());
1496         }
1497         else
1498         {
1499                 contacts_record_set_str(organizationHandle, _contacts_company.department, null);
1500         }
1501
1502         // role
1503         stringValue = organization.GetRole();
1504         if (!stringValue.IsEmpty())
1505         {
1506                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1507                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1508
1509                 contacts_record_set_str(organizationHandle, _contacts_company.role, pCharArray.get());
1510         }
1511         else
1512         {
1513                 contacts_record_set_str(organizationHandle, _contacts_company.role, null);
1514         }
1515
1516         // agent
1517         stringValue = organization.GetAgent();
1518         if (!stringValue.IsEmpty())
1519         {
1520                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1521                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1522
1523                 contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, pCharArray.get());
1524         }
1525         else
1526         {
1527                 contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, null);
1528         }
1529
1530         // type
1531         int type = 0;
1532
1533         switch (organization.GetType())
1534         {
1535                 case ORGANIZATION_TYPE_WORK:
1536                         type = CONTACTS_COMPANY_TYPE_WORK;
1537                         break;
1538                 case ORGANIZATION_TYPE_CUSTOM:
1539                         type = CONTACTS_COMPANY_TYPE_CUSTOM;
1540                         break;
1541                 case ORGANIZATION_TYPE_OTHER:
1542                         // fall through
1543                 default:
1544                         type = CONTACTS_COMPANY_TYPE_OTHER;
1545                         break;
1546         }
1547         contacts_record_set_int(organizationHandle, _contacts_company.type, type);
1548
1549         // label
1550         stringValue = organization.GetLabel();
1551         if (!stringValue.IsEmpty())
1552         {
1553                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1554                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1555
1556                 contacts_record_set_str(organizationHandle, _contacts_company.label, pCharArray.get());
1557         }
1558         else
1559         {
1560                 contacts_record_set_str(organizationHandle, _contacts_company.label, null);
1561         }
1562
1563         // location
1564         stringValue = organization.GetLocation();
1565         if (!stringValue.IsEmpty())
1566         {
1567                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1568                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1569
1570                 contacts_record_set_str(organizationHandle, _contacts_company.location, pCharArray.get());
1571         }
1572         else
1573         {
1574                 contacts_record_set_str(organizationHandle, _contacts_company.location, null);
1575         }
1576
1577         // description
1578         stringValue = organization.GetDescription();
1579         if (!stringValue.IsEmpty())
1580         {
1581                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1582                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1583
1584                 contacts_record_set_str(organizationHandle, _contacts_company.description, pCharArray.get());
1585         }
1586         else
1587         {
1588                 contacts_record_set_str(organizationHandle, _contacts_company.description, null);
1589         }
1590
1591         // phonetic name
1592         stringValue = organization.GetPhoneticName();
1593         if (!stringValue.IsEmpty())
1594         {
1595                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1596                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1597
1598                 contacts_record_set_str(organizationHandle, _contacts_company.phonetic_name, pCharArray.get());
1599         }
1600         else
1601         {
1602                 contacts_record_set_str(organizationHandle, _contacts_company.phonetic_name, null);
1603         }
1604
1605         // logo path
1606         if (_OrganizationImpl::GetInstance(organization)->IsLogoPathChanged() == true)
1607         {
1608                 stringValue = organization.GetLogoPath();
1609                 if (!stringValue.IsEmpty())
1610                 {
1611                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1612                         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1613
1614                         contacts_record_set_str(organizationHandle, _contacts_company.logo, pCharArray.get());
1615                 }
1616                 else
1617                 {
1618                         contacts_record_set_str(organizationHandle, _contacts_company.logo, null);
1619                 }
1620         }
1621
1622         return E_SUCCESS;
1623 }
1624
1625 result
1626 _UserProfileImpl::SetRelationshipAt(int index, const Relationship& relationship)
1627 {
1628         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);
1629         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));
1630         //SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1631
1632         int intValue = 0;
1633         unsigned int count = 0;
1634         contacts_record_h relationshipHandle = null;
1635
1636         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.relationship, &count);
1637         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);
1638
1639         contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.relationship, index, &relationshipHandle);
1640
1641         switch (relationship.GetType())
1642         {
1643                 case CONTACT_RELATIONSHIP_TYPE_ASSISTANT:
1644                         intValue = CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;
1645                         break;
1646                 case CONTACT_RELATIONSHIP_TYPE_BROTHER:
1647                         intValue = CONTACTS_RELATIONSHIP_TYPE_BROTHER;
1648                         break;
1649                 case CONTACT_RELATIONSHIP_TYPE_CHILD:
1650                         intValue = CONTACTS_RELATIONSHIP_TYPE_CHILD;
1651                         break;
1652                 case CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
1653                         intValue = CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER;
1654                         break;
1655                 case CONTACT_RELATIONSHIP_TYPE_FATHER:
1656                         intValue = CONTACTS_RELATIONSHIP_TYPE_FATHER;
1657                         break;
1658                 case CONTACT_RELATIONSHIP_TYPE_FRIEND:
1659                         intValue = CONTACTS_RELATIONSHIP_TYPE_FRIEND;
1660                         break;
1661                 case CONTACT_RELATIONSHIP_TYPE_MANAGER:
1662                         intValue = CONTACTS_RELATIONSHIP_TYPE_MANAGER;
1663                         break;
1664                 case CONTACT_RELATIONSHIP_TYPE_MOTHER:
1665                         intValue = CONTACTS_RELATIONSHIP_TYPE_MOTHER;
1666                         break;
1667                 case CONTACT_RELATIONSHIP_TYPE_PARENT:
1668                         intValue = CONTACTS_RELATIONSHIP_TYPE_PARENT;
1669                         break;
1670                 case CONTACT_RELATIONSHIP_TYPE_PARTNER:
1671                         intValue = CONTACTS_RELATIONSHIP_TYPE_PARTNER;
1672                         break;
1673                 case CONTACT_RELATIONSHIP_TYPE_REFERRED_BY:
1674                         intValue = CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY;
1675                         break;
1676                 case CONTACT_RELATIONSHIP_TYPE_RELATIVE:
1677                         intValue = CONTACTS_RELATIONSHIP_TYPE_RELATIVE;
1678                         break;
1679                 case CONTACT_RELATIONSHIP_TYPE_SISTER:
1680                         intValue = CONTACTS_RELATIONSHIP_TYPE_SISTER;
1681                         break;
1682                 case CONTACT_RELATIONSHIP_TYPE_SPOUSE:
1683                         intValue = CONTACTS_RELATIONSHIP_TYPE_SPOUSE;
1684                         break;
1685                 case CONTACT_RELATIONSHIP_TYPE_CUSTOM:
1686                         intValue = CONTACTS_RELATIONSHIP_TYPE_CUSTOM;
1687                         break;
1688                 default:
1689                         intValue = CONTACTS_RELATIONSHIP_TYPE_OTHER;
1690                         break;
1691         }
1692
1693         // type
1694         contacts_record_set_int(relationshipHandle, _contacts_relationship.type, intValue);
1695
1696         // label
1697         String stringValue = relationship.GetLabel();
1698         if (!stringValue.IsEmpty())
1699         {
1700                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1701                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1702
1703                 contacts_record_set_str(relationshipHandle, _contacts_relationship.label, pCharArray.get());
1704         }
1705         else
1706         {
1707                 contacts_record_set_str(relationshipHandle, _contacts_relationship.label, null);
1708         }
1709
1710         // name
1711         stringValue = relationship.GetRelativeName();
1712         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1713         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1714
1715         contacts_record_set_str(relationshipHandle, _contacts_relationship.name, pCharArray.get());
1716
1717         return E_SUCCESS;
1718 }
1719
1720 AddressbookId
1721 _UserProfileImpl::GetAddressbookId(void) const
1722 {
1723         int addressbookId = 0;
1724
1725         contacts_record_get_int(__profileHandle, _contacts_my_profile.address_book_id, &addressbookId);
1726
1727         return addressbookId;
1728 }
1729
1730 IList*
1731 _UserProfileImpl::GetValuesN(const UserProfileMultiPropertyId id) const
1732 {
1733         IList* pList = null;
1734
1735         ClearLastResult();
1736
1737         switch (id)
1738         {
1739         case USER_PROFILE_MPROPERTY_ID_PHONE_NUMBERS:
1740                 pList = GetPhoneNumbersN();
1741                 break;
1742
1743         case USER_PROFILE_MPROPERTY_ID_EMAILS:
1744                 pList = GetEmailsN();
1745                 break;
1746
1747         case USER_PROFILE_MPROPERTY_ID_URLS:
1748                 pList = GetUrlsN();
1749                 break;
1750
1751         case USER_PROFILE_MPROPERTY_ID_ADDRESSES:
1752                 pList = GetAddressesN();
1753                 break;
1754
1755         case USER_PROFILE_MPROPERTY_ID_IMADDRESSES:
1756                 pList = GetImAddressesN();
1757                 break;
1758
1759         case USER_PROFILE_MPROPERTY_ID_EVENTS:
1760                 pList = GetEventsN();
1761                 break;
1762
1763         case USER_PROFILE_MPROPERTY_ID_ORGANIZATIONS:
1764                 pList = GetOrganizationsN();
1765                 break;
1766
1767         case USER_PROFILE_MPROPERTY_ID_NOTES:
1768                 pList = GetNotesN();
1769                 break;
1770
1771         case CONTACT_MPROPERTY_ID_NICKNAMES:
1772                 pList = GetNicknamesN();
1773                 break;
1774
1775         case USER_PROFILE_MPROPERTY_ID_RELATIONSHIPS:
1776                 pList = GetRelationshipsN();
1777                 break;
1778
1779
1780         default:
1781                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
1782                 return null;
1783         }
1784
1785         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1786
1787         return pList;
1788
1789 }
1790
1791 result
1792 _UserProfileImpl::AddPhoneNumber(const PhoneNumber& phoneNumber)
1793 {
1794         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));
1795
1796         int type = 0;
1797         String stringValue;
1798         contacts_record_h numberHandle = null;
1799
1800         int ret = contacts_record_create(_contacts_number._uri, &numberHandle);
1801         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1802
1803         __ContactsRecordHandle recordHandle(numberHandle);
1804
1805         switch (_PhoneNumberImpl::GetInstance(phoneNumber)->GetType())
1806         {
1807                 case PHONENUMBER_TYPE_HOME:
1808                         type = CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE;
1809                         break;
1810                 case PHONENUMBER_TYPE_WORK:
1811                         type = CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE;
1812                         break;
1813                 case PHONENUMBER_TYPE_MOBILE:
1814                         type = CONTACTS_NUMBER_TYPE_CELL;
1815                         break;
1816                 case PHONENUMBER_TYPE_HOME_FAX:
1817                         type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME;
1818                         break;
1819                 case PHONENUMBER_TYPE_WORK_FAX:
1820                         type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK;
1821                         break;
1822                 case PHONENUMBER_TYPE_PAGER:
1823                         type = CONTACTS_NUMBER_TYPE_PAGER;
1824                         break;
1825                 case PHONENUMBER_TYPE_CUSTOM:
1826                         type = CONTACTS_NUMBER_TYPE_CUSTOM;
1827                         break;
1828                 case PHONENUMBER_TYPE_ASSISTANT:
1829                         type = CONTACTS_NUMBER_TYPE_ASSISTANT;
1830                         break;
1831                 case PHONENUMBER_TYPE_OTHER:
1832                 default:
1833                         type = CONTACTS_NUMBER_TYPE_OTHER;
1834                         break;
1835         }
1836
1837         contacts_record_set_int(numberHandle, _contacts_number.type, type);
1838
1839         stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetLabel();
1840
1841         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1842         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1843
1844         contacts_record_set_str(numberHandle, _contacts_number.label, pCharArray.get());
1845
1846         stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetPhoneNumber();
1847         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1848         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1849
1850         contacts_record_set_str(numberHandle, _contacts_number.number, pCharArray.get());
1851
1852         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.number, numberHandle);
1853         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1854
1855         recordHandle.Release();
1856
1857         return E_SUCCESS;
1858
1859 }
1860
1861 result
1862 _UserProfileImpl::AddNickname(const String& nickname)
1863 {
1864
1865         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));
1866
1867         contacts_record_h nicknameHandle = null;
1868
1869         int ret = contacts_record_create(_contacts_nickname._uri, &nicknameHandle);
1870         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1871
1872         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(nickname));
1873         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1874
1875         contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
1876
1877         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.nickname, nicknameHandle);
1878         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1879
1880         return E_SUCCESS;
1881
1882 }
1883
1884 result
1885 _UserProfileImpl::AddNote(const String& note)
1886 {
1887         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));
1888
1889         contacts_record_h noteHandle = null;
1890
1891         int ret = contacts_record_create(_contacts_note._uri, &noteHandle);
1892         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1893
1894         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(note));
1895         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1896
1897         contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
1898
1899         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.note, noteHandle);
1900         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1901
1902         return E_SUCCESS;
1903
1904 }
1905
1906 result
1907 _UserProfileImpl::AddEmail(const Email& email)
1908 {
1909
1910         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));
1911
1912         int type = 0;
1913         String stringValue;
1914         contacts_record_h emailHandle = null;
1915
1916         int ret = contacts_record_create(_contacts_email._uri, &emailHandle);
1917         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1918
1919         __ContactsRecordHandle recordHandle(emailHandle);
1920
1921         switch (_EmailImpl::GetInstance(email)->GetType())
1922         {
1923                 case EMAIL_TYPE_PERSONAL:
1924                         type = CONTACTS_EMAIL_TYPE_HOME;
1925                         break;
1926                 case EMAIL_TYPE_WORK:
1927                         type = CONTACTS_EMAIL_TYPE_WORK;
1928                         break;
1929                 case EMAIL_TYPE_CUSTOM:
1930                         type = CONTACTS_EMAIL_TYPE_CUSTOM;
1931                         break;
1932                 case EMAIL_TYPE_MOBILE:
1933                         type = CONTACTS_EMAIL_TYPE_MOBILE;
1934                         break;
1935                 case EMAIL_TYPE_OTHER:
1936                         // fall through
1937                 default:
1938                         type = CONTACTS_EMAIL_TYPE_OTHER;
1939                         break;
1940         }
1941
1942         contacts_record_set_int(emailHandle, _contacts_email.type, type);
1943
1944         stringValue = _EmailImpl::GetInstance(email)->GetLabel();
1945         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1946         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1947
1948         contacts_record_set_str(emailHandle, _contacts_email.label, pCharArray.get());
1949
1950         stringValue = _EmailImpl::GetInstance(email)->GetEmail();
1951         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1952         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1953
1954         contacts_record_set_str(emailHandle, _contacts_email.email, pCharArray.get());
1955
1956         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.email, emailHandle);
1957         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1958
1959         recordHandle.Release();
1960
1961         return E_SUCCESS;
1962
1963 }
1964
1965 result
1966 _UserProfileImpl::AddUrl(const Url& url)
1967 {
1968         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));
1969
1970         int type = 0;
1971         String stringValue;
1972         contacts_record_h urlHandle = null;
1973
1974         int ret = contacts_record_create(_contacts_url._uri, &urlHandle);
1975         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1976
1977         __ContactsRecordHandle recordHandle(urlHandle);
1978
1979         switch (_UrlImpl::GetInstance(url)->GetType())
1980         {
1981                 case URL_TYPE_PERSONAL:
1982                         type = CONTACTS_URL_TYPE_HOME;
1983                         break;
1984                 case URL_TYPE_WORK:
1985                         type = CONTACTS_URL_TYPE_WORK;
1986                         break;
1987                 case URL_TYPE_CUSTOM:
1988                         type = CONTACTS_URL_TYPE_CUSTOM;
1989                         break;
1990                 case URL_TYPE_OTHER:
1991                         // fall through
1992                 default:
1993                         type = CONTACTS_URL_TYPE_OTHER;
1994                         break;
1995         }
1996
1997         // set type
1998         contacts_record_set_int(urlHandle, _contacts_url.type, type);
1999
2000         // set label
2001         stringValue = _UrlImpl::GetInstance(url)->GetLabel();
2002         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2003         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2004
2005         contacts_record_set_str(urlHandle, _contacts_url.label, pCharArray.get());
2006
2007         // set url
2008         stringValue = _UrlImpl::GetInstance(url)->GetUrl();
2009         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
2010         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2011
2012         contacts_record_set_str(urlHandle, _contacts_url.url, pCharArray.get());
2013
2014         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.url, urlHandle);
2015         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2016
2017         recordHandle.Release();
2018
2019         return E_SUCCESS;
2020
2021 }
2022
2023 result
2024 _UserProfileImpl::AddAddress(const Address& address)
2025 {
2026
2027         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));
2028
2029         int type = 0;
2030         String stringValue;
2031         contacts_record_h addressHandle = null;
2032
2033         int ret = contacts_record_create(_contacts_address._uri, &addressHandle);
2034         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2035
2036         __ContactsRecordHandle recordHandle(addressHandle);
2037
2038         switch (_AddressImpl::GetInstance(address)->GetType())
2039         {
2040                 case ADDRESS_TYPE_HOME:
2041                         type = CONTACTS_ADDRESS_TYPE_HOME;
2042                         break;
2043                 case ADDRESS_TYPE_WORK:
2044                         type = CONTACTS_ADDRESS_TYPE_WORK;
2045                         break;
2046                 case ADDRESS_TYPE_CUSTOM:
2047                         type = CONTACTS_ADDRESS_TYPE_CUSTOM;
2048                         break;
2049                 case ADDRESS_TYPE_OTHER:
2050                         // fall through
2051                 default:
2052                         type = CONTACTS_ADDRESS_TYPE_OTHER;
2053                         break;
2054         }
2055
2056         contacts_record_set_int(addressHandle, _contacts_address.type, type);
2057
2058         stringValue = _AddressImpl::GetInstance(address)->GetLabel();
2059         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2060         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2061
2062         contacts_record_set_str(addressHandle, _contacts_address.label, pCharArray.get());
2063
2064         stringValue = _AddressImpl::GetInstance(address)->GetCity();
2065         if (!stringValue.IsEmpty())
2066         {
2067                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2068                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2069
2070                 contacts_record_set_str(addressHandle, _contacts_address.locality, pCharArray.get());
2071         }
2072
2073
2074         stringValue = _AddressImpl::GetInstance(address)->GetCountry();
2075         if (!stringValue.IsEmpty())
2076         {
2077                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2078                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2079
2080                 contacts_record_set_str(addressHandle, _contacts_address.country, pCharArray.get());
2081         }
2082
2083         stringValue = _AddressImpl::GetInstance(address)->GetExtended();
2084         if (!stringValue.IsEmpty())
2085         {
2086                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2087                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2088
2089                 contacts_record_set_str(addressHandle, _contacts_address.extended, pCharArray.get());
2090         }
2091
2092         stringValue = _AddressImpl::GetInstance(address)->GetPostalCode();
2093         if (!stringValue.IsEmpty())
2094         {
2095                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2096                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2097
2098                 contacts_record_set_str(addressHandle, _contacts_address.postal_code, pCharArray.get());
2099         }
2100
2101         stringValue = _AddressImpl::GetInstance(address)->GetPostOfficeBoxNumber();
2102         if (!stringValue.IsEmpty())
2103         {
2104                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2105                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2106
2107                 contacts_record_set_str(addressHandle, _contacts_address.postbox, pCharArray.get());
2108         }
2109
2110         stringValue = _AddressImpl::GetInstance(address)->GetState();
2111         if (!stringValue.IsEmpty())
2112         {
2113                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2114                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2115
2116                 contacts_record_set_str(addressHandle, _contacts_address.region, pCharArray.get());
2117         }
2118
2119         stringValue = _AddressImpl::GetInstance(address)->GetStreet();
2120         if (!stringValue.IsEmpty())
2121         {
2122                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2123                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2124
2125                 contacts_record_set_str(addressHandle, _contacts_address.street, pCharArray.get());
2126         }
2127
2128         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.address, addressHandle);
2129         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2130
2131         recordHandle.Release();
2132
2133         return E_SUCCESS;
2134
2135 }
2136
2137 result
2138 _UserProfileImpl::AddImAddress(const ImAddress& imAddress)
2139 {
2140
2141         SysTryReturn(NID_SCL, !imAddress.GetImAddress().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%] Invalid argument is used. The imAddress is empty.", GetErrorMessage(E_INVALID_ARG));
2142
2143         int type = 0;
2144         String stringValue;
2145         contacts_record_h messengerHandle = null;
2146
2147         std::unique_ptr<char[]> pCharArray(null);
2148
2149         int ret = contacts_record_create(_contacts_messenger._uri, &messengerHandle);
2150         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2151
2152         __ContactsRecordHandle recordHandle(messengerHandle);
2153
2154         stringValue = _ImAddressImpl::GetInstance(imAddress)->GetServiceProviderName();
2155
2156         if (stringValue == IM_ADDRESS_GOOGLE_TALK)
2157         {
2158                 type = CONTACTS_MESSENGER_TYPE_GOOGLE;
2159         }
2160         else if (stringValue == IM_ADDRESS_MSN)
2161         {
2162                 type = CONTACTS_MESSENGER_TYPE_WLM;
2163         }
2164         else if (stringValue == IM_ADDRESS_ICQ)
2165         {
2166                 type = CONTACTS_MESSENGER_TYPE_ICQ;
2167         }
2168         else if (stringValue == IM_ADDRESS_AIM)
2169         {
2170                 type = CONTACTS_MESSENGER_TYPE_AIM;
2171         }
2172         else if (stringValue == IM_ADDRESS_YAHOO)
2173         {
2174                 type = CONTACTS_MESSENGER_TYPE_YAHOO;
2175         }
2176         else if (stringValue == IM_ADDRESS_QQ)
2177         {
2178                 type = CONTACTS_MESSENGER_TYPE_QQ;
2179         }
2180         else if (stringValue == IM_ADDRESS_SKYPE)
2181         {
2182                 type = CONTACTS_MESSENGER_TYPE_SKYPE;
2183         }
2184         else if (stringValue == IM_ADDRESS_JABBER)
2185         {
2186                 type = CONTACTS_MESSENGER_TYPE_JABBER;
2187         }
2188         else
2189         {
2190                 type = CONTACTS_MESSENGER_TYPE_CUSTOM;
2191         }
2192
2193         contacts_record_set_int(messengerHandle, _contacts_messenger.type, type);
2194         if (type == CONTACTS_MESSENGER_TYPE_CUSTOM)
2195         {
2196                 pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
2197                 SysTryReturn(NID_SCL, pCharArray != null,  E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2198
2199                 contacts_record_set_str(messengerHandle, _contacts_messenger.label, pCharArray.get());
2200         }
2201
2202         stringValue = _ImAddressImpl::GetInstance(imAddress)->GetImAddress();
2203         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
2204         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2205
2206         contacts_record_set_str(messengerHandle, _contacts_messenger.im_id, pCharArray.get());
2207
2208         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.messenger, messengerHandle);
2209         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2210
2211         recordHandle.Release();
2212
2213         return E_SUCCESS;
2214
2215 }
2216 result
2217 _UserProfileImpl::AddRelationship(const Relationship& relationship)
2218 {
2219         SysTryReturn(NID_SCL, !relationship.GetRelativeName().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%] Invalid argument is used. The relationship is empty.", GetErrorMessage(E_INVALID_ARG));
2220
2221         int intValue = 0;
2222         contacts_record_h relationshipHandle = null;
2223
2224         int ret = contacts_record_create(_contacts_relationship._uri, &relationshipHandle);
2225         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2226
2227         __ContactsRecordHandle recordHandle(relationshipHandle);
2228
2229         switch (relationship.GetType())
2230         {
2231                 case CONTACT_RELATIONSHIP_TYPE_ASSISTANT:
2232                         intValue = CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;
2233                         break;
2234                 case CONTACT_RELATIONSHIP_TYPE_BROTHER:
2235                         intValue = CONTACTS_RELATIONSHIP_TYPE_BROTHER;
2236                         break;
2237                 case CONTACT_RELATIONSHIP_TYPE_CHILD:
2238                         intValue = CONTACTS_RELATIONSHIP_TYPE_CHILD;
2239                         break;
2240                 case CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
2241                         intValue = CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER;
2242                         break;
2243                 case CONTACT_RELATIONSHIP_TYPE_FATHER:
2244                         intValue = CONTACTS_RELATIONSHIP_TYPE_FATHER;
2245                         break;
2246                 case CONTACT_RELATIONSHIP_TYPE_FRIEND:
2247                         intValue = CONTACTS_RELATIONSHIP_TYPE_FRIEND;
2248                         break;
2249                 case CONTACT_RELATIONSHIP_TYPE_MANAGER:
2250                         intValue = CONTACTS_RELATIONSHIP_TYPE_MANAGER;
2251                         break;
2252                 case CONTACT_RELATIONSHIP_TYPE_MOTHER:
2253                         intValue = CONTACTS_RELATIONSHIP_TYPE_MOTHER;
2254                         break;
2255                 case CONTACT_RELATIONSHIP_TYPE_PARENT:
2256                         intValue = CONTACTS_RELATIONSHIP_TYPE_PARENT;
2257                         break;
2258                 case CONTACT_RELATIONSHIP_TYPE_PARTNER:
2259                         intValue = CONTACTS_RELATIONSHIP_TYPE_PARTNER;
2260                         break;
2261                 case CONTACT_RELATIONSHIP_TYPE_REFERRED_BY:
2262                         intValue = CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY;
2263                         break;
2264                 case CONTACT_RELATIONSHIP_TYPE_RELATIVE:
2265                         intValue = CONTACTS_RELATIONSHIP_TYPE_RELATIVE;
2266                         break;
2267                 case CONTACT_RELATIONSHIP_TYPE_SISTER:
2268                         intValue = CONTACTS_RELATIONSHIP_TYPE_SISTER;
2269                         break;
2270                 case CONTACT_RELATIONSHIP_TYPE_SPOUSE:
2271                         intValue = CONTACTS_RELATIONSHIP_TYPE_SPOUSE;
2272                         break;
2273                 case CONTACT_RELATIONSHIP_TYPE_CUSTOM:
2274                         intValue = CONTACTS_RELATIONSHIP_TYPE_CUSTOM;
2275                         break;
2276                 default:
2277                         intValue = CONTACTS_RELATIONSHIP_TYPE_OTHER;
2278                         break;
2279         }
2280
2281         // type
2282         contacts_record_set_int(relationshipHandle, _contacts_relationship.type, intValue);
2283
2284         // label
2285         String stringValue = relationship.GetLabel();
2286         if (!stringValue.IsEmpty())
2287         {
2288                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2289                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2290
2291                 contacts_record_set_str(relationshipHandle, _contacts_relationship.label, pCharArray.get());
2292         }
2293
2294         // name
2295         stringValue = relationship.GetRelativeName();
2296         if (!stringValue.IsEmpty())
2297         {
2298                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2299                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2300
2301                 contacts_record_set_str(relationshipHandle, _contacts_relationship.name, pCharArray.get());
2302         }
2303
2304         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.relationship, relationshipHandle);
2305         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2306
2307         recordHandle.Release();
2308
2309         return E_SUCCESS;
2310
2311
2312 }
2313
2314 result
2315 _UserProfileImpl::AddEvent(const ContactEvent& event)
2316 {
2317
2318         int type = 0;
2319         int intValue = 0;
2320         String stringValue;
2321         contacts_record_h eventHandle = null;
2322
2323         int ret = contacts_record_create(_contacts_event._uri, &eventHandle);
2324         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2325
2326         __ContactsRecordHandle recordHandle(eventHandle);
2327
2328         switch (event.GetType())
2329         {
2330                 case CONTACT_EVENT_TYPE_ANNIVERSARY:
2331                         type = CONTACTS_EVENT_TYPE_ANNIVERSARY;
2332                         break;
2333                 case CONTACT_EVENT_TYPE_BIRTHDAY:
2334                         type = CONTACTS_EVENT_TYPE_BIRTH;
2335                         break;
2336                 case CONTACT_EVENT_TYPE_CUSTOM:
2337                         type = CONTACTS_EVENT_TYPE_CUSTOM;
2338                         break;
2339                 case CONTACT_EVENT_TYPE_OTHER:
2340                         // fall through
2341                 default:
2342                         type = CONTACTS_EVENT_TYPE_OTHER;
2343                         break;
2344         }
2345
2346         // type
2347         contacts_record_set_int(eventHandle, _contacts_event.type, type);
2348
2349         // label
2350         stringValue = event.GetLabel();
2351         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2352         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2353
2354         contacts_record_set_str(eventHandle, _contacts_event.label, pCharArray.get());
2355
2356         // date
2357         DateTime dateValue = event.GetDate();
2358         intValue = dateValue.GetYear()*10000 + dateValue.GetMonth()*100 + dateValue.GetDay();
2359         contacts_record_set_int(eventHandle, _contacts_event.date, intValue);
2360
2361         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.event, eventHandle);
2362         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2363
2364         recordHandle.Release();
2365
2366         return E_SUCCESS;
2367
2368 }
2369
2370 result
2371 _UserProfileImpl::AddOrganization(const Organization& organization)
2372 {
2373         SysTryReturn(NID_SCL
2374                                           ,     !organization.GetName().IsEmpty() ||
2375                                                 !organization.GetJobTitle().IsEmpty() ||
2376                                                 !organization.GetDepartment().IsEmpty() ||
2377                                                 !organization.GetRole().IsEmpty() ||
2378                                                 !organization.GetAgent().IsEmpty() ||
2379                                                 !organization.GetDescription().IsEmpty() ||
2380                                                 !organization.GetLocation().IsEmpty() ||
2381                                                 !organization.GetPhoneticName().IsEmpty() ||
2382                                                 !organization.GetLogoPath().IsEmpty()
2383                                           ,E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The organization is empty.", GetErrorMessage(E_INVALID_ARG));
2384
2385         contacts_record_h organizationHandle = null;
2386
2387         int ret = contacts_record_create(_contacts_company._uri, &organizationHandle);
2388         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2389
2390         __ContactsRecordHandle recordHandle(organizationHandle);
2391
2392         // name
2393         String stringValue = organization.GetName();
2394         if (!stringValue.IsEmpty())
2395         {
2396                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2397                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2398
2399                 contacts_record_set_str(organizationHandle, _contacts_company.name, pCharArray.get());
2400         }
2401
2402         // job title
2403         stringValue = organization.GetJobTitle();
2404         if (!stringValue.IsEmpty())
2405         {
2406                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2407                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2408
2409                 contacts_record_set_str(organizationHandle, _contacts_company.job_title, pCharArray.get());
2410         }
2411
2412         // department
2413         stringValue = organization.GetDepartment();
2414         if (!stringValue.IsEmpty())
2415         {
2416                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2417                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2418
2419                 contacts_record_set_str(organizationHandle, _contacts_company.department, pCharArray.get());
2420         }
2421
2422         // role
2423         stringValue = organization.GetRole();
2424         if (!stringValue.IsEmpty())
2425         {
2426                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2427                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2428
2429                 contacts_record_set_str(organizationHandle, _contacts_company.role, pCharArray.get());
2430         }
2431
2432         // agent
2433         stringValue = organization.GetAgent();
2434         if (!stringValue.IsEmpty())
2435         {
2436                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2437                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2438
2439                 contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, pCharArray.get());
2440         }
2441
2442         // type
2443         int type = 0;
2444
2445         switch (organization.GetType())
2446         {
2447                 case ORGANIZATION_TYPE_WORK:
2448                         type = CONTACTS_COMPANY_TYPE_WORK;
2449                         break;
2450                 case ORGANIZATION_TYPE_CUSTOM:
2451                         type = CONTACTS_COMPANY_TYPE_CUSTOM;
2452                         break;
2453                 case ORGANIZATION_TYPE_OTHER:
2454                         // fall through
2455                 default:
2456                         type = CONTACTS_COMPANY_TYPE_OTHER;
2457                         break;
2458         }
2459
2460         contacts_record_set_int(organizationHandle, _contacts_company.type, type);
2461
2462         // label
2463         stringValue = organization.GetLabel();
2464         if (!stringValue.IsEmpty())
2465         {
2466                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2467                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2468
2469                 contacts_record_set_str(organizationHandle, _contacts_company.label, pCharArray.get());
2470         }
2471
2472         // description
2473         stringValue = organization.GetDescription();
2474         if (!stringValue.IsEmpty())
2475         {
2476                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2477                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2478
2479                 contacts_record_set_str(organizationHandle, _contacts_company.description, pCharArray.get());
2480         }
2481
2482         // location
2483         stringValue = organization.GetLocation();
2484         if (!stringValue.IsEmpty())
2485         {
2486                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2487                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2488
2489                 contacts_record_set_str(organizationHandle, _contacts_company.location, pCharArray.get());
2490         }
2491
2492         // phonetic name
2493         stringValue = organization.GetPhoneticName();
2494         if (!stringValue.IsEmpty())
2495         {
2496                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2497                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2498
2499                 contacts_record_set_str(organizationHandle, _contacts_company.phonetic_name, pCharArray.get());
2500         }
2501
2502         // logo path
2503         if (_OrganizationImpl::GetInstance(organization)->IsLogoPathChanged() == true)
2504         {
2505                 stringValue = organization.GetLogoPath();
2506                 if (!stringValue.IsEmpty())
2507                 {
2508                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2509                         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2510
2511                         contacts_record_set_str(organizationHandle, _contacts_company.logo, pCharArray.get());
2512                 }
2513         }
2514
2515         ret = contacts_record_add_child_record(__profileHandle, _contacts_my_profile.company, organizationHandle);
2516         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2517
2518         recordHandle.Release();
2519
2520         return E_SUCCESS;
2521
2522 }
2523
2524 result
2525 _UserProfileImpl::RemoveAt(UserProfileMultiPropertyId id, int index)
2526 {
2527         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);
2528
2529         unsigned int count = 0;
2530         contacts_record_h recordHandle = null;
2531
2532         switch (id)
2533         {
2534         case USER_PROFILE_MPROPERTY_ID_PHONE_NUMBERS:
2535                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.number, &count);
2536                 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);
2537
2538                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.number, index, &recordHandle);
2539                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.number, recordHandle);
2540                 contacts_record_destroy(recordHandle, true);
2541
2542                 break;
2543         case USER_PROFILE_MPROPERTY_ID_EMAILS:
2544                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.email, &count);
2545                 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);
2546
2547                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.email, index, &recordHandle);
2548                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.email, recordHandle);
2549                 contacts_record_destroy(recordHandle, true);
2550
2551                 break;
2552         case USER_PROFILE_MPROPERTY_ID_URLS:
2553                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.url, &count);
2554                 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);
2555
2556                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.url, index, &recordHandle);
2557                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.url, recordHandle);
2558                 contacts_record_destroy(recordHandle, true);
2559
2560                 break;
2561         case USER_PROFILE_MPROPERTY_ID_ADDRESSES:
2562                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.address, &count);
2563                 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);
2564
2565                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.address, index, &recordHandle);
2566                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.address, recordHandle);
2567                 contacts_record_destroy(recordHandle, true);
2568
2569                 break;
2570         case USER_PROFILE_MPROPERTY_ID_IMADDRESSES:
2571                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.messenger, &count);
2572                 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);
2573
2574                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.messenger, index, &recordHandle);
2575                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.messenger, recordHandle);
2576                 contacts_record_destroy(recordHandle, true);
2577
2578                 break;
2579         case USER_PROFILE_MPROPERTY_ID_ORGANIZATIONS:
2580                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.company, &count);
2581                 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);
2582
2583                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.company, index, &recordHandle);
2584                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.company, recordHandle);
2585                 contacts_record_destroy(recordHandle, true);
2586
2587                 break;
2588         case USER_PROFILE_MPROPERTY_ID_EVENTS:
2589                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.event, &count);
2590                 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);
2591
2592                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.event, index, &recordHandle);
2593                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.event, recordHandle);
2594                 contacts_record_destroy(recordHandle, true);
2595
2596                 break;
2597         case USER_PROFILE_MPROPERTY_ID_RELATIONSHIPS:
2598                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.relationship, &count);
2599                 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);
2600
2601                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.relationship, index, &recordHandle);
2602                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.relationship, recordHandle);
2603                 contacts_record_destroy(recordHandle, true);
2604
2605                 break;
2606         case USER_PROFILE_MPROPERTY_ID_NOTES:
2607                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.note, &count);
2608                 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);
2609
2610                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.note, index, &recordHandle);
2611                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.note, recordHandle);
2612                 contacts_record_destroy(recordHandle, true);
2613
2614                 break;
2615         case USER_PROFILE_MPROPERTY_ID_NICKNAMES:
2616                 contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.nickname, &count);
2617                 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);
2618
2619                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.nickname, index, &recordHandle);
2620                 contacts_record_remove_child_record(__profileHandle, _contacts_my_profile.nickname, recordHandle);
2621                 contacts_record_destroy(recordHandle, true);
2622
2623                 break;
2624         default:
2625                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
2626                 return E_INVALID_ARG;
2627         }
2628
2629         return E_SUCCESS;
2630 }
2631
2632 IList*
2633 _UserProfileImpl::GetOrganizationsN(void) const
2634 {
2635         result r = E_SUCCESS;
2636         contacts_record_h organizationHandle = null;
2637         int ret = CONTACTS_ERROR_NONE;
2638         char* pCharValue = null;
2639         int intValue = 0;
2640         unsigned int count = 0;
2641         std::unique_ptr<Organization> pOrganization(null);
2642
2643         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2644         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2645
2646         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.company, &count);
2647
2648         r = pList->Construct(count);
2649         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2650
2651         for (unsigned int index = 0; index < count; index++)
2652         {
2653                 ret = contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.company, index, &organizationHandle);
2654                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2655
2656                 pOrganization.reset(new (std::nothrow) Organization());
2657                 SysTryReturn(NID_SCL, pOrganization != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2658
2659                 // name
2660                 contacts_record_get_str_p(organizationHandle, _contacts_company.name, &pCharValue);
2661                 pOrganization->SetName(pCharValue);
2662
2663                 // job title
2664                 contacts_record_get_str_p(organizationHandle, _contacts_company.job_title, &pCharValue);
2665                 pOrganization->SetJobTitle(pCharValue);
2666
2667                 // department
2668                 contacts_record_get_str_p(organizationHandle, _contacts_company.department, &pCharValue);
2669                 pOrganization->SetDepartment(pCharValue);
2670
2671                 // role
2672                 contacts_record_get_str_p(organizationHandle, _contacts_company.role, &pCharValue);
2673                 pOrganization->SetRole(pCharValue);
2674
2675                 // agent
2676                 contacts_record_get_str_p(organizationHandle, _contacts_company.assistant_name, &pCharValue);
2677                 pOrganization->SetAgent(pCharValue);
2678
2679                 // type
2680                 contacts_record_get_int(organizationHandle, _contacts_company.type, &intValue);
2681                 switch (intValue)
2682                 {
2683                         case CONTACTS_COMPANY_TYPE_WORK:
2684                                 pOrganization->SetType(ORGANIZATION_TYPE_WORK);
2685                                 break;
2686                         case CONTACTS_COMPANY_TYPE_CUSTOM:
2687                                 pOrganization->SetType(ORGANIZATION_TYPE_CUSTOM);
2688                                 break;
2689                         case CONTACTS_COMPANY_TYPE_OTHER:
2690                                 // fall through
2691                         default:
2692                                 pOrganization->SetType(ORGANIZATION_TYPE_OTHER);
2693                                 break;
2694                 }
2695
2696                 // label
2697                 contacts_record_get_str_p(organizationHandle, _contacts_company.label, &pCharValue);
2698                 pOrganization->SetLabel(pCharValue);
2699
2700                 // description
2701                 contacts_record_get_str_p(organizationHandle, _contacts_company.description, &pCharValue);
2702                 pOrganization->SetDescription(pCharValue);
2703
2704                 // location
2705                 contacts_record_get_str_p(organizationHandle, _contacts_company.location, &pCharValue);
2706                 pOrganization->SetLocation(pCharValue);
2707
2708                 // phonetic name
2709                 contacts_record_get_str_p(organizationHandle, _contacts_company.phonetic_name, &pCharValue);
2710                 pOrganization->SetPhoneticName(pCharValue);
2711
2712                 // logo path
2713                 contacts_record_get_str_p(organizationHandle, _contacts_company.logo, &pCharValue);
2714                 _OrganizationImpl::GetInstance(*pOrganization)->SetLogoPath(pCharValue);
2715
2716                 r = pList->Add(*pOrganization);
2717                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2718
2719                 pOrganization.release();
2720         }
2721
2722         return pList.release();
2723
2724 }
2725
2726 IList*
2727 _UserProfileImpl::GetRelationshipsN(void) const
2728 {
2729
2730         result r = E_SUCCESS;
2731         contacts_record_h relationshipHandle = null;
2732         int ret = CONTACTS_ERROR_NONE;
2733         int intValue = 0;
2734         char* pCharValue = null;
2735         unsigned int count = 0;
2736         std::unique_ptr<Relationship> pRelationship(null);
2737
2738         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2739         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2740
2741         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.relationship, &count);
2742
2743         r = pList->Construct(count);
2744         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2745
2746         for (unsigned int index = 0; index < count; index++)
2747         {
2748                 ret = contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.relationship, index, &relationshipHandle);
2749                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2750
2751                 pRelationship.reset(new (std::nothrow) Relationship());
2752                 SysTryReturn(NID_SCL, pRelationship != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2753
2754                 // type
2755                 contacts_record_get_int(relationshipHandle, _contacts_relationship.type, &intValue);
2756                 switch (intValue)
2757                 {
2758                 case CONTACTS_RELATIONSHIP_TYPE_ASSISTANT:
2759                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_ASSISTANT);
2760                         break;
2761                 case CONTACTS_RELATIONSHIP_TYPE_BROTHER:
2762                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_BROTHER);
2763                         break;
2764                 case CONTACTS_RELATIONSHIP_TYPE_CHILD:
2765                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_CHILD);
2766                         break;
2767                 case CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
2768                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER);
2769                         break;
2770                 case CONTACTS_RELATIONSHIP_TYPE_FATHER:
2771                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_FATHER);
2772                         break;
2773                 case CONTACTS_RELATIONSHIP_TYPE_FRIEND:
2774                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_FRIEND);
2775                         break;
2776                 case CONTACTS_RELATIONSHIP_TYPE_MANAGER:
2777                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_MANAGER);
2778                         break;
2779                 case CONTACTS_RELATIONSHIP_TYPE_MOTHER:
2780                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_MOTHER);
2781                         break;
2782                 case CONTACTS_RELATIONSHIP_TYPE_PARENT:
2783                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_PARENT);
2784                         break;
2785                 case CONTACTS_RELATIONSHIP_TYPE_PARTNER:
2786                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_PARTNER);
2787                         break;
2788                 case CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY:
2789                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_REFERRED_BY);
2790                         break;
2791                 case CONTACTS_RELATIONSHIP_TYPE_RELATIVE:
2792                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_RELATIVE);
2793                         break;
2794                 case CONTACTS_RELATIONSHIP_TYPE_SISTER:
2795                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_SISTER);
2796                         break;
2797                 case CONTACTS_RELATIONSHIP_TYPE_SPOUSE:
2798                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_SPOUSE);
2799                         break;
2800                 case CONTACTS_RELATIONSHIP_TYPE_CUSTOM:
2801                         // fall through
2802                 default:
2803                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_CUSTOM);
2804                         break;
2805                 }
2806
2807                 // label
2808                 contacts_record_get_str_p(relationshipHandle, _contacts_relationship.label, &pCharValue);
2809                 pRelationship->SetLabel(pCharValue);
2810
2811                 // name
2812                 contacts_record_get_str_p(relationshipHandle, _contacts_relationship.name, &pCharValue);
2813                 pRelationship->SetRelativeName(pCharValue);
2814
2815                 r = pList->Add(*pRelationship);
2816                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2817
2818                 pRelationship.release();
2819         }
2820
2821         return pList.release();
2822
2823 }
2824
2825 IList*
2826 _UserProfileImpl::GetEventsN(void) const
2827 {
2828         result r = E_SUCCESS;
2829         char* pCharValue = null;
2830         int intValue = 0;
2831         unsigned int count = 0;
2832         contacts_record_h eventHandle = null;
2833         std::unique_ptr<ContactEvent> pEvent(null);
2834
2835         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2836         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2837
2838         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.event, &count);
2839
2840         r = pList->Construct(count);
2841         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2842
2843         for (unsigned int index = 0; index < count; index++)
2844         {
2845                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.event, index, &eventHandle);
2846
2847                 pEvent.reset(new (std::nothrow) ContactEvent());
2848                 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2849
2850                 // label
2851                 contacts_record_get_str_p(eventHandle, _contacts_event.label, &pCharValue);
2852                 pEvent->SetLabel(pCharValue);
2853
2854                 // type
2855                 contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
2856                 switch (intValue)
2857                 {
2858                 case CONTACTS_EVENT_TYPE_BIRTH:
2859                         pEvent->SetType(CONTACT_EVENT_TYPE_BIRTHDAY);
2860                         break;
2861                 case CONTACTS_EVENT_TYPE_ANNIVERSARY:
2862                         pEvent->SetType(CONTACT_EVENT_TYPE_ANNIVERSARY);
2863                         break;
2864                 case CONTACTS_URL_TYPE_CUSTOM:
2865                         pEvent->SetType(CONTACT_EVENT_TYPE_CUSTOM);
2866                         break;
2867                 default:
2868                         pEvent->SetType(CONTACT_EVENT_TYPE_OTHER);
2869                         break;
2870                 }
2871
2872                 DateTime dateTime;
2873
2874                 contacts_record_get_int(eventHandle, _contacts_event.date, &intValue);
2875                 __CONVERT_DATE_TO_DATETIME(intValue, dateTime);
2876                 pEvent->SetDate(dateTime);
2877
2878                 pList->Add(*pEvent);
2879                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2880
2881                 pEvent.release();
2882         }
2883
2884         return pList.release();
2885
2886 }
2887
2888 IList*
2889 _UserProfileImpl::GetNotesN(void) const
2890 {
2891         result r = E_SUCCESS;
2892         char* pCharValue = null;
2893         unsigned int count = 0;
2894         contacts_record_h noteHandle = null;
2895         std::unique_ptr<String> pNote(null);
2896
2897         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2898         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2899
2900         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.note, &count);
2901
2902         r = pList->Construct(count);
2903         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2904
2905         for (unsigned int index = 0; index < count; index++)
2906         {
2907                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.note, index, &noteHandle);
2908
2909                 contacts_record_get_str_p(noteHandle, _contacts_note.note, &pCharValue);
2910
2911                 pNote.reset(new (std::nothrow) String(pCharValue));
2912                 SysTryReturn(NID_SCL, pNote != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2913
2914                 pList->Add(*pNote);
2915                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2916
2917                 pNote.release();
2918         }
2919
2920         return pList.release();
2921
2922 }
2923
2924 IList*
2925 _UserProfileImpl::GetNicknamesN(void) const
2926 {
2927         result r = E_SUCCESS;
2928         char* pCharValue = null;
2929         unsigned int count = 0;
2930         contacts_record_h nicknameHandle = null;
2931         std::unique_ptr<String> pNickname(null);
2932
2933         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2934         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2935
2936         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.nickname, &count);
2937
2938         r = pList->Construct(count);
2939         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2940
2941         for (unsigned int index = 0; index < count; index++)
2942         {
2943                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.nickname, index, &nicknameHandle);
2944
2945                 contacts_record_get_str_p(nicknameHandle, _contacts_nickname.name, &pCharValue);
2946
2947                 pNickname.reset(new (std::nothrow) String(pCharValue));
2948                 SysTryReturn(NID_SCL, pNickname != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2949
2950                 pList->Add(*pNickname);
2951                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2952
2953                 pNickname.release();
2954         }
2955
2956         return pList.release();
2957
2958 }
2959
2960 IList*
2961 _UserProfileImpl::GetPhoneNumbersN(void) const
2962 {
2963         result r = E_SUCCESS;
2964         unsigned int count = 0;
2965         contacts_record_h numberHandle = null;
2966         int intValue = 0;
2967         char* pCharValue = null;
2968         PhoneNumberType type = PHONENUMBER_TYPE_HOME;
2969         std::unique_ptr<PhoneNumber> pPhoneNumber(null);
2970
2971         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2972         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2973
2974
2975         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.number, &count);
2976
2977         contacts_record_get_int(__profileHandle, _contacts_my_profile.id, &intValue);
2978
2979         r = pList->Construct(count);
2980         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2981
2982         for (unsigned int index = 0; index < count; index++)
2983         {
2984                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.number, index, &numberHandle);
2985
2986                 pPhoneNumber.reset(new (std::nothrow) PhoneNumber());
2987                 SysTryReturn(NID_SCL, pPhoneNumber != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2988
2989                 contacts_record_get_int(numberHandle, _contacts_number.id, &intValue);
2990                 _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetRecordId(intValue);
2991
2992                 contacts_record_get_str_p(numberHandle, _contacts_number.label, &pCharValue);
2993                 _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetLabel(pCharValue);
2994
2995                 contacts_record_get_int(numberHandle, _contacts_number.type, &intValue);
2996
2997                 switch (intValue)
2998                 {
2999                         case CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE:
3000                                 type = PHONENUMBER_TYPE_HOME;
3001                                 break;
3002                         case CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE:
3003                                 type = PHONENUMBER_TYPE_WORK;
3004                                 break;
3005                         case CONTACTS_NUMBER_TYPE_CELL:
3006                                 type = PHONENUMBER_TYPE_MOBILE;
3007                                 break;
3008                         case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME:
3009                                 type = PHONENUMBER_TYPE_HOME_FAX;
3010                                 break;
3011                         case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK:
3012                                 type = PHONENUMBER_TYPE_WORK_FAX;
3013                                 break;
3014                         case CONTACTS_NUMBER_TYPE_PAGER:
3015                                 type = PHONENUMBER_TYPE_PAGER;
3016                                 break;
3017                         case CONTACTS_NUMBER_TYPE_CUSTOM:
3018                                 type = PHONENUMBER_TYPE_CUSTOM;
3019                                 break;
3020                         case CONTACTS_NUMBER_TYPE_ASSISTANT:
3021                                 type = PHONENUMBER_TYPE_ASSISTANT;
3022                                 break;
3023                         default:
3024                                 if (intValue & CONTACTS_NUMBER_TYPE_FAX)
3025                                 {
3026                                         type = PHONENUMBER_TYPE_HOME_FAX;
3027                                 }
3028                                 else if (intValue & CONTACTS_NUMBER_TYPE_CELL)
3029                                 {
3030                                         type = PHONENUMBER_TYPE_MOBILE;
3031                                 }
3032                                 else if (intValue & CONTACTS_NUMBER_TYPE_PAGER)
3033                                 {
3034                                         type = PHONENUMBER_TYPE_PAGER;
3035                                 }
3036                                 else if (intValue & CONTACTS_NUMBER_TYPE_HOME)
3037                                 {
3038                                         type = PHONENUMBER_TYPE_HOME;
3039                                 }
3040                                 else if (intValue & CONTACTS_NUMBER_TYPE_WORK)
3041                                 {
3042                                         type = PHONENUMBER_TYPE_WORK;
3043                                 }
3044                                 else if (intValue & CONTACTS_NUMBER_TYPE_VOICE)
3045                                 {
3046                                         type = PHONENUMBER_TYPE_HOME;
3047                                 }
3048                                 else
3049                                 {
3050                                         type = PHONENUMBER_TYPE_OTHER;
3051                                 }
3052                                 break;
3053                 }
3054
3055                 _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetType(type);
3056
3057                 contacts_record_get_str_p(numberHandle, _contacts_number.number, &pCharValue);
3058                 _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetPhoneNumber(pCharValue);
3059
3060                 r = pList->Add(*pPhoneNumber);
3061                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3062
3063                 pPhoneNumber.release();
3064         }
3065
3066         return pList.release();
3067
3068 }
3069
3070 IList*
3071 _UserProfileImpl::GetEmailsN(void) const
3072 {
3073         result r = E_SUCCESS;
3074         contacts_record_h currentHandle = null;
3075         int ret = CONTACTS_ERROR_NONE;
3076         int intValue = 0;
3077         unsigned int count = 0;
3078         char* pCharValue = null;
3079         EmailType type = EMAIL_TYPE_PERSONAL;
3080         std::unique_ptr<Email> pEmail(null);
3081
3082         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3083         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3084
3085         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.email, &count);
3086
3087         r = pList->Construct(count);
3088         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3089
3090         for (unsigned int index = 0; index < count; index++)
3091         {
3092                 ret = contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.email, index, &currentHandle);
3093                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM))
3094
3095                 pEmail.reset(new (std::nothrow) Email());
3096                 SysTryReturn(NID_SCL, pEmail != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3097
3098                 contacts_record_get_int(currentHandle, _contacts_email.id, &intValue);
3099                 _EmailImpl::GetInstance(*pEmail)->SetRecordId(intValue);
3100
3101                 contacts_record_get_str_p(currentHandle, _contacts_email.label, &pCharValue);
3102                 _EmailImpl::GetInstance(*pEmail)->SetLabel(pCharValue);
3103
3104                 contacts_record_get_int(currentHandle, _contacts_email.type, &intValue);
3105                 switch (intValue)
3106                 {
3107                 case CONTACTS_EMAIL_TYPE_HOME:
3108                         type = EMAIL_TYPE_PERSONAL;
3109                         break;
3110                 case CONTACTS_EMAIL_TYPE_WORK:
3111                         type = EMAIL_TYPE_WORK;
3112                         break;
3113                 case CONTACTS_EMAIL_TYPE_CUSTOM:
3114                         type = EMAIL_TYPE_CUSTOM;
3115                         break;
3116                 case CONTACTS_EMAIL_TYPE_MOBILE:
3117                         type = EMAIL_TYPE_MOBILE;
3118                         break;
3119                 default:
3120                         type = EMAIL_TYPE_OTHER;
3121                         break;
3122                 }
3123
3124                 _EmailImpl::GetInstance(*pEmail)->SetType(type);
3125
3126                 contacts_record_get_str_p(currentHandle, _contacts_email.email, &pCharValue);
3127                 _EmailImpl::GetInstance(*pEmail)->SetEmail(pCharValue);
3128
3129                 r = pList->Add(*pEmail);
3130                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3131
3132                 pEmail.release();
3133         }
3134
3135         return pList.release();
3136
3137 }
3138
3139 IList*
3140 _UserProfileImpl::GetUrlsN(void) const
3141 {
3142
3143         result r = E_SUCCESS;
3144         char* pCharValue = null;
3145         int intValue = 0;
3146         unsigned int count = 0;
3147         UrlType type = URL_TYPE_PERSONAL;
3148         contacts_record_h urlHandle = null;
3149         std::unique_ptr<Url> pUrl(null);
3150
3151         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3152         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3153
3154         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.url, &count);
3155
3156         r = pList->Construct(count);
3157         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3158
3159         for (unsigned int index = 0; index < count; index++)
3160         {
3161                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.url, index, &urlHandle);
3162
3163                 pUrl.reset(new (std::nothrow) Url());
3164                 SysTryReturn(NID_SCL, pUrl != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3165
3166                 contacts_record_get_str_p(urlHandle, _contacts_url.label, &pCharValue);
3167                 pUrl->SetLabel(pCharValue);
3168
3169                 contacts_record_get_int(urlHandle, _contacts_url.type, &intValue);
3170                 switch (intValue)
3171                 {
3172                 case CONTACTS_URL_TYPE_HOME:
3173                         type = URL_TYPE_PERSONAL;
3174                         break;
3175                 case CONTACTS_URL_TYPE_WORK:
3176                         type = URL_TYPE_WORK;
3177                         break;
3178                 case CONTACTS_URL_TYPE_CUSTOM:
3179                         type = URL_TYPE_CUSTOM;
3180                         break;
3181                 default:
3182                         type = URL_TYPE_OTHER;
3183                         break;
3184                 }
3185
3186                 pUrl->SetType(type);
3187
3188                 contacts_record_get_str_p(urlHandle, _contacts_url.url, &pCharValue);
3189                 _UrlImpl::GetInstance(*pUrl)->SetUrl(pCharValue);
3190
3191                 pList->Add(*pUrl);
3192                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3193
3194                 pUrl.release();
3195         }
3196
3197         return pList.release();
3198
3199 }
3200
3201 IList*
3202 _UserProfileImpl::GetAddressesN(void) const
3203 {
3204         result r = E_SUCCESS;
3205         char* pCharValue = null;
3206         int intValue = 0;
3207         unsigned int count = 0;
3208         contacts_record_h addressHandle = 0;
3209         std::unique_ptr<Address> pAddress(null);
3210
3211         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3212         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3213
3214         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.address, &count);
3215
3216         r = pList->Construct(count);
3217         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3218
3219
3220         for (unsigned int index = 0; index < count; index++)
3221         {
3222                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.address, index, &addressHandle);
3223
3224                 pAddress.reset(new (std::nothrow) Address());
3225                 SysTryReturn(NID_SCL, pAddress != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3226
3227                 contacts_record_get_str_p(addressHandle, _contacts_address.label, &pCharValue);
3228                 pAddress->SetLabel(pCharValue);
3229
3230                 contacts_record_get_int(addressHandle, _contacts_address.type, &intValue);
3231                 switch (intValue)
3232                 {
3233                 case CONTACTS_ADDRESS_TYPE_HOME:
3234                         pAddress->SetType(ADDRESS_TYPE_HOME);
3235                         break;
3236                 case CONTACTS_ADDRESS_TYPE_WORK:
3237                         pAddress->SetType(ADDRESS_TYPE_WORK);
3238                         break;
3239                 case CONTACTS_ADDRESS_TYPE_CUSTOM:
3240                         pAddress->SetType(ADDRESS_TYPE_CUSTOM);
3241                         break;
3242                 default:
3243                         pAddress->SetType(ADDRESS_TYPE_OTHER);
3244                         break;
3245                 }
3246
3247                 // 1. country
3248                 contacts_record_get_str_p(addressHandle, _contacts_address.country, &pCharValue);
3249                 _AddressImpl::GetInstance(*pAddress)->SetCountry(pCharValue);
3250
3251                 // 2. region
3252                 contacts_record_get_str_p(addressHandle, _contacts_address.region, &pCharValue);
3253                 _AddressImpl::GetInstance(*pAddress)->SetState(pCharValue);
3254
3255                 // 3. city
3256                 contacts_record_get_str_p(addressHandle, _contacts_address.locality, &pCharValue);
3257                 _AddressImpl::GetInstance(*pAddress)->SetCity(pCharValue);
3258
3259                 // 4. street
3260                 contacts_record_get_str_p(addressHandle, _contacts_address.street, &pCharValue);
3261                 _AddressImpl::GetInstance(*pAddress)->SetStreet(pCharValue);
3262
3263                 // 5. extended
3264                 contacts_record_get_str_p(addressHandle, _contacts_address.extended, &pCharValue);
3265                 _AddressImpl::GetInstance(*pAddress)->SetExtended(pCharValue);
3266
3267                 // 6. postbox
3268                 contacts_record_get_str_p(addressHandle, _contacts_address.postbox, &pCharValue);
3269                 _AddressImpl::GetInstance(*pAddress)->SetPostOfficeBoxNumber(pCharValue);
3270
3271                 // 7. postal code
3272                 contacts_record_get_str_p(addressHandle, _contacts_address.postal_code, &pCharValue);
3273                 _AddressImpl::GetInstance(*pAddress)->SetPostalCode(pCharValue);
3274
3275                 r = pList->Add(*pAddress);
3276                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3277
3278                 pAddress.release();
3279         }
3280
3281         return pList.release();
3282
3283 }
3284
3285 IList*
3286 _UserProfileImpl::GetImAddressesN(void) const
3287 {
3288         result r = E_SUCCESS;
3289         char* pCharValue = null;
3290         int intValue = 0;
3291         contacts_record_h messengerHandle = null;
3292         unsigned int count = 0;
3293         std::unique_ptr<ImAddress> pImAddress(null);
3294
3295         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3296         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3297
3298         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.messenger, &count);
3299
3300         r = pList->Construct(count);
3301         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3302
3303         for (unsigned int index = 0; index < count; index++)
3304         {
3305                 contacts_record_get_child_record_at_p(__profileHandle, _contacts_my_profile.messenger, index, &messengerHandle);
3306
3307                 pImAddress.reset(new (std::nothrow) ImAddress());
3308                 SysTryReturn(NID_SCL, pImAddress != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3309
3310                 contacts_record_get_int(messengerHandle, _contacts_messenger.type, &intValue);
3311                 switch (intValue)
3312                 {
3313                 case CONTACTS_MESSENGER_TYPE_GOOGLE:
3314                         pImAddress->SetServiceProviderName(IM_ADDRESS_GOOGLE_TALK);
3315                         break;
3316                 case CONTACTS_MESSENGER_TYPE_WLM:
3317                         pImAddress->SetServiceProviderName(IM_ADDRESS_MSN);
3318                         break;
3319                 case CONTACTS_MESSENGER_TYPE_ICQ:
3320                         pImAddress->SetServiceProviderName(IM_ADDRESS_ICQ);
3321                         break;
3322                 case CONTACTS_MESSENGER_TYPE_AIM:
3323                         pImAddress->SetServiceProviderName(IM_ADDRESS_AIM);
3324                         break;
3325                 case CONTACTS_MESSENGER_TYPE_YAHOO:
3326                         pImAddress->SetServiceProviderName(IM_ADDRESS_YAHOO);
3327                         break;
3328                 case CONTACTS_MESSENGER_TYPE_QQ:
3329                         pImAddress->SetServiceProviderName(IM_ADDRESS_QQ);
3330                         break;
3331                 case CONTACTS_MESSENGER_TYPE_SKYPE:
3332                         pImAddress->SetServiceProviderName(IM_ADDRESS_SKYPE);
3333                         break;
3334                 case CONTACTS_MESSENGER_TYPE_JABBER:
3335                         pImAddress->SetServiceProviderName(IM_ADDRESS_JABBER);
3336                         break;
3337                 case CONTACTS_MESSENGER_TYPE_CUSTOM:
3338                         // fall through
3339                 default:
3340                         contacts_record_get_str_p(messengerHandle, _contacts_messenger.label, &pCharValue);
3341                         pImAddress->SetServiceProviderName(pCharValue);
3342                         break;
3343                 }
3344
3345                 contacts_record_get_str_p(messengerHandle, _contacts_messenger.im_id, &pCharValue);
3346                 _ImAddressImpl::GetInstance(*pImAddress)->SetImAddress(pCharValue);
3347
3348                 r = pList->Add(*pImAddress);
3349                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3350
3351                 pImAddress.release();
3352         }
3353
3354         return pList.release();
3355
3356 }
3357
3358 //////////////////
3359 bool
3360 _UserProfileImpl::IsEmptyCompany(contacts_record_h companyHandle)
3361 {
3362         char* pCharValue = null;
3363
3364         contacts_record_get_str_p(companyHandle, _contacts_company.name, &pCharValue);
3365         if (pCharValue != null)
3366         {
3367                 return false;
3368         }
3369
3370         contacts_record_get_str_p(companyHandle, _contacts_company.job_title, &pCharValue);
3371         if (pCharValue != null)
3372         {
3373                 return false;
3374         }
3375
3376
3377         contacts_record_get_str_p(companyHandle, _contacts_company.department, &pCharValue);
3378         if (pCharValue != null)
3379         {
3380                 return false;
3381         }
3382
3383         contacts_record_get_str_p(companyHandle, _contacts_company.role, &pCharValue);
3384         if (pCharValue != null)
3385         {
3386                 return false;
3387         }
3388
3389         contacts_record_get_str_p(companyHandle, _contacts_company.assistant_name, &pCharValue);
3390         if (pCharValue != null)
3391         {
3392                 return false;
3393         }
3394
3395         return true;
3396 }
3397
3398 bool
3399 _UserProfileImpl::IsEmptyName(contacts_record_h nameHandle)
3400 {
3401         char* pCharValue = null;
3402
3403         contacts_record_get_str_p(nameHandle, _contacts_name.first, &pCharValue);
3404         if (pCharValue != null)
3405         {
3406                 return false;
3407         }
3408
3409         contacts_record_get_str_p(nameHandle, _contacts_name.last, &pCharValue);
3410         if (pCharValue != null)
3411         {
3412                 return false;
3413         }
3414
3415         contacts_record_get_str_p(nameHandle, _contacts_name.addition, &pCharValue);
3416         if (pCharValue != null)
3417         {
3418                 return false;
3419         }
3420
3421         contacts_record_get_str_p(nameHandle, _contacts_name.prefix, &pCharValue);
3422         if (pCharValue != null)
3423         {
3424                 return false;
3425         }
3426
3427         contacts_record_get_str_p(nameHandle, _contacts_name.suffix, &pCharValue);
3428         if (pCharValue != null)
3429         {
3430                 return false;
3431         }
3432
3433         return true;
3434
3435 }
3436
3437 bool
3438 _UserProfileImpl::IsEmpty(void) const
3439 {
3440         unsigned int count = 0;
3441
3442         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.number, &count);
3443         if (count > 0)
3444         {
3445                 return false;
3446         }
3447
3448         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.email, &count);
3449         if (count > 0)
3450         {
3451                 return false;
3452         }
3453
3454         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.url, &count);
3455         if (count > 0)
3456         {
3457                 return false;
3458         }
3459
3460         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.address, &count);
3461         if (count > 0)
3462         {
3463                 return false;
3464         }
3465
3466         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.messenger, &count);
3467         if (count > 0)
3468         {
3469                 return false;
3470         }
3471
3472         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.name, &count);
3473         if (count > 0)
3474         {
3475                 return false;
3476         }
3477
3478         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.company, &count);
3479         if (count > 0)
3480         {
3481                 return false;
3482         }
3483
3484         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.event, &count);
3485         if (count > 0)
3486         {
3487                 return false;
3488         }
3489
3490         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.note, &count);
3491         if (count > 0)
3492         {
3493                 return false;
3494         }
3495
3496         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.nickname, &count);
3497         if (count > 0)
3498         {
3499                 return false;
3500         }
3501
3502         contacts_record_get_child_record_count(__profileHandle, _contacts_my_profile.image, &count);
3503         if (count > 0)
3504         {
3505                 return false;
3506         }
3507
3508         return true;
3509
3510 }
3511
3512 void
3513 _UserProfileImpl::SetUserProfileHandle(contacts_record_h profileHandle)
3514 {
3515         contacts_record_destroy(__profileHandle, true);
3516
3517         __profileHandle = profileHandle;
3518 }
3519
3520 contacts_record_h
3521 _UserProfileImpl::GetUserProfileHandle(void) const
3522 {
3523         return __profileHandle;
3524 }
3525
3526 const _UserProfileImpl*
3527 _UserProfileImpl::GetInstance(const UserProfile& userProfile)
3528 {
3529         return userProfile.__pUserProfileImpl;
3530 }
3531
3532 _UserProfileImpl*
3533 _UserProfileImpl::GetInstance(UserProfile& userProfile)
3534 {
3535         return userProfile.__pUserProfileImpl;
3536 }
3537
3538 }} // Tizen::Social