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