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