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"
28 #include <Commons/Exception.h>
29 #include <Commons/Regex.h>
30 #include "AddressBook.h"
32 #include "ContactUtility.h"
38 using namespace WrtDeviceApis::Commons;
41 ContactObjectP2AConverter::ContactObjectP2AConverter(contacts_record_h platformContact,
43 m_platformContact(platformContact),
44 m_abstractContact(ContactPtr(NULL)),
45 m_forScratch(forScratch),
46 m_convertFinished(false)
50 ContactObjectP2AConverter::ContactObjectP2AConverter(contacts_record_h platformContact,
52 ContactPtr &abstractContact) :
53 m_platformContact(platformContact),
54 m_abstractContact(abstractContact),
55 m_forScratch(forScratch),
56 m_convertFinished(false)
60 ContactObjectP2AConverter::~ContactObjectP2AConverter()
64 ContactPtr ContactObjectP2AConverter::getAbstractContact()
68 if(m_platformContact == NULL)
70 LoggerE("Platform contact object did not set");
71 ThrowMsg(InvalidArgumentException, "Platform contact object did not set");
74 if(m_abstractContact == NULL)
76 //LoggerD("Abstract contact object did not set, so a new object has been created");
77 m_abstractContact = ContactPtr(new Contact());
80 //LoggerD("for scratch : " << m_forScratch);
84 if(m_convertFinished == false)
85 convertToAbstractObject();
89 LoggerE("Error while converting - " << _rethrown_exception.GetMessage());
90 ThrowMsg(PlatformException, "Fail to convert platform object to abstract object.");
93 return m_abstractContact;
96 void ContactObjectP2AConverter::convertToAbstractObject()
98 exportBaseInfoValue();
104 exportGrouprelList();
108 exportNicknameList();
110 m_convertFinished = true;
113 void ContactObjectP2AConverter::exportBaseInfoValue()
120 contacts_record_get_int(m_platformContact, _contacts_contact.id, &id);
121 m_abstractContact->setId(id);
123 int addressBookId = 0;
124 contacts_record_get_int(m_platformContact, _contacts_contact.address_book_id, &addressBookId);
125 m_abstractContact->setAddressBookId(addressBookId);
128 contacts_record_get_int(m_platformContact, _contacts_contact.person_id, &personId);
129 m_abstractContact->setPersonId(personId);
132 contacts_record_get_int(m_platformContact, _contacts_contact.changed_time, &changedTime);
133 time_t changedTimeT = static_cast<time_t>(changedTime);
134 struct tm *changedTimeTm = gmtime(&changedTimeT);
135 m_abstractContact->setLastUpdated(*changedTimeTm);
137 bool isFavorite = false;
138 errorCode = contacts_record_get_bool(m_platformContact, _contacts_contact.is_favorite, &isFavorite);
139 if(errorCode != CONTACTS_ERROR_NONE)
140 LoggerE("contacts_record_get_bool returned " << errorCode);
141 m_abstractContact->setIsFavorite(isFavorite);
144 char *charValue = NULL;
146 contacts_record_get_str_p(m_platformContact, _contacts_contact.image_thumbnail_path, &charValue);
148 m_abstractContact->setPhotoURI(ContactUtility::convertPathToUri(charValue));
151 if(m_abstractContact->getPhotoURIIsSet())
152 m_abstractContact->unsetPhotoURI();
155 contacts_record_get_str_p(m_platformContact, _contacts_contact.ringtone_path, &charValue);
157 m_abstractContact->setRingtoneURI(ContactUtility::convertPathToUri(charValue));
160 if(m_abstractContact->getRingtoneURIIsSet())
161 m_abstractContact->unsetRingtoneURI();
166 contacts_record_get_str_p(m_platformContact, _contacts_contact.display_name, &charValue);
169 ContactNamePtr contactName = m_abstractContact->getName();
170 if(contactName == NULL)
172 contactName = ContactNamePtr(new ContactName());
173 m_abstractContact->setName(contactName);
175 contactName->setDisplayName(charValue);
178 // ThrowMsg(UnknownException, "converting base data (no display name)");
182 void ContactObjectP2AConverter::exportNameValue()
185 contacts_record_h child_record = NULL;
187 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.name, 0, &child_record);
188 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
189 ThrowMsg(UnknownException, "getting name value (err:" << errorCode << ")");
191 if(child_record == NULL || errorCode == CONTACTS_ERROR_NO_DATA)
193 //LoggerD("Platform contact don't have name value");
194 ContactNamePtr contactName = m_abstractContact->getName();
195 if(contactName != NULL)
197 if(contactName->getFirstNameIsSet())
198 contactName->unsetFirstName();
200 if(contactName->getMiddleNameIsSet())
201 contactName->unsetMiddleName();
203 if(contactName->getLastNameIsSet())
204 contactName->unsetLastName();
206 if(contactName->getPrefixIsSet())
207 contactName->unsetPrefix();
209 if(contactName->getSuffixIsSet())
210 contactName->unsetSuffix();
212 if(contactName->getPhoneticFirstNameIsSet())
213 contactName->unsetPhoneticFirstName();
215 if(contactName->getPhoneticLastNameIsSet())
216 contactName->unsetPhoneticLastName();
221 ContactNamePtr contactName = m_abstractContact->getName();
222 if(contactName == NULL)
224 contactName = ContactNamePtr(new ContactName());
225 m_abstractContact->setName(contactName);
228 char *charValue = NULL;
230 contacts_record_get_str_p(child_record, _contacts_name.first, &charValue);
232 contactName->setFirstName(charValue);
235 if(contactName->getFirstNameIsSet())
236 contactName->unsetFirstName();
239 contacts_record_get_str_p(child_record, _contacts_name.addition, &charValue);
241 contactName->setMiddleName(charValue);
244 if(contactName->getMiddleNameIsSet())
245 contactName->unsetMiddleName();
248 contacts_record_get_str_p(child_record, _contacts_name.last, &charValue);
250 contactName->setLastName(charValue);
253 if(contactName->getLastNameIsSet())
254 contactName->unsetLastName();
257 contacts_record_get_str_p(child_record, _contacts_name.prefix, &charValue);
259 contactName->setPrefix(charValue);
262 if(contactName->getPrefixIsSet())
263 contactName->unsetPrefix();
266 contacts_record_get_str_p(child_record, _contacts_name.suffix, &charValue);
268 contactName->setSuffix(charValue);
271 if(contactName->getSuffixIsSet())
272 contactName->unsetSuffix();
275 contacts_record_get_str_p(child_record, _contacts_name.phonetic_first, &charValue);
277 contactName->setPhoneticFirstName(charValue);
280 if(contactName->getPhoneticFirstNameIsSet())
281 contactName->unsetPhoneticFirstName();
284 contacts_record_get_str_p(child_record, _contacts_name.phonetic_last, &charValue);
286 contactName->setPhoneticLastName(charValue);
289 if(contactName->getPhoneticLastNameIsSet())
290 contactName->unsetPhoneticLastName();
294 void ContactObjectP2AConverter::exportCompanyList()
297 unsigned int child_count = 0;
299 if(m_abstractContact->getOrganizationsNum() > 0)
300 m_abstractContact->clearOrganizations();
302 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.company, &child_count);
303 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
304 ThrowMsg(UnknownException, "getting company list (err:" << errorCode << ")");
306 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
308 //LoggerD("Platform contact don't have company list");
312 ContactOrganizationArrayPtr organizations = m_abstractContact->getOrganizations();
314 for(unsigned int i=0; i<child_count; i++)
316 contacts_record_h child_record = NULL;
318 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.company, i, &child_record);
319 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
322 ContactOrganizationPtr organization(new ContactOrganization());
324 organizations->push_back(organization);
326 char *charValue = NULL;
328 contacts_record_get_str_p(child_record, _contacts_company.name, &charValue);
330 organization->setName(charValue);
333 if(organization->getNameIsSet())
334 organization->unsetName();
337 contacts_record_get_str_p(child_record, _contacts_company.department, &charValue);
339 organization->setDepartment(charValue);
342 if(organization->getDepartmentIsSet())
343 organization->unsetDepartment();
346 contacts_record_get_str_p(child_record, _contacts_company.job_title, &charValue);
348 organization->setTitle(charValue);
351 if(organization->getTitleIsSet())
352 organization->unsetTitle();
355 contacts_record_get_str_p(child_record, _contacts_company.role, &charValue);
357 organization->setRole(charValue);
360 if(organization->getRoleIsSet())
361 organization->unsetRole();
364 contacts_record_get_str_p(child_record, _contacts_company.logo, &charValue);
366 organization->setLogoURI(ContactUtility::convertPathToUri(charValue));
369 if(organization->getLogoURIIsSet())
370 organization->unsetLogoURI();
375 void ContactObjectP2AConverter::exportNoteList()
378 unsigned int child_count = 0;
380 if(m_abstractContact->getNotesNum() > 0)
381 m_abstractContact->clearNotes();
383 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.note, &child_count);
384 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
385 ThrowMsg(UnknownException, "getting note list (err:" << errorCode << ")");
387 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
389 //LoggerD("Platform contact don't have note list");
393 StringArrayPtr notes = m_abstractContact->getNotes();
395 for(unsigned int i=0; i<child_count; i++)
397 contacts_record_h child_record = NULL;
399 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.note, i, &child_record);
400 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
403 char *charValue = NULL;
405 contacts_record_get_str_p(child_record, _contacts_note.note, &charValue);
407 notes->push_back(charValue);
411 void ContactObjectP2AConverter::exportNumberList()
414 unsigned int child_count = 0;
416 if(m_abstractContact->getPhoneNumbersNum() > 0)
417 m_abstractContact->clearPhoneNumbers();
419 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.number, &child_count);
420 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
421 ThrowMsg(UnknownException, "getting number list (err:" << errorCode << ")");
423 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
425 //LoggerD("Platform contact don't have number list");
429 ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
431 for(unsigned int i=0; i<child_count; i++)
433 contacts_record_h child_record = NULL;
435 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.number, i, &child_record);
436 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
439 ContactPhoneNumberPtr phoneNumber(new ContactPhoneNumber());
441 char *charValue = NULL;
442 bool boolValue = false;
445 contacts_record_get_str_p(child_record, _contacts_number.number, &charValue);
448 phoneNumber->setNumber(charValue);
449 phoneNumbers->push_back(phoneNumber);
453 //LoggerD("Platform contact have a empty phone number");
457 contacts_record_get_bool(child_record, _contacts_number.is_default, &boolValue);
458 phoneNumber->setIsDefault(boolValue);
460 contacts_record_get_int(child_record, _contacts_number.type, &intValue);
461 if(intValue & CONTACTS_NUMBER_TYPE_HOME)
462 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_HOME);
463 if(intValue & CONTACTS_NUMBER_TYPE_WORK)
464 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_WORK);
465 if(intValue & CONTACTS_NUMBER_TYPE_VOICE)
466 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE);
467 if(intValue & CONTACTS_NUMBER_TYPE_FAX)
468 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_FAX);
469 if(intValue & CONTACTS_NUMBER_TYPE_MSG)
470 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MSG);
471 if(intValue & CONTACTS_NUMBER_TYPE_CELL)
472 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CELL);
473 if(intValue & CONTACTS_NUMBER_TYPE_PAGER)
474 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER);
475 if(intValue & CONTACTS_NUMBER_TYPE_BBS)
476 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_BBS);
477 if(intValue & CONTACTS_NUMBER_TYPE_MODEM)
478 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MODEM);
479 if(intValue & CONTACTS_NUMBER_TYPE_CAR)
480 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CAR);
481 if(intValue & CONTACTS_NUMBER_TYPE_ISDN)
482 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN);
483 if(intValue & CONTACTS_NUMBER_TYPE_VIDEO)
484 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO);
485 if(intValue & CONTACTS_NUMBER_TYPE_PCS)
486 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PCS);
488 if(phoneNumber->getTypes()->size() == 0)
489 phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE);
491 // TODO Will be added after type changed to string
492 // if(intValue & CONTACTS_NUMBER_TYPE_CUSTOM)
494 // contacts_record_get_str_p(child_record, _contacts_number.label, &charValue);
496 // phoneNumber->addType(CUSTOM);
501 void ContactObjectP2AConverter::exportEmailList()
504 unsigned int child_count = 0;
506 if(m_abstractContact->getEmailsNum() > 0)
507 m_abstractContact->clearEmails();
509 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.email, &child_count);
510 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
511 ThrowMsg(UnknownException, "getting email list (err:" << errorCode << ")");
513 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
515 //LoggerD("Platform contact don't have email list");
519 ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
521 for(unsigned int i=0; i<child_count; i++)
523 contacts_record_h child_record = NULL;
525 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.email, i, &child_record);
526 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
529 ContactEmailAddressPtr email(new ContactEmailAddress());
531 char *charValue = NULL;
532 bool boolValue = false;
535 contacts_record_get_str_p(child_record, _contacts_email.email, &charValue);
538 email->setEmail(charValue);
539 emails->push_back(email);
543 //LoggerD("Platform contact have a empty email address");
547 contacts_record_get_bool(child_record, _contacts_email.is_default, &boolValue);
548 email->setIsDefault(boolValue);
550 contacts_record_get_int(child_record, _contacts_email.type, &intValue);
551 if(intValue & CONTACTS_EMAIL_TYPE_HOME)
552 email->addType(CONTACT_EMAIL_TYPE_HOME);
553 if(intValue & CONTACTS_EMAIL_TYPE_WORK)
554 email->addType(CONTACT_EMAIL_TYPE_WORK);
556 if(email->getTypes()->size() == 0)
557 email->addType(CONTACT_EMAIL_TYPE_HOME);
559 // TODO Will be added after type changed to string
560 // if(intValue & CONTACTS_EMAIL_TYPE_CUSTOM)
562 // contacts_record_get_str_p(child_record, _contacts_email.label, &charValue);
564 // email->addType(CUSTOM);
569 void ContactObjectP2AConverter::exportGrouprelList()
572 unsigned int child_count = 0;
574 if(m_abstractContact->getGroupIdsNum() > 0)
575 m_abstractContact->clearGroupIds();
577 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.group_relation, &child_count);
578 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
579 ThrowMsg(UnknownException, "getting group list (err:" << errorCode << ")");
581 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
583 //LoggerD("Platform contact don't have group list");
587 StringArrayPtr groupIds = m_abstractContact->getGroupIds();
589 for(unsigned int i=0; i<child_count; i++)
591 contacts_record_h child_record = NULL;
593 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.group_relation, i, &child_record);
594 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
599 contacts_record_get_int(child_record, _contacts_group_relation.group_id, &groupId);
601 groupIds->push_back(ContactUtility::intToStr(groupId));
605 void ContactObjectP2AConverter::exportEventList()
608 unsigned int child_count = 0;
610 if(m_abstractContact->getAnniversariesNum() > 0)
611 m_abstractContact->clearAnniversaries();
613 if(m_abstractContact->getBirthdayIsSet())
614 m_abstractContact->unsetBirthday();
616 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.event, &child_count);
617 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
618 ThrowMsg(UnknownException, "getting event list (err:" << errorCode << ")");
620 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
622 //LoggerD("Platform contact don't have group list");
626 ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
628 for(unsigned int i=0; i<child_count; i++)
630 contacts_record_h child_record = NULL;
632 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.event, i, &child_record);
633 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
636 char *charValue = NULL;
637 int intValueType = 0;
638 int intValueDate = 0;
640 contacts_record_get_int(child_record, _contacts_event.date, &intValueDate);
645 tmDate = ContactUtility::toDateTmFromDateDbInt(intValueDate);
647 LoggerE("date has wrong value");
650 contacts_record_get_int(child_record, _contacts_event.type, &intValueType);
651 if (intValueType == CONTACTS_EVENT_TYPE_BIRTH)
653 m_abstractContact->setBirthday(tmDate);
655 else if(intValueType == CONTACTS_EVENT_TYPE_ANNIVERSARY)
657 ContactAnniversaryPtr anniversary = ContactAnniversaryPtr(new ContactAnniversary());
659 anniversary->setDate(tmDate);
660 contacts_record_get_str_p(child_record, _contacts_event.label, &charValue);
662 anniversary->setLabel(charValue);
664 anniversaries->push_back(anniversary);
666 ContactAnniversaryPtr anniversary = ContactAnniversaryPtr(new ContactAnniversary());
668 anniversary->setDate(tmDate);
669 contacts_record_get_str_p(child_record, _contacts_event.label, &charValue);
671 anniversary->setLabel(charValue);
673 anniversaries->push_back(anniversary);
678 void ContactObjectP2AConverter::exportPostalList()
681 unsigned int child_count = 0;
683 if(m_abstractContact->getAddressesNum() > 0)
684 m_abstractContact->clearAddresses();
686 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.address, &child_count);
687 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
688 ThrowMsg(UnknownException, "getting address list (err:" << errorCode << ")");
690 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
692 //LoggerD("Platform contact don't have address list");
696 ContactAddressArrayPtr addresss = m_abstractContact->getAddresses();
698 for(unsigned int i=0; i<child_count; i++)
700 contacts_record_h child_record = NULL;
702 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.address, i, &child_record);
703 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
706 ContactAddressPtr address(new ContactAddress());
708 char *charValue = NULL;
709 bool boolValue = false;
712 addresss->push_back(address);
714 contacts_record_get_str_p(child_record, _contacts_address.postal_code, &charValue);
716 address->setPostalCode(charValue);
718 contacts_record_get_str_p(child_record, _contacts_address.region, &charValue);
720 address->setRegion(charValue);
722 contacts_record_get_str_p(child_record, _contacts_address.locality, &charValue);
724 address->setCity(charValue);
726 contacts_record_get_str_p(child_record, _contacts_address.street, &charValue);
728 address->setStreetAddress(charValue);
730 contacts_record_get_str_p(child_record, _contacts_address.extended, &charValue);
732 address->setAdditionalInformation(charValue);
734 contacts_record_get_str_p(child_record, _contacts_address.country, &charValue);
736 address->setCountry(charValue);
738 contacts_record_get_bool(child_record, _contacts_address.is_default, &boolValue);
739 address->setIsDefault(boolValue);
741 contacts_record_get_int(child_record, _contacts_address.type, &intValue);
742 if(intValue & CONTACTS_ADDRESS_TYPE_HOME)
743 address->addType(CONTACT_ADDRESS_TYPE_HOME);
744 if(intValue & CONTACTS_ADDRESS_TYPE_WORK)
745 address->addType(CONTACT_ADDRESS_TYPE_WORK);
747 if(address->getTypes()->size() == 0)
748 address->addType(CONTACT_ADDRESS_TYPE_HOME);
750 // TODO Will be added after type changed to string
751 // if(intValue & CONTACTS_ADDRESS_TYPE_CUSTOM)
753 // contacts_record_get_str_p(child_record, _contacts_address.label, &charValue);
755 // address->addType(CUSTOM);
760 void ContactObjectP2AConverter::exportWebAddrList()
763 unsigned int child_count = 0;
765 if(m_abstractContact->getUrlsNum() > 0)
766 m_abstractContact->clearUrls();
768 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.url, &child_count);
769 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
770 ThrowMsg(UnknownException, "getting address list (err:" << errorCode << ")");
772 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
774 //LoggerD("Platform contact don't have address list");
778 ContactWebSiteArrayPtr urls = m_abstractContact->getUrls();
780 for(unsigned int i=0; i<child_count; i++)
782 contacts_record_h child_record = NULL;
784 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.url, i, &child_record);
785 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
788 ContactWebSitePtr url(new ContactWebSite());
790 char *charValue = NULL;
793 urls->push_back(url);
795 contacts_record_get_str_p(child_record, _contacts_url.url, &charValue);
797 url->setUrl(charValue);
799 contacts_record_get_int(child_record, _contacts_url.type, &intValue);
800 if(intValue == CONTACTS_URL_TYPE_HOME)
801 url->setType(WEBSITE_TYPE_HOMEPAGE);
802 if(intValue == CONTACTS_URL_TYPE_WORK)
803 url->setType(WEBSITE_TYPE_BLOG);
805 if(url->getTypeIsSet() == false)
806 url->setType(WEBSITE_TYPE_HOMEPAGE);
808 // TODO Will be added after type changed to string
809 // if(intValue & CONTACTS_URL_TYPE_CUSTOM)
811 // contacts_record_get_int(child_record, _contacts_url.label, &intValue);
813 // url->setType(CUSTOM);
818 void ContactObjectP2AConverter::exportNicknameList()
821 unsigned int child_count = 0;
823 ContactNamePtr contactName = m_abstractContact->getName();
824 if(contactName == NULL)
826 contactName = ContactNamePtr(new ContactName());
827 m_abstractContact->setName(contactName);
830 if(contactName->getNicknamesNum() > 0)
831 contactName->clearNicknames();
833 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.nickname, &child_count);
834 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
835 ThrowMsg(UnknownException, "getting nickname list (err:" << errorCode << ")");
837 if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
839 //LoggerD("Platform contact don't have nickname list");
843 StringArrayPtr nicknames = contactName->getNicknames();
845 for(unsigned int i=0; i<child_count; i++)
847 contacts_record_h child_record = NULL;
849 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.nickname, i, &child_record);
850 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
853 char *charValue = NULL;
855 contacts_record_get_str_p(child_record, _contacts_nickname.name, &charValue);
857 nicknames->push_back(charValue);