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