2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file ContactObjectP2AConverter.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
22 * @brief Converter (contacts_record_h -> ContactPtr)
25 #include "ContactObjectP2AConverter.h"
29 #include <dpl/log/log.h>
30 #include <Commons/Exception.h>
31 #include <Commons/Regex.h>
32 #include "AddressBook.h"
34 #include "ContactUtility.h"
39 using namespace WrtDeviceApis::Commons;
42 ContactObjectP2AConverter::ContactObjectP2AConverter(contacts_record_h platformContact,
44 m_platformContact(platformContact),
45 m_abstractContact(ContactPtr(NULL)),
46 m_forScratch(forScratch),
47 m_convertFinished(false)
51 ContactObjectP2AConverter::ContactObjectP2AConverter(contacts_record_h platformContact,
53 ContactPtr &abstractContact) :
54 m_platformContact(platformContact),
55 m_abstractContact(abstractContact),
56 m_forScratch(forScratch),
57 m_convertFinished(false)
61 ContactObjectP2AConverter::~ContactObjectP2AConverter()
65 ContactPtr ContactObjectP2AConverter::getAbstractContact()
69 if(m_platformContact == NULL)
71 LogError("Platform contact object did not set");
72 ThrowMsg(InvalidArgumentException, "Platform contact object did not set");
75 if(m_abstractContact == NULL)
77 //LogDebug("Abstract contact object did not set, so a new object has been created");
78 m_abstractContact = ContactPtr(new Contact());
81 //LogDebug("for scratch : " << m_forScratch);
85 if(m_convertFinished == false)
86 convertToAbstractObject();
90 LogError("Error while converting - " << _rethrown_exception.GetMessage());
91 ThrowMsg(PlatformException, "Fail to convert platform object to abstract object.");
94 return m_abstractContact;
97 void ContactObjectP2AConverter::convertToAbstractObject()
99 exportBaseInfoValue();
105 exportGrouprelList();
109 exportNicknameList();
111 m_convertFinished = true;
114 void ContactObjectP2AConverter::exportBaseInfoValue()
121 contacts_record_get_int(m_platformContact, _contacts_contact.id, &id);
122 m_abstractContact->setId(id);
124 int addressBookId = 0;
125 contacts_record_get_int(m_platformContact, _contacts_contact.address_book_id, &addressBookId);
126 m_abstractContact->setAddressBookId(addressBookId);
129 contacts_record_get_int(m_platformContact, _contacts_contact.person_id, &personId);
130 m_abstractContact->setPersonId(personId);
133 contacts_record_get_int(m_platformContact, _contacts_contact.changed_time, &changedTime);
134 time_t changedTimeT = static_cast<time_t>(changedTime);
135 struct tm *changedTimeTm = gmtime(&changedTimeT);
136 m_abstractContact->setLastUpdated(*changedTimeTm);
138 bool isFavorite = false;
139 errorCode = contacts_record_get_bool(m_platformContact, _contacts_contact.is_favorite, &isFavorite);
140 if(errorCode != CONTACTS_ERROR_NONE)
141 LogError("contacts_record_get_bool returned " << errorCode);
142 m_abstractContact->setIsFavorite(isFavorite);
145 char *charValue = NULL;
147 contacts_record_get_str_p(m_platformContact, _contacts_contact.image_thumbnail_path, &charValue);
149 m_abstractContact->setPhotoURI(ContactUtility::convertPathToUri(charValue));
152 if(m_abstractContact->getPhotoURIIsSet())
153 m_abstractContact->unsetPhotoURI();
156 contacts_record_get_str_p(m_platformContact, _contacts_contact.ringtone_path, &charValue);
158 m_abstractContact->setRingtoneURI(ContactUtility::convertPathToUri(charValue));
161 if(m_abstractContact->getRingtoneURIIsSet())
162 m_abstractContact->unsetRingtoneURI();
167 contacts_record_get_str_p(m_platformContact, _contacts_contact.display_name, &charValue);
170 ContactNamePtr contactName = m_abstractContact->getName();
171 if(contactName == NULL)
173 contactName = ContactNamePtr(new ContactName());
174 m_abstractContact->setName(contactName);
176 contactName->setDisplayName(charValue);
179 // ThrowMsg(UnknownException, "converting base data (no display name)");
183 void ContactObjectP2AConverter::exportNameValue()
186 contacts_record_h child_record = NULL;
188 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.name, 0, &child_record);
189 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
190 ThrowMsg(UnknownException, "getting name value (err:" << errorCode << ")");
192 if(child_record == NULL || errorCode == CONTACTS_ERROR_NO_DATA)
194 //LogDebug("Platform contact don't have name value");
195 ContactNamePtr contactName = m_abstractContact->getName();
196 if(contactName != NULL)
198 if(contactName->getFirstNameIsSet())
199 contactName->unsetFirstName();
201 if(contactName->getMiddleNameIsSet())
202 contactName->unsetMiddleName();
204 if(contactName->getLastNameIsSet())
205 contactName->unsetLastName();
207 if(contactName->getPrefixIsSet())
208 contactName->unsetPrefix();
210 if(contactName->getSuffixIsSet())
211 contactName->unsetSuffix();
213 if(contactName->getPhoneticFirstNameIsSet())
214 contactName->unsetPhoneticFirstName();
216 if(contactName->getPhoneticLastNameIsSet())
217 contactName->unsetPhoneticLastName();
222 ContactNamePtr contactName = m_abstractContact->getName();
223 if(contactName == NULL)
225 contactName = ContactNamePtr(new ContactName());
226 m_abstractContact->setName(contactName);
229 char *charValue = NULL;
231 contacts_record_get_str_p(child_record, _contacts_name.first, &charValue);
233 contactName->setFirstName(charValue);
236 if(contactName->getFirstNameIsSet())
237 contactName->unsetFirstName();
240 contacts_record_get_str_p(child_record, _contacts_name.addition, &charValue);
242 contactName->setMiddleName(charValue);
245 if(contactName->getMiddleNameIsSet())
246 contactName->unsetMiddleName();
249 contacts_record_get_str_p(child_record, _contacts_name.last, &charValue);
251 contactName->setLastName(charValue);
254 if(contactName->getLastNameIsSet())
255 contactName->unsetLastName();
258 contacts_record_get_str_p(child_record, _contacts_name.prefix, &charValue);
260 contactName->setPrefix(charValue);
263 if(contactName->getPrefixIsSet())
264 contactName->unsetPrefix();
267 contacts_record_get_str_p(child_record, _contacts_name.suffix, &charValue);
269 contactName->setSuffix(charValue);
272 if(contactName->getSuffixIsSet())
273 contactName->unsetSuffix();
276 contacts_record_get_str_p(child_record, _contacts_name.phonetic_first, &charValue);
278 contactName->setPhoneticFirstName(charValue);
281 if(contactName->getPhoneticFirstNameIsSet())
282 contactName->unsetPhoneticFirstName();
285 contacts_record_get_str_p(child_record, _contacts_name.phonetic_last, &charValue);
287 contactName->setPhoneticLastName(charValue);
290 if(contactName->getPhoneticLastNameIsSet())
291 contactName->unsetPhoneticLastName();
295 void ContactObjectP2AConverter::exportCompanyList()
298 unsigned int child_count = 0;
300 if(m_abstractContact->getOrganizationsNum() > 0)
301 m_abstractContact->clearOrganizations();
303 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.company, &child_count);
304 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
305 ThrowMsg(UnknownException, "getting company list (err:" << errorCode << ")");
307 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
309 //LogDebug("Platform contact don't have company list");
313 ContactOrganizationArrayPtr organizations = m_abstractContact->getOrganizations();
315 for(unsigned int i=0; i<child_count; i++)
317 contacts_record_h child_record = NULL;
319 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.company, i, &child_record);
320 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
323 ContactOrganizationPtr organization(new ContactOrganization());
325 organizations->push_back(organization);
327 char *charValue = NULL;
329 contacts_record_get_str_p(child_record, _contacts_company.name, &charValue);
331 organization->setName(charValue);
334 if(organization->getNameIsSet())
335 organization->unsetName();
338 contacts_record_get_str_p(child_record, _contacts_company.department, &charValue);
340 organization->setDepartment(charValue);
343 if(organization->getDepartmentIsSet())
344 organization->unsetDepartment();
347 contacts_record_get_str_p(child_record, _contacts_company.job_title, &charValue);
349 organization->setTitle(charValue);
352 if(organization->getTitleIsSet())
353 organization->unsetTitle();
356 contacts_record_get_str_p(child_record, _contacts_company.role, &charValue);
358 organization->setRole(charValue);
361 if(organization->getRoleIsSet())
362 organization->unsetRole();
365 contacts_record_get_str_p(child_record, _contacts_company.logo, &charValue);
367 organization->setLogoURI(ContactUtility::convertPathToUri(charValue));
370 if(organization->getLogoURIIsSet())
371 organization->unsetLogoURI();
376 void ContactObjectP2AConverter::exportNoteList()
379 unsigned int child_count = 0;
381 if(m_abstractContact->getNotesNum() > 0)
382 m_abstractContact->clearNotes();
384 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.note, &child_count);
385 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
386 ThrowMsg(UnknownException, "getting note list (err:" << errorCode << ")");
388 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
390 //LogDebug("Platform contact don't have note list");
394 StringArrayPtr notes = m_abstractContact->getNotes();
396 for(unsigned int i=0; i<child_count; i++)
398 contacts_record_h child_record = NULL;
400 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.note, i, &child_record);
401 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
404 char *charValue = NULL;
406 contacts_record_get_str_p(child_record, _contacts_note.note, &charValue);
408 notes->push_back(charValue);
412 void ContactObjectP2AConverter::exportNumberList()
415 unsigned int child_count = 0;
417 if(m_abstractContact->getPhoneNumbersNum() > 0)
418 m_abstractContact->clearPhoneNumbers();
420 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.number, &child_count);
421 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
422 ThrowMsg(UnknownException, "getting number list (err:" << errorCode << ")");
424 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
426 //LogDebug("Platform contact don't have number list");
430 ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
432 for(unsigned int i=0; i<child_count; i++)
434 contacts_record_h child_record = NULL;
436 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.number, i, &child_record);
437 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
440 ContactPhoneNumberPtr phoneNumber(new ContactPhoneNumber());
442 char *charValue = NULL;
443 bool boolValue = false;
446 contacts_record_get_str_p(child_record, _contacts_number.number, &charValue);
449 phoneNumber->setNumber(charValue);
450 phoneNumbers->push_back(phoneNumber);
454 //LogDebug("Platform contact have a empty phone number");
458 contacts_record_get_bool(child_record, _contacts_number.is_default, &boolValue);
459 phoneNumber->setIsDefault(boolValue);
461 contacts_record_get_int(child_record, _contacts_number.type, &intValue);
462 if(intValue & CONTACTS_NUMBER_TYPE_HOME)
463 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_HOME);
464 if(intValue & CONTACTS_NUMBER_TYPE_WORK)
465 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_WORK);
466 if(intValue & CONTACTS_NUMBER_TYPE_VOICE)
467 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE);
468 if(intValue & CONTACTS_NUMBER_TYPE_FAX)
469 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_FAX);
470 if(intValue & CONTACTS_NUMBER_TYPE_MSG)
471 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MSG);
472 if(intValue & CONTACTS_NUMBER_TYPE_CELL)
473 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CELL);
474 if(intValue & CONTACTS_NUMBER_TYPE_PAGER)
475 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER);
476 if(intValue & CONTACTS_NUMBER_TYPE_BBS)
477 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_BBS);
478 if(intValue & CONTACTS_NUMBER_TYPE_MODEM)
479 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MODEM);
480 if(intValue & CONTACTS_NUMBER_TYPE_CAR)
481 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CAR);
482 if(intValue & CONTACTS_NUMBER_TYPE_ISDN)
483 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN);
484 if(intValue & CONTACTS_NUMBER_TYPE_VIDEO)
485 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO);
486 if(intValue & CONTACTS_NUMBER_TYPE_PCS)
487 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PCS);
489 if(phoneNumber->getTypes()->size() == 0)
490 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE);
492 // TODO Will be added after type changed to string
493 // if(intValue & CONTACTS_NUMBER_TYPE_CUSTOM)
495 // contacts_record_get_str_p(child_record, _contacts_number.label, &charValue);
497 // phoneNumber->addType(CUSTOM);
502 void ContactObjectP2AConverter::exportEmailList()
505 unsigned int child_count = 0;
507 if(m_abstractContact->getEmailsNum() > 0)
508 m_abstractContact->clearEmails();
510 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.email, &child_count);
511 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
512 ThrowMsg(UnknownException, "getting email list (err:" << errorCode << ")");
514 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
516 //LogDebug("Platform contact don't have email list");
520 ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
522 for(unsigned int i=0; i<child_count; i++)
524 contacts_record_h child_record = NULL;
526 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.email, i, &child_record);
527 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
530 ContactEmailAddressPtr email(new ContactEmailAddress());
532 char *charValue = NULL;
533 bool boolValue = false;
536 contacts_record_get_str_p(child_record, _contacts_email.email, &charValue);
539 email->setEmail(charValue);
540 emails->push_back(email);
544 //LogDebug("Platform contact have a empty email address");
548 contacts_record_get_bool(child_record, _contacts_email.is_default, &boolValue);
549 email->setIsDefault(boolValue);
551 contacts_record_get_int(child_record, _contacts_email.type, &intValue);
552 if(intValue & CONTACTS_EMAIL_TYPE_HOME)
553 email->addType(CONTACT_EMAIL_TYPE_HOME);
554 if(intValue & CONTACTS_EMAIL_TYPE_WORK)
555 email->addType(CONTACT_EMAIL_TYPE_WORK);
557 if(email->getTypes()->size() == 0)
558 email->addType(CONTACT_EMAIL_TYPE_HOME);
560 // TODO Will be added after type changed to string
561 // if(intValue & CONTACTS_EMAIL_TYPE_CUSTOM)
563 // contacts_record_get_str_p(child_record, _contacts_email.label, &charValue);
565 // email->addType(CUSTOM);
570 void ContactObjectP2AConverter::exportGrouprelList()
573 unsigned int child_count = 0;
575 if(m_abstractContact->getGroupIdsNum() > 0)
576 m_abstractContact->clearGroupIds();
578 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.group_relation, &child_count);
579 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
580 ThrowMsg(UnknownException, "getting group list (err:" << errorCode << ")");
582 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
584 //LogDebug("Platform contact don't have group list");
588 StringArrayPtr groupIds = m_abstractContact->getGroupIds();
590 for(unsigned int i=0; i<child_count; i++)
592 contacts_record_h child_record = NULL;
594 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.group_relation, i, &child_record);
595 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
600 contacts_record_get_int(child_record, _contacts_group_relation.group_id, &groupId);
602 groupIds->push_back(ContactUtility::intToStr(groupId));
606 void ContactObjectP2AConverter::exportEventList()
609 unsigned int child_count = 0;
611 if(m_abstractContact->getAnniversariesNum() > 0)
612 m_abstractContact->clearAnniversaries();
614 if(m_abstractContact->getBirthdayIsSet())
615 m_abstractContact->unsetBirthday();
617 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.event, &child_count);
618 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
619 ThrowMsg(UnknownException, "getting event list (err:" << errorCode << ")");
621 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
623 //LogDebug("Platform contact don't have group list");
627 ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
629 for(unsigned int i=0; i<child_count; i++)
631 contacts_record_h child_record = NULL;
633 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.event, i, &child_record);
634 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
637 char *charValue = NULL;
638 int intValueType = 0;
639 int intValueDate = 0;
641 contacts_record_get_int(child_record, _contacts_event.date, &intValueDate);
646 tmDate = ContactUtility::toDateTmFromDateDbInt(intValueDate);
648 LogError("date has wrong value");
651 contacts_record_get_int(child_record, _contacts_event.type, &intValueType);
652 if (intValueType == CONTACTS_EVENT_TYPE_BIRTH)
654 m_abstractContact->setBirthday(tmDate);
656 else if(intValueType == CONTACTS_EVENT_TYPE_ANNIVERSARY)
658 ContactAnniversaryPtr anniversary = ContactAnniversaryPtr(new ContactAnniversary());
660 anniversary->setDate(tmDate);
661 contacts_record_get_str_p(child_record, _contacts_event.label, &charValue);
663 anniversary->setLabel(charValue);
665 anniversaries->push_back(anniversary);
667 ContactAnniversaryPtr anniversary = ContactAnniversaryPtr(new ContactAnniversary());
669 anniversary->setDate(tmDate);
670 contacts_record_get_str_p(child_record, _contacts_event.label, &charValue);
672 anniversary->setLabel(charValue);
674 anniversaries->push_back(anniversary);
679 void ContactObjectP2AConverter::exportPostalList()
682 unsigned int child_count = 0;
684 if(m_abstractContact->getAddressesNum() > 0)
685 m_abstractContact->clearAddresses();
687 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.address, &child_count);
688 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
689 ThrowMsg(UnknownException, "getting address list (err:" << errorCode << ")");
691 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
693 //LogDebug("Platform contact don't have address list");
697 ContactAddressArrayPtr addresss = m_abstractContact->getAddresses();
699 for(unsigned int i=0; i<child_count; i++)
701 contacts_record_h child_record = NULL;
703 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.address, i, &child_record);
704 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
707 ContactAddressPtr address(new ContactAddress());
709 char *charValue = NULL;
710 bool boolValue = false;
713 addresss->push_back(address);
715 contacts_record_get_str_p(child_record, _contacts_address.postal_code, &charValue);
717 address->setPostalCode(charValue);
719 contacts_record_get_str_p(child_record, _contacts_address.region, &charValue);
721 address->setRegion(charValue);
723 contacts_record_get_str_p(child_record, _contacts_address.locality, &charValue);
725 address->setCity(charValue);
727 contacts_record_get_str_p(child_record, _contacts_address.street, &charValue);
729 address->setStreetAddress(charValue);
731 contacts_record_get_str_p(child_record, _contacts_address.extended, &charValue);
733 address->setAdditionalInformation(charValue);
735 contacts_record_get_str_p(child_record, _contacts_address.country, &charValue);
737 address->setCountry(charValue);
739 contacts_record_get_bool(child_record, _contacts_address.is_default, &boolValue);
740 address->setIsDefault(boolValue);
742 contacts_record_get_int(child_record, _contacts_address.type, &intValue);
743 if(intValue & CONTACTS_ADDRESS_TYPE_HOME)
744 address->addType(CONTACT_ADDRESS_TYPE_HOME);
745 if(intValue & CONTACTS_ADDRESS_TYPE_WORK)
746 address->addType(CONTACT_ADDRESS_TYPE_WORK);
748 if(address->getTypes()->size() == 0)
749 address->addType(CONTACT_ADDRESS_TYPE_HOME);
751 // TODO Will be added after type changed to string
752 // if(intValue & CONTACTS_ADDRESS_TYPE_CUSTOM)
754 // contacts_record_get_str_p(child_record, _contacts_address.label, &charValue);
756 // address->addType(CUSTOM);
761 void ContactObjectP2AConverter::exportWebAddrList()
764 unsigned int child_count = 0;
766 if(m_abstractContact->getUrlsNum() > 0)
767 m_abstractContact->clearUrls();
769 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.url, &child_count);
770 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
771 ThrowMsg(UnknownException, "getting address list (err:" << errorCode << ")");
773 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
775 //LogDebug("Platform contact don't have address list");
779 ContactWebSiteArrayPtr urls = m_abstractContact->getUrls();
781 for(unsigned int i=0; i<child_count; i++)
783 contacts_record_h child_record = NULL;
785 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.url, i, &child_record);
786 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
789 ContactWebSitePtr url(new ContactWebSite());
791 char *charValue = NULL;
794 urls->push_back(url);
796 contacts_record_get_str_p(child_record, _contacts_url.url, &charValue);
798 url->setUrl(charValue);
800 contacts_record_get_int(child_record, _contacts_url.type, &intValue);
801 if(intValue == CONTACTS_URL_TYPE_HOME)
802 url->setType(WEBSITE_TYPE_HOMEPAGE);
803 if(intValue == CONTACTS_URL_TYPE_WORK)
804 url->setType(WEBSITE_TYPE_BLOG);
806 if(url->getTypeIsSet() == false)
807 url->setType(WEBSITE_TYPE_HOMEPAGE);
809 // TODO Will be added after type changed to string
810 // if(intValue & CONTACTS_URL_TYPE_CUSTOM)
812 // contacts_record_get_int(child_record, _contacts_url.label, &intValue);
814 // url->setType(CUSTOM);
819 void ContactObjectP2AConverter::exportNicknameList()
822 unsigned int child_count = 0;
824 ContactNamePtr contactName = m_abstractContact->getName();
825 if(contactName == NULL)
827 contactName = ContactNamePtr(new ContactName());
828 m_abstractContact->setName(contactName);
831 if(contactName->getNicknamesNum() > 0)
832 contactName->clearNicknames();
834 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.nickname, &child_count);
835 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
836 ThrowMsg(UnknownException, "getting nickname list (err:" << errorCode << ")");
838 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
840 //LogDebug("Platform contact don't have nickname list");
844 StringArrayPtr nicknames = contactName->getNicknames();
846 for(unsigned int i=0; i<child_count; i++)
848 contacts_record_h child_record = NULL;
850 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.nickname, i, &child_record);
851 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
854 char *charValue = NULL;
856 contacts_record_get_str_p(child_record, _contacts_nickname.name, &charValue);
858 nicknames->push_back(charValue);