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>
24 #include <FBaseColIListT.h>
25 #include <FBaseColArrayListT.h>
26 #include <FBaseColHashMapT.h>
27 #include <FBaseResult.h>
28 #include <FBaseLongLong.h>
29 #include <FBaseInteger.h>
31 #include <FSclAddressbook.h>
32 #include <FSclAddressbookManager.h>
33 #include <FSclIAddressbookChangeEventListener.h>
34 #include <FSclContact.h>
35 #include <FSclCategory.h>
36 #include <FSclUserProfile.h>
37 #include <FSclContactChangeInfo.h>
38 #include <FSclCategoryChangeInfo.h>
39 #include <FSclPerson.h>
40 #include <FSclPhoneNumberContact.h>
41 #include <FScl_PhoneNumberContactImpl.h>
42 #include <FSclEmailContact.h>
43 #include <FScl_EmailContactImpl.h>
44 #include <FSclAddressbookFilter.h>
45 #include <FSclIAddressbookEventListener.h>
46 #include <FSclIRecordEventListener.h>
47 #include <FBaseSysLog.h>
48 #include <FApp_AppInfo.h>
49 #include <FBase_StringConverter.h>
50 #include "FScl_AddressbookImpl.h"
51 #include "FScl_AddressbookFilterImpl.h"
52 #include "FScl_AddressbookManagerImpl.h"
53 #include "FScl_AddressbookUtil.h"
54 #include "FScl_RecordImpl.h"
55 #include "FScl_ContactImpl.h"
56 #include "FScl_CategoryImpl.h"
57 #include "FScl_PersonImpl.h"
58 #include "FScl_AddressbookUtil.h"
59 #include "FScl_ContactChangeInfoImpl.h"
60 #include "FScl_CategoryChangeInfoImpl.h"
61 #include "FScl_ContactDbMonitor.h"
62 #include "FScl_ContactDbConnector.h"
63 #include "FScl_UserProfileImpl.h"
66 using namespace Tizen::App;
67 using namespace Tizen::Base;
68 using namespace Tizen::Base::Collection;
69 using namespace Tizen::Io;
70 using namespace Tizen::Graphics;
72 namespace Tizen { namespace Social
75 _AddressbookManagerImpl::_AddressbookManagerImpl(void)
76 : __pIAddressbookEventListener(null)
77 , __pIAddressbookChangeEventListener(null)
78 , __dbVersionForContact(0)
79 , __dbVersionForGroup(0)
80 , __dbVersionForRelation(0)
85 _AddressbookManagerImpl::~_AddressbookManagerImpl(void)
87 if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null)
89 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
90 if (pContactDbMonitor != null)
92 pContactDbMonitor->RemoveListener(*this);
98 _AddressbookManagerImpl::Construct(void)
100 result r = _ContactDbConnector::EnsureDbConnection();
101 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
107 _AddressbookManagerImpl::SetEventListener(IAddressbookEventListener* pListener)
109 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
111 result r = E_SUCCESS;
113 if (pListener != null)
115 if (__pIAddressbookEventListener == null && __pIAddressbookChangeEventListener == null)
117 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
118 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
120 r = pContactDbMonitor->AddListener(*this);
121 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
124 __dbVersionForContact = GetLatestVersion();
125 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
127 __dbVersionForGroup = __dbVersionForContact;
128 __dbVersionForRelation = __dbVersionForContact;
130 __pIAddressbookChangeEventListener = null;
131 __pIAddressbookEventListener = pListener;
135 if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null)
138 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
139 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
141 pContactDbMonitor->RemoveListener(*this);
144 __pIAddressbookEventListener = null;
145 __pIAddressbookChangeEventListener = null;
152 _AddressbookManagerImpl::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
154 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
156 result r = E_SUCCESS;
158 if (pListener != null)
160 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
162 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
163 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
165 r = pContactDbMonitor->AddListener(*this);
166 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
169 __dbVersionForContact = GetLatestVersion();
170 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
172 __dbVersionForGroup = __dbVersionForContact;
173 __dbVersionForRelation = __dbVersionForContact;
175 __pIAddressbookEventListener = null;
176 __pIAddressbookChangeEventListener = pListener;
180 if (__pIAddressbookChangeEventListener != null || __pIAddressbookEventListener != null)
183 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
184 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
186 pContactDbMonitor->RemoveListener(*this);
189 __pIAddressbookChangeEventListener = null;
190 __pIAddressbookEventListener = null;
197 _AddressbookManagerImpl::CreateAddressbookN(AccountId accountId, const String& name)
199 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
200 SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. account id is invalid.", GetErrorMessage(E_INVALID_ARG));
201 SysTryReturn(NID_SCL, !name.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The name is empty.", GetErrorMessage(E_INVALID_ARG));
205 result r = E_SUCCESS;
208 unique_ptr<char[]> pNameString(_StringConverter::CopyToCharArrayN(name));
209 SysTryReturn(NID_SCL, pNameString !=null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
211 __Filter<__ContactsAddressbook> filter;
213 filter.AddString(_contacts_address_book.name, CONTACTS_MATCH_EXACTLY, pNameString.get());
216 filter.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
217 filter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
220 __Query<__ContactsAddressbook> query;
222 query.SetFilter(filter);
224 int count = _AddressbookUtil::GetCountWithQuery(query);
225 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));
227 unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
228 SysTryReturn(NID_SCL, pAddressbook != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
230 r = pAddressbook->Construct();
231 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
233 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::CreateContactRecordN(_contacts_address_book._uri));
234 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
236 contacts_record_set_str(pAbRecord.get(), _contacts_address_book.name, pNameString.get());
237 contacts_record_set_int(pAbRecord.get(), _contacts_address_book.account_id, accountId);
239 r = _AddressbookUtil::InsertContactRecordN(pAbRecord.get(), recordId);
240 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
242 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(accountId);
243 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(name);
244 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(recordId);
246 return pAddressbook.release();
250 _AddressbookManagerImpl::DeleteAddressbook(AddressbookId addressbookId)
252 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));
253 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
254 result r = _AddressbookUtil::DeleteContactRecord(_contacts_address_book._uri, addressbookId);
255 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
261 _AddressbookManagerImpl::GetAddressbooksByAccountN(AccountId accountId) const
263 SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. account id is invalid.", GetErrorMessage(E_INVALID_ARG));
264 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
268 IList* pAddressbooks = null;
270 __Filter<__ContactsAddressbook> accountFilter;
271 accountFilter.Construct();
272 accountFilter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
274 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
275 if (pRwAbFilter->Get() == null)
277 __Query<__ContactsAddressbook> query;
279 query.SetFilter(accountFilter);
281 pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
282 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
286 __Filter<__ContactsAddressbook> mainFilter;
287 mainFilter.Construct();
289 mainFilter.AddFilter(*pRwAbFilter);
290 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
291 mainFilter.AddFilter(accountFilter);
293 __Query<__ContactsAddressbook> query;
295 query.SetFilter(mainFilter);
297 pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
298 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
301 return pAddressbooks;
305 _AddressbookManagerImpl::GetAllAddressbooksN(void) const
307 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
311 __Filter<__ContactsAddressbook> abFilter;
312 abFilter.Construct();
313 abFilter.AddInt(_contacts_address_book.mode, CONTACTS_MATCH_EQUAL, 0);
315 __Query<__ContactsAddressbook> query;
317 query.SetFilter(abFilter);
318 query.SetSort(_contacts_address_book.name, true);
320 IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
321 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
323 return pAddressbooks;
327 _AddressbookManagerImpl::GetAddressbookN(AddressbookId addressbookId) const
329 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. addressbookId.", GetErrorMessage(E_INVALID_ARG), addressbookId);
330 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
334 result r = E_SUCCESS;
336 char* pCharValue = null;
338 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
339 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
341 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
342 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
344 unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
345 SysTryReturn(NID_SCL, pAddressbook !=null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
347 r = pAddressbook->Construct();
348 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
350 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(addressbookId);
352 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.account_id, &intValue);
353 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
355 contacts_record_get_str_p(pAbRecord.get(), _contacts_address_book.name, &pCharValue);
356 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
358 return pAddressbook.release();
362 _AddressbookManagerImpl::AddContact(Contact& contact, AddressbookId addressbookId)
364 if (_ContactImpl::GetInstance(contact)->IsRemoved())
366 result r = _ContactImpl::GetInstance(contact)->Invalidate();
367 SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
370 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));
371 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));
372 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
374 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
375 SysTryReturn(NID_SCL, pAbRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
378 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
379 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
381 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
382 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, addressbookId);
385 result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
386 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
388 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, recordId));
389 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
391 _ContactImpl::GetInstance(contact)->SetContactRecordHandle(pContactRecord.release());
392 _RecordImpl::GetInstance(contact)->SetRecordId(recordId);
398 _AddressbookManagerImpl::AddCategory(Category& category, AddressbookId addressbookId)
400 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));
401 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
403 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
404 SysTryReturn(NID_SCL, pAbRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
407 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
408 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
410 contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
411 contacts_record_set_int(recordHandle, _contacts_group.address_book_id, addressbookId);
414 result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
415 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
417 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, recordId));
418 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
420 _CategoryImpl::GetInstance(category)->SetRecordHandle(pCategoryRecord.release());
421 _RecordImpl::GetInstance(category)->SetRecordId(recordId);
423 unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
424 if (pList != null && pList->GetCount() > 0)
426 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
428 while (pEnum->MoveNext() == E_SUCCESS)
431 pEnum->GetCurrent(tableId);
433 AddMemberToCategory(category.GetRecordId(), tableId);
436 _CategoryImpl::GetInstance(category)->ClearAddedMemberList();
443 _AddressbookManagerImpl::RemoveContact(RecordId contactId)
445 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));
446 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
448 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
449 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
452 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
453 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
455 int ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
456 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));
457 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
458 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
464 _AddressbookManagerImpl::RemoveCategory(RecordId categoryId)
466 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);
467 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
469 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
470 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
473 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
474 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
476 bool isReadOnly = false;
477 contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly);
478 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));
480 int ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
481 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));
482 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
483 // SysTryReturnResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OPERATION_FAILED, "Failed to delete a category.(%d)", ret); // temp
489 _AddressbookManagerImpl::UpdateContact(const Contact& contact)
491 RecordId contactId = contact.GetRecordId();
492 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));
493 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));
494 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
496 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
497 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
500 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
501 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
503 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
505 int ret = contacts_db_update_record(recordHandle);
506 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));
507 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
508 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));
510 pContactRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contact.GetRecordId()));
511 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
513 _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(pContactRecord.release());
519 _AddressbookManagerImpl::UpdateCategory(const Category& category)
521 RecordId categoryId = category.GetRecordId();
522 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));
523 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));
524 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
526 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
527 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
530 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
531 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
533 contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
535 int ret = contacts_db_update_record(recordHandle);
536 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));
537 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
538 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
540 pCategoryRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
541 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
543 _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(pCategoryRecord.release());
545 unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
546 if (pList != null && pList->GetCount() > 0)
549 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
550 while (pEnum->MoveNext() == E_SUCCESS)
552 pEnum->GetCurrent(tableId);
554 AddMemberToCategory(category.GetRecordId(), tableId);
557 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList();
560 pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN());
561 if (pList != null && pList->GetCount() > 0)
564 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
565 while (pEnum->MoveNext() == E_SUCCESS)
567 pEnum->GetCurrent(tableId);
569 RemoveMemberFromCategory(category.GetRecordId(), tableId);
572 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList();
579 _AddressbookManagerImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
581 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);
582 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);
583 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
585 int ret = contacts_group_add_contact(categoryId, contactId);
586 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
587 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));
588 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
594 _AddressbookManagerImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
596 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);
597 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);
598 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
600 int ret = contacts_group_remove_contact(categoryId, contactId);
601 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
602 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));
603 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
609 _AddressbookManagerImpl::GetAllCategoriesN(void) const
611 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
615 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
617 __Query<__ContactsGroup> query;
619 query.SetSort(_contacts_group.name, true);
621 if (pRwAbFilter->Get() != null)
623 query.SetFilter(*pRwAbFilter);
626 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
627 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
633 _AddressbookManagerImpl::GetCategoriesByContactN(RecordId contactId) const
635 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
636 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));
639 IList* pCategories = null;
641 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
643 __Filter<__ContactsContactGroupRel> relFilter;
644 relFilter.Construct();
645 relFilter.AddInt(_contacts_contact_grouprel.contact_id, CONTACTS_MATCH_EQUAL, contactId);
647 if (pRwAbFilter->Get() != null)
649 __Filter<__ContactsContactGroupRel> mainFilter;
650 mainFilter.Construct();
651 mainFilter.AddFilter(*pRwAbFilter);
652 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
653 mainFilter.AddFilter(relFilter);
655 __Query<__ContactsContactGroupRel> query;
657 query.SetFilter(mainFilter);
659 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
660 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
664 __Query<__ContactsContactGroupRel> query;
666 query.SetFilter(relFilter);
668 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
669 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
676 _AddressbookManagerImpl::GetCategoriesByPersonN(PersonId personId) const
678 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
682 IList* pCategories = null;
684 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
686 __Filter<__ContactsContactGroupRel> relFilter;
687 relFilter.Construct();
688 relFilter.AddInt(_contacts_contact_grouprel.person_id, CONTACTS_MATCH_EQUAL, personId);
689 relFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
690 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_GREATER_THAN, 0);
692 unsigned int propertyIds[] =
694 _contacts_contact_grouprel.group_id,
697 if (pRwAbFilter->Get() != null)
700 __Filter<__ContactsContactGroupRel> mainFilter;
701 mainFilter.Construct();
702 mainFilter.AddFilter(*pRwAbFilter);
703 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
704 mainFilter.AddFilter(relFilter);
707 __Query<__ContactsContactGroupRel> query;
709 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
710 query.SetFilter(mainFilter);
711 query.SetSort(_contacts_contact_grouprel.group_name, true);
712 query.SetDistinct(true);
714 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
715 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
719 __Query<__ContactsContactGroupRel> query;
721 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
722 query.SetFilter(relFilter);
723 query.SetSort(_contacts_contact_grouprel.group_name, true);
724 query.SetDistinct(true);
726 pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
727 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
735 _AddressbookManagerImpl::GetAllContactsN(void) const
737 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
741 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
743 __Query<__ContactsContact> query;
745 query.SetSort(_contacts_contact.display_name, true);
747 if (pRwAbFilter->Get() != null)
749 query.SetFilter(*pRwAbFilter);
752 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
753 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
759 _AddressbookManagerImpl::GetContactsByCategoryN(RecordId categoryId) const
761 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));
762 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
766 IList* pContacts = null;
768 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
770 __Filter<__ContactsContactGroupRel> relFilter;
771 relFilter.Construct();
773 if (categoryId != INVALID_RECORD_ID)
775 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
779 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
782 if (pRwAbFilter->Get() != null)
784 __Filter<__ContactsContactGroupRel> mainFilter;
785 mainFilter.Construct();
787 mainFilter.AddFilter(*pRwAbFilter);
788 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
789 mainFilter.AddFilter(relFilter);
791 __Query<__ContactsContactGroupRel> query;
793 query.SetFilter(mainFilter);
795 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
796 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
800 __Query<__ContactsContactGroupRel> query;
802 query.SetFilter(relFilter);
804 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
805 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
812 _AddressbookManagerImpl::GetContactsByPersonN(PersonId personId) const
814 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
818 IList* pContacts = null;
820 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
822 __Filter<__ContactsContact> contactFilter;
823 contactFilter.Construct();
824 contactFilter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
826 if (pRwAbFilter->Get() != null)
828 __Filter<__ContactsContact> mainFilter;
829 mainFilter.Construct();
831 mainFilter.AddFilter(*pRwAbFilter);
832 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
833 mainFilter.AddFilter(contactFilter);
835 __Query<__ContactsContact> query;
837 query.SetFilter(mainFilter);
838 query.SetSort(_contacts_contact.display_name, true);
840 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
841 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
845 __Query<__ContactsContact> query;
847 query.SetFilter(contactFilter);
848 query.SetSort(_contacts_contact.display_name, true);
850 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
851 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
858 _AddressbookManagerImpl::SearchContactsByEmailN(const String& email) const
860 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));
861 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
865 IList* pContacts = null;
867 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
869 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
870 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
872 __Filter<__ContactsContactEmail> emailFilter;
873 emailFilter.Construct();
874 emailFilter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
876 if (pRwAbFilter->Get() != null)
878 __Filter<__ContactsContactEmail> mainFilter;
879 mainFilter.Construct();
881 mainFilter.AddFilter(*pRwAbFilter);
882 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
883 mainFilter.AddFilter(emailFilter);
885 __Query<__ContactsContactEmail> query;
887 query.SetFilter(mainFilter);
888 query.SetSort(_contacts_contact_email.display_name, true);
890 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
891 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
895 __Query<__ContactsContactEmail> query;
897 query.SetFilter(emailFilter);
898 query.SetSort(_contacts_contact_email.display_name, true);
900 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
901 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
909 _AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
911 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
915 IList* pContacts = null;
917 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
919 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));
921 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
922 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
924 __Filter<__ContactsContact> nameFilter;
925 nameFilter.Construct();
926 nameFilter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
928 if (pRwAbFilter->Get() != null)
930 __Filter<__ContactsContact> mainFilter;
931 mainFilter.Construct();
933 mainFilter.AddFilter(*pRwAbFilter);
934 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
935 mainFilter.AddFilter(nameFilter);
937 __Query<__ContactsContact> query;
939 query.SetFilter(mainFilter);
940 query.SetSort(_contacts_contact.display_name, true);
942 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
943 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
947 __Query<__ContactsContact> query;
949 query.SetFilter(nameFilter);
950 query.SetSort(_contacts_contact.display_name, true);
952 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
953 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
960 _AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
962 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
966 IList* pContacts = null;
968 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));
970 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
972 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
973 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
975 __Filter<__ContactsContactNumber> numberFilter;
976 numberFilter.Construct();
977 numberFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
979 if (pRwAbFilter->Get() != null)
981 __Filter<__ContactsContactNumber> mainFilter;
982 mainFilter.Construct();
984 mainFilter.AddFilter(*pRwAbFilter);
985 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
986 mainFilter.AddFilter(numberFilter);
988 __Query<__ContactsContactNumber> query;
990 query.SetFilter(mainFilter);
991 query.SetDistinct(true);
992 query.SetSort(_contacts_contact_number.display_name, true);
994 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
995 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
999 __Query<__ContactsContactNumber> query;
1001 query.SetFilter(numberFilter);
1002 query.SetDistinct(true);
1003 query.SetSort(_contacts_contact_number.display_name, true);
1005 pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
1006 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1014 _AddressbookManagerImpl::GetCategoryCount(void) const
1016 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1020 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1022 int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(pRwAbFilter->Get());
1023 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1029 _AddressbookManagerImpl::GetContactCount(void) const
1031 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1035 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1037 int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(pRwAbFilter->Get());
1038 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1044 _AddressbookManagerImpl::GetContactN(RecordId contactId) const
1046 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1047 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
1051 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId));
1052 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1055 contacts_record_get_int(pContactRecord.get(), _contacts_contact.address_book_id, &intValue);
1057 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
1058 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1060 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
1061 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Contact does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
1063 contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue);
1064 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1066 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
1067 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1069 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
1070 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
1072 return pContact.release();
1076 _AddressbookManagerImpl::GetPersonN(PersonId personId) const
1078 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1079 SysTryReturn(NID_SCL, personId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1083 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1086 contacts_record_get_int(pPersonRecord.get(), _contacts_person.id, &intValue);
1087 SysTryReturn(NID_SCL, intValue == personId, null, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1089 Person* pPerson = __ContactsPerson::ConvertHandleTo<Person>(pPersonRecord.get());
1090 SysTryReturn(NID_SCL, pPerson != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1096 _AddressbookManagerImpl::GetCategoryN(RecordId categoryId) const
1098 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. categoryId = %d.", categoryId);
1099 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1103 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
1104 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1108 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
1109 SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1111 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.address_book_id, &intValue);
1113 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
1114 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1116 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
1117 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Category does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
1119 unique_ptr<Category> pCategory(new (std::nothrow) Category());
1120 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1122 __Filter<__ContactsGroupRelation> filter;
1124 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1126 __Query<__ContactsGroupRelation> query;
1128 query.SetFilter(filter);
1130 int count = _AddressbookUtil::GetCountWithQuery(query);
1131 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1133 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
1134 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1135 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1137 return pCategory.release();
1141 _AddressbookManagerImpl::GetLatestVersion(void) const
1143 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1145 int latestVersion = -1;
1149 int ret = contacts_db_get_current_version(&latestVersion);
1150 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1152 return latestVersion;
1156 _AddressbookManagerImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1158 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);
1159 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1163 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1165 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1166 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1168 return pChangedContacts;
1172 _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1174 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);
1175 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1179 int latestVersion1 = 0;
1180 int latestVersion2 = 0;
1182 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1184 unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion1, pRwAbIdList.get()));
1185 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1187 unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion2, pRwAbIdList.get()));
1188 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1190 unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1191 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1193 result r = pChangeList->AddItems(*pChangedGroups);
1194 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1196 r = pChangeList->AddItems(*pChangedRelations);
1197 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1199 pChangedGroups->RemoveAll(false);
1200 pChangedRelations->RemoveAll(false);
1202 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1204 return pChangeList.release();
1208 _AddressbookManagerImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1210 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);
1211 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1215 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1217 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1218 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1220 return pChangedRelations;
1224 _AddressbookManagerImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1226 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);
1227 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1231 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1233 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1234 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1236 return pChangedRelations;
1240 _AddressbookManagerImpl::OnContactChanged(void)
1242 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1247 IList* pChangedContactList = GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact);
1248 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1250 if (pChangedContactList->GetCount() > 0)
1252 if (__pIAddressbookChangeEventListener != null)
1254 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1258 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1262 pChangedContactList->RemoveAll(true);
1263 delete pChangedContactList;
1267 _AddressbookManagerImpl::OnCategoryChanged(void)
1269 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1274 IList* pChangedCategoryList = GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup);
1275 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1277 if (pChangedCategoryList->GetCount() > 0)
1279 if (__pIAddressbookChangeEventListener != null)
1281 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1285 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1289 pChangedCategoryList->RemoveAll(true);
1290 delete pChangedCategoryList;
1294 _AddressbookManagerImpl::OnRelationChanged(void)
1296 if (__pIAddressbookEventListener == null)
1301 IList* pChangedCategoryList = GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation);
1302 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1304 if (pChangedCategoryList->GetCount() > 0)
1306 if (__pIAddressbookEventListener != null)
1308 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1312 pChangedCategoryList->RemoveAll(true);
1313 delete pChangedCategoryList;
1317 _AddressbookManagerImpl::RemovePerson(PersonId personId)
1319 SysTryReturnResult(NID_SCL, personId > 0, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1320 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1322 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1323 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1325 int ret = contacts_db_delete_record(_contacts_person._uri, personId);
1326 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The person is not found.");
1327 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));
1328 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed remove a person.", GetErrorMessage(E_SYSTEM));
1334 _AddressbookManagerImpl::GetAllPersonsN(void) const
1336 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1340 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1342 unsigned int propertyIds[] =
1344 _contacts_person_grouprel.person_id,
1345 _contacts_person_grouprel.display_name,
1346 _contacts_person_grouprel.image_thumbnail_path,
1347 _contacts_person_grouprel.ringtone_path,
1348 _contacts_person_grouprel.is_favorite,
1349 _contacts_person_grouprel.has_phonenumber,
1350 _contacts_person_grouprel.has_email,
1351 _contacts_person_grouprel.addressbook_ids,
1355 __Query<__ContactsPersonGroupRel> query;
1357 query.SetSort(_contacts_person.display_name, true);
1358 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1359 query.SetDistinct(true);
1361 if (pRwAbFilter->Get() != null)
1363 query.SetFilter(*pRwAbFilter);
1366 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1367 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1373 _AddressbookManagerImpl::GetPersonsByCategoryN(RecordId categoryId) const
1375 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));
1376 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1380 IList* pPersons = null;
1382 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1384 __Filter<__ContactsPersonGroupRel> groupFilter;
1385 groupFilter.Construct();
1386 if (categoryId != INVALID_RECORD_ID)
1388 groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1392 groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
1395 unsigned int propertyIds[] =
1397 _contacts_person_grouprel.person_id,
1398 _contacts_person_grouprel.display_name,
1399 _contacts_person_grouprel.image_thumbnail_path,
1400 _contacts_person_grouprel.ringtone_path,
1401 _contacts_person_grouprel.is_favorite,
1402 _contacts_person_grouprel.has_phonenumber,
1403 _contacts_person_grouprel.has_email,
1404 _contacts_person_grouprel.addressbook_ids,
1407 if (pRwAbFilter->Get() != null)
1409 __Filter<__ContactsPersonGroupRel> mainFilter;
1410 mainFilter.Construct();
1412 mainFilter.AddFilter(*pRwAbFilter);
1413 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1414 mainFilter.AddFilter(groupFilter);
1416 __Query<__ContactsPersonGroupRel> query;
1418 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1419 query.SetFilter(mainFilter);
1420 query.SetSort(_contacts_person_grouprel.display_name, true);
1421 query.SetDistinct(true);
1423 pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1424 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1428 __Query<__ContactsPersonGroupRel> query;
1430 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1431 query.SetFilter(groupFilter);
1432 query.SetSort(_contacts_person_grouprel.display_name, true);
1433 query.SetDistinct(true);
1435 pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1436 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1444 _AddressbookManagerImpl::GetFavoritePersonsN() const
1446 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1450 __Filter<__ContactsPerson> filter;
1452 filter.AddBool(_contacts_person.is_favorite, true);
1454 __Query<__ContactsPerson> query;
1456 query.SetFilter(filter);
1457 query.SetSort(_contacts_person.display_name, true);
1459 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPerson, Person>(query);
1460 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1466 _AddressbookManagerImpl::SearchPersonsN(const Tizen::Base::String& keyword) const
1468 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1469 SysTryReturn(NID_SCL, !keyword.IsEmpty(), null, E_INVALID_ARG, "Invalid argument is used. keyword is empty string.", GetErrorMessage(E_INVALID_ARG));
1473 contacts_record_h currentRecord = null;
1474 unique_ptr<Person> pPerson(null);
1476 unique_ptr<ArrayList, AllElementsDeleter> pPersonList(new (std::nothrow) ArrayList());
1477 SysTryReturn(NID_SCL, pPersonList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1479 result r = pPersonList->Construct();
1480 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1482 unique_ptr<__SearchResult<__ContactsPerson> > pSearchResult(_AddressbookUtil::Search<__ContactsPerson>(keyword));
1483 SysTryReturn(NID_SCL, pSearchResult != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1485 while (pSearchResult->MoveNext() == E_SUCCESS)
1487 currentRecord = pSearchResult->GetCurrentRecord();
1488 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1490 pPerson.reset(__ContactsPerson::ConvertHandleTo<Person>(currentRecord));
1491 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1493 r = pPersonList->Add(*pPerson);
1494 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1499 return pPersonList.release();
1503 _AddressbookManagerImpl::SetPersonAsFavorite(PersonId personId, bool isFavorite)
1505 SysTryReturn(NID_SCL, personId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1506 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1508 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1509 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1511 bool boolValue = false;
1512 contacts_record_get_bool(pPersonRecord.get(), _contacts_person.is_favorite, &boolValue);
1514 if (boolValue != isFavorite)
1516 contacts_record_set_bool(pPersonRecord.get(), _contacts_person.is_favorite, isFavorite);
1518 int ret = contacts_db_update_record(pPersonRecord.get());
1519 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));
1520 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1527 _AddressbookManagerImpl::MergePersons(PersonId sourcePersonId, PersonId targetPersonId)
1529 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);
1530 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1532 int ret = contacts_person_link_person(targetPersonId, sourcePersonId);
1533 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1534 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1540 _AddressbookManagerImpl::UnlinkContact(PersonId personId, RecordId contactId, PersonId& newPersonId)
1542 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);
1543 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1545 int ret = contacts_person_unlink_contact(personId, contactId, &newPersonId);
1546 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));
1547 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1553 _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount)
1555 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1559 IList* pList = null;
1560 bool ascending = false;
1561 unsigned int viewSortPropertyId = 0;
1563 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1564 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1566 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);
1568 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1570 viewSortPropertyId = _AddressbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1571 ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1576 case AB_FI_TYPE_ADDRESSBOOK:
1578 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
1580 __Filter<__ContactsAddressbook> abFilter;
1581 abFilter.Construct(filterHandle);
1583 if (pRwAbFilter->Get() != null)
1585 __Filter<__ContactsAddressbook> mainFilter;
1586 mainFilter.Construct();
1587 mainFilter.AddFilter(*pRwAbFilter);
1588 if (abFilter.Get() != null)
1590 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1591 mainFilter.AddFilter(abFilter);
1594 __Query<__ContactsAddressbook> query;
1596 query.SetFilter(mainFilter);
1598 if (viewSortPropertyId != 0)
1600 query.SetSort(viewSortPropertyId, ascending);
1603 pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
1607 __Query<__ContactsAddressbook> query;
1609 query.SetFilter(abFilter);
1611 if (viewSortPropertyId != 0)
1613 query.SetSort(viewSortPropertyId, ascending);
1616 pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
1621 case AB_FI_TYPE_PERSON:
1623 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1625 __Filter<__ContactsPersonGroupRel> personFilter;
1626 personFilter.Construct(filterHandle);
1628 unsigned int propertyIds[] =
1629 { _contacts_person_grouprel.person_id,
1630 _contacts_person_grouprel.addressbook_ids,
1631 _contacts_person_grouprel.is_favorite,
1632 _contacts_person_grouprel.has_phonenumber,
1633 _contacts_person_grouprel.has_email,
1634 _contacts_person_grouprel.image_thumbnail_path,
1635 _contacts_person_grouprel.ringtone_path,
1636 _contacts_person_grouprel.display_name
1639 if (pRwAbFilter->Get() != null)
1641 __Filter<__ContactsPersonGroupRel> mainFilter;
1642 mainFilter.Construct();
1643 mainFilter.AddFilter(*pRwAbFilter);
1644 if (personFilter.Get() != null)
1646 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1647 mainFilter.AddFilter(personFilter);
1650 __Query<__ContactsPersonGroupRel> query;
1652 query.SetFilter(mainFilter);
1653 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1654 query.SetDistinct(true);
1656 if (viewSortPropertyId != 0)
1658 query.SetSort(viewSortPropertyId, ascending);
1661 pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
1665 __Query<__ContactsPersonGroupRel> query;
1667 query.SetFilter(personFilter);
1668 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1669 query.SetDistinct(true);
1671 if (viewSortPropertyId != 0)
1673 query.SetSort(viewSortPropertyId, ascending);
1676 pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
1680 case AB_FI_TYPE_CONTACT:
1682 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1684 __Filter<__ContactsContact> contactFilter;
1685 contactFilter.Construct(filterHandle);
1687 if (pRwAbFilter->Get() != null)
1689 __Filter<__ContactsContact> mainFilter;
1690 mainFilter.Construct();
1691 mainFilter.AddFilter(*pRwAbFilter);
1692 if (contactFilter.Get() != null)
1694 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1695 mainFilter.AddFilter(contactFilter);
1698 __Query<__ContactsContact> query;
1700 query.SetFilter(mainFilter);
1702 if (viewSortPropertyId != 0)
1704 query.SetSort(viewSortPropertyId, ascending);
1707 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
1711 __Query<__ContactsContact> query;
1713 query.SetFilter(contactFilter);
1715 if (viewSortPropertyId != 0)
1717 query.SetSort(viewSortPropertyId, ascending);
1720 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
1725 case AB_FI_TYPE_CATEGORY:
1727 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1729 __Filter<__ContactsGroup> groupFilter;
1730 groupFilter.Construct(filterHandle);
1732 if (pRwAbFilter->Get() != null)
1734 __Filter<__ContactsGroup> mainFilter;
1735 mainFilter.Construct();
1736 mainFilter.AddFilter(*pRwAbFilter);
1737 if (groupFilter.Get() != null)
1739 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1740 mainFilter.AddFilter(groupFilter);
1743 __Query<__ContactsGroup> query;
1745 query.SetFilter(mainFilter);
1747 if (viewSortPropertyId != 0)
1749 query.SetSort(viewSortPropertyId, ascending);
1752 pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
1756 __Query<__ContactsGroup> query;
1758 query.SetFilter(groupFilter);
1760 if (viewSortPropertyId != 0)
1762 query.SetSort(viewSortPropertyId, ascending);
1765 pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
1769 case AB_FI_TYPE_PHONE_CONTACT:
1771 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
1773 __Filter<__ContactsContactNumber> numberFilter;
1774 numberFilter.Construct(filterHandle);
1776 if (pRwAbFilter->Get() != null)
1778 __Filter<__ContactsContactNumber> mainFilter;
1779 mainFilter.Construct();
1780 mainFilter.AddFilter(*pRwAbFilter);
1781 if (numberFilter.Get() != null)
1783 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1784 mainFilter.AddFilter(numberFilter);
1787 __Query<__ContactsContactNumber> query;
1789 query.SetFilter(mainFilter);
1791 if (viewSortPropertyId != 0)
1793 query.SetSort(viewSortPropertyId, ascending);
1796 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
1800 __Query<__ContactsContactNumber> query;
1802 query.SetFilter(numberFilter);
1804 if (viewSortPropertyId != 0)
1806 query.SetSort(viewSortPropertyId, ascending);
1809 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
1813 case AB_FI_TYPE_EMAIL_CONTACT:
1815 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
1817 __Filter<__ContactsContactEmail> emailFilter;
1818 emailFilter.Construct(filterHandle);
1820 if (pRwAbFilter->Get() != null)
1822 __Filter<__ContactsContactEmail> mainFilter;
1823 mainFilter.Construct();
1824 mainFilter.AddFilter(*pRwAbFilter);
1825 if (emailFilter.Get() != null)
1827 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1828 mainFilter.AddFilter(emailFilter);
1831 __Query<__ContactsContactEmail> query;
1833 query.SetFilter(mainFilter);
1835 if (viewSortPropertyId != 0)
1837 query.SetSort(viewSortPropertyId, ascending);
1840 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
1844 __Query<__ContactsContactEmail> query;
1846 query.SetFilter(emailFilter);
1848 if (viewSortPropertyId != 0)
1850 query.SetSort(viewSortPropertyId, ascending);
1853 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
1858 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The filter type is invalid", GetErrorMessage(E_INVALID_ARG));
1866 _AddressbookManagerImpl::GetMatchedItemCount(const AddressbookFilter& filter)
1868 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1873 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1874 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1878 case AB_FI_TYPE_ADDRESSBOOK:
1880 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
1882 __Filter<__ContactsAddressbook> abFilter;
1883 abFilter.Construct(filterHandle);
1885 if (pRwAbFilter->Get() != null)
1887 __Filter<__ContactsAddressbook> mainFilter;
1888 mainFilter.Construct();
1889 mainFilter.AddFilter(*pRwAbFilter);
1890 if (abFilter.Get() != null)
1892 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1893 mainFilter.AddFilter(abFilter);
1896 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(mainFilter.Get());
1900 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(abFilter.Get());
1904 case AB_FI_TYPE_PERSON:
1906 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1908 __Filter<__ContactsPersonGroupRel> personFilter;
1909 personFilter.Construct(filterHandle);
1911 if (pRwAbFilter->Get() != null)
1913 __Filter<__ContactsPersonGroupRel> mainFilter;
1914 mainFilter.Construct();
1915 mainFilter.AddFilter(*pRwAbFilter);
1916 if (personFilter.Get() != null)
1918 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1919 mainFilter.AddFilter(personFilter);
1922 unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
1924 __Query<__ContactsPersonGroupRel> query;
1926 query.SetFilter(mainFilter);
1927 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1928 query.SetDistinct(true);
1930 count = _AddressbookUtil::GetCountWithQuery(query);
1934 unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
1936 __Query<__ContactsPersonGroupRel> query;
1938 query.SetFilter(personFilter);
1939 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1940 query.SetDistinct(true);
1942 count = _AddressbookUtil::GetCountWithQuery(query);
1948 case AB_FI_TYPE_CONTACT:
1950 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1952 __Filter<__ContactsContact> contactFilter;
1953 contactFilter.Construct(filterHandle);
1955 if (pRwAbFilter->Get() != null)
1957 __Filter<__ContactsContact> mainFilter;
1958 mainFilter.Construct();
1959 mainFilter.AddFilter(*pRwAbFilter);
1960 if (contactFilter.Get() != null)
1962 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1963 mainFilter.AddFilter(contactFilter);
1966 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(mainFilter.Get());
1970 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(contactFilter.Get());
1974 case AB_FI_TYPE_CATEGORY:
1976 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1978 __Filter<__ContactsGroup> groupFilter;
1979 groupFilter.Construct(filterHandle);
1981 if (pRwAbFilter->Get() != null)
1983 __Filter<__ContactsGroup> mainFilter;
1984 mainFilter.Construct();
1985 mainFilter.AddFilter(*pRwAbFilter);
1986 if (groupFilter.Get() != null)
1988 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1989 mainFilter.AddFilter(groupFilter);
1992 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(mainFilter.Get());
1996 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(groupFilter.Get());
2000 case AB_FI_TYPE_PHONE_CONTACT:
2002 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
2004 __Filter<__ContactsContactNumber> numberFilter;
2005 numberFilter.Construct(filterHandle);
2007 if (pRwAbFilter->Get() != null)
2009 __Filter<__ContactsContactNumber> mainFilter;
2010 mainFilter.Construct();
2011 mainFilter.AddFilter(*pRwAbFilter);
2012 if (numberFilter.Get() != null)
2014 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2015 mainFilter.AddFilter(numberFilter);
2018 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(mainFilter.Get());
2022 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(numberFilter.Get());
2026 case AB_FI_TYPE_EMAIL_CONTACT:
2028 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
2030 __Filter<__ContactsContactEmail> emailFilter;
2031 emailFilter.Construct(filterHandle);
2033 if (pRwAbFilter->Get() != null)
2035 __Filter<__ContactsContactEmail> mainFilter;
2036 mainFilter.Construct();
2037 mainFilter.AddFilter(*pRwAbFilter);
2038 if (emailFilter.Get() != null)
2040 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
2041 mainFilter.AddFilter(emailFilter);
2044 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(mainFilter.Get());
2048 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(emailFilter.Get());
2053 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter is invalid", GetErrorMessage(GetLastResult()));
2061 _AddressbookManagerImpl::OnEachContact(contacts_record_h recordHandle, void* pUserData)
2063 IList* pList = static_cast<IList*>(pUserData);
2067 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
2068 SysTryReturn(NID_SCL, pContact != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2070 contacts_record_h newRecordHandle = null;
2072 contacts_record_clone(recordHandle, &newRecordHandle);
2073 SysTryReturn(NID_SCL, newRecordHandle != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2075 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecordHandle);
2077 result r = pList->Add(*pContact);
2078 SysTryReturn(NID_SCL, !IsFailed(r), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2086 _AddressbookManagerImpl::ParseContactsFromVcardN(const Tizen::Base::String& vcardPath)
2088 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2093 result r = file.Construct(vcardPath, "r");
2094 SysTryReturn(NID_SCL, r != E_INVALID_ARG, null, E_INVALID_ARG, "[%s] Invalid argument is used..", GetErrorMessage(E_INVALID_ARG));
2095 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));
2096 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));
2097 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2099 unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2101 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(vcardPath));
2103 int ret = contacts_vcard_parse_to_contact_foreach(pCharArray.get(), OnEachContact, pList.get());
2104 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2105 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2106 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2108 return pList.release();
2112 _AddressbookManagerImpl::ExportPersonToVcard(const Person& person, const Tizen::Base::String& vcardPath)
2114 bool exist = File::IsFileExist(vcardPath);
2115 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2116 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2117 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2120 result r = file.Construct(vcardPath, "w");
2121 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));
2122 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2123 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2125 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
2126 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2128 char* pVcardStream = null;
2129 int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2130 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));
2131 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2133 r = file.Write(pVcardStream, strlen(pVcardStream));
2135 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2136 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2142 _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::IList& personList, const Tizen::Base::String& vcardPath)
2144 bool exist = File::IsFileExist(vcardPath);
2145 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2146 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2147 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2149 int ret = CONTACTS_ERROR_NONE;
2150 char* pVcardStream = null;
2153 result r = file.Construct(vcardPath, "w");
2154 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));
2155 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2156 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2159 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
2161 unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
2162 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2164 while (pEnum->MoveNext() == E_SUCCESS)
2166 Person* pPerson = static_cast<Person*>(pEnum->GetCurrent());
2168 pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
2169 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2171 ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2172 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));
2173 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2175 r = file.Write(pVcardStream, strlen(pVcardStream));
2177 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2178 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2185 _AddressbookManagerImpl::ExportContactToVcard(const Contact& contact, const Tizen::Base::String& vcardPath)
2187 bool exist = File::IsFileExist(vcardPath);
2188 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2189 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2190 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2193 result r = file.Construct(vcardPath, "w");
2194 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));
2195 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2196 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2198 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
2200 char* pVcardStream = null;
2202 int ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2203 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));
2204 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2206 r = file.Write(pVcardStream, strlen(pVcardStream));
2208 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2209 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2215 _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IList& contactList, const Tizen::Base::String& vcardPath)
2217 bool exist = File::IsFileExist(vcardPath);
2218 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2219 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2220 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2222 int ret = CONTACTS_ERROR_NONE;
2223 char* pVcardStream = null;
2225 Contact* pContact = null;
2227 result r = file.Construct(vcardPath, "w");
2228 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));
2229 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2230 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2232 contacts_record_h recordHandle = null;
2234 unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
2235 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2237 while (pEnum->MoveNext() == E_SUCCESS)
2239 pContact = static_cast<Contact*>(pEnum->GetCurrent());
2241 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
2243 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2244 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));
2245 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2247 r = file.Write(pVcardStream, strlen(pVcardStream));
2249 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2250 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2257 _AddressbookManagerImpl::ExportContactToVcardStreamN(const Contact& contact)
2259 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2263 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
2265 char* pVcardStream = null;
2266 int ret = CONTACTS_ERROR_NONE;
2268 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2269 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2270 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2271 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2273 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2274 if (pByteBuffer == null)
2277 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2282 result r = pByteBuffer->Construct(strlen(pVcardStream));
2286 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2291 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2293 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2294 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2296 return pByteBuffer.release();
2300 _AddressbookManagerImpl::ExportContactsToVcardStreamN(const Tizen::Base::Collection::IList& contactList)
2302 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2306 char* pVcardStream = null;
2307 int ret = CONTACTS_ERROR_NONE;
2308 Contact* pContact = null;
2309 result r = E_SUCCESS;
2312 contacts_record_h recordHandle = null;
2314 unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
2315 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2317 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2318 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2320 r = pByteBuffer->Construct(capacity);
2321 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2323 if (contactList.GetCount() == 0)
2325 return pByteBuffer.release();
2328 while (pEnum->MoveNext() == E_SUCCESS)
2330 pContact = static_cast<Contact*>(pEnum->GetCurrent());
2332 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
2334 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2335 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2336 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2337 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2339 capacity += strlen(pVcardStream);
2340 r = pByteBuffer->ExpandCapacity(capacity);
2344 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2349 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2351 pVcardStream = null;
2352 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2355 return pByteBuffer.release();
2359 _AddressbookManagerImpl::ExportPersonToVcardStreamN(const Person& person)
2361 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2365 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
2366 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2367 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2369 char* pVcardStream = null;
2370 int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2371 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2372 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2373 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2375 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2376 if (pByteBuffer == null)
2379 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2384 result r = pByteBuffer->Construct(strlen(pVcardStream));
2388 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2393 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2395 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2397 return pByteBuffer.release();
2401 _AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collection::IList& personList)
2403 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2407 int ret = CONTACTS_ERROR_NONE;
2408 Person* pPerson = null;
2409 char* pVcardStream = null;
2413 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
2415 unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
2416 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2418 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2419 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2421 result r = pByteBuffer->Construct(capacity);
2422 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2424 if (personList.GetCount() == 0)
2426 return pByteBuffer.release();
2429 while (pEnum->MoveNext() == E_SUCCESS)
2431 pPerson = static_cast<Person*>(pEnum->GetCurrent());
2433 pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
2434 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2435 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2437 ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2438 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2439 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2440 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2442 capacity += strlen(pVcardStream);
2443 r = pByteBuffer->ExpandCapacity(capacity);
2447 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2452 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2454 pVcardStream = null;
2455 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2458 return pByteBuffer.release();
2462 _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardStream)
2464 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2468 contacts_list_h listHandle = null;
2469 result r = E_SUCCESS;
2471 int ret = contacts_vcard_parse_to_contacts(reinterpret_cast<char*>(const_cast<byte*>(vcardStream.GetPointer())), &listHandle);
2472 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2473 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2475 unsigned int count = 0;
2476 contacts_record_h recordHandle = null;
2477 contacts_list_get_count(listHandle, &count);
2479 unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2482 contacts_list_destroy(listHandle, true);
2483 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2488 r = pList->Construct(count);
2491 contacts_list_destroy(listHandle, true);
2492 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2497 for (unsigned int i = 0; i < count; i++)
2499 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
2500 if (pContact == null)
2502 contacts_list_destroy(listHandle, true);
2503 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2508 r = pList->Add(pContact.get());
2511 contacts_list_destroy(listHandle, true);
2512 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2520 unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2522 while (pEnum->MoveNext() == E_SUCCESS)
2524 Contact* pContact = static_cast <Contact*> (pEnum->GetCurrent());
2526 contacts_list_get_current_record_p(listHandle, &recordHandle);
2527 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(recordHandle);
2529 ret = contacts_list_next(listHandle);
2532 contacts_list_destroy(listHandle, false);
2534 return pList.release();
2538 _AddressbookManagerImpl::ExportUserProfileToVcardStreamN(const UserProfile& userProfile)
2540 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2544 char* pVcardStream = null;
2545 int ret = CONTACTS_ERROR_NONE;
2546 contacts_record_h recordHandle = null;
2548 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2550 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2551 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2552 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2553 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2555 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2556 if (pByteBuffer == null)
2559 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2563 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2565 result r = pByteBuffer->Construct(strlen(pVcardStream));
2569 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2574 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2576 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2577 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2579 return pByteBuffer.release();
2583 _AddressbookManagerImpl::ExportUserProfilesToVcardStreamN(const Tizen::Base::Collection::IList& userProfileList)
2585 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2589 char* pVcardStream = null;
2590 int ret = CONTACTS_ERROR_NONE;
2591 UserProfile* pProfile = null;
2592 result r = E_SUCCESS;
2595 unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2596 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2598 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2599 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2601 r = pByteBuffer->Construct(capacity);
2602 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2604 if (userProfileList.GetCount() == 0)
2606 return pByteBuffer.release();
2609 while (pEnum->MoveNext() == E_SUCCESS)
2611 contacts_record_h recordHandle = null;
2613 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2615 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2617 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2618 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2619 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2620 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2622 capacity += strlen(pVcardStream);
2623 r = pByteBuffer->ExpandCapacity(capacity);
2627 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2632 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2634 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2637 return pByteBuffer.release();
2641 _AddressbookManagerImpl::ExportUserProfileToVcard(const UserProfile& userProfile, const Tizen::Base::String& vcardPath)
2643 bool exist = File::IsFileExist(vcardPath);
2644 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2645 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2646 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2649 result r = file.Construct(vcardPath, "w");
2650 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));
2651 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2652 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2654 char* pVcardStream = null;
2655 contacts_record_h recordHandle = null;
2657 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2659 int ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2660 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));
2661 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2663 r = file.Write(pVcardStream, strlen(pVcardStream));
2665 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2666 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2672 _AddressbookManagerImpl::ExportUserProfilesToVcard(const Tizen::Base::Collection::IList& userProfileList, const Tizen::Base::String& vcardPath)
2674 bool exist = File::IsFileExist(vcardPath);
2675 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2676 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2677 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2679 int ret = CONTACTS_ERROR_NONE;
2680 char* pVcardStream = null;
2682 UserProfile* pProfile = null;
2684 result r = file.Construct(vcardPath, "w");
2685 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));
2686 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2687 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2689 unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2690 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2692 while (pEnum->MoveNext() == E_SUCCESS)
2694 contacts_record_h recordHandle = null;
2696 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2698 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2700 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2701 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));
2702 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2704 r = file.Write(pVcardStream, strlen(pVcardStream));
2706 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2707 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2714 _AddressbookManagerImpl::GetAllUserProfilesN(void) const
2716 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2720 unique_ptr< __Filter<__ContactsUserProfile> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsUserProfile>());
2721 SysTryReturn(NID_SCL, pRwAbFilter != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2723 __Query<__ContactsUserProfile> query;
2725 query.SetSort(_contacts_my_profile.display_name, true);
2727 if (pRwAbFilter->Get() != null)
2729 query.SetFilter(*pRwAbFilter);
2732 IList* pUserProfilesList = _AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query);
2733 SysTryReturn(NID_SCL, pUserProfilesList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2735 return pUserProfilesList;
2739 _AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
2741 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2742 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. Addressbook Id(%d).", GetErrorMessage(E_INVALID_ARG), addressbookId);
2747 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
2748 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2750 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &mode);
2751 SysTryReturn(NID_SCL, mode == 0, null, E_OBJ_NOT_FOUND, "[%s] The addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
2753 __Filter<__ContactsUserProfile> filter;
2755 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, addressbookId);
2757 __Query<__ContactsUserProfile> query;
2759 query.SetFilter(filter);
2761 unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
2762 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2763 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
2764 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
2766 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
2767 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
2772 _AddressbookManagerImpl*
2773 _AddressbookManagerImpl::GetInstance(AddressbookManager& addressbookManager)
2775 return addressbookManager.__pAddressbookManagerImpl;
2778 const _AddressbookManagerImpl*
2779 _AddressbookManagerImpl::GetInstance(const AddressbookManager& addressbookManager)
2781 return addressbookManager.__pAddressbookManagerImpl;