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()));
705 __Filter<__ContactsGroupRelation> filter;
707 filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
709 __Query<__ContactsGroupRelation> query;
711 query.SetFilter(filter);
712 query.SetSort(_contacts_group_relation.name, true);
714 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query);
715 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
721 _AddressbookImpl::GetAllContactsN(void) const
723 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
727 __Filter<__ContactsContact> filter;
729 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
731 __Query<__ContactsContact> query;
733 query.SetFilter(filter);
734 query.SetSort(_contacts_contact.display_name, true);
736 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
737 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
743 _AddressbookImpl::GetContactsByCategoryN(RecordId categoryId) const
745 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));
746 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
750 __Filter<__ContactsContactGroupRel> filter;
752 if (categoryId != INVALID_RECORD_ID)
754 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
758 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
761 __Query<__ContactsContactGroupRel> query;
763 query.SetFilter(filter);
764 query.SetSort(_contacts_contact_grouprel.display_name, true);
766 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
767 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
773 _AddressbookImpl::GetContactsN(int pageNo, int countPerPage) const
775 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);
776 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
778 int offset = (pageNo - 1)*countPerPage;
779 int limit = countPerPage;
783 __Filter<__ContactsContact> filter;
785 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
787 __Query<__ContactsContact> query;
789 query.SetFilter(filter);
790 query.SetSort(_contacts_contact.display_name, true);
792 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, limit);
793 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
799 _AddressbookImpl::GetContactsInN(const Category& category, int pageNo, int countPerPage) const
801 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));
802 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);
803 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
805 int offset = (pageNo - 1)*countPerPage;
806 int limit = countPerPage;
810 __Filter<__ContactsContactGroupRel> filter;
812 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, category.GetRecordId());
814 __Query<__ContactsContactGroupRel> query;
816 query.SetFilter(filter);
817 query.SetSort(_contacts_contact_grouprel.display_name, true);
819 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query, offset, limit);
820 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
826 _AddressbookImpl::SearchContactsByEmailN(const String& email) const
828 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));
829 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
831 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
833 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));
838 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
839 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
841 __Filter<__ContactsContactEmail> filter;
843 filter.AddInt(_contacts_contact_email.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
844 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
845 filter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
847 unsigned int projectionIds[1];
848 projectionIds[0] = _contacts_contact_email.contact_id;
850 __Query<__ContactsContactEmail> query;
852 query.SetProjection(projectionIds, 1);
853 query.SetFilter(filter);
854 query.SetDistinct(true);
855 query.SetSort(_contacts_contact_email.display_name, true);
857 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
858 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
864 _AddressbookImpl::SearchContactsByNameN(const String& name) const
866 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));
867 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
869 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
871 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));
877 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
878 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
880 __Filter<__ContactsContact> filter;
882 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
883 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
884 filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
886 __Query<__ContactsContact> query;
888 query.SetFilter(filter);
889 query.SetSort(_contacts_contact.display_name, true);
890 query.SetDistinct(true);
892 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
893 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
900 _AddressbookImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
902 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));
903 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
906 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
908 int count = phoneNumber.GetLength();
909 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));
914 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
915 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
917 __Filter<__ContactsContactNumber> filter;
919 filter.AddInt(_contacts_contact_number.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
920 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
921 filter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
923 unsigned int projectionIds[1];
924 projectionIds[0] = _contacts_contact_number.contact_id;
926 __Query<__ContactsContactNumber> query;
928 query.SetProjection(projectionIds, 1);
929 query.SetFilter(filter);
930 query.SetDistinct(true);
931 query.SetSort(_contacts_contact_number.display_name, true);
933 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
934 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
940 _AddressbookImpl::GetCategoryCount(void) const
942 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
948 __Filter<__ContactsGroup> filter;
950 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
952 __Query<__ContactsGroup> query;
954 query.SetFilter(filter);
956 count = _AddressbookUtil::GetCountWithQuery(query);
957 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
963 _AddressbookImpl::GetContactCount(void) const
965 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
971 __Filter<__ContactsContact> filter;
973 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
975 __Query<__ContactsContact> query;
977 query.SetFilter(filter);
979 count = _AddressbookUtil::GetCountWithQuery(query);
980 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
986 _AddressbookImpl::GetContactN(RecordId contactId) const
988 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
989 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
992 contacts_record_h contactHandle = null;
996 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
997 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
999 int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &contactHandle);
1000 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1001 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1002 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1004 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle);
1006 contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue);
1007 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1009 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
1011 return pContact.release();
1015 _AddressbookImpl::GetCategoryN(RecordId categoryId) const
1017 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
1018 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1020 contacts_record_h recordHandle = null;
1025 int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
1026 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1027 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1028 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1030 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
1031 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1033 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
1034 SysTryReturn(NID_SCL, intValue == categoryId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1036 __Filter<__ContactsGroupRelation> filter;
1038 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1040 __Query<__ContactsGroupRelation> query;
1042 query.SetFilter(filter);
1044 int count = _AddressbookUtil::GetCountWithQuery(query);
1045 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1047 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(recordHandle);
1048 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1049 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1051 return pCategory.release();
1055 _AddressbookImpl::GetLatestVersion(void) const
1057 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1059 int latestVersion = -1;
1063 int ret = contacts_db_get_current_version(&latestVersion);
1064 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, -1, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1065 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1067 return latestVersion;
1071 _AddressbookImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1073 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);
1074 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1076 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1077 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1079 return pChangedContacts;
1083 _AddressbookImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1085 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);
1086 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1088 int latestVersion1 = 0;
1089 int latestVersion2 = 0;
1091 std::unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion1));
1092 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1094 std::unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion2));
1095 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1097 std::unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1098 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1100 result r = pChangeList->AddItems(*pChangedGroups);
1101 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1103 r = pChangeList->AddItems(*pChangedRelations);
1104 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1106 pChangedGroups->RemoveAll(false);
1107 pChangedRelations->RemoveAll(false);
1109 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1111 return pChangeList.release();
1115 _AddressbookImpl::GetChangedContactInfoListN(int version, int& latestVersion) const
1117 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);
1118 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1120 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1121 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1123 return pChangedContacts;
1127 _AddressbookImpl::GetChangedCategoryInfoListN(int version, int& latestVersion) const
1129 return GetChangedGroupsAfterN(version, latestVersion);
1133 _AddressbookImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1135 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);
1136 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1138 IList* pChangedGroups = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1139 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1141 return pChangedGroups;
1145 _AddressbookImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1147 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);
1148 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1152 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1153 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1155 return pChangedRelations;
1159 _AddressbookImpl::AddContacts(const Tizen::Base::Collection::IList& contactList, Tizen::Base::Collection::IListT<RecordId>* pContactIdList)
1161 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1162 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1164 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1165 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1167 Contact* pContact = null;
1168 int ret = CONTACTS_ERROR_NONE;
1169 int* pContactIds = null;
1170 unsigned int contactsCount = 0;
1172 contacts_record_h recordHandle = null;
1173 contacts_list_h listHandle = null;
1175 ret = contacts_list_create(&listHandle);
1176 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1178 while (pContactEnum->MoveNext() == E_SUCCESS)
1180 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1182 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1184 contacts_list_destroy(listHandle, false);
1185 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1186 return E_INVALID_ARG;
1188 if (pContact->GetRecordId() != INVALID_RECORD_ID)
1190 contacts_list_destroy(listHandle, false);
1191 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1192 return E_INVALID_ARG;
1195 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1196 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
1197 contacts_list_add(listHandle, recordHandle);
1200 ret = contacts_db_insert_records(listHandle, &pContactIds, &contactsCount);
1201 contacts_list_destroy(listHandle, false);
1202 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));
1203 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1204 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1205 SysTryReturn(NID_SCL, pContactIds, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1207 int* pTemp = pContactIds;
1209 if (pContactIdList != null)
1211 for (int i = 0; i < contactsCount; i++)
1213 pContactIdList->Add(*pTemp);
1224 _AddressbookImpl::UpdateContacts(const Tizen::Base::Collection::IList& contactList)
1226 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1227 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1229 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1230 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1232 Contact* pContact = null;
1233 int ret = CONTACTS_ERROR_NONE;
1234 contacts_record_h recordHandle = null;
1235 contacts_list_h listHandle = null;
1237 ret = contacts_list_create(&listHandle);
1238 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1240 while (pContactEnum->MoveNext() == E_SUCCESS)
1242 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1244 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1246 contacts_list_destroy(listHandle, false);
1247 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1248 return E_INVALID_ARG;
1250 if (pContact->GetRecordId() == INVALID_RECORD_ID)
1252 contacts_list_destroy(listHandle, false);
1253 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1254 return E_INVALID_ARG;
1257 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1258 contacts_list_add(listHandle, recordHandle);
1261 ret = contacts_db_update_records(listHandle);
1262 contacts_list_destroy(listHandle, false);
1263 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));
1264 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1265 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));
1266 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1272 _AddressbookImpl::RemoveContacts(const Tizen::Base::Collection::IListT<RecordId>& contactIdList)
1274 SysTryReturn(NID_SCL, contactIdList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactIdList is empty.", GetErrorMessage(E_INVALID_ARG));
1275 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1277 std::unique_ptr<IEnumeratorT<RecordId> > pContactIdEnum(contactIdList.GetEnumeratorN());
1278 SysTryReturnResult(NID_SCL, pContactIdEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1280 RecordId contactId = INVALID_RECORD_ID;
1281 int ret = CONTACTS_ERROR_NONE;
1282 int count = contactIdList.GetCount();
1283 std::unique_ptr<int[]> pRecordIds(new (std::nothrow) int[count]);
1284 int* pInt = pRecordIds.get();
1287 while (pContactIdEnum->MoveNext() == E_SUCCESS)
1289 pContactIdEnum->GetCurrent(contactId);
1290 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));
1296 ret = contacts_db_delete_records(_contacts_contact._uri, pInt, count);
1297 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));
1298 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));
1304 _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
1306 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1309 int existingRecordId = 0;
1310 int ret = CONTACTS_ERROR_NONE;
1311 result r = E_SUCCESS;
1312 contacts_record_h recordHandle = null;
1314 std::unique_ptr<UserProfile> pExistingProfile(GetUserProfileN());
1315 SysTryReturn(NID_SCL, pExistingProfile != null || GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1317 if (pExistingProfile != null)
1319 recordHandle = _UserProfileImpl::GetInstance(*pExistingProfile)->GetUserProfileHandle();
1320 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &existingRecordId);
1323 if (pUserProfile != null)
1325 SysTryReturn(NID_SCL, !((_UserProfileImpl::GetInstance(*pUserProfile))->IsEmpty()), E_SYSTEM, E_SYSTEM, "[%s] UserProfile is Empty.", GetErrorMessage(E_SYSTEM));
1327 recordHandle = _UserProfileImpl::GetInstance(*pUserProfile)->GetUserProfileHandle();
1328 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &recordId);
1331 if (pExistingProfile != null)
1333 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
1334 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));
1335 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1338 contacts_record_h newRecordHandle = null;
1339 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1340 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));
1342 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1343 if (ret != CONTACTS_ERROR_NONE)
1345 contacts_record_destroy(newRecordHandle, true);
1346 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1350 ret = contacts_db_insert_record(newRecordHandle, &recordId);
1351 contacts_record_destroy(newRecordHandle, true);
1352 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));
1353 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1355 else if (recordId > 0)
1357 if (recordId == existingRecordId)
1359 contacts_record_h newRecordHandle = null;
1360 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1361 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));
1363 ret = contacts_db_update_record(newRecordHandle);
1364 contacts_record_destroy(newRecordHandle, true);
1365 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));
1366 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1370 if (pExistingProfile != null)
1372 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
1373 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));
1374 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1377 contacts_record_h newRecordHandle = null;
1378 ret = contacts_record_create(_contacts_my_profile._uri, &newRecordHandle);
1379 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1381 r = CopyMyProfileContents(recordHandle, newRecordHandle);
1384 contacts_record_destroy(newRecordHandle, true);
1385 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1386 return E_OUT_OF_MEMORY;
1390 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1391 if (ret != CONTACTS_ERROR_NONE)
1393 contacts_record_destroy(newRecordHandle, true);
1394 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1398 ret = contacts_db_insert_record(newRecordHandle, &recordId);
1399 contacts_record_destroy(newRecordHandle, true);
1400 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));
1401 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1407 if (pExistingProfile != null)
1409 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
1410 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));
1411 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1419 _AddressbookImpl::GetUserProfileN(void) const
1421 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1425 __Filter<__ContactsUserProfile> filter;
1427 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
1429 __Query<__ContactsUserProfile> query;
1431 query.SetFilter(filter);
1433 std::unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
1434 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1435 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
1436 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
1438 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
1439 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
1445 _AddressbookImpl::IsUserProfileChangedAfter(int version) const
1447 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);
1448 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1452 int latestVersion = 0;
1453 int count = _AddressbookUtil::GetChangedItemCountByVersion<__ContactsMyProfileUpdatedInfo>(__addressbookId, version, latestVersion);
1454 SysTryReturn(NID_SCL, count >= 0, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1465 _AddressbookImpl::CopyMyProfileContents(contacts_record_h srcHandle, contacts_record_h dstHandle)
1467 int ret = CONTACTS_ERROR_NONE;
1469 unsigned int count = 0;
1471 char* pCharValue = null;
1473 contacts_record_h srcRecordHandle = null;
1474 contacts_record_h dstRecordHandle = null;
1477 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.name, &count);
1480 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.name, 0, &srcRecordHandle);
1482 ret = contacts_record_create(_contacts_name._uri, &dstRecordHandle);
1483 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1485 __ContactsRecordHandle nameHandle(dstRecordHandle);
1487 contacts_record_get_str(srcRecordHandle, _contacts_name.first, &pCharValue);
1488 contacts_record_set_str(dstRecordHandle, _contacts_name.first, pCharValue);
1490 contacts_record_get_str(srcRecordHandle, _contacts_name.last, &pCharValue);
1491 contacts_record_set_str(dstRecordHandle, _contacts_name.last, pCharValue);
1493 contacts_record_get_str(srcRecordHandle, _contacts_name.addition, &pCharValue);
1494 contacts_record_set_str(dstRecordHandle, _contacts_name.addition, pCharValue);
1496 contacts_record_get_str(srcRecordHandle, _contacts_name.suffix, &pCharValue);
1497 contacts_record_set_str(dstRecordHandle, _contacts_name.suffix, pCharValue);
1499 contacts_record_get_str(srcRecordHandle, _contacts_name.prefix, &pCharValue);
1500 contacts_record_set_str(dstRecordHandle, _contacts_name.prefix, pCharValue);
1502 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_first, &pCharValue);
1503 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_first, pCharValue);
1505 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
1506 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_middle, pCharValue);
1508 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_last, &pCharValue);
1509 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_last, pCharValue);
1511 contacts_record_add_child_record(dstHandle, _contacts_my_profile.name, dstRecordHandle);
1513 nameHandle.Release();
1517 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.company, &count);
1518 for (i = 0; i < count; i++)
1520 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.company, i, &srcRecordHandle);
1522 ret = contacts_record_create(_contacts_company._uri, &dstRecordHandle);
1523 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1525 __ContactsRecordHandle companyHandle(dstRecordHandle);
1527 contacts_record_get_int(srcRecordHandle, _contacts_company.type, &intValue);
1528 contacts_record_set_int(dstRecordHandle, _contacts_company.type, intValue);
1530 contacts_record_get_str_p(srcRecordHandle, _contacts_company.name, &pCharValue);
1531 contacts_record_set_str(dstRecordHandle, _contacts_company.name, pCharValue);
1533 contacts_record_get_str_p(srcRecordHandle, _contacts_company.department, &pCharValue);
1534 contacts_record_set_str(dstRecordHandle, _contacts_company.department, pCharValue);
1536 contacts_record_get_str_p(srcRecordHandle, _contacts_company.job_title, &pCharValue);
1537 contacts_record_set_str(dstRecordHandle, _contacts_company.job_title, pCharValue);
1539 contacts_record_get_str_p(srcRecordHandle, _contacts_company.assistant_name, &pCharValue);
1540 contacts_record_set_str(dstRecordHandle, _contacts_company.assistant_name, pCharValue);
1542 contacts_record_get_str_p(srcRecordHandle, _contacts_company.role, &pCharValue);
1543 contacts_record_set_str(dstRecordHandle, _contacts_company.role, pCharValue);
1545 contacts_record_get_str_p(srcRecordHandle, _contacts_company.logo, &pCharValue);
1546 contacts_record_set_str(dstRecordHandle, _contacts_company.logo, pCharValue);
1548 contacts_record_get_str_p(srcRecordHandle, _contacts_company.location, &pCharValue);
1549 contacts_record_set_str(dstRecordHandle, _contacts_company.location, pCharValue);
1551 contacts_record_get_str_p(srcRecordHandle, _contacts_company.description, &pCharValue);
1552 contacts_record_set_str(dstRecordHandle, _contacts_company.description, pCharValue);
1554 contacts_record_get_str_p(srcRecordHandle, _contacts_company.phonetic_name, &pCharValue);
1555 contacts_record_set_str(dstRecordHandle, _contacts_company.phonetic_name, pCharValue);
1557 contacts_record_add_child_record(dstHandle, _contacts_my_profile.company, dstRecordHandle);
1559 companyHandle.Release();
1563 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.note, &count);
1564 for (i = 0; i < count; i++)
1566 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.note, i, &srcRecordHandle);
1568 ret = contacts_record_create(_contacts_note._uri, &dstRecordHandle);
1569 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1571 __ContactsRecordHandle noteHandle(dstRecordHandle);
1573 contacts_record_get_str_p(srcRecordHandle, _contacts_note.note, &pCharValue);
1574 contacts_record_set_str(dstRecordHandle, _contacts_note.note, pCharValue);
1576 contacts_record_add_child_record(dstHandle, _contacts_my_profile.note, dstRecordHandle);
1578 noteHandle.Release();
1582 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.number, &count);
1583 for (i = 0; i < count; i++)
1585 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.number, i, &srcRecordHandle);
1587 ret = contacts_record_create(_contacts_number._uri, &dstRecordHandle);
1588 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1590 __ContactsRecordHandle numberHandle(dstRecordHandle);
1592 contacts_record_get_int(srcRecordHandle, _contacts_number.type, &intValue);
1593 contacts_record_set_int(dstRecordHandle, _contacts_number.type, intValue);
1595 contacts_record_get_str_p(srcRecordHandle, _contacts_number.label, &pCharValue);
1596 contacts_record_set_str(dstRecordHandle, _contacts_number.label, pCharValue);
1598 contacts_record_get_str_p(srcRecordHandle, _contacts_number.number, &pCharValue);
1599 contacts_record_set_str(dstRecordHandle, _contacts_number.number, pCharValue);
1601 contacts_record_add_child_record(dstHandle, _contacts_my_profile.number, dstRecordHandle);
1603 numberHandle.Release();
1607 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.email, &count);
1608 for (i = 0; i < count; i++)
1610 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.email, i, &srcRecordHandle);
1612 ret = contacts_record_create(_contacts_email._uri, &dstRecordHandle);
1613 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1615 __ContactsRecordHandle emailHandle(dstRecordHandle);
1617 contacts_record_get_int(srcRecordHandle, _contacts_email.type, &intValue);
1618 contacts_record_set_int(dstRecordHandle, _contacts_email.type, intValue);
1620 contacts_record_get_str_p(srcRecordHandle, _contacts_email.label, &pCharValue);
1621 contacts_record_set_str(dstRecordHandle, _contacts_email.label, pCharValue);
1623 contacts_record_get_str_p(srcRecordHandle, _contacts_email.email, &pCharValue);
1624 contacts_record_set_str(dstRecordHandle, _contacts_email.email, pCharValue);
1626 contacts_record_add_child_record(dstHandle, _contacts_my_profile.email, dstRecordHandle);
1628 emailHandle.Release();
1633 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.event, &count);
1634 for (i = 0; i < count; i++)
1636 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.event, i, &srcRecordHandle);
1638 ret = contacts_record_create(_contacts_event._uri, &dstRecordHandle);
1639 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1641 __ContactsRecordHandle eventHandle(dstRecordHandle);
1643 contacts_record_get_int(srcRecordHandle, _contacts_event.type, &intValue);
1644 contacts_record_set_int(dstRecordHandle, _contacts_event.type, intValue);
1646 contacts_record_get_str_p(srcRecordHandle, _contacts_event.label, &pCharValue);
1647 contacts_record_set_str(dstRecordHandle, _contacts_event.label, pCharValue);
1649 contacts_record_get_int(srcRecordHandle, _contacts_event.date, &intValue);
1650 contacts_record_set_int(dstRecordHandle, _contacts_event.date, intValue);
1652 contacts_record_add_child_record(dstHandle, _contacts_my_profile.event, dstRecordHandle);
1654 eventHandle.Release();
1658 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.messenger, &count);
1659 for (i = 0; i < count; i++)
1661 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.messenger, i, &srcRecordHandle);
1663 ret = contacts_record_create(_contacts_messenger._uri, &dstRecordHandle);
1664 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1666 __ContactsRecordHandle imAddressHandle(dstRecordHandle);
1668 contacts_record_get_int(srcRecordHandle, _contacts_messenger.type, &intValue);
1669 contacts_record_set_int(dstRecordHandle, _contacts_messenger.type, intValue);
1671 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.label, &pCharValue);
1672 contacts_record_set_str(dstRecordHandle, _contacts_messenger.label, pCharValue);
1674 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.im_id, &pCharValue);
1675 contacts_record_set_str(dstRecordHandle, _contacts_messenger.im_id, pCharValue);
1677 contacts_record_add_child_record(dstHandle, _contacts_my_profile.messenger, dstRecordHandle);
1679 imAddressHandle.Release();
1683 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.address, &count);
1684 for (i = 0; i < count; i++)
1686 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.address, i, &srcRecordHandle);
1688 ret = contacts_record_create(_contacts_address._uri, &dstRecordHandle);
1689 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1691 __ContactsRecordHandle addressHandle(dstRecordHandle);
1693 contacts_record_get_int(srcRecordHandle, _contacts_address.type, &intValue);
1694 contacts_record_set_int(dstRecordHandle, _contacts_address.type, intValue);
1696 contacts_record_get_str_p(srcRecordHandle, _contacts_address.label, &pCharValue);
1697 contacts_record_set_str(dstRecordHandle, _contacts_address.label, pCharValue);
1699 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postbox, &pCharValue);
1700 contacts_record_set_str(dstRecordHandle, _contacts_address.postbox, pCharValue);
1702 contacts_record_get_str_p(srcRecordHandle, _contacts_address.extended, &pCharValue);
1703 contacts_record_set_str(dstRecordHandle, _contacts_address.extended, pCharValue);
1705 contacts_record_get_str_p(srcRecordHandle, _contacts_address.street, &pCharValue);
1706 contacts_record_set_str(dstRecordHandle, _contacts_address.street, pCharValue);
1708 contacts_record_get_str_p(srcRecordHandle, _contacts_address.locality, &pCharValue);
1709 contacts_record_set_str(dstRecordHandle, _contacts_address.locality, pCharValue);
1711 contacts_record_get_str_p(srcRecordHandle, _contacts_address.region, &pCharValue);
1712 contacts_record_set_str(dstRecordHandle, _contacts_address.region, pCharValue);
1714 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postal_code, &pCharValue);
1715 contacts_record_set_str(dstRecordHandle, _contacts_address.postal_code, pCharValue);
1717 contacts_record_get_str_p(srcRecordHandle, _contacts_address.country, &pCharValue);
1718 contacts_record_set_str(dstRecordHandle, _contacts_address.country, pCharValue);
1720 contacts_record_add_child_record(dstHandle, _contacts_my_profile.address, dstRecordHandle);
1722 addressHandle.Release();
1726 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.url, &count);
1727 for (i = 0; i < count; i++)
1729 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.url, i, &srcRecordHandle);
1731 ret = contacts_record_create(_contacts_url._uri, &dstRecordHandle);
1732 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1734 __ContactsRecordHandle urlHandle(dstRecordHandle);
1736 contacts_record_get_int(srcRecordHandle, _contacts_url.type, &intValue);
1737 contacts_record_set_int(dstRecordHandle, _contacts_url.type, intValue);
1739 contacts_record_get_str_p(srcRecordHandle, _contacts_url.label, &pCharValue);
1740 contacts_record_set_str(dstRecordHandle, _contacts_url.label, pCharValue);
1742 contacts_record_get_str_p(srcRecordHandle, _contacts_url.url, &pCharValue);
1743 contacts_record_set_str(dstRecordHandle, _contacts_url.url, pCharValue);
1745 contacts_record_add_child_record(dstHandle, _contacts_my_profile.url, dstRecordHandle);
1747 urlHandle.Release();
1751 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.nickname, &count);
1752 for (i = 0; i < count; i++)
1754 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.nickname, i, &srcRecordHandle);
1756 ret = contacts_record_create(_contacts_nickname._uri, &dstRecordHandle);
1757 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1759 __ContactsRecordHandle nicknameHandle(dstRecordHandle);
1761 contacts_record_get_str_p(srcRecordHandle, _contacts_nickname.name, &pCharValue);
1762 contacts_record_set_str(dstRecordHandle, _contacts_nickname.name, pCharValue);
1764 contacts_record_add_child_record(dstHandle, _contacts_my_profile.nickname, dstRecordHandle);
1766 nicknameHandle.Release();
1770 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.relationship, &count);
1771 for (i = 0; i < count; i++)
1773 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.relationship, i, &srcRecordHandle);
1775 ret = contacts_record_create(_contacts_relationship._uri, &dstRecordHandle);
1776 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1778 __ContactsRecordHandle relationshipHandle(dstRecordHandle);
1780 contacts_record_get_str_p(srcRecordHandle, _contacts_relationship.name, &pCharValue);
1781 contacts_record_set_str(dstRecordHandle, _contacts_relationship.name, pCharValue);
1783 contacts_record_add_child_record(dstHandle, _contacts_my_profile.relationship, dstRecordHandle);
1785 relationshipHandle.Release();
1789 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.image, &count);
1792 contacts_record_get_int(srcHandle, _contacts_my_profile.id, &recordId);
1794 if (count > 0 && recordId == 0)
1796 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.image, 0, &srcRecordHandle);
1798 ret = contacts_record_create(_contacts_image._uri, &dstRecordHandle);
1799 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1801 __ContactsRecordHandle imageHandle(dstRecordHandle);
1803 contacts_record_get_int(srcRecordHandle, _contacts_image.type, &intValue);
1804 contacts_record_set_int(dstRecordHandle, _contacts_image.type, intValue);
1806 contacts_record_get_str_p(srcRecordHandle, _contacts_image.label, &pCharValue);
1807 contacts_record_set_str(dstRecordHandle, _contacts_image.label, pCharValue);
1809 contacts_record_get_str_p(srcRecordHandle, _contacts_image.path, &pCharValue);
1810 contacts_record_set_str(dstRecordHandle, _contacts_image.path, pCharValue);
1812 contacts_record_add_child_record(dstHandle, _contacts_contact.image, dstRecordHandle);
1814 imageHandle.Release();
1821 _AddressbookImpl::OnContactChanged(void)
1823 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1828 std::unique_ptr<IList, AllElementsDeleter> pChangedContactList(GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact));
1829 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1831 if (pChangedContactList->GetCount() > 0)
1833 if (__pIAddressbookEventListener != null)
1835 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1837 else if (__pIAddressbookChangeEventListener != null)
1839 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1843 RecordEventType recordEventType = RECORD_ADDED;
1844 std::unique_ptr<IEnumerator> pEnum(pChangedContactList->GetEnumeratorN());
1845 std::unique_ptr<Contact> pContact(null);
1847 while (pEnum->MoveNext() == E_SUCCESS)
1849 ContactChangeInfo* pContactChagneInfo = static_cast<ContactChangeInfo*>(pEnum->GetCurrent());
1851 if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
1853 recordEventType = RECORD_ADDED;
1854 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
1855 if (pContact == null)
1857 if (GetLastResult() == E_OBJ_NOT_FOUND)
1867 else if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
1869 recordEventType = RECORD_UPDATED;
1870 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
1871 if (pContact == null)
1873 if (GetLastResult() == E_OBJ_NOT_FOUND)
1885 recordEventType = RECORD_REMOVED;
1886 pContact.reset(new (std::nothrow) Contact());
1887 if (pContact == null)
1889 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1893 _RecordImpl::GetInstance(*pContact)->SetRecordId(pContactChagneInfo->GetContactId());
1896 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CONTACT, *pContact, null, null);
1904 _AddressbookImpl::OnCategoryChanged(void)
1906 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1911 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup));
1912 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1914 if (pChangedCategoryList->GetCount() > 0)
1916 if (__pIAddressbookEventListener != null)
1918 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1920 else if (__pIAddressbookChangeEventListener != null)
1922 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1926 RecordEventType recordEventType = RECORD_ADDED;
1927 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
1928 std::unique_ptr<Category> pCategory(null);
1930 while (pEnum->MoveNext() == E_SUCCESS)
1932 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
1934 if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
1936 recordEventType = RECORD_ADDED;
1937 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1938 if (pCategory == null)
1940 if (GetLastResult() == E_OBJ_NOT_FOUND)
1950 else if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
1952 recordEventType = RECORD_UPDATED;
1953 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1954 if (pCategory == null)
1956 if (GetLastResult() == E_OBJ_NOT_FOUND)
1968 recordEventType = RECORD_REMOVED;
1969 pCategory.reset(new (std::nothrow) Category());
1970 if (pCategory == null)
1972 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1976 _RecordImpl::GetInstance(*pCategory)->SetRecordId(pCategoryChagneInfo->GetCategoryId());
1979 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
1987 _AddressbookImpl::OnRelationChanged(void)
1989 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null)
1994 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation));
1995 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1997 if (pChangedCategoryList->GetCount() > 0)
1999 if (__pIAddressbookEventListener != null)
2001 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
2005 RecordEventType recordEventType = RECORD_ADDED;
2006 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
2007 std::unique_ptr<Category> pCategory(null);
2009 while (pEnum->MoveNext() == E_SUCCESS)
2011 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
2013 recordEventType = RECORD_UPDATED;
2014 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2015 if (pCategory == null)
2017 if (GetLastResult() == E_OBJ_NOT_FOUND)
2027 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2034 _AddressbookImpl::GetInstance(Addressbook& addressbook)
2036 return addressbook.__pAddressbookImpl;
2039 const _AddressbookImpl*
2040 _AddressbookImpl::GetInstance(const Addressbook& addressbook)
2042 return addressbook.__pAddressbookImpl;