2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FScl_AddressbookManagerImpl.cpp
19 * @brief This is the implementation for _AddressbookManagerImpl class.
21 * This file contains definitions of @e _AddressbookManagerImpl class.
24 #include <unique_ptr.h>
25 #include <FBaseColIListT.h>
26 #include <FBaseColArrayListT.h>
27 #include <FBaseColHashMapT.h>
28 #include <FBaseResult.h>
29 #include <FBaseLongLong.h>
30 #include <FBaseInteger.h>
32 #include <FSclAddressbook.h>
33 #include <FSclAddressbookManager.h>
34 #include <FSclIAddressbookChangeEventListener.h>
35 #include <FSclContact.h>
36 #include <FSclCategory.h>
37 #include <FSclUserProfile.h>
38 #include <FSclContactChangeInfo.h>
39 #include <FSclCategoryChangeInfo.h>
40 #include <FSclPerson.h>
41 #include <FSclPhoneNumberContact.h>
42 #include <FScl_PhoneNumberContactImpl.h>
43 #include <FSclEmailContact.h>
44 #include <FScl_EmailContactImpl.h>
45 #include <FSclAddressbookFilter.h>
46 #include <FSclIAddressbookEventListener.h>
47 #include <FSclIRecordEventListener.h>
48 #include <FBaseSysLog.h>
49 #include <FApp_AppInfo.h>
50 #include <FBase_StringConverter.h>
51 #include "FScl_AddressbookImpl.h"
52 #include "FScl_AddressbookFilterImpl.h"
53 #include "FScl_AddressbookManagerImpl.h"
54 #include "FScl_AddressbookUtil.h"
55 #include "FScl_RecordImpl.h"
56 #include "FScl_ContactImpl.h"
57 #include "FScl_CategoryImpl.h"
58 #include "FScl_PersonImpl.h"
59 #include "FScl_AddressbookUtil.h"
60 #include "FScl_ContactChangeInfoImpl.h"
61 #include "FScl_CategoryChangeInfoImpl.h"
62 #include "FScl_ContactDbMonitor.h"
63 #include "FScl_ContactDbConnector.h"
64 #include "FScl_UserProfileImpl.h"
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));
203 result r = E_SUCCESS;
204 int ret = CONTACTS_ERROR_NONE;
206 contacts_record_h addressbookHandle = null;
208 std::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 std::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 ret = contacts_record_create(_contacts_address_book._uri, &addressbookHandle);
234 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
235 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
237 __ContactsRecordHandle recordHandle(addressbookHandle);
239 contacts_record_set_str(addressbookHandle, _contacts_address_book.name, pNameString.get());
240 contacts_record_set_int(addressbookHandle, _contacts_address_book.account_id, accountId);
242 ret = contacts_db_insert_record(addressbookHandle, &recordId);
243 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
244 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
245 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
247 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(accountId);
248 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(name);
249 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(recordId);
251 return pAddressbook.release();
255 _AddressbookManagerImpl::DeleteAddressbook(AddressbookId addressbookId)
257 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));
258 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
260 int ret = contacts_db_delete_record(_contacts_address_book._uri, addressbookId);
261 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));
262 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));
263 // SysTryReturnResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OPERATION_FAILED, "Failed to delete an addressbook.(%d)", ret); // temp
269 _AddressbookManagerImpl::GetAddressbooksByAccountN(AccountId accountId) const
271 SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. accountId = %d.", GetErrorMessage(E_INVALID_ARG), accountId);
272 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
274 __Filter<__ContactsAddressbook> filter;
276 filter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
278 __Query<__ContactsAddressbook> query;
280 query.SetFilter(filter);
282 IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
283 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
285 return pAddressbooks;
289 _AddressbookManagerImpl::GetAllAddressbooksN(void) const
291 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
293 __Query<__ContactsAddressbook> query;
295 query.SetSort(_contacts_address_book.name, true);
297 IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
298 SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
300 return pAddressbooks;
304 _AddressbookManagerImpl::GetAddressbookN(AddressbookId addressbookId) const
306 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. addressbookId.", GetErrorMessage(E_INVALID_ARG), addressbookId);
307 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
309 result r = E_SUCCESS;
310 int ret = CONTACTS_ERROR_NONE;
311 contacts_record_h addressbookHandle = null;
313 char* pCharValue = null;
315 std::unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
316 SysTryReturn(NID_SCL, pAddressbook !=null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
318 r = pAddressbook->Construct();
319 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
322 ret = contacts_db_get_record(_contacts_address_book._uri, addressbookId, &addressbookHandle);
323 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
324 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The addressbook %d is not found.", GetErrorMessage(E_OBJ_NOT_FOUND), addressbookId);
325 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred. Addressbook Id(%d)", GetErrorMessage(E_SYSTEM), addressbookId);
327 _AddressbookImpl::GetInstance(*pAddressbook)->SetId(addressbookId);
329 contacts_record_get_int(addressbookHandle, _contacts_address_book.account_id, &intValue);
330 _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
332 contacts_record_get_str_p(addressbookHandle, _contacts_address_book.name, &pCharValue);
333 _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
335 contacts_record_destroy(addressbookHandle, true);
337 return pAddressbook.release();
341 _AddressbookManagerImpl::AddContact(Contact& contact, AddressbookId addressbookId)
343 if (_ContactImpl::GetInstance(contact)->IsRemoved())
345 result r = _ContactImpl::GetInstance(contact)->Invalidate();
346 SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
349 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));
350 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));
351 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
355 contacts_record_h recordHandle = null;
357 int ret = contacts_db_get_record(_contacts_address_book._uri, addressbookId, &recordHandle);
358 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));
359 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));
360 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
362 contacts_record_destroy(recordHandle, true);
364 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
366 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, addressbookId);
368 ret = contacts_db_insert_record(recordHandle, &recordId);
369 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));
370 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
371 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
373 ret = contacts_db_get_record(_contacts_contact._uri, recordId, &recordHandle);
374 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));
375 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));
376 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A sytem error has been occurred.", GetErrorMessage(E_SYSTEM));
378 _ContactImpl::GetInstance(contact)->SetContactRecordHandle(recordHandle);
379 _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()));
392 contacts_record_h recordHandle = null;
393 std::unique_ptr<IListT<int> > pList(null);
395 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
397 contacts_record_set_int(recordHandle, _contacts_group.address_book_id, addressbookId);
399 int ret = contacts_db_insert_record(recordHandle, &recordId);
400 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));
401 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
402 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
404 ret = contacts_db_get_record(_contacts_group._uri, recordId, &recordHandle);
405 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));
406 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));
407 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A sytem error has been occurred.", GetErrorMessage(E_SYSTEM));
409 _CategoryImpl::GetInstance(category)->SetRecordHandle(recordHandle);
410 _RecordImpl::GetInstance(category)->SetRecordId(recordId);
412 pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
413 if (pList != null && pList->GetCount() > 0)
415 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
417 while (pEnum->MoveNext() == E_SUCCESS)
420 pEnum->GetCurrent(tableId);
422 AddMemberToCategory(category.GetRecordId(), tableId);
425 _CategoryImpl::GetInstance(category)->ClearAddedMemberList();
433 _AddressbookManagerImpl::RemoveContact(RecordId contactId)
435 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));
436 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
438 contacts_record_h recordHandle = null;
441 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
442 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));
443 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));
444 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
446 contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
448 contacts_record_destroy(recordHandle, true);
449 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
451 ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
452 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));
453 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));
454 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
460 _AddressbookManagerImpl::RemoveCategory(RecordId categoryId)
462 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);
463 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
466 int ret = CONTACTS_ERROR_NONE;
467 contacts_record_h recordHandle = null;
469 ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
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 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));
472 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
474 __ContactsRecordHandle categoryHandle(recordHandle);
476 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
477 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
479 bool isReadOnly = false;
480 contacts_record_get_bool(recordHandle, _contacts_group.is_read_only, &isReadOnly);
481 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));
483 ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
484 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));
485 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));
486 // SysTryReturnResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OPERATION_FAILED, "Failed to delete a category.(%d)", ret); // temp
492 _AddressbookManagerImpl::UpdateContact(const Contact& contact)
494 RecordId contactId = contact.GetRecordId();
495 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));
496 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));
497 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
499 contacts_record_h recordHandle = null;
502 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
503 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));
504 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));
505 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
507 contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
509 contacts_record_destroy(recordHandle, true);
510 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
512 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
514 ret = contacts_db_update_record(recordHandle);
515 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));
516 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
517 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));
519 ret = contacts_db_get_record(_contacts_contact._uri, contact.GetRecordId(), &recordHandle);
520 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));
521 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));
522 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
524 _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(recordHandle);
530 _AddressbookManagerImpl::UpdateCategory(const Category& category)
532 RecordId categoryId = category.GetRecordId();
533 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));
534 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));
535 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
537 contacts_record_h recordHandle = null;
540 int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
541 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));
542 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The specified category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
544 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
546 contacts_record_destroy(recordHandle, true);
547 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
549 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
551 ret = contacts_db_update_record(recordHandle);
552 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));
553 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
554 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
556 ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
557 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The category is not found.");
558 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));
559 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
561 _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(recordHandle);
563 std::unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
564 if (pList != null && pList->GetCount() > 0)
567 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
568 while (pEnum->MoveNext() == E_SUCCESS)
570 pEnum->GetCurrent(tableId);
572 AddMemberToCategory(category.GetRecordId(), tableId);
575 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList();
578 pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN());
579 if (pList != null && pList->GetCount() > 0)
582 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
583 while (pEnum->MoveNext() == E_SUCCESS)
585 pEnum->GetCurrent(tableId);
587 RemoveMemberFromCategory(category.GetRecordId(), tableId);
590 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList();
598 _AddressbookManagerImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
601 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);
602 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);
603 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
605 int ret = contacts_group_add_contact(categoryId, contactId);
606 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
607 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));
608 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
614 _AddressbookManagerImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
617 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);
618 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);
619 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
621 int ret = contacts_group_remove_contact(categoryId, contactId);
622 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
623 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));
624 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
630 _AddressbookManagerImpl::GetAllCategoriesN(void) const
632 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
636 __Query<__ContactsGroup> query;
638 query.SetSort(_contacts_group.name, true);
640 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
641 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
647 _AddressbookManagerImpl::GetCategoriesByContactN(RecordId contactId) const
649 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
650 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));
654 __Filter<__ContactsGroupRelation> filter;
656 filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
658 __Query<__ContactsGroupRelation> query;
660 query.SetFilter(filter);
662 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query);
663 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
669 _AddressbookManagerImpl::GetCategoriesByPersonN(PersonId personId) const
671 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
675 __Filter<__ContactsContactGroupRel> filter;
677 filter.AddInt(_contacts_contact_grouprel.person_id, CONTACTS_MATCH_EQUAL, personId);
678 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
679 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_GREATER_THAN, 0);
681 unsigned int propertyIds[] =
683 _contacts_contact_grouprel.group_id,
686 __Query<__ContactsContactGroupRel> query;
688 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
689 query.SetFilter(filter);
690 query.SetSort(_contacts_contact_grouprel.group_name, true);
691 query.SetDistinct(true);
693 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
694 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
700 _AddressbookManagerImpl::GetAllContactsN(void) const
702 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
706 __Query<__ContactsContact> query;
708 query.SetSort(_contacts_contact.display_name, true);
710 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
711 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
717 _AddressbookManagerImpl::GetContactsByCategoryN(RecordId categoryId) const
719 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));
720 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
724 __Filter<__ContactsContactGroupRel> filter;
727 if (categoryId != INVALID_RECORD_ID)
729 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
733 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
736 __Query<__ContactsContactGroupRel> query;
738 query.SetFilter(filter);
741 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
742 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
748 _AddressbookManagerImpl::GetContactsByPersonN(PersonId personId) const
750 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
754 __Filter<__ContactsContact> filter;
756 filter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
758 __Query<__ContactsContact> query;
760 query.SetFilter(filter);
761 query.SetSort(_contacts_contact.display_name, true);
763 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
764 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
770 _AddressbookManagerImpl::SearchContactsByEmailN(const String& email) const
772 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));
773 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
777 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
778 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
780 __Filter<__ContactsContactEmail> filter;
782 filter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
784 __Query<__ContactsContactEmail> query;
786 query.SetFilter(filter);
787 query.SetSort(_contacts_contact_email.display_name, true);
789 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
790 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
797 _AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
799 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
803 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));
805 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
806 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
808 __Filter<__ContactsContact> filter;
810 filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
812 __Query<__ContactsContact> query;
814 query.SetFilter(filter);
815 query.SetSort(_contacts_contact.display_name, true);
817 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
818 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
824 _AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
826 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
830 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));
832 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
833 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
835 __Filter<__ContactsContactNumber> filter;
837 filter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
839 __Query<__ContactsContactNumber> query;
841 query.SetFilter(filter);
842 query.SetDistinct(true);
843 query.SetSort(_contacts_contact_number.display_name, true);
845 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
846 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
852 _AddressbookManagerImpl::GetCategoryCount(void) const
854 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
860 count = _AddressbookUtil::GetCount<__ContactsGroup>();
861 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
867 _AddressbookManagerImpl::GetContactCount(void) const
869 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
875 count = _AddressbookUtil::GetCount<__ContactsContact>();
876 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
882 _AddressbookManagerImpl::GetContactN(RecordId contactId) const
884 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
886 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
889 contacts_record_h contactHandle = null;
891 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
892 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
894 int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &contactHandle);
895 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
896 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
897 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
899 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle);
901 contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue);
902 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
904 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
906 return pContact.release();
910 _AddressbookManagerImpl::GetPersonN(PersonId personId) const
912 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
914 SysTryReturn(NID_SCL, personId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
916 contacts_record_h recordHandle = null;
919 int ret = contacts_db_get_record(_contacts_person._uri, personId, &recordHandle);
920 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
921 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
922 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
924 __ContactsRecordHandle personRecord(recordHandle);
926 contacts_record_get_int(recordHandle, _contacts_person.id, &intValue);
927 SysTryReturn(NID_SCL, intValue == personId, null, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
929 Person* pPerson = __ContactsPerson::ConvertHandleTo<Person>(recordHandle);
930 SysTryReturn(NID_SCL, pPerson != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
936 _AddressbookManagerImpl::GetCategoryN(RecordId categoryId) const
938 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. categoryId = %d.", categoryId);
939 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
942 contacts_record_h recordHandle = null;
946 int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
947 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
948 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
949 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
952 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
954 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
955 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
957 SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
959 __Filter<__ContactsGroupRelation> filter;
961 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
963 __Query<__ContactsGroupRelation> query;
965 query.SetFilter(filter);
967 int count = _AddressbookUtil::GetCountWithQuery(query);
968 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
970 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(recordHandle);
971 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
972 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
974 return pCategory.release();
978 _AddressbookManagerImpl::GetLatestVersion(void) const
980 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
982 int latestVersion = -1;
986 int ret = contacts_db_get_current_version(&latestVersion);
987 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
989 return latestVersion;
993 _AddressbookManagerImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
995 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);
996 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
999 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion);
1000 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1002 return pChangedContacts;
1006 _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1008 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);
1009 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1013 int latestVersion1 = 0;
1014 int latestVersion2 = 0;
1016 std::unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion1));
1017 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1019 std::unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion2));
1020 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1022 std::unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1023 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1025 result r = pChangeList->AddItems(*pChangedGroups);
1026 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1028 r = pChangeList->AddItems(*pChangedRelations);
1029 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1031 pChangedGroups->RemoveAll(false);
1032 pChangedRelations->RemoveAll(false);
1034 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1036 return pChangeList.release();
1041 _AddressbookManagerImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1043 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);
1044 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1048 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion);
1049 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1051 return pChangedRelations;
1055 _AddressbookManagerImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1057 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);
1058 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1062 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion);
1063 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1065 return pChangedRelations;
1069 _AddressbookManagerImpl::OnContactChanged(void)
1071 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1076 IList* pChangedContactList = GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact);
1077 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1079 if (pChangedContactList->GetCount() > 0)
1081 if (__pIAddressbookChangeEventListener != null)
1083 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1087 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1091 pChangedContactList->RemoveAll(true);
1092 delete pChangedContactList;
1096 _AddressbookManagerImpl::OnCategoryChanged(void)
1098 if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1103 IList* pChangedCategoryList = GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup);
1104 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1106 if (pChangedCategoryList->GetCount() > 0)
1108 if (__pIAddressbookChangeEventListener != null)
1110 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1114 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1118 pChangedCategoryList->RemoveAll(true);
1119 delete pChangedCategoryList;
1123 _AddressbookManagerImpl::OnRelationChanged(void)
1125 if (__pIAddressbookEventListener == null)
1130 IList* pChangedCategoryList = GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation);
1131 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1133 if (pChangedCategoryList->GetCount() > 0)
1135 if (__pIAddressbookEventListener != null)
1137 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1141 pChangedCategoryList->RemoveAll(true);
1142 delete pChangedCategoryList;
1146 _AddressbookManagerImpl::RemovePerson(PersonId personId)
1148 SysTryReturnResult(NID_SCL, personId > 0, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1149 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1151 contacts_record_h recordHandle = null;
1153 int ret = contacts_db_get_record(_contacts_person._uri, personId, &recordHandle);
1154 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1155 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));
1156 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));
1158 contacts_record_destroy(recordHandle, true);
1160 ret = contacts_db_delete_record(_contacts_person._uri, personId);
1161 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.");
1162 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));
1163 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));
1169 _AddressbookManagerImpl::GetAllPersonsN(void) const
1171 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1175 __Query<__ContactsPerson> query;
1177 query.SetSort(_contacts_person.display_name, true);
1179 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPerson, Person>(query);
1180 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1186 _AddressbookManagerImpl::GetPersonsByCategoryN(RecordId categoryId) const
1188 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));
1189 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1193 __Filter<__ContactsPersonGroupRel> filter;
1195 if (categoryId != INVALID_RECORD_ID)
1197 filter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1201 filter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
1204 unsigned int propertyIds[] =
1206 _contacts_person_grouprel.person_id,
1207 _contacts_person_grouprel.display_name,
1208 _contacts_person_grouprel.image_thumbnail_path,
1209 _contacts_person_grouprel.ringtone_path,
1210 _contacts_person_grouprel.is_favorite,
1211 _contacts_person_grouprel.has_phonenumber,
1212 _contacts_person_grouprel.has_email,
1213 _contacts_person_grouprel.link_count,
1216 __Query<__ContactsPersonGroupRel> query;
1218 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1219 query.SetFilter(filter);
1220 query.SetSort(_contacts_person_grouprel.display_name, true);
1221 query.SetDistinct(true);
1223 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
1224 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1230 _AddressbookManagerImpl::GetFavoritePersonsN() const
1232 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1236 __Filter<__ContactsPerson> filter;
1238 filter.AddBool(_contacts_person.is_favorite, true);
1240 __Query<__ContactsPerson> query;
1242 query.SetFilter(filter);
1243 query.SetSort(_contacts_person.display_name, true);
1245 IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPerson, Person>(query);
1246 SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1252 _AddressbookManagerImpl::SearchPersonsN(const Tizen::Base::String& keyword) const
1254 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1255 SysTryReturn(NID_SCL, !keyword.IsEmpty(), null, E_INVALID_ARG, "Invalid argument is used. keyword is empty string.", GetErrorMessage(E_INVALID_ARG));
1257 contacts_record_h currentRecord = null;
1258 std::unique_ptr<Person> pPerson(null);
1260 std::unique_ptr<ArrayList, AllElementsDeleter> pPersonList(new (std::nothrow) ArrayList());
1261 SysTryReturn(NID_SCL, pPersonList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1263 result r = pPersonList->Construct();
1264 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1266 std::unique_ptr<__SearchResult<__ContactsPerson> > pSearchResult(_AddressbookUtil::Search<__ContactsPerson>(keyword));
1267 SysTryReturn(NID_SCL, pSearchResult != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1269 while (pSearchResult->MoveNext() == E_SUCCESS)
1271 currentRecord = pSearchResult->GetCurrentRecord();
1272 SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1274 pPerson.reset(__ContactsPerson::ConvertHandleTo<Person>(currentRecord));
1275 SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1277 r = pPersonList->Add(*pPerson);
1278 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
1283 return pPersonList.release();
1287 _AddressbookManagerImpl::SetPersonAsFavorite(PersonId personId, bool isFavorite)
1289 SysTryReturn(NID_SCL, personId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
1290 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1292 bool boolValue = false;
1293 contacts_record_h personHandle = null;
1295 int ret = contacts_db_get_record(_contacts_person._uri, personId, &personHandle);
1296 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));
1297 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1299 __ContactsRecordHandle recordHandle(personHandle);
1301 contacts_record_get_bool(personHandle, _contacts_person.is_favorite, &boolValue);
1303 if (boolValue != isFavorite)
1305 contacts_record_set_bool(personHandle, _contacts_person.is_favorite, isFavorite);
1307 ret = contacts_db_update_record(personHandle);
1308 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));
1309 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1316 _AddressbookManagerImpl::MergePersons(PersonId sourcePersonId, PersonId targetPersonId)
1318 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);
1319 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1321 int ret = contacts_person_link_person(targetPersonId, sourcePersonId);
1322 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1323 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1329 _AddressbookManagerImpl::UnlinkContact(PersonId personId, RecordId contactId, PersonId& newPersonId)
1331 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);
1332 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1334 int ret = contacts_person_unlink_contact(personId, contactId, &newPersonId);
1335 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));
1336 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1342 _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount)
1344 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1346 IList* pList = null;
1347 bool ascending = false;
1348 unsigned int viewSortPropertyId = 0;
1350 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1351 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1353 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);
1355 if (propertySortedBy != 0 && sortOrder != SORT_ORDER_NONE)
1357 viewSortPropertyId = _AddressbookFilterImpl::GetViewPropertyId(type, propertySortedBy);
1358 ascending = (sortOrder == SORT_ORDER_ASCENDING) ? true : false;
1363 case AB_FI_TYPE_ADDRESSBOOK:
1365 __Filter<__ContactsAddressbook> filter;
1366 filter.Construct(filterHandle);
1368 __Query<__ContactsAddressbook> query;
1370 query.SetFilter(filter);
1372 if (viewSortPropertyId != 0)
1374 query.SetSort(viewSortPropertyId, ascending);
1377 pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
1380 case AB_FI_TYPE_PERSON:
1382 __Filter<__ContactsPersonGroupRel> filter;
1383 filter.Construct(filterHandle);
1385 unsigned int propertyIds[] =
1386 { _contacts_person_grouprel.person_id,
1387 _contacts_person_grouprel.addressbook_ids,
1388 _contacts_person_grouprel.is_favorite,
1389 _contacts_person_grouprel.has_phonenumber,
1390 _contacts_person_grouprel.has_email,
1391 _contacts_person_grouprel.image_thumbnail_path,
1392 _contacts_person_grouprel.ringtone_path,
1393 _contacts_person_grouprel.display_name
1396 __Query<__ContactsPersonGroupRel> query;
1398 query.SetFilter(filter);
1399 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1400 query.SetDistinct(true);
1402 if (viewSortPropertyId != 0)
1404 query.SetSort(viewSortPropertyId, ascending);
1407 pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
1410 case AB_FI_TYPE_CONTACT:
1412 __Filter<__ContactsContact> filter;
1413 filter.Construct(filterHandle);
1415 __Query<__ContactsContact> query;
1417 query.SetFilter(filter);
1419 if (viewSortPropertyId != 0)
1421 query.SetSort(viewSortPropertyId, ascending);
1424 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
1427 case AB_FI_TYPE_CATEGORY:
1429 __Filter<__ContactsGroup> filter;
1430 filter.Construct(filterHandle);
1432 __Query<__ContactsGroup> query;
1434 query.SetFilter(filter);
1436 if (viewSortPropertyId != 0)
1438 query.SetSort(viewSortPropertyId, ascending);
1441 pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
1444 case AB_FI_TYPE_PHONE_CONTACT:
1446 __Filter<__ContactsContactNumber> filter;
1447 filter.Construct(filterHandle);
1449 __Query<__ContactsContactNumber> query;
1451 query.SetFilter(filter);
1453 if (viewSortPropertyId != 0)
1455 query.SetSort(viewSortPropertyId, ascending);
1458 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
1461 case AB_FI_TYPE_EMAIL_CONTACT:
1463 __Filter<__ContactsContactEmail> filter;
1464 filter.Construct(filterHandle);
1466 __Query<__ContactsContactEmail> query;
1468 query.SetFilter(filter);
1470 if (viewSortPropertyId != 0)
1472 query.SetSort(viewSortPropertyId, ascending);
1475 pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
1479 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The filter type is invalid", GetErrorMessage(E_INVALID_ARG));
1487 _AddressbookManagerImpl::GetMatchedItemCount(const AddressbookFilter& filter)
1489 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1492 AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
1493 contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
1497 case AB_FI_TYPE_ADDRESSBOOK:
1498 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(filterHandle);
1500 case AB_FI_TYPE_PERSON:
1502 __Filter<__ContactsPersonGroupRel> filter;
1503 filter.Construct(filterHandle);
1505 unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
1507 __Query<__ContactsPersonGroupRel> query;
1509 query.SetFilter(filter);
1510 query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
1511 query.SetDistinct(true);
1513 count = _AddressbookUtil::GetCountWithQuery(query);
1517 case AB_FI_TYPE_CONTACT:
1518 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(filterHandle);
1520 case AB_FI_TYPE_CATEGORY:
1521 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(filterHandle);
1523 case AB_FI_TYPE_PHONE_CONTACT:
1524 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(filterHandle);
1526 case AB_FI_TYPE_EMAIL_CONTACT:
1527 count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(filterHandle);
1530 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter is invalid", GetErrorMessage(GetLastResult()));
1538 _AddressbookManagerImpl::OnEachContact(contacts_record_h recordHandle, void* pUserData)
1540 IList* pList = static_cast<IList*>(pUserData);
1544 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
1545 SysTryReturn(NID_SCL, pContact != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1547 contacts_record_h newRecordHandle = null;
1549 contacts_record_clone(recordHandle, &newRecordHandle);
1550 SysTryReturn(NID_SCL, newRecordHandle != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1552 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecordHandle);
1554 result r = pList->Add(*pContact);
1555 SysTryReturn(NID_SCL, !IsFailed(r), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1563 _AddressbookManagerImpl::ParseContactsFromVcardN(const Tizen::Base::String& vcardPath)
1565 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1570 result r = file.Construct(vcardPath, "r");
1571 SysTryReturn(NID_SCL, r != E_INVALID_ARG, null, E_INVALID_ARG, "[%s] Invalid argument is used..", GetErrorMessage(E_INVALID_ARG));
1572 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));
1573 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));
1574 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1576 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1578 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(vcardPath));
1580 int ret = contacts_vcard_parse_to_contact_foreach(pCharArray.get(), OnEachContact, pList.get());
1581 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1582 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1583 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1585 return pList.release();
1589 _AddressbookManagerImpl::ExportPersonToVcard(const Person& person, const Tizen::Base::String& vcardPath)
1591 bool exist = File::IsFileExist(vcardPath);
1592 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
1593 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
1594 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1597 result r = file.Construct(vcardPath, "w");
1598 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));
1599 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1600 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1602 contacts_record_h personRecordHandle = null;
1604 int ret = contacts_db_get_record(_contacts_person._uri, person.GetId(), &personRecordHandle);
1605 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The specified person does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
1606 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));
1607 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1609 __ContactsRecordHandle recordHandle(personRecordHandle);
1611 char* pVcardStream = null;
1612 ret = contacts_vcard_make_from_person(personRecordHandle, &pVcardStream);
1613 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));
1614 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1616 r = file.Write(pVcardStream, strlen(pVcardStream));
1618 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1619 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1625 _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::IList& personList, const Tizen::Base::String& vcardPath)
1627 bool exist = File::IsFileExist(vcardPath);
1628 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
1629 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
1630 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1632 int ret = CONTACTS_ERROR_NONE;
1633 char* pVcardStream = null;
1636 result r = file.Construct(vcardPath, "w");
1637 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));
1638 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1639 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1641 contacts_record_h personRecordHandle = null;
1642 __ContactsRecordHandle recordHandle(null);
1644 std::unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
1645 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1647 while (pEnum->MoveNext() == E_SUCCESS)
1649 Person* pPerson = static_cast<Person*>(pEnum->GetCurrent());
1651 ret = contacts_db_get_record(_contacts_person._uri, pPerson->GetId(), &personRecordHandle);
1652 SysTryReturnResult(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, "The specified person does not exist.");
1653 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));
1654 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1656 recordHandle.Reset(personRecordHandle);
1658 ret = contacts_vcard_make_from_person(personRecordHandle, &pVcardStream);
1659 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));
1660 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1662 r = file.Write(pVcardStream, strlen(pVcardStream));
1664 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1665 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1672 _AddressbookManagerImpl::ExportContactToVcard(const Contact& contact, const Tizen::Base::String& vcardPath)
1674 bool exist = File::IsFileExist(vcardPath);
1675 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
1676 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
1677 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1680 result r = file.Construct(vcardPath, "w");
1681 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));
1682 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1683 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1685 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
1687 char* pVcardStream = null;
1689 int ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
1690 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));
1691 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1693 r = file.Write(pVcardStream, strlen(pVcardStream));
1695 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1696 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1702 _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IList& contactList, const Tizen::Base::String& vcardPath)
1704 bool exist = File::IsFileExist(vcardPath);
1705 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
1706 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
1707 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1709 int ret = CONTACTS_ERROR_NONE;
1710 char* pVcardStream = null;
1712 Contact* pContact = null;
1714 result r = file.Construct(vcardPath, "w");
1715 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));
1716 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1717 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1719 contacts_record_h recordHandle = null;
1721 std::unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
1722 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1724 while (pEnum->MoveNext() == E_SUCCESS)
1726 pContact = static_cast<Contact*>(pEnum->GetCurrent());
1728 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1730 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
1731 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));
1732 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1734 r = file.Write(pVcardStream, strlen(pVcardStream));
1736 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
1737 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1744 _AddressbookManagerImpl::ExportContactToVcardStreamN(const Contact& contact)
1746 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1748 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
1750 char* pVcardStream = null;
1751 int ret = CONTACTS_ERROR_NONE;
1753 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
1754 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1755 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1756 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1758 std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
1759 if (pByteBuffer == null)
1762 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1767 result r = pByteBuffer->Construct(strlen(pVcardStream));
1771 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1776 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
1778 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1779 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1781 return pByteBuffer.release();
1785 _AddressbookManagerImpl::ExportContactsToVcardStreamN(const Tizen::Base::Collection::IList& contactList)
1787 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1789 char* pVcardStream = null;
1790 int ret = CONTACTS_ERROR_NONE;
1791 Contact* pContact = null;
1792 result r = E_SUCCESS;
1795 contacts_record_h recordHandle = null;
1797 std::unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
1798 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1800 std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
1801 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1803 r = pByteBuffer->Construct(capacity);
1804 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1806 if (contactList.GetCount() == 0)
1808 return pByteBuffer.release();
1811 while (pEnum->MoveNext() == E_SUCCESS)
1813 pContact = static_cast<Contact*>(pEnum->GetCurrent());
1815 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1817 ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
1818 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1819 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1820 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1822 capacity += strlen(pVcardStream);
1823 r = pByteBuffer->ExpandCapacity(capacity);
1827 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1832 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
1834 pVcardStream = null;
1835 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
1838 return pByteBuffer.release();
1842 _AddressbookManagerImpl::ExportPersonToVcardStreamN(const Person& person)
1844 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1846 int ret = CONTACTS_ERROR_NONE;
1848 contacts_record_h personRecordHandle = null;
1850 ret =contacts_db_get_record(_contacts_person._uri, person.GetId(), &personRecordHandle);
1851 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1852 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1853 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1855 __ContactsRecordHandle recordHandle(personRecordHandle);
1857 char* pVcardStream = null;
1859 ret = contacts_vcard_make_from_person(personRecordHandle, &pVcardStream);
1860 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1861 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1862 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1864 std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
1865 if (pByteBuffer == null)
1868 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1873 result r = pByteBuffer->Construct(strlen(pVcardStream));
1877 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1882 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
1884 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1886 return pByteBuffer.release();
1890 _AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collection::IList& personList)
1892 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1894 int ret = CONTACTS_ERROR_NONE;
1895 Person* pPerson = null;
1896 char* pVcardStream = null;
1900 contacts_record_h personRecordHandle = null;
1901 __ContactsRecordHandle recordHandle(null);
1903 std::unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
1904 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1906 std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
1907 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1909 result r = pByteBuffer->Construct(capacity);
1910 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1912 if (personList.GetCount() == 0)
1914 return pByteBuffer.release();
1917 while (pEnum->MoveNext() == E_SUCCESS)
1919 pPerson = static_cast<Person*>(pEnum->GetCurrent());
1921 ret = contacts_db_get_record(_contacts_person._uri, pPerson->GetId(), &personRecordHandle);
1922 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1923 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1924 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1926 recordHandle.Reset(personRecordHandle);
1928 ret = contacts_vcard_make_from_person(personRecordHandle, &pVcardStream);
1929 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1930 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1931 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1933 capacity += strlen(pVcardStream);
1934 r = pByteBuffer->ExpandCapacity(capacity);
1938 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1943 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
1945 pVcardStream = null;
1946 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1949 return pByteBuffer.release();
1953 _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardStream)
1955 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1957 contacts_list_h listHandle = null;
1958 result r = E_SUCCESS;
1960 int ret = contacts_vcard_parse_to_contacts(reinterpret_cast<char*>(const_cast<byte*>(vcardStream.GetPointer())), &listHandle);
1961 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1962 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1964 unsigned int count = 0;
1965 contacts_record_h recordHandle = null;
1966 contacts_list_get_count(listHandle, &count);
1968 std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
1971 contacts_list_destroy(listHandle, true);
1972 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1977 r = pList->Construct(count);
1980 contacts_list_destroy(listHandle, true);
1981 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1986 for (unsigned int i = 0; i < count; i++)
1988 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
1989 if (pContact == null)
1991 contacts_list_destroy(listHandle, true);
1992 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1997 r = pList->Add(pContact.get());
2000 contacts_list_destroy(listHandle, true);
2001 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2009 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
2011 while (pEnum->MoveNext() == E_SUCCESS)
2013 Contact* pContact = static_cast <Contact*> (pEnum->GetCurrent());
2015 contacts_list_get_current_record_p(listHandle, &recordHandle);
2016 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(recordHandle);
2018 ret = contacts_list_next(listHandle);
2021 contacts_list_destroy(listHandle, false);
2023 return pList.release();
2026 Tizen::Base::ByteBuffer*
2027 _AddressbookManagerImpl::ExportUserProfileToVcardStreamN(const UserProfile& userProfile)
2029 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2031 char* pVcardStream = null;
2032 int ret = CONTACTS_ERROR_NONE;
2033 contacts_record_h recordHandle = null;
2035 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2037 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2038 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2039 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2040 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2042 std::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));
2050 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2052 result r = pByteBuffer->Construct(strlen(pVcardStream));
2056 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2061 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2063 SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2064 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2066 return pByteBuffer.release();
2069 Tizen::Base::ByteBuffer*
2070 _AddressbookManagerImpl::ExportUserProfilesToVcardStreamN(const Tizen::Base::Collection::IList& userProfileList)
2072 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2074 char* pVcardStream = null;
2075 int ret = CONTACTS_ERROR_NONE;
2076 UserProfile* pProfile = null;
2077 result r = E_SUCCESS;
2080 std::unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2081 SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2083 std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
2084 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2086 r = pByteBuffer->Construct(capacity);
2087 SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2089 if (userProfileList.GetCount() == 0)
2091 return pByteBuffer.release();
2094 while (pEnum->MoveNext() == E_SUCCESS)
2096 contacts_record_h recordHandle = null;
2098 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2100 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2102 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2103 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
2104 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2105 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2107 capacity += strlen(pVcardStream);
2108 r = pByteBuffer->ExpandCapacity(capacity);
2112 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2117 r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
2119 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
2122 return pByteBuffer.release();
2126 _AddressbookManagerImpl::ExportUserProfileToVcard(const UserProfile& userProfile, const Tizen::Base::String& vcardPath)
2128 bool exist = File::IsFileExist(vcardPath);
2129 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2130 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2131 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2134 result r = file.Construct(vcardPath, "w");
2135 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));
2136 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2137 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2139 char* pVcardStream = null;
2140 contacts_record_h recordHandle = null;
2142 recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
2144 int ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2145 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));
2146 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2148 r = file.Write(pVcardStream, strlen(pVcardStream));
2150 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2151 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2157 _AddressbookManagerImpl::ExportUserProfilesToVcard(const Tizen::Base::Collection::IList& userProfileList, const Tizen::Base::String& vcardPath)
2159 bool exist = File::IsFileExist(vcardPath);
2160 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
2161 SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
2162 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2164 int ret = CONTACTS_ERROR_NONE;
2165 char* pVcardStream = null;
2167 UserProfile* pProfile = null;
2169 result r = file.Construct(vcardPath, "w");
2170 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));
2171 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2172 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2174 std::unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
2175 SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2177 while (pEnum->MoveNext() == E_SUCCESS)
2179 contacts_record_h recordHandle = null;
2181 pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
2183 recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
2185 ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
2186 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));
2187 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2189 r = file.Write(pVcardStream, strlen(pVcardStream));
2191 SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
2192 SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
2198 Tizen::Base::Collection::IList*
2199 _AddressbookManagerImpl::GetAllUserProfilesN(void) const
2201 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2205 __Query<__ContactsUserProfile> query;
2207 query.SetSort(_contacts_my_profile.display_name, true);
2209 IList* pUserProfilesList = _AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query);
2210 SysTryReturn(NID_SCL, pUserProfilesList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2212 return pUserProfilesList;
2216 _AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
2218 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2219 SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. Addressbook Id(%d).", GetErrorMessage(E_INVALID_ARG), addressbookId);
2223 contacts_record_h addressbookHandle = null;
2224 int ret = contacts_db_get_record(_contacts_address_book._uri, addressbookId, &addressbookHandle);
2225 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2226 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The addressbook %d is not found.", GetErrorMessage(E_OBJ_NOT_FOUND), addressbookId);
2227 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred. Addressbook Id(%d)", GetErrorMessage(E_SYSTEM), addressbookId);
2229 contacts_record_destroy(addressbookHandle, true);
2231 __Filter<__ContactsUserProfile> filter;
2233 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, addressbookId);
2235 __Query<__ContactsUserProfile> query;
2237 query.SetFilter(filter);
2239 std::unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
2240 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2241 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
2242 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
2244 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
2245 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
2250 _AddressbookManagerImpl*
2251 _AddressbookManagerImpl::GetInstance(AddressbookManager& addressbookManager)
2253 return addressbookManager.__pAddressbookManagerImpl;
2256 const _AddressbookManagerImpl*
2257 _AddressbookManagerImpl::GetInstance(const AddressbookManager& addressbookManager)
2259 return addressbookManager.__pAddressbookManagerImpl;