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 int ret = contacts_group_add_contact(categoryId, contactId);
666 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
667 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));
668 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
674 _AddressbookManagerImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
676 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);
677 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);
678 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
680 int ret = contacts_group_remove_contact(categoryId, contactId);
681 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
682 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));
683 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
689 _AddressbookManagerImpl::GetAllCategoriesN(void) const
691 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
695 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
697 __Query<__ContactsGroup> query;
699 query.SetSort(_contacts_group.name, true);
701 if (pRwAbFilter->Get() != null)
703 query.SetFilter(*pRwAbFilter);
706 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
707 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
713 _AddressbookManagerImpl::GetCategoriesByContactN(RecordId contactId) const
715 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
716 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));
719 IList* pCategories = null;
721 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
723 __Filter<__ContactsContactGroupRel> relFilter;
724 relFilter.Construct();
725 relFilter.AddInt(_contacts_contact_grouprel.contact_id, CONTACTS_MATCH_EQUAL, contactId);
727 if (pRwAbFilter->Get() != null)
729 __Filter<__ContactsContactGroupRel> mainFilter;
730 mainFilter.Construct();
731 mainFilter.AddFilter(*pRwAbFilter);
732 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
733 mainFilter.AddFilter(relFilter);
735 __Query<__ContactsContactGroupRel> query;
737 query.SetFilter(mainFilter);
739 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
740 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
744 __Query<__ContactsContactGroupRel> query;
746 query.SetFilter(relFilter);
748 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
749 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
756 _AddressbookManagerImpl::GetCategoriesByPersonN(PersonId personId) const
758 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
762 IList* pCategories = null;
764 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
766 __Filter<__ContactsContactGroupRel> relFilter;
767 relFilter.Construct();
768 relFilter.AddInt(_contacts_contact_grouprel.person_id, CONTACTS_MATCH_EQUAL, personId);
769 relFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
770 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_GREATER_THAN, 0);
772 unsigned int propertyIds[] =
774 _contacts_contact_grouprel.group_id,
777 if (pRwAbFilter->Get() != null)
780 __Filter<__ContactsContactGroupRel> mainFilter;
781 mainFilter.Construct();
782 mainFilter.AddFilter(*pRwAbFilter);
783 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
784 mainFilter.AddFilter(relFilter);
787 __Query<__ContactsContactGroupRel> query;
789 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
790 query.SetFilter(mainFilter);
791 query.SetSort(_contacts_contact_grouprel.group_name, true);
792 query.SetDistinct(true);
794 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
795 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
799 __Query<__ContactsContactGroupRel> query;
801 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
802 query.SetFilter(relFilter);
803 query.SetSort(_contacts_contact_grouprel.group_name, true);
804 query.SetDistinct(true);
806 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
807 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
815 _AddressbookManagerImpl::GetAllContactsN(void) const
817 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
821 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
823 __Query<__ContactsContact> query;
825 query.SetSort(_contacts_contact.display_name, true);
827 if (pRwAbFilter->Get() != null)
829 query.SetFilter(*pRwAbFilter);
832 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
833 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
839 _AddressbookManagerImpl::GetContactsByCategoryN(RecordId categoryId) const
841 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));
842 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
846 IList* pContacts = null;
848 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
850 __Filter<__ContactsContactGroupRel> relFilter;
851 relFilter.Construct();
853 if (categoryId != INVALID_RECORD_ID)
855 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
859 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
862 if (pRwAbFilter->Get() != null)
864 __Filter<__ContactsContactGroupRel> mainFilter;
865 mainFilter.Construct();
867 mainFilter.AddFilter(*pRwAbFilter);
868 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
869 mainFilter.AddFilter(relFilter);
871 __Query<__ContactsContactGroupRel> query;
873 query.SetFilter(mainFilter);
875 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
876 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
880 __Query<__ContactsContactGroupRel> query;
882 query.SetFilter(relFilter);
884 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
885 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
892 _AddressbookManagerImpl::GetContactsByPersonN(PersonId personId) const
894 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
898 IList* pContacts = null;
900 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
902 __Filter<__ContactsContact> contactFilter;
903 contactFilter.Construct();
904 contactFilter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
906 if (pRwAbFilter->Get() != null)
908 __Filter<__ContactsContact> mainFilter;
909 mainFilter.Construct();
911 mainFilter.AddFilter(*pRwAbFilter);
912 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
913 mainFilter.AddFilter(contactFilter);
915 __Query<__ContactsContact> query;
917 query.SetFilter(mainFilter);
918 query.SetSort(_contacts_contact.display_name, true);
920 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
921 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
925 __Query<__ContactsContact> query;
927 query.SetFilter(contactFilter);
928 query.SetSort(_contacts_contact.display_name, true);
930 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
931 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
938 _AddressbookManagerImpl::SearchContactsByEmailN(const String& email) const
940 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));
941 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
945 IList* pContacts = null;
947 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
949 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
950 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
952 __Filter<__ContactsContactEmail> emailFilter;
953 emailFilter.Construct();
954 emailFilter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
956 if (pRwAbFilter->Get() != null)
958 __Filter<__ContactsContactEmail> mainFilter;
959 mainFilter.Construct();
961 mainFilter.AddFilter(*pRwAbFilter);
962 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
963 mainFilter.AddFilter(emailFilter);
965 __Query<__ContactsContactEmail> query;
967 query.SetFilter(mainFilter);
968 query.SetSort(_contacts_contact_email.display_name, true);
970 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
971 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
975 __Query<__ContactsContactEmail> query;
977 query.SetFilter(emailFilter);
978 query.SetSort(_contacts_contact_email.display_name, true);
980 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
981 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
989 _AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
991 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
995 IList* pContacts = null;
997 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
999 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));
1001 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
1002 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1004 __Filter<__ContactsContact> nameFilter;
1005 nameFilter.Construct();
1006 nameFilter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
1008 if (pRwAbFilter->Get() != null)
1010 __Filter<__ContactsContact> mainFilter;
1011 mainFilter.Construct();
1013 mainFilter.AddFilter(*pRwAbFilter);
1014 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1015 mainFilter.AddFilter(nameFilter);
1017 __Query<__ContactsContact> query;
1019 query.SetFilter(mainFilter);
1020 query.SetSort(_contacts_contact.display_name, true);
1022 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
1023 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1027 __Query<__ContactsContact> query;
1029 query.SetFilter(nameFilter);
1030 query.SetSort(_contacts_contact.display_name, true);
1032 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
1033 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1040 _AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
1042 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1046 IList* pContacts = null;
1048 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));
1050 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
1052 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
1053 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1055 __Filter<__ContactsContactNumber> numberFilter;
1056 numberFilter.Construct();
1057 numberFilter.AddString(_contacts_contact_number.normalized_number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
1058 numberFilter.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
1059 numberFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
1061 if (pRwAbFilter->Get() != null)
1063 __Filter<__ContactsContactNumber> mainFilter;
1064 mainFilter.Construct();
1066 mainFilter.AddFilter(*pRwAbFilter);
1067 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1068 mainFilter.AddFilter(numberFilter);
1070 __Query<__ContactsContactNumber> query;
1072 query.SetFilter(mainFilter);
1073 query.SetDistinct(true);
1074 query.SetSort(_contacts_contact_number.display_name, true);
1076 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
1077 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1081 __Query<__ContactsContactNumber> query;
1083 query.SetFilter(numberFilter);
1084 query.SetDistinct(true);
1085 query.SetSort(_contacts_contact_number.display_name, true);
1087 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
1088 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1096 _AddressbookManagerImpl::GetCategoryCount(void) const
1098 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1102 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1104 int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(pRwAbFilter->Get());
1105 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1111 _AddressbookManagerImpl::GetContactCount(void) const
1113 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1117 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1119 int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(pRwAbFilter->Get());
1120 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1126 _AddressbookManagerImpl::GetContactN(RecordId contactId) const
1128 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1129 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
1133 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId));
1134 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1137 contacts_record_get_int(pContactRecord.get(), _contacts_contact.address_book_id, &intValue);
1139 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
1140 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1142 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
1143 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Contact does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
1145 contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue);
1146 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1148 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
1149 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1151 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
1152 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
1154 return pContact.release();
1158 _AddressbookManagerImpl::GetPersonN(PersonId personId) const
1160 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1161 SysTryReturn(NID_SCL, personId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1165 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1168 contacts_record_get_int(pPersonRecord.get(), _contacts_person.id, &intValue);
1169 SysTryReturn(NID_SCL, intValue == personId, null, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1171 Person* pPerson = __ContactsPerson::ConvertHandleTo<Person>(pPersonRecord.get());
1172 SysTryReturn(NID_SCL, pPerson != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1178 _AddressbookManagerImpl::GetCategoryN(RecordId categoryId) const
1180 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. categoryId = %d.", categoryId);
1181 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1185 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
1186 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1190 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
1191 SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1193 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.address_book_id, &intValue);
1195 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
1196 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1198 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
1199 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Category does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
1201 unique_ptr<Category> pCategory(new (std::nothrow) Category());
1202 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1204 __Filter<__ContactsGroupRelation> filter;
1206 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1208 __Query<__ContactsGroupRelation> query;
1210 query.SetFilter(filter);
1212 int count = _AddressbookUtil::GetCountWithQuery(query);
1213 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1215 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
1216 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1217 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1219 return pCategory.release();
1223 _AddressbookManagerImpl::GetLatestVersion(void) const
1225 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1227 int latestVersion = -1;
1231 int ret = contacts_db_get_current_version(&latestVersion);
1232 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1234 return latestVersion;
1238 _AddressbookManagerImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1240 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);
1241 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1245 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1247 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1248 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1250 return pChangedContacts;
1254 _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1256 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);
1257 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1261 int latestVersion1 = 0;
1262 int latestVersion2 = 0;
1264 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1266 unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion1, pRwAbIdList.get()));
1267 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1269 unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion2, pRwAbIdList.get()));
1270 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1272 unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1273 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1275 result r = pChangeList->AddItems(*pChangedGroups);
1276 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1278 r = pChangeList->AddItems(*pChangedRelations);
1279 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1281 pChangedGroups->RemoveAll(false);
1282 pChangedRelations->RemoveAll(false);
1284 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1286 return pChangeList.release();
1290 _AddressbookManagerImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1292 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);
1293 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1297 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1299 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1300 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1302 return pChangedRelations;
1306 _AddressbookManagerImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1308 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);
1309 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1313 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1315 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1316 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1318 return pChangedRelations;
1322 _AddressbookManagerImpl::OnContactChanged(void)
1324 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1329 IList* pChangedContactList = GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact);
1330 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1332 if (pChangedContactList->GetCount() > 0)
1334 if (__pIAddressbookChangeEventListener != null)
1336 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1340 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1344 pChangedContactList->RemoveAll(true);
1345 delete pChangedContactList;
1349 _AddressbookManagerImpl::OnCategoryChanged(void)
1351 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1356 IList* pChangedCategoryList = GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup);
1357 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1359 if (pChangedCategoryList->GetCount() > 0)
1361 if (__pIAddressbookChangeEventListener != null)
1363 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1367 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1371 pChangedCategoryList->RemoveAll(true);
1372 delete pChangedCategoryList;
1376 _AddressbookManagerImpl::OnRelationChanged(void)
1378 if (__pIAddressbookEventListener == null)
1383 IList* pChangedCategoryList = GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation);
1384 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1386 if (pChangedCategoryList->GetCount() > 0)
1388 if (__pIAddressbookEventListener != null)
1390 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1394 pChangedCategoryList->RemoveAll(true);
1395 delete pChangedCategoryList;
1399 _AddressbookManagerImpl::RemovePerson(PersonId personId)
1401 SysTryReturnResult(NID_SCL, personId > 0, E_INVALID_ARG, "[%s] Invalid argument is used. ", GetErrorMessage(E_INVALID_ARG));
1402 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1404 result r = _AddressbookUtil::DeleteContactRecord(_contacts_person._uri, personId);
1405 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1411 _AddressbookManagerImpl::GetAllPersonsN(void) const
1413 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1417 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1419 unsigned int propertyIds[] =
1421 _contacts_person_grouprel.person_id,
1422 _contacts_person_grouprel.display_name,
1423 _contacts_person_grouprel.image_thumbnail_path,
1424 _contacts_person_grouprel.ringtone_path,
1425 _contacts_person_grouprel.is_favorite,
1426 _contacts_person_grouprel.has_phonenumber,
1427 _contacts_person_grouprel.has_email,
1428 _contacts_person_grouprel.addressbook_ids,
1432 __Query<__ContactsPersonGroupRel> query;
1434 query.SetSort(_contacts_person.display_name, true);
1435 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1436 query.SetDistinct(true);
1438 if (pRwAbFilter->Get() != null)
1440 query.SetFilter(*pRwAbFilter);
1443 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1444 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1450 _AddressbookManagerImpl::GetPersonsByCategoryN(RecordId categoryId) const
1452 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));
1453 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1457 IList* pPersons = null;
1459 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1461 __Filter<__ContactsPersonGroupRel> groupFilter;
1462 groupFilter.Construct();
1463 if (categoryId != INVALID_RECORD_ID)
1465 groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1469 groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
1472 unsigned int propertyIds[] =
1474 _contacts_person_grouprel.person_id,
1475 _contacts_person_grouprel.display_name,
1476 _contacts_person_grouprel.image_thumbnail_path,
1477 _contacts_person_grouprel.ringtone_path,
1478 _contacts_person_grouprel.is_favorite,
1479 _contacts_person_grouprel.has_phonenumber,
1480 _contacts_person_grouprel.has_email,
1481 _contacts_person_grouprel.addressbook_ids,
1484 if (pRwAbFilter->Get() != null)
1486 __Filter<__ContactsPersonGroupRel> mainFilter;
1487 mainFilter.Construct();
1489 mainFilter.AddFilter(*pRwAbFilter);
1490 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1491 mainFilter.AddFilter(groupFilter);
1493 __Query<__ContactsPersonGroupRel> query;
1495 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1496 query.SetFilter(mainFilter);
1497 query.SetSort(_contacts_person_grouprel.display_name, true);
1498 query.SetDistinct(true);
1500 pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1501 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1505 __Query<__ContactsPersonGroupRel> query;
1507 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1508 query.SetFilter(groupFilter);
1509 query.SetSort(_contacts_person_grouprel.display_name, true);
1510 query.SetDistinct(true);
1512 pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1513 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1521 _AddressbookManagerImpl::GetFavoritePersonsN() const
1523 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1527 __Filter<__ContactsPerson> filter;
1529 filter.AddBool(_contacts_person.is_favorite, true);
1531 __Query<__ContactsPerson> query;
1533 query.SetFilter(filter);
1534 query.SetSort(_contacts_person.display_name, true);
1536 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPerson, Person>(query);
1537 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1543 _AddressbookManagerImpl::SearchPersonsN(const Tizen::Base::String& keyword) const
1545 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1546 SysTryReturn(NID_SCL, !keyword.IsEmpty(), null, E_INVALID_ARG, "Invalid argument is used. keyword is empty string.", GetErrorMessage(E_INVALID_ARG));
1550 contacts_record_h currentRecord = null;
1551 unique_ptr<Person> pPerson(null);
1553 unique_ptr<ArrayList, AllElementsDeleter> pPersonList(new (std::nothrow) ArrayList());
1554 SysTryReturn(NID_SCL, pPersonList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1556 result r = pPersonList->Construct();
1557 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1559 unique_ptr<__SearchResult<__ContactsPerson> > pSearchResult(_AddressbookUtil::Search<__ContactsPerson>(keyword));
1560 SysTryReturn(NID_SCL, pSearchResult != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1562 while (pSearchResult->MoveNext() == E_SUCCESS)
1564 currentRecord = pSearchResult->GetCurrentRecord();
1565 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1567 pPerson.reset(__ContactsPerson::ConvertHandleTo<Person>(currentRecord));
1568 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1570 r = pPersonList->Add(*pPerson);
1571 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1576 return pPersonList.release();
1580 _AddressbookManagerImpl::SetPersonAsFavorite(PersonId personId, bool isFavorite)
1582 SysTryReturn(NID_SCL, personId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1583 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1585 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1586 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1588 bool boolValue = false;
1589 contacts_record_get_bool(pPersonRecord.get(), _contacts_person.is_favorite, &boolValue);
1591 if (boolValue != isFavorite)
1593 contacts_record_set_bool(pPersonRecord.get(), _contacts_person.is_favorite, isFavorite);
1595 result r = _AddressbookUtil::UpdateContactRecord(pPersonRecord.get());
1596 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1603 _AddressbookManagerImpl::MergePersons(PersonId sourcePersonId, PersonId targetPersonId)
1605 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);
1606 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1608 int ret = contacts_person_link_person(targetPersonId, sourcePersonId);
1609 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1610 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1616 _AddressbookManagerImpl::UnlinkContact(PersonId personId, RecordId contactId, PersonId& newPersonId)
1618 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);
1619 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1621 int ret = contacts_person_unlink_contact(personId, contactId, &newPersonId);
1622 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));
1623 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1629 _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount)
1631 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1635 IList* pList = null;
1636 bool ascending = false;
1637 unsigned int viewSortPropertyId = 0;
1639 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1640 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1642 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);
1644 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1646 viewSortPropertyId = _AddressbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1647 ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1652 case AB_FI_TYPE_ADDRESSBOOK:
1654 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
1656 __Filter<__ContactsAddressbook> abFilter;
1657 abFilter.Construct(filterHandle);
1659 if (pRwAbFilter->Get() != null)
1661 __Filter<__ContactsAddressbook> mainFilter;
1662 mainFilter.Construct();
1663 mainFilter.AddFilter(*pRwAbFilter);
1664 if (abFilter.Get() != null)
1666 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1667 mainFilter.AddFilter(abFilter);
1670 __Query<__ContactsAddressbook> query;
1672 query.SetFilter(mainFilter);
1674 if (viewSortPropertyId != 0)
1676 query.SetSort(viewSortPropertyId, ascending);
1679 pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
1683 __Query<__ContactsAddressbook> query;
1685 query.SetFilter(abFilter);
1687 if (viewSortPropertyId != 0)
1689 query.SetSort(viewSortPropertyId, ascending);
1692 pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
1697 case AB_FI_TYPE_PERSON:
1699 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1701 __Filter<__ContactsPersonGroupRel> personFilter;
1702 personFilter.Construct(filterHandle);
1704 unsigned int propertyIds[] =
1705 { _contacts_person_grouprel.person_id,
1706 _contacts_person_grouprel.addressbook_ids,
1707 _contacts_person_grouprel.is_favorite,
1708 _contacts_person_grouprel.has_phonenumber,
1709 _contacts_person_grouprel.has_email,
1710 _contacts_person_grouprel.image_thumbnail_path,
1711 _contacts_person_grouprel.ringtone_path,
1712 _contacts_person_grouprel.display_name
1715 if (pRwAbFilter->Get() != null)
1717 __Filter<__ContactsPersonGroupRel> mainFilter;
1718 mainFilter.Construct();
1719 mainFilter.AddFilter(*pRwAbFilter);
1720 if (personFilter.Get() != null)
1722 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1723 mainFilter.AddFilter(personFilter);
1726 __Query<__ContactsPersonGroupRel> query;
1728 query.SetFilter(mainFilter);
1729 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1730 query.SetDistinct(true);
1732 if (viewSortPropertyId != 0)
1734 query.SetSort(viewSortPropertyId, ascending);
1737 pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
1741 __Query<__ContactsPersonGroupRel> query;
1743 query.SetFilter(personFilter);
1744 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1745 query.SetDistinct(true);
1747 if (viewSortPropertyId != 0)
1749 query.SetSort(viewSortPropertyId, ascending);
1752 pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
1756 case AB_FI_TYPE_CONTACT:
1758 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1760 __Filter<__ContactsContact> contactFilter;
1761 contactFilter.Construct(filterHandle);
1763 if (pRwAbFilter->Get() != null)
1765 __Filter<__ContactsContact> mainFilter;
1766 mainFilter.Construct();
1767 mainFilter.AddFilter(*pRwAbFilter);
1768 if (contactFilter.Get() != null)
1770 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1771 mainFilter.AddFilter(contactFilter);
1774 __Query<__ContactsContact> query;
1776 query.SetFilter(mainFilter);
1778 if (viewSortPropertyId != 0)
1780 query.SetSort(viewSortPropertyId, ascending);
1783 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
1787 __Query<__ContactsContact> query;
1789 query.SetFilter(contactFilter);
1791 if (viewSortPropertyId != 0)
1793 query.SetSort(viewSortPropertyId, ascending);
1796 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
1801 case AB_FI_TYPE_CATEGORY:
1803 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1805 __Filter<__ContactsGroup> groupFilter;
1806 groupFilter.Construct(filterHandle);
1808 if (pRwAbFilter->Get() != null)
1810 __Filter<__ContactsGroup> mainFilter;
1811 mainFilter.Construct();
1812 mainFilter.AddFilter(*pRwAbFilter);
1813 if (groupFilter.Get() != null)
1815 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1816 mainFilter.AddFilter(groupFilter);
1819 __Query<__ContactsGroup> query;
1821 query.SetFilter(mainFilter);
1823 if (viewSortPropertyId != 0)
1825 query.SetSort(viewSortPropertyId, ascending);
1828 pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
1832 __Query<__ContactsGroup> query;
1834 query.SetFilter(groupFilter);
1836 if (viewSortPropertyId != 0)
1838 query.SetSort(viewSortPropertyId, ascending);
1841 pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
1845 case AB_FI_TYPE_PHONE_CONTACT:
1847 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
1849 __Filter<__ContactsContactNumber> numberFilter;
1850 numberFilter.Construct(filterHandle);
1852 if (pRwAbFilter->Get() != null)
1854 __Filter<__ContactsContactNumber> mainFilter;
1855 mainFilter.Construct();
1856 mainFilter.AddFilter(*pRwAbFilter);
1857 if (numberFilter.Get() != null)
1859 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1860 mainFilter.AddFilter(numberFilter);
1863 __Query<__ContactsContactNumber> query;
1865 query.SetFilter(mainFilter);
1867 if (viewSortPropertyId != 0)
1869 query.SetSort(viewSortPropertyId, ascending);
1872 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
1876 __Query<__ContactsContactNumber> query;
1878 query.SetFilter(numberFilter);
1880 if (viewSortPropertyId != 0)
1882 query.SetSort(viewSortPropertyId, ascending);
1885 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
1889 case AB_FI_TYPE_EMAIL_CONTACT:
1891 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
1893 __Filter<__ContactsContactEmail> emailFilter;
1894 emailFilter.Construct(filterHandle);
1896 if (pRwAbFilter->Get() != null)
1898 __Filter<__ContactsContactEmail> mainFilter;
1899 mainFilter.Construct();
1900 mainFilter.AddFilter(*pRwAbFilter);
1901 if (emailFilter.Get() != null)
1903 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1904 mainFilter.AddFilter(emailFilter);
1907 __Query<__ContactsContactEmail> query;
1909 query.SetFilter(mainFilter);
1911 if (viewSortPropertyId != 0)
1913 query.SetSort(viewSortPropertyId, ascending);
1916 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
1920 __Query<__ContactsContactEmail> query;
1922 query.SetFilter(emailFilter);
1924 if (viewSortPropertyId != 0)
1926 query.SetSort(viewSortPropertyId, ascending);
1929 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
1934 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The filter type is invalid", GetErrorMessage(E_INVALID_ARG));
1943 _AddressbookManagerImpl::GetMatchedItemCount(const AddressbookFilter& filter)
1945 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1950 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1951 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1955 case AB_FI_TYPE_ADDRESSBOOK:
1957 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
1959 __Filter<__ContactsAddressbook> abFilter;
1960 abFilter.Construct(filterHandle);
1962 if (pRwAbFilter->Get() != null)
1964 __Filter<__ContactsAddressbook> mainFilter;
1965 mainFilter.Construct();
1966 mainFilter.AddFilter(*pRwAbFilter);
1967 if (abFilter.Get() != null)
1969 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1970 mainFilter.AddFilter(abFilter);
1973 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(mainFilter.Get());
1977 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(abFilter.Get());
1981 case AB_FI_TYPE_PERSON:
1983 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1985 __Filter<__ContactsPersonGroupRel> personFilter;
1986 personFilter.Construct(filterHandle);
1988 if (pRwAbFilter->Get() != null)
1990 __Filter<__ContactsPersonGroupRel> mainFilter;
1991 mainFilter.Construct();
1992 mainFilter.AddFilter(*pRwAbFilter);
1993 if (personFilter.Get() != null)
1995 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1996 mainFilter.AddFilter(personFilter);
1999 unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
2001 __Query<__ContactsPersonGroupRel> query;
2003 query.SetFilter(mainFilter);
2004 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
2005 query.SetDistinct(true);
2007 count = _AddressbookUtil::GetCountWithQuery(query);
2011 unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
2013 __Query<__ContactsPersonGroupRel> query;
2015 query.SetFilter(personFilter);
2016 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
2017 query.SetDistinct(true);
2019 count = _AddressbookUtil::GetCountWithQuery(query);
2025 case AB_FI_TYPE_CONTACT:
2027 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
2029 __Filter<__ContactsContact> contactFilter;
2030 contactFilter.Construct(filterHandle);
2032 if (pRwAbFilter->Get() != null)
2034 __Filter<__ContactsContact> mainFilter;
2035 mainFilter.Construct();
2036 mainFilter.AddFilter(*pRwAbFilter);
2037 if (contactFilter.Get() != null)
2039 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2040 mainFilter.AddFilter(contactFilter);
2043 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(mainFilter.Get());
2047 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(contactFilter.Get());
2051 case AB_FI_TYPE_CATEGORY:
2053 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
2055 __Filter<__ContactsGroup> groupFilter;
2056 groupFilter.Construct(filterHandle);
2058 if (pRwAbFilter->Get() != null)
2060 __Filter<__ContactsGroup> mainFilter;
2061 mainFilter.Construct();
2062 mainFilter.AddFilter(*pRwAbFilter);
2063 if (groupFilter.Get() != null)
2065 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2066 mainFilter.AddFilter(groupFilter);
2069 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(mainFilter.Get());
2073 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(groupFilter.Get());
2077 case AB_FI_TYPE_PHONE_CONTACT:
2079 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
2081 __Filter<__ContactsContactNumber> numberFilter;
2082 numberFilter.Construct(filterHandle);
2084 if (pRwAbFilter->Get() != null)
2086 __Filter<__ContactsContactNumber> mainFilter;
2087 mainFilter.Construct();
2088 mainFilter.AddFilter(*pRwAbFilter);
2089 if (numberFilter.Get() != null)
2091 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2092 mainFilter.AddFilter(numberFilter);
2095 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(mainFilter.Get());
2099 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(numberFilter.Get());
2103 case AB_FI_TYPE_EMAIL_CONTACT:
2105 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
2107 __Filter<__ContactsContactEmail> emailFilter;
2108 emailFilter.Construct(filterHandle);
2110 if (pRwAbFilter->Get() != null)
2112 __Filter<__ContactsContactEmail> mainFilter;
2113 mainFilter.Construct();
2114 mainFilter.AddFilter(*pRwAbFilter);
2115 if (emailFilter.Get() != null)
2117 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2118 mainFilter.AddFilter(emailFilter);
2121 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(mainFilter.Get());
2125 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(emailFilter.Get());
2130 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter is invalid", GetErrorMessage(GetLastResult()));
2139 _AddressbookManagerImpl::OnEachContact(contacts_record_h recordHandle, void* pUserData)
2141 IList* pList = static_cast<IList*>(pUserData);
2145 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
2146 SysTryReturn(NID_SCL, pContact != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2148 contacts_record_h newRecordHandle = null;
2150 contacts_record_clone(recordHandle, &newRecordHandle);
2151 SysTryReturn(NID_SCL, newRecordHandle != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2153 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecordHandle);
2155 result r = pList->Add(*pContact);
2156 SysTryReturn(NID_SCL, !IsFailed(r), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2164 _AddressbookManagerImpl::ParseContactsFromVcardN(const Tizen::Base::String& vcardPath)
2166 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2171 result r = file.Construct(vcardPath, "r");
2172 SysTryReturn(NID_SCL, r != E_INVALID_ARG, null, E_INVALID_ARG, "[%s] Invalid argument is used..", GetErrorMessage(E_INVALID_ARG));
2173 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));
2174 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));
2175 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2177 unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2179 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(vcardPath));
2181 int ret = contacts_vcard_parse_to_contact_foreach(pCharArray.get(), OnEachContact, pList.get());
2182 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2183 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2184 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2186 return pList.release();
2190 _AddressbookManagerImpl::ExportPersonToVcard(const Person& person, const Tizen::Base::String& vcardPath)
2192 bool exist = File::IsFileExist(vcardPath);
2193 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2194 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2195 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2198 result r = file.Construct(vcardPath, "w");
2199 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));
2200 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2201 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2203 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
2204 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2206 char* pVcardStream = null;
2207 int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2208 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));
2209 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2211 r = file.Write(pVcardStream, strlen(pVcardStream));
2213 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2214 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2220 _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::IList& personList, const Tizen::Base::String& vcardPath)
2222 bool exist = File::IsFileExist(vcardPath);
2223 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2224 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2225 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2227 int ret = CONTACTS_ERROR_NONE;
2228 char* pVcardStream = null;
2231 result r = file.Construct(vcardPath, "w");
2232 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));
2233 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2234 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2237 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
2239 unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
2240 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2242 while (pEnum->MoveNext() == E_SUCCESS)
2244 Person* pPerson = static_cast<Person*>(pEnum->GetCurrent());
2246 pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
2247 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2249 ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2250 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));
2251 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2253 r = file.Write(pVcardStream, strlen(pVcardStream));
2255 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2256 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2263 _AddressbookManagerImpl::ExportContactToVcard(const Contact& contact, const Tizen::Base::String& vcardPath)
2265 bool exist = File::IsFileExist(vcardPath);
2266 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2267 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2268 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2271 result r = file.Construct(vcardPath, "w");
2272 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));
2273 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2274 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2276 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
2278 char* pVcardStream = null;
2280 int ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2281 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));
2282 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2284 r = file.Write(pVcardStream, strlen(pVcardStream));
2286 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2287 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2293 _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IList& contactList, const Tizen::Base::String& vcardPath)
2295 bool exist = File::IsFileExist(vcardPath);
2296 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2297 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2298 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2300 int ret = CONTACTS_ERROR_NONE;
2301 char* pVcardStream = null;
2303 Contact* pContact = null;
2305 result r = file.Construct(vcardPath, "w");
2306 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));
2307 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2308 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2310 contacts_record_h recordHandle = null;
2312 unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
2313 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2315 while (pEnum->MoveNext() == E_SUCCESS)
2317 pContact = static_cast<Contact*>(pEnum->GetCurrent());
2319 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
2321 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2322 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));
2323 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2325 r = file.Write(pVcardStream, strlen(pVcardStream));
2327 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2328 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2335 _AddressbookManagerImpl::ExportContactToVcardStreamN(const Contact& contact)
2337 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2341 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
2343 char* pVcardStream = null;
2344 int ret = CONTACTS_ERROR_NONE;
2346 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2347 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2348 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2349 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2351 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2352 if (pByteBuffer == null)
2355 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2360 result r = pByteBuffer->Construct(strlen(pVcardStream));
2364 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2369 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2371 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2372 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2374 return pByteBuffer.release();
2378 _AddressbookManagerImpl::ExportContactsToVcardStreamN(const Tizen::Base::Collection::IList& contactList)
2380 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2384 char* pVcardStream = null;
2385 int ret = CONTACTS_ERROR_NONE;
2386 Contact* pContact = null;
2387 result r = E_SUCCESS;
2390 contacts_record_h recordHandle = null;
2392 unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
2393 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2395 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2396 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2398 r = pByteBuffer->Construct(capacity);
2399 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2401 if (contactList.GetCount() == 0)
2403 return pByteBuffer.release();
2406 while (pEnum->MoveNext() == E_SUCCESS)
2408 pContact = static_cast<Contact*>(pEnum->GetCurrent());
2410 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
2412 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2413 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2414 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2415 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2417 capacity += strlen(pVcardStream);
2418 r = pByteBuffer->ExpandCapacity(capacity);
2422 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2427 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2429 pVcardStream = null;
2430 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2433 return pByteBuffer.release();
2437 _AddressbookManagerImpl::ExportPersonToVcardStreamN(const Person& person)
2439 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2443 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
2444 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2445 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2447 char* pVcardStream = null;
2448 int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2449 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2450 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2451 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2453 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2454 if (pByteBuffer == null)
2457 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2462 result r = pByteBuffer->Construct(strlen(pVcardStream));
2466 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2471 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2473 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2475 return pByteBuffer.release();
2479 _AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collection::IList& personList)
2481 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2485 int ret = CONTACTS_ERROR_NONE;
2486 Person* pPerson = null;
2487 char* pVcardStream = null;
2491 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
2493 unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
2494 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2496 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2497 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2499 result r = pByteBuffer->Construct(capacity);
2500 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2502 if (personList.GetCount() == 0)
2504 return pByteBuffer.release();
2507 while (pEnum->MoveNext() == E_SUCCESS)
2509 pPerson = static_cast<Person*>(pEnum->GetCurrent());
2511 pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
2512 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2513 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2515 ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2516 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2517 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2518 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2520 capacity += strlen(pVcardStream);
2521 r = pByteBuffer->ExpandCapacity(capacity);
2525 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2530 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2532 pVcardStream = null;
2533 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2536 return pByteBuffer.release();
2540 _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardStream)
2542 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2546 contacts_list_h listHandle = null;
2547 result r = E_SUCCESS;
2549 int ret = contacts_vcard_parse_to_contacts(reinterpret_cast<char*>(const_cast<byte*>(vcardStream.GetPointer())), &listHandle);
2550 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2551 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2553 unsigned int count = 0;
2554 contacts_record_h recordHandle = null;
2555 contacts_list_get_count(listHandle, &count);
2557 unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2560 contacts_list_destroy(listHandle, true);
2561 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2566 r = pList->Construct(count);
2569 contacts_list_destroy(listHandle, true);
2570 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2575 for (unsigned int i = 0; i < count; i++)
2577 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
2578 if (pContact == null)
2580 contacts_list_destroy(listHandle, true);
2581 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2586 r = pList->Add(pContact.get());
2589 contacts_list_destroy(listHandle, true);
2590 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2598 unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2600 while (pEnum->MoveNext() == E_SUCCESS)
2602 Contact* pContact = static_cast <Contact*> (pEnum->GetCurrent());
2604 contacts_list_get_current_record_p(listHandle, &recordHandle);
2605 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(recordHandle);
2607 ret = contacts_list_next(listHandle);
2610 contacts_list_destroy(listHandle, false);
2612 return pList.release();
2616 _AddressbookManagerImpl::ExportUserProfileToVcardStreamN(const UserProfile& userProfile)
2618 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2622 char* pVcardStream = null;
2623 int ret = CONTACTS_ERROR_NONE;
2624 contacts_record_h recordHandle = null;
2626 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2628 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2629 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2630 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2631 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2633 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2634 if (pByteBuffer == null)
2637 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2641 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2643 result r = pByteBuffer->Construct(strlen(pVcardStream));
2647 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2652 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2654 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2655 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2657 return pByteBuffer.release();
2661 _AddressbookManagerImpl::ExportUserProfilesToVcardStreamN(const Tizen::Base::Collection::IList& userProfileList)
2663 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2667 char* pVcardStream = null;
2668 int ret = CONTACTS_ERROR_NONE;
2669 UserProfile* pProfile = null;
2670 result r = E_SUCCESS;
2673 unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2674 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2676 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2677 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2679 r = pByteBuffer->Construct(capacity);
2680 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2682 if (userProfileList.GetCount() == 0)
2684 return pByteBuffer.release();
2687 while (pEnum->MoveNext() == E_SUCCESS)
2689 contacts_record_h recordHandle = null;
2691 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2693 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2695 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2696 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2697 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2698 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2700 capacity += strlen(pVcardStream);
2701 r = pByteBuffer->ExpandCapacity(capacity);
2705 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2710 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2712 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2715 return pByteBuffer.release();
2719 _AddressbookManagerImpl::ExportUserProfileToVcard(const UserProfile& userProfile, const Tizen::Base::String& vcardPath)
2721 bool exist = File::IsFileExist(vcardPath);
2722 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2723 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2724 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2727 result r = file.Construct(vcardPath, "w");
2728 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));
2729 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2730 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2732 char* pVcardStream = null;
2733 contacts_record_h recordHandle = null;
2735 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2737 int ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2738 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));
2739 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2741 r = file.Write(pVcardStream, strlen(pVcardStream));
2743 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2744 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2750 _AddressbookManagerImpl::ExportUserProfilesToVcard(const Tizen::Base::Collection::IList& userProfileList, const Tizen::Base::String& vcardPath)
2752 bool exist = File::IsFileExist(vcardPath);
2753 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2754 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2755 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2757 int ret = CONTACTS_ERROR_NONE;
2758 char* pVcardStream = null;
2760 UserProfile* pProfile = null;
2762 result r = file.Construct(vcardPath, "w");
2763 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));
2764 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2765 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2767 unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2768 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2770 while (pEnum->MoveNext() == E_SUCCESS)
2772 contacts_record_h recordHandle = null;
2774 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2776 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2778 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2779 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));
2780 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2782 r = file.Write(pVcardStream, strlen(pVcardStream));
2784 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2785 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2792 _AddressbookManagerImpl::GetAllUserProfilesN(void) const
2794 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2798 unique_ptr< __Filter<__ContactsUserProfile> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsUserProfile>());
2799 SysTryReturn(NID_SCL, pRwAbFilter != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2801 __Query<__ContactsUserProfile> query;
2803 query.SetSort(_contacts_my_profile.display_name, true);
2805 if (pRwAbFilter->Get() != null)
2807 query.SetFilter(*pRwAbFilter);
2810 IList* pUserProfilesList = _AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query);
2811 SysTryReturn(NID_SCL, pUserProfilesList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2813 return pUserProfilesList;
2817 _AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
2819 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2820 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. Addressbook Id(%d).", GetErrorMessage(E_INVALID_ARG), addressbookId);
2825 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
2826 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2828 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &mode);
2829 SysTryReturn(NID_SCL, mode == 0, null, E_OBJ_NOT_FOUND, "[%s] The addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
2831 __Filter<__ContactsUserProfile> filter;
2833 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, addressbookId);
2835 __Query<__ContactsUserProfile> query;
2837 query.SetFilter(filter);
2839 unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
2840 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2841 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
2842 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
2844 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
2845 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
2851 _AddressbookManagerImpl::CopyContactRecordHandle(contacts_record_h srcHandle)
2855 int ret = CONTACTS_ERROR_NONE;
2857 unsigned int count = 0;
2858 char* pCharValue = null;
2860 bool boolValue = false;
2862 contacts_record_h contactHandle = null;
2863 contacts_record_h sourceRecordHandle = null;
2864 contacts_record_h destRecordHandle = null;
2866 ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
2867 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2870 contacts_record_get_bool(sourceRecordHandle, _contacts_contact.is_favorite, &boolValue);
2871 contacts_record_set_bool(destRecordHandle, _contacts_contact.is_favorite, boolValue);
2874 contacts_record_get_str_p(sourceRecordHandle, _contacts_contact.uid, &pCharValue);
2875 contacts_record_set_str(destRecordHandle, _contacts_contact.uid, pCharValue);
2877 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2879 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2880 contacts_record_get_child_record_count(srcHandle, _contacts_contact.name, &count);
2883 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.name, 0, &sourceRecordHandle);
2885 ret = contacts_record_create(_contacts_name._uri, &destRecordHandle);
2886 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2888 __ContactsRecordHandle nameHandle(destRecordHandle);
2891 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.first, &pCharValue);
2892 contacts_record_set_str(destRecordHandle, _contacts_name.first, pCharValue);
2895 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.last, &pCharValue);
2896 contacts_record_set_str(destRecordHandle, _contacts_name.last, pCharValue);
2899 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.addition, &pCharValue);
2900 contacts_record_set_str(destRecordHandle, _contacts_name.addition, pCharValue);
2903 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.suffix, &pCharValue);
2904 contacts_record_set_str(destRecordHandle, _contacts_name.suffix, pCharValue);
2907 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.prefix, &pCharValue);
2908 contacts_record_set_str(destRecordHandle, _contacts_name.prefix, pCharValue);
2910 // 6. phonetic_first
2911 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_first, &pCharValue);
2912 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_first, pCharValue);
2915 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_last, &pCharValue);
2916 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_last, pCharValue);
2918 // 8. phonetic_middle
2919 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
2920 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_middle, pCharValue);
2922 contacts_record_add_child_record(contactHandle, _contacts_contact.name, destRecordHandle);
2924 nameHandle.Release();
2927 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2929 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2930 contacts_record_get_child_record_count(srcHandle, _contacts_contact.image, &count);
2931 for (i = 0; i < count; i++)
2933 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.image, i, &sourceRecordHandle);
2935 ret = contacts_record_create(_contacts_image._uri, &destRecordHandle);
2936 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2938 __ContactsRecordHandle imageHandle(destRecordHandle);
2940 contacts_record_get_int(sourceRecordHandle, _contacts_image.type, &intValue);
2941 contacts_record_set_int(destRecordHandle, _contacts_image.type, intValue);
2943 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.label, &pCharValue);
2944 contacts_record_set_str(destRecordHandle, _contacts_image.label, pCharValue);
2946 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.path, &pCharValue);
2947 contacts_record_set_str(destRecordHandle, _contacts_image.path, pCharValue);
2949 contacts_record_add_child_record(contactHandle, _contacts_contact.image, destRecordHandle);
2951 imageHandle.Release();
2954 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2956 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2957 contacts_record_get_child_record_count(srcHandle, _contacts_contact.company, &count);
2958 for (i = 0; i < count; i++)
2960 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.company, i, &sourceRecordHandle);
2962 ret = contacts_record_create(_contacts_company._uri, &destRecordHandle);
2963 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2965 __ContactsRecordHandle companyHandle(destRecordHandle);
2967 contacts_record_get_int(sourceRecordHandle, _contacts_company.type, &intValue);
2968 contacts_record_set_int(destRecordHandle, _contacts_company.type, intValue);
2970 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.name, &pCharValue);
2971 contacts_record_set_str(destRecordHandle, _contacts_company.name, pCharValue);
2973 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.department, &pCharValue);
2974 contacts_record_set_str(destRecordHandle, _contacts_company.department, pCharValue);
2976 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.job_title, &pCharValue);
2977 contacts_record_set_str(destRecordHandle, _contacts_company.job_title, pCharValue);
2979 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.assistant_name, &pCharValue);
2980 contacts_record_set_str(destRecordHandle, _contacts_company.assistant_name, pCharValue);
2982 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.role, &pCharValue);
2983 contacts_record_set_str(destRecordHandle, _contacts_company.role, pCharValue);
2985 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.logo, &pCharValue);
2986 contacts_record_set_str(destRecordHandle, _contacts_company.logo, pCharValue);
2988 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.location, &pCharValue);
2989 contacts_record_set_str(destRecordHandle, _contacts_company.location, pCharValue);
2991 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.description, &pCharValue);
2992 contacts_record_set_str(destRecordHandle, _contacts_company.description, pCharValue);
2994 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.phonetic_name, &pCharValue);
2995 contacts_record_set_str(destRecordHandle, _contacts_company.phonetic_name, pCharValue);
2997 contacts_record_add_child_record(contactHandle, _contacts_contact.company, destRecordHandle);
2999 companyHandle.Release();
3002 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3004 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3005 contacts_record_get_child_record_count(srcHandle, _contacts_contact.note, &count);
3006 for (i = 0; i < count; i++)
3008 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.note, i, &sourceRecordHandle);
3010 ret = contacts_record_create(_contacts_note._uri, &destRecordHandle);
3011 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3013 __ContactsRecordHandle noteHandle(destRecordHandle);
3015 contacts_record_get_str_p(sourceRecordHandle, _contacts_note.note, &pCharValue);
3016 contacts_record_set_str(destRecordHandle, _contacts_note.note, pCharValue);
3018 contacts_record_add_child_record(contactHandle, _contacts_contact.note, destRecordHandle);
3020 noteHandle.Release();
3023 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3025 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3026 contacts_record_get_child_record_count(srcHandle, _contacts_contact.number, &count);
3027 for (i = 0; i < count; i++)
3029 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.number, i, &sourceRecordHandle);
3031 ret = contacts_record_create(_contacts_number._uri, &destRecordHandle);
3032 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3034 __ContactsRecordHandle numberHandle(destRecordHandle);
3036 contacts_record_get_int(sourceRecordHandle, _contacts_number.type, &intValue);
3037 contacts_record_set_int(destRecordHandle, _contacts_number.type, intValue);
3039 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.label, &pCharValue);
3040 contacts_record_set_str(destRecordHandle, _contacts_number.label, pCharValue);
3042 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.number, &pCharValue);
3043 contacts_record_set_str(destRecordHandle, _contacts_number.number, pCharValue);
3045 contacts_record_add_child_record(contactHandle, _contacts_contact.number, destRecordHandle);
3047 numberHandle.Release();
3050 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3052 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3053 contacts_record_get_child_record_count(srcHandle, _contacts_contact.email, &count);
3054 for (i = 0; i < count; i++)
3056 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.email, i, &sourceRecordHandle);
3058 ret = contacts_record_create(_contacts_email._uri, &destRecordHandle);
3059 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3061 __ContactsRecordHandle emailHandle(destRecordHandle);
3063 contacts_record_get_int(sourceRecordHandle, _contacts_email.type, &intValue);
3064 contacts_record_set_int(destRecordHandle, _contacts_email.type, intValue);
3066 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.label, &pCharValue);
3067 contacts_record_set_str(destRecordHandle, _contacts_email.label, pCharValue);
3069 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.email, &pCharValue);
3070 contacts_record_set_str(destRecordHandle, _contacts_email.email, pCharValue);
3072 contacts_record_add_child_record(contactHandle, _contacts_contact.email, destRecordHandle);
3074 emailHandle.Release();
3078 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3080 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3081 contacts_record_get_child_record_count(srcHandle, _contacts_contact.event, &count);
3082 for (i = 0; i < count; i++)
3084 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.event, i, &sourceRecordHandle);
3086 ret = contacts_record_create(_contacts_event._uri, &destRecordHandle);
3087 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3089 __ContactsRecordHandle eventHandle(destRecordHandle);
3091 contacts_record_get_int(sourceRecordHandle, _contacts_event.type, &intValue);
3092 contacts_record_set_int(destRecordHandle, _contacts_event.type, intValue);
3094 contacts_record_get_str_p(sourceRecordHandle, _contacts_event.label, &pCharValue);
3095 contacts_record_set_str(destRecordHandle, _contacts_event.label, pCharValue);
3097 contacts_record_get_int(sourceRecordHandle, _contacts_event.date, &intValue);
3098 contacts_record_set_int(destRecordHandle, _contacts_event.date, intValue);
3100 contacts_record_add_child_record(contactHandle, _contacts_contact.event, destRecordHandle);
3102 eventHandle.Release();
3105 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3107 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3108 contacts_record_get_child_record_count(srcHandle, _contacts_contact.messenger, &count);
3109 for (i = 0; i < count; i++)
3111 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.messenger, i, &sourceRecordHandle);
3113 ret = contacts_record_create(_contacts_messenger._uri, &destRecordHandle);
3114 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3116 __ContactsRecordHandle imAddressHandle(destRecordHandle);
3118 contacts_record_get_int(sourceRecordHandle, _contacts_messenger.type, &intValue);
3119 contacts_record_set_int(destRecordHandle, _contacts_messenger.type, intValue);
3121 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.label, &pCharValue);
3122 contacts_record_set_str(destRecordHandle, _contacts_messenger.label, pCharValue);
3124 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.im_id, &pCharValue);
3125 contacts_record_set_str(destRecordHandle, _contacts_messenger.im_id, pCharValue);
3127 contacts_record_add_child_record(contactHandle, _contacts_contact.messenger, destRecordHandle);
3129 imAddressHandle.Release();
3132 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3134 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3135 contacts_record_get_child_record_count(srcHandle, _contacts_contact.address, &count);
3136 for (i = 0; i < count; i++)
3138 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.address, i, &sourceRecordHandle);
3140 ret = contacts_record_create(_contacts_address._uri, &destRecordHandle);
3141 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3143 __ContactsRecordHandle addressHandle(destRecordHandle);
3145 contacts_record_get_int(sourceRecordHandle, _contacts_address.type, &intValue);
3146 contacts_record_set_int(destRecordHandle, _contacts_address.type, intValue);
3148 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.label, &pCharValue);
3149 contacts_record_set_str(destRecordHandle, _contacts_address.label, pCharValue);
3151 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postbox, &pCharValue);
3152 contacts_record_set_str(destRecordHandle, _contacts_address.postbox, pCharValue);
3154 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.extended, &pCharValue);
3155 contacts_record_set_str(destRecordHandle, _contacts_address.extended, pCharValue);
3157 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.street, &pCharValue);
3158 contacts_record_set_str(destRecordHandle, _contacts_address.street, pCharValue);
3160 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.locality, &pCharValue);
3161 contacts_record_set_str(destRecordHandle, _contacts_address.locality, pCharValue);
3163 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.region, &pCharValue);
3164 contacts_record_set_str(destRecordHandle, _contacts_address.region, pCharValue);
3166 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postal_code, &pCharValue);
3167 contacts_record_set_str(destRecordHandle, _contacts_address.postal_code, pCharValue);
3169 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.country, &pCharValue);
3170 contacts_record_set_str(destRecordHandle, _contacts_address.country, pCharValue);
3172 contacts_record_add_child_record(contactHandle, _contacts_contact.address, destRecordHandle);
3174 addressHandle.Release();
3177 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3179 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3180 contacts_record_get_child_record_count(srcHandle, _contacts_contact.url, &count);
3181 for (i = 0; i < count; i++)
3183 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.url, i, &sourceRecordHandle);
3185 ret = contacts_record_create(_contacts_url._uri, &destRecordHandle);
3186 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3188 __ContactsRecordHandle urlHandle(destRecordHandle);
3190 contacts_record_get_int(sourceRecordHandle, _contacts_url.type, &intValue);
3191 contacts_record_set_int(destRecordHandle, _contacts_url.type, intValue);
3193 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.label, &pCharValue);
3194 contacts_record_set_str(destRecordHandle, _contacts_url.label, pCharValue);
3196 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.url, &pCharValue);
3197 contacts_record_set_str(destRecordHandle, _contacts_url.url, pCharValue);
3199 contacts_record_add_child_record(contactHandle, _contacts_contact.url, destRecordHandle);
3201 urlHandle.Release();
3204 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3206 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3207 contacts_record_get_child_record_count(srcHandle, _contacts_contact.nickname, &count);
3208 for (i = 0; i < count; i++)
3210 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.nickname, i, &sourceRecordHandle);
3212 ret = contacts_record_create(_contacts_nickname._uri, &destRecordHandle);
3213 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3215 __ContactsRecordHandle nicknameHandle(destRecordHandle);
3217 contacts_record_get_str_p(sourceRecordHandle, _contacts_nickname.name, &pCharValue);
3218 contacts_record_set_str(destRecordHandle, _contacts_nickname.name, pCharValue);
3220 contacts_record_add_child_record(contactHandle, _contacts_contact.nickname, destRecordHandle);
3222 nicknameHandle.Release();
3225 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3227 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3228 contacts_record_get_child_record_count(srcHandle, _contacts_contact.relationship, &count);
3229 for (i = 0; i < count; i++)
3231 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.relationship, i, &sourceRecordHandle);
3233 ret = contacts_record_create(_contacts_relationship._uri, &destRecordHandle);
3234 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3236 __ContactsRecordHandle relationshipHandle(destRecordHandle);
3238 contacts_record_get_str_p(sourceRecordHandle, _contacts_relationship.name, &pCharValue);
3239 contacts_record_set_str(destRecordHandle, _contacts_relationship.name, pCharValue);
3241 contacts_record_add_child_record(contactHandle, _contacts_contact.relationship, destRecordHandle);
3243 relationshipHandle.Release();
3246 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3248 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
3249 contacts_record_get_child_record_count(srcHandle, _contacts_contact.profile, &count);
3250 for (i = 0; i < count; i++)
3252 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.profile, i, &sourceRecordHandle);
3254 ret = contacts_record_create(_contacts_profile._uri, &destRecordHandle);
3255 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3257 __ContactsRecordHandle profileHandle(destRecordHandle);
3259 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.text, &pCharValue);
3260 contacts_record_set_str(destRecordHandle, _contacts_profile.text, pCharValue);
3262 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uid, &pCharValue);
3263 contacts_record_set_str(destRecordHandle, _contacts_profile.uid, pCharValue);
3265 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.app_id, &pCharValue);
3266 contacts_record_set_str(destRecordHandle, _contacts_profile.app_id, pCharValue);
3268 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.service_operation, &pCharValue);
3269 contacts_record_set_str(destRecordHandle, _contacts_profile.service_operation, pCharValue);
3271 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uri, &pCharValue);
3272 contacts_record_set_str(destRecordHandle, _contacts_profile.uri, pCharValue);
3274 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.category, &pCharValue);
3275 contacts_record_set_str(destRecordHandle, _contacts_profile.category, pCharValue);
3277 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.mime, &pCharValue);
3278 contacts_record_set_str(destRecordHandle, _contacts_profile.mime, pCharValue);
3280 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.extra_data, &pCharValue);
3281 contacts_record_set_str(destRecordHandle, _contacts_profile.extra_data, pCharValue);
3283 contacts_record_add_child_record(contactHandle, _contacts_contact.profile, destRecordHandle);
3285 profileHandle.Release();
3288 return contactHandle;
3291 _AddressbookManagerImpl*
3292 _AddressbookManagerImpl::GetInstance(AddressbookManager& addressbookManager)
3294 return addressbookManager.__pAddressbookManagerImpl;
3297 const _AddressbookManagerImpl*
3298 _AddressbookManagerImpl::GetInstance(const AddressbookManager& addressbookManager)
3300 return addressbookManager.__pAddressbookManagerImpl;