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_AddressbookImpl.cpp
19 * @brief This is the implementation for _AddressbookImpl class.
21 * This file contains definitions of @e _AddressbookImpl class.
24 #include <FBaseColIListT.h>
25 #include <FBaseColArrayListT.h>
26 #include <FBaseResult.h>
27 #include <FBaseLongLong.h>
28 #include <FBaseInteger.h>
29 #include <FSclContact.h>
30 #include <FSclCategory.h>
31 #include <FSclUserProfile.h>
32 #include <FSclContactChangeInfo.h>
33 #include <FSclCategoryChangeInfo.h>
34 #include <FSclAddressbook.h>
35 #include <FSclIAddressbookEventListener.h>
36 #include <FSclIAddressbookChangeEventListener.h>
37 #include <FSclIRecordEventListener.h>
38 #include <FApp_AppInfo.h>
39 #include <FBaseSysLog.h>
40 #include <FBase_StringConverter.h>
41 #include "FScl_AddressbookImpl.h"
42 #include "FScl_AddressbookUtil.h"
43 #include "FScl_CategoryChangeInfoImpl.h"
44 #include "FScl_CategoryImpl.h"
45 #include "FScl_ContactChangeInfoImpl.h"
46 #include "FScl_ContactDbMonitor.h"
47 #include "FScl_ContactImpl.h"
48 #include "FScl_RecordImpl.h"
49 #include "FScl_UserProfileImpl.h"
50 #include "FScl_ContactDbConnector.h"
52 using namespace Tizen::App;
53 using namespace Tizen::Base;
54 using namespace Tizen::Base::Collection;
55 using namespace Tizen::Graphics;
57 namespace Tizen { namespace Social
60 _AddressbookImpl::_AddressbookImpl(void)
61 : __pIRecordEventListener(null)
62 , __pIAddressbookEventListener(null)
63 , __pIAddressbookChangeEventListener(null)
64 , __dbVersionForContact(0)
65 , __dbVersionForGroup(0)
66 , __dbVersionForRelation(0)
67 , __addressbookId(INVALID_ADDRESSBOOK_ID)
73 _AddressbookImpl::~_AddressbookImpl(void)
75 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
77 _ContactDbMonitor* pDbMonitor = _ContactDbMonitor::GetInstance();
78 if (pDbMonitor != null)
80 pDbMonitor->RemoveListener(*this);
86 _AddressbookImpl::Construct(void)
88 static AccountId accountId = 0;
93 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
96 contacts_record_h recordHandle = null;
97 int ret = contacts_db_get_record(_contacts_address_book._uri, DEFAULT_ADDRESSBOOK_ID, &recordHandle);
98 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
99 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred. Addressbook Id(%d)", GetErrorMessage(E_SYSTEM), DEFAULT_ADDRESSBOOK_ID);
101 contacts_record_get_str_p(recordHandle, _contacts_address_book.name, &pName);
102 contacts_record_get_int(recordHandle, _contacts_address_book.account_id, &accountId);
106 contacts_record_destroy(recordHandle, true);
109 __addressbookId = DEFAULT_ADDRESSBOOK_ID;
110 __accountId = accountId;
117 _AddressbookImpl::SetRecordEventListener(IRecordEventListener* pListener)
119 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
121 result r = E_SUCCESS;
123 if (pListener != null)
125 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null)
127 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
128 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
130 r = pContactDbMonitor->AddListener(*this);
131 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
134 __dbVersionForContact = GetLatestVersion();
135 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
137 __dbVersionForGroup = __dbVersionForContact;
138 __dbVersionForRelation = __dbVersionForContact;
140 __pIAddressbookEventListener = null;
141 __pIAddressbookChangeEventListener = null;
142 __pIRecordEventListener = pListener;
146 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
148 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
149 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()))
150 pContactDbMonitor->RemoveListener(*this);
153 __pIAddressbookEventListener = null;
154 __pIAddressbookChangeEventListener = null;
155 __pIRecordEventListener = null;
162 _AddressbookImpl::SetAddressbookEventListener(IAddressbookEventListener* pListener)
164 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
166 result r = E_SUCCESS;
168 if (pListener != null)
170 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null)
172 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
173 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
175 r = pContactDbMonitor->AddListener(*this);
176 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
179 __dbVersionForContact = GetLatestVersion();
180 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
182 __dbVersionForGroup = __dbVersionForContact;
183 __dbVersionForRelation = __dbVersionForContact;
185 __pIRecordEventListener = null;
186 __pIAddressbookChangeEventListener = null;
187 __pIAddressbookEventListener = pListener;
191 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
193 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
194 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
196 pContactDbMonitor->RemoveListener(*this);
199 __pIAddressbookEventListener = null;
200 __pIAddressbookChangeEventListener = null;
201 __pIRecordEventListener = null;
208 _AddressbookImpl::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
210 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
212 result r = E_SUCCESS;
214 if (pListener != null)
216 if (__pIAddressbookEventListener == null && __pIAddressbookChangeEventListener == null && __pIRecordEventListener == null)
218 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
219 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
221 r = pContactDbMonitor->AddListener(*this);
222 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
225 __dbVersionForContact = GetLatestVersion();
226 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
228 __dbVersionForGroup = __dbVersionForContact;
229 __dbVersionForRelation = __dbVersionForContact;
231 __pIRecordEventListener = null;
232 __pIAddressbookEventListener = null;
233 __pIAddressbookChangeEventListener = pListener;
237 if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null || __pIRecordEventListener != null)
239 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
240 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
242 pContactDbMonitor->RemoveListener(*this);
245 __pIAddressbookEventListener = null;
246 __pIAddressbookChangeEventListener = null;
247 __pIRecordEventListener = null;
254 _AddressbookImpl::SetId(AddressbookId addressbookId)
256 __addressbookId = addressbookId;
260 _AddressbookImpl::SetAccountId(AccountId accountId)
262 __accountId = accountId;
266 _AddressbookImpl::SetName(const String& name)
272 _AddressbookImpl::GetId(void) const
274 return __addressbookId;
278 _AddressbookImpl::GetAccountId(void) const
284 _AddressbookImpl::GetName(void) const
290 _AddressbookImpl::AddContact(Contact& contact)
292 if (_ContactImpl::GetInstance(contact)->IsRemoved())
294 result r = _ContactImpl::GetInstance(contact)->Invalidate();
295 SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
298 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));
299 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));
300 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
303 contacts_record_h recordHandle = null;
305 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
307 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
309 int ret = contacts_db_insert_record(recordHandle, &recordId);
310 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));
311 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
312 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
314 ret = contacts_db_get_record(_contacts_contact._uri, recordId, &recordHandle);
315 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The contact is not found.");
316 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OBJ_NOT_FOUND, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
317 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
319 _ContactImpl::GetInstance(contact)->SetContactRecordHandle(recordHandle);
320 _RecordImpl::GetInstance(contact)->SetRecordId(recordId);
326 _AddressbookImpl::AddCategory(Category& category)
328 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));
329 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
332 contacts_record_h recordHandle = null;
333 std::unique_ptr<IListT<int> > pList(null);
335 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
337 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
339 // It is not allowed to have a same name with other.
341 char* pCharValue = null;
342 contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue);
344 __Filter<__ContactsGroup> filter;
346 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
347 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
348 filter.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue);
350 __Query<__ContactsGroup> query;
352 query.SetFilter(filter);
354 count = _AddressbookUtil::GetCountWithQuery(query);
355 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
356 SysTryReturn(NID_SCL, count == 0, E_OBJ_ALREADY_EXIST, E_OBJ_ALREADY_EXIST, "[%s] The category name is already being used by other category.", GetErrorMessage(E_OBJ_ALREADY_EXIST));
359 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
361 contacts_record_set_int(recordHandle, _contacts_group.address_book_id, __addressbookId);
363 int ret = contacts_db_insert_record(recordHandle, &recordId);
364 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));
365 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
366 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
368 ret = contacts_db_get_record(_contacts_group._uri, recordId, &recordHandle);
369 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));
370 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));
371 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%d] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
373 _CategoryImpl::GetInstance(category)->SetRecordHandle(recordHandle);
374 _RecordImpl::GetInstance(category)->SetRecordId(recordId);
376 pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
377 if (pList != null && pList->GetCount() > 0)
379 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
381 while (pEnum->MoveNext() == E_SUCCESS)
384 pEnum->GetCurrent(tableId);
386 AddMemberToCategory(category.GetRecordId(), tableId);
389 _CategoryImpl::GetInstance(category)->ClearAddedMemberList();
396 _AddressbookImpl::RemoveContact(RecordId contactId)
398 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);
399 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
402 int ret = CONTACTS_ERROR_NONE;
403 contacts_record_h recordHandle = null;
405 ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
406 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));
407 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));
408 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
410 contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
412 contacts_record_destroy(recordHandle, true);
414 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
416 ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
417 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));
418 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));
419 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
425 _AddressbookImpl::RemoveContact(Contact& contact)
427 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));
428 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
430 result r = RemoveContact(contact.GetRecordId());
431 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
433 _ContactImpl::GetInstance(contact)->SetAsRemoved();
434 _RecordImpl::GetInstance(contact)->SetRecordId(INVALID_RECORD_ID);
440 _AddressbookImpl::RemoveCategory(RecordId categoryId)
442 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);
443 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
446 int ret = CONTACTS_ERROR_NONE;
447 contacts_record_h recordHandle = null;
449 ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
450 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.");
451 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));
452 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
454 __ContactsRecordHandle categoryHandle(recordHandle);
456 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
457 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
459 bool isReadOnly = false;
460 contacts_record_get_bool(recordHandle, _contacts_group.is_read_only, &isReadOnly);
461 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));
463 ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
464 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));
465 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));
466 //SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed remove a category.");
472 _AddressbookImpl::UpdateContact(const Contact& contact)
474 RecordId contactId = contact.GetRecordId();
475 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
476 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));
477 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
479 contacts_record_h recordHandle = null;
482 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
483 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));
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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
487 contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
489 contacts_record_destroy(recordHandle, true);
490 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
492 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
494 ret = contacts_db_update_record(recordHandle);
495 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));
496 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));
497 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
498 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
500 ret = contacts_db_get_record(_contacts_contact._uri, contact.GetRecordId(), &recordHandle);
501 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));
502 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));
503 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
505 _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(recordHandle);
511 _AddressbookImpl::UpdateCategory(const Category& category)
513 RecordId categoryId = category.GetRecordId();
514 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));
515 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));
516 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
518 contacts_record_h recordHandle = null;
520 int ret = CONTACTS_ERROR_NONE;
522 ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
523 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));
524 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));
525 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
527 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
529 contacts_record_destroy(recordHandle, true);
531 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
533 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
535 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
538 char* pCharValue = null;
540 contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue);
541 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
543 __Filter<__ContactsGroup> filter1;
545 filter1.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
546 filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
547 filter1.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue);
549 __Filter<__ContactsGroup> filter2;
551 filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_LESS_THAN, intValue);
552 filter2.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
553 filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_GREATER_THAN, intValue);
555 filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
556 filter1.AddFilter(filter2);
558 __Query<__ContactsGroup> query;
560 query.SetFilter(filter1);
562 count = _AddressbookUtil::GetCountWithQuery(query);
563 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
564 SysTryReturn(NID_SCL, count == 0, E_OBJ_ALREADY_EXIST, E_OBJ_ALREADY_EXIST, "[%s] The category name is alread being used by other category.", GetErrorMessage(E_OBJ_ALREADY_EXIST));
567 ret = contacts_db_update_record(recordHandle);
568 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));
569 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));
570 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
571 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
573 ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
574 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));
575 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
576 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
578 _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(recordHandle);
580 std::unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
581 if (pList != null && pList->GetCount() > 0)
584 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
585 while (pEnum->MoveNext() == E_SUCCESS)
587 pEnum->GetCurrent(tableId);
589 AddMemberToCategory(category.GetRecordId(), tableId);
592 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList();
595 pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN());
596 if (pList != null && pList->GetCount() > 0)
599 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
600 while (pEnum->MoveNext() == E_SUCCESS)
602 pEnum->GetCurrent(tableId);
604 RemoveMemberFromCategory(category.GetRecordId(), tableId);
607 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList();
614 _AddressbookImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
616 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);
617 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);
618 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
620 contacts_record_h recordHandle = null;
621 int addressbookId = 0;
622 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
623 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist.", GetErrorMessage(E_INVALID_ARG));
624 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));
625 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
626 contacts_record_get_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId);
627 contacts_record_destroy(recordHandle, true);
629 SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG));
631 ret = contacts_group_add_contact(categoryId, contactId);
632 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
633 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));
634 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
640 _AddressbookImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
642 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);
643 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);
644 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
646 contacts_record_h recordHandle = null;
647 int addressbookId = 0;
648 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
649 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist.", GetErrorMessage(E_INVALID_ARG));
650 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));
651 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
652 contacts_record_get_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId);
653 contacts_record_destroy(recordHandle, true);
655 SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG));
657 ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
658 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The category does not exist.", GetErrorMessage(E_INVALID_ARG));
659 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));
660 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
662 contacts_record_get_int(recordHandle, _contacts_group.address_book_id, &addressbookId);
663 contacts_record_destroy(recordHandle, true);
665 SysTryReturn(NID_SCL, addressbookId == __addressbookId, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The category does not exist in this addresbook.", GetErrorMessage(E_INVALID_ARG));
667 ret = contacts_group_remove_contact(categoryId, contactId);
668 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
669 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));
670 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
676 _AddressbookImpl::GetAllCategoriesN(void) const
678 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
682 __Filter<__ContactsGroup> filter;
684 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
686 __Query<__ContactsGroup> query;
688 query.SetFilter(filter);
689 query.SetSort(_contacts_group.name, true);
692 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
693 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
699 _AddressbookImpl::GetCategoriesByContactN(RecordId contactId) const
701 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
702 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));
706 __Filter<__ContactsGroupRelation> filter;
708 filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
710 __Query<__ContactsGroupRelation> query;
712 query.SetFilter(filter);
713 query.SetSort(_contacts_group_relation.name, true);
715 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query);
716 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
722 _AddressbookImpl::GetAllContactsN(void) const
724 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
728 __Filter<__ContactsContact> filter;
730 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
732 __Query<__ContactsContact> query;
734 query.SetFilter(filter);
735 query.SetSort(_contacts_contact.display_name, true);
737 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
738 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
744 _AddressbookImpl::GetContactsByCategoryN(RecordId categoryId) const
746 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));
747 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
751 __Filter<__ContactsContactGroupRel> filter;
753 if (categoryId != INVALID_RECORD_ID)
755 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
759 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
762 __Query<__ContactsContactGroupRel> query;
764 query.SetFilter(filter);
765 query.SetSort(_contacts_contact_grouprel.display_name, true);
767 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
768 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
774 _AddressbookImpl::GetContactsN(int pageNo, int countPerPage) const
776 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_OUT_OF_RANGE, "[%s] pageNo(%d) or countPerPage(%d) is less than 1.", GetErrorMessage(E_OUT_OF_RANGE), pageNo, countPerPage);
777 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
779 int offset = (pageNo - 1)*countPerPage;
780 int limit = countPerPage;
784 __Filter<__ContactsContact> filter;
786 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
788 __Query<__ContactsContact> query;
790 query.SetFilter(filter);
791 query.SetSort(_contacts_contact.display_name, true);
793 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, limit);
794 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
800 _AddressbookImpl::GetContactsInN(const Category& category, int pageNo, int countPerPage) const
802 SysTryReturn(NID_SCL, category.GetRecordId() != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is invalid.", GetErrorMessage(E_INVALID_ARG));
803 SysTryReturn(NID_SCL, pageNo > 0 && countPerPage > 0, null, E_OUT_OF_RANGE, "[%s] pageNo(%d) or countPerPage(%d) is less than 1.", GetErrorMessage(E_OUT_OF_RANGE), pageNo, countPerPage);
804 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
806 int offset = (pageNo - 1)*countPerPage;
807 int limit = countPerPage;
811 __Filter<__ContactsContactGroupRel> filter;
813 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, category.GetRecordId());
815 __Query<__ContactsContactGroupRel> query;
817 query.SetFilter(filter);
818 query.SetSort(_contacts_contact_grouprel.display_name, true);
820 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query, offset, limit);
821 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
827 _AddressbookImpl::SearchContactsByEmailN(const String& email) const
829 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));
830 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
832 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
834 SysTryReturn(NID_SCL, email.GetLength() <= MAX_EMAIL_LENGTH, null, E_INVALID_ARG, "[%s] Invalid argument is used. The length of email is greater than MAX_EMAIL_LENGTH.", GetErrorMessage(E_INVALID_ARG));
839 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
840 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
842 __Filter<__ContactsContactEmail> filter;
844 filter.AddInt(_contacts_contact_email.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
845 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
846 filter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
848 unsigned int projectionIds[1];
849 projectionIds[0] = _contacts_contact_email.contact_id;
851 __Query<__ContactsContactEmail> query;
853 query.SetProjection(projectionIds, 1);
854 query.SetFilter(filter);
855 query.SetDistinct(true);
856 query.SetSort(_contacts_contact_email.display_name, true);
858 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
859 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
865 _AddressbookImpl::SearchContactsByNameN(const String& name) const
867 SysTryReturn(NID_SCL, !name.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified email is an empty string.", GetErrorMessage(E_INVALID_ARG));
868 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
870 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
872 SysTryReturn(NID_SCL, name.GetLength() <= MAX_CONTACT_NAME_LENGTH, null, E_INVALID_ARG, "[%s] Invalid argument is used. The length of name is greater than MAX_CONTACT_NAME_LENGTH.", GetErrorMessage(E_INVALID_ARG));
878 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
879 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
881 __Filter<__ContactsContact> filter;
883 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
884 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
885 filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
887 __Query<__ContactsContact> query;
889 query.SetFilter(filter);
890 query.SetSort(_contacts_contact.display_name, true);
891 query.SetDistinct(true);
893 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
894 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
901 _AddressbookImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
903 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));
904 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
907 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
909 int count = phoneNumber.GetLength();
910 SysTryReturn(NID_SCL, count >= MIN_PHONENUMBER_QUERY_LENGTH && count <= MAX_PHONE_NUMBER_LENGTH, null, E_INVALID_ARG, "[%s] Invalid argument is used. The length of phoneNumber is shorter than MIN_PHONENUMBER_QUERY_LENGTH or greater than MAX_PHONE_NUMBER_LENGTH.", GetErrorMessage(E_INVALID_ARG));
915 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
916 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
918 __Filter<__ContactsContactNumber> filter;
920 filter.AddInt(_contacts_contact_number.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
921 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
922 filter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
924 unsigned int projectionIds[1];
925 projectionIds[0] = _contacts_contact_number.contact_id;
927 __Query<__ContactsContactNumber> query;
929 query.SetProjection(projectionIds, 1);
930 query.SetFilter(filter);
931 query.SetDistinct(true);
932 query.SetSort(_contacts_contact_number.display_name, true);
934 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
935 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
941 _AddressbookImpl::GetCategoryCount(void) const
943 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
949 __Filter<__ContactsGroup> filter;
951 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
953 __Query<__ContactsGroup> query;
955 query.SetFilter(filter);
957 count = _AddressbookUtil::GetCountWithQuery(query);
958 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
964 _AddressbookImpl::GetContactCount(void) const
966 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
972 __Filter<__ContactsContact> filter;
974 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
976 __Query<__ContactsContact> query;
978 query.SetFilter(filter);
980 count = _AddressbookUtil::GetCountWithQuery(query);
981 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
987 _AddressbookImpl::GetContactN(RecordId contactId) const
989 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
990 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
993 contacts_record_h contactHandle = null;
997 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
998 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1000 int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &contactHandle);
1001 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1002 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1003 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1005 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle);
1007 contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue);
1008 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1010 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
1012 return pContact.release();
1016 _AddressbookImpl::GetCategoryN(RecordId categoryId) const
1018 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
1019 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1021 contacts_record_h recordHandle = null;
1026 int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
1027 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1028 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1029 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1031 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
1032 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1034 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
1035 SysTryReturn(NID_SCL, intValue == categoryId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1037 __Filter<__ContactsGroupRelation> filter;
1039 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1041 __Query<__ContactsGroupRelation> query;
1043 query.SetFilter(filter);
1045 int count = _AddressbookUtil::GetCountWithQuery(query);
1046 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1048 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(recordHandle);
1049 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1050 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1052 return pCategory.release();
1056 _AddressbookImpl::GetLatestVersion(void) const
1058 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1060 int latestVersion = -1;
1064 int ret = contacts_db_get_current_version(&latestVersion);
1065 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, -1, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1066 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1068 return latestVersion;
1072 _AddressbookImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1074 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);
1075 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1077 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1078 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1080 return pChangedContacts;
1084 _AddressbookImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1086 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);
1087 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1089 int latestVersion1 = 0;
1090 int latestVersion2 = 0;
1092 std::unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion1));
1093 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1095 std::unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion2));
1096 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1098 std::unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1099 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1101 result r = pChangeList->AddItems(*pChangedGroups);
1102 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1104 r = pChangeList->AddItems(*pChangedRelations);
1105 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1107 pChangedGroups->RemoveAll(false);
1108 pChangedRelations->RemoveAll(false);
1110 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1112 return pChangeList.release();
1116 _AddressbookImpl::GetChangedContactInfoListN(int version, int& latestVersion) const
1118 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);
1119 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1121 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1122 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1124 return pChangedContacts;
1128 _AddressbookImpl::GetChangedCategoryInfoListN(int version, int& latestVersion) const
1130 return GetChangedGroupsAfterN(version, latestVersion);
1134 _AddressbookImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1136 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);
1137 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1139 IList* pChangedGroups = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1140 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1142 return pChangedGroups;
1146 _AddressbookImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1148 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);
1149 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1153 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1154 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1156 return pChangedRelations;
1160 _AddressbookImpl::AddContacts(const Tizen::Base::Collection::IList& contactList, Tizen::Base::Collection::IListT<RecordId>* pContactIdList)
1162 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1163 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1165 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1166 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1168 Contact* pContact = null;
1169 int ret = CONTACTS_ERROR_NONE;
1170 int* pContactIds = null;
1171 unsigned int contactsCount = 0;
1173 contacts_record_h recordHandle = null;
1174 contacts_list_h listHandle = null;
1176 ret = contacts_list_create(&listHandle);
1177 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1179 while (pContactEnum->MoveNext() == E_SUCCESS)
1181 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1183 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1185 contacts_list_destroy(listHandle, false);
1186 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1187 return E_INVALID_ARG;
1189 if (pContact->GetRecordId() != INVALID_RECORD_ID)
1191 contacts_list_destroy(listHandle, false);
1192 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1193 return E_INVALID_ARG;
1196 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1197 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
1198 contacts_list_add(listHandle, recordHandle);
1201 ret = contacts_db_insert_records(listHandle, &pContactIds, &contactsCount);
1202 contacts_list_destroy(listHandle, false);
1203 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));
1204 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1205 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1206 SysTryReturn(NID_SCL, pContactIds, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1208 int* pTemp = pContactIds;
1210 if (pContactIdList != null)
1212 for (unsigned int i = 0; i < contactsCount; i++)
1214 pContactIdList->Add(*pTemp);
1225 _AddressbookImpl::UpdateContacts(const Tizen::Base::Collection::IList& contactList)
1227 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1228 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1230 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1231 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1233 Contact* pContact = null;
1234 int ret = CONTACTS_ERROR_NONE;
1235 contacts_record_h recordHandle = null;
1236 contacts_list_h listHandle = null;
1238 ret = contacts_list_create(&listHandle);
1239 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1241 while (pContactEnum->MoveNext() == E_SUCCESS)
1243 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1245 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1247 contacts_list_destroy(listHandle, false);
1248 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1249 return E_INVALID_ARG;
1251 if (pContact->GetRecordId() == INVALID_RECORD_ID)
1253 contacts_list_destroy(listHandle, false);
1254 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1255 return E_INVALID_ARG;
1258 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1259 contacts_list_add(listHandle, recordHandle);
1262 ret = contacts_db_update_records(listHandle);
1263 contacts_list_destroy(listHandle, false);
1264 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));
1265 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1266 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));
1267 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1273 _AddressbookImpl::RemoveContacts(const Tizen::Base::Collection::IListT<RecordId>& contactIdList)
1275 SysTryReturn(NID_SCL, contactIdList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactIdList is empty.", GetErrorMessage(E_INVALID_ARG));
1276 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1278 std::unique_ptr<IEnumeratorT<RecordId> > pContactIdEnum(contactIdList.GetEnumeratorN());
1279 SysTryReturnResult(NID_SCL, pContactIdEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1281 RecordId contactId = INVALID_RECORD_ID;
1282 int ret = CONTACTS_ERROR_NONE;
1283 int count = contactIdList.GetCount();
1284 std::unique_ptr<int[]> pRecordIds(new (std::nothrow) int[count]);
1285 int* pInt = pRecordIds.get();
1288 while (pContactIdEnum->MoveNext() == E_SUCCESS)
1290 pContactIdEnum->GetCurrent(contactId);
1291 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. Contact id is invalid record id.", GetErrorMessage(E_INVALID_ARG));
1297 ret = contacts_db_delete_records(_contacts_contact._uri, pInt, count);
1298 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));
1299 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE || ret == CONTACTS_ERROR_NO_DATA, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1305 _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
1307 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1310 int existingRecordId = 0;
1311 int ret = CONTACTS_ERROR_NONE;
1312 result r = E_SUCCESS;
1313 contacts_record_h recordHandle = null;
1315 std::unique_ptr<UserProfile> pExistingProfile(GetUserProfileN());
1316 SysTryReturn(NID_SCL, pExistingProfile != null || GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1318 if (pExistingProfile != null)
1320 recordHandle = _UserProfileImpl::GetInstance(*pExistingProfile)->GetUserProfileHandle();
1321 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &existingRecordId);
1324 if (pUserProfile != null)
1326 SysTryReturn(NID_SCL, !((_UserProfileImpl::GetInstance(*pUserProfile))->IsEmpty()), E_SYSTEM, E_SYSTEM, "[%s] UserProfile is Empty.", GetErrorMessage(E_SYSTEM));
1328 recordHandle = _UserProfileImpl::GetInstance(*pUserProfile)->GetUserProfileHandle();
1329 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &recordId);
1332 if (pExistingProfile != null)
1334 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
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));
1339 contacts_record_h newRecordHandle = null;
1340 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1341 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));
1343 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1344 if (ret != CONTACTS_ERROR_NONE)
1346 contacts_record_destroy(newRecordHandle, true);
1347 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1351 ret = contacts_db_insert_record(newRecordHandle, &recordId);
1352 contacts_record_destroy(newRecordHandle, true);
1353 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));
1354 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1356 else if (recordId > 0)
1358 if (recordId == existingRecordId)
1360 contacts_record_h newRecordHandle = null;
1361 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1362 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));
1364 ret = contacts_db_update_record(newRecordHandle);
1365 contacts_record_destroy(newRecordHandle, true);
1366 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));
1367 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1371 if (pExistingProfile != null)
1373 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
1374 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));
1375 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1378 contacts_record_h newRecordHandle = null;
1379 ret = contacts_record_create(_contacts_my_profile._uri, &newRecordHandle);
1380 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1382 r = CopyMyProfileContents(recordHandle, newRecordHandle);
1385 contacts_record_destroy(newRecordHandle, true);
1386 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1387 return E_OUT_OF_MEMORY;
1391 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1392 if (ret != CONTACTS_ERROR_NONE)
1394 contacts_record_destroy(newRecordHandle, true);
1395 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1399 ret = contacts_db_insert_record(newRecordHandle, &recordId);
1400 contacts_record_destroy(newRecordHandle, true);
1401 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));
1402 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1408 if (pExistingProfile != null)
1410 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
1411 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));
1412 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1420 _AddressbookImpl::GetUserProfileN(void) const
1422 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1426 __Filter<__ContactsUserProfile> filter;
1428 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
1430 __Query<__ContactsUserProfile> query;
1432 query.SetFilter(filter);
1434 std::unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
1435 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1436 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
1437 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
1439 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
1440 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
1446 _AddressbookImpl::IsUserProfileChangedAfter(int version) const
1448 SysTryReturn(NID_SCL, version >= 0, false, E_INVALID_ARG, "[%s] Invalid argument is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version);
1449 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1451 UserProfile* pExistingProfile = GetUserProfileN();
1452 if (pExistingProfile == null)
1457 delete pExistingProfile;
1461 int latestVersion = 0;
1462 int count = _AddressbookUtil::GetChangedItemCountByVersion<__ContactsMyProfileUpdatedInfo>(__addressbookId, version, latestVersion);
1463 SysTryReturn(NID_SCL, count >= 0, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1474 _AddressbookImpl::CopyMyProfileContents(contacts_record_h srcHandle, contacts_record_h dstHandle)
1476 int ret = CONTACTS_ERROR_NONE;
1478 unsigned int count = 0;
1480 char* pCharValue = null;
1482 contacts_record_h srcRecordHandle = null;
1483 contacts_record_h dstRecordHandle = null;
1486 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.name, &count);
1489 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.name, 0, &srcRecordHandle);
1491 ret = contacts_record_create(_contacts_name._uri, &dstRecordHandle);
1492 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1494 __ContactsRecordHandle nameHandle(dstRecordHandle);
1496 contacts_record_get_str(srcRecordHandle, _contacts_name.first, &pCharValue);
1497 contacts_record_set_str(dstRecordHandle, _contacts_name.first, pCharValue);
1499 contacts_record_get_str(srcRecordHandle, _contacts_name.last, &pCharValue);
1500 contacts_record_set_str(dstRecordHandle, _contacts_name.last, pCharValue);
1502 contacts_record_get_str(srcRecordHandle, _contacts_name.addition, &pCharValue);
1503 contacts_record_set_str(dstRecordHandle, _contacts_name.addition, pCharValue);
1505 contacts_record_get_str(srcRecordHandle, _contacts_name.suffix, &pCharValue);
1506 contacts_record_set_str(dstRecordHandle, _contacts_name.suffix, pCharValue);
1508 contacts_record_get_str(srcRecordHandle, _contacts_name.prefix, &pCharValue);
1509 contacts_record_set_str(dstRecordHandle, _contacts_name.prefix, pCharValue);
1511 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_first, &pCharValue);
1512 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_first, pCharValue);
1514 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
1515 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_middle, pCharValue);
1517 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_last, &pCharValue);
1518 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_last, pCharValue);
1520 contacts_record_add_child_record(dstHandle, _contacts_my_profile.name, dstRecordHandle);
1522 nameHandle.Release();
1526 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.company, &count);
1527 for (i = 0; i < count; i++)
1529 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.company, i, &srcRecordHandle);
1531 ret = contacts_record_create(_contacts_company._uri, &dstRecordHandle);
1532 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1534 __ContactsRecordHandle companyHandle(dstRecordHandle);
1536 contacts_record_get_int(srcRecordHandle, _contacts_company.type, &intValue);
1537 contacts_record_set_int(dstRecordHandle, _contacts_company.type, intValue);
1539 contacts_record_get_str_p(srcRecordHandle, _contacts_company.name, &pCharValue);
1540 contacts_record_set_str(dstRecordHandle, _contacts_company.name, pCharValue);
1542 contacts_record_get_str_p(srcRecordHandle, _contacts_company.department, &pCharValue);
1543 contacts_record_set_str(dstRecordHandle, _contacts_company.department, pCharValue);
1545 contacts_record_get_str_p(srcRecordHandle, _contacts_company.job_title, &pCharValue);
1546 contacts_record_set_str(dstRecordHandle, _contacts_company.job_title, pCharValue);
1548 contacts_record_get_str_p(srcRecordHandle, _contacts_company.assistant_name, &pCharValue);
1549 contacts_record_set_str(dstRecordHandle, _contacts_company.assistant_name, pCharValue);
1551 contacts_record_get_str_p(srcRecordHandle, _contacts_company.role, &pCharValue);
1552 contacts_record_set_str(dstRecordHandle, _contacts_company.role, pCharValue);
1554 contacts_record_get_str_p(srcRecordHandle, _contacts_company.logo, &pCharValue);
1555 contacts_record_set_str(dstRecordHandle, _contacts_company.logo, pCharValue);
1557 contacts_record_get_str_p(srcRecordHandle, _contacts_company.location, &pCharValue);
1558 contacts_record_set_str(dstRecordHandle, _contacts_company.location, pCharValue);
1560 contacts_record_get_str_p(srcRecordHandle, _contacts_company.description, &pCharValue);
1561 contacts_record_set_str(dstRecordHandle, _contacts_company.description, pCharValue);
1563 contacts_record_get_str_p(srcRecordHandle, _contacts_company.phonetic_name, &pCharValue);
1564 contacts_record_set_str(dstRecordHandle, _contacts_company.phonetic_name, pCharValue);
1566 contacts_record_add_child_record(dstHandle, _contacts_my_profile.company, dstRecordHandle);
1568 companyHandle.Release();
1572 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.note, &count);
1573 for (i = 0; i < count; i++)
1575 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.note, i, &srcRecordHandle);
1577 ret = contacts_record_create(_contacts_note._uri, &dstRecordHandle);
1578 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1580 __ContactsRecordHandle noteHandle(dstRecordHandle);
1582 contacts_record_get_str_p(srcRecordHandle, _contacts_note.note, &pCharValue);
1583 contacts_record_set_str(dstRecordHandle, _contacts_note.note, pCharValue);
1585 contacts_record_add_child_record(dstHandle, _contacts_my_profile.note, dstRecordHandle);
1587 noteHandle.Release();
1591 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.number, &count);
1592 for (i = 0; i < count; i++)
1594 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.number, i, &srcRecordHandle);
1596 ret = contacts_record_create(_contacts_number._uri, &dstRecordHandle);
1597 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1599 __ContactsRecordHandle numberHandle(dstRecordHandle);
1601 contacts_record_get_int(srcRecordHandle, _contacts_number.type, &intValue);
1602 contacts_record_set_int(dstRecordHandle, _contacts_number.type, intValue);
1604 contacts_record_get_str_p(srcRecordHandle, _contacts_number.label, &pCharValue);
1605 contacts_record_set_str(dstRecordHandle, _contacts_number.label, pCharValue);
1607 contacts_record_get_str_p(srcRecordHandle, _contacts_number.number, &pCharValue);
1608 contacts_record_set_str(dstRecordHandle, _contacts_number.number, pCharValue);
1610 contacts_record_add_child_record(dstHandle, _contacts_my_profile.number, dstRecordHandle);
1612 numberHandle.Release();
1616 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.email, &count);
1617 for (i = 0; i < count; i++)
1619 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.email, i, &srcRecordHandle);
1621 ret = contacts_record_create(_contacts_email._uri, &dstRecordHandle);
1622 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1624 __ContactsRecordHandle emailHandle(dstRecordHandle);
1626 contacts_record_get_int(srcRecordHandle, _contacts_email.type, &intValue);
1627 contacts_record_set_int(dstRecordHandle, _contacts_email.type, intValue);
1629 contacts_record_get_str_p(srcRecordHandle, _contacts_email.label, &pCharValue);
1630 contacts_record_set_str(dstRecordHandle, _contacts_email.label, pCharValue);
1632 contacts_record_get_str_p(srcRecordHandle, _contacts_email.email, &pCharValue);
1633 contacts_record_set_str(dstRecordHandle, _contacts_email.email, pCharValue);
1635 contacts_record_add_child_record(dstHandle, _contacts_my_profile.email, dstRecordHandle);
1637 emailHandle.Release();
1642 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.event, &count);
1643 for (i = 0; i < count; i++)
1645 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.event, i, &srcRecordHandle);
1647 ret = contacts_record_create(_contacts_event._uri, &dstRecordHandle);
1648 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1650 __ContactsRecordHandle eventHandle(dstRecordHandle);
1652 contacts_record_get_int(srcRecordHandle, _contacts_event.type, &intValue);
1653 contacts_record_set_int(dstRecordHandle, _contacts_event.type, intValue);
1655 contacts_record_get_str_p(srcRecordHandle, _contacts_event.label, &pCharValue);
1656 contacts_record_set_str(dstRecordHandle, _contacts_event.label, pCharValue);
1658 contacts_record_get_int(srcRecordHandle, _contacts_event.date, &intValue);
1659 contacts_record_set_int(dstRecordHandle, _contacts_event.date, intValue);
1661 contacts_record_add_child_record(dstHandle, _contacts_my_profile.event, dstRecordHandle);
1663 eventHandle.Release();
1667 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.messenger, &count);
1668 for (i = 0; i < count; i++)
1670 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.messenger, i, &srcRecordHandle);
1672 ret = contacts_record_create(_contacts_messenger._uri, &dstRecordHandle);
1673 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1675 __ContactsRecordHandle imAddressHandle(dstRecordHandle);
1677 contacts_record_get_int(srcRecordHandle, _contacts_messenger.type, &intValue);
1678 contacts_record_set_int(dstRecordHandle, _contacts_messenger.type, intValue);
1680 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.label, &pCharValue);
1681 contacts_record_set_str(dstRecordHandle, _contacts_messenger.label, pCharValue);
1683 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.im_id, &pCharValue);
1684 contacts_record_set_str(dstRecordHandle, _contacts_messenger.im_id, pCharValue);
1686 contacts_record_add_child_record(dstHandle, _contacts_my_profile.messenger, dstRecordHandle);
1688 imAddressHandle.Release();
1692 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.address, &count);
1693 for (i = 0; i < count; i++)
1695 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.address, i, &srcRecordHandle);
1697 ret = contacts_record_create(_contacts_address._uri, &dstRecordHandle);
1698 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1700 __ContactsRecordHandle addressHandle(dstRecordHandle);
1702 contacts_record_get_int(srcRecordHandle, _contacts_address.type, &intValue);
1703 contacts_record_set_int(dstRecordHandle, _contacts_address.type, intValue);
1705 contacts_record_get_str_p(srcRecordHandle, _contacts_address.label, &pCharValue);
1706 contacts_record_set_str(dstRecordHandle, _contacts_address.label, pCharValue);
1708 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postbox, &pCharValue);
1709 contacts_record_set_str(dstRecordHandle, _contacts_address.postbox, pCharValue);
1711 contacts_record_get_str_p(srcRecordHandle, _contacts_address.extended, &pCharValue);
1712 contacts_record_set_str(dstRecordHandle, _contacts_address.extended, pCharValue);
1714 contacts_record_get_str_p(srcRecordHandle, _contacts_address.street, &pCharValue);
1715 contacts_record_set_str(dstRecordHandle, _contacts_address.street, pCharValue);
1717 contacts_record_get_str_p(srcRecordHandle, _contacts_address.locality, &pCharValue);
1718 contacts_record_set_str(dstRecordHandle, _contacts_address.locality, pCharValue);
1720 contacts_record_get_str_p(srcRecordHandle, _contacts_address.region, &pCharValue);
1721 contacts_record_set_str(dstRecordHandle, _contacts_address.region, pCharValue);
1723 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postal_code, &pCharValue);
1724 contacts_record_set_str(dstRecordHandle, _contacts_address.postal_code, pCharValue);
1726 contacts_record_get_str_p(srcRecordHandle, _contacts_address.country, &pCharValue);
1727 contacts_record_set_str(dstRecordHandle, _contacts_address.country, pCharValue);
1729 contacts_record_add_child_record(dstHandle, _contacts_my_profile.address, dstRecordHandle);
1731 addressHandle.Release();
1735 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.url, &count);
1736 for (i = 0; i < count; i++)
1738 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.url, i, &srcRecordHandle);
1740 ret = contacts_record_create(_contacts_url._uri, &dstRecordHandle);
1741 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1743 __ContactsRecordHandle urlHandle(dstRecordHandle);
1745 contacts_record_get_int(srcRecordHandle, _contacts_url.type, &intValue);
1746 contacts_record_set_int(dstRecordHandle, _contacts_url.type, intValue);
1748 contacts_record_get_str_p(srcRecordHandle, _contacts_url.label, &pCharValue);
1749 contacts_record_set_str(dstRecordHandle, _contacts_url.label, pCharValue);
1751 contacts_record_get_str_p(srcRecordHandle, _contacts_url.url, &pCharValue);
1752 contacts_record_set_str(dstRecordHandle, _contacts_url.url, pCharValue);
1754 contacts_record_add_child_record(dstHandle, _contacts_my_profile.url, dstRecordHandle);
1756 urlHandle.Release();
1760 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.nickname, &count);
1761 for (i = 0; i < count; i++)
1763 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.nickname, i, &srcRecordHandle);
1765 ret = contacts_record_create(_contacts_nickname._uri, &dstRecordHandle);
1766 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1768 __ContactsRecordHandle nicknameHandle(dstRecordHandle);
1770 contacts_record_get_str_p(srcRecordHandle, _contacts_nickname.name, &pCharValue);
1771 contacts_record_set_str(dstRecordHandle, _contacts_nickname.name, pCharValue);
1773 contacts_record_add_child_record(dstHandle, _contacts_my_profile.nickname, dstRecordHandle);
1775 nicknameHandle.Release();
1779 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.relationship, &count);
1780 for (i = 0; i < count; i++)
1782 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.relationship, i, &srcRecordHandle);
1784 ret = contacts_record_create(_contacts_relationship._uri, &dstRecordHandle);
1785 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1787 __ContactsRecordHandle relationshipHandle(dstRecordHandle);
1789 contacts_record_get_str_p(srcRecordHandle, _contacts_relationship.name, &pCharValue);
1790 contacts_record_set_str(dstRecordHandle, _contacts_relationship.name, pCharValue);
1792 contacts_record_add_child_record(dstHandle, _contacts_my_profile.relationship, dstRecordHandle);
1794 relationshipHandle.Release();
1798 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.image, &count);
1801 contacts_record_get_int(srcHandle, _contacts_my_profile.id, &recordId);
1803 if (count > 0 && recordId == 0)
1805 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.image, 0, &srcRecordHandle);
1807 ret = contacts_record_create(_contacts_image._uri, &dstRecordHandle);
1808 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1810 __ContactsRecordHandle imageHandle(dstRecordHandle);
1812 contacts_record_get_int(srcRecordHandle, _contacts_image.type, &intValue);
1813 contacts_record_set_int(dstRecordHandle, _contacts_image.type, intValue);
1815 contacts_record_get_str_p(srcRecordHandle, _contacts_image.label, &pCharValue);
1816 contacts_record_set_str(dstRecordHandle, _contacts_image.label, pCharValue);
1818 contacts_record_get_str_p(srcRecordHandle, _contacts_image.path, &pCharValue);
1819 contacts_record_set_str(dstRecordHandle, _contacts_image.path, pCharValue);
1821 contacts_record_add_child_record(dstHandle, _contacts_contact.image, dstRecordHandle);
1823 imageHandle.Release();
1830 _AddressbookImpl::OnContactChanged(void)
1832 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1837 std::unique_ptr<IList, AllElementsDeleter> pChangedContactList(GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact));
1838 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1840 if (pChangedContactList->GetCount() > 0)
1842 if (__pIAddressbookEventListener != null)
1844 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1846 else if (__pIAddressbookChangeEventListener != null)
1848 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1852 RecordEventType recordEventType = RECORD_ADDED;
1853 std::unique_ptr<IEnumerator> pEnum(pChangedContactList->GetEnumeratorN());
1854 std::unique_ptr<Contact> pContact(null);
1856 while (pEnum->MoveNext() == E_SUCCESS)
1858 ContactChangeInfo* pContactChagneInfo = static_cast<ContactChangeInfo*>(pEnum->GetCurrent());
1860 if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
1862 recordEventType = RECORD_ADDED;
1863 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
1864 if (pContact == null)
1866 if (GetLastResult() == E_OBJ_NOT_FOUND)
1876 else if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
1878 recordEventType = RECORD_UPDATED;
1879 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
1880 if (pContact == null)
1882 if (GetLastResult() == E_OBJ_NOT_FOUND)
1894 recordEventType = RECORD_REMOVED;
1895 pContact.reset(new (std::nothrow) Contact());
1896 if (pContact == null)
1898 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1902 _RecordImpl::GetInstance(*pContact)->SetRecordId(pContactChagneInfo->GetContactId());
1905 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CONTACT, *pContact, null, null);
1913 _AddressbookImpl::OnCategoryChanged(void)
1915 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1920 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup));
1921 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1923 if (pChangedCategoryList->GetCount() > 0)
1925 if (__pIAddressbookEventListener != null)
1927 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1929 else if (__pIAddressbookChangeEventListener != null)
1931 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1935 RecordEventType recordEventType = RECORD_ADDED;
1936 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
1937 std::unique_ptr<Category> pCategory(null);
1939 while (pEnum->MoveNext() == E_SUCCESS)
1941 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
1943 if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
1945 recordEventType = RECORD_ADDED;
1946 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1947 if (pCategory == null)
1949 if (GetLastResult() == E_OBJ_NOT_FOUND)
1959 else if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
1961 recordEventType = RECORD_UPDATED;
1962 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1963 if (pCategory == null)
1965 if (GetLastResult() == E_OBJ_NOT_FOUND)
1977 recordEventType = RECORD_REMOVED;
1978 pCategory.reset(new (std::nothrow) Category());
1979 if (pCategory == null)
1981 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1985 _RecordImpl::GetInstance(*pCategory)->SetRecordId(pCategoryChagneInfo->GetCategoryId());
1988 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
1996 _AddressbookImpl::OnRelationChanged(void)
1998 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null)
2003 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation));
2004 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2006 if (pChangedCategoryList->GetCount() > 0)
2008 if (__pIAddressbookEventListener != null)
2010 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
2014 RecordEventType recordEventType = RECORD_ADDED;
2015 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
2016 std::unique_ptr<Category> pCategory(null);
2018 while (pEnum->MoveNext() == E_SUCCESS)
2020 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
2022 recordEventType = RECORD_UPDATED;
2023 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2024 if (pCategory == null)
2026 if (GetLastResult() == E_OBJ_NOT_FOUND)
2036 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2043 _AddressbookImpl::GetInstance(Addressbook& addressbook)
2045 return addressbook.__pAddressbookImpl;
2048 const _AddressbookImpl*
2049 _AddressbookImpl::GetInstance(const Addressbook& addressbook)
2051 return addressbook.__pAddressbookImpl;