merge with master
[framework/osp/social.git] / src / FScl_ContactImpl.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_ContactImpl.cpp
19  * @brief               This is the implementation for _ContactImpl class.
20  *
21  * This file contains definitions of _ContactImpl 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 <FApp_AppInfo.h>
38 #include <FBase_StringConverter.h>
39 #include "FScl_ContactDbConnector.h"
40 #include "FScl_PhoneNumberImpl.h"
41 #include "FScl_ContactImpl.h"
42 #include "FScl_AddressbookUtil.h"
43 #include "FScl_UrlImpl.h"
44 #include "FScl_EmailImpl.h"
45 #include "FScl_AddressImpl.h"
46 #include "FScl_ImAddressImpl.h"
47 #include "FScl_OrganizationImpl.h"
48
49 using namespace Tizen::App;
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Graphics;
53 using namespace Tizen::Media;
54 using namespace Tizen::Io;
55
56 namespace Tizen { namespace Social
57 {
58
59 extern const wchar_t OTHER_LABEL[] = L"Other";
60
61 const int __CONTACT_CHANGED_TIME_YEAR_OFFSET  = 1900;
62 const int __CONTACT_CHANGED_TIME_MONTH_OFFSET = 1;
63
64 const int __CONTACT_MOD_YEAR = 10000;
65 const int __CONTACT_MOD_MONTH = 100;
66
67 #define __PARSE_DATE(date, year, month, day)                    \
68         do                                                      \
69         {                                                       \
70                 int temp = date;                                \
71                 year = temp/__CONTACT_MOD_YEAR;                 \
72                 temp -= year*__CONTACT_MOD_YEAR;                \
73                 month = temp/__CONTACT_MOD_MONTH;               \
74                 day = temp - month*__CONTACT_MOD_MONTH;         \
75         }while(0)
76
77 #define __CONVERT_DATE_TO_DATETIME(date, dateTime)              \
78         do                                                      \
79         {                                                       \
80                 int temp = date;                                \
81                 int year = 0;                                   \
82                 int month = 0;                                  \
83                 int day = 0;                                    \
84                 year = temp/__CONTACT_MOD_YEAR;                 \
85                 temp -= year*__CONTACT_MOD_YEAR;                \
86                 month = temp/__CONTACT_MOD_MONTH;               \
87                 day = temp - month*__CONTACT_MOD_MONTH;         \
88                 dateTime.SetValue(year, month, day, 0, 0, 0);   \
89         }while(0)
90
91
92 #define __CONVERT_DATETIME_TO_DATE(dateTime, date)                                                                              \
93         do                                                                                                                      \
94         {                                                                                                                       \
95                 date = dateTime.GetYear()*__CONTACT_MOD_YEAR + dateTime.GetMonth()*__CONTACT_MOD_MONTH + dateTime.GetDay();     \
96         }while(0)
97
98 _ContactImpl::_ContactImpl(void)
99         : __contactHandle(null)
100         , __isRemoved(false)
101 {
102         contacts_record_h contactHandle = null;
103
104         SysTryReturnVoidResult(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
105
106         int ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
107         SysTryReturnVoidResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
108
109         __contactHandle = contactHandle;
110 }
111
112 _ContactImpl::_ContactImpl(const _ContactImpl& rhs)
113         : __contactHandle(null)
114 {
115         contacts_record_h contactHandle = null;
116
117         SysTryReturnVoidResult(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
118
119         int ret = contacts_record_clone(rhs.__contactHandle, &contactHandle);
120         SysTryReturnVoidResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
121
122         __contactHandle = contactHandle;
123         __isRemoved = rhs.__isRemoved;
124 }
125
126 _ContactImpl::~_ContactImpl(void)
127 {
128         if (__contactHandle != null)
129         {
130                 contacts_record_destroy(__contactHandle, true);
131         }
132 }
133
134 _ContactImpl&
135 _ContactImpl::operator =(const _ContactImpl& rhs)
136 {
137         if (this == &rhs)
138         {
139                 return *this;
140         }
141
142         contacts_record_h contactHandle = null;
143
144         int ret = contacts_record_clone(rhs.__contactHandle, &contactHandle);
145         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
146
147         contacts_record_destroy(__contactHandle, true);
148         __contactHandle = contactHandle;
149
150         __isRemoved = rhs.__isRemoved;
151
152         return *this;
153 }
154
155 void
156 _ContactImpl::SetContactRecordHandle(contacts_record_h contactHandle)
157 {
158         contacts_record_destroy(__contactHandle, true);
159
160         __contactHandle = contactHandle;
161 }
162
163 contacts_record_h
164 _ContactImpl::GetContactRecordHandle(void) const
165 {
166         return __contactHandle;
167 }
168
169 result
170 _ContactImpl::SetThumbnailPath(const Tizen::Base::String& filePath)
171 {
172         SysTryReturn(NID_SCL, filePath.IsEmpty() || File::IsFileExist(filePath), E_FILE_NOT_FOUND, E_FILE_NOT_FOUND, "[%s] The specified file is not found.", GetErrorMessage(E_FILE_NOT_FOUND));
173
174         unsigned int count = 0;
175         contacts_record_h imageHandle = null;
176
177         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
178         if (count > 0)
179         {
180                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &imageHandle);
181
182                 if (!filePath.IsEmpty())
183                 {
184                         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(filePath));
185                         SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
186
187                         contacts_record_set_str(imageHandle, _contacts_image.path, pCharArray.get());
188                 }
189                 else
190                 {
191                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.image, imageHandle);
192                 }
193         }
194         else
195         {
196                 if (!filePath.IsEmpty())
197                 {
198                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(filePath));
199                         SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
200
201                         int ret = contacts_record_create(_contacts_image._uri, &imageHandle);
202                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
203
204                         contacts_record_set_str(imageHandle, _contacts_image.path, pCharArray.get());
205
206                         contacts_record_add_child_record(__contactHandle, _contacts_contact.image, imageHandle);
207                 }
208         }
209
210         return E_SUCCESS;
211 }
212
213 String
214 _ContactImpl::GetThumbnailPath(void) const
215 {
216         unsigned int count = 0;
217
218         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
219         if (count == 0)
220         {
221                 return String(L"");
222         }
223
224         char* pCharValue = null;
225         contacts_record_h imageHandle = null;
226
227         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &imageHandle);
228         contacts_record_get_str_p(imageHandle, _contacts_image.path, &pCharValue);
229
230         return String(pCharValue);
231 }
232
233 Bitmap*
234 _ContactImpl::GetThumbnailN(void) const
235 {
236         unsigned int count = 0;
237         char* pCharValue = null;
238         contacts_record_h imageHandle = null;
239
240         ClearLastResult();
241
242         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
243         if (count == 0)
244         {
245                 return null;
246         }
247
248         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &imageHandle);
249         contacts_record_get_str_p(imageHandle, _contacts_image.path, &pCharValue);
250
251         String thumbnailPath(pCharValue);
252
253         Image image;
254         result r = image.Construct();
255         SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
256         SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] Failed to construct Image.", GetErrorMessage(E_SYSTEM));
257
258         ImageFormat imageFormat = image.GetImageFormat(thumbnailPath);
259         SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
260         SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_SYSTEM, "[%s] Failed to get the format of the thumbnail image.", GetErrorMessage(E_SYSTEM));
261
262         BitmapPixelFormat bitmapPixelFormat = BITMAP_PIXEL_FORMAT_RGB565;
263
264         switch (imageFormat)
265         {
266         case IMG_FORMAT_JPG:
267                 //fall through
268         case IMG_FORMAT_GIF:
269                 //fall through
270         case IMG_FORMAT_BMP:
271                 bitmapPixelFormat = BITMAP_PIXEL_FORMAT_RGB565;
272                 break;
273         case IMG_FORMAT_PNG:
274                 bitmapPixelFormat = BITMAP_PIXEL_FORMAT_ARGB8888;
275                 break;
276         default:
277                 SysLogException(NID_SCL, E_SYSTEM, "[%s] Unsupported image format.", GetErrorMessage(E_SYSTEM));
278                 return null;
279         }
280
281         Bitmap* pBitmap = image.DecodeN(thumbnailPath, bitmapPixelFormat);
282         SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed. ", GetErrorMessage(E_OUT_OF_MEMORY));
283         SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred. ", GetErrorMessage(E_SYSTEM));
284
285         return pBitmap;
286 }
287
288 result
289 _ContactImpl::GetValue(const ContactPropertyId id, String& value) const
290 {
291         unsigned int count = 0;
292         char* pCharValue = null;
293
294         switch (id)
295         {
296         case CONTACT_PROPERTY_ID_FIRST_NAME:
297                 {
298                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
299                         if (count > 0)
300                         {
301                                 contacts_record_h nameHandle = null;
302
303                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
304                                 contacts_record_get_str_p(nameHandle, _contacts_name.first, &pCharValue);
305                         }
306
307                         value = pCharValue;
308                 }
309                 break;
310         case CONTACT_PROPERTY_ID_LAST_NAME:
311                 {
312                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
313                         if (count > 0)
314                         {
315                                 contacts_record_h nameHandle = null;
316
317                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
318                                 contacts_record_get_str_p(nameHandle, _contacts_name.last, &pCharValue);
319                         }
320
321                         value = pCharValue;
322                 }
323                 break;
324         case CONTACT_PROPERTY_ID_DISPLAY_NAME:
325                         contacts_record_get_str_p(__contactHandle, _contacts_contact.display_name, &pCharValue);
326                         value = pCharValue;
327                 break;
328         case CONTACT_PROPERTY_ID_NICK_NAME:
329                 {
330                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
331                         if (count > 0)
332                         {
333                                 contacts_record_h nicknameHandle = null;
334
335                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, 0, &nicknameHandle);
336                                 contacts_record_get_str_p(nicknameHandle, _contacts_nickname.name, &pCharValue);
337                         }
338
339                         value = pCharValue;
340                 }
341                 break;
342         case CONTACT_PROPERTY_ID_MIDDLE_NAME:
343                 {
344                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
345                         if (count > 0)
346                         {
347                                 contacts_record_h nameHandle = null;
348
349                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
350                                 contacts_record_get_str_p(nameHandle, _contacts_name.addition, &pCharValue);
351                         }
352
353                         value = pCharValue;
354                 }
355                 break;
356         case CONTACT_PROPERTY_ID_NAME_PREFIX:
357                 {
358                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
359                         if (count > 0)
360                         {
361                                 contacts_record_h nameHandle = null;
362
363                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
364                                 contacts_record_get_str_p(nameHandle, _contacts_name.prefix, &pCharValue);
365                         }
366
367                         value = pCharValue;
368                 }
369                 break;
370         case CONTACT_PROPERTY_ID_NAME_SUFFIX:
371                 {
372                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
373                         if (count > 0)
374                         {
375                                 contacts_record_h nameHandle = null;
376
377                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
378                                 contacts_record_get_str_p(nameHandle, _contacts_name.suffix, &pCharValue);
379                         }
380
381                         value = pCharValue;
382                 }
383                 break;
384         case CONTACT_PROPERTY_ID_JOB_TITLE:
385                 {
386                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
387                         if (count > 0)
388                         {
389                                 contacts_record_h companyHandle = null;
390
391                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
392                                 contacts_record_get_str_p(companyHandle, _contacts_company.job_title, &pCharValue);
393                         }
394
395                         value = pCharValue;
396                 }
397                 break;
398         case CONTACT_PROPERTY_ID_COMPANY:
399                 {
400                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
401                         if (count > 0)
402                         {
403                                 contacts_record_h companyHandle = null;
404
405                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
406                                 contacts_record_get_str_p(companyHandle, _contacts_company.name, &pCharValue);
407                         }
408
409                         value = pCharValue;
410                 }
411                 break;
412         case CONTACT_PROPERTY_ID_NOTE:
413                 {
414                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
415                         if (count > 0)
416                         {
417                                 contacts_record_h noteHandle = null;
418
419                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, 0, &noteHandle);
420                                 contacts_record_get_str_p(noteHandle, _contacts_note.note, &pCharValue);
421                         }
422
423                         value = pCharValue;
424                 }
425                 break;
426         case CONTACT_PROPERTY_ID_RINGTONE:
427                 contacts_record_get_str_p(__contactHandle, _contacts_contact.ringtone_path, &pCharValue);
428                 value = pCharValue;
429                 break;
430         case CONTACT_PROPERTY_ID_THUMBNAIL:
431                 {
432                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
433                         if (count > 0)
434                         {
435                                 contacts_record_h imageHandle = null;
436
437                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &imageHandle);
438                                 contacts_record_get_str_p(imageHandle, _contacts_image.path, &pCharValue);
439                         }
440                 }
441                 value = pCharValue;
442                 break;
443         case CONTACT_PROPERTY_ID_PHONETIC_FIRST_NAME:
444                 {
445                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
446                         if (count > 0)
447                         {
448                                 contacts_record_h phoneticNameHandle = null;
449
450                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &phoneticNameHandle);
451                                 contacts_record_get_str_p(phoneticNameHandle, _contacts_name.phonetic_first, &pCharValue);
452                         }
453
454                         value = pCharValue;
455                 }
456                 break;
457         case CONTACT_PROPERTY_ID_PHONETIC_LAST_NAME:
458                 {
459                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
460                         if (count > 0)
461                         {
462                                 contacts_record_h phoneticNameHandle = null;
463
464                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &phoneticNameHandle);
465                                 contacts_record_get_str_p(phoneticNameHandle, _contacts_name.phonetic_last, &pCharValue);
466                         }
467
468                         value = pCharValue;
469                 }
470                 break;
471         case CONTACT_PROPERTY_ID_PHONETIC_MIDDLE_NAME:
472                 {
473                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
474                         if (count > 0)
475                         {
476                                 contacts_record_h phoneticNameHandle = null;
477
478                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &phoneticNameHandle);
479                                 contacts_record_get_str_p(phoneticNameHandle, _contacts_name.phonetic_middle, &pCharValue);
480                         }
481
482                         value = pCharValue;
483                 }
484                 break;
485         case CONTACT_PROPERTY_ID_UID:
486                 {
487                         contacts_record_get_str_p(__contactHandle, _contacts_contact.uid, &pCharValue);
488                         value = pCharValue;
489                 }
490                 break;
491
492         default:
493                 value = String(L"");
494                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d", GetErrorMessage(E_INVALID_ARG), id);
495                 return E_INVALID_ARG;
496         }
497
498         return E_SUCCESS;
499 }
500
501 result
502 _ContactImpl::GetValue(const ContactPropertyId id, DateTime& value) const
503 {
504         int intValue = 0;
505         DateTime dataTime;
506         unsigned int count = 0;
507
508         value = DateTime::GetMinValue();
509
510         switch (id)
511         {
512         case CONTACT_PROPERTY_ID_BIRTHDAY:
513                 {
514                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
515                         if (count > 0)
516                         {
517                                 int year = 0;
518                                 int month = 0;
519                                 int day = 0;
520
521                                 contacts_record_h eventHandle = null;
522                                 for (unsigned int i = 0; i < count; i++)
523                                 {
524                                         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
525                                         contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
526                                         if (intValue == CONTACTS_EVENT_TYPE_BIRTH)
527                                         {
528                                                 contacts_record_get_int(eventHandle, _contacts_event.date, &intValue);
529
530                                                 __PARSE_DATE(intValue, year, month, day);
531
532                                                 value.SetValue(year, month, day, 0, 0, 0);
533                                                 break;
534                                         }
535                                 }
536                         }
537                 }
538                 break;
539
540         case CONTACT_PROPERTY_ID_ANNIVERSARY:
541                 {
542                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
543                         if (count > 0)
544                         {
545                                 int year = 0;
546                                 int month = 0;
547                                 int day = 0;
548
549                                 contacts_record_h eventHandle = null;
550                                 for (unsigned int i = 0; i < count; i++)
551                                 {
552                                         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
553                                         contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
554                                         if (intValue == CONTACTS_EVENT_TYPE_ANNIVERSARY)
555                                         {
556                                                 contacts_record_get_int(eventHandle, _contacts_event.date, &intValue);
557
558                                                 __PARSE_DATE(intValue, year, month, day);
559
560                                                 value.SetValue(year, month, day, 0, 0, 0);
561                                                 break;
562                                         }
563                                 }
564                         }
565                 }
566                 break;
567
568         case CONTACT_PROPERTY_ID_LAST_REVISION:
569                 {
570                         struct tm ts;
571                         int intValue = 0;
572
573                         contacts_record_get_int(__contactHandle, _contacts_contact.changed_time, &intValue);
574                         gmtime_r((time_t *)intValue, &ts);
575
576                         value.SetValue(ts.tm_year + __CONTACT_CHANGED_TIME_YEAR_OFFSET, ts.tm_mon + __CONTACT_CHANGED_TIME_MONTH_OFFSET, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
577                 }
578                 break;
579
580         default:
581                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
582                 return E_INVALID_ARG;
583         }
584
585         return E_SUCCESS;
586 }
587
588 bool
589 _ContactImpl::IsEmptyCompany(contacts_record_h companyHandle)
590 {
591         char* pCharValue = null;
592
593         contacts_record_get_str_p(companyHandle, _contacts_company.name, &pCharValue);
594         if (pCharValue != null)
595         {
596                 return false;
597         }
598
599         contacts_record_get_str_p(companyHandle, _contacts_company.job_title, &pCharValue);
600         if (pCharValue != null)
601         {
602                 return false;
603         }
604
605         contacts_record_get_str_p(companyHandle, _contacts_company.department, &pCharValue);
606         if (pCharValue != null)
607         {
608                 return false;
609         }
610
611         contacts_record_get_str_p(companyHandle, _contacts_company.role, &pCharValue);
612         if (pCharValue != null)
613         {
614                 return false;
615         }
616
617         contacts_record_get_str_p(companyHandle, _contacts_company.assistant_name, &pCharValue);
618         if (pCharValue != null)
619         {
620                 return false;
621         }
622
623         contacts_record_get_str_p(companyHandle, _contacts_company.description, &pCharValue);
624         if (pCharValue != null)
625         {
626                 return false;
627         }
628
629         contacts_record_get_str_p(companyHandle, _contacts_company.location, &pCharValue);
630         if (pCharValue != null)
631         {
632                 return false;
633         }
634
635         contacts_record_get_str_p(companyHandle, _contacts_company.phonetic_name, &pCharValue);
636         if (pCharValue != null)
637         {
638                 return false;
639         }
640
641         contacts_record_get_str_p(companyHandle, _contacts_company.logo, &pCharValue);
642         if (pCharValue != null)
643         {
644                 return false;
645         }
646
647         return true;
648 }
649
650 bool
651 _ContactImpl::IsEmptyName(contacts_record_h nameHandle)
652 {
653         char* pCharValue = null;
654
655         contacts_record_get_str_p(nameHandle, _contacts_name.first, &pCharValue);
656         if (pCharValue != null)
657         {
658                 return false;
659         }
660
661         contacts_record_get_str_p(nameHandle, _contacts_name.last, &pCharValue);
662         if (pCharValue != null)
663         {
664                 return false;
665         }
666
667         contacts_record_get_str_p(nameHandle, _contacts_name.addition, &pCharValue);
668         if (pCharValue != null)
669         {
670                 return false;
671         }
672
673         contacts_record_get_str_p(nameHandle, _contacts_name.prefix, &pCharValue);
674         if (pCharValue != null)
675         {
676                 return false;
677         }
678
679         contacts_record_get_str_p(nameHandle, _contacts_name.suffix, &pCharValue);
680         if (pCharValue != null)
681         {
682                 return false;
683         }
684
685         contacts_record_get_str_p(nameHandle, _contacts_name.phonetic_first, &pCharValue);
686         if (pCharValue != null)
687         {
688                 return false;
689         }
690
691         contacts_record_get_str_p(nameHandle, _contacts_name.phonetic_last, &pCharValue);
692         if (pCharValue != null)
693         {
694                 return false;
695         }
696
697         contacts_record_get_str_p(nameHandle, _contacts_name.phonetic_middle, &pCharValue);
698         if (pCharValue != null)
699         {
700                 return false;
701         }
702
703         return true;
704 }
705
706 result
707 _ContactImpl::SetValue(ContactPropertyId id, const String& value)
708 {
709         SysTryReturn(NID_SCL, id != CONTACT_PROPERTY_ID_THUMBNAIL, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. Thumbnail cannot be set using this.", GetErrorMessage(E_INVALID_ARG));
710         SysTryReturn(NID_SCL, id != CONTACT_PROPERTY_ID_DISPLAY_NAME, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. Display cannot be set using this.", GetErrorMessage(E_INVALID_ARG));
711
712         int ret = CONTACTS_ERROR_NONE;
713         unsigned int count = 0;
714
715         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
716         {
717                 int maxLength = GetMaxLength(id);
718                 SysTryReturn(NID_SCL, value.GetLength() <= maxLength || maxLength == -1 , E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the value=%ls exceeds the maximum length.", GetErrorMessage(E_INVALID_ARG), value.GetPointer());
719         }
720
721         switch (id)
722         {
723         case CONTACT_PROPERTY_ID_FIRST_NAME:
724                 {
725                         contacts_record_h nameHandle = null;
726                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
727                         if (count > 0)
728                         {
729                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
730
731                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
732                                 contacts_record_set_str(nameHandle, _contacts_name.first, pCharArray.get());
733
734                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
735                                 {
736                                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
737                                 }
738                         }
739                         else
740                         {
741                                 if (!value.IsEmpty())
742                                 {
743                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
744                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
745
746                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
747                                         contacts_record_set_str(nameHandle, _contacts_name.first, pCharArray.get());
748
749                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
750                                 }
751                         }
752                 }
753                 break;
754
755         case CONTACT_PROPERTY_ID_MIDDLE_NAME:
756                 {
757                         contacts_record_h nameHandle = null;
758                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
759                         if (count > 0)
760                         {
761                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
762
763                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
764                                 contacts_record_set_str(nameHandle, _contacts_name.addition, pCharArray.get());
765
766                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
767                                 {
768                                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
769                                 }
770                         }
771                         else
772                         {
773                                 if (!value.IsEmpty())
774                                 {
775                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
776                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
777
778                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
779                                         contacts_record_set_str(nameHandle, _contacts_name.addition, pCharArray.get());
780
781                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
782                                 }
783                         }
784
785                 }
786
787                 break;
788
789         case CONTACT_PROPERTY_ID_LAST_NAME:
790                 {
791                         contacts_record_h nameHandle = null;
792                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
793                         if (count > 0)
794                         {
795                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
796
797                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
798                                 contacts_record_set_str(nameHandle, _contacts_name.last, pCharArray.get());
799
800                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
801                                 {
802                                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
803                                 }
804                         }
805                         else
806                         {
807                                 if (!value.IsEmpty())
808                                 {
809                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
810                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
811
812                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
813                                         contacts_record_set_str(nameHandle, _contacts_name.last, pCharArray.get());
814
815                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
816                                 }
817                         }
818
819                 }
820
821                 break;
822         case CONTACT_PROPERTY_ID_NAME_SUFFIX:
823                 {
824                         contacts_record_h nameHandle = null;
825                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
826                         if (count > 0)
827                         {
828                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
829
830                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
831                                 contacts_record_set_str(nameHandle, _contacts_name.suffix, pCharArray.get());
832
833                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
834                                 {
835                                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
836                                 }
837
838                         }
839                         else
840                         {
841                                 if (!value.IsEmpty())
842                                 {
843                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
844
845                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
846
847                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
848                                         contacts_record_set_str(nameHandle, _contacts_name.suffix, pCharArray.get());
849
850                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
851                                 }
852                         }
853
854                 }
855
856                 break;
857
858         case CONTACT_PROPERTY_ID_NAME_PREFIX:
859                 {
860                         contacts_record_h nameHandle = null;
861                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
862                         if (count > 0)
863                         {
864                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &nameHandle);
865
866                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
867                                 contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
868
869                                 if (value.IsEmpty() && IsEmptyName(nameHandle))
870                                 {
871                                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, nameHandle);
872                                 }
873                         }
874                         else
875                         {
876                                 if (!value.IsEmpty())
877                                 {
878                                         ret = contacts_record_create(_contacts_name._uri, &nameHandle);
879                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
880
881                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
882                                         contacts_record_set_str(nameHandle, _contacts_name.prefix, pCharArray.get());
883
884                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.name, nameHandle);
885                                 }
886                         }
887
888                 }
889
890                 break;
891
892         case CONTACT_PROPERTY_ID_NICK_NAME:
893                 {
894                         contacts_record_h nicknameHandle = null;
895                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
896                         if (count > 0)
897                         {
898                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, 0, &nicknameHandle);
899                                 if (!value.IsEmpty())
900                                 {
901                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
902                                         contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
903                                 }
904                                 else
905                                 {
906                                         while (true)
907                                         {
908                                                 ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, 0, &nicknameHandle);
909                                                 if (ret != CONTACTS_ERROR_NONE)
910                                                 {
911                                                         break;
912                                                 }
913
914                                                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.nickname, nicknameHandle);
915                                         }
916                                 }
917                         }
918                         else
919                         {
920                                 if (!value.IsEmpty())
921                                 {
922                                         ret = contacts_record_create(_contacts_nickname._uri, &nicknameHandle);
923                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
924
925                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
926                                         contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
927
928                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.nickname, nicknameHandle);
929                                 }
930                         }
931
932                 }
933
934                 break;
935
936         case CONTACT_PROPERTY_ID_JOB_TITLE:
937                 {
938                         contacts_record_h companyHandle = null;
939                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
940                         if (count > 0)
941                         {
942                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
943
944                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
945                                 contacts_record_set_str(companyHandle, _contacts_company.job_title, pCharArray.get());
946
947                                 if (value.IsEmpty() && IsEmptyCompany(companyHandle))
948                                 {
949                                         while (true)
950                                         {
951                                                 ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
952                                                 if (ret != CONTACTS_ERROR_NONE)
953                                                 {
954                                                         break;
955                                                 }
956
957                                                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.company, companyHandle);
958                                         }
959                                 }
960                         }
961                         else
962                         {
963                                 if (!value.IsEmpty())
964                                 {
965                                         ret = contacts_record_create(_contacts_company._uri, &companyHandle);
966                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
967
968                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
969                                         contacts_record_set_str(companyHandle, _contacts_company.job_title, pCharArray.get());
970
971                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.company, companyHandle);
972                                 }
973                         }
974
975                 }
976                 break;
977
978         case CONTACT_PROPERTY_ID_COMPANY:
979                 {
980                         contacts_record_h companyHandle = null;
981                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
982                         if (count > 0)
983                         {
984                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
985
986                                 std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
987                                 contacts_record_set_str(companyHandle, _contacts_company.name, pCharArray.get());
988
989                                 if (value.IsEmpty() && IsEmptyCompany(companyHandle))
990                                 {
991                                         while (true)
992                                         {
993                                                 ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, 0, &companyHandle);
994                                                 if (ret != CONTACTS_ERROR_NONE)
995                                                 {
996                                                         break;
997                                                 }
998
999                                                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.company, companyHandle);
1000                                         }
1001
1002                                 }
1003                         }
1004                         else
1005                         {
1006                                 if (!value.IsEmpty())
1007                                 {
1008                                         ret = contacts_record_create(_contacts_company._uri, &companyHandle);
1009                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1010
1011                                         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
1012                                         contacts_record_set_str(companyHandle, _contacts_company.name, pCharArray.get());
1013
1014                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.company, companyHandle);
1015                                 }
1016                         }
1017
1018                 }
1019                 break;
1020
1021         case CONTACT_PROPERTY_ID_NOTE:
1022                 {
1023                         contacts_record_h noteHandle = null;
1024                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
1025                         if (count > 0)
1026                         {
1027                                 if (!value.IsEmpty())
1028                                 {
1029                                         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, 0, &noteHandle);
1030
1031                                         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
1032                                         contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
1033                                 }
1034                                 else
1035                                 {
1036                                         while (true)
1037                                         {
1038                                                 ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, 0, &noteHandle);
1039                                                 if (ret != CONTACTS_ERROR_NONE)
1040                                                 {
1041                                                         break;
1042                                                 }
1043
1044                                                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.note, noteHandle);
1045                                         }
1046                                 }
1047                         }
1048                         else
1049                         {
1050                                 if (!value.IsEmpty())
1051                                 {
1052                                         ret = contacts_record_create(_contacts_note._uri, &noteHandle);
1053                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1054
1055                                         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
1056                                         contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
1057
1058                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.note, noteHandle);
1059                                 }
1060                         }
1061                 }
1062                 break;
1063
1064         case CONTACT_PROPERTY_ID_RINGTONE:
1065         {
1066                 if (!value.IsEmpty() && !File::IsFileExist(value))
1067                 {
1068                         SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The specified ringtone file does not exist.", GetErrorMessage(E_INVALID_ARG));
1069                         return E_INVALID_ARG;
1070                 }
1071
1072                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
1073
1074                 contacts_record_set_str(__contactHandle, _contacts_contact.ringtone_path, pCharArray.get());
1075         }
1076         break;
1077
1078         case CONTACT_PROPERTY_ID_PHONETIC_FIRST_NAME:
1079                 {
1080                         contacts_record_h phoneticNameHandle = null;
1081                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
1082                         if (count > 0)
1083                         {
1084                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &phoneticNameHandle);
1085
1086                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
1087                                 contacts_record_set_str(phoneticNameHandle, _contacts_name.phonetic_first, pCharArray.get());
1088
1089                                 if (value.IsEmpty() && IsEmptyName(phoneticNameHandle))
1090                                 {
1091                                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, phoneticNameHandle);
1092                                 }
1093                         }
1094                         else
1095                         {
1096                                 if (!value.IsEmpty())
1097                                 {
1098                                         ret = contacts_record_create(_contacts_name._uri, &phoneticNameHandle);
1099                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1100
1101                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
1102                                         contacts_record_set_str(phoneticNameHandle, _contacts_name.phonetic_first, pCharArray.get());
1103
1104                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.name, phoneticNameHandle);
1105                                 }
1106                         }
1107                 }
1108                 break;
1109         case CONTACT_PROPERTY_ID_PHONETIC_LAST_NAME:
1110                 {
1111                         contacts_record_h phoneticNameHandle = null;
1112                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
1113                         if (count > 0)
1114                         {
1115                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &phoneticNameHandle);
1116
1117                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
1118                                 contacts_record_set_str(phoneticNameHandle, _contacts_name.phonetic_last, pCharArray.get());
1119
1120                                 if (value.IsEmpty() && IsEmptyName(phoneticNameHandle))
1121                                 {
1122                                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, phoneticNameHandle);
1123                                 }
1124                         }
1125                         else
1126                         {
1127                                 if (!value.IsEmpty())
1128                                 {
1129                                         ret = contacts_record_create(_contacts_name._uri, &phoneticNameHandle);
1130                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1131
1132                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
1133                                         contacts_record_set_str(phoneticNameHandle, _contacts_name.phonetic_last, pCharArray.get());
1134
1135                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.name, phoneticNameHandle);
1136                                 }
1137                         }
1138                 }
1139                 break;
1140         case CONTACT_PROPERTY_ID_PHONETIC_MIDDLE_NAME:
1141                 {
1142                         contacts_record_h phoneticNameHandle = null;
1143                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
1144                         if (count > 0)
1145                         {
1146                                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &phoneticNameHandle);
1147
1148                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
1149                                 contacts_record_set_str(phoneticNameHandle, _contacts_name.phonetic_middle, pCharArray.get());
1150
1151                                 if (value.IsEmpty() && IsEmptyName(phoneticNameHandle))
1152                                 {
1153                                         contacts_record_remove_child_record(__contactHandle, _contacts_contact.name, phoneticNameHandle);
1154                                 }
1155                         }
1156                         else
1157                         {
1158                                 if (!value.IsEmpty())
1159                                 {
1160                                         ret = contacts_record_create(_contacts_name._uri, &phoneticNameHandle);
1161                                         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1162
1163                                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
1164                                         contacts_record_set_str(phoneticNameHandle, _contacts_name.phonetic_middle, pCharArray.get());
1165
1166                                         contacts_record_add_child_record(__contactHandle, _contacts_contact.name, phoneticNameHandle);
1167                                 }
1168                         }
1169                 }
1170                 break;
1171         case CONTACT_PROPERTY_ID_UID:
1172                 {
1173                         if (!value.IsEmpty())
1174                         {
1175                                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(value));
1176                                 contacts_record_set_str(__contactHandle, _contacts_contact.uid, pCharArray.get());
1177                         }
1178                         else
1179                         {
1180                                 contacts_record_set_str(__contactHandle, _contacts_contact.uid, null);
1181                         }
1182                 }
1183                 break;
1184         default:
1185                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
1186                 return E_INVALID_ARG;
1187         }
1188
1189         return E_SUCCESS;
1190 }
1191
1192 result
1193 _ContactImpl::SetValue(ContactPropertyId id, const DateTime& value)
1194 {
1195         SysTryReturn(NID_SCL, id != CONTACT_PROPERTY_ID_LAST_REVISION, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. Thumbnail cannot be set using this.", GetErrorMessage(E_INVALID_ARG));
1196
1197         unsigned int count = 0;
1198         int intValue = 0;
1199         int ret = CONTACTS_ERROR_NONE;
1200
1201         switch (id)
1202         {
1203         case CONTACT_PROPERTY_ID_BIRTHDAY:
1204                 {
1205                         bool found = false;
1206                         int date = 0;
1207                         contacts_record_h eventHandle = null;
1208
1209                         __CONVERT_DATETIME_TO_DATE(value, date);
1210
1211                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
1212                         if (count > 0)
1213                         {
1214                                 for (unsigned int i = 0; i < count; i++)
1215                                 {
1216                                         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
1217                                         contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
1218                                         if (intValue == CONTACTS_EVENT_TYPE_BIRTH)
1219                                         {
1220                                                 contacts_record_set_int(eventHandle, _contacts_event.date, date);
1221                                                 found = true;
1222                                                 break;
1223                                         }
1224                                 }
1225                         }
1226
1227                         if (!found)
1228                         {
1229                                 ret = contacts_record_create(_contacts_event._uri, &eventHandle);
1230                                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1231
1232                                 contacts_record_set_int(eventHandle, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
1233                                 contacts_record_set_int(eventHandle, _contacts_event.date, date);
1234
1235                                 contacts_record_add_child_record(__contactHandle, _contacts_contact.event, eventHandle);
1236                         }
1237                 }
1238
1239                 break;
1240
1241         case CONTACT_PROPERTY_ID_ANNIVERSARY:
1242                 {
1243                         bool found = false;
1244                         int date = 0;
1245                         contacts_record_h eventHandle = null;
1246
1247                         __CONVERT_DATETIME_TO_DATE(value, date);
1248
1249                         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
1250                         if (count > 0)
1251                         {
1252                                 for (unsigned int i = 0; i < count; i++)
1253                                 {
1254                                         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
1255                                         contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
1256                                         if (intValue == CONTACTS_EVENT_TYPE_ANNIVERSARY)
1257                                         {
1258                                                 contacts_record_set_int(eventHandle, _contacts_event.date, date);
1259                                                 found = true;
1260                                                 break;
1261                                         }
1262                                 }
1263                         }
1264
1265                         if (!found)
1266                         {
1267                                 ret = contacts_record_create(_contacts_event._uri, &eventHandle);
1268                                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1269
1270                                 contacts_record_set_int(eventHandle, _contacts_event.type, CONTACTS_EVENT_TYPE_ANNIVERSARY);
1271                                 contacts_record_set_int(eventHandle, _contacts_event.date, date);
1272
1273                                 contacts_record_add_child_record(__contactHandle, _contacts_contact.event, eventHandle);
1274                         }
1275                 }
1276
1277                 break;
1278
1279         default:
1280                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
1281                 return E_INVALID_ARG;
1282         }
1283
1284         return E_SUCCESS;
1285 }
1286
1287 result
1288 _ContactImpl::AddPhoneNumber(const PhoneNumber& phoneNumber)
1289 {
1290         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));
1291         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1292
1293         int type = 0;
1294         String stringValue;
1295         contacts_record_h numberHandle = null;
1296
1297         int ret = contacts_record_create(_contacts_number._uri, &numberHandle);
1298         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1299
1300         __ContactsRecordHandle recordHandle(numberHandle);
1301
1302         switch (_PhoneNumberImpl::GetInstance(phoneNumber)->GetType())
1303         {
1304                 case PHONENUMBER_TYPE_HOME:
1305                         type = CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE;
1306                         break;
1307                 case PHONENUMBER_TYPE_WORK:
1308                         type = CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE;
1309                         break;
1310                 case PHONENUMBER_TYPE_MOBILE:
1311                         type = CONTACTS_NUMBER_TYPE_CELL;
1312                         break;
1313                 case PHONENUMBER_TYPE_HOME_FAX:
1314                         type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME;
1315                         break;
1316                 case PHONENUMBER_TYPE_WORK_FAX:
1317                         type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK;
1318                         break;
1319                 case PHONENUMBER_TYPE_PAGER:
1320                         type = CONTACTS_NUMBER_TYPE_PAGER;
1321                         break;
1322                 case PHONENUMBER_TYPE_CUSTOM:
1323                         type = CONTACTS_NUMBER_TYPE_CUSTOM;
1324                         break;
1325                 case PHONENUMBER_TYPE_ASSISTANT:
1326                         type = CONTACTS_NUMBER_TYPE_ASSISTANT;
1327                         break;
1328                 case PHONENUMBER_TYPE_OTHER:
1329                 default:
1330                         type = CONTACTS_NUMBER_TYPE_OTHER;
1331                         break;
1332         }
1333
1334         contacts_record_set_int(numberHandle, _contacts_number.type, type);
1335
1336         stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetLabel();
1337
1338         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1339         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1340
1341         contacts_record_set_str(numberHandle, _contacts_number.label, pCharArray.get());
1342
1343         stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetPhoneNumber();
1344         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1345         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1346
1347         contacts_record_set_str(numberHandle, _contacts_number.number, pCharArray.get());
1348
1349         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.number, numberHandle);
1350         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1351
1352         recordHandle.Release();
1353
1354         return E_SUCCESS;
1355 }
1356
1357 result
1358 _ContactImpl::AddNickname(const String& nickname)
1359 {
1360         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));
1361         SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1362         contacts_record_h nicknameHandle = null;
1363
1364         int ret = contacts_record_create(_contacts_nickname._uri, &nicknameHandle);
1365         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1366
1367         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(nickname));
1368         SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1369
1370         contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
1371
1372         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.nickname, nicknameHandle);
1373         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1374
1375         return E_SUCCESS;
1376 }
1377
1378 result
1379 _ContactImpl::AddNote(const String& note)
1380 {
1381         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));
1382         SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1383         contacts_record_h noteHandle = null;
1384
1385         int ret = contacts_record_create(_contacts_note._uri, &noteHandle);
1386         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1387
1388         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(note));
1389         SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1390
1391         contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
1392
1393         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.note, noteHandle);
1394         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1395
1396         return E_SUCCESS;
1397 }
1398
1399 result
1400 _ContactImpl::AddEmail(const Email& email)
1401 {
1402         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));
1403         SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1404
1405         int type = 0;
1406         String stringValue;
1407         contacts_record_h emailHandle = null;
1408
1409         int ret = contacts_record_create(_contacts_email._uri, &emailHandle);
1410         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1411
1412         __ContactsRecordHandle recordHandle(emailHandle);
1413
1414         switch (_EmailImpl::GetInstance(email)->GetType())
1415         {
1416                 case EMAIL_TYPE_PERSONAL:
1417                         type = CONTACTS_EMAIL_TYPE_HOME;
1418                         break;
1419                 case EMAIL_TYPE_WORK:
1420                         type = CONTACTS_EMAIL_TYPE_WORK;
1421                         break;
1422                 case EMAIL_TYPE_CUSTOM:
1423                         type = CONTACTS_EMAIL_TYPE_CUSTOM;
1424                         break;
1425                 case EMAIL_TYPE_MOBILE:
1426                         type = CONTACTS_EMAIL_TYPE_MOBILE;
1427                         break;
1428                 case EMAIL_TYPE_OTHER:
1429                         // fall through
1430                 default:
1431                         type = CONTACTS_EMAIL_TYPE_OTHER;
1432                         break;
1433         }
1434
1435         contacts_record_set_int(emailHandle, _contacts_email.type, type);
1436
1437         stringValue = _EmailImpl::GetInstance(email)->GetLabel();
1438         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1439         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1440
1441         contacts_record_set_str(emailHandle, _contacts_email.label, pCharArray.get());
1442
1443         stringValue = _EmailImpl::GetInstance(email)->GetEmail();
1444         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1445         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1446
1447         contacts_record_set_str(emailHandle, _contacts_email.email, pCharArray.get());
1448
1449         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.email, emailHandle);
1450         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1451
1452         recordHandle.Release();
1453
1454         return E_SUCCESS;
1455 }
1456
1457 result
1458 _ContactImpl::AddUrl(const Url& url)
1459 {
1460         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));
1461         SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1462
1463         int type = 0;
1464         String stringValue;
1465         contacts_record_h urlHandle = null;
1466
1467         int ret = contacts_record_create(_contacts_url._uri, &urlHandle);
1468         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1469
1470         __ContactsRecordHandle recordHandle(urlHandle);
1471
1472         switch (_UrlImpl::GetInstance(url)->GetType())
1473         {
1474                 case URL_TYPE_PERSONAL:
1475                         type = CONTACTS_URL_TYPE_HOME;
1476                         break;
1477                 case URL_TYPE_WORK:
1478                         type = CONTACTS_URL_TYPE_WORK;
1479                         break;
1480                 case URL_TYPE_CUSTOM:
1481                         type = CONTACTS_URL_TYPE_CUSTOM;
1482                         break;
1483                 case URL_TYPE_OTHER:
1484                         // fall through
1485                 default:
1486                         type = CONTACTS_URL_TYPE_OTHER;
1487                         break;
1488         }
1489
1490         // set type
1491         contacts_record_set_int(urlHandle, _contacts_url.type, type);
1492
1493         // set label
1494         stringValue = _UrlImpl::GetInstance(url)->GetLabel();
1495         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1496         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1497
1498         contacts_record_set_str(urlHandle, _contacts_url.label, pCharArray.get());
1499
1500         // set url
1501         stringValue = _UrlImpl::GetInstance(url)->GetUrl();
1502         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1503         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1504
1505         contacts_record_set_str(urlHandle, _contacts_url.url, pCharArray.get());
1506
1507         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.url, urlHandle);
1508         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1509
1510         recordHandle.Release();
1511
1512         return E_SUCCESS;
1513 }
1514
1515 result
1516 _ContactImpl::AddAddress(const Address& address)
1517 {
1518         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));
1519         SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1520
1521         int type = 0;
1522         String stringValue;
1523         contacts_record_h addressHandle = null;
1524
1525         int ret = contacts_record_create(_contacts_address._uri, &addressHandle);
1526         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1527
1528         __ContactsRecordHandle recordHandle(addressHandle);
1529
1530         switch (_AddressImpl::GetInstance(address)->GetType())
1531         {
1532                 case ADDRESS_TYPE_HOME:
1533                         type = CONTACTS_ADDRESS_TYPE_HOME;
1534                         break;
1535                 case ADDRESS_TYPE_WORK:
1536                         type = CONTACTS_ADDRESS_TYPE_WORK;
1537                         break;
1538                 case ADDRESS_TYPE_CUSTOM:
1539                         type = CONTACTS_ADDRESS_TYPE_CUSTOM;
1540                         break;
1541                 case ADDRESS_TYPE_OTHER:
1542                         // fall through
1543                 default:
1544                         type = CONTACTS_ADDRESS_TYPE_OTHER;
1545                         break;
1546         }
1547
1548         contacts_record_set_int(addressHandle, _contacts_address.type, type);
1549
1550         stringValue = _AddressImpl::GetInstance(address)->GetLabel();
1551         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1552         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1553
1554         contacts_record_set_str(addressHandle, _contacts_address.label, pCharArray.get());
1555
1556         stringValue = _AddressImpl::GetInstance(address)->GetCity();
1557         if (!stringValue.IsEmpty())
1558         {
1559                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1560                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1561
1562                 contacts_record_set_str(addressHandle, _contacts_address.locality, pCharArray.get());
1563         }
1564
1565
1566         stringValue = _AddressImpl::GetInstance(address)->GetCountry();
1567         if (!stringValue.IsEmpty())
1568         {
1569                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1570                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1571
1572                 contacts_record_set_str(addressHandle, _contacts_address.country, pCharArray.get());
1573         }
1574
1575         stringValue = _AddressImpl::GetInstance(address)->GetExtended();
1576         if (!stringValue.IsEmpty())
1577         {
1578                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1579                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1580
1581                 contacts_record_set_str(addressHandle, _contacts_address.extended, pCharArray.get());
1582         }
1583
1584         stringValue = _AddressImpl::GetInstance(address)->GetPostalCode();
1585         if (!stringValue.IsEmpty())
1586         {
1587                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1588                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1589
1590                 contacts_record_set_str(addressHandle, _contacts_address.postal_code, pCharArray.get());
1591         }
1592
1593         stringValue = _AddressImpl::GetInstance(address)->GetPostOfficeBoxNumber();
1594         if (!stringValue.IsEmpty())
1595         {
1596                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1597                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1598
1599                 contacts_record_set_str(addressHandle, _contacts_address.postbox, pCharArray.get());
1600         }
1601
1602         stringValue = _AddressImpl::GetInstance(address)->GetState();
1603         if (!stringValue.IsEmpty())
1604         {
1605                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1606                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1607
1608                 contacts_record_set_str(addressHandle, _contacts_address.region, pCharArray.get());
1609         }
1610
1611         stringValue = _AddressImpl::GetInstance(address)->GetStreet();
1612         if (!stringValue.IsEmpty())
1613         {
1614                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1615                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1616
1617                 contacts_record_set_str(addressHandle, _contacts_address.street, pCharArray.get());
1618         }
1619
1620         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.address, addressHandle);
1621         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1622
1623         recordHandle.Release();
1624
1625         return E_SUCCESS;
1626 }
1627
1628 result
1629 _ContactImpl::AddImAddress(const ImAddress& imAddress)
1630 {
1631         SysTryReturn(NID_SCL, !imAddress.GetImAddress().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%] Invalid argument is used. The imAddress is empty.", GetErrorMessage(E_INVALID_ARG));
1632         SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1633
1634         int type = 0;
1635         String stringValue;
1636         contacts_record_h messengerHandle = null;
1637
1638         std::unique_ptr<char[]> pCharArray(null);
1639
1640         int ret = contacts_record_create(_contacts_messenger._uri, &messengerHandle);
1641         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1642
1643         __ContactsRecordHandle recordHandle(messengerHandle);
1644
1645         stringValue = _ImAddressImpl::GetInstance(imAddress)->GetServiceProviderName();
1646
1647         if (stringValue == IM_ADDRESS_GOOGLE_TALK)
1648         {
1649                 type = CONTACTS_MESSENGER_TYPE_GOOGLE;
1650         }
1651         else if (stringValue == IM_ADDRESS_MSN)
1652         {
1653                 type = CONTACTS_MESSENGER_TYPE_WLM;
1654         }
1655         else if (stringValue == IM_ADDRESS_ICQ)
1656         {
1657                 type = CONTACTS_MESSENGER_TYPE_ICQ;
1658         }
1659         else if (stringValue == IM_ADDRESS_AIM)
1660         {
1661                 type = CONTACTS_MESSENGER_TYPE_AIM;
1662         }
1663         else if (stringValue == IM_ADDRESS_YAHOO)
1664         {
1665                 type = CONTACTS_MESSENGER_TYPE_YAHOO;
1666         }
1667         else if (stringValue == IM_ADDRESS_QQ)
1668         {
1669                 type = CONTACTS_MESSENGER_TYPE_QQ;
1670         }
1671         else if (stringValue == IM_ADDRESS_SKYPE)
1672         {
1673                 type = CONTACTS_MESSENGER_TYPE_SKYPE;
1674         }
1675         else if (stringValue == IM_ADDRESS_JABBER)
1676         {
1677                 type = CONTACTS_MESSENGER_TYPE_JABBER;
1678         }
1679         else
1680         {
1681                 type = CONTACTS_MESSENGER_TYPE_CUSTOM;
1682         }
1683
1684         contacts_record_set_int(messengerHandle, _contacts_messenger.type, type);
1685         if (type == CONTACTS_MESSENGER_TYPE_CUSTOM)
1686         {
1687                 pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1688                 SysTryReturn(NID_SCL, pCharArray != null,  E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1689
1690                 contacts_record_set_str(messengerHandle, _contacts_messenger.label, pCharArray.get());
1691         }
1692
1693         stringValue = _ImAddressImpl::GetInstance(imAddress)->GetImAddress();
1694         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
1695         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1696
1697         contacts_record_set_str(messengerHandle, _contacts_messenger.im_id, pCharArray.get());
1698
1699         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.messenger, messengerHandle);
1700         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1701
1702         recordHandle.Release();
1703
1704         return E_SUCCESS;
1705 }
1706 result
1707 _ContactImpl::AddRelationship(const Relationship& relationship)
1708 {
1709         SysTryReturn(NID_SCL, !relationship.GetRelativeName().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%] Invalid argument is used. The relationship is empty.", GetErrorMessage(E_INVALID_ARG));
1710         SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1711
1712         int intValue = 0;
1713         contacts_record_h relationshipHandle = null;
1714
1715         int ret = contacts_record_create(_contacts_relationship._uri, &relationshipHandle);
1716         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1717
1718         __ContactsRecordHandle recordHandle(relationshipHandle);
1719
1720         switch (relationship.GetType())
1721         {
1722                 case CONTACT_RELATIONSHIP_TYPE_ASSISTANT:
1723                         intValue = CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;
1724                         break;
1725                 case CONTACT_RELATIONSHIP_TYPE_BROTHER:
1726                         intValue = CONTACTS_RELATIONSHIP_TYPE_BROTHER;
1727                         break;
1728                 case CONTACT_RELATIONSHIP_TYPE_CHILD:
1729                         intValue = CONTACTS_RELATIONSHIP_TYPE_CHILD;
1730                         break;
1731                 case CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
1732                         intValue = CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER;
1733                         break;
1734                 case CONTACT_RELATIONSHIP_TYPE_FATHER:
1735                         intValue = CONTACTS_RELATIONSHIP_TYPE_FATHER;
1736                         break;
1737                 case CONTACT_RELATIONSHIP_TYPE_FRIEND:
1738                         intValue = CONTACTS_RELATIONSHIP_TYPE_FRIEND;
1739                         break;
1740                 case CONTACT_RELATIONSHIP_TYPE_MANAGER:
1741                         intValue = CONTACTS_RELATIONSHIP_TYPE_MANAGER;
1742                         break;
1743                 case CONTACT_RELATIONSHIP_TYPE_MOTHER:
1744                         intValue = CONTACTS_RELATIONSHIP_TYPE_MOTHER;
1745                         break;
1746                 case CONTACT_RELATIONSHIP_TYPE_PARENT:
1747                         intValue = CONTACTS_RELATIONSHIP_TYPE_PARENT;
1748                         break;
1749                 case CONTACT_RELATIONSHIP_TYPE_PARTNER:
1750                         intValue = CONTACTS_RELATIONSHIP_TYPE_PARTNER;
1751                         break;
1752                 case CONTACT_RELATIONSHIP_TYPE_REFERRED_BY:
1753                         intValue = CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY;
1754                         break;
1755                 case CONTACT_RELATIONSHIP_TYPE_RELATIVE:
1756                         intValue = CONTACTS_RELATIONSHIP_TYPE_RELATIVE;
1757                         break;
1758                 case CONTACT_RELATIONSHIP_TYPE_SISTER:
1759                         intValue = CONTACTS_RELATIONSHIP_TYPE_SISTER;
1760                         break;
1761                 case CONTACT_RELATIONSHIP_TYPE_SPOUSE:
1762                         intValue = CONTACTS_RELATIONSHIP_TYPE_SPOUSE;
1763                         break;
1764                 case CONTACT_RELATIONSHIP_TYPE_CUSTOM:
1765                         intValue = CONTACTS_RELATIONSHIP_TYPE_CUSTOM;
1766                         break;
1767                 default:
1768                         intValue = CONTACTS_RELATIONSHIP_TYPE_OTHER;
1769                         break;
1770         }
1771
1772         // type
1773         contacts_record_set_int(relationshipHandle, _contacts_relationship.type, intValue);
1774
1775         // label
1776         String stringValue = relationship.GetLabel();
1777         if (!stringValue.IsEmpty())
1778         {
1779                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1780                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1781
1782                 contacts_record_set_str(relationshipHandle, _contacts_relationship.label, pCharArray.get());
1783         }
1784
1785         // name
1786         stringValue = relationship.GetRelativeName();
1787         if (!stringValue.IsEmpty())
1788         {
1789                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1790                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1791
1792                 contacts_record_set_str(relationshipHandle, _contacts_relationship.name, pCharArray.get());
1793         }
1794
1795         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.relationship, relationshipHandle);
1796         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1797
1798         recordHandle.Release();
1799
1800         return E_SUCCESS;
1801
1802 }
1803
1804 result
1805 _ContactImpl::AddEvent(const ContactEvent& event)
1806 {
1807         SysTryReturn(NID_SCL, !__isRemoved || !IsFailed(Invalidate()), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1808
1809         int type = 0;
1810         int intValue = 0;
1811         String stringValue;
1812         contacts_record_h eventHandle = null;
1813
1814         int ret = contacts_record_create(_contacts_event._uri, &eventHandle);
1815         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1816
1817         __ContactsRecordHandle recordHandle(eventHandle);
1818
1819         switch (event.GetType())
1820         {
1821                 case CONTACT_EVENT_TYPE_ANNIVERSARY:
1822                         type = CONTACTS_EVENT_TYPE_ANNIVERSARY;
1823                         break;
1824                 case CONTACT_EVENT_TYPE_BIRTHDAY:
1825                         type = CONTACTS_EVENT_TYPE_BIRTH;
1826                         break;
1827                 case CONTACT_EVENT_TYPE_CUSTOM:
1828                         type = CONTACTS_EVENT_TYPE_CUSTOM;
1829                         break;
1830                 case CONTACT_EVENT_TYPE_OTHER:
1831                         // fall through
1832                 default:
1833                         type = CONTACTS_EVENT_TYPE_OTHER;
1834                         break;
1835         }
1836
1837         // type
1838         contacts_record_set_int(eventHandle, _contacts_event.type, type);
1839
1840         // label
1841         stringValue = event.GetLabel();
1842         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1843         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1844
1845         contacts_record_set_str(eventHandle, _contacts_event.label, pCharArray.get());
1846
1847         // date
1848         DateTime dateValue = event.GetDate();
1849         intValue = dateValue.GetYear()*10000 + dateValue.GetMonth()*100 + dateValue.GetDay();
1850         contacts_record_set_int(eventHandle, _contacts_event.date, intValue);
1851
1852         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.event, eventHandle);
1853         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1854
1855         recordHandle.Release();
1856
1857         return E_SUCCESS;
1858 }
1859
1860 result
1861 _ContactImpl::AddOrganization(const Organization& organization)
1862 {
1863         SysTryReturn(NID_SCL
1864                                           ,     !organization.GetName().IsEmpty() ||
1865                                                 !organization.GetJobTitle().IsEmpty() ||
1866                                                 !organization.GetDepartment().IsEmpty() ||
1867                                                 !organization.GetRole().IsEmpty() ||
1868                                                 !organization.GetAgent().IsEmpty() ||
1869                                                 !organization.GetDescription().IsEmpty() ||
1870                                                 !organization.GetLocation().IsEmpty() ||
1871                                                 !organization.GetPhoneticName().IsEmpty() ||
1872                                                 !organization.GetLogoPath().IsEmpty()
1873                                           ,E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The organization is empty.", GetErrorMessage(E_INVALID_ARG));
1874         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1875
1876         contacts_record_h organizationHandle = null;
1877
1878         int ret = contacts_record_create(_contacts_company._uri, &organizationHandle);
1879         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1880
1881         __ContactsRecordHandle recordHandle(organizationHandle);
1882
1883         // name
1884         String stringValue = organization.GetName();
1885         if (!stringValue.IsEmpty())
1886         {
1887                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1888                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1889
1890                 contacts_record_set_str(organizationHandle, _contacts_company.name, pCharArray.get());
1891         }
1892
1893         // job title
1894         stringValue = organization.GetJobTitle();
1895         if (!stringValue.IsEmpty())
1896         {
1897                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1898                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1899
1900                 contacts_record_set_str(organizationHandle, _contacts_company.job_title, pCharArray.get());
1901         }
1902
1903         // department
1904         stringValue = organization.GetDepartment();
1905         if (!stringValue.IsEmpty())
1906         {
1907                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1908                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1909
1910                 contacts_record_set_str(organizationHandle, _contacts_company.department, pCharArray.get());
1911         }
1912
1913         // role
1914         stringValue = organization.GetRole();
1915         if (!stringValue.IsEmpty())
1916         {
1917                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1918                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1919
1920                 contacts_record_set_str(organizationHandle, _contacts_company.role, pCharArray.get());
1921         }
1922
1923         // agent
1924         stringValue = organization.GetAgent();
1925         if (!stringValue.IsEmpty())
1926         {
1927                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1928                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1929
1930                 contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, pCharArray.get());
1931         }
1932
1933         // type
1934         int type = 0;
1935
1936         switch (organization.GetType())
1937         {
1938                 case ORGANIZATION_TYPE_WORK:
1939                         type = CONTACTS_COMPANY_TYPE_WORK;
1940                         break;
1941                 case ORGANIZATION_TYPE_CUSTOM:
1942                         type = CONTACTS_COMPANY_TYPE_CUSTOM;
1943                         break;
1944                 case ORGANIZATION_TYPE_OTHER:
1945                         // fall through
1946                 default:
1947                         type = CONTACTS_COMPANY_TYPE_OTHER;
1948                         break;
1949         }
1950
1951         contacts_record_set_int(organizationHandle, _contacts_company.type, type);
1952
1953         // label
1954         stringValue = organization.GetLabel();
1955         if (!stringValue.IsEmpty())
1956         {
1957                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1958                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1959
1960                 contacts_record_set_str(organizationHandle, _contacts_company.label, pCharArray.get());
1961         }
1962
1963         // description
1964         stringValue = organization.GetDescription();
1965         if (!stringValue.IsEmpty())
1966         {
1967                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1968                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1969
1970                 contacts_record_set_str(organizationHandle, _contacts_company.description, pCharArray.get());
1971         }
1972
1973         // location
1974         stringValue = organization.GetLocation();
1975         if (!stringValue.IsEmpty())
1976         {
1977                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1978                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1979
1980                 contacts_record_set_str(organizationHandle, _contacts_company.location, pCharArray.get());
1981         }
1982
1983         // phonetic name
1984         stringValue = organization.GetPhoneticName();
1985         if (!stringValue.IsEmpty())
1986         {
1987                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
1988                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1989
1990                 contacts_record_set_str(organizationHandle, _contacts_company.phonetic_name, pCharArray.get());
1991         }
1992
1993         // logo path
1994         if (_OrganizationImpl::GetInstance(organization)->IsLogoPathChanged() == true)
1995         {
1996                 stringValue = organization.GetLogoPath();
1997                 if (!stringValue.IsEmpty())
1998                 {
1999                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2000                         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2001
2002                         contacts_record_set_str(organizationHandle, _contacts_company.logo, pCharArray.get());
2003                 }
2004         }
2005
2006         ret = contacts_record_add_child_record(__contactHandle, _contacts_contact.company, organizationHandle);
2007         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2008
2009         recordHandle.Release();
2010
2011         return E_SUCCESS;
2012 }
2013
2014 result
2015 _ContactImpl::RemoveAt(ContactMultiPropertyId id, int index)
2016 {
2017         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);
2018
2019         unsigned int count = 0;
2020         contacts_record_h recordHandle = null;
2021
2022         switch (id)
2023         {
2024         case CONTACT_MPROPERTY_ID_PHONE_NUMBERS:
2025                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
2026                 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);
2027
2028                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.number, index, &recordHandle);
2029                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.number, recordHandle);
2030
2031                 break;
2032         case CONTACT_MPROPERTY_ID_EMAILS:
2033                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
2034                 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);
2035
2036                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.email, index, &recordHandle);
2037                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.email, recordHandle);
2038
2039                 break;
2040         case CONTACT_MPROPERTY_ID_URLS:
2041                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
2042                 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);
2043
2044                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.url, index, &recordHandle);
2045                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.url, recordHandle);
2046
2047                 break;
2048         case CONTACT_MPROPERTY_ID_ADDRESSES:
2049                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
2050                 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);
2051
2052                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.address, index, &recordHandle);
2053                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.address, recordHandle);
2054
2055                 break;
2056         case CONTACT_MPROPERTY_ID_IMADDRESSES:
2057                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
2058                 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);
2059
2060                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.messenger, index, &recordHandle);
2061                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.messenger, recordHandle);
2062
2063                 break;
2064         case CONTACT_MPROPERTY_ID_ORGANIZATIONS:
2065                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
2066                 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);
2067
2068                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, index, &recordHandle);
2069                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.company, recordHandle);
2070
2071                 break;
2072         case CONTACT_MPROPERTY_ID_EVENTS:
2073                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
2074                 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);
2075
2076                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, index, &recordHandle);
2077                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.event, recordHandle);
2078
2079                 break;
2080         case CONTACT_MPROPERTY_ID_RELATIONSHIPS:
2081                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.relationship, &count);
2082                 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);
2083
2084                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.relationship, index, &recordHandle);
2085                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.relationship, recordHandle);
2086
2087                 break;
2088         case CONTACT_MPROPERTY_ID_NOTES:
2089                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
2090                 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);
2091
2092                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, index, &recordHandle);
2093                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.note, recordHandle);
2094
2095                 break;
2096         case CONTACT_MPROPERTY_ID_NICKNAMES:
2097                 contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
2098                 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);
2099
2100                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, index, &recordHandle);
2101                 contacts_record_remove_child_record(__contactHandle, _contacts_contact.nickname, recordHandle);
2102
2103                 break;
2104         default:
2105                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
2106                 return E_INVALID_ARG;
2107         }
2108
2109         return E_SUCCESS;
2110 }
2111
2112 IList*
2113 _ContactImpl::GetValuesN(const ContactMultiPropertyId id)
2114 {
2115         IList* pList = null;
2116
2117         SetLastResult(E_SUCCESS);
2118
2119         switch (id)
2120         {
2121         case CONTACT_MPROPERTY_ID_PHONE_NUMBERS:
2122                 pList = GetPhoneNumbersN();
2123                 break;
2124
2125         case CONTACT_MPROPERTY_ID_EMAILS:
2126                 pList = GetEmailsN();
2127                 break;
2128
2129         case CONTACT_MPROPERTY_ID_URLS:
2130                 pList = GetUrlsN();
2131                 break;
2132
2133         case CONTACT_MPROPERTY_ID_ADDRESSES:
2134                 pList = GetAddressesN();
2135                 break;
2136
2137         case CONTACT_MPROPERTY_ID_IMADDRESSES:
2138                 pList = GetImAddressesN();
2139                 break;
2140
2141         case CONTACT_MPROPERTY_ID_ORGANIZATIONS:
2142                 pList = GetOrganizationsN();
2143                 break;
2144
2145         case CONTACT_MPROPERTY_ID_EVENTS:
2146                 pList = GetEventsN();
2147                 break;
2148
2149         case CONTACT_MPROPERTY_ID_RELATIONSHIPS:
2150                 pList = GetRelationshipsN();
2151                 break;
2152
2153         case CONTACT_MPROPERTY_ID_NOTES:
2154                 pList = GetNotesN();
2155                 break;
2156
2157         case CONTACT_MPROPERTY_ID_NICKNAMES:
2158                 pList = GetNicknamesN();
2159                 break;
2160         default:
2161                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. id=%d.", GetErrorMessage(E_INVALID_ARG), id);
2162                 return null;
2163         }
2164
2165         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2166
2167         return pList;
2168 }
2169
2170 result
2171 _ContactImpl::SetPhoneNumberAt(int index, const PhoneNumber& phoneNumber)
2172 {
2173         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);
2174         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));
2175         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2176
2177         unsigned int count = 0;
2178         contacts_record_h recordHandle = null;
2179         String stringValue;
2180         int type = 0;
2181         int oriType = 0;
2182
2183         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
2184         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);
2185
2186         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.number, index, &recordHandle);
2187
2188
2189         stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetLabel();
2190
2191         switch (_PhoneNumberImpl::GetInstance(phoneNumber)->GetType())
2192         {
2193                 case PHONENUMBER_TYPE_HOME:
2194                         type = CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE;
2195                         break;
2196                 case PHONENUMBER_TYPE_WORK:
2197                         type = CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE;
2198                         break;
2199                 case PHONENUMBER_TYPE_MOBILE:
2200                         type = CONTACTS_NUMBER_TYPE_CELL;
2201                         break;
2202                 case PHONENUMBER_TYPE_HOME_FAX:
2203                         type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME;
2204                         break;
2205                 case PHONENUMBER_TYPE_WORK_FAX:
2206                         type = CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK;
2207                         break;
2208                 case PHONENUMBER_TYPE_PAGER:
2209                         type = CONTACTS_NUMBER_TYPE_PAGER;
2210                         break;
2211                 case PHONENUMBER_TYPE_CUSTOM:
2212                         type = CONTACTS_NUMBER_TYPE_CUSTOM;
2213                         break;
2214                 case PHONENUMBER_TYPE_ASSISTANT:
2215                         type = CONTACTS_NUMBER_TYPE_ASSISTANT;
2216                         break;
2217                 case PHONENUMBER_TYPE_OTHER:
2218                         contacts_record_get_int(recordHandle, _contacts_number.type, &oriType);
2219
2220                         if (oriType == (CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE)
2221                                 || oriType == (CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE)
2222                                 || oriType == CONTACTS_NUMBER_TYPE_CELL
2223                                 || oriType == (CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME)
2224                                 || oriType == (CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK)
2225                                 || oriType == CONTACTS_NUMBER_TYPE_PAGER)
2226                         {
2227                                 type = CONTACTS_NUMBER_TYPE_OTHER;
2228                         }
2229                         else if (oriType == CONTACTS_NUMBER_TYPE_CUSTOM)
2230                         {
2231                                 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2232                                 {
2233                                         char* pCharValue = null;
2234
2235                                         contacts_record_get_str_p(recordHandle, _contacts_number.label, &pCharValue);
2236
2237                                         stringValue = pCharValue;
2238                                         type = CONTACTS_NUMBER_TYPE_CUSTOM;
2239
2240                                 }
2241                                 else
2242                                 {
2243                                         type = CONTACTS_NUMBER_TYPE_OTHER;
2244                                 }
2245                         }
2246                         else if (oriType == CONTACTS_NUMBER_TYPE_ASSISTANT)
2247                         {
2248                                 if (_AppInfo::GetApiVersion() < _API_VERSION_2_1)
2249                                 {
2250                                         type = CONTACTS_NUMBER_TYPE_ASSISTANT;
2251                                 }
2252                                 else
2253                                 {
2254                                         type = CONTACTS_NUMBER_TYPE_OTHER;
2255                                 }
2256                         }
2257                         else
2258                         {
2259                                 type = oriType;
2260                         }
2261                         break;
2262                 default:
2263                         type = CONTACTS_NUMBER_TYPE_OTHER;
2264                         break;
2265         }
2266
2267         // set type
2268         contacts_record_set_int(recordHandle, _contacts_number.type, type);
2269
2270         // set label
2271         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2272         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2273
2274         contacts_record_set_str(recordHandle, _contacts_number.label, pCharArray.get());
2275
2276         // set phone number
2277         stringValue = _PhoneNumberImpl::GetInstance(phoneNumber)->GetPhoneNumber();
2278         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
2279         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2280
2281         contacts_record_set_str(recordHandle, _contacts_number.number, pCharArray.get());
2282
2283         return E_SUCCESS;
2284 }
2285
2286 result
2287 _ContactImpl::SetNicknameAt(int index, const String& nickname)
2288 {
2289         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);
2290         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));
2291         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2292
2293         unsigned int count = 0;
2294         contacts_record_h nicknameHandle = null;
2295
2296         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
2297         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);
2298
2299         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, index, &nicknameHandle);
2300
2301         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(nickname));
2302         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2303
2304         contacts_record_set_str(nicknameHandle, _contacts_nickname.name, pCharArray.get());
2305
2306         return E_SUCCESS;
2307 }
2308
2309 result
2310 _ContactImpl::SetNoteAt(int index, const String& note)
2311 {
2312         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);
2313         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));
2314         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2315
2316         unsigned int count = 0;
2317         contacts_record_h noteHandle = null;
2318
2319         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
2320         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);
2321
2322         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, index, &noteHandle);
2323
2324         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(note));
2325         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2326
2327         contacts_record_set_str(noteHandle, _contacts_note.note, pCharArray.get());
2328
2329         return E_SUCCESS;
2330 }
2331
2332 result
2333 _ContactImpl::SetOrganizationAt(int index, const Organization& organization)
2334 {
2335         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);
2336         SysTryReturn(NID_SCL
2337                                           ,     !organization.GetName().IsEmpty() ||
2338                                                 !organization.GetJobTitle().IsEmpty() ||
2339                                                 !organization.GetDepartment().IsEmpty() ||
2340                                                 !organization.GetRole().IsEmpty() ||
2341                                                 !organization.GetAgent().IsEmpty() ||
2342                                                 !organization.GetDescription().IsEmpty() ||
2343                                                 !organization.GetLocation().IsEmpty() ||
2344                                                 !organization.GetPhoneticName().IsEmpty() ||
2345                                                 !organization.GetLogoPath().IsEmpty()
2346                                           ,E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The organization is empty.", GetErrorMessage(E_INVALID_ARG));
2347         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2348
2349         unsigned int count = 0;
2350         contacts_record_h organizationHandle = null;
2351
2352         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
2353         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);
2354
2355
2356         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, index, &organizationHandle);
2357
2358         // name
2359         String stringValue = organization.GetName();
2360         if (!stringValue.IsEmpty())
2361         {
2362                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2363                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2364
2365                 contacts_record_set_str(organizationHandle, _contacts_company.name, pCharArray.get());
2366         }
2367         else
2368         {
2369                 contacts_record_set_str(organizationHandle, _contacts_company.name, null);
2370         }
2371
2372         // job title
2373         stringValue = organization.GetJobTitle();
2374         if (!stringValue.IsEmpty())
2375         {
2376                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2377                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2378
2379                 contacts_record_set_str(organizationHandle, _contacts_company.job_title, pCharArray.get());
2380         }
2381         else
2382         {
2383                 contacts_record_set_str(organizationHandle, _contacts_company.job_title, null);
2384         }
2385
2386         // department
2387         stringValue = organization.GetDepartment();
2388         if (!stringValue.IsEmpty())
2389         {
2390                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2391                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2392
2393                 contacts_record_set_str(organizationHandle, _contacts_company.department, pCharArray.get());
2394         }
2395         else
2396         {
2397                 contacts_record_set_str(organizationHandle, _contacts_company.department, null);
2398         }
2399
2400         // role
2401         stringValue = organization.GetRole();
2402         if (!stringValue.IsEmpty())
2403         {
2404                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2405                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2406
2407                 contacts_record_set_str(organizationHandle, _contacts_company.role, pCharArray.get());
2408         }
2409         else
2410         {
2411                 contacts_record_set_str(organizationHandle, _contacts_company.role, null);
2412         }
2413
2414         // agent
2415         stringValue = organization.GetAgent();
2416         if (!stringValue.IsEmpty())
2417         {
2418                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2419                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2420
2421                 contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, pCharArray.get());
2422         }
2423         else
2424         {
2425                 contacts_record_set_str(organizationHandle, _contacts_company.assistant_name, null);
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         else
2458         {
2459                 contacts_record_set_str(organizationHandle, _contacts_company.label, null);
2460         }
2461
2462         // description
2463         stringValue = organization.GetDescription();
2464         if (!stringValue.IsEmpty())
2465         {
2466                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2467                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2468
2469                 contacts_record_set_str(organizationHandle, _contacts_company.description, pCharArray.get());
2470         }
2471         else
2472         {
2473                 contacts_record_set_str(organizationHandle, _contacts_company.description, null);
2474         }
2475
2476         // location
2477         stringValue = organization.GetLocation();
2478         if (!stringValue.IsEmpty())
2479         {
2480                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2481                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2482
2483                 contacts_record_set_str(organizationHandle, _contacts_company.location, pCharArray.get());
2484         }
2485         else
2486         {
2487                 contacts_record_set_str(organizationHandle, _contacts_company.location, null);
2488         }
2489
2490         // phonetic name
2491         stringValue = organization.GetPhoneticName();
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.phonetic_name, pCharArray.get());
2498         }
2499         else
2500         {
2501                 contacts_record_set_str(organizationHandle, _contacts_company.phonetic_name, null);
2502         }
2503
2504         // logo path
2505         if (_OrganizationImpl::GetInstance(organization)->IsLogoPathChanged() == true)
2506         {
2507                 stringValue = organization.GetLogoPath();
2508                 if (!stringValue.IsEmpty())
2509                 {
2510                         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2511                         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2512
2513                         contacts_record_set_str(organizationHandle, _contacts_company.logo, pCharArray.get());
2514                 }
2515                 else
2516                 {
2517                         contacts_record_set_str(organizationHandle, _contacts_company.logo, null);
2518                 }
2519         }
2520
2521         return E_SUCCESS;
2522 }
2523
2524 result
2525 _ContactImpl::SetEventAt(int index, const ContactEvent& event)
2526 {
2527         SysTryReturn(NID_SCL, index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index %d must be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), index);
2528         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2529
2530         int type = 0;
2531         int intValue = 0;
2532         unsigned int count = 0;
2533         String stringValue;
2534         contacts_record_h eventHandle = null;
2535
2536         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
2537         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);
2538
2539         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, index, &eventHandle);
2540
2541         switch (event.GetType())
2542         {
2543                 case CONTACT_EVENT_TYPE_ANNIVERSARY:
2544                         type = CONTACTS_EVENT_TYPE_ANNIVERSARY;
2545                         break;
2546                 case CONTACT_EVENT_TYPE_BIRTHDAY:
2547                         type = CONTACTS_EVENT_TYPE_BIRTH;
2548                         break;
2549                 case CONTACT_EVENT_TYPE_CUSTOM:
2550                         type = CONTACTS_EVENT_TYPE_CUSTOM;
2551                         break;
2552                 case CONTACT_EVENT_TYPE_OTHER:
2553                         // fall through
2554                 default:
2555                         type = CONTACTS_EVENT_TYPE_OTHER;
2556                         break;
2557         }
2558
2559         // type
2560         contacts_record_set_int(eventHandle, _contacts_event.type, type);
2561
2562         // label
2563         stringValue = event.GetLabel();
2564
2565         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2566         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2567
2568         contacts_record_set_str(eventHandle, _contacts_event.label, pCharArray.get());
2569
2570         // date
2571         DateTime dateValue = event.GetDate();
2572         intValue = dateValue.GetYear()*10000 + dateValue.GetMonth()*100 + dateValue.GetDay();
2573         contacts_record_set_int(eventHandle, _contacts_event.date, intValue);
2574
2575         return E_SUCCESS;
2576 }
2577
2578 result
2579 _ContactImpl::SetRelationshipAt(int index, const Relationship& relationship)
2580 {
2581         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);
2582         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));
2583         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2584
2585         int intValue = 0;
2586         unsigned int count = 0;
2587         contacts_record_h relationshipHandle = null;
2588
2589         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.relationship, &count);
2590         SysTryReturn(NID_SCL, count > (unsigned int)index, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index=%d must be less than the current count(%d) of relationships.", GetErrorMessage(E_OUT_OF_RANGE), index, count);
2591
2592         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.relationship, index, &relationshipHandle);
2593
2594         switch (relationship.GetType())
2595         {
2596                 case CONTACT_RELATIONSHIP_TYPE_ASSISTANT:
2597                         intValue = CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;
2598                         break;
2599                 case CONTACT_RELATIONSHIP_TYPE_BROTHER:
2600                         intValue = CONTACTS_RELATIONSHIP_TYPE_BROTHER;
2601                         break;
2602                 case CONTACT_RELATIONSHIP_TYPE_CHILD:
2603                         intValue = CONTACTS_RELATIONSHIP_TYPE_CHILD;
2604                         break;
2605                 case CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
2606                         intValue = CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER;
2607                         break;
2608                 case CONTACT_RELATIONSHIP_TYPE_FATHER:
2609                         intValue = CONTACTS_RELATIONSHIP_TYPE_FATHER;
2610                         break;
2611                 case CONTACT_RELATIONSHIP_TYPE_FRIEND:
2612                         intValue = CONTACTS_RELATIONSHIP_TYPE_FRIEND;
2613                         break;
2614                 case CONTACT_RELATIONSHIP_TYPE_MANAGER:
2615                         intValue = CONTACTS_RELATIONSHIP_TYPE_MANAGER;
2616                         break;
2617                 case CONTACT_RELATIONSHIP_TYPE_MOTHER:
2618                         intValue = CONTACTS_RELATIONSHIP_TYPE_MOTHER;
2619                         break;
2620                 case CONTACT_RELATIONSHIP_TYPE_PARENT:
2621                         intValue = CONTACTS_RELATIONSHIP_TYPE_PARENT;
2622                         break;
2623                 case CONTACT_RELATIONSHIP_TYPE_PARTNER:
2624                         intValue = CONTACTS_RELATIONSHIP_TYPE_PARTNER;
2625                         break;
2626                 case CONTACT_RELATIONSHIP_TYPE_REFERRED_BY:
2627                         intValue = CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY;
2628                         break;
2629                 case CONTACT_RELATIONSHIP_TYPE_RELATIVE:
2630                         intValue = CONTACTS_RELATIONSHIP_TYPE_RELATIVE;
2631                         break;
2632                 case CONTACT_RELATIONSHIP_TYPE_SISTER:
2633                         intValue = CONTACTS_RELATIONSHIP_TYPE_SISTER;
2634                         break;
2635                 case CONTACT_RELATIONSHIP_TYPE_SPOUSE:
2636                         intValue = CONTACTS_RELATIONSHIP_TYPE_SPOUSE;
2637                         break;
2638                 case CONTACT_RELATIONSHIP_TYPE_CUSTOM:
2639                         intValue = CONTACTS_RELATIONSHIP_TYPE_CUSTOM;
2640                         break;
2641                 default:
2642                         intValue = CONTACTS_RELATIONSHIP_TYPE_OTHER;
2643                         break;
2644         }
2645
2646         // type
2647         contacts_record_set_int(relationshipHandle, _contacts_relationship.type, intValue);
2648
2649         // label
2650         String stringValue = relationship.GetLabel();
2651         if (!stringValue.IsEmpty())
2652         {
2653                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2654                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2655
2656                 contacts_record_set_str(relationshipHandle, _contacts_relationship.label, pCharArray.get());
2657         }
2658         else
2659         {
2660                 contacts_record_set_str(relationshipHandle, _contacts_relationship.label, null);
2661         }
2662
2663         // name
2664         stringValue = relationship.GetRelativeName();
2665         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2666         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2667
2668         contacts_record_set_str(relationshipHandle, _contacts_relationship.name, pCharArray.get());
2669
2670         return E_SUCCESS;
2671 }
2672
2673 result
2674 _ContactImpl::SetEmailAt(int index, const Email& email)
2675 {
2676         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);
2677         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));
2678         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2679
2680         unsigned int count = 0;
2681         contacts_record_h emailHandle = null;
2682         String stringValue;
2683         int type = 0;
2684         int oriType = 0;
2685
2686         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
2687         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);
2688
2689         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.email, index, &emailHandle);
2690
2691         stringValue = _EmailImpl::GetInstance(email)->GetLabel();
2692
2693         switch (_EmailImpl::GetInstance(email)->GetType())
2694         {
2695                 case EMAIL_TYPE_PERSONAL:
2696                         type = CONTACTS_EMAIL_TYPE_HOME;
2697                         break;
2698                 case EMAIL_TYPE_WORK:
2699                         type = CONTACTS_EMAIL_TYPE_WORK;
2700                         break;
2701                 case EMAIL_TYPE_CUSTOM:
2702                         type = CONTACTS_EMAIL_TYPE_CUSTOM;
2703                         break;
2704                 case EMAIL_TYPE_MOBILE:
2705                         type = CONTACTS_EMAIL_TYPE_MOBILE;
2706                         break;
2707                 case EMAIL_TYPE_OTHER:
2708                         contacts_record_get_int(emailHandle, _contacts_email.type, &oriType);
2709                         if (oriType == CONTACTS_EMAIL_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
2710                         {
2711                                 char* pCharValue = null;
2712
2713                                 contacts_record_get_str_p(emailHandle, _contacts_email.label, &pCharValue);
2714
2715                                 stringValue = pCharValue;
2716                                 type = CONTACTS_EMAIL_TYPE_CUSTOM;
2717                         }
2718                         else if (oriType == CONTACTS_EMAIL_TYPE_MOBILE && _AppInfo::GetApiVersion() < _API_VERSION_2_1)
2719                         {
2720                                 type = CONTACTS_EMAIL_TYPE_MOBILE;
2721                         }
2722                         else
2723                         {
2724                                 type = CONTACTS_EMAIL_TYPE_OTHER;
2725                         }
2726                         break;
2727                 default:
2728                         type = CONTACTS_EMAIL_TYPE_OTHER;
2729                         break;
2730         }
2731
2732         // set type
2733         contacts_record_set_int(emailHandle, _contacts_email.type, type);
2734
2735         // set label
2736         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2737         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2738
2739         contacts_record_set_str(emailHandle, _contacts_email.label, pCharArray.get());
2740
2741         // set email
2742         stringValue = _EmailImpl::GetInstance(email)->GetEmail();
2743         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
2744         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2745
2746         contacts_record_set_str(emailHandle, _contacts_email.email, pCharArray.get());
2747
2748         return E_SUCCESS;
2749 }
2750
2751 result
2752 _ContactImpl::SetUrlAt(int index, const Url& url)
2753 {
2754         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);
2755         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));
2756         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2757
2758         unsigned int count = 0;
2759         contacts_record_h recordHandle = null;
2760         String stringValue;
2761         int type = 0;
2762         int oriType = 0;
2763
2764         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
2765         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);
2766
2767         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.url, index, &recordHandle);
2768
2769
2770         stringValue = _UrlImpl::GetInstance(url)->GetLabel();
2771
2772         switch (_UrlImpl::GetInstance(url)->GetType())
2773         {
2774                 case URL_TYPE_PERSONAL:
2775                         type = CONTACTS_URL_TYPE_HOME;
2776                         break;
2777                 case URL_TYPE_WORK:
2778                         type = CONTACTS_URL_TYPE_WORK;
2779                         break;
2780                 case URL_TYPE_CUSTOM:
2781                         type = CONTACTS_URL_TYPE_CUSTOM;
2782                         break;
2783                 case URL_TYPE_OTHER:
2784                         contacts_record_get_int(recordHandle, _contacts_url.type, &oriType);
2785
2786                         if (oriType == CONTACTS_URL_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
2787                         {
2788                                 char* pCharValue = null;
2789
2790                                 contacts_record_get_str_p(recordHandle, _contacts_url.label, &pCharValue);
2791
2792                                 stringValue = pCharValue;
2793                                 type = CONTACTS_URL_TYPE_CUSTOM;
2794                         }
2795                         else
2796                         {
2797                                 type = CONTACTS_URL_TYPE_OTHER;
2798                         }
2799                         break;
2800                 default:
2801                         type = CONTACTS_URL_TYPE_OTHER;
2802                         break;
2803         }
2804
2805         // set type
2806         contacts_record_set_int(recordHandle, _contacts_url.type, type);
2807
2808         // set label
2809         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2810         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2811
2812         contacts_record_set_str(recordHandle, _contacts_url.label, pCharArray.get());
2813
2814         // set url
2815         stringValue = _UrlImpl::GetInstance(url)->GetUrl();
2816         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
2817         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2818
2819         contacts_record_set_str(recordHandle, _contacts_url.url, pCharArray.get());
2820
2821         return E_SUCCESS;
2822 }
2823
2824 result
2825 _ContactImpl::SetAddressAt(int index, const Address& address)
2826 {
2827         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);
2828         SysTryReturn(NID_SCL,
2829                                           !address.GetCity().IsEmpty() ||
2830                                           !address.GetCountry().IsEmpty() ||
2831                                           !address.GetExtended().IsEmpty() ||
2832                                           !address.GetPostalCode().IsEmpty() ||
2833                                           !address.GetPostOfficeBoxNumber().IsEmpty() ||
2834                                           !address.GetState().IsEmpty() ||
2835                                           !address.GetStreet().IsEmpty(),
2836                                           E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The address is empty.", GetErrorMessage(E_INVALID_ARG));
2837         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2838
2839         unsigned int count = 0;
2840         contacts_record_h recordHandle = null;
2841         int type = 0;
2842         int oriType = 0;
2843         String stringValue;
2844
2845         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
2846         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);
2847
2848         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.address, index, &recordHandle);
2849
2850         stringValue = _AddressImpl::GetInstance(address)->GetLabel();
2851
2852         switch (_AddressImpl::GetInstance(address)->GetType())
2853         {
2854                 case ADDRESS_TYPE_HOME:
2855                         type = CONTACTS_ADDRESS_TYPE_HOME;
2856                         break;
2857                 case ADDRESS_TYPE_WORK:
2858                         type = CONTACTS_ADDRESS_TYPE_WORK;
2859                         break;
2860                 case ADDRESS_TYPE_CUSTOM:
2861                         type = CONTACTS_ADDRESS_TYPE_CUSTOM;
2862                         break;
2863                 case ADDRESS_TYPE_OTHER:
2864                         contacts_record_get_int(recordHandle, _contacts_address.type, &oriType);
2865
2866                         if (oriType == CONTACTS_ADDRESS_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
2867                         {
2868                                 char* pCharValue = null;
2869
2870                                 contacts_record_get_str_p(recordHandle, _contacts_address.label, &pCharValue);
2871
2872                                 stringValue = pCharValue;
2873                                 type = CONTACTS_ADDRESS_TYPE_CUSTOM;
2874                         }
2875                         else
2876                         {
2877                                 type = CONTACTS_ADDRESS_TYPE_OTHER;
2878                         }
2879                         break;
2880                 default:
2881                         type = CONTACTS_ADDRESS_TYPE_OTHER;
2882                         break;
2883         }
2884
2885         // set type
2886         contacts_record_set_int(recordHandle, _contacts_address.type, type);
2887
2888         // set label
2889         std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2890         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2891
2892         contacts_record_set_str(recordHandle, _contacts_address.label, pCharArray.get());
2893
2894         // address
2895         stringValue = _AddressImpl::GetInstance(address)->GetCity();
2896         if (!stringValue.IsEmpty())
2897         {
2898                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2899                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2900
2901                 contacts_record_set_str(recordHandle, _contacts_address.locality, pCharArray.get());
2902         }
2903         else
2904         {
2905                 contacts_record_set_str(recordHandle, _contacts_address.locality, null);
2906         }
2907
2908         stringValue = _AddressImpl::GetInstance(address)->GetCountry();
2909         if (!stringValue.IsEmpty())
2910         {
2911                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2912                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2913
2914                 contacts_record_set_str(recordHandle, _contacts_address.country, pCharArray.get());
2915         }
2916         else
2917         {
2918                 contacts_record_set_str(recordHandle, _contacts_address.country, null);
2919         }
2920
2921         stringValue = _AddressImpl::GetInstance(address)->GetExtended();
2922         if (!stringValue.IsEmpty())
2923         {
2924                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2925                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2926
2927                 contacts_record_set_str(recordHandle, _contacts_address.extended, pCharArray.get());
2928         }
2929         else
2930         {
2931                 contacts_record_set_str(recordHandle, _contacts_address.extended, null);
2932         }
2933
2934         stringValue = _AddressImpl::GetInstance(address)->GetPostalCode();
2935         if (!stringValue.IsEmpty())
2936         {
2937                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2938                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2939
2940                 contacts_record_set_str(recordHandle, _contacts_address.postal_code, pCharArray.get());
2941         }
2942         else
2943         {
2944                 contacts_record_set_str(recordHandle, _contacts_address.postal_code, null);
2945         }
2946
2947         stringValue = _AddressImpl::GetInstance(address)->GetPostOfficeBoxNumber();
2948         if (!stringValue.IsEmpty())
2949         {
2950                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2951                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2952
2953                 contacts_record_set_str(recordHandle, _contacts_address.postbox, pCharArray.get());
2954         }
2955         else
2956         {
2957                 contacts_record_set_str(recordHandle, _contacts_address.postbox, null);
2958         }
2959
2960         stringValue = _AddressImpl::GetInstance(address)->GetState();
2961         if (!stringValue.IsEmpty())
2962         {
2963                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2964                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2965
2966                 contacts_record_set_str(recordHandle, _contacts_address.region, pCharArray.get());
2967         }
2968         else
2969         {
2970                 contacts_record_set_str(recordHandle, _contacts_address.region, null);
2971         }
2972
2973         stringValue = _AddressImpl::GetInstance(address)->GetStreet();
2974         if (!stringValue.IsEmpty())
2975         {
2976                 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(stringValue));
2977                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2978
2979                 contacts_record_set_str(recordHandle, _contacts_address.street, pCharArray.get());
2980         }
2981         else
2982         {
2983                 contacts_record_set_str(recordHandle, _contacts_address.street, null);
2984         }
2985
2986         return E_SUCCESS;
2987 }
2988
2989 result
2990 _ContactImpl::SetImAddressAt(int index, const ImAddress& imAddress)
2991 {
2992         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);
2993         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));
2994         SysTryReturn(NID_SCL, !__isRemoved || Invalidate() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2995
2996         unsigned int count = 0;
2997         contacts_record_h messengerHandle = null;
2998         String stringValue;
2999         int type = 0;
3000         std::unique_ptr<char[]> pCharArray(null);
3001
3002         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
3003         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);
3004
3005         contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.messenger, index, &messengerHandle);
3006
3007         stringValue = _ImAddressImpl::GetInstance(imAddress)->GetServiceProviderName();
3008
3009         if (stringValue == IM_ADDRESS_GOOGLE_TALK)
3010         {
3011                 type = CONTACTS_MESSENGER_TYPE_GOOGLE;
3012         }
3013         else if (stringValue == IM_ADDRESS_MSN)
3014         {
3015                 type = CONTACTS_MESSENGER_TYPE_WLM;
3016         }
3017         else if (stringValue == IM_ADDRESS_ICQ)
3018         {
3019                 type = CONTACTS_MESSENGER_TYPE_ICQ;
3020         }
3021         else if (stringValue == IM_ADDRESS_AIM)
3022         {
3023                 type = CONTACTS_MESSENGER_TYPE_AIM;
3024         }
3025         else if (stringValue == IM_ADDRESS_YAHOO)
3026         {
3027                 type = CONTACTS_MESSENGER_TYPE_YAHOO;
3028         }
3029         else if (stringValue == IM_ADDRESS_QQ)
3030         {
3031                 type = CONTACTS_MESSENGER_TYPE_QQ;
3032         }
3033         else if (stringValue == IM_ADDRESS_SKYPE)
3034         {
3035                 type = CONTACTS_MESSENGER_TYPE_SKYPE;
3036         }
3037         else if (stringValue == IM_ADDRESS_JABBER)
3038         {
3039                 type = CONTACTS_MESSENGER_TYPE_JABBER;
3040         }
3041         else
3042         {
3043                 type = CONTACTS_MESSENGER_TYPE_CUSTOM;
3044         }
3045
3046         contacts_record_set_int(messengerHandle, _contacts_messenger.type, type);
3047         if (type == CONTACTS_MESSENGER_TYPE_CUSTOM)
3048         {
3049                 pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
3050                 SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3051
3052                 contacts_record_set_str(messengerHandle, _contacts_messenger.label, pCharArray.get());
3053         }
3054
3055         stringValue = _ImAddressImpl::GetInstance(imAddress)->GetImAddress();
3056         pCharArray.reset(_StringConverter::CopyToCharArrayN(stringValue));
3057         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3058
3059         contacts_record_set_str(messengerHandle, _contacts_messenger.im_id, pCharArray.get());
3060
3061         return E_SUCCESS;
3062 }
3063
3064 int
3065 _ContactImpl::GetMaxLength(ContactPropertyId id)
3066 {
3067         switch (id)
3068         {
3069         case CONTACT_PROPERTY_ID_FIRST_NAME:
3070                 //fall through
3071         case CONTACT_PROPERTY_ID_LAST_NAME:
3072                 //fall through
3073         case CONTACT_PROPERTY_ID_DISPLAY_NAME:
3074                 //fall through
3075         case CONTACT_PROPERTY_ID_NICK_NAME:
3076                 //fall through
3077         case CONTACT_PROPERTY_ID_MIDDLE_NAME:
3078                 return MAX_CONTACT_NAME_LENGTH;
3079
3080         case CONTACT_PROPERTY_ID_THUMBNAIL:
3081                 return -1;
3082
3083         case CONTACT_PROPERTY_ID_JOB_TITLE:
3084                 return MAX_CONTACT_JOB_TITLE_LENGTH;
3085
3086         case CONTACT_PROPERTY_ID_COMPANY:
3087                 return MAX_CONTACT_COMPANY_LENGTH;
3088
3089         case CONTACT_PROPERTY_ID_NOTE:
3090                 return MAX_CONTACT_NOTE_LENGTH;
3091
3092         case CONTACT_PROPERTY_ID_RINGTONE:
3093                 return -1;
3094
3095         case CONTACT_PROPERTY_ID_PHONETIC_FIRST_NAME:
3096                 //fall through
3097         case CONTACT_PROPERTY_ID_PHONETIC_LAST_NAME:
3098                 //fall through
3099         case CONTACT_PROPERTY_ID_PHONETIC_MIDDLE_NAME:
3100                 return MAX_CONTACT_NAME_LENGTH;
3101
3102         default:
3103                 return -1;
3104         }
3105 }
3106
3107 IList*
3108 _ContactImpl::GetOrganizationsN(void) const
3109 {
3110         result r = E_SUCCESS;
3111         contacts_record_h organizationHandle = null;
3112         int ret = CONTACTS_ERROR_NONE;
3113         char* pCharValue = null;
3114         int intValue = 0;
3115         unsigned int count = 0;
3116         std::unique_ptr<Organization> pOrganization(null);
3117
3118         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3119         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3120
3121         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
3122
3123         r = pList->Construct(count);
3124         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3125
3126         for (unsigned int i = 0; i < count; i++)
3127         {
3128                 ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, i, &organizationHandle);
3129                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
3130
3131                 pOrganization.reset(new (std::nothrow) Organization());
3132                 SysTryReturn(NID_SCL, pOrganization != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3133
3134                 // name
3135                 contacts_record_get_str_p(organizationHandle, _contacts_company.name, &pCharValue);
3136                 pOrganization->SetName(pCharValue);
3137
3138                 // job title
3139                 contacts_record_get_str_p(organizationHandle, _contacts_company.job_title, &pCharValue);
3140                 pOrganization->SetJobTitle(pCharValue);
3141
3142                 // department
3143                 contacts_record_get_str_p(organizationHandle, _contacts_company.department, &pCharValue);
3144                 pOrganization->SetDepartment(pCharValue);
3145
3146                 // role
3147                 contacts_record_get_str_p(organizationHandle, _contacts_company.role, &pCharValue);
3148                 pOrganization->SetRole(pCharValue);
3149
3150                 // agent
3151                 contacts_record_get_str_p(organizationHandle, _contacts_company.assistant_name, &pCharValue);
3152                 pOrganization->SetAgent(pCharValue);
3153
3154                 // type
3155                 contacts_record_get_int(organizationHandle, _contacts_company.type, &intValue);
3156                 switch (intValue)
3157                 {
3158                         case CONTACTS_COMPANY_TYPE_WORK:
3159                                 pOrganization->SetType(ORGANIZATION_TYPE_WORK);
3160                                 break;
3161                         case CONTACTS_COMPANY_TYPE_CUSTOM:
3162                                 pOrganization->SetType(ORGANIZATION_TYPE_CUSTOM);
3163                                 break;
3164                         case CONTACTS_COMPANY_TYPE_OTHER:
3165                                 // fall through
3166                         default:
3167                                 pOrganization->SetType(ORGANIZATION_TYPE_OTHER);
3168                                 break;
3169                 }
3170
3171                 // label
3172                 contacts_record_get_str_p(organizationHandle, _contacts_company.label, &pCharValue);
3173                 pOrganization->SetLabel(pCharValue);
3174
3175                 // description
3176                 contacts_record_get_str_p(organizationHandle, _contacts_company.description, &pCharValue);
3177                 pOrganization->SetDescription(pCharValue);
3178
3179                 // location
3180                 contacts_record_get_str_p(organizationHandle, _contacts_company.location, &pCharValue);
3181                 pOrganization->SetLocation(pCharValue);
3182
3183                 // phonetic name
3184                 contacts_record_get_str_p(organizationHandle, _contacts_company.phonetic_name, &pCharValue);
3185                 pOrganization->SetPhoneticName(pCharValue);
3186
3187                 // logo path
3188                 contacts_record_get_str_p(organizationHandle, _contacts_company.logo, &pCharValue);
3189                 _OrganizationImpl::GetInstance(*pOrganization)->SetLogoPath(pCharValue);
3190
3191                 r = pList->Add(*pOrganization);
3192                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3193
3194                 pOrganization.release();
3195         }
3196
3197         return pList.release();
3198 }
3199
3200 IList*
3201 _ContactImpl::GetRelationshipsN(void) const
3202 {
3203         result r = E_SUCCESS;
3204         contacts_record_h relationshipHandle = null;
3205         int ret = CONTACTS_ERROR_NONE;
3206         int intValue = 0;
3207         char* pCharValue = null;
3208         unsigned int count = 0;
3209         std::unique_ptr<Relationship> pRelationship(null);
3210
3211         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3212         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3213
3214         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.relationship, &count);
3215
3216         r = pList->Construct(count);
3217         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3218
3219         for (unsigned int i = 0; i < count; i++)
3220         {
3221                 ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.relationship, i, &relationshipHandle);
3222                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
3223
3224                 pRelationship.reset(new (std::nothrow) Relationship());
3225                 SysTryReturn(NID_SCL, pRelationship != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3226
3227                 // type
3228                 contacts_record_get_int(relationshipHandle, _contacts_relationship.type, &intValue);
3229                 switch (intValue)
3230                 {
3231                 case CONTACTS_RELATIONSHIP_TYPE_ASSISTANT:
3232                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_ASSISTANT);
3233                         break;
3234                 case CONTACTS_RELATIONSHIP_TYPE_BROTHER:
3235                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_BROTHER);
3236                         break;
3237                 case CONTACTS_RELATIONSHIP_TYPE_CHILD:
3238                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_CHILD);
3239                         break;
3240                 case CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
3241                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_DOMESTIC_PARTNER);
3242                         break;
3243                 case CONTACTS_RELATIONSHIP_TYPE_FATHER:
3244                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_FATHER);
3245                         break;
3246                 case CONTACTS_RELATIONSHIP_TYPE_FRIEND:
3247                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_FRIEND);
3248                         break;
3249                 case CONTACTS_RELATIONSHIP_TYPE_MANAGER:
3250                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_MANAGER);
3251                         break;
3252                 case CONTACTS_RELATIONSHIP_TYPE_MOTHER:
3253                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_MOTHER);
3254                         break;
3255                 case CONTACTS_RELATIONSHIP_TYPE_PARENT:
3256                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_PARENT);
3257                         break;
3258                 case CONTACTS_RELATIONSHIP_TYPE_PARTNER:
3259                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_PARTNER);
3260                         break;
3261                 case CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY:
3262                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_REFERRED_BY);
3263                         break;
3264                 case CONTACTS_RELATIONSHIP_TYPE_RELATIVE:
3265                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_RELATIVE);
3266                         break;
3267                 case CONTACTS_RELATIONSHIP_TYPE_SISTER:
3268                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_SISTER);
3269                         break;
3270                 case CONTACTS_RELATIONSHIP_TYPE_SPOUSE:
3271                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_SPOUSE);
3272                         break;
3273                 case CONTACTS_RELATIONSHIP_TYPE_CUSTOM:
3274                         // fall through
3275                 default:
3276                         pRelationship->SetType(CONTACT_RELATIONSHIP_TYPE_CUSTOM);
3277                         break;
3278                 }
3279
3280                 // label
3281                 contacts_record_get_str_p(relationshipHandle, _contacts_relationship.label, &pCharValue);
3282                 pRelationship->SetLabel(pCharValue);
3283
3284                 // name
3285                 contacts_record_get_str_p(relationshipHandle, _contacts_relationship.name, &pCharValue);
3286                 pRelationship->SetRelativeName(pCharValue);
3287
3288                 r = pList->Add(*pRelationship);
3289                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3290
3291                 pRelationship.release();
3292         }
3293
3294         return pList.release();
3295 }
3296
3297 IList*
3298 _ContactImpl::GetEventsN(void) const
3299 {
3300         result r = E_SUCCESS;
3301         char* pCharValue = null;
3302         int intValue = 0;
3303         unsigned int count = 0;
3304         contacts_record_h eventHandle = null;
3305         std::unique_ptr<ContactEvent> pEvent(null);
3306
3307         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3308         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3309
3310         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
3311
3312         r = pList->Construct(count);
3313         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3314
3315         for (unsigned int i = 0; i < count; i++)
3316         {
3317                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &eventHandle);
3318
3319                 pEvent.reset(new (std::nothrow) ContactEvent());
3320                 SysTryReturn(NID_SCL, pEvent != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3321
3322                 // label
3323                 contacts_record_get_str_p(eventHandle, _contacts_event.label, &pCharValue);
3324                 pEvent->SetLabel(pCharValue);
3325
3326                 // type
3327                 contacts_record_get_int(eventHandle, _contacts_event.type, &intValue);
3328                 switch (intValue)
3329                 {
3330                 case CONTACTS_EVENT_TYPE_BIRTH:
3331                         pEvent->SetType(CONTACT_EVENT_TYPE_BIRTHDAY);
3332                         break;
3333                 case CONTACTS_EVENT_TYPE_ANNIVERSARY:
3334                         pEvent->SetType(CONTACT_EVENT_TYPE_ANNIVERSARY);
3335                         break;
3336                 case CONTACTS_URL_TYPE_CUSTOM:
3337                         pEvent->SetType(CONTACT_EVENT_TYPE_CUSTOM);
3338                         break;
3339                 default:
3340                         pEvent->SetType(CONTACT_EVENT_TYPE_OTHER);
3341                         break;
3342                 }
3343
3344                 DateTime dateTime;
3345
3346                 contacts_record_get_int(eventHandle, _contacts_event.date, &intValue);
3347                 __CONVERT_DATE_TO_DATETIME(intValue, dateTime);
3348                 pEvent->SetDate(dateTime);
3349
3350                 pList->Add(*pEvent);
3351                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3352
3353                 pEvent.release();
3354         }
3355
3356         return pList.release();
3357 }
3358
3359 IList*
3360 _ContactImpl::GetNotesN(void) const
3361 {
3362         result r = E_SUCCESS;
3363         char* pCharValue = null;
3364         unsigned int count = 0;
3365         contacts_record_h noteHandle = null;
3366         std::unique_ptr<String> pNote(null);
3367
3368         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3369         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3370
3371         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
3372
3373         r = pList->Construct(count);
3374         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3375
3376         for (unsigned int i = 0; i < count; i++)
3377         {
3378                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, i, &noteHandle);
3379
3380                 contacts_record_get_str_p(noteHandle, _contacts_note.note, &pCharValue);
3381
3382                 pNote.reset(new (std::nothrow) String(pCharValue));
3383                 SysTryReturn(NID_SCL, pNote != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3384
3385                 pList->Add(*pNote);
3386                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3387
3388                 pNote.release();
3389         }
3390
3391         return pList.release();
3392 }
3393
3394 IList*
3395 _ContactImpl::GetNicknamesN(void) const
3396 {
3397         result r = E_SUCCESS;
3398         char* pCharValue = null;
3399         unsigned int count = 0;
3400         contacts_record_h nicknameHandle = null;
3401         std::unique_ptr<String> pNickname(null);
3402
3403         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3404         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3405
3406         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
3407
3408         r = pList->Construct(count);
3409         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3410
3411         for (unsigned int i = 0; i < count; i++)
3412         {
3413                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, i, &nicknameHandle);
3414
3415                 contacts_record_get_str_p(nicknameHandle, _contacts_nickname.name, &pCharValue);
3416         
3417                 pNickname.reset(new (std::nothrow) String(pCharValue));
3418                 SysTryReturn(NID_SCL, pNickname != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3419
3420                 pList->Add(*pNickname);
3421                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3422
3423                 pNickname.release();
3424         }
3425
3426         return pList.release();
3427 }
3428
3429 IList*
3430 _ContactImpl::GetPhoneNumbersN(void) const
3431 {
3432         result r = E_SUCCESS;
3433         unsigned int count = 0;
3434         contacts_record_h numberHandle = null;
3435         int intValue = 0;
3436         char* pCharValue = null;
3437         PhoneNumberType type = PHONENUMBER_TYPE_HOME;
3438         std::unique_ptr<PhoneNumber> pPhoneNumber(null);
3439
3440         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3441         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3442
3443
3444         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
3445
3446         contacts_record_get_int(__contactHandle, _contacts_contact.id, &intValue);
3447
3448         r = pList->Construct(count);
3449         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3450
3451         for (unsigned int i = 0; i < count; i++)
3452         {
3453                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.number, i, &numberHandle);
3454
3455                 pPhoneNumber.reset(new (std::nothrow) PhoneNumber());
3456                 SysTryReturn(NID_SCL, pPhoneNumber != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3457
3458                 contacts_record_get_int(numberHandle, _contacts_number.id, &intValue);
3459                 _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetRecordId(intValue);
3460
3461                 contacts_record_get_str_p(numberHandle, _contacts_number.label, &pCharValue);
3462                 _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetLabel(pCharValue);
3463
3464                 contacts_record_get_int(numberHandle, _contacts_number.type, &intValue);
3465
3466                 switch (intValue)
3467                 {
3468                         case CONTACTS_NUMBER_TYPE_HOME:
3469                                 // fall through
3470                         case CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE:
3471                                 type = PHONENUMBER_TYPE_HOME;
3472                                 break;
3473                         case CONTACTS_NUMBER_TYPE_WORK:
3474                                 // fall through
3475                         case CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE:
3476                                 type = PHONENUMBER_TYPE_WORK;
3477                                 break;
3478                         case CONTACTS_NUMBER_TYPE_CELL:
3479                                 type = PHONENUMBER_TYPE_MOBILE;
3480                                 break;
3481                         case CONTACTS_NUMBER_TYPE_FAX:
3482                                 // fall through
3483                         case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME:
3484                                 type = PHONENUMBER_TYPE_HOME_FAX;
3485                                 break;
3486                         case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK:
3487                                 type = PHONENUMBER_TYPE_WORK_FAX;
3488                                 break;
3489                         case CONTACTS_NUMBER_TYPE_PAGER:
3490                                 type = PHONENUMBER_TYPE_PAGER;
3491                                 break;
3492                         case CONTACTS_NUMBER_TYPE_CUSTOM:
3493                                 type = PHONENUMBER_TYPE_CUSTOM;
3494                                 break;
3495                         case CONTACTS_NUMBER_TYPE_ASSISTANT:
3496                                 if (_AppInfo::GetApiVersion() < _API_VERSION_2_1)
3497                                 {
3498                                         type = PHONENUMBER_TYPE_OTHER;
3499                                 }
3500                                 else
3501                                 {
3502                                         type = PHONENUMBER_TYPE_ASSISTANT;
3503                                 }
3504                                 break;
3505                         case CONTACTS_NUMBER_TYPE_OTHER:
3506                                 type = PHONENUMBER_TYPE_OTHER;
3507                                 break;
3508                         default:
3509                                 if (intValue & CONTACTS_NUMBER_TYPE_FAX)
3510                                 {
3511                                         type = PHONENUMBER_TYPE_HOME_FAX;
3512                                 }
3513                                 else if (intValue & CONTACTS_NUMBER_TYPE_CELL)
3514                                 {
3515                                         type = PHONENUMBER_TYPE_MOBILE;
3516                                 }
3517                                 else if (intValue & CONTACTS_NUMBER_TYPE_PAGER)
3518                                 {
3519                                         type = PHONENUMBER_TYPE_PAGER;
3520                                 }
3521                                 else if (intValue & CONTACTS_NUMBER_TYPE_HOME)
3522                                 {
3523                                         type = PHONENUMBER_TYPE_HOME;
3524                                 }
3525                                 else if (intValue & CONTACTS_NUMBER_TYPE_WORK)
3526                                 {
3527                                         type = PHONENUMBER_TYPE_WORK;
3528                                 }
3529                                 else if (intValue & CONTACTS_NUMBER_TYPE_VOICE)
3530                                 {
3531                                         type = PHONENUMBER_TYPE_HOME;
3532                                 }
3533                                 else
3534                                 {
3535                                         type = PHONENUMBER_TYPE_OTHER;
3536                                 }
3537                                 break;
3538                 }
3539
3540                 _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetType(type);
3541
3542                 contacts_record_get_str_p(numberHandle, _contacts_number.number, &pCharValue);
3543                 _PhoneNumberImpl::GetInstance(*pPhoneNumber)->SetPhoneNumber(pCharValue);
3544
3545                 r = pList->Add(*pPhoneNumber);
3546                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3547
3548                 pPhoneNumber.release();
3549         }
3550
3551         return pList.release();
3552 }
3553
3554 IList*
3555 _ContactImpl::GetEmailsN(void) const
3556 {
3557         result r = E_SUCCESS;
3558         contacts_record_h currentHandle = null;
3559         int ret = CONTACTS_ERROR_NONE;
3560         int intValue = 0;
3561         unsigned int count = 0;
3562         char* pCharValue = null;
3563         EmailType type = EMAIL_TYPE_PERSONAL;
3564         std::unique_ptr<Email> pEmail(null);
3565
3566         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3567         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3568
3569         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
3570
3571         r = pList->Construct(count);
3572         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3573
3574         for (unsigned int i = 0; i < count; i++)
3575         {
3576                 ret = contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.email, i, &currentHandle);
3577                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM))
3578
3579                 pEmail.reset(new (std::nothrow) Email());
3580                 SysTryReturn(NID_SCL, pEmail != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3581
3582                 contacts_record_get_int(currentHandle, _contacts_email.id, &intValue);
3583                 _EmailImpl::GetInstance(*pEmail)->SetRecordId(intValue);
3584
3585                 contacts_record_get_str_p(currentHandle, _contacts_email.label, &pCharValue);
3586                 _EmailImpl::GetInstance(*pEmail)->SetLabel(pCharValue);
3587
3588                 contacts_record_get_int(currentHandle, _contacts_email.type, &intValue);
3589                 switch (intValue)
3590                 {
3591                 case CONTACTS_EMAIL_TYPE_HOME:
3592                         type = EMAIL_TYPE_PERSONAL;
3593                         break;
3594                 case CONTACTS_EMAIL_TYPE_WORK:
3595                         type = EMAIL_TYPE_WORK;
3596                         break;
3597                 case CONTACTS_EMAIL_TYPE_CUSTOM:
3598                         type = EMAIL_TYPE_CUSTOM;
3599                         break;
3600                 case CONTACTS_EMAIL_TYPE_MOBILE:
3601                         if (_AppInfo::GetApiVersion() < _API_VERSION_2_1)
3602                         {
3603                                 type = EMAIL_TYPE_OTHER;
3604                         }
3605                         else
3606                         {
3607                                 type = EMAIL_TYPE_MOBILE;
3608                         }
3609                         break;
3610                 default:
3611                         type = EMAIL_TYPE_OTHER;
3612                         break;
3613                 }
3614
3615                 _EmailImpl::GetInstance(*pEmail)->SetType(type);
3616
3617                 contacts_record_get_str_p(currentHandle, _contacts_email.email, &pCharValue);
3618                 _EmailImpl::GetInstance(*pEmail)->SetEmail(pCharValue);
3619
3620                 r = pList->Add(*pEmail);
3621                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3622
3623                 pEmail.release();
3624         }
3625
3626         return pList.release();
3627 }
3628
3629 IList*
3630 _ContactImpl::GetUrlsN(void) const
3631 {
3632         result r = E_SUCCESS;
3633         char* pCharValue = null;
3634         int intValue = 0;
3635         unsigned int count = 0;
3636         UrlType type = URL_TYPE_PERSONAL;
3637         contacts_record_h urlHandle = null;
3638         std::unique_ptr<Url> pUrl(null);
3639
3640         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3641         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3642
3643         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
3644
3645         r = pList->Construct(count);
3646         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3647
3648         for (unsigned int i = 0; i < count; i++)
3649         {
3650                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.url, i, &urlHandle);
3651
3652                 pUrl.reset(new (std::nothrow) Url());
3653                 SysTryReturn(NID_SCL, pUrl != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3654
3655                 contacts_record_get_str_p(urlHandle, _contacts_url.label, &pCharValue);
3656                 pUrl->SetLabel(pCharValue);
3657
3658                 contacts_record_get_int(urlHandle, _contacts_url.type, &intValue);
3659                 switch (intValue)
3660                 {
3661                 case CONTACTS_URL_TYPE_HOME:
3662                         type = URL_TYPE_PERSONAL;
3663                         break;
3664                 case CONTACTS_URL_TYPE_WORK:
3665                         type = URL_TYPE_WORK;
3666                         break;
3667                 case CONTACTS_URL_TYPE_CUSTOM:
3668                         type = URL_TYPE_CUSTOM;
3669                         break;
3670                 default:
3671                         type = URL_TYPE_OTHER;
3672                         break;
3673                 }
3674
3675                 pUrl->SetType(type);
3676
3677                 contacts_record_get_str_p(urlHandle, _contacts_url.url, &pCharValue);
3678                 _UrlImpl::GetInstance(*pUrl)->SetUrl(pCharValue);
3679
3680                 pList->Add(*pUrl);
3681                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3682
3683                 pUrl.release();
3684         }
3685
3686         return pList.release();
3687 }
3688
3689 IList*
3690 _ContactImpl::GetAddressesN(void) const
3691 {
3692         result r = E_SUCCESS;
3693         char* pCharValue = null;
3694         int intValue = 0;
3695         unsigned int count = 0;
3696         contacts_record_h addressHandle = 0;
3697         std::unique_ptr<Address> pAddress(null);
3698
3699         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3700         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3701
3702         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
3703
3704         r = pList->Construct(count);
3705         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3706
3707
3708         for (unsigned int i = 0; i < count; i++)
3709         {
3710                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.address, i, &addressHandle);
3711
3712                 pAddress.reset(new (std::nothrow) Address());
3713                 SysTryReturn(NID_SCL, pAddress != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3714
3715                 contacts_record_get_str_p(addressHandle, _contacts_address.label, &pCharValue);
3716                 pAddress->SetLabel(pCharValue);
3717
3718                 contacts_record_get_int(addressHandle, _contacts_address.type, &intValue);
3719                 switch (intValue)
3720                 {
3721                 case CONTACTS_ADDRESS_TYPE_HOME:
3722                         pAddress->SetType(ADDRESS_TYPE_HOME);
3723                         break;
3724                 case CONTACTS_ADDRESS_TYPE_WORK:
3725                         pAddress->SetType(ADDRESS_TYPE_WORK);
3726                         break;
3727                 case CONTACTS_ADDRESS_TYPE_CUSTOM:
3728                         pAddress->SetType(ADDRESS_TYPE_CUSTOM);
3729                         break;
3730                 default:
3731                         pAddress->SetType(ADDRESS_TYPE_OTHER);
3732                         break;
3733                 }
3734
3735                 // 1. country
3736                 contacts_record_get_str_p(addressHandle, _contacts_address.country, &pCharValue);
3737                 _AddressImpl::GetInstance(*pAddress)->SetCountry(pCharValue);
3738
3739                 // 2. region
3740                 contacts_record_get_str_p(addressHandle, _contacts_address.region, &pCharValue);
3741                 _AddressImpl::GetInstance(*pAddress)->SetState(pCharValue);
3742
3743                 // 3. city
3744                 contacts_record_get_str_p(addressHandle, _contacts_address.locality, &pCharValue);
3745                 _AddressImpl::GetInstance(*pAddress)->SetCity(pCharValue);
3746
3747                 // 4. street
3748                 contacts_record_get_str_p(addressHandle, _contacts_address.street, &pCharValue);
3749                 _AddressImpl::GetInstance(*pAddress)->SetStreet(pCharValue);
3750
3751                 // 5. extended
3752                 contacts_record_get_str_p(addressHandle, _contacts_address.extended, &pCharValue);
3753                 _AddressImpl::GetInstance(*pAddress)->SetExtended(pCharValue);
3754
3755                 // 6. postbox
3756                 contacts_record_get_str_p(addressHandle, _contacts_address.postbox, &pCharValue);
3757                 _AddressImpl::GetInstance(*pAddress)->SetPostOfficeBoxNumber(pCharValue);
3758
3759                 // 7. postal code
3760                 contacts_record_get_str_p(addressHandle, _contacts_address.postal_code, &pCharValue);
3761                 _AddressImpl::GetInstance(*pAddress)->SetPostalCode(pCharValue);
3762
3763                 r = pList->Add(*pAddress);
3764                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3765
3766                 pAddress.release();
3767         }
3768
3769         return pList.release();
3770 }
3771
3772 IList*
3773 _ContactImpl::GetImAddressesN(void) const
3774 {
3775         result r = E_SUCCESS;
3776         char* pCharValue = null;
3777         int intValue = 0;
3778         contacts_record_h messengerHandle = null;
3779         unsigned int count = 0;
3780         std::unique_ptr<ImAddress> pImAddress(null);
3781
3782         std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
3783         SysTryReturn(NID_SCL, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3784
3785         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
3786
3787         r = pList->Construct(count);
3788         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3789
3790
3791         for (unsigned int i = 0; i < count; i++)
3792         {
3793                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.messenger, i, &messengerHandle);
3794
3795                 pImAddress.reset(new (std::nothrow) ImAddress());
3796                 SysTryReturn(NID_SCL, pImAddress != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3797
3798                 contacts_record_get_int(messengerHandle, _contacts_messenger.type, &intValue);
3799                 switch (intValue)
3800                 {
3801                 case CONTACTS_MESSENGER_TYPE_GOOGLE:
3802                         pImAddress->SetServiceProviderName(IM_ADDRESS_GOOGLE_TALK);
3803                         break;
3804                 case CONTACTS_MESSENGER_TYPE_WLM:
3805                         pImAddress->SetServiceProviderName(IM_ADDRESS_MSN);
3806                         break;
3807                 case CONTACTS_MESSENGER_TYPE_ICQ:
3808                         pImAddress->SetServiceProviderName(IM_ADDRESS_ICQ);
3809                         break;
3810                 case CONTACTS_MESSENGER_TYPE_AIM:
3811                         pImAddress->SetServiceProviderName(IM_ADDRESS_AIM);
3812                         break;
3813                 case CONTACTS_MESSENGER_TYPE_YAHOO:
3814                         pImAddress->SetServiceProviderName(IM_ADDRESS_YAHOO);
3815                         break;
3816                 case CONTACTS_MESSENGER_TYPE_QQ:
3817                         pImAddress->SetServiceProviderName(IM_ADDRESS_QQ);
3818                         break;
3819                 case CONTACTS_MESSENGER_TYPE_SKYPE:
3820                         pImAddress->SetServiceProviderName(IM_ADDRESS_SKYPE);
3821                         break;
3822                 case CONTACTS_MESSENGER_TYPE_JABBER:
3823                         pImAddress->SetServiceProviderName(IM_ADDRESS_JABBER);
3824                         break;
3825                 case CONTACTS_MESSENGER_TYPE_CUSTOM:
3826                         // fall through
3827                 default:
3828                         contacts_record_get_str_p(messengerHandle, _contacts_messenger.label, &pCharValue);
3829                         pImAddress->SetServiceProviderName(pCharValue);
3830                         break;
3831                 }
3832
3833                 contacts_record_get_str_p(messengerHandle, _contacts_messenger.im_id, &pCharValue);
3834                 _ImAddressImpl::GetInstance(*pImAddress)->SetImAddress(pCharValue);
3835
3836                 r = pList->Add(*pImAddress);
3837                 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3838
3839                 pImAddress.release();
3840         }
3841
3842         return pList.release();
3843 }
3844
3845 bool
3846 _ContactImpl::IsEmpty(void) const
3847 {
3848         char* pCharValue = null;
3849         unsigned int count = 0;
3850
3851         contacts_record_get_str_p(__contactHandle, _contacts_contact.ringtone_path, &pCharValue);
3852         if (pCharValue != null)
3853         {
3854                 return false;
3855         }
3856
3857         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
3858         if (count > 0)
3859         {
3860                 return false;
3861         }
3862
3863         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
3864         if (count > 0)
3865         {
3866                 return false;
3867         }
3868
3869         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
3870         if (count > 0)
3871         {
3872                 return false;
3873         }
3874
3875         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
3876         if (count > 0)
3877         {
3878                 return false;
3879         }
3880
3881         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
3882         if (count > 0)
3883         {
3884                 return false;
3885         }
3886
3887         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
3888         if (count > 0)
3889         {
3890                 return false;
3891         }
3892
3893         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
3894         if (count > 0)
3895         {
3896                 return false;
3897         }
3898
3899         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
3900         if (count > 0)
3901         {
3902                 return false;
3903         }
3904
3905         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
3906         if (count > 0)
3907         {
3908                 return false;
3909         }
3910
3911         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
3912         if (count > 0)
3913         {
3914                 return false;
3915         }
3916
3917         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
3918         if (count > 0)
3919         {
3920                 return false;
3921         }
3922
3923         contacts_record_get_str_p(__contactHandle, _contacts_contact.uid, &pCharValue);
3924         if (pCharValue != null)
3925         {
3926                 return false;
3927         }
3928
3929         return true;
3930 }
3931
3932 AddressbookId
3933 _ContactImpl::GetAddressbookId(void) const
3934 {
3935         int addressbookId = 0;
3936
3937         contacts_record_get_int(__contactHandle, _contacts_contact.address_book_id, &addressbookId);
3938
3939         return addressbookId;
3940 }
3941
3942 PersonId
3943 _ContactImpl::GetPersonId(void) const
3944 {
3945         int personId = 0;
3946
3947         contacts_record_get_int(__contactHandle, _contacts_contact.person_id, &personId);
3948
3949         return personId;
3950 }
3951
3952 void
3953 _ContactImpl::SetAsRemoved(void)
3954 {
3955         __isRemoved = true;
3956 }
3957
3958 bool
3959 _ContactImpl::IsRemoved(void) const
3960 {
3961         return __isRemoved;
3962 }
3963
3964 bool
3965 _ContactImpl::IsFavorite(void) const
3966 {
3967         bool isFavorite = false;
3968         contacts_record_get_bool(__contactHandle, _contacts_contact.is_favorite, &isFavorite);
3969
3970         return isFavorite;
3971 }
3972
3973 void
3974 _ContactImpl::SetAsFavorite(bool isFavorite)
3975 {
3976         contacts_record_set_bool(__contactHandle, _contacts_contact.is_favorite, isFavorite);
3977 }
3978
3979 result
3980 _ContactImpl::Invalidate(void)
3981 {
3982         int ret = CONTACTS_ERROR_NONE;
3983         unsigned int i = 0;
3984         unsigned int count = 0;
3985         char* pCharValue = null;
3986         int intValue = 0;
3987         bool boolValue = false;
3988
3989         contacts_record_h contactHandle = null;
3990         contacts_record_h sourceRecordHandle = null;
3991         contacts_record_h destRecordHandle = null;
3992
3993         ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
3994         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3995
3996         __ContactsRecordHandle recordHandle(contactHandle);
3997
3998         // favorite
3999         contacts_record_get_bool(sourceRecordHandle, _contacts_contact.is_favorite, &boolValue);
4000         contacts_record_set_bool(destRecordHandle, _contacts_contact.is_favorite, boolValue);
4001
4002         // uid
4003         contacts_record_get_str_p(sourceRecordHandle, _contacts_contact.uid, &pCharValue);
4004         contacts_record_set_str(destRecordHandle, _contacts_contact.uid, pCharValue);
4005
4006         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4007         // name
4008         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4009         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.name, &count);
4010         if (count > 0)
4011         {
4012                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.name, 0, &sourceRecordHandle);
4013
4014                 ret = contacts_record_create(_contacts_name._uri, &destRecordHandle);
4015                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4016
4017                 __ContactsRecordHandle nameHandle(destRecordHandle);
4018
4019                 // 1. first
4020                 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.first, &pCharValue);
4021                 contacts_record_set_str(destRecordHandle, _contacts_name.first, pCharValue);
4022
4023                 // 2. last
4024                 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.last, &pCharValue);
4025                 contacts_record_set_str(destRecordHandle, _contacts_name.last, pCharValue);
4026
4027                 // 3. addition
4028                 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.addition, &pCharValue);
4029                 contacts_record_set_str(destRecordHandle, _contacts_name.addition, pCharValue);
4030
4031                 // 4. suffix
4032                 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.suffix, &pCharValue);
4033                 contacts_record_set_str(destRecordHandle, _contacts_name.suffix, pCharValue);
4034
4035                 // 5. prefix
4036                 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.prefix, &pCharValue);
4037                 contacts_record_set_str(destRecordHandle, _contacts_name.prefix, pCharValue);
4038
4039                 // 6. phonetic_first
4040                 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_first, &pCharValue);
4041                 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_first, pCharValue);
4042
4043                 // 7. phonetic_last
4044                 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_last, &pCharValue);
4045                 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_last, pCharValue);
4046
4047                 // 8. phonetic_middle
4048                 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
4049                 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_middle, pCharValue);
4050
4051                 contacts_record_add_child_record(contactHandle, _contacts_contact.name, destRecordHandle);
4052
4053                 nameHandle.Release();
4054         }
4055
4056         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4057         // image
4058         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4059         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.image, &count);
4060         if (count > 0)
4061         {
4062                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.image, 0, &sourceRecordHandle);
4063
4064                 ret = contacts_record_create(_contacts_image._uri, &destRecordHandle);
4065                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4066
4067                 __ContactsRecordHandle imageHandle(destRecordHandle);
4068
4069                 contacts_record_get_int(sourceRecordHandle, _contacts_image.type, &intValue);
4070                 contacts_record_set_int(destRecordHandle, _contacts_image.type, intValue);
4071
4072                 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.label, &pCharValue);
4073                 contacts_record_set_str(destRecordHandle, _contacts_image.label, pCharValue);
4074
4075                 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.path, &pCharValue);
4076                 contacts_record_set_str(destRecordHandle, _contacts_image.path, pCharValue);
4077
4078                 contacts_record_add_child_record(contactHandle, _contacts_contact.image, destRecordHandle);
4079
4080                 imageHandle.Release();
4081         }
4082
4083         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4084         // company
4085         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4086         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.company, &count);
4087         for (i = 0; i < count; i++)
4088         {
4089                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.company, i, &sourceRecordHandle);
4090
4091                 ret = contacts_record_create(_contacts_company._uri, &destRecordHandle);
4092                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4093
4094                 __ContactsRecordHandle companyHandle(destRecordHandle);
4095
4096                 contacts_record_get_int(sourceRecordHandle, _contacts_company.type, &intValue);
4097                 contacts_record_set_int(destRecordHandle, _contacts_company.type, intValue);
4098
4099                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.name, &pCharValue);
4100                 contacts_record_set_str(destRecordHandle, _contacts_company.name, pCharValue);
4101
4102                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.department, &pCharValue);
4103                 contacts_record_set_str(destRecordHandle, _contacts_company.department, pCharValue);
4104
4105                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.job_title, &pCharValue);
4106                 contacts_record_set_str(destRecordHandle, _contacts_company.job_title, pCharValue);
4107
4108                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.assistant_name, &pCharValue);
4109                 contacts_record_set_str(destRecordHandle, _contacts_company.assistant_name, pCharValue);
4110
4111                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.role, &pCharValue);
4112                 contacts_record_set_str(destRecordHandle, _contacts_company.role, pCharValue);
4113
4114                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.logo, &pCharValue);
4115                 contacts_record_set_str(destRecordHandle, _contacts_company.logo, pCharValue);
4116
4117                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.location, &pCharValue);
4118                 contacts_record_set_str(destRecordHandle, _contacts_company.location, pCharValue);
4119
4120                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.description, &pCharValue);
4121                 contacts_record_set_str(destRecordHandle, _contacts_company.description, pCharValue);
4122
4123                 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.phonetic_name, &pCharValue);
4124                 contacts_record_set_str(destRecordHandle, _contacts_company.phonetic_name, pCharValue);
4125
4126                 contacts_record_add_child_record(contactHandle, _contacts_contact.company, destRecordHandle);
4127
4128                 companyHandle.Release();
4129         }
4130
4131         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4132         // note
4133         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4134         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.note, &count);
4135         for (i = 0; i < count; i++)
4136         {
4137                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.note, i, &sourceRecordHandle);
4138
4139                 ret = contacts_record_create(_contacts_note._uri, &destRecordHandle);
4140                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4141
4142                 __ContactsRecordHandle noteHandle(destRecordHandle);
4143
4144                 contacts_record_get_str_p(sourceRecordHandle, _contacts_note.note, &pCharValue);
4145                 contacts_record_set_str(destRecordHandle, _contacts_note.note, pCharValue);
4146
4147                 contacts_record_add_child_record(contactHandle, _contacts_contact.note, destRecordHandle);
4148
4149                 noteHandle.Release();
4150         }
4151
4152         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4153         // phone number
4154         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4155         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.number, &count);
4156         for (i = 0; i < count; i++)
4157         {
4158                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.number, i, &sourceRecordHandle);
4159
4160                 ret = contacts_record_create(_contacts_number._uri, &destRecordHandle);
4161                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4162
4163                 __ContactsRecordHandle numberHandle(destRecordHandle);
4164
4165                 contacts_record_get_int(sourceRecordHandle, _contacts_number.type, &intValue);
4166                 contacts_record_set_int(destRecordHandle, _contacts_number.type, intValue);
4167
4168                 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.label, &pCharValue);
4169                 contacts_record_set_str(destRecordHandle, _contacts_number.label, pCharValue);
4170
4171                 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.number, &pCharValue);
4172                 contacts_record_set_str(destRecordHandle, _contacts_number.number, pCharValue);
4173
4174                 contacts_record_add_child_record(contactHandle, _contacts_contact.number, destRecordHandle);
4175
4176                 numberHandle.Release();
4177         }
4178
4179         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4180         // email
4181         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4182         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.email, &count);
4183         for (i = 0; i < count; i++)
4184         {
4185                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.email, i, &sourceRecordHandle);
4186
4187                 ret = contacts_record_create(_contacts_email._uri, &destRecordHandle);
4188                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4189
4190                 __ContactsRecordHandle emailHandle(destRecordHandle);
4191
4192                 contacts_record_get_int(sourceRecordHandle, _contacts_email.type, &intValue);
4193                 contacts_record_set_int(destRecordHandle, _contacts_email.type, intValue);
4194
4195                 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.label, &pCharValue);
4196                 contacts_record_set_str(destRecordHandle, _contacts_email.label, pCharValue);
4197
4198                 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.email, &pCharValue);
4199                 contacts_record_set_str(destRecordHandle, _contacts_email.email, pCharValue);
4200
4201                 contacts_record_add_child_record(contactHandle, _contacts_contact.email, destRecordHandle);
4202
4203                 emailHandle.Release();
4204
4205         }
4206
4207         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4208         // event
4209         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4210         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.event, &count);
4211         for (i = 0; i < count; i++)
4212         {
4213                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.event, i, &sourceRecordHandle);
4214
4215                 ret = contacts_record_create(_contacts_event._uri, &destRecordHandle);
4216                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4217
4218                 __ContactsRecordHandle eventHandle(destRecordHandle);
4219
4220                 contacts_record_get_int(sourceRecordHandle, _contacts_event.type, &intValue);
4221                 contacts_record_set_int(destRecordHandle, _contacts_event.type, intValue);
4222
4223                 contacts_record_get_str_p(sourceRecordHandle, _contacts_event.label, &pCharValue);
4224                 contacts_record_set_str(destRecordHandle, _contacts_event.label, pCharValue);
4225
4226                 contacts_record_get_int(sourceRecordHandle, _contacts_event.date, &intValue);
4227                 contacts_record_set_int(destRecordHandle, _contacts_event.date, intValue);
4228
4229                 contacts_record_add_child_record(contactHandle, _contacts_contact.event, destRecordHandle);
4230
4231                 eventHandle.Release();
4232         }
4233
4234         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4235         // im address
4236         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4237         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.messenger, &count);
4238         for (i = 0; i < count; i++)
4239         {
4240                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.messenger, i, &sourceRecordHandle);
4241
4242                 ret = contacts_record_create(_contacts_messenger._uri, &destRecordHandle);
4243                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4244
4245                 __ContactsRecordHandle imAddressHandle(destRecordHandle);
4246
4247                 contacts_record_get_int(sourceRecordHandle, _contacts_messenger.type, &intValue);
4248                 contacts_record_set_int(destRecordHandle, _contacts_messenger.type, intValue);
4249
4250                 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.label, &pCharValue);
4251                 contacts_record_set_str(destRecordHandle, _contacts_messenger.label, pCharValue);
4252
4253                 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.im_id, &pCharValue);
4254                 contacts_record_set_str(destRecordHandle, _contacts_messenger.im_id, pCharValue);
4255
4256                 contacts_record_add_child_record(contactHandle, _contacts_contact.messenger, destRecordHandle);
4257
4258                 imAddressHandle.Release();
4259         }
4260
4261         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4262         // address
4263         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4264         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.address, &count);
4265         for (i = 0; i < count; i++)
4266         {
4267                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.address, i, &sourceRecordHandle);
4268
4269                 ret = contacts_record_create(_contacts_address._uri, &destRecordHandle);
4270                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4271
4272                 __ContactsRecordHandle addressHandle(destRecordHandle);
4273
4274                 contacts_record_get_int(sourceRecordHandle, _contacts_address.type, &intValue);
4275                 contacts_record_set_int(destRecordHandle, _contacts_address.type, intValue);
4276
4277                 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.label, &pCharValue);
4278                 contacts_record_set_str(destRecordHandle, _contacts_address.label, pCharValue);
4279
4280                 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postbox, &pCharValue);
4281                 contacts_record_set_str(destRecordHandle, _contacts_address.postbox, pCharValue);
4282
4283                 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.extended, &pCharValue);
4284                 contacts_record_set_str(destRecordHandle, _contacts_address.extended, pCharValue);
4285
4286                 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.street, &pCharValue);
4287                 contacts_record_set_str(destRecordHandle, _contacts_address.street, pCharValue);
4288
4289                 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.locality, &pCharValue);
4290                 contacts_record_set_str(destRecordHandle, _contacts_address.locality, pCharValue);
4291
4292                 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.region, &pCharValue);
4293                 contacts_record_set_str(destRecordHandle, _contacts_address.region, pCharValue);
4294
4295                 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postal_code, &pCharValue);
4296                 contacts_record_set_str(destRecordHandle, _contacts_address.postal_code, pCharValue);
4297
4298                 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.country, &pCharValue);
4299                 contacts_record_set_str(destRecordHandle, _contacts_address.country, pCharValue);
4300
4301                 contacts_record_add_child_record(contactHandle, _contacts_contact.address, destRecordHandle);
4302
4303                 addressHandle.Release();
4304         }
4305
4306         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4307         // url
4308         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4309         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.url, &count);
4310         for (i = 0; i < count; i++)
4311         {
4312                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.url, i, &sourceRecordHandle);
4313
4314                 ret = contacts_record_create(_contacts_url._uri, &destRecordHandle);
4315                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4316
4317                 __ContactsRecordHandle urlHandle(destRecordHandle);
4318
4319                 contacts_record_get_int(sourceRecordHandle, _contacts_url.type, &intValue);
4320                 contacts_record_set_int(destRecordHandle, _contacts_url.type, intValue);
4321
4322                 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.label, &pCharValue);
4323                 contacts_record_set_str(destRecordHandle, _contacts_url.label, pCharValue);
4324
4325                 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.url, &pCharValue);
4326                 contacts_record_set_str(destRecordHandle, _contacts_url.url, pCharValue);
4327
4328                 contacts_record_add_child_record(contactHandle, _contacts_contact.url, destRecordHandle);
4329
4330                 urlHandle.Release();
4331         }
4332
4333         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4334         // nickname
4335         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4336         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.nickname, &count);
4337         for (i = 0; i < count; i++)
4338         {
4339                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.nickname, i, &sourceRecordHandle);
4340
4341                 ret = contacts_record_create(_contacts_nickname._uri, &destRecordHandle);
4342                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4343
4344                 __ContactsRecordHandle nicknameHandle(destRecordHandle);
4345
4346                 contacts_record_get_str_p(sourceRecordHandle, _contacts_nickname.name, &pCharValue);
4347                 contacts_record_set_str(destRecordHandle, _contacts_nickname.name, pCharValue);
4348
4349                 contacts_record_add_child_record(contactHandle, _contacts_contact.nickname, destRecordHandle);
4350
4351                 nicknameHandle.Release();
4352         }
4353
4354         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4355         // relationship
4356         /////////////////////////////////////////////////////////////////////////////////////////////////////////////
4357         contacts_record_get_child_record_count(__contactHandle, _contacts_contact.relationship, &count);
4358         for (i = 0; i < count; i++)
4359         {
4360                 contacts_record_get_child_record_at_p(__contactHandle, _contacts_contact.relationship, i, &sourceRecordHandle);
4361
4362                 ret = contacts_record_create(_contacts_relationship._uri, &destRecordHandle);
4363                 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4364
4365                 __ContactsRecordHandle relationshipHandle(destRecordHandle);
4366
4367                 contacts_record_get_str_p(sourceRecordHandle, _contacts_relationship.name, &pCharValue);
4368                 contacts_record_set_str(destRecordHandle, _contacts_relationship.name, pCharValue);
4369
4370                 contacts_record_add_child_record(contactHandle, _contacts_contact.relationship, destRecordHandle);
4371
4372                 relationshipHandle.Release();
4373         }
4374
4375         contacts_record_destroy(__contactHandle, true);
4376         __contactHandle = contactHandle;
4377
4378         __isRemoved = false;
4379
4380         recordHandle.Release();
4381
4382         return E_SUCCESS;
4383 }
4384
4385 const _ContactImpl*
4386 _ContactImpl::GetInstance(const Contact& contact)
4387 {
4388         return contact.__pContactImpl;
4389 }
4390
4391 _ContactImpl*
4392 _ContactImpl::GetInstance(Contact& contact)
4393 {
4394         return contact.__pContactImpl;
4395 }
4396
4397 }} // Tizen::Social