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 <unique_ptr.h>
25 #include <FBaseDateTime.h>
26 #include <FBaseColArrayList.h>
27 #include <FBaseColArrayListT.h>
28 #include <FSclTypes.h>
29 #include <FSclContact.h>
30 #include <FSclPerson.h>
31 #include <FSclCategory.h>
32 #include <FSclUserProfile.h>
34 #include <FSclAddress.h>
35 #include <FSclImAddress.h>
36 #include <FSclContactEvent.h>
37 #include <FSclRelationship.h>
38 #include <FSclOrganization.h>
39 #include <FBaseSysLog.h>
40 #include <FBase_StringConverter.h>
41 #include <FSclContactChangeInfo.h>
42 #include <FScl_ContactChangeInfoImpl.h>
43 #include <FSclCategoryChangeInfo.h>
44 #include <FScl_CategoryChangeInfoImpl.h>
45 #include "FScl_AddressbookUtil.h"
46 #include "FScl_ContactImpl.h"
47 #include "FScl_CategoryImpl.h"
48 #include "FScl_RecordImpl.h"
49 #include <FSclPhoneNumberContact.h>
50 #include "FScl_PhoneNumberContactImpl.h"
51 #include <FSclEmailContact.h>
52 #include "FScl_EmailContactImpl.h"
53 #include "FScl_PersonImpl.h"
54 #include "FSclAddressbook.h"
55 #include "FScl_AddressbookImpl.h"
56 #include "FScl_UserProfileImpl.h"
59 using namespace Tizen::Base;
60 using namespace Tizen::Base::Collection;
62 namespace Tizen { namespace Social
67 __ContactsContact::ConvertResultTo<Contact>(__SearchResult<__ContactsContact>& searchResult)
70 contacts_record_h newRecord = null;
72 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
73 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
75 contacts_record_get_int(currentRecord, _contacts_contact.id, &intValue);
76 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
78 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
79 SysTryReturn(NID_SCL, pContact != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
81 contacts_record_clone(currentRecord, &newRecord);
82 SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
84 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
86 contacts_record_get_int(newRecord, _contacts_contact.id, &intValue);
88 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
90 return pContact.release();
95 __ContactsGroup::ConvertResultTo<Category>(__SearchResult<__ContactsGroup>& searchResult)
98 contacts_record_h newRecord = null;
100 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
101 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
103 contacts_record_get_int(currentRecord, _contacts_group.id, &intValue);
104 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
106 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
107 SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
109 contacts_record_clone(currentRecord, &newRecord);
110 SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
112 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
114 contacts_record_get_int(newRecord, _contacts_group.id, &intValue);
116 _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
118 __Filter<__ContactsGroupRelation> filter;
120 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
122 __Query<__ContactsGroupRelation> query;
124 query.SetFilter(filter);
126 int count = _AddressbookUtil::GetCountWithQuery(query);
127 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
129 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
131 return pCategory.release();
136 __ContactsGroupRelation::ConvertResultTo<Category>(__SearchResult<__ContactsGroupRelation>& searchResult)
138 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
142 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
143 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
145 contacts_record_get_int(currentRecord, _contacts_group_relation.group_id, &intValue);
146 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
148 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
149 SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
151 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue));
152 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
154 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
155 _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
157 __Filter<__ContactsGroupRelation> filter;
159 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
161 __Query<__ContactsGroupRelation> query;
163 query.SetFilter(filter);
165 int count = _AddressbookUtil::GetCountWithQuery(query);
168 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
169 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
174 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
176 return pCategory.release();
181 __ContactsContactGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsContactGroupRel>& searchResult)
183 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
187 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
188 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
190 contacts_record_get_int(currentRecord, _contacts_contact_grouprel.group_id, &intValue);
191 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
193 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
194 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
196 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue));
197 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
199 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
200 _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
202 __Filter<__ContactsGroupRelation> filter;
204 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
206 __Query<__ContactsGroupRelation> query;
208 query.SetFilter(filter);
210 int count = _AddressbookUtil::GetCountWithQuery(query);
213 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
214 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
219 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
221 return pCategory.release();
227 __ContactsContactGroupRel::ConvertResultTo<Contact>(__SearchResult<__ContactsContactGroupRel>& searchResult)
229 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
233 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
234 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
236 contacts_record_get_int(currentRecord, _contacts_contact_grouprel.contact_id, &intValue);
237 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
239 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
240 SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
242 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue));
243 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
245 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
246 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
248 return pContact.release();
253 __ContactsContactEmail::ConvertResultTo<Contact>(__SearchResult<__ContactsContactEmail>& searchResult)
256 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
260 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
261 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
263 contacts_record_get_int(currentRecord, _contacts_contact_email.contact_id, &intValue);
264 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
266 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
267 SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
269 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue));
270 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
272 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
273 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
275 return pContact.release();
280 __ContactsContactEmail::ConvertResultTo<EmailContact>(__SearchResult<__ContactsContactEmail>& queryResult)
283 EmailType type = EMAIL_TYPE_PERSONAL;
284 char* pCharValue = null;
285 int emailRecordId = 0;
289 contacts_record_h recordHandle = queryResult.GetCurrentRecord();
290 SysTryReturn(NID_SCL, recordHandle != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
292 contacts_record_get_int(recordHandle, _contacts_contact_email.contact_id, &intValue);
293 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
295 std::unique_ptr<EmailContact> pEmailContact(new (std::nothrow) EmailContact());
296 SysTryReturn(NID_SCL, pEmailContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
298 contacts_record_get_int(recordHandle, _contacts_contact_email.contact_id, &intValue);
299 _EmailContactImpl::GetInstance(*pEmailContact)->SetContactId(intValue);
301 contacts_record_get_int(recordHandle, _contacts_contact_email.person_id, &intValue);
302 _EmailContactImpl::GetInstance(*pEmailContact)->SetPersonId(intValue);
304 contacts_record_get_int(recordHandle, _contacts_contact_email.address_book_id, &intValue);
305 _EmailContactImpl::GetInstance(*pEmailContact)->SetAddressbookId(intValue);
307 contacts_record_get_str_p(recordHandle, _contacts_contact_email.display_name, &pCharValue);
308 _EmailContactImpl::GetInstance(*pEmailContact)->SetDisplayName(pCharValue);
310 contacts_record_get_str_p(recordHandle, _contacts_contact_email.image_thumbnail_path, &pCharValue);
311 _EmailContactImpl::GetInstance(*pEmailContact)->SetThumbnailPath(pCharValue);
313 contacts_record_get_str_p(recordHandle, _contacts_contact_email.ringtone_path, &pCharValue);
314 _EmailContactImpl::GetInstance(*pEmailContact)->SetRingtonePath(pCharValue);
317 contacts_record_get_int(recordHandle, _contacts_contact_email.email_id, &intValue);
318 emailRecordId = intValue;
321 contacts_record_get_str_p(recordHandle, _contacts_contact_email.label, &pCharValue);
325 contacts_record_get_int(recordHandle, _contacts_contact_email.type, &intValue);
328 case CONTACTS_EMAIL_TYPE_HOME:
329 type = EMAIL_TYPE_PERSONAL;
331 case CONTACTS_EMAIL_TYPE_WORK:
332 type = EMAIL_TYPE_WORK;
334 case CONTACTS_EMAIL_TYPE_CUSTOM:
335 type = EMAIL_TYPE_CUSTOM;
338 type = EMAIL_TYPE_OTHER;
343 contacts_record_get_str_p(recordHandle, _contacts_contact_email.email, &pCharValue);
346 _EmailContactImpl::GetInstance(*pEmailContact)->SetEmailData(emailRecordId, type, label, email);
348 return pEmailContact.release();
353 __ContactsContactNumber::ConvertResultTo<Contact>(__SearchResult<__ContactsContactNumber>& searchResult)
355 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
359 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
360 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
362 contacts_record_get_int(currentRecord, _contacts_contact_number.contact_id, &intValue);
363 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
365 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
366 SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
368 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue));
369 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
371 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
372 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
374 return pContact.release();
379 __ContactsContactNumber::ConvertResultTo<PhoneNumberContact>(__SearchResult<__ContactsContactNumber>& queryResult)
382 PhoneNumberType type = PHONENUMBER_TYPE_HOME;
383 char* pCharValue = null;
384 int numberRecordId = 0;
388 contacts_record_h recordHandle = queryResult.GetCurrentRecord();
389 SysTryReturn(NID_SCL, recordHandle != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
391 contacts_record_get_int(recordHandle, _contacts_contact_number.contact_id, &intValue);
392 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
394 std::unique_ptr<PhoneNumberContact> pPhoneNumberContact(new (std::nothrow) PhoneNumberContact());
395 SysTryReturn(NID_SCL, pPhoneNumberContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
397 contacts_record_get_int(recordHandle, _contacts_contact_number.contact_id, &intValue);
398 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetContactId(intValue);
400 contacts_record_get_int(recordHandle, _contacts_contact_number.person_id, &intValue);
401 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetPersonId(intValue);
403 contacts_record_get_int(recordHandle, _contacts_contact_number.address_book_id, &intValue);
404 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetAddressbookId(intValue);
406 contacts_record_get_str_p(recordHandle, _contacts_contact_number.display_name, &pCharValue);
407 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetDisplayName(pCharValue);
409 contacts_record_get_str_p(recordHandle, _contacts_contact_number.image_thumbnail_path, &pCharValue);
410 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetThumbnailPath(pCharValue);
412 contacts_record_get_str_p(recordHandle, _contacts_contact_number.ringtone_path, &pCharValue);
413 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetRingtonePath(pCharValue);
416 contacts_record_get_int(recordHandle, _contacts_contact_number.number_id, &intValue);
417 numberRecordId = intValue;
420 contacts_record_get_str_p(recordHandle, _contacts_contact_number.label, &pCharValue);
424 contacts_record_get_int(recordHandle, _contacts_contact_number.type, &intValue);
427 case CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE:
428 type = PHONENUMBER_TYPE_HOME;
430 case CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE:
431 type = PHONENUMBER_TYPE_WORK;
433 case CONTACTS_NUMBER_TYPE_CELL:
434 type = PHONENUMBER_TYPE_MOBILE;
436 case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME:
437 type = PHONENUMBER_TYPE_HOME_FAX;
439 case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK:
440 type = PHONENUMBER_TYPE_WORK_FAX;
442 case CONTACTS_NUMBER_TYPE_PAGER:
443 type = PHONENUMBER_TYPE_PAGER;
445 case CONTACTS_NUMBER_TYPE_CUSTOM:
446 type = PHONENUMBER_TYPE_CUSTOM;
449 type = PHONENUMBER_TYPE_OTHER;
454 contacts_record_get_str_p(recordHandle, _contacts_contact_number.number, &pCharValue);
457 _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetPhoneNumberData(numberRecordId, type, label, number);
459 return pPhoneNumberContact.release();
464 __ContactsAddressbook::ConvertResultTo<Addressbook>(__SearchResult<__ContactsAddressbook>& queryResult)
467 char* pCharValue = null;
469 contacts_record_h currentRecord = queryResult.GetCurrentRecord();
470 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
472 std::unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
473 SysTryReturn(NID_SCL, pAddressbook != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
475 result r = pAddressbook->Construct();
476 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
478 contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
479 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(intValue);
481 contacts_record_get_str_p(currentRecord, _contacts_address_book.name, &pCharValue);
482 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
484 contacts_record_get_int(currentRecord, _contacts_address_book.account_id, &intValue);
485 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
487 return pAddressbook.release();
494 __ContactsPerson::ConvertResultTo<Person>(__SearchResult<__ContactsPerson>& queryResult)
497 char* pCharValue = null;
498 bool boolValue = false;
500 contacts_record_h currentRecord = queryResult.GetCurrentRecord();
501 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
503 std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
504 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
506 contacts_record_get_int(currentRecord, _contacts_person.id, &intValue);
507 _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
509 contacts_record_get_str_p(currentRecord, _contacts_person.addressbook_ids, &pCharValue);
510 _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
512 contacts_record_get_bool(currentRecord, _contacts_person.is_favorite, &boolValue);
513 _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
515 contacts_record_get_bool(currentRecord, _contacts_person.has_phonenumber, &boolValue);
516 _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
518 contacts_record_get_bool(currentRecord, _contacts_person.has_email, &boolValue);
519 _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
521 contacts_record_get_str_p(currentRecord, _contacts_person.image_thumbnail_path, &pCharValue);
522 _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
524 contacts_record_get_str_p(currentRecord, _contacts_person.ringtone_path, &pCharValue);
525 _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
527 contacts_record_get_str_p(currentRecord, _contacts_person.display_name, &pCharValue);
528 _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
530 return pPerson.release();
535 _AddressbookUtil::CreatePersonN(void)
537 Person* pPerson = new (std::nothrow) Person();
543 __ContactsPersonGroupRel::ConvertResultTo<Person>(__SearchResult<__ContactsPersonGroupRel>& searchResult)
546 char* pCharValue = null;
547 bool boolValue = false;
549 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
550 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
552 std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
553 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
555 contacts_record_get_int(currentRecord, _contacts_person_grouprel.person_id, &intValue);
556 _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
558 contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.addressbook_ids, &pCharValue);
559 _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
561 contacts_record_get_bool(currentRecord, _contacts_person_grouprel.is_favorite, &boolValue);
562 _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
564 contacts_record_get_bool(currentRecord, _contacts_person_grouprel.has_phonenumber, &boolValue);
565 _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
567 contacts_record_get_bool(currentRecord, _contacts_person_grouprel.has_email, &boolValue);
568 _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
570 contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.image_thumbnail_path, &pCharValue);
571 _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
573 contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.ringtone_path, &pCharValue);
574 _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
576 contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.display_name, &pCharValue);
577 _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
579 return pPerson.release();
584 __ContactsPersonGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsPersonGroupRel>& searchResult)
586 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
590 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
591 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
593 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
594 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
596 contacts_record_get_int(currentRecord, _contacts_person_grouprel.group_id, &intValue);
597 SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
600 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue));
601 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
603 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
604 _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
606 __Filter<__ContactsGroupRelation> filter;
608 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
610 __Query<__ContactsGroupRelation> query;
612 query.SetFilter(filter);
614 int count = _AddressbookUtil::GetCountWithQuery(query);
617 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
618 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
623 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
625 return pCategory.release();
630 __ContactsPerson::ConvertHandleTo<Person>(contacts_record_h recordHandle)
633 char* pCharValue = null;
634 bool boolValue = false;
636 std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
637 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
639 contacts_record_get_int(recordHandle, _contacts_person.id, &intValue);
640 _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
642 contacts_record_get_str_p(recordHandle, _contacts_person.addressbook_ids, &pCharValue);
643 _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
645 contacts_record_get_bool(recordHandle, _contacts_person.is_favorite, &boolValue);
646 _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
648 contacts_record_get_bool(recordHandle, _contacts_person.has_phonenumber, &boolValue);
649 _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
651 contacts_record_get_bool(recordHandle, _contacts_person.has_email, &boolValue);
652 _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
654 contacts_record_get_str_p(recordHandle, _contacts_person.image_thumbnail_path, &pCharValue);
655 _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
657 contacts_record_get_str_p(recordHandle, _contacts_person.ringtone_path, &pCharValue);
658 _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
660 contacts_record_get_str_p(recordHandle, _contacts_person.display_name, &pCharValue);
661 _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
663 return pPerson.release();
668 __ContactsPersonGroupRel::ConvertHandleTo<Person>(contacts_record_h recordHandle)
671 char* pCharValue = null;
672 bool boolValue = false;
674 std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
675 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
677 contacts_record_get_int(recordHandle, _contacts_person_grouprel.person_id, &intValue);
678 _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
680 contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.addressbook_ids, &pCharValue);
681 _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
683 contacts_record_get_bool(recordHandle, _contacts_person_grouprel.is_favorite, &boolValue);
684 _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
686 contacts_record_get_bool(recordHandle, _contacts_person_grouprel.has_phonenumber, &boolValue);
687 _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
689 contacts_record_get_bool(recordHandle, _contacts_person_grouprel.has_email, &boolValue);
690 _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
692 contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.image_thumbnail_path, &pCharValue);
693 _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
695 contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.ringtone_path, &pCharValue);
696 _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
698 contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.display_name, &pCharValue);
699 _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
701 return pPerson.release();
706 __ContactsContactUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsContactUpdatedInfo>& searchResult)
709 bool boolValue = false;
710 RecordChangeType changeType = RECORD_CHANGE_TYPE_ADDED;
712 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
713 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
715 std::unique_ptr<ContactChangeInfo> pContactChagneInfo(new (std::nothrow) ContactChangeInfo());
716 SysTryReturn(NID_SCL, pContactChagneInfo != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
718 contacts_record_get_int(currentRecord, _contacts_contact_updated_info.contact_id, &intValue);
719 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetContactId(intValue);
721 contacts_record_get_int(currentRecord, _contacts_contact_updated_info.address_book_id, &intValue);
722 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetAddressbookId(intValue);
724 contacts_record_get_int(currentRecord, _contacts_contact_updated_info.type, &intValue);
728 case CONTACTS_CHANGE_INSERTED:
729 changeType = RECORD_CHANGE_TYPE_ADDED;
731 case CONTACTS_CHANGE_UPDATED:
732 changeType = RECORD_CHANGE_TYPE_UPDATED;
734 case CONTACTS_CHANGE_DELETED:
737 changeType = RECORD_CHANGE_TYPE_REMOVED;
741 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetChangeType(changeType);
743 contacts_record_get_int(currentRecord, _contacts_contact_updated_info.version, &intValue);
744 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetVersion(intValue);
746 contacts_record_get_bool(currentRecord, _contacts_contact_updated_info.image_changed, &boolValue);
747 _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetThumbnailChangeStatus(boolValue);
749 return pContactChagneInfo.release();
754 __ContactsGroupUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsGroupUpdatedInfo>& searchResult)
757 RecordChangeType changeType = RECORD_CHANGE_TYPE_ADDED;
759 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
760 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
762 std::unique_ptr<CategoryChangeInfo> pCategoryChangeInfo(new (std::nothrow) CategoryChangeInfo());
763 SysTryReturn(NID_SCL, pCategoryChangeInfo != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
765 contacts_record_get_int(currentRecord, _contacts_group_updated_info.group_id, &intValue);
766 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetCategoryId(intValue);
768 contacts_record_get_int(currentRecord, _contacts_group_updated_info.address_book_id, &intValue);
769 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetAddressbookId(intValue);
771 contacts_record_get_int(currentRecord, _contacts_group_updated_info.type, &intValue);
775 case CONTACTS_CHANGE_INSERTED:
776 changeType = RECORD_CHANGE_TYPE_ADDED;
778 case CONTACTS_CHANGE_UPDATED:
779 changeType = RECORD_CHANGE_TYPE_UPDATED;
781 case CONTACTS_CHANGE_DELETED:
784 changeType = RECORD_CHANGE_TYPE_REMOVED;
788 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetChangeType(changeType);
790 contacts_record_get_int(currentRecord, _contacts_group_updated_info.version, &intValue);
791 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
793 return pCategoryChangeInfo.release();
798 __ContactsGroupRelUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsGroupRelUpdatedInfo>& searchResult)
802 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
803 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
805 std::unique_ptr<CategoryChangeInfo> pCategoryChangeInfo(new (std::nothrow) CategoryChangeInfo());
806 SysTryReturn(NID_SCL, pCategoryChangeInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
808 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.group_id, &intValue);
809 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetCategoryId(intValue);
811 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.version, &intValue);
812 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
814 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.address_book_id, &intValue);
815 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetAddressbookId(intValue);
817 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.type, &intValue);
819 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetChangeType(RECORD_CHANGE_TYPE_UPDATED);
821 contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.version, &intValue);
822 _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
824 return pCategoryChangeInfo.release();
829 __ContactsUserProfile::ConvertResultTo<UserProfile>(__SearchResult<__ContactsUserProfile>& searchResult)
831 contacts_record_h newRecord = null;
833 contacts_record_h currentRecord = searchResult.GetCurrentRecord();
834 SysTryReturn(NID_SCL, currentRecord != null, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
836 std::unique_ptr<UserProfile> pProfile(new (std::nothrow) UserProfile());
837 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
839 contacts_record_clone(currentRecord, &newRecord);
840 SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
842 _UserProfileImpl::GetInstance(*pProfile)->SetUserProfileHandle(newRecord);
844 return pProfile.release();
848 __SearchResult<__ContactsPerson>*
849 _AddressbookUtil::Search(const Tizen::Base::String& keyword)
851 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
853 __SearchResult<__ContactsPerson>* pQueryResult = null;
855 contacts_list_h list = null;
856 std::unique_ptr<char[]> pKeyword(_StringConverter::CopyToCharArrayN(keyword));
858 int ret = contacts_db_search_records(__ContactsPerson::GetUri(), pKeyword.get(), 0, 0, &list);
859 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
860 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
862 pQueryResult = new (std::nothrow) __SearchResult<__ContactsPerson>(list);
863 SysTryReturn(NID_SCL, pQueryResult, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
868 IListT<AddressbookId>*
869 _AddressbookUtil::GetRwAbIdListN(void)
873 __Filter<__ContactsAddressbook> filter;
875 filter.AddInt(_contacts_address_book.mode, CONTACTS_MATCH_GREATER_THAN, 0);
877 __Query<__ContactsAddressbook> query;
879 query.SetFilter(filter);
881 std::unique_ptr<IList, AllElementsDeleter> pAbList(SearchWithQueryN<__ContactsAddressbook, Addressbook>(query));
882 SysTryReturn(NID_SCL, pAbList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
884 std::unique_ptr<IEnumerator> pEnum(pAbList->GetEnumeratorN());
885 SysTryReturn(NID_SCL, pEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
887 std::unique_ptr< ArrayListT<AddressbookId> > pAbIdList(new (std::nothrow) ArrayListT<AddressbookId>);
888 SysTryReturn(NID_SCL, pAbIdList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
890 result r = pAbIdList->Construct(pAbList->GetCount());
891 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
893 while (pEnum->MoveNext() == E_SUCCESS)
895 Addressbook* pAddressbook = static_cast<Addressbook*>(pEnum->GetCurrent());
897 pAbIdList->Add(pAddressbook->GetId());
900 return pAbIdList.release();
904 _AddressbookUtil::GetAbListN(IListT<AddressbookId>& rwAbIdList, IListT<AddressbookId>& roAbIdList)
908 __Query<__ContactsAddressbook> query;
911 std::unique_ptr<__SearchResult<__ContactsAddressbook> > pSearchResult(_AddressbookUtil::ExecuteQuery(query, 0, 0));
912 if (pSearchResult == null)
917 while (pSearchResult->MoveNext() == E_SUCCESS)
920 contacts_record_h currentRecord = pSearchResult->GetCurrentRecord();
922 contacts_record_get_int(currentRecord, _contacts_address_book.mode, &intValue);
923 if (intValue == CONTACTS_ADDRESS_BOOK_MODE_NONE)
925 contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
927 rwAbIdList.Add(intValue);
931 contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
932 roAbIdList.Add(intValue);