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 is 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()));
255 int ret = contacts_db_delete_record(_contacts_address_book._uri, addressbookId);
256 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));
257 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The addressbook is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
258 // SysTryReturnResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OPERATION_FAILED, "Failed to delete an addressbook.(%d)", ret); // temp
264 _AddressbookManagerImpl::GetAddressbooksByAccountN(AccountId accountId) const
266 SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. account id is invalid.", GetErrorMessage(E_INVALID_ARG));
267 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
271 __Filter<__ContactsAddressbook> accountFilter;
272 accountFilter.Construct();
273 accountFilter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
275 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
277 __Filter<__ContactsAddressbook> mainFilter;
278 mainFilter.Construct();
280 mainFilter.AddFilter(*pRwAbFilter);
281 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
282 mainFilter.AddFilter(accountFilter);
284 __Query<__ContactsAddressbook> query;
286 query.SetFilter(mainFilter);
288 IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
289 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
291 return pAddressbooks;
295 _AddressbookManagerImpl::GetAllAddressbooksN(void) const
297 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
301 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
303 __Query<__ContactsAddressbook> query;
305 query.SetFilter(*pRwAbFilter);
306 query.SetSort(_contacts_address_book.name, true);
308 IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
309 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
311 return pAddressbooks;
315 _AddressbookManagerImpl::GetAddressbookN(AddressbookId addressbookId) const
317 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. addressbookId.", GetErrorMessage(E_INVALID_ARG), addressbookId);
318 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
322 result r = E_SUCCESS;
324 char* pCharValue = null;
326 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
327 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
329 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
330 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
332 unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
333 SysTryReturn(NID_SCL, pAddressbook !=null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
335 r = pAddressbook->Construct();
336 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
338 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(addressbookId);
340 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.account_id, &intValue);
341 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
343 contacts_record_get_str_p(pAbRecord.get(), _contacts_address_book.name, &pCharValue);
344 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
346 return pAddressbook.release();
350 _AddressbookManagerImpl::AddContact(Contact& contact, AddressbookId addressbookId)
352 if (_ContactImpl::GetInstance(contact)->IsRemoved())
354 result r = _ContactImpl::GetInstance(contact)->Invalidate();
355 SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
358 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));
359 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));
360 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
362 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
363 SysTryReturn(NID_SCL, pAbRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
366 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
367 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
369 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
370 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, addressbookId);
373 result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
374 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
376 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, recordId));
377 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
379 _ContactImpl::GetInstance(contact)->SetContactRecordHandle(pContactRecord.release());
380 _RecordImpl::GetInstance(contact)->SetRecordId(recordId);
386 _AddressbookManagerImpl::AddCategory(Category& category, AddressbookId addressbookId)
388 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));
389 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
391 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
392 SysTryReturn(NID_SCL, pAbRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
395 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
396 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
398 contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
399 contacts_record_set_int(recordHandle, _contacts_group.address_book_id, addressbookId);
402 result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
403 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
405 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, recordId));
406 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
408 _CategoryImpl::GetInstance(category)->SetRecordHandle(pCategoryRecord.release());
409 _RecordImpl::GetInstance(category)->SetRecordId(recordId);
411 unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
412 if (pList != null && pList->GetCount() > 0)
414 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
416 while (pEnum->MoveNext() == E_SUCCESS)
419 pEnum->GetCurrent(tableId);
421 AddMemberToCategory(category.GetRecordId(), tableId);
424 _CategoryImpl::GetInstance(category)->ClearAddedMemberList();
431 _AddressbookManagerImpl::RemoveContact(RecordId contactId)
433 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));
434 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
436 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
437 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
440 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
441 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
443 int ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
444 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));
445 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));
446 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
452 _AddressbookManagerImpl::RemoveCategory(RecordId categoryId)
454 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);
455 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
457 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
458 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
461 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
462 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
464 bool isReadOnly = false;
465 contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly);
466 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));
468 int ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
469 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));
470 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));
471 // SysTryReturnResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OPERATION_FAILED, "Failed to delete a category.(%d)", ret); // temp
477 _AddressbookManagerImpl::UpdateContact(const Contact& contact)
479 RecordId contactId = contact.GetRecordId();
480 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));
481 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));
482 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
484 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
485 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
488 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
489 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
491 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
493 int ret = contacts_db_update_record(recordHandle);
494 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));
495 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
496 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));
498 pContactRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contact.GetRecordId()));
499 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
501 _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(pContactRecord.release());
507 _AddressbookManagerImpl::UpdateCategory(const Category& category)
509 RecordId categoryId = category.GetRecordId();
510 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));
511 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));
512 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
514 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
515 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
518 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
519 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
521 contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
523 int ret = contacts_db_update_record(recordHandle);
524 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));
525 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
526 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
528 pCategoryRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
529 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
531 _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(pCategoryRecord.release());
533 unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
534 if (pList != null && pList->GetCount() > 0)
537 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
538 while (pEnum->MoveNext() == E_SUCCESS)
540 pEnum->GetCurrent(tableId);
542 AddMemberToCategory(category.GetRecordId(), tableId);
545 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList();
548 pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN());
549 if (pList != null && pList->GetCount() > 0)
552 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
553 while (pEnum->MoveNext() == E_SUCCESS)
555 pEnum->GetCurrent(tableId);
557 RemoveMemberFromCategory(category.GetRecordId(), tableId);
560 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList();
567 _AddressbookManagerImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
569 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);
570 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);
571 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
573 int ret = contacts_group_add_contact(categoryId, contactId);
574 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
575 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));
576 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
582 _AddressbookManagerImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
584 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);
585 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);
586 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
588 int ret = contacts_group_remove_contact(categoryId, contactId);
589 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
590 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));
591 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
597 _AddressbookManagerImpl::GetAllCategoriesN(void) const
599 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
603 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
605 __Query<__ContactsGroup> query;
607 query.SetFilter(*pRwAbFilter);
608 query.SetSort(_contacts_group.name, true);
610 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
611 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
617 _AddressbookManagerImpl::GetCategoriesByContactN(RecordId contactId) const
619 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
620 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));
624 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
626 __Filter<__ContactsContactGroupRel> relFilter;
627 relFilter.Construct();
628 relFilter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
630 __Filter<__ContactsContactGroupRel> mainFilter;
631 mainFilter.AddFilter(*pRwAbFilter);
632 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
633 mainFilter.AddFilter(relFilter);
635 __Query<__ContactsContactGroupRel> query;
637 query.SetFilter(mainFilter);
639 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
640 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
646 _AddressbookManagerImpl::GetCategoriesByPersonN(PersonId personId) const
648 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
652 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
654 __Filter<__ContactsContactGroupRel> relFilter;
655 relFilter.Construct();
656 relFilter.AddInt(_contacts_contact_grouprel.person_id, CONTACTS_MATCH_EQUAL, personId);
657 relFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
658 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_GREATER_THAN, 0);
660 __Filter<__ContactsContactGroupRel> mainFilter;
661 mainFilter.AddFilter(*pRwAbFilter);
662 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
663 mainFilter.AddFilter(relFilter);
665 unsigned int propertyIds[] =
667 _contacts_contact_grouprel.group_id,
670 __Query<__ContactsContactGroupRel> query;
672 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
673 query.SetFilter(mainFilter);
674 query.SetSort(_contacts_contact_grouprel.group_name, true);
675 query.SetDistinct(true);
677 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
678 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
684 _AddressbookManagerImpl::GetAllContactsN(void) const
686 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
690 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
692 __Query<__ContactsContact> query;
694 query.SetFilter(*pRwAbFilter);
695 query.SetSort(_contacts_contact.display_name, true);
697 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
698 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
704 _AddressbookManagerImpl::GetContactsByCategoryN(RecordId categoryId) const
706 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));
707 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
711 unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
713 __Filter<__ContactsContactGroupRel> relFilter;
714 relFilter.Construct();
716 if (categoryId != INVALID_RECORD_ID)
718 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
722 relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
725 __Filter<__ContactsContactGroupRel> mainFilter;
726 mainFilter.Construct();
728 mainFilter.AddFilter(*pRwAbFilter);
729 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
730 mainFilter.AddFilter(relFilter);
732 __Query<__ContactsContactGroupRel> query;
734 query.SetFilter(mainFilter);
736 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
737 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
743 _AddressbookManagerImpl::GetContactsByPersonN(PersonId personId) const
745 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
749 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
751 __Filter<__ContactsContact> contactFilter;
752 contactFilter.Construct();
753 contactFilter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
755 __Filter<__ContactsContact> mainFilter;
756 mainFilter.Construct();
758 mainFilter.AddFilter(*pRwAbFilter);
759 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
760 mainFilter.AddFilter(contactFilter);
762 __Query<__ContactsContact> query;
764 query.SetFilter(mainFilter);
765 query.SetSort(_contacts_contact.display_name, true);
767 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
768 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
774 _AddressbookManagerImpl::SearchContactsByEmailN(const String& email) const
776 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));
777 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
781 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
783 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
784 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
786 __Filter<__ContactsContactEmail> emailFilter;
787 emailFilter.Construct();
788 emailFilter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
790 __Filter<__ContactsContactEmail> mainFilter;
791 mainFilter.Construct();
793 mainFilter.AddFilter(*pRwAbFilter);
794 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
795 mainFilter.AddFilter(emailFilter);
797 __Query<__ContactsContactEmail> query;
799 query.SetFilter(mainFilter);
800 query.SetSort(_contacts_contact_email.display_name, true);
802 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
803 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
809 _AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
811 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
815 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
817 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));
819 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
820 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
822 __Filter<__ContactsContact> nameFilter;
823 nameFilter.Construct();
824 nameFilter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
826 __Filter<__ContactsContact> mainFilter;
827 mainFilter.Construct();
829 mainFilter.AddFilter(*pRwAbFilter);
830 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
831 mainFilter.AddFilter(nameFilter);
833 __Query<__ContactsContact> query;
835 query.SetFilter(mainFilter);
836 query.SetSort(_contacts_contact.display_name, true);
838 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
839 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
845 _AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
847 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
851 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));
853 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
855 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
856 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
858 __Filter<__ContactsContactNumber> numberFilter;
859 numberFilter.Construct();
860 numberFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
862 __Filter<__ContactsContactNumber> mainFilter;
863 mainFilter.Construct();
865 mainFilter.AddFilter(*pRwAbFilter);
866 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
867 mainFilter.AddFilter(numberFilter);
869 __Query<__ContactsContactNumber> query;
871 query.SetFilter(mainFilter);
872 query.SetDistinct(true);
873 query.SetSort(_contacts_contact_number.display_name, true);
875 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
876 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
882 _AddressbookManagerImpl::GetCategoryCount(void) const
884 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
888 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
890 int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(pRwAbFilter->Get());
891 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
897 _AddressbookManagerImpl::GetContactCount(void) const
899 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
903 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
905 int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(pRwAbFilter->Get());
906 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
912 _AddressbookManagerImpl::GetContactN(RecordId contactId) const
914 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
915 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
919 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId));
920 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
923 contacts_record_get_int(pContactRecord.get(), _contacts_contact.address_book_id, &intValue);
925 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
926 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
928 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
929 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Contact does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
931 contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue);
932 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
934 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
935 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
937 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
938 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
940 return pContact.release();
944 _AddressbookManagerImpl::GetPersonN(PersonId personId) const
946 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
947 SysTryReturn(NID_SCL, personId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
951 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
954 contacts_record_get_int(pPersonRecord.get(), _contacts_person.id, &intValue);
955 SysTryReturn(NID_SCL, intValue == personId, null, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
957 Person* pPerson = __ContactsPerson::ConvertHandleTo<Person>(pPersonRecord.get());
958 SysTryReturn(NID_SCL, pPerson != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
964 _AddressbookManagerImpl::GetCategoryN(RecordId categoryId) const
966 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. categoryId = %d.", categoryId);
967 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
971 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
972 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
976 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
977 SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
979 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.address_book_id, &intValue);
981 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
982 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
984 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
985 SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Category does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
987 unique_ptr<Category> pCategory(new (std::nothrow) Category());
988 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
990 __Filter<__ContactsGroupRelation> filter;
992 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
994 __Query<__ContactsGroupRelation> query;
996 query.SetFilter(filter);
998 int count = _AddressbookUtil::GetCountWithQuery(query);
999 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1001 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
1002 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1003 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1005 return pCategory.release();
1009 _AddressbookManagerImpl::GetLatestVersion(void) const
1011 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1013 int latestVersion = -1;
1017 int ret = contacts_db_get_current_version(&latestVersion);
1018 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1020 return latestVersion;
1024 _AddressbookManagerImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1026 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);
1027 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1031 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1033 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1034 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1036 return pChangedContacts;
1040 _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1042 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);
1043 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1047 int latestVersion1 = 0;
1048 int latestVersion2 = 0;
1050 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1052 unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion1, pRwAbIdList.get()));
1053 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1055 unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion2, pRwAbIdList.get()));
1056 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1058 unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1059 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1061 result r = pChangeList->AddItems(*pChangedGroups);
1062 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1064 r = pChangeList->AddItems(*pChangedRelations);
1065 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1067 pChangedGroups->RemoveAll(false);
1068 pChangedRelations->RemoveAll(false);
1070 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1072 return pChangeList.release();
1076 _AddressbookManagerImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1078 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);
1079 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1083 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1085 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1086 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1088 return pChangedRelations;
1092 _AddressbookManagerImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1094 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);
1095 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1099 unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
1101 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
1102 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1104 return pChangedRelations;
1108 _AddressbookManagerImpl::OnContactChanged(void)
1110 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1115 IList* pChangedContactList = GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact);
1116 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1118 if (pChangedContactList->GetCount() > 0)
1120 if (__pIAddressbookChangeEventListener != null)
1122 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1126 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1130 pChangedContactList->RemoveAll(true);
1131 delete pChangedContactList;
1135 _AddressbookManagerImpl::OnCategoryChanged(void)
1137 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1142 IList* pChangedCategoryList = GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup);
1143 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1145 if (pChangedCategoryList->GetCount() > 0)
1147 if (__pIAddressbookChangeEventListener != null)
1149 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1153 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1157 pChangedCategoryList->RemoveAll(true);
1158 delete pChangedCategoryList;
1162 _AddressbookManagerImpl::OnRelationChanged(void)
1164 if (__pIAddressbookEventListener == null)
1169 IList* pChangedCategoryList = GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation);
1170 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1172 if (pChangedCategoryList->GetCount() > 0)
1174 if (__pIAddressbookEventListener != null)
1176 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1180 pChangedCategoryList->RemoveAll(true);
1181 delete pChangedCategoryList;
1185 _AddressbookManagerImpl::RemovePerson(PersonId personId)
1187 SysTryReturnResult(NID_SCL, personId > 0, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1188 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1190 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1191 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1193 int ret = contacts_db_delete_record(_contacts_person._uri, personId);
1194 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.");
1195 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));
1196 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));
1202 _AddressbookManagerImpl::GetAllPersonsN(void) const
1204 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1208 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1210 // unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
1211 unsigned int propertyIds[] =
1213 _contacts_person_grouprel.person_id,
1214 _contacts_person_grouprel.display_name,
1215 _contacts_person_grouprel.image_thumbnail_path,
1216 _contacts_person_grouprel.ringtone_path,
1217 _contacts_person_grouprel.is_favorite,
1218 _contacts_person_grouprel.has_phonenumber,
1219 _contacts_person_grouprel.has_email,
1220 _contacts_person_grouprel.addressbook_ids,
1224 __Query<__ContactsPersonGroupRel> query;
1226 query.SetFilter(*pRwAbFilter);
1227 query.SetSort(_contacts_person.display_name, true);
1228 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1229 query.SetDistinct(true);
1231 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1232 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1238 _AddressbookManagerImpl::GetPersonsByCategoryN(RecordId categoryId) const
1240 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));
1241 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1245 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1247 __Filter<__ContactsPersonGroupRel> groupFilter;
1248 groupFilter.Construct();
1249 if (categoryId != INVALID_RECORD_ID)
1251 groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1255 groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
1258 unsigned int propertyIds[] =
1260 _contacts_person_grouprel.person_id,
1261 _contacts_person_grouprel.display_name,
1262 _contacts_person_grouprel.image_thumbnail_path,
1263 _contacts_person_grouprel.ringtone_path,
1264 _contacts_person_grouprel.is_favorite,
1265 _contacts_person_grouprel.has_phonenumber,
1266 _contacts_person_grouprel.has_email,
1267 _contacts_person_grouprel.addressbook_ids,
1270 __Filter<__ContactsPersonGroupRel> mainFilter;
1271 mainFilter.Construct();
1273 mainFilter.AddFilter(*pRwAbFilter);
1274 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1275 mainFilter.AddFilter(groupFilter);
1278 __Query<__ContactsPersonGroupRel> query;
1280 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1281 query.SetFilter(mainFilter);
1282 query.SetSort(_contacts_person_grouprel.display_name, true);
1283 query.SetDistinct(true);
1285 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1286 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1292 _AddressbookManagerImpl::GetFavoritePersonsN() const
1294 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1298 __Filter<__ContactsPerson> filter;
1300 filter.AddBool(_contacts_person.is_favorite, true);
1302 __Query<__ContactsPerson> query;
1304 query.SetFilter(filter);
1305 query.SetSort(_contacts_person.display_name, true);
1307 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPerson, Person>(query);
1308 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1314 _AddressbookManagerImpl::SearchPersonsN(const Tizen::Base::String& keyword) const
1316 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1317 SysTryReturn(NID_SCL, !keyword.IsEmpty(), null, E_INVALID_ARG, "Invalid argument is used. keyword is empty string.", GetErrorMessage(E_INVALID_ARG));
1321 contacts_record_h currentRecord = null;
1322 unique_ptr<Person> pPerson(null);
1324 unique_ptr<ArrayList, AllElementsDeleter> pPersonList(new (std::nothrow) ArrayList());
1325 SysTryReturn(NID_SCL, pPersonList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1327 result r = pPersonList->Construct();
1328 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1330 unique_ptr<__SearchResult<__ContactsPerson> > pSearchResult(_AddressbookUtil::Search<__ContactsPerson>(keyword));
1331 SysTryReturn(NID_SCL, pSearchResult != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1333 while (pSearchResult->MoveNext() == E_SUCCESS)
1335 currentRecord = pSearchResult->GetCurrentRecord();
1336 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1338 pPerson.reset(__ContactsPerson::ConvertHandleTo<Person>(currentRecord));
1339 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1341 r = pPersonList->Add(*pPerson);
1342 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1347 return pPersonList.release();
1351 _AddressbookManagerImpl::SetPersonAsFavorite(PersonId personId, bool isFavorite)
1353 SysTryReturn(NID_SCL, personId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1354 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1356 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
1357 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1359 bool boolValue = false;
1360 contacts_record_get_bool(pPersonRecord.get(), _contacts_person.is_favorite, &boolValue);
1362 if (boolValue != isFavorite)
1364 contacts_record_set_bool(pPersonRecord.get(), _contacts_person.is_favorite, isFavorite);
1366 int ret = contacts_db_update_record(pPersonRecord.get());
1367 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));
1368 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1375 _AddressbookManagerImpl::MergePersons(PersonId sourcePersonId, PersonId targetPersonId)
1377 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);
1378 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1380 int ret = contacts_person_link_person(targetPersonId, sourcePersonId);
1381 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1382 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1388 _AddressbookManagerImpl::UnlinkContact(PersonId personId, RecordId contactId, PersonId& newPersonId)
1390 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);
1391 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1393 int ret = contacts_person_unlink_contact(personId, contactId, &newPersonId);
1394 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));
1395 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1401 _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount)
1403 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1407 IList* pList = null;
1408 bool ascending = false;
1409 unsigned int viewSortPropertyId = 0;
1411 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1412 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1414 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);
1416 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1418 viewSortPropertyId = _AddressbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1419 ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1424 case AB_FI_TYPE_ADDRESSBOOK:
1426 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
1428 __Filter<__ContactsAddressbook> abFilter;
1429 abFilter.Construct(filterHandle);
1431 __Filter<__ContactsAddressbook> mainFilter;
1432 mainFilter.Construct();
1434 mainFilter.AddFilter(*pRwAbFilter);
1435 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1436 mainFilter.AddFilter(abFilter);
1438 __Query<__ContactsAddressbook> query;
1440 query.SetFilter(mainFilter);
1442 if (viewSortPropertyId != 0)
1444 query.SetSort(viewSortPropertyId, ascending);
1447 pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
1450 case AB_FI_TYPE_PERSON:
1452 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1454 __Filter<__ContactsPersonGroupRel> personFilter;
1455 personFilter.Construct(filterHandle);
1457 __Filter<__ContactsPersonGroupRel> mainFilter;
1458 mainFilter.Construct();
1460 mainFilter.AddFilter(*pRwAbFilter);
1461 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1462 mainFilter.AddFilter(personFilter);
1464 unsigned int propertyIds[] =
1465 { _contacts_person_grouprel.person_id,
1466 _contacts_person_grouprel.addressbook_ids,
1467 _contacts_person_grouprel.is_favorite,
1468 _contacts_person_grouprel.has_phonenumber,
1469 _contacts_person_grouprel.has_email,
1470 _contacts_person_grouprel.image_thumbnail_path,
1471 _contacts_person_grouprel.ringtone_path,
1472 _contacts_person_grouprel.display_name
1475 __Query<__ContactsPersonGroupRel> query;
1477 query.SetFilter(mainFilter);
1478 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1479 query.SetDistinct(true);
1481 if (viewSortPropertyId != 0)
1483 query.SetSort(viewSortPropertyId, ascending);
1486 pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
1489 case AB_FI_TYPE_CONTACT:
1491 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1493 __Filter<__ContactsContact> contactFilter;
1494 contactFilter.Construct(filterHandle);
1496 __Filter<__ContactsContact> mainFilter;
1497 mainFilter.Construct();
1499 mainFilter.AddFilter(*pRwAbFilter);
1500 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1501 mainFilter.AddFilter(contactFilter);
1503 __Query<__ContactsContact> query;
1505 query.SetFilter(mainFilter);
1507 if (viewSortPropertyId != 0)
1509 query.SetSort(viewSortPropertyId, ascending);
1512 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
1515 case AB_FI_TYPE_CATEGORY:
1517 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1519 __Filter<__ContactsGroup> groupFilter;
1520 groupFilter.Construct(filterHandle);
1522 __Filter<__ContactsGroup> mainFilter;
1523 mainFilter.Construct();
1525 mainFilter.AddFilter(*pRwAbFilter);
1526 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1527 mainFilter.AddFilter(groupFilter);
1529 __Query<__ContactsGroup> query;
1531 query.SetFilter(mainFilter);
1533 if (viewSortPropertyId != 0)
1535 query.SetSort(viewSortPropertyId, ascending);
1538 pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
1541 case AB_FI_TYPE_PHONE_CONTACT:
1543 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
1545 __Filter<__ContactsContactNumber> numberFilter;
1546 numberFilter.Construct(filterHandle);
1548 __Filter<__ContactsContactNumber> mainFilter;
1549 mainFilter.Construct();
1551 mainFilter.AddFilter(*pRwAbFilter);
1552 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1553 mainFilter.AddFilter(numberFilter);
1555 __Query<__ContactsContactNumber> query;
1557 query.SetFilter(mainFilter);
1559 if (viewSortPropertyId != 0)
1561 query.SetSort(viewSortPropertyId, ascending);
1564 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
1567 case AB_FI_TYPE_EMAIL_CONTACT:
1569 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
1571 __Filter<__ContactsContactEmail> emailFilter;
1572 emailFilter.Construct(filterHandle);
1574 __Filter<__ContactsContactEmail> mainFilter;
1575 mainFilter.Construct();
1577 mainFilter.AddFilter(*pRwAbFilter);
1578 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1579 mainFilter.AddFilter(emailFilter);
1581 __Query<__ContactsContactEmail> query;
1583 query.SetFilter(mainFilter);
1585 if (viewSortPropertyId != 0)
1587 query.SetSort(viewSortPropertyId, ascending);
1590 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
1594 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The filter type is invalid", GetErrorMessage(E_INVALID_ARG));
1602 _AddressbookManagerImpl::GetMatchedItemCount(const AddressbookFilter& filter)
1604 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1609 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1610 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1614 case AB_FI_TYPE_ADDRESSBOOK:
1616 unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
1618 __Filter<__ContactsAddressbook> abFilter;
1619 abFilter.Construct(filterHandle);
1621 __Filter<__ContactsAddressbook> mainFilter;
1622 mainFilter.Construct();
1623 mainFilter.AddFilter(*pRwAbFilter);
1624 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1625 mainFilter.AddFilter(abFilter);
1627 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(mainFilter.Get());
1630 case AB_FI_TYPE_PERSON:
1632 unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
1634 __Filter<__ContactsPersonGroupRel> personFilter;
1635 personFilter.Construct(filterHandle);
1637 __Filter<__ContactsPersonGroupRel> mainFilter;
1638 mainFilter.Construct();
1639 mainFilter.AddFilter(*pRwAbFilter);
1640 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1641 mainFilter.AddFilter(personFilter);
1643 unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
1645 __Query<__ContactsPersonGroupRel> query;
1647 query.SetFilter(mainFilter);
1648 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1649 query.SetDistinct(true);
1651 count = _AddressbookUtil::GetCountWithQuery(query);
1655 case AB_FI_TYPE_CONTACT:
1657 unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
1659 __Filter<__ContactsContact> contactFilter;
1660 contactFilter.Construct(filterHandle);
1662 __Filter<__ContactsContact> mainFilter;
1663 mainFilter.Construct();
1664 mainFilter.AddFilter(*pRwAbFilter);
1665 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1666 mainFilter.AddFilter(contactFilter);
1668 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(mainFilter.Get());
1671 case AB_FI_TYPE_CATEGORY:
1673 unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
1675 __Filter<__ContactsGroup> groupFilter;
1676 groupFilter.Construct(filterHandle);
1678 __Filter<__ContactsGroup> mainFilter;
1679 mainFilter.Construct();
1680 mainFilter.AddFilter(*pRwAbFilter);
1681 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1682 mainFilter.AddFilter(groupFilter);
1684 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(mainFilter.Get());
1687 case AB_FI_TYPE_PHONE_CONTACT:
1689 unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
1691 __Filter<__ContactsContactNumber> numberFilter;
1692 numberFilter.Construct(filterHandle);
1694 __Filter<__ContactsContactNumber> mainFilter;
1695 mainFilter.Construct();
1696 mainFilter.AddFilter(*pRwAbFilter);
1697 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1698 mainFilter.AddFilter(numberFilter);
1700 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(mainFilter.Get());
1703 case AB_FI_TYPE_EMAIL_CONTACT:
1705 unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
1707 __Filter<__ContactsContactEmail> emailFilter;
1708 emailFilter.Construct(filterHandle);
1710 __Filter<__ContactsContactEmail> mainFilter;
1711 mainFilter.Construct();
1712 mainFilter.AddFilter(*pRwAbFilter);
1713 mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
1714 mainFilter.AddFilter(emailFilter);
1716 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(mainFilter.Get());
1720 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter is invalid", GetErrorMessage(GetLastResult()));
1728 _AddressbookManagerImpl::OnEachContact(contacts_record_h recordHandle, void* pUserData)
1730 IList* pList = static_cast<IList*>(pUserData);
1734 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
1735 SysTryReturn(NID_SCL, pContact != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1737 contacts_record_h newRecordHandle = null;
1739 contacts_record_clone(recordHandle, &newRecordHandle);
1740 SysTryReturn(NID_SCL, newRecordHandle != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1742 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecordHandle);
1744 result r = pList->Add(*pContact);
1745 SysTryReturn(NID_SCL, !IsFailed(r), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1753 _AddressbookManagerImpl::ParseContactsFromVcardN(const Tizen::Base::String& vcardPath)
1755 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1760 result r = file.Construct(vcardPath, "r");
1761 SysTryReturn(NID_SCL, r != E_INVALID_ARG, null, E_INVALID_ARG, "[%s] Invalid argument is used..", GetErrorMessage(E_INVALID_ARG));
1762 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));
1763 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));
1764 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1766 unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1768 unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(vcardPath));
1770 int ret = contacts_vcard_parse_to_contact_foreach(pCharArray.get(), OnEachContact, pList.get());
1771 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1772 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1773 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1775 return pList.release();
1779 _AddressbookManagerImpl::ExportPersonToVcard(const Person& person, const Tizen::Base::String& vcardPath)
1781 bool exist = File::IsFileExist(vcardPath);
1782 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
1783 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
1784 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1787 result r = file.Construct(vcardPath, "w");
1788 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));
1789 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1790 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1792 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
1793 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1795 char* pVcardStream = null;
1796 int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
1797 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));
1798 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1800 r = file.Write(pVcardStream, strlen(pVcardStream));
1802 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1803 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1809 _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::IList& personList, const Tizen::Base::String& vcardPath)
1811 bool exist = File::IsFileExist(vcardPath);
1812 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
1813 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
1814 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1816 int ret = CONTACTS_ERROR_NONE;
1817 char* pVcardStream = null;
1820 result r = file.Construct(vcardPath, "w");
1821 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));
1822 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1823 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1826 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
1828 unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
1829 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1831 while (pEnum->MoveNext() == E_SUCCESS)
1833 Person* pPerson = static_cast<Person*>(pEnum->GetCurrent());
1835 pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
1836 SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1838 ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
1839 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));
1840 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1842 r = file.Write(pVcardStream, strlen(pVcardStream));
1844 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1845 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1852 _AddressbookManagerImpl::ExportContactToVcard(const Contact& contact, const Tizen::Base::String& vcardPath)
1854 bool exist = File::IsFileExist(vcardPath);
1855 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
1856 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
1857 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1860 result r = file.Construct(vcardPath, "w");
1861 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));
1862 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1863 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1865 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
1867 char* pVcardStream = null;
1869 int ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
1870 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));
1871 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1873 r = file.Write(pVcardStream, strlen(pVcardStream));
1875 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1876 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1882 _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IList& contactList, const Tizen::Base::String& vcardPath)
1884 bool exist = File::IsFileExist(vcardPath);
1885 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
1886 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
1887 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1889 int ret = CONTACTS_ERROR_NONE;
1890 char* pVcardStream = null;
1892 Contact* pContact = null;
1894 result r = file.Construct(vcardPath, "w");
1895 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));
1896 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1897 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1899 contacts_record_h recordHandle = null;
1901 unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
1902 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1904 while (pEnum->MoveNext() == E_SUCCESS)
1906 pContact = static_cast<Contact*>(pEnum->GetCurrent());
1908 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1910 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
1911 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));
1912 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1914 r = file.Write(pVcardStream, strlen(pVcardStream));
1916 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1917 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1924 _AddressbookManagerImpl::ExportContactToVcardStreamN(const Contact& contact)
1926 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1930 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
1932 char* pVcardStream = null;
1933 int ret = CONTACTS_ERROR_NONE;
1935 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
1936 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1937 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1938 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1940 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
1941 if (pByteBuffer == null)
1944 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1949 result r = pByteBuffer->Construct(strlen(pVcardStream));
1953 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1958 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
1960 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1961 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1963 return pByteBuffer.release();
1967 _AddressbookManagerImpl::ExportContactsToVcardStreamN(const Tizen::Base::Collection::IList& contactList)
1969 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1973 char* pVcardStream = null;
1974 int ret = CONTACTS_ERROR_NONE;
1975 Contact* pContact = null;
1976 result r = E_SUCCESS;
1979 contacts_record_h recordHandle = null;
1981 unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
1982 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1984 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
1985 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1987 r = pByteBuffer->Construct(capacity);
1988 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1990 if (contactList.GetCount() == 0)
1992 return pByteBuffer.release();
1995 while (pEnum->MoveNext() == E_SUCCESS)
1997 pContact = static_cast<Contact*>(pEnum->GetCurrent());
1999 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
2001 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
2002 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2003 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2004 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2006 capacity += strlen(pVcardStream);
2007 r = pByteBuffer->ExpandCapacity(capacity);
2011 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2016 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2018 pVcardStream = null;
2019 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2022 return pByteBuffer.release();
2026 _AddressbookManagerImpl::ExportPersonToVcardStreamN(const Person& person)
2028 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2032 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
2033 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2034 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2036 char* pVcardStream = null;
2037 int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2038 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2039 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2040 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2042 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2043 if (pByteBuffer == null)
2046 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2051 result r = pByteBuffer->Construct(strlen(pVcardStream));
2055 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2060 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2062 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2064 return pByteBuffer.release();
2068 _AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collection::IList& personList)
2070 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2074 int ret = CONTACTS_ERROR_NONE;
2075 Person* pPerson = null;
2076 char* pVcardStream = null;
2080 unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
2082 unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
2083 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2085 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2086 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2088 result r = pByteBuffer->Construct(capacity);
2089 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2091 if (personList.GetCount() == 0)
2093 return pByteBuffer.release();
2096 while (pEnum->MoveNext() == E_SUCCESS)
2098 pPerson = static_cast<Person*>(pEnum->GetCurrent());
2100 pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
2101 SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2102 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
2104 ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
2105 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2106 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2107 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2109 capacity += strlen(pVcardStream);
2110 r = pByteBuffer->ExpandCapacity(capacity);
2114 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2119 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2121 pVcardStream = null;
2122 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2125 return pByteBuffer.release();
2129 _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardStream)
2131 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2135 contacts_list_h listHandle = null;
2136 result r = E_SUCCESS;
2138 int ret = contacts_vcard_parse_to_contacts(reinterpret_cast<char*>(const_cast<byte*>(vcardStream.GetPointer())), &listHandle);
2139 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2140 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2142 unsigned int count = 0;
2143 contacts_record_h recordHandle = null;
2144 contacts_list_get_count(listHandle, &count);
2146 unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
2149 contacts_list_destroy(listHandle, true);
2150 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2155 r = pList->Construct(count);
2158 contacts_list_destroy(listHandle, true);
2159 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2164 for (unsigned int i = 0; i < count; i++)
2166 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
2167 if (pContact == null)
2169 contacts_list_destroy(listHandle, true);
2170 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2175 r = pList->Add(pContact.get());
2178 contacts_list_destroy(listHandle, true);
2179 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2187 unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2189 while (pEnum->MoveNext() == E_SUCCESS)
2191 Contact* pContact = static_cast <Contact*> (pEnum->GetCurrent());
2193 contacts_list_get_current_record_p(listHandle, &recordHandle);
2194 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(recordHandle);
2196 ret = contacts_list_next(listHandle);
2199 contacts_list_destroy(listHandle, false);
2201 return pList.release();
2205 _AddressbookManagerImpl::ExportUserProfileToVcardStreamN(const UserProfile& userProfile)
2207 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2211 char* pVcardStream = null;
2212 int ret = CONTACTS_ERROR_NONE;
2213 contacts_record_h recordHandle = null;
2215 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2217 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2218 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2219 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2220 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2222 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2223 if (pByteBuffer == null)
2226 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2230 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2232 result r = pByteBuffer->Construct(strlen(pVcardStream));
2236 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2241 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2243 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2244 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2246 return pByteBuffer.release();
2250 _AddressbookManagerImpl::ExportUserProfilesToVcardStreamN(const Tizen::Base::Collection::IList& userProfileList)
2252 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2256 char* pVcardStream = null;
2257 int ret = CONTACTS_ERROR_NONE;
2258 UserProfile* pProfile = null;
2259 result r = E_SUCCESS;
2262 unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2263 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2265 unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2266 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2268 r = pByteBuffer->Construct(capacity);
2269 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2271 if (userProfileList.GetCount() == 0)
2273 return pByteBuffer.release();
2276 while (pEnum->MoveNext() == E_SUCCESS)
2278 contacts_record_h recordHandle = null;
2280 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2282 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2284 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2285 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2286 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2287 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2289 capacity += strlen(pVcardStream);
2290 r = pByteBuffer->ExpandCapacity(capacity);
2294 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2299 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2301 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2304 return pByteBuffer.release();
2308 _AddressbookManagerImpl::ExportUserProfileToVcard(const UserProfile& userProfile, const Tizen::Base::String& vcardPath)
2310 bool exist = File::IsFileExist(vcardPath);
2311 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2312 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2313 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2316 result r = file.Construct(vcardPath, "w");
2317 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));
2318 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2319 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2321 char* pVcardStream = null;
2322 contacts_record_h recordHandle = null;
2324 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2326 int ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2327 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));
2328 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2330 r = file.Write(pVcardStream, strlen(pVcardStream));
2332 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2333 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2339 _AddressbookManagerImpl::ExportUserProfilesToVcard(const Tizen::Base::Collection::IList& userProfileList, const Tizen::Base::String& vcardPath)
2341 bool exist = File::IsFileExist(vcardPath);
2342 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2343 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2344 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2346 int ret = CONTACTS_ERROR_NONE;
2347 char* pVcardStream = null;
2349 UserProfile* pProfile = null;
2351 result r = file.Construct(vcardPath, "w");
2352 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));
2353 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2354 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2356 unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2357 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2359 while (pEnum->MoveNext() == E_SUCCESS)
2361 contacts_record_h recordHandle = null;
2363 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2365 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2367 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2368 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));
2369 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2371 r = file.Write(pVcardStream, strlen(pVcardStream));
2373 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2374 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2381 _AddressbookManagerImpl::GetAllUserProfilesN(void) const
2383 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2387 unique_ptr< __Filter<__ContactsUserProfile> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsUserProfile>());
2388 SysTryReturn(NID_SCL, pRwAbFilter != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2390 __Query<__ContactsUserProfile> query2;
2392 query2.SetFilter(*pRwAbFilter);
2393 query2.SetSort(_contacts_my_profile.display_name, true);
2395 IList* pUserProfilesList = _AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query2);
2396 SysTryReturn(NID_SCL, pUserProfilesList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2398 return pUserProfilesList;
2402 _AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
2404 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2405 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. Addressbook Id(%d).", GetErrorMessage(E_INVALID_ARG), addressbookId);
2410 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
2411 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2413 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &mode);
2414 SysTryReturn(NID_SCL, mode == 0, null, E_OBJ_NOT_FOUND, "[%s] The addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
2416 __Filter<__ContactsUserProfile> filter;
2418 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, addressbookId);
2420 __Query<__ContactsUserProfile> query;
2422 query.SetFilter(filter);
2424 unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
2425 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2426 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
2427 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
2429 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
2430 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
2435 _AddressbookManagerImpl*
2436 _AddressbookManagerImpl::GetInstance(AddressbookManager& addressbookManager)
2438 return addressbookManager.__pAddressbookManagerImpl;
2441 const _AddressbookManagerImpl*
2442 _AddressbookManagerImpl::GetInstance(const AddressbookManager& addressbookManager)
2444 return addressbookManager.__pAddressbookManagerImpl;