2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FScl_AddressbookUtil.cpp
18 * @brief This is the implementation for _AddressbookUtil class.
20 * This file contains definitions of @e _AddressbookUtil class.
24 #include <FBaseDateTime.h>
25 #include <FBaseColArrayList.h>
26 #include <FBaseColArrayListT.h>
27 #include <FSclTypes.h>
28 #include <FSclContact.h>
29 #include <FSclPerson.h>
30 #include <FSclCategory.h>
31 #include <FSclUserProfile.h>
33 #include <FSclAddress.h>
34 #include <FSclImAddress.h>
35 #include <FSclContactEvent.h>
36 #include <FSclRelationship.h>
37 #include <FSclOrganization.h>
38 #include <FBaseSysLog.h>
39 #include <FBase_StringConverter.h>
40 #include <FSclContactChangeInfo.h>
41 #include <FScl_ContactChangeInfoImpl.h>
42 #include <FSclCategoryChangeInfo.h>
43 #include <FScl_CategoryChangeInfoImpl.h>
44 #include "FScl_AddressbookUtil.h"
45 #include "FScl_ContactImpl.h"
46 #include "FScl_CategoryImpl.h"
47 #include "FScl_RecordImpl.h"
48 #include <FSclPhoneNumberContact.h>
49 #include "FScl_PhoneNumberContactImpl.h"
50 #include <FSclEmailContact.h>
51 #include "FScl_EmailContactImpl.h"
52 #include "FScl_PersonImpl.h"
53 #include "FSclAddressbook.h"
54 #include "FScl_AddressbookImpl.h"
55 #include "FScl_UserProfileImpl.h"
57 using namespace Tizen::Base;
58 using namespace Tizen::Base::Collection;
60 namespace Tizen { namespace Social
65 __ContactsContact::ConvertResultTo<Contact>(__SearchResult<__ContactsContact>& searchResult)
68 contacts_record_h newRecord = null;
70 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
71 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
73 contacts_record_get_int(currentRecord, _contacts_contact.id, &intValue);
74 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
76 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
77 SysTryReturn(NID_SCL, pContact != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
79 contacts_record_clone(currentRecord, &newRecord);
80 SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
82 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
84 contacts_record_get_int(newRecord, _contacts_contact.id, &intValue);
86 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
88 return pContact.release();
93 __ContactsGroup::ConvertResultTo<Category>(__SearchResult<__ContactsGroup>& searchResult)
96 contacts_record_h newRecord = null;
98 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
99 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
101 contacts_record_get_int(currentRecord, _contacts_group.id, &intValue);
102 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
104 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
105 SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
107 contacts_record_clone(currentRecord, &newRecord);
108 SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
110 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
112 contacts_record_get_int(newRecord, _contacts_group.id, &intValue);
114 _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
116 __Filter<__ContactsGroupRelation> filter;
118 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
120 __Query<__ContactsGroupRelation> query;
122 query.SetFilter(filter);
124 int count = _AddressbookUtil::GetCountWithQuery(query);
125 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
127 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
129 return pCategory.release();
134 __ContactsGroupRelation::ConvertResultTo<Category>(__SearchResult<__ContactsGroupRelation>& searchResult)
136 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
139 contacts_record_h newRecord = null;
141 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
142 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
144 contacts_record_get_int(currentRecord, _contacts_group_relation.group_id, &intValue);
145 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
147 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
148 SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
150 int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord);
151 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
152 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
153 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
155 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
156 _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
158 __Filter<__ContactsGroupRelation> filter;
160 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
162 __Query<__ContactsGroupRelation> query;
164 query.SetFilter(filter);
166 int count = _AddressbookUtil::GetCountWithQuery(query);
169 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
170 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
175 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
177 return pCategory.release();
182 __ContactsContactGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsContactGroupRel>& searchResult)
184 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
187 contacts_record_h newRecord = null;
189 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
190 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
192 contacts_record_get_int(currentRecord, _contacts_contact_grouprel.group_id, &intValue);
193 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
195 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
196 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
198 int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord);
199 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
200 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
201 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
203 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
204 _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
206 __Filter<__ContactsGroupRelation> filter;
208 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
210 __Query<__ContactsGroupRelation> query;
212 query.SetFilter(filter);
214 int count = _AddressbookUtil::GetCountWithQuery(query);
217 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
218 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
223 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
225 return pCategory.release();
231 __ContactsContactGroupRel::ConvertResultTo<Contact>(__SearchResult<__ContactsContactGroupRel>& searchResult)
233 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
236 contacts_record_h newRecord = null;
238 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
239 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
241 contacts_record_get_int(currentRecord, _contacts_contact_grouprel.contact_id, &intValue);
242 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
244 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
245 SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
247 int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord);
248 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
249 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
250 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
252 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
253 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
255 return pContact.release();
260 __ContactsContactEmail::ConvertResultTo<Contact>(__SearchResult<__ContactsContactEmail>& searchResult)
263 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
266 contacts_record_h newRecord = null;
268 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
269 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
271 contacts_record_get_int(currentRecord, _contacts_contact_email.contact_id, &intValue);
272 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
274 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
275 SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
277 int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord);
278 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
279 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
280 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
282 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
283 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
285 return pContact.release();
290 __ContactsContactEmail::ConvertResultTo<EmailContact>(__SearchResult<__ContactsContactEmail>& queryResult)
293 EmailType type = EMAIL_TYPE_PERSONAL;
294 char* pCharValue = null;
295 int emailRecordId = 0;
299 contacts_record_h recordHandle = queryResult.GetCurrentRecord();
300 SysTryReturn(NID_SCL, recordHandle != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
302 contacts_record_get_int(recordHandle, _contacts_contact_email.contact_id, &intValue);
303 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
305 std::unique_ptr<EmailContact> pEmailContact(new (std::nothrow) EmailContact());
306 SysTryReturn(NID_SCL, pEmailContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
308 contacts_record_get_int(recordHandle, _contacts_contact_email.contact_id, &intValue);
309 _EmailContactImpl::GetInstance(*pEmailContact)->SetContactId(intValue);
311 contacts_record_get_int(recordHandle, _contacts_contact_email.person_id, &intValue);
312 _EmailContactImpl::GetInstance(*pEmailContact)->SetPersonId(intValue);
314 contacts_record_get_int(recordHandle, _contacts_contact_email.address_book_id, &intValue);
315 _EmailContactImpl::GetInstance(*pEmailContact)->SetAddressbookId(intValue);
317 contacts_record_get_str_p(recordHandle, _contacts_contact_email.display_name, &pCharValue);
318 _EmailContactImpl::GetInstance(*pEmailContact)->SetDisplayName(pCharValue);
320 contacts_record_get_str_p(recordHandle, _contacts_contact_email.image_thumbnail_path, &pCharValue);
321 _EmailContactImpl::GetInstance(*pEmailContact)->SetThumbnailPath(pCharValue);
323 contacts_record_get_str_p(recordHandle, _contacts_contact_email.ringtone_path, &pCharValue);
324 _EmailContactImpl::GetInstance(*pEmailContact)->SetRingtonePath(pCharValue);
327 contacts_record_get_int(recordHandle, _contacts_contact_email.email_id, &intValue);
328 emailRecordId = intValue;
331 contacts_record_get_str_p(recordHandle, _contacts_contact_email.label, &pCharValue);
335 contacts_record_get_int(recordHandle, _contacts_contact_email.type, &intValue);
338 case CONTACTS_EMAIL_TYPE_HOME:
339 type = EMAIL_TYPE_PERSONAL;
341 case CONTACTS_EMAIL_TYPE_WORK:
342 type = EMAIL_TYPE_WORK;
344 case CONTACTS_EMAIL_TYPE_CUSTOM:
345 type = EMAIL_TYPE_CUSTOM;
348 type = EMAIL_TYPE_OTHER;
353 contacts_record_get_str_p(recordHandle, _contacts_contact_email.email, &pCharValue);
356 _EmailContactImpl::GetInstance(*pEmailContact)->SetEmailData(emailRecordId, type, label, email);
358 return pEmailContact.release();
363 __ContactsContactNumber::ConvertResultTo<Contact>(__SearchResult<__ContactsContactNumber>& searchResult)
365 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
368 contacts_record_h newRecord = null;
370 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
371 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
373 contacts_record_get_int(currentRecord, _contacts_contact_number.contact_id, &intValue);
374 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
376 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
377 SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
379 int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord);
380 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
381 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
382 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
384 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
385 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
387 return pContact.release();
392 __ContactsContactNumber::ConvertResultTo<PhoneNumberContact>(__SearchResult<__ContactsContactNumber>& queryResult)
395 PhoneNumberType type = PHONENUMBER_TYPE_HOME;
396 char* pCharValue = null;
397 int numberRecordId = 0;
401 contacts_record_h recordHandle = queryResult.GetCurrentRecord();
402 SysTryReturn(NID_SCL, recordHandle != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
404 contacts_record_get_int(recordHandle, _contacts_contact_number.contact_id, &intValue);
405 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
407 std::unique_ptr<PhoneNumberContact> pPhoneNumberContact(new (std::nothrow) PhoneNumberContact());
408 SysTryReturn(NID_SCL, pPhoneNumberContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
410 contacts_record_get_int(recordHandle, _contacts_contact_number.contact_id, &intValue);
411 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetContactId(intValue);
413 contacts_record_get_int(recordHandle, _contacts_contact_number.person_id, &intValue);
414 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetPersonId(intValue);
416 contacts_record_get_int(recordHandle, _contacts_contact_number.address_book_id, &intValue);
417 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetAddressbookId(intValue);
419 contacts_record_get_str_p(recordHandle, _contacts_contact_number.display_name, &pCharValue);
420 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetDisplayName(pCharValue);
422 contacts_record_get_str_p(recordHandle, _contacts_contact_number.image_thumbnail_path, &pCharValue);
423 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetThumbnailPath(pCharValue);
425 contacts_record_get_str_p(recordHandle, _contacts_contact_number.ringtone_path, &pCharValue);
426 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetRingtonePath(pCharValue);
429 contacts_record_get_int(recordHandle, _contacts_contact_number.number_id, &intValue);
430 numberRecordId = intValue;
433 contacts_record_get_str_p(recordHandle, _contacts_contact_number.label, &pCharValue);
437 contacts_record_get_int(recordHandle, _contacts_contact_number.type, &intValue);
440 case CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE:
441 type = PHONENUMBER_TYPE_HOME;
443 case CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE:
444 type = PHONENUMBER_TYPE_WORK;
446 case CONTACTS_NUMBER_TYPE_CELL:
447 type = PHONENUMBER_TYPE_MOBILE;
449 case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME:
450 type = PHONENUMBER_TYPE_HOME_FAX;
452 case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK:
453 type = PHONENUMBER_TYPE_WORK_FAX;
455 case CONTACTS_NUMBER_TYPE_PAGER:
456 type = PHONENUMBER_TYPE_PAGER;
458 case CONTACTS_NUMBER_TYPE_CUSTOM:
459 type = PHONENUMBER_TYPE_CUSTOM;
462 type = PHONENUMBER_TYPE_OTHER;
467 contacts_record_get_str_p(recordHandle, _contacts_contact_number.number, &pCharValue);
470 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetPhoneNumberData(numberRecordId, type, label, number);
472 return pPhoneNumberContact.release();
477 __ContactsAddressbook::ConvertResultTo<Addressbook>(__SearchResult<__ContactsAddressbook>& queryResult)
480 char* pCharValue = null;
482 contacts_record_h currentRecord = queryResult.GetCurrentRecord();
483 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
485 std::unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
486 SysTryReturn(NID_SCL, pAddressbook != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
488 result r = pAddressbook->Construct();
489 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
491 contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
492 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(intValue);
494 contacts_record_get_str_p(currentRecord, _contacts_address_book.name, &pCharValue);
495 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
497 contacts_record_get_int(currentRecord, _contacts_address_book.account_id, &intValue);
498 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
500 return pAddressbook.release();
507 __ContactsPerson::ConvertResultTo<Person>(__SearchResult<__ContactsPerson>& queryResult)
510 char* pCharValue = null;
511 bool boolValue = false;
513 contacts_record_h currentRecord = queryResult.GetCurrentRecord();
514 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
516 std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
517 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
519 contacts_record_get_int(currentRecord, _contacts_person.id, &intValue);
520 _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
522 contacts_record_get_str_p(currentRecord, _contacts_person.addressbook_ids, &pCharValue);
523 _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
525 contacts_record_get_bool(currentRecord, _contacts_person.is_favorite, &boolValue);
526 _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
528 contacts_record_get_bool(currentRecord, _contacts_person.has_phonenumber, &boolValue);
529 _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
531 contacts_record_get_bool(currentRecord, _contacts_person.has_email, &boolValue);
532 _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
534 contacts_record_get_str_p(currentRecord, _contacts_person.image_thumbnail_path, &pCharValue);
535 _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
537 contacts_record_get_str_p(currentRecord, _contacts_person.ringtone_path, &pCharValue);
538 _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
540 contacts_record_get_str_p(currentRecord, _contacts_person.display_name, &pCharValue);
541 _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
543 return pPerson.release();
548 _AddressbookUtil::CreatePersonN(void)
550 Person* pPerson = new (std::nothrow) Person();
556 __ContactsPersonGroupRel::ConvertResultTo<Person>(__SearchResult<__ContactsPersonGroupRel>& searchResult)
559 char* pCharValue = null;
560 bool boolValue = false;
562 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
563 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
565 std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
566 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
568 contacts_record_get_int(currentRecord, _contacts_person_grouprel.person_id, &intValue);
569 _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
571 contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.addressbook_ids, &pCharValue);
572 _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
574 contacts_record_get_bool(currentRecord, _contacts_person_grouprel.is_favorite, &boolValue);
575 _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
577 contacts_record_get_bool(currentRecord, _contacts_person_grouprel.has_phonenumber, &boolValue);
578 _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
580 contacts_record_get_bool(currentRecord, _contacts_person_grouprel.has_email, &boolValue);
581 _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
583 contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.image_thumbnail_path, &pCharValue);
584 _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
586 contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.ringtone_path, &pCharValue);
587 _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
589 contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.display_name, &pCharValue);
590 _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
592 return pPerson.release();
597 __ContactsPersonGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsPersonGroupRel>& searchResult)
599 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
602 contacts_record_h newRecord = null;
604 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
605 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
607 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
608 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
610 contacts_record_get_int(currentRecord, _contacts_person_grouprel.group_id, &intValue);
611 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
613 int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord);
614 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
615 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
616 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
618 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
619 _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
621 __Filter<__ContactsGroupRelation> filter;
623 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
625 __Query<__ContactsGroupRelation> query;
627 query.SetFilter(filter);
629 int count = _AddressbookUtil::GetCountWithQuery(query);
632 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
633 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
638 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
640 return pCategory.release();
645 __ContactsPerson::ConvertHandleTo<Person>(contacts_record_h recordHandle)
648 char* pCharValue = null;
649 bool boolValue = false;
651 std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
652 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
654 contacts_record_get_int(recordHandle, _contacts_person.id, &intValue);
655 _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
657 contacts_record_get_str_p(recordHandle, _contacts_person.addressbook_ids, &pCharValue);
658 _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
660 contacts_record_get_bool(recordHandle, _contacts_person.is_favorite, &boolValue);
661 _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
663 contacts_record_get_bool(recordHandle, _contacts_person.has_phonenumber, &boolValue);
664 _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
666 contacts_record_get_bool(recordHandle, _contacts_person.has_email, &boolValue);
667 _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
669 contacts_record_get_str_p(recordHandle, _contacts_person.image_thumbnail_path, &pCharValue);
670 _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
672 contacts_record_get_str_p(recordHandle, _contacts_person.ringtone_path, &pCharValue);
673 _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
675 contacts_record_get_str_p(recordHandle, _contacts_person.display_name, &pCharValue);
676 _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
678 return pPerson.release();
683 __ContactsPersonGroupRel::ConvertHandleTo<Person>(contacts_record_h recordHandle)
686 char* pCharValue = null;
687 bool boolValue = false;
689 std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
690 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
692 contacts_record_get_int(recordHandle, _contacts_person_grouprel.person_id, &intValue);
693 _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
695 contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.addressbook_ids, &pCharValue);
696 _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
698 contacts_record_get_bool(recordHandle, _contacts_person_grouprel.is_favorite, &boolValue);
699 _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
701 contacts_record_get_bool(recordHandle, _contacts_person_grouprel.has_phonenumber, &boolValue);
702 _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
704 contacts_record_get_bool(recordHandle, _contacts_person_grouprel.has_email, &boolValue);
705 _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
707 contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.image_thumbnail_path, &pCharValue);
708 _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
710 contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.ringtone_path, &pCharValue);
711 _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
713 contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.display_name, &pCharValue);
714 _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
716 return pPerson.release();
721 __ContactsContactUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsContactUpdatedInfo>& searchResult)
724 bool boolValue = false;
725 RecordChangeType changeType = RECORD_CHANGE_TYPE_ADDED;
727 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
728 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
730 std::unique_ptr<ContactChangeInfo> pContactChagneInfo(new (std::nothrow) ContactChangeInfo());
731 SysTryReturn(NID_SCL, pContactChagneInfo != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
733 contacts_record_get_int(currentRecord, _contacts_contact_updated_info.contact_id, &intValue);
734 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetContactId(intValue);
736 contacts_record_get_int(currentRecord, _contacts_contact_updated_info.address_book_id, &intValue);
737 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetAddressbookId(intValue);
739 contacts_record_get_int(currentRecord, _contacts_contact_updated_info.type, &intValue);
743 case CONTACTS_CHANGE_INSERTED:
744 changeType = RECORD_CHANGE_TYPE_ADDED;
746 case CONTACTS_CHANGE_UPDATED:
747 changeType = RECORD_CHANGE_TYPE_UPDATED;
749 case CONTACTS_CHANGE_DELETED:
752 changeType = RECORD_CHANGE_TYPE_REMOVED;
756 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetChangeType(changeType);
758 contacts_record_get_int(currentRecord, _contacts_contact_updated_info.version, &intValue);
759 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetVersion(intValue);
761 contacts_record_get_bool(currentRecord, _contacts_contact_updated_info.image_changed, &boolValue);
762 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetThumbnailChangeStatus(boolValue);
764 return pContactChagneInfo.release();
769 __ContactsGroupUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsGroupUpdatedInfo>& searchResult)
772 RecordChangeType changeType = RECORD_CHANGE_TYPE_ADDED;
774 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
775 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
777 std::unique_ptr<CategoryChangeInfo> pCategoryChangeInfo(new (std::nothrow) CategoryChangeInfo());
778 SysTryReturn(NID_SCL, pCategoryChangeInfo != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
780 contacts_record_get_int(currentRecord, _contacts_group_updated_info.group_id, &intValue);
781 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetCategoryId(intValue);
783 contacts_record_get_int(currentRecord, _contacts_group_updated_info.address_book_id, &intValue);
784 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetAddressbookId(intValue);
786 contacts_record_get_int(currentRecord, _contacts_group_updated_info.type, &intValue);
790 case CONTACTS_CHANGE_INSERTED:
791 changeType = RECORD_CHANGE_TYPE_ADDED;
793 case CONTACTS_CHANGE_UPDATED:
794 changeType = RECORD_CHANGE_TYPE_UPDATED;
796 case CONTACTS_CHANGE_DELETED:
799 changeType = RECORD_CHANGE_TYPE_REMOVED;
803 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetChangeType(changeType);
805 contacts_record_get_int(currentRecord, _contacts_group_updated_info.version, &intValue);
806 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
808 return pCategoryChangeInfo.release();
813 __ContactsGroupRelUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsGroupRelUpdatedInfo>& searchResult)
817 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
818 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
820 std::unique_ptr<CategoryChangeInfo> pCategoryChangeInfo(new (std::nothrow) CategoryChangeInfo());
821 SysTryReturn(NID_SCL, pCategoryChangeInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
823 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.group_id, &intValue);
824 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetCategoryId(intValue);
826 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.version, &intValue);
827 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
829 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.address_book_id, &intValue);
830 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetAddressbookId(intValue);
832 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.type, &intValue);
834 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetChangeType(RECORD_CHANGE_TYPE_UPDATED);
836 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.version, &intValue);
837 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
839 return pCategoryChangeInfo.release();
844 __ContactsUserProfile::ConvertResultTo<UserProfile>(__SearchResult<__ContactsUserProfile>& searchResult)
846 contacts_record_h newRecord = null;
848 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
849 SysTryReturn(NID_SCL, currentRecord != null, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
851 std::unique_ptr<UserProfile> pProfile(new (std::nothrow) UserProfile());
852 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
854 contacts_record_clone(currentRecord, &newRecord);
855 SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
857 _UserProfileImpl::GetInstance(*pProfile)->SetUserProfileHandle(newRecord);
859 return pProfile.release();
863 __SearchResult<__ContactsPerson>*
864 _AddressbookUtil::Search(const Tizen::Base::String& keyword)
866 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
868 __SearchResult<__ContactsPerson>* pQueryResult = null;
870 contacts_list_h list = null;
871 std::unique_ptr<char[]> pKeyword(_StringConverter::CopyToCharArrayN(keyword));
873 int ret = contacts_db_search_records(__ContactsPerson::GetUri(), pKeyword.get(), 0, 0, &list);
874 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
875 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
877 pQueryResult = new (std::nothrow) __SearchResult<__ContactsPerson>(list);
878 SysTryReturn(NID_SCL, pQueryResult, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));