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_AddressbookManagerImpl.cpp
18 * @brief This is the implementation for _AddressbookManagerImpl class.
20 * This file contains definitions of @e _AddressbookManagerImpl class.
23 #include <unique_ptr.h>
25 #include <FBaseColIListT.h>
26 #include <FBaseColArrayListT.h>
27 #include <FBaseColHashMapT.h>
28 #include <FBaseResult.h>
29 #include <FBaseLongLong.h>
30 #include <FBaseInteger.h>
32 #include <FSclAddressbook.h>
33 #include <FSclAddressbookManager.h>
34 #include <FSclIAddressbookChangeEventListener.h>
35 #include <FSclContact.h>
36 #include <FSclCategory.h>
37 #include <FSclUserProfile.h>
38 #include <FSclContactChangeInfo.h>
39 #include <FSclCategoryChangeInfo.h>
40 #include <FSclPerson.h>
41 #include <FSclPhoneNumberContact.h>
42 #include <FScl_PhoneNumberContactImpl.h>
43 #include <FSclEmailContact.h>
44 #include <FScl_EmailContactImpl.h>
45 #include <FSclAddressbookFilter.h>
46 #include <FSclIAddressbookEventListener.h>
47 #include <FSclIRecordEventListener.h>
48 #include <FBaseSysLog.h>
49 #include <FApp_AppInfo.h>
50 #include <FBase_StringConverter.h>
51 #include "FScl_AddressbookImpl.h"
52 #include "FScl_AddressbookFilterImpl.h"
53 #include "FScl_AddressbookManagerImpl.h"
54 #include "FScl_AddressbookUtil.h"
55 #include "FScl_RecordImpl.h"
56 #include "FScl_ContactImpl.h"
57 #include "FScl_CategoryImpl.h"
58 #include "FScl_PersonImpl.h"
59 #include "FScl_AddressbookUtil.h"
60 #include "FScl_ContactChangeInfoImpl.h"
61 #include "FScl_CategoryChangeInfoImpl.h"
62 #include "FScl_ContactDbMonitor.h"
63 #include "FScl_ContactDbConnector.h"
64 #include "FScl_UserProfileImpl.h"
67 using namespace Tizen::App;
68 using namespace Tizen::Base;
69 using namespace Tizen::Base::Collection;
70 using namespace Tizen::Io;
71 using namespace Tizen::Graphics;
73 namespace Tizen { namespace Social
76 _AddressbookManagerImpl::_AddressbookManagerImpl(void)
77 : __pIAddressbookEventListener(null)
78 , __pIAddressbookChangeEventListener(null)
79 , __dbVersionForContact(0)
80 , __dbVersionForGroup(0)
81 , __dbVersionForRelation(0)
86 _AddressbookManagerImpl::~_AddressbookManagerImpl(void)
88 if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null)
90 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
91 if (pContactDbMonitor != null)
93 pContactDbMonitor->RemoveListener(*this);
99 _AddressbookManagerImpl::Construct(void)
101 result r = _ContactDbConnector::EnsureDbConnection();
102 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
108 _AddressbookManagerImpl::SetEventListener(IAddressbookEventListener* pListener)
110 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
112 result r = E_SUCCESS;
114 if (pListener != null)
116 if (__pIAddressbookEventListener == null && __pIAddressbookChangeEventListener == null)
118 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
119 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
121 r = pContactDbMonitor->AddListener(*this);
122 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
125 __dbVersionForContact = GetLatestVersion();
126 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
128 __dbVersionForGroup = __dbVersionForContact;
129 __dbVersionForRelation = __dbVersionForContact;
131 __pIAddressbookChangeEventListener = null;
132 __pIAddressbookEventListener = pListener;
136 if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null)
139 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
140 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
142 pContactDbMonitor->RemoveListener(*this);
145 __pIAddressbookEventListener = null;
146 __pIAddressbookChangeEventListener = null;
153 _AddressbookManagerImpl::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
155 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
157 result r = E_SUCCESS;
159 if (pListener != null)
161 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
163 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
164 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
166 r = pContactDbMonitor->AddListener(*this);
167 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
170 __dbVersionForContact = GetLatestVersion();
171 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
173 __dbVersionForGroup = __dbVersionForContact;
174 __dbVersionForRelation = __dbVersionForContact;
176 __pIAddressbookEventListener = null;
177 __pIAddressbookChangeEventListener = pListener;
181 if (__pIAddressbookChangeEventListener != null || __pIAddressbookEventListener != null)
184 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
185 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
187 pContactDbMonitor->RemoveListener(*this);
190 __pIAddressbookChangeEventListener = null;
191 __pIAddressbookEventListener = null;
198 _AddressbookManagerImpl::CreateAddressbookN(AccountId accountId, const String& name)
200 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
201 SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. account id is invalid.", GetErrorMessage(E_INVALID_ARG));
202 SysTryReturn(NID_SCL, !name.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The name is empty.", GetErrorMessage(E_INVALID_ARG));
206 result r = E_SUCCESS;
209 unique_ptr<char[]> pNameString(_StringConverter::CopyToCharArrayN(name));
210 SysTryReturn(NID_SCL, pNameString !=null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
212 __Filter<__ContactsAddressbook> filter;
214 filter.AddString(_contacts_address_book.name, CONTACTS_MATCH_EXACTLY, pNameString.get());
217 filter.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
218 filter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
221 __Query<__ContactsAddressbook> query;
223 query.SetFilter(filter);
225 int count = _AddressbookUtil::GetCountWithQuery(query);
226 SysTryReturn(NID_SCL, count == 0, null, E_OBJ_ALREADY_EXIST, "[%s] The name is already being used by other addressbook.", GetErrorMessage(E_OBJ_ALREADY_EXIST));
228 unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
229 SysTryReturn(NID_SCL, pAddressbook != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
231 r = pAddressbook->Construct();
232 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
234 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::CreateContactRecordN(_contacts_address_book._uri));
235 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
237 contacts_record_set_str(pAbRecord.get(), _contacts_address_book.name, pNameString.get());
238 contacts_record_set_int(pAbRecord.get(), _contacts_address_book.account_id, accountId);
240 r = _AddressbookUtil::InsertContactRecordN(pAbRecord.get(), recordId);
241 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
243 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(accountId);
244 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(name);
245 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(recordId);
247 return pAddressbook.release();
251 _AddressbookManagerImpl::DeleteAddressbook(AddressbookId addressbookId)
253 SysTryReturn(NID_SCL, addressbookId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument used.The addressbook ID is invalid or the default addressbook ID.", GetErrorMessage(E_INVALID_ARG));
254 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
255 result r = _AddressbookUtil::DeleteContactRecord(_contacts_address_book._uri, addressbookId);
256 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
262 _AddressbookManagerImpl::GetAddressbooksByAccountN(AccountId accountId) const
264 SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. account id is invalid.", GetErrorMessage(E_INVALID_ARG));
265 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
269 IList* pAddressbooks = null;
271 __Filter<__ContactsAddressbook> accountFilter;
272 accountFilter.Construct();
273 accountFilter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
275 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
276 if (pRwAbFilter->Get() == null)
278 __Query<__ContactsAddressbook> query;
280 query.SetFilter(accountFilter);
282 pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
283 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
287 __Filter<__ContactsAddressbook> mainFilter;
288 mainFilter.Construct();
290 mainFilter.AddFilter(*pRwAbFilter);
291 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
292 mainFilter.AddFilter(accountFilter);
294 __Query<__ContactsAddressbook> query;
296 query.SetFilter(mainFilter);
298 pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
299 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
302 return pAddressbooks;
306 _AddressbookManagerImpl::GetAllAddressbooksN(void) const
308 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
312 __Filter<__ContactsAddressbook> abFilter;
313 abFilter.Construct();
314 abFilter.AddInt(_contacts_address_book.mode, CONTACTS_MATCH_EQUAL, 0);
316 __Query<__ContactsAddressbook> query;
318 query.SetFilter(abFilter);
319 query.SetSort(_contacts_address_book.name, true);
321 IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
322 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
324 return pAddressbooks;
328 _AddressbookManagerImpl::GetAddressbookN(AddressbookId addressbookId) const
330 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. addressbookId.", GetErrorMessage(E_INVALID_ARG), addressbookId);
331 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
335 result r = E_SUCCESS;
337 char* pCharValue = null;
339 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
340 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
342 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
343 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
345 unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
346 SysTryReturn(NID_SCL, pAddressbook !=null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
348 r = pAddressbook->Construct();
349 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
351 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(addressbookId);
353 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.account_id, &intValue);
354 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
356 contacts_record_get_str_p(pAbRecord.get(), _contacts_address_book.name, &pCharValue);
357 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
359 return pAddressbook.release();
363 _AddressbookManagerImpl::AddContact(Contact& contact, AddressbookId addressbookId)
365 if (_ContactImpl::GetInstance(contact)->IsRemoved())
367 result r = _ContactImpl::GetInstance(contact)->Invalidate();
368 SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
371 SysTryReturn(NID_SCL, contact.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The ID of specified contact is not INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
372 SysTryReturn(NID_SCL, !_ContactImpl::GetInstance(contact)->IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact does not have any property.", GetErrorMessage(E_INVALID_ARG));
373 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
375 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
376 SysTryReturn(NID_SCL, pAbRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
379 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
380 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
382 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
383 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, addressbookId);
386 result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
387 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
389 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, recordId));
390 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
392 _ContactImpl::GetInstance(contact)->SetContactRecordHandle(pContactRecord.release());
393 _RecordImpl::GetInstance(contact)->SetRecordId(recordId);
399 _AddressbookManagerImpl::AddCategory(Category& category, AddressbookId addressbookId)
401 SysTryReturn(NID_SCL, category.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified categoryId is not INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
402 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
404 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
405 SysTryReturn(NID_SCL, pAbRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
408 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
409 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
411 contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
412 contacts_record_set_int(recordHandle, _contacts_group.address_book_id, addressbookId);
415 result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
416 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
418 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, recordId));
419 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
421 _CategoryImpl::GetInstance(category)->SetRecordHandle(pCategoryRecord.release());
422 _RecordImpl::GetInstance(category)->SetRecordId(recordId);
424 unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
425 if (pList != null && pList->GetCount() > 0)
427 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
429 while (pEnum->MoveNext() == E_SUCCESS)
432 pEnum->GetCurrent(tableId);
434 AddMemberToCategory(category.GetRecordId(), tableId);
437 _CategoryImpl::GetInstance(category)->ClearAddedMemberList();
444 _AddressbookManagerImpl::RemoveContact(RecordId contactId)
446 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contactId is invalid.", GetErrorMessage(E_INVALID_ARG));
447 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
448 result r = _AddressbookUtil::DeleteContactRecord(_contacts_contact._uri, contactId);
449 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
455 _AddressbookManagerImpl::RemoveCategory(RecordId categoryId)
457 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified categoryId is invalid", GetErrorMessage(E_INVALID_ARG));
458 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
460 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
461 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
463 bool isReadOnly = false;
464 contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly);
465 SysTryReturn(NID_SCL, !isReadOnly, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is a default category.", GetErrorMessage(E_INVALID_ARG));
467 result r = _AddressbookUtil::DeleteContactRecord(_contacts_group._uri, categoryId);
468 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
474 _AddressbookManagerImpl::UpdateContact(const Contact& contact)
476 RecordId contactId = contact.GetRecordId();
477 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contactId is not INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
478 SysTryReturn(NID_SCL, !_ContactImpl::GetInstance(contact)->IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact does not have any property.", GetErrorMessage(E_INVALID_ARG));
479 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
481 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
482 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
485 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
486 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
488 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
489 SysTryReturn(NID_SCL, recordHandle != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
491 result r = _AddressbookUtil::UpdateContactRecord(recordHandle);
492 if (r == E_OBJ_NOT_FOUND)
494 unsigned int count = 0;
495 unsigned int count2 = 0;
497 contacts_record_h newRecordHandle = null;
498 int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &newRecordHandle);
499 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
500 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
502 contacts_record_get_child_record_count(newRecordHandle, _contacts_contact.image, &count);
503 contacts_record_get_child_record_count(recordHandle, _contacts_contact.image, &count2);
505 contacts_record_h imageHandle = null;
506 contacts_record_h imageHandle2 = null;
511 for (int i = (int)count2 - 1; i >= 0; i--)
513 contacts_record_get_child_record_at_p(recordHandle, _contacts_contact.image, i, &imageHandle);
514 contacts_record_get_int(imageHandle, _contacts_image.id, &imageId);
520 bool matchFound = false;
522 for (unsigned int j = 0; j < count; j++)
524 contacts_record_get_child_record_at_p(newRecordHandle, _contacts_contact.image, i, &imageHandle2);
525 contacts_record_get_int(imageHandle2, _contacts_image.id, &imageId2);
526 if (imageId == imageId2)
535 contacts_record_remove_child_record(recordHandle, _contacts_contact.image, imageHandle);
539 contacts_record_destroy(newRecordHandle, true);
541 contacts_record_h copyRecordHandle = CopyContactRecordHandle(recordHandle);
542 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
544 contacts_record_h tempHandle = null;
545 contacts_record_get_child_record_count(copyRecordHandle, _contacts_contact.image, &count);
547 char* pCharValue = null;
550 for (unsigned int i = 0; i < count; i++)
552 contacts_record_get_child_record_at_p(copyRecordHandle, _contacts_contact.image, i, &tempHandle);
553 contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue);
555 tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp";
556 tempPath.Append((int)i);
557 tempPath.Append(L".jpg");
558 String servicePath(pCharValue);
560 File::Copy(servicePath, tempPath, true);
562 std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(tempPath));
563 SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
565 contacts_record_set_str(tempHandle, _contacts_image.path, pCharArray.get());
566 contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue);
571 ret = contacts_db_replace_record(copyRecordHandle, contactId);
572 contacts_record_destroy(copyRecordHandle, true);
574 for (unsigned int i = 0; i < count; i++)
576 tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp";
577 tempPath.Append((int)i);
578 tempPath.Append(L".jpg");
580 File::Remove(tempPath);
584 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
585 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
586 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed to update a contact.", GetErrorMessage(E_SYSTEM));
590 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
592 pContactRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contact.GetRecordId()));
593 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
595 _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(pContactRecord.release());
601 _AddressbookManagerImpl::UpdateCategory(const Category& category)
603 RecordId categoryId = category.GetRecordId();
604 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is invalid.", GetErrorMessage(E_INVALID_ARG));
605 SysTryReturn(NID_SCL, !category.GetName().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category does not have name.", GetErrorMessage(E_INVALID_ARG));
606 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
608 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
609 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
612 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
613 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
615 contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
617 result r = _AddressbookUtil::UpdateContactRecord(recordHandle);
618 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
620 pCategoryRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
621 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
623 _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(pCategoryRecord.release());
625 unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
626 if (pList != null && pList->GetCount() > 0)
629 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
630 while (pEnum->MoveNext() == E_SUCCESS)
632 pEnum->GetCurrent(tableId);
634 AddMemberToCategory(category.GetRecordId(), tableId);
637 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList();
640 pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN());
641 if (pList != null && pList->GetCount() > 0)
644 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
645 while (pEnum->MoveNext() == E_SUCCESS)
647 pEnum->GetCurrent(tableId);
649 RemoveMemberFromCategory(category.GetRecordId(), tableId);
652 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList();
659 _AddressbookManagerImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
661 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
662 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
663 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
665 result r = _AddressbookUtil::AddContactToCategory(categoryId, contactId);
666 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
672 _AddressbookManagerImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
674 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
675 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
676 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
678 result r = _AddressbookUtil::RemoveContactFromCategory(categoryId, contactId);
679 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
685 _AddressbookManagerImpl::GetAllCategoriesN(void) const
687 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
691 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
693 __Query<__ContactsGroup> query;
695 query.SetSort(_contacts_group.name, true);
697 if (pRwAbFilter->Get() != null)
699 query.SetFilter(*pRwAbFilter);
702 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
703 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
709 _AddressbookManagerImpl::GetCategoriesByContactN(RecordId contactId) const
711 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
712 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact is invalid.", GetErrorMessage(E_INVALID_ARG));
715 IList* pCategories = null;
717 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
719 __Filter<__ContactsContactGroupRel> relFilter;
720 relFilter.Construct();
721 relFilter.AddInt(_contacts_contact_grouprel.contact_id, CONTACTS_MATCH_EQUAL, contactId);
723 if (pRwAbFilter->Get() != null)
725 __Filter<__ContactsContactGroupRel> mainFilter;
726 mainFilter.Construct();
727 mainFilter.AddFilter(*pRwAbFilter);
728 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
729 mainFilter.AddFilter(relFilter);
731 __Query<__ContactsContactGroupRel> query;
733 query.SetFilter(mainFilter);
735 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
736 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
740 __Query<__ContactsContactGroupRel> query;
742 query.SetFilter(relFilter);
744 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
745 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
752 _AddressbookManagerImpl::GetCategoriesByPersonN(PersonId personId) const
754 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
758 IList* pCategories = null;
760 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
762 __Filter<__ContactsContactGroupRel> relFilter;
763 relFilter.Construct();
764 relFilter.AddInt(_contacts_contact_grouprel.person_id, CONTACTS_MATCH_EQUAL, personId);
765 relFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
766 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_GREATER_THAN, 0);
768 unsigned int propertyIds[] =
770 _contacts_contact_grouprel.group_id,
773 if (pRwAbFilter->Get() != null)
776 __Filter<__ContactsContactGroupRel> mainFilter;
777 mainFilter.Construct();
778 mainFilter.AddFilter(*pRwAbFilter);
779 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
780 mainFilter.AddFilter(relFilter);
783 __Query<__ContactsContactGroupRel> query;
785 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
786 query.SetFilter(mainFilter);
787 query.SetSort(_contacts_contact_grouprel.group_name, true);
788 query.SetDistinct(true);
790 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
791 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
795 __Query<__ContactsContactGroupRel> query;
797 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
798 query.SetFilter(relFilter);
799 query.SetSort(_contacts_contact_grouprel.group_name, true);
800 query.SetDistinct(true);
802 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
803 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
811 _AddressbookManagerImpl::GetAllContactsN(void) const
813 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
817 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
819 __Query<__ContactsContact> query;
821 query.SetSort(_contacts_contact.display_name, true);
823 if (pRwAbFilter->Get() != null)
825 query.SetFilter(*pRwAbFilter);
828 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
829 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
835 _AddressbookManagerImpl::GetContactsByCategoryN(RecordId categoryId) const
837 SysTryReturn(NID_SCL, categoryId >= INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. The category ID must be greater than or equal to INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
838 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
842 IList* pContacts = null;
844 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
846 __Filter<__ContactsContactGroupRel> relFilter;
847 relFilter.Construct();
849 if (categoryId != INVALID_RECORD_ID)
851 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
855 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
858 if (pRwAbFilter->Get() != null)
860 __Filter<__ContactsContactGroupRel> mainFilter;
861 mainFilter.Construct();
863 mainFilter.AddFilter(*pRwAbFilter);
864 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
865 mainFilter.AddFilter(relFilter);
867 __Query<__ContactsContactGroupRel> query;
869 query.SetFilter(mainFilter);
871 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
872 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
876 __Query<__ContactsContactGroupRel> query;
878 query.SetFilter(relFilter);
880 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
881 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
888 _AddressbookManagerImpl::GetContactsByPersonN(PersonId personId) const
890 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
894 IList* pContacts = null;
896 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
898 __Filter<__ContactsContact> contactFilter;
899 contactFilter.Construct();
900 contactFilter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
902 if (pRwAbFilter->Get() != null)
904 __Filter<__ContactsContact> mainFilter;
905 mainFilter.Construct();
907 mainFilter.AddFilter(*pRwAbFilter);
908 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
909 mainFilter.AddFilter(contactFilter);
911 __Query<__ContactsContact> query;
913 query.SetFilter(mainFilter);
914 query.SetSort(_contacts_contact.display_name, true);
916 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
917 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
921 __Query<__ContactsContact> query;
923 query.SetFilter(contactFilter);
924 query.SetSort(_contacts_contact.display_name, true);
926 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
927 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
934 _AddressbookManagerImpl::SearchContactsByEmailN(const String& email) const
936 SysTryReturn(NID_SCL, !email.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified email is an empty string.", GetErrorMessage(E_INVALID_ARG));
937 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
941 IList* pContacts = null;
943 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
945 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
946 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
948 __Filter<__ContactsContactEmail> emailFilter;
949 emailFilter.Construct();
950 emailFilter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
952 if (pRwAbFilter->Get() != null)
954 __Filter<__ContactsContactEmail> mainFilter;
955 mainFilter.Construct();
957 mainFilter.AddFilter(*pRwAbFilter);
958 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
959 mainFilter.AddFilter(emailFilter);
961 __Query<__ContactsContactEmail> query;
963 query.SetFilter(mainFilter);
964 query.SetSort(_contacts_contact_email.display_name, true);
966 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
967 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
971 __Query<__ContactsContactEmail> query;
973 query.SetFilter(emailFilter);
974 query.SetSort(_contacts_contact_email.display_name, true);
976 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
977 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
985 _AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
987 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
991 IList* pContacts = null;
993 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
995 SysTryReturn(NID_SCL, !name.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified email is an name string.", GetErrorMessage(E_INVALID_ARG));
997 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
998 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1000 __Filter<__ContactsContact> nameFilter;
1001 nameFilter.Construct();
1002 nameFilter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
1004 if (pRwAbFilter->Get() != null)
1006 __Filter<__ContactsContact> mainFilter;
1007 mainFilter.Construct();
1009 mainFilter.AddFilter(*pRwAbFilter);
1010 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1011 mainFilter.AddFilter(nameFilter);
1013 __Query<__ContactsContact> query;
1015 query.SetFilter(mainFilter);
1016 query.SetSort(_contacts_contact.display_name, true);
1018 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
1019 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1023 __Query<__ContactsContact> query;
1025 query.SetFilter(nameFilter);
1026 query.SetSort(_contacts_contact.display_name, true);
1028 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
1029 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1036 _AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
1038 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1042 IList* pContacts = null;
1044 SysTryReturn(NID_SCL, !phoneNumber.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified phoneNumber is an empty string.", GetErrorMessage(E_INVALID_ARG));
1046 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
1048 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
1049 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1051 __Filter<__ContactsContactNumber> numberFilter;
1052 numberFilter.Construct();
1053 numberFilter.AddString(_contacts_contact_number.normalized_number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
1054 numberFilter.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
1055 numberFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
1057 if (pRwAbFilter->Get() != null)
1059 __Filter<__ContactsContactNumber> mainFilter;
1060 mainFilter.Construct();
1062 mainFilter.AddFilter(*pRwAbFilter);
1063 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1064 mainFilter.AddFilter(numberFilter);
1066 __Query<__ContactsContactNumber> query;
1068 query.SetFilter(mainFilter);
1069 query.SetDistinct(true);
1070 query.SetSort(_contacts_contact_number.display_name, true);
1072 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
1073 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1077 __Query<__ContactsContactNumber> query;
1079 query.SetFilter(numberFilter);
1080 query.SetDistinct(true);
1081 query.SetSort(_contacts_contact_number.display_name, true);
1083 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
1084 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1092 _AddressbookManagerImpl::GetCategoryCount(void) const
1094 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1098 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1100 int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(pRwAbFilter->Get());
1101 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1107 _AddressbookManagerImpl::GetContactCount(void) const
1109 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1113 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1115 int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(pRwAbFilter->Get());
1116 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1122 _AddressbookManagerImpl::GetContactN(RecordId contactId) const
1124 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1125 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
1129 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId));
1130 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1133 contacts_record_get_int(pContactRecord.get(), _contacts_contact.address_book_id, &intValue);
1135 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
1136 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1138 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
1139 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Contact does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
1141 contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue);
1142 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1144 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
1145 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1147 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
1148 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
1150 return pContact.release();
1154 _AddressbookManagerImpl::GetPersonN(PersonId personId) const
1156 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1157 SysTryReturn(NID_SCL, personId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1161 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1164 contacts_record_get_int(pPersonRecord.get(), _contacts_person.id, &intValue);
1165 SysTryReturn(NID_SCL, intValue == personId, null, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1167 Person* pPerson = __ContactsPerson::ConvertHandleTo<Person>(pPersonRecord.get());
1168 SysTryReturn(NID_SCL, pPerson != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1174 _AddressbookManagerImpl::GetCategoryN(RecordId categoryId) const
1176 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. categoryId = %d.", categoryId);
1177 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1181 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
1182 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1186 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
1187 SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1189 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.address_book_id, &intValue);
1191 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
1192 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1194 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
1195 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Category does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
1197 unique_ptr<Category> pCategory(new (std::nothrow) Category());
1198 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1200 __Filter<__ContactsGroupRelation> filter;
1202 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1204 __Query<__ContactsGroupRelation> query;
1206 query.SetFilter(filter);
1208 int count = _AddressbookUtil::GetCountWithQuery(query);
1209 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1211 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
1212 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1213 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1215 return pCategory.release();
1219 _AddressbookManagerImpl::GetLatestVersion(void) const
1221 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1223 int latestVersion = -1;
1227 int ret = contacts_db_get_current_version(&latestVersion);
1228 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1230 return latestVersion;
1234 _AddressbookManagerImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1236 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid arguent is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version);
1237 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1241 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1243 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1244 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1246 return pChangedContacts;
1250 _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1252 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid arguemnt is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version);
1253 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1257 int latestVersion1 = 0;
1258 int latestVersion2 = 0;
1260 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1262 unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion1, pRwAbIdList.get()));
1263 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1265 unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion2, pRwAbIdList.get()));
1266 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1268 unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1269 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1271 result r = pChangeList->AddItems(*pChangedGroups);
1272 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1274 r = pChangeList->AddItems(*pChangedRelations);
1275 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1277 pChangedGroups->RemoveAll(false);
1278 pChangedRelations->RemoveAll(false);
1280 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1282 return pChangeList.release();
1286 _AddressbookManagerImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1288 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version);
1289 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1293 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1295 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1296 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1298 return pChangedRelations;
1302 _AddressbookManagerImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1304 SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version);
1305 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1309 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1311 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1312 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1314 return pChangedRelations;
1318 _AddressbookManagerImpl::OnContactChanged(void)
1320 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1325 IList* pChangedContactList = GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact);
1326 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1328 if (pChangedContactList->GetCount() > 0)
1330 if (__pIAddressbookChangeEventListener != null)
1332 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1336 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1340 pChangedContactList->RemoveAll(true);
1341 delete pChangedContactList;
1345 _AddressbookManagerImpl::OnCategoryChanged(void)
1347 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1352 IList* pChangedCategoryList = GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup);
1353 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1355 if (pChangedCategoryList->GetCount() > 0)
1357 if (__pIAddressbookChangeEventListener != null)
1359 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1363 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1367 pChangedCategoryList->RemoveAll(true);
1368 delete pChangedCategoryList;
1372 _AddressbookManagerImpl::OnRelationChanged(void)
1374 if (__pIAddressbookEventListener == null)
1379 IList* pChangedCategoryList = GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation);
1380 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1382 if (pChangedCategoryList->GetCount() > 0)
1384 if (__pIAddressbookEventListener != null)
1386 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1390 pChangedCategoryList->RemoveAll(true);
1391 delete pChangedCategoryList;
1395 _AddressbookManagerImpl::RemovePerson(PersonId personId)
1397 SysTryReturnResult(NID_SCL, personId > 0, E_INVALID_ARG, "[%s] Invalid argument is used. ", GetErrorMessage(E_INVALID_ARG));
1398 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1400 result r = _AddressbookUtil::DeleteContactRecord(_contacts_person._uri, personId);
1401 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1407 _AddressbookManagerImpl::GetAllPersonsN(void) const
1409 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1413 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1415 unsigned int propertyIds[] =
1417 _contacts_person_grouprel.person_id,
1418 _contacts_person_grouprel.display_name,
1419 _contacts_person_grouprel.image_thumbnail_path,
1420 _contacts_person_grouprel.ringtone_path,
1421 _contacts_person_grouprel.is_favorite,
1422 _contacts_person_grouprel.has_phonenumber,
1423 _contacts_person_grouprel.has_email,
1424 _contacts_person_grouprel.addressbook_ids,
1428 __Query<__ContactsPersonGroupRel> query;
1430 query.SetSort(_contacts_person.display_name, true);
1431 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1432 query.SetDistinct(true);
1434 if (pRwAbFilter->Get() != null)
1436 query.SetFilter(*pRwAbFilter);
1439 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1440 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1446 _AddressbookManagerImpl::GetPersonsByCategoryN(RecordId categoryId) const
1448 SysTryReturn(NID_SCL, categoryId >= INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified categoryId is less than INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
1449 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1453 if (categoryId > INVALID_RECORD_ID)
1455 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
1456 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1457 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_SYSTEM, "[%s] An system error has been occurred.", GetErrorMessage(E_SYSTEM));
1460 IList* pPersons = null;
1462 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1464 __Filter<__ContactsPersonGroupRel> groupFilter;
1465 groupFilter.Construct();
1466 if (categoryId != INVALID_RECORD_ID)
1468 groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1472 groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
1475 unsigned int propertyIds[] =
1477 _contacts_person_grouprel.person_id,
1478 _contacts_person_grouprel.display_name,
1479 _contacts_person_grouprel.image_thumbnail_path,
1480 _contacts_person_grouprel.ringtone_path,
1481 _contacts_person_grouprel.is_favorite,
1482 _contacts_person_grouprel.has_phonenumber,
1483 _contacts_person_grouprel.has_email,
1484 _contacts_person_grouprel.addressbook_ids,
1487 if (pRwAbFilter->Get() != null)
1489 __Filter<__ContactsPersonGroupRel> mainFilter;
1490 mainFilter.Construct();
1492 mainFilter.AddFilter(*pRwAbFilter);
1493 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1494 mainFilter.AddFilter(groupFilter);
1496 __Query<__ContactsPersonGroupRel> query;
1498 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1499 query.SetFilter(mainFilter);
1500 query.SetSort(_contacts_person_grouprel.display_name, true);
1501 query.SetDistinct(true);
1503 pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1504 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1508 __Query<__ContactsPersonGroupRel> query;
1510 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1511 query.SetFilter(groupFilter);
1512 query.SetSort(_contacts_person_grouprel.display_name, true);
1513 query.SetDistinct(true);
1515 pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1516 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1524 _AddressbookManagerImpl::GetFavoritePersonsN() const
1526 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1530 __Filter<__ContactsPerson> filter;
1532 filter.AddBool(_contacts_person.is_favorite, true);
1534 __Query<__ContactsPerson> query;
1536 query.SetFilter(filter);
1537 query.SetSort(_contacts_person.display_name, true);
1539 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPerson, Person>(query);
1540 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1546 _AddressbookManagerImpl::SearchPersonsN(const Tizen::Base::String& keyword) const
1548 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1549 SysTryReturn(NID_SCL, !keyword.IsEmpty(), null, E_INVALID_ARG, "Invalid argument is used. keyword is empty string.", GetErrorMessage(E_INVALID_ARG));
1553 contacts_record_h currentRecord = null;
1554 unique_ptr<Person> pPerson(null);
1556 unique_ptr<ArrayList, AllElementsDeleter> pPersonList(new (std::nothrow) ArrayList());
1557 SysTryReturn(NID_SCL, pPersonList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1559 result r = pPersonList->Construct();
1560 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1562 unique_ptr<__SearchResult<__ContactsPerson> > pSearchResult(_AddressbookUtil::Search<__ContactsPerson>(keyword));
1563 SysTryReturn(NID_SCL, pSearchResult != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1565 while (pSearchResult->MoveNext() == E_SUCCESS)
1567 currentRecord = pSearchResult->GetCurrentRecord();
1568 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1570 pPerson.reset(__ContactsPerson::ConvertHandleTo<Person>(currentRecord));
1571 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1573 r = pPersonList->Add(*pPerson);
1574 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1579 return pPersonList.release();
1583 _AddressbookManagerImpl::SetPersonAsFavorite(PersonId personId, bool isFavorite)
1585 SysTryReturn(NID_SCL, personId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1586 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1588 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1589 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1591 bool boolValue = false;
1592 contacts_record_get_bool(pPersonRecord.get(), _contacts_person.is_favorite, &boolValue);
1594 if (boolValue != isFavorite)
1596 contacts_record_set_bool(pPersonRecord.get(), _contacts_person.is_favorite, isFavorite);
1598 result r = _AddressbookUtil::UpdateContactRecord(pPersonRecord.get());
1599 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1606 _AddressbookManagerImpl::MergePersons(PersonId sourcePersonId, PersonId targetPersonId)
1608 SysTryReturn(NID_SCL, sourcePersonId > 0 && targetPersonId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. sourcePersonId %d and targetPersonId must be greater than 0.", GetErrorMessage(E_INVALID_ARG), sourcePersonId, targetPersonId);
1609 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1611 int ret = contacts_person_link_person(targetPersonId, sourcePersonId);
1612 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1613 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1619 _AddressbookManagerImpl::UnlinkContact(PersonId personId, RecordId contactId, PersonId& newPersonId)
1621 SysTryReturn(NID_SCL, personId > 0 && contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. personId %d must be greater thant 0 and contactId %d must not be INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG), personId, contactId);
1622 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1624 int ret = contacts_person_unlink_contact(personId, contactId, &newPersonId);
1625 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1626 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1632 _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount)
1634 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1638 IList* pList = null;
1639 bool ascending = false;
1640 unsigned int viewSortPropertyId = 0;
1642 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1643 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1645 SysTryReturn(NID_SCL, propertySortedBy == 0 || _AddressbookFilterImpl::IsValidProperty(type, propertySortedBy), null, E_INVALID_ARG, "[%s] Invalid argument is used. The protertyToSort %d can not be used for property for sorting.", GetErrorMessage(E_INVALID_ARG), propertySortedBy);
1647 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1649 viewSortPropertyId = _AddressbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1650 ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1655 case AB_FI_TYPE_ADDRESSBOOK:
1657 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
1659 __Filter<__ContactsAddressbook> abFilter;
1660 abFilter.Construct(filterHandle);
1662 if (pRwAbFilter->Get() != null)
1664 __Filter<__ContactsAddressbook> mainFilter;
1665 mainFilter.Construct();
1666 mainFilter.AddFilter(*pRwAbFilter);
1667 if (abFilter.Get() != null)
1669 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1670 mainFilter.AddFilter(abFilter);
1673 __Query<__ContactsAddressbook> query;
1675 query.SetFilter(mainFilter);
1677 if (viewSortPropertyId != 0)
1679 query.SetSort(viewSortPropertyId, ascending);
1682 pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
1686 __Query<__ContactsAddressbook> query;
1688 query.SetFilter(abFilter);
1690 if (viewSortPropertyId != 0)
1692 query.SetSort(viewSortPropertyId, ascending);
1695 pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
1700 case AB_FI_TYPE_PERSON:
1702 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1704 __Filter<__ContactsPersonGroupRel> personFilter;
1705 personFilter.Construct(filterHandle);
1707 unsigned int propertyIds[] =
1708 { _contacts_person_grouprel.person_id,
1709 _contacts_person_grouprel.addressbook_ids,
1710 _contacts_person_grouprel.is_favorite,
1711 _contacts_person_grouprel.has_phonenumber,
1712 _contacts_person_grouprel.has_email,
1713 _contacts_person_grouprel.image_thumbnail_path,
1714 _contacts_person_grouprel.ringtone_path,
1715 _contacts_person_grouprel.display_name
1718 if (pRwAbFilter->Get() != null)
1720 __Filter<__ContactsPersonGroupRel> mainFilter;
1721 mainFilter.Construct();
1722 mainFilter.AddFilter(*pRwAbFilter);
1723 if (personFilter.Get() != null)
1725 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1726 mainFilter.AddFilter(personFilter);
1729 __Query<__ContactsPersonGroupRel> query;
1731 query.SetFilter(mainFilter);
1732 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1733 query.SetDistinct(true);
1735 if (viewSortPropertyId != 0)
1737 query.SetSort(viewSortPropertyId, ascending);
1740 pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
1744 __Query<__ContactsPersonGroupRel> query;
1746 query.SetFilter(personFilter);
1747 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1748 query.SetDistinct(true);
1750 if (viewSortPropertyId != 0)
1752 query.SetSort(viewSortPropertyId, ascending);
1755 pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
1759 case AB_FI_TYPE_CONTACT:
1761 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1763 __Filter<__ContactsContact> contactFilter;
1764 contactFilter.Construct(filterHandle);
1766 if (pRwAbFilter->Get() != null)
1768 __Filter<__ContactsContact> mainFilter;
1769 mainFilter.Construct();
1770 mainFilter.AddFilter(*pRwAbFilter);
1771 if (contactFilter.Get() != null)
1773 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1774 mainFilter.AddFilter(contactFilter);
1777 __Query<__ContactsContact> query;
1779 query.SetFilter(mainFilter);
1781 if (viewSortPropertyId != 0)
1783 query.SetSort(viewSortPropertyId, ascending);
1786 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
1790 __Query<__ContactsContact> query;
1792 query.SetFilter(contactFilter);
1794 if (viewSortPropertyId != 0)
1796 query.SetSort(viewSortPropertyId, ascending);
1799 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
1804 case AB_FI_TYPE_CATEGORY:
1806 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1808 __Filter<__ContactsGroup> groupFilter;
1809 groupFilter.Construct(filterHandle);
1811 if (pRwAbFilter->Get() != null)
1813 __Filter<__ContactsGroup> mainFilter;
1814 mainFilter.Construct();
1815 mainFilter.AddFilter(*pRwAbFilter);
1816 if (groupFilter.Get() != null)
1818 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1819 mainFilter.AddFilter(groupFilter);
1822 __Query<__ContactsGroup> query;
1824 query.SetFilter(mainFilter);
1826 if (viewSortPropertyId != 0)
1828 query.SetSort(viewSortPropertyId, ascending);
1831 pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
1835 __Query<__ContactsGroup> query;
1837 query.SetFilter(groupFilter);
1839 if (viewSortPropertyId != 0)
1841 query.SetSort(viewSortPropertyId, ascending);
1844 pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
1848 case AB_FI_TYPE_PHONE_CONTACT:
1850 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
1852 __Filter<__ContactsContactNumber> numberFilter;
1853 numberFilter.Construct(filterHandle);
1855 if (pRwAbFilter->Get() != null)
1857 __Filter<__ContactsContactNumber> mainFilter;
1858 mainFilter.Construct();
1859 mainFilter.AddFilter(*pRwAbFilter);
1860 if (numberFilter.Get() != null)
1862 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1863 mainFilter.AddFilter(numberFilter);
1866 __Query<__ContactsContactNumber> query;
1868 query.SetFilter(mainFilter);
1870 if (viewSortPropertyId != 0)
1872 query.SetSort(viewSortPropertyId, ascending);
1875 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
1879 __Query<__ContactsContactNumber> query;
1881 query.SetFilter(numberFilter);
1883 if (viewSortPropertyId != 0)
1885 query.SetSort(viewSortPropertyId, ascending);
1888 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
1892 case AB_FI_TYPE_EMAIL_CONTACT:
1894 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
1896 __Filter<__ContactsContactEmail> emailFilter;
1897 emailFilter.Construct(filterHandle);
1899 if (pRwAbFilter->Get() != null)
1901 __Filter<__ContactsContactEmail> mainFilter;
1902 mainFilter.Construct();
1903 mainFilter.AddFilter(*pRwAbFilter);
1904 if (emailFilter.Get() != null)
1906 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1907 mainFilter.AddFilter(emailFilter);
1910 __Query<__ContactsContactEmail> query;
1912 query.SetFilter(mainFilter);
1914 if (viewSortPropertyId != 0)
1916 query.SetSort(viewSortPropertyId, ascending);
1919 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
1923 __Query<__ContactsContactEmail> query;
1925 query.SetFilter(emailFilter);
1927 if (viewSortPropertyId != 0)
1929 query.SetSort(viewSortPropertyId, ascending);
1932 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
1937 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The filter type is invalid", GetErrorMessage(E_INVALID_ARG));
1946 _AddressbookManagerImpl::GetMatchedItemCount(const AddressbookFilter& filter)
1948 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1953 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1954 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1958 case AB_FI_TYPE_ADDRESSBOOK:
1960 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
1962 __Filter<__ContactsAddressbook> abFilter;
1963 abFilter.Construct(filterHandle);
1965 if (pRwAbFilter->Get() != null)
1967 __Filter<__ContactsAddressbook> mainFilter;
1968 mainFilter.Construct();
1969 mainFilter.AddFilter(*pRwAbFilter);
1970 if (abFilter.Get() != null)
1972 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1973 mainFilter.AddFilter(abFilter);
1976 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(mainFilter.Get());
1980 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(abFilter.Get());
1984 case AB_FI_TYPE_PERSON:
1986 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1988 __Filter<__ContactsPersonGroupRel> personFilter;
1989 personFilter.Construct(filterHandle);
1991 if (pRwAbFilter->Get() != null)
1993 __Filter<__ContactsPersonGroupRel> mainFilter;
1994 mainFilter.Construct();
1995 mainFilter.AddFilter(*pRwAbFilter);
1996 if (personFilter.Get() != null)
1998 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1999 mainFilter.AddFilter(personFilter);
2002 unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
2004 __Query<__ContactsPersonGroupRel> query;
2006 query.SetFilter(mainFilter);
2007 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
2008 query.SetDistinct(true);
2010 count = _AddressbookUtil::GetCountWithQuery(query);
2014 unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
2016 __Query<__ContactsPersonGroupRel> query;
2018 query.SetFilter(personFilter);
2019 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
2020 query.SetDistinct(true);
2022 count = _AddressbookUtil::GetCountWithQuery(query);
2028 case AB_FI_TYPE_CONTACT:
2030 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
2032 __Filter<__ContactsContact> contactFilter;
2033 contactFilter.Construct(filterHandle);
2035 if (pRwAbFilter->Get() != null)
2037 __Filter<__ContactsContact> mainFilter;
2038 mainFilter.Construct();
2039 mainFilter.AddFilter(*pRwAbFilter);
2040 if (contactFilter.Get() != null)
2042 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2043 mainFilter.AddFilter(contactFilter);
2046 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(mainFilter.Get());
2050 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(contactFilter.Get());
2054 case AB_FI_TYPE_CATEGORY:
2056 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
2058 __Filter<__ContactsGroup> groupFilter;
2059 groupFilter.Construct(filterHandle);
2061 if (pRwAbFilter->Get() != null)
2063 __Filter<__ContactsGroup> mainFilter;
2064 mainFilter.Construct();
2065 mainFilter.AddFilter(*pRwAbFilter);
2066 if (groupFilter.Get() != null)
2068 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2069 mainFilter.AddFilter(groupFilter);
2072 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(mainFilter.Get());
2076 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(groupFilter.Get());
2080 case AB_FI_TYPE_PHONE_CONTACT:
2082 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
2084 __Filter<__ContactsContactNumber> numberFilter;
2085 numberFilter.Construct(filterHandle);
2087 if (pRwAbFilter->Get() != null)
2089 __Filter<__ContactsContactNumber> mainFilter;
2090 mainFilter.Construct();
2091 mainFilter.AddFilter(*pRwAbFilter);
2092 if (numberFilter.Get() != null)
2094 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2095 mainFilter.AddFilter(numberFilter);
2098 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(mainFilter.Get());
2102 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(numberFilter.Get());
2106 case AB_FI_TYPE_EMAIL_CONTACT:
2108 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
2110 __Filter<__ContactsContactEmail> emailFilter;
2111 emailFilter.Construct(filterHandle);
2113 if (pRwAbFilter->Get() != null)
2115 __Filter<__ContactsContactEmail> mainFilter;
2116 mainFilter.Construct();
2117 mainFilter.AddFilter(*pRwAbFilter);
2118 if (emailFilter.Get() != null)
2120 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2121 mainFilter.AddFilter(emailFilter);
2124 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(mainFilter.Get());
2128 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(emailFilter.Get());
2133 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter is invalid", GetErrorMessage(GetLastResult()));
2142 _AddressbookManagerImpl::OnEachContact(contacts_record_h recordHandle, void* pUserData)
2144 IList* pList = static_cast<IList*>(pUserData);
2148 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
2149 SysTryReturn(NID_SCL, pContact != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2151 contacts_record_h newRecordHandle = null;
2153 contacts_record_clone(recordHandle, &newRecordHandle);
2154 SysTryReturn(NID_SCL, newRecordHandle != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2156 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecordHandle);
2158 result r = pList->Add(*pContact);
2159 SysTryReturn(NID_SCL, !IsFailed(r), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2167 _AddressbookManagerImpl::ParseContactsFromVcardN(const Tizen::Base::String& vcardPath)
2169 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2174 result r = file.Construct(vcardPath, "r");
2175 SysTryReturn(NID_SCL, r != E_INVALID_ARG, null, E_INVALID_ARG, "[%s] Invalid argument is used..", GetErrorMessage(E_INVALID_ARG));
2176 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
2177 SysTryReturn(NID_SCL, r != E_FILE_NOT_FOUND, null, E_FILE_NOT_FOUND, "[%s] The specified file does not exist.", GetErrorMessage(E_FILE_NOT_FOUND));
2178 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2180 unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2182 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(vcardPath));
2184 int ret = contacts_vcard_parse_to_contact_foreach(pCharArray.get(), OnEachContact, pList.get());
2185 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2186 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2187 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2189 return pList.release();
2193 _AddressbookManagerImpl::ExportPersonToVcard(const Person& person, const Tizen::Base::String& vcardPath)
2195 bool exist = File::IsFileExist(vcardPath);
2196 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2197 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2198 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2201 result r = file.Construct(vcardPath, "w");
2202 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
2203 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2204 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2206 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
2207 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2209 char* pVcardStream = null;
2210 int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2211 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2212 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2214 r = file.Write(pVcardStream, strlen(pVcardStream));
2216 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2217 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2223 _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::IList& personList, const Tizen::Base::String& vcardPath)
2225 bool exist = File::IsFileExist(vcardPath);
2226 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2227 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2228 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2230 int ret = CONTACTS_ERROR_NONE;
2231 char* pVcardStream = null;
2234 result r = file.Construct(vcardPath, "w");
2235 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
2236 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2237 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2240 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
2242 unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
2243 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2245 while (pEnum->MoveNext() == E_SUCCESS)
2247 Person* pPerson = static_cast<Person*>(pEnum->GetCurrent());
2249 pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
2250 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2252 ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2253 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2254 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2256 r = file.Write(pVcardStream, strlen(pVcardStream));
2258 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2259 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2266 _AddressbookManagerImpl::ExportContactToVcard(const Contact& contact, const Tizen::Base::String& vcardPath)
2268 bool exist = File::IsFileExist(vcardPath);
2269 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2270 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2271 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2274 result r = file.Construct(vcardPath, "w");
2275 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
2276 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2277 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2279 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
2281 char* pVcardStream = null;
2283 int ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2284 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2285 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2287 r = file.Write(pVcardStream, strlen(pVcardStream));
2289 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2290 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2296 _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IList& contactList, const Tizen::Base::String& vcardPath)
2298 bool exist = File::IsFileExist(vcardPath);
2299 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2300 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2301 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2303 int ret = CONTACTS_ERROR_NONE;
2304 char* pVcardStream = null;
2306 Contact* pContact = null;
2308 result r = file.Construct(vcardPath, "w");
2309 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
2310 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2311 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2313 contacts_record_h recordHandle = null;
2315 unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
2316 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2318 while (pEnum->MoveNext() == E_SUCCESS)
2320 pContact = static_cast<Contact*>(pEnum->GetCurrent());
2322 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
2324 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2325 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2326 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2328 r = file.Write(pVcardStream, strlen(pVcardStream));
2330 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2331 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2338 _AddressbookManagerImpl::ExportContactToVcardStreamN(const Contact& contact)
2340 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2344 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
2346 char* pVcardStream = null;
2347 int ret = CONTACTS_ERROR_NONE;
2349 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2350 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2351 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2352 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2354 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2355 if (pByteBuffer == null)
2358 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2363 result r = pByteBuffer->Construct(strlen(pVcardStream));
2367 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2372 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2374 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2375 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2377 return pByteBuffer.release();
2381 _AddressbookManagerImpl::ExportContactsToVcardStreamN(const Tizen::Base::Collection::IList& contactList)
2383 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2387 char* pVcardStream = null;
2388 int ret = CONTACTS_ERROR_NONE;
2389 Contact* pContact = null;
2390 result r = E_SUCCESS;
2393 contacts_record_h recordHandle = null;
2395 unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
2396 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2398 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2399 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2401 r = pByteBuffer->Construct(capacity);
2402 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2404 if (contactList.GetCount() == 0)
2406 return pByteBuffer.release();
2409 while (pEnum->MoveNext() == E_SUCCESS)
2411 pContact = static_cast<Contact*>(pEnum->GetCurrent());
2413 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
2415 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2416 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2417 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2418 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2420 capacity += strlen(pVcardStream);
2421 r = pByteBuffer->ExpandCapacity(capacity);
2425 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2430 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2432 pVcardStream = null;
2433 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2436 return pByteBuffer.release();
2440 _AddressbookManagerImpl::ExportPersonToVcardStreamN(const Person& person)
2442 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2446 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
2447 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2448 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2450 char* pVcardStream = null;
2451 int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2452 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2453 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2454 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2456 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2457 if (pByteBuffer == null)
2460 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2465 result r = pByteBuffer->Construct(strlen(pVcardStream));
2469 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2474 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2476 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2478 return pByteBuffer.release();
2482 _AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collection::IList& personList)
2484 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2488 int ret = CONTACTS_ERROR_NONE;
2489 Person* pPerson = null;
2490 char* pVcardStream = null;
2494 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
2496 unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
2497 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2499 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2500 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2502 result r = pByteBuffer->Construct(capacity);
2503 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2505 if (personList.GetCount() == 0)
2507 return pByteBuffer.release();
2510 while (pEnum->MoveNext() == E_SUCCESS)
2512 pPerson = static_cast<Person*>(pEnum->GetCurrent());
2514 pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
2515 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2516 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2518 ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2519 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2520 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2521 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2523 capacity += strlen(pVcardStream);
2524 r = pByteBuffer->ExpandCapacity(capacity);
2528 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2533 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2535 pVcardStream = null;
2536 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2539 return pByteBuffer.release();
2543 _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardStream)
2545 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2549 contacts_list_h listHandle = null;
2550 result r = E_SUCCESS;
2552 int ret = contacts_vcard_parse_to_contacts(reinterpret_cast<char*>(const_cast<byte*>(vcardStream.GetPointer())), &listHandle);
2553 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2554 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2556 unsigned int count = 0;
2557 contacts_record_h recordHandle = null;
2558 contacts_list_get_count(listHandle, &count);
2560 unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2563 contacts_list_destroy(listHandle, true);
2564 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2569 r = pList->Construct(count);
2572 contacts_list_destroy(listHandle, true);
2573 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2578 for (unsigned int i = 0; i < count; i++)
2580 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
2581 if (pContact == null)
2583 contacts_list_destroy(listHandle, true);
2584 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2589 r = pList->Add(pContact.get());
2592 contacts_list_destroy(listHandle, true);
2593 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2601 unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2603 while (pEnum->MoveNext() == E_SUCCESS)
2605 Contact* pContact = static_cast <Contact*> (pEnum->GetCurrent());
2607 contacts_list_get_current_record_p(listHandle, &recordHandle);
2608 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(recordHandle);
2610 ret = contacts_list_next(listHandle);
2613 contacts_list_destroy(listHandle, false);
2615 return pList.release();
2619 _AddressbookManagerImpl::ExportUserProfileToVcardStreamN(const UserProfile& userProfile)
2621 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2625 char* pVcardStream = null;
2626 int ret = CONTACTS_ERROR_NONE;
2627 contacts_record_h recordHandle = null;
2629 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2631 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2632 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2633 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2634 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2636 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2637 if (pByteBuffer == null)
2640 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2644 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2646 result r = pByteBuffer->Construct(strlen(pVcardStream));
2650 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2655 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2657 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2658 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2660 return pByteBuffer.release();
2664 _AddressbookManagerImpl::ExportUserProfilesToVcardStreamN(const Tizen::Base::Collection::IList& userProfileList)
2666 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2670 char* pVcardStream = null;
2671 int ret = CONTACTS_ERROR_NONE;
2672 UserProfile* pProfile = null;
2673 result r = E_SUCCESS;
2676 unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2677 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2679 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2680 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2682 r = pByteBuffer->Construct(capacity);
2683 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2685 if (userProfileList.GetCount() == 0)
2687 return pByteBuffer.release();
2690 while (pEnum->MoveNext() == E_SUCCESS)
2692 contacts_record_h recordHandle = null;
2694 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2696 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2698 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2699 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2700 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2701 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2703 capacity += strlen(pVcardStream);
2704 r = pByteBuffer->ExpandCapacity(capacity);
2708 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2713 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2715 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2718 return pByteBuffer.release();
2722 _AddressbookManagerImpl::ExportUserProfileToVcard(const UserProfile& userProfile, const Tizen::Base::String& vcardPath)
2724 bool exist = File::IsFileExist(vcardPath);
2725 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2726 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2727 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2730 result r = file.Construct(vcardPath, "w");
2731 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
2732 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2733 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2735 char* pVcardStream = null;
2736 contacts_record_h recordHandle = null;
2738 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2740 int ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2741 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2742 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2744 r = file.Write(pVcardStream, strlen(pVcardStream));
2746 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2747 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2753 _AddressbookManagerImpl::ExportUserProfilesToVcard(const Tizen::Base::Collection::IList& userProfileList, const Tizen::Base::String& vcardPath)
2755 bool exist = File::IsFileExist(vcardPath);
2756 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2757 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2758 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2760 int ret = CONTACTS_ERROR_NONE;
2761 char* pVcardStream = null;
2763 UserProfile* pProfile = null;
2765 result r = file.Construct(vcardPath, "w");
2766 SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
2767 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2768 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2770 unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2771 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2773 while (pEnum->MoveNext() == E_SUCCESS)
2775 contacts_record_h recordHandle = null;
2777 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2779 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2781 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2782 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2783 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2785 r = file.Write(pVcardStream, strlen(pVcardStream));
2787 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2788 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2795 _AddressbookManagerImpl::GetAllUserProfilesN(void) const
2797 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2801 unique_ptr< __Filter<__ContactsUserProfile> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsUserProfile>());
2802 SysTryReturn(NID_SCL, pRwAbFilter != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2804 __Query<__ContactsUserProfile> query;
2806 query.SetSort(_contacts_my_profile.display_name, true);
2808 if (pRwAbFilter->Get() != null)
2810 query.SetFilter(*pRwAbFilter);
2813 IList* pUserProfilesList = _AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query);
2814 SysTryReturn(NID_SCL, pUserProfilesList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2816 return pUserProfilesList;
2820 _AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
2822 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2823 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. Addressbook Id(%d).", GetErrorMessage(E_INVALID_ARG), addressbookId);
2828 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
2829 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2831 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &mode);
2832 SysTryReturn(NID_SCL, mode == 0, null, E_OBJ_NOT_FOUND, "[%s] The addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
2834 __Filter<__ContactsUserProfile> filter;
2836 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, addressbookId);
2838 __Query<__ContactsUserProfile> query;
2840 query.SetFilter(filter);
2842 unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
2843 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2844 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
2845 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
2847 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
2848 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
2854 _AddressbookManagerImpl::CopyContactRecordHandle(contacts_record_h srcHandle)
2858 int ret = CONTACTS_ERROR_NONE;
2860 unsigned int count = 0;
2861 char* pCharValue = null;
2863 bool boolValue = false;
2865 contacts_record_h contactHandle = null;
2866 contacts_record_h sourceRecordHandle = null;
2867 contacts_record_h destRecordHandle = null;
2869 ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
2870 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2873 contacts_record_get_bool(sourceRecordHandle, _contacts_contact.is_favorite, &boolValue);
2874 contacts_record_set_bool(destRecordHandle, _contacts_contact.is_favorite, boolValue);
2877 contacts_record_get_str_p(sourceRecordHandle, _contacts_contact.uid, &pCharValue);
2878 contacts_record_set_str(destRecordHandle, _contacts_contact.uid, pCharValue);
2880 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2882 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2883 contacts_record_get_child_record_count(srcHandle, _contacts_contact.name, &count);
2886 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.name, 0, &sourceRecordHandle);
2888 ret = contacts_record_create(_contacts_name._uri, &destRecordHandle);
2889 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2891 __ContactsRecordHandle nameHandle(destRecordHandle);
2894 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.first, &pCharValue);
2895 contacts_record_set_str(destRecordHandle, _contacts_name.first, pCharValue);
2898 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.last, &pCharValue);
2899 contacts_record_set_str(destRecordHandle, _contacts_name.last, pCharValue);
2902 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.addition, &pCharValue);
2903 contacts_record_set_str(destRecordHandle, _contacts_name.addition, pCharValue);
2906 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.suffix, &pCharValue);
2907 contacts_record_set_str(destRecordHandle, _contacts_name.suffix, pCharValue);
2910 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.prefix, &pCharValue);
2911 contacts_record_set_str(destRecordHandle, _contacts_name.prefix, pCharValue);
2913 // 6. phonetic_first
2914 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_first, &pCharValue);
2915 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_first, pCharValue);
2918 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_last, &pCharValue);
2919 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_last, pCharValue);
2921 // 8. phonetic_middle
2922 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
2923 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_middle, pCharValue);
2925 contacts_record_add_child_record(contactHandle, _contacts_contact.name, destRecordHandle);
2927 nameHandle.Release();
2930 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2932 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2933 contacts_record_get_child_record_count(srcHandle, _contacts_contact.image, &count);
2934 for (i = 0; i < count; i++)
2936 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.image, i, &sourceRecordHandle);
2938 ret = contacts_record_create(_contacts_image._uri, &destRecordHandle);
2939 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2941 __ContactsRecordHandle imageHandle(destRecordHandle);
2943 contacts_record_get_int(sourceRecordHandle, _contacts_image.type, &intValue);
2944 contacts_record_set_int(destRecordHandle, _contacts_image.type, intValue);
2946 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.label, &pCharValue);
2947 contacts_record_set_str(destRecordHandle, _contacts_image.label, pCharValue);
2949 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.path, &pCharValue);
2950 contacts_record_set_str(destRecordHandle, _contacts_image.path, pCharValue);
2952 contacts_record_add_child_record(contactHandle, _contacts_contact.image, destRecordHandle);
2954 imageHandle.Release();
2957 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2959 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2960 contacts_record_get_child_record_count(srcHandle, _contacts_contact.company, &count);
2961 for (i = 0; i < count; i++)
2963 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.company, i, &sourceRecordHandle);
2965 ret = contacts_record_create(_contacts_company._uri, &destRecordHandle);
2966 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2968 __ContactsRecordHandle companyHandle(destRecordHandle);
2970 contacts_record_get_int(sourceRecordHandle, _contacts_company.type, &intValue);
2971 contacts_record_set_int(destRecordHandle, _contacts_company.type, intValue);
2973 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.name, &pCharValue);
2974 contacts_record_set_str(destRecordHandle, _contacts_company.name, pCharValue);
2976 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.department, &pCharValue);
2977 contacts_record_set_str(destRecordHandle, _contacts_company.department, pCharValue);
2979 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.job_title, &pCharValue);
2980 contacts_record_set_str(destRecordHandle, _contacts_company.job_title, pCharValue);
2982 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.assistant_name, &pCharValue);
2983 contacts_record_set_str(destRecordHandle, _contacts_company.assistant_name, pCharValue);
2985 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.role, &pCharValue);
2986 contacts_record_set_str(destRecordHandle, _contacts_company.role, pCharValue);
2988 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.logo, &pCharValue);
2989 contacts_record_set_str(destRecordHandle, _contacts_company.logo, pCharValue);
2991 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.location, &pCharValue);
2992 contacts_record_set_str(destRecordHandle, _contacts_company.location, pCharValue);
2994 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.description, &pCharValue);
2995 contacts_record_set_str(destRecordHandle, _contacts_company.description, pCharValue);
2997 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.phonetic_name, &pCharValue);
2998 contacts_record_set_str(destRecordHandle, _contacts_company.phonetic_name, pCharValue);
3000 contacts_record_add_child_record(contactHandle, _contacts_contact.company, destRecordHandle);
3002 companyHandle.Release();
3005 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3007 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3008 contacts_record_get_child_record_count(srcHandle, _contacts_contact.note, &count);
3009 for (i = 0; i < count; i++)
3011 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.note, i, &sourceRecordHandle);
3013 ret = contacts_record_create(_contacts_note._uri, &destRecordHandle);
3014 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3016 __ContactsRecordHandle noteHandle(destRecordHandle);
3018 contacts_record_get_str_p(sourceRecordHandle, _contacts_note.note, &pCharValue);
3019 contacts_record_set_str(destRecordHandle, _contacts_note.note, pCharValue);
3021 contacts_record_add_child_record(contactHandle, _contacts_contact.note, destRecordHandle);
3023 noteHandle.Release();
3026 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3028 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3029 contacts_record_get_child_record_count(srcHandle, _contacts_contact.number, &count);
3030 for (i = 0; i < count; i++)
3032 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.number, i, &sourceRecordHandle);
3034 ret = contacts_record_create(_contacts_number._uri, &destRecordHandle);
3035 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3037 __ContactsRecordHandle numberHandle(destRecordHandle);
3039 contacts_record_get_int(sourceRecordHandle, _contacts_number.type, &intValue);
3040 contacts_record_set_int(destRecordHandle, _contacts_number.type, intValue);
3042 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.label, &pCharValue);
3043 contacts_record_set_str(destRecordHandle, _contacts_number.label, pCharValue);
3045 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.number, &pCharValue);
3046 contacts_record_set_str(destRecordHandle, _contacts_number.number, pCharValue);
3048 contacts_record_add_child_record(contactHandle, _contacts_contact.number, destRecordHandle);
3050 numberHandle.Release();
3053 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3055 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3056 contacts_record_get_child_record_count(srcHandle, _contacts_contact.email, &count);
3057 for (i = 0; i < count; i++)
3059 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.email, i, &sourceRecordHandle);
3061 ret = contacts_record_create(_contacts_email._uri, &destRecordHandle);
3062 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3064 __ContactsRecordHandle emailHandle(destRecordHandle);
3066 contacts_record_get_int(sourceRecordHandle, _contacts_email.type, &intValue);
3067 contacts_record_set_int(destRecordHandle, _contacts_email.type, intValue);
3069 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.label, &pCharValue);
3070 contacts_record_set_str(destRecordHandle, _contacts_email.label, pCharValue);
3072 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.email, &pCharValue);
3073 contacts_record_set_str(destRecordHandle, _contacts_email.email, pCharValue);
3075 contacts_record_add_child_record(contactHandle, _contacts_contact.email, destRecordHandle);
3077 emailHandle.Release();
3081 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3083 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3084 contacts_record_get_child_record_count(srcHandle, _contacts_contact.event, &count);
3085 for (i = 0; i < count; i++)
3087 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.event, i, &sourceRecordHandle);
3089 ret = contacts_record_create(_contacts_event._uri, &destRecordHandle);
3090 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3092 __ContactsRecordHandle eventHandle(destRecordHandle);
3094 contacts_record_get_int(sourceRecordHandle, _contacts_event.type, &intValue);
3095 contacts_record_set_int(destRecordHandle, _contacts_event.type, intValue);
3097 contacts_record_get_str_p(sourceRecordHandle, _contacts_event.label, &pCharValue);
3098 contacts_record_set_str(destRecordHandle, _contacts_event.label, pCharValue);
3100 contacts_record_get_int(sourceRecordHandle, _contacts_event.date, &intValue);
3101 contacts_record_set_int(destRecordHandle, _contacts_event.date, intValue);
3103 contacts_record_add_child_record(contactHandle, _contacts_contact.event, destRecordHandle);
3105 eventHandle.Release();
3108 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3110 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3111 contacts_record_get_child_record_count(srcHandle, _contacts_contact.messenger, &count);
3112 for (i = 0; i < count; i++)
3114 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.messenger, i, &sourceRecordHandle);
3116 ret = contacts_record_create(_contacts_messenger._uri, &destRecordHandle);
3117 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3119 __ContactsRecordHandle imAddressHandle(destRecordHandle);
3121 contacts_record_get_int(sourceRecordHandle, _contacts_messenger.type, &intValue);
3122 contacts_record_set_int(destRecordHandle, _contacts_messenger.type, intValue);
3124 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.label, &pCharValue);
3125 contacts_record_set_str(destRecordHandle, _contacts_messenger.label, pCharValue);
3127 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.im_id, &pCharValue);
3128 contacts_record_set_str(destRecordHandle, _contacts_messenger.im_id, pCharValue);
3130 contacts_record_add_child_record(contactHandle, _contacts_contact.messenger, destRecordHandle);
3132 imAddressHandle.Release();
3135 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3137 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3138 contacts_record_get_child_record_count(srcHandle, _contacts_contact.address, &count);
3139 for (i = 0; i < count; i++)
3141 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.address, i, &sourceRecordHandle);
3143 ret = contacts_record_create(_contacts_address._uri, &destRecordHandle);
3144 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3146 __ContactsRecordHandle addressHandle(destRecordHandle);
3148 contacts_record_get_int(sourceRecordHandle, _contacts_address.type, &intValue);
3149 contacts_record_set_int(destRecordHandle, _contacts_address.type, intValue);
3151 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.label, &pCharValue);
3152 contacts_record_set_str(destRecordHandle, _contacts_address.label, pCharValue);
3154 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postbox, &pCharValue);
3155 contacts_record_set_str(destRecordHandle, _contacts_address.postbox, pCharValue);
3157 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.extended, &pCharValue);
3158 contacts_record_set_str(destRecordHandle, _contacts_address.extended, pCharValue);
3160 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.street, &pCharValue);
3161 contacts_record_set_str(destRecordHandle, _contacts_address.street, pCharValue);
3163 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.locality, &pCharValue);
3164 contacts_record_set_str(destRecordHandle, _contacts_address.locality, pCharValue);
3166 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.region, &pCharValue);
3167 contacts_record_set_str(destRecordHandle, _contacts_address.region, pCharValue);
3169 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postal_code, &pCharValue);
3170 contacts_record_set_str(destRecordHandle, _contacts_address.postal_code, pCharValue);
3172 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.country, &pCharValue);
3173 contacts_record_set_str(destRecordHandle, _contacts_address.country, pCharValue);
3175 contacts_record_add_child_record(contactHandle, _contacts_contact.address, destRecordHandle);
3177 addressHandle.Release();
3180 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3182 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3183 contacts_record_get_child_record_count(srcHandle, _contacts_contact.url, &count);
3184 for (i = 0; i < count; i++)
3186 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.url, i, &sourceRecordHandle);
3188 ret = contacts_record_create(_contacts_url._uri, &destRecordHandle);
3189 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3191 __ContactsRecordHandle urlHandle(destRecordHandle);
3193 contacts_record_get_int(sourceRecordHandle, _contacts_url.type, &intValue);
3194 contacts_record_set_int(destRecordHandle, _contacts_url.type, intValue);
3196 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.label, &pCharValue);
3197 contacts_record_set_str(destRecordHandle, _contacts_url.label, pCharValue);
3199 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.url, &pCharValue);
3200 contacts_record_set_str(destRecordHandle, _contacts_url.url, pCharValue);
3202 contacts_record_add_child_record(contactHandle, _contacts_contact.url, destRecordHandle);
3204 urlHandle.Release();
3207 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3209 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3210 contacts_record_get_child_record_count(srcHandle, _contacts_contact.nickname, &count);
3211 for (i = 0; i < count; i++)
3213 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.nickname, i, &sourceRecordHandle);
3215 ret = contacts_record_create(_contacts_nickname._uri, &destRecordHandle);
3216 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3218 __ContactsRecordHandle nicknameHandle(destRecordHandle);
3220 contacts_record_get_str_p(sourceRecordHandle, _contacts_nickname.name, &pCharValue);
3221 contacts_record_set_str(destRecordHandle, _contacts_nickname.name, pCharValue);
3223 contacts_record_add_child_record(contactHandle, _contacts_contact.nickname, destRecordHandle);
3225 nicknameHandle.Release();
3228 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3230 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3231 contacts_record_get_child_record_count(srcHandle, _contacts_contact.relationship, &count);
3232 for (i = 0; i < count; i++)
3234 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.relationship, i, &sourceRecordHandle);
3236 ret = contacts_record_create(_contacts_relationship._uri, &destRecordHandle);
3237 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3239 __ContactsRecordHandle relationshipHandle(destRecordHandle);
3241 contacts_record_get_str_p(sourceRecordHandle, _contacts_relationship.name, &pCharValue);
3242 contacts_record_set_str(destRecordHandle, _contacts_relationship.name, pCharValue);
3244 contacts_record_add_child_record(contactHandle, _contacts_contact.relationship, destRecordHandle);
3246 relationshipHandle.Release();
3249 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3251 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3252 contacts_record_get_child_record_count(srcHandle, _contacts_contact.profile, &count);
3253 for (i = 0; i < count; i++)
3255 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.profile, i, &sourceRecordHandle);
3257 ret = contacts_record_create(_contacts_profile._uri, &destRecordHandle);
3258 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3260 __ContactsRecordHandle profileHandle(destRecordHandle);
3262 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.text, &pCharValue);
3263 contacts_record_set_str(destRecordHandle, _contacts_profile.text, pCharValue);
3265 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uid, &pCharValue);
3266 contacts_record_set_str(destRecordHandle, _contacts_profile.uid, pCharValue);
3268 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.app_id, &pCharValue);
3269 contacts_record_set_str(destRecordHandle, _contacts_profile.app_id, pCharValue);
3271 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.service_operation, &pCharValue);
3272 contacts_record_set_str(destRecordHandle, _contacts_profile.service_operation, pCharValue);
3274 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uri, &pCharValue);
3275 contacts_record_set_str(destRecordHandle, _contacts_profile.uri, pCharValue);
3277 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.category, &pCharValue);
3278 contacts_record_set_str(destRecordHandle, _contacts_profile.category, pCharValue);
3280 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.mime, &pCharValue);
3281 contacts_record_set_str(destRecordHandle, _contacts_profile.mime, pCharValue);
3283 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.extra_data, &pCharValue);
3284 contacts_record_set_str(destRecordHandle, _contacts_profile.extra_data, pCharValue);
3286 contacts_record_add_child_record(contactHandle, _contacts_contact.profile, destRecordHandle);
3288 profileHandle.Release();
3291 return contactHandle;
3294 _AddressbookManagerImpl*
3295 _AddressbookManagerImpl::GetInstance(AddressbookManager& addressbookManager)
3297 return addressbookManager.__pAddressbookManagerImpl;
3300 const _AddressbookManagerImpl*
3301 _AddressbookManagerImpl::GetInstance(const AddressbookManager& addressbookManager)
3303 return addressbookManager.__pAddressbookManagerImpl;