2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 * @file FScl_AddressbookImpl.cpp
18 * @brief This is the implementation for _AddressbookImpl class.
20 * This file contains definitions of @e _AddressbookImpl class.
23 #include <FBaseColIListT.h>
24 #include <FBaseColArrayListT.h>
25 #include <FBaseResult.h>
26 #include <FBaseLongLong.h>
27 #include <FBaseInteger.h>
28 #include <FSclContact.h>
29 #include <FSclCategory.h>
30 #include <FSclUserProfile.h>
31 #include <FSclContactChangeInfo.h>
32 #include <FSclCategoryChangeInfo.h>
33 #include <FSclAddressbook.h>
34 #include <FSclIAddressbookEventListener.h>
35 #include <FSclIAddressbookChangeEventListener.h>
36 #include <FSclIRecordEventListener.h>
37 #include <FApp_AppInfo.h>
38 #include <FBaseSysLog.h>
39 #include <FBase_StringConverter.h>
40 #include "FScl_AddressbookImpl.h"
41 #include "FScl_AddressbookUtil.h"
42 #include "FScl_CategoryChangeInfoImpl.h"
43 #include "FScl_CategoryImpl.h"
44 #include "FScl_ContactChangeInfoImpl.h"
45 #include "FScl_ContactDbMonitor.h"
46 #include "FScl_ContactImpl.h"
47 #include "FScl_RecordImpl.h"
48 #include "FScl_UserProfileImpl.h"
49 #include "FScl_ContactDbConnector.h"
51 using namespace Tizen::App;
52 using namespace Tizen::Base;
53 using namespace Tizen::Base::Collection;
54 using namespace Tizen::Graphics;
56 namespace Tizen { namespace Social
59 _AddressbookImpl::_AddressbookImpl(void)
60 : __pIRecordEventListener(null)
61 , __pIAddressbookEventListener(null)
62 , __pIAddressbookChangeEventListener(null)
63 , __dbVersionForContact(0)
64 , __dbVersionForGroup(0)
65 , __dbVersionForRelation(0)
66 , __addressbookId(INVALID_ADDRESSBOOK_ID)
72 _AddressbookImpl::~_AddressbookImpl(void)
74 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
76 _ContactDbMonitor* pDbMonitor = _ContactDbMonitor::GetInstance();
77 if (pDbMonitor != null)
79 pDbMonitor->RemoveListener(*this);
85 _AddressbookImpl::Construct(void)
87 static AccountId accountId = 0;
92 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
95 contacts_record_h recordHandle = null;
96 int ret = contacts_db_get_record(_contacts_address_book._uri, DEFAULT_ADDRESSBOOK_ID, &recordHandle);
97 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
98 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);
100 contacts_record_get_str_p(recordHandle, _contacts_address_book.name, &pName);
101 contacts_record_get_int(recordHandle, _contacts_address_book.account_id, &accountId);
105 contacts_record_destroy(recordHandle, true);
108 __addressbookId = DEFAULT_ADDRESSBOOK_ID;
109 __accountId = accountId;
116 _AddressbookImpl::SetRecordEventListener(IRecordEventListener* pListener)
118 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
120 result r = E_SUCCESS;
122 if (pListener != null)
124 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null)
126 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
127 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
129 r = pContactDbMonitor->AddListener(*this);
130 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
133 __dbVersionForContact = GetLatestVersion();
134 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
136 __dbVersionForGroup = __dbVersionForContact;
137 __dbVersionForRelation = __dbVersionForContact;
139 __pIAddressbookEventListener = null;
140 __pIAddressbookChangeEventListener = null;
141 __pIRecordEventListener = pListener;
145 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
147 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
148 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()))
149 pContactDbMonitor->RemoveListener(*this);
152 __pIAddressbookEventListener = null;
153 __pIAddressbookChangeEventListener = null;
154 __pIRecordEventListener = null;
161 _AddressbookImpl::SetAddressbookEventListener(IAddressbookEventListener* pListener)
163 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
165 result r = E_SUCCESS;
167 if (pListener != null)
169 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null)
171 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
172 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
174 r = pContactDbMonitor->AddListener(*this);
175 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
178 __dbVersionForContact = GetLatestVersion();
179 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
181 __dbVersionForGroup = __dbVersionForContact;
182 __dbVersionForRelation = __dbVersionForContact;
184 __pIRecordEventListener = null;
185 __pIAddressbookChangeEventListener = null;
186 __pIAddressbookEventListener = pListener;
190 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
192 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
193 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
195 pContactDbMonitor->RemoveListener(*this);
198 __pIAddressbookEventListener = null;
199 __pIAddressbookChangeEventListener = null;
200 __pIRecordEventListener = null;
207 _AddressbookImpl::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
209 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
211 result r = E_SUCCESS;
213 if (pListener != null)
215 if (__pIAddressbookEventListener == null && __pIAddressbookChangeEventListener == null && __pIRecordEventListener == null)
217 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
218 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
220 r = pContactDbMonitor->AddListener(*this);
221 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
224 __dbVersionForContact = GetLatestVersion();
225 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
227 __dbVersionForGroup = __dbVersionForContact;
228 __dbVersionForRelation = __dbVersionForContact;
230 __pIRecordEventListener = null;
231 __pIAddressbookEventListener = null;
232 __pIAddressbookChangeEventListener = pListener;
236 if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null || __pIRecordEventListener != null)
238 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
239 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
241 pContactDbMonitor->RemoveListener(*this);
244 __pIAddressbookEventListener = null;
245 __pIAddressbookChangeEventListener = null;
246 __pIRecordEventListener = null;
253 _AddressbookImpl::SetId(AddressbookId addressbookId)
255 __addressbookId = addressbookId;
259 _AddressbookImpl::SetAccountId(AccountId accountId)
261 __accountId = accountId;
265 _AddressbookImpl::SetName(const String& name)
271 _AddressbookImpl::GetId(void) const
273 return __addressbookId;
277 _AddressbookImpl::GetAccountId(void) const
283 _AddressbookImpl::GetName(void) const
289 _AddressbookImpl::AddContact(Contact& contact)
291 if (_ContactImpl::GetInstance(contact)->IsRemoved())
293 result r = _ContactImpl::GetInstance(contact)->Invalidate();
294 SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
297 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));
298 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));
299 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
302 contacts_record_h recordHandle = null;
304 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
306 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
308 int ret = contacts_db_insert_record(recordHandle, &recordId);
309 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));
310 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
311 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
313 ret = contacts_db_get_record(_contacts_contact._uri, recordId, &recordHandle);
314 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.");
315 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));
316 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
318 _ContactImpl::GetInstance(contact)->SetContactRecordHandle(recordHandle);
319 _RecordImpl::GetInstance(contact)->SetRecordId(recordId);
325 _AddressbookImpl::AddCategory(Category& category)
327 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));
328 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
331 contacts_record_h recordHandle = null;
332 std::unique_ptr<IListT<int> > pList(null);
334 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
336 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
338 // It is not allowed to have a same name with other.
340 char* pCharValue = null;
341 contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue);
343 __Filter<__ContactsGroup> filter;
345 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
346 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
347 filter.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue);
349 __Query<__ContactsGroup> query;
351 query.SetFilter(filter);
353 count = _AddressbookUtil::GetCountWithQuery(query);
354 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
355 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));
358 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
360 contacts_record_set_int(recordHandle, _contacts_group.address_book_id, __addressbookId);
362 int ret = contacts_db_insert_record(recordHandle, &recordId);
363 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));
364 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
365 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
367 ret = contacts_db_get_record(_contacts_group._uri, recordId, &recordHandle);
368 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));
369 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
370 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%d] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
372 _CategoryImpl::GetInstance(category)->SetRecordHandle(recordHandle);
373 _RecordImpl::GetInstance(category)->SetRecordId(recordId);
375 pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
376 if (pList != null && pList->GetCount() > 0)
378 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
380 while (pEnum->MoveNext() == E_SUCCESS)
383 pEnum->GetCurrent(tableId);
385 AddMemberToCategory(category.GetRecordId(), tableId);
388 _CategoryImpl::GetInstance(category)->ClearAddedMemberList();
395 _AddressbookImpl::RemoveContact(RecordId contactId)
397 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);
398 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
401 int ret = CONTACTS_ERROR_NONE;
402 contacts_record_h recordHandle = null;
404 ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
405 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));
406 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
407 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
409 contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
411 contacts_record_destroy(recordHandle, true);
413 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
415 ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
416 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));
417 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));
418 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
424 _AddressbookImpl::RemoveContact(Contact& contact)
426 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));
427 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
429 result r = RemoveContact(contact.GetRecordId());
430 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
432 _ContactImpl::GetInstance(contact)->SetAsRemoved();
433 _RecordImpl::GetInstance(contact)->SetRecordId(INVALID_RECORD_ID);
439 _AddressbookImpl::RemoveCategory(RecordId categoryId)
441 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);
442 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
445 int ret = CONTACTS_ERROR_NONE;
446 contacts_record_h recordHandle = null;
448 ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
449 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.");
450 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));
451 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
453 __ContactsRecordHandle categoryHandle(recordHandle);
455 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
456 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
458 bool isReadOnly = false;
459 contacts_record_get_bool(recordHandle, _contacts_group.is_read_only, &isReadOnly);
460 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));
462 ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
463 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));
464 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));
465 //SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed remove a category.");
471 _AddressbookImpl::UpdateContact(const Contact& contact)
473 RecordId contactId = contact.GetRecordId();
474 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
475 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));
476 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
478 contacts_record_h recordHandle = null;
481 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
482 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));
483 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));
484 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
486 contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
488 contacts_record_destroy(recordHandle, true);
489 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
491 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
493 ret = contacts_db_update_record(recordHandle);
494 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));
495 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));
496 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
497 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
499 ret = contacts_db_get_record(_contacts_contact._uri, contact.GetRecordId(), &recordHandle);
500 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));
501 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));
502 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
504 _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(recordHandle);
510 _AddressbookImpl::UpdateCategory(const Category& category)
512 RecordId categoryId = category.GetRecordId();
513 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));
514 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));
515 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
517 contacts_record_h recordHandle = null;
519 int ret = CONTACTS_ERROR_NONE;
521 ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
522 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));
523 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));
524 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
526 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
528 contacts_record_destroy(recordHandle, true);
530 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
532 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
534 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
537 char* pCharValue = null;
539 contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue);
540 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
542 __Filter<__ContactsGroup> filter1;
544 filter1.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
545 filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
546 filter1.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue);
548 __Filter<__ContactsGroup> filter2;
550 filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_LESS_THAN, intValue);
551 filter2.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
552 filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_GREATER_THAN, intValue);
554 filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
555 filter1.AddFilter(filter2);
557 __Query<__ContactsGroup> query;
559 query.SetFilter(filter1);
561 count = _AddressbookUtil::GetCountWithQuery(query);
562 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
563 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));
566 ret = contacts_db_update_record(recordHandle);
567 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));
568 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));
569 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
570 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
572 ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
573 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));
574 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));
575 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
577 _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(recordHandle);
579 std::unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
580 if (pList != null && pList->GetCount() > 0)
583 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
584 while (pEnum->MoveNext() == E_SUCCESS)
586 pEnum->GetCurrent(tableId);
588 AddMemberToCategory(category.GetRecordId(), tableId);
591 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList();
594 pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN());
595 if (pList != null && pList->GetCount() > 0)
598 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
599 while (pEnum->MoveNext() == E_SUCCESS)
601 pEnum->GetCurrent(tableId);
603 RemoveMemberFromCategory(category.GetRecordId(), tableId);
606 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList();
613 _AddressbookImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
615 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);
616 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);
617 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
619 contacts_record_h recordHandle = null;
620 int addressbookId = 0;
621 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
622 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));
623 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
624 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
625 contacts_record_get_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId);
626 contacts_record_destroy(recordHandle, true);
628 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));
630 ret = contacts_group_add_contact(categoryId, contactId);
631 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
632 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));
633 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
639 _AddressbookImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
641 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);
642 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);
643 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
645 contacts_record_h recordHandle = null;
646 int addressbookId = 0;
647 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
648 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));
649 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));
650 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
651 contacts_record_get_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId);
652 contacts_record_destroy(recordHandle, true);
654 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));
656 ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
657 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));
658 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));
659 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
661 contacts_record_get_int(recordHandle, _contacts_group.address_book_id, &addressbookId);
662 contacts_record_destroy(recordHandle, true);
664 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));
666 ret = contacts_group_remove_contact(categoryId, contactId);
667 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
668 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));
669 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
675 _AddressbookImpl::GetAllCategoriesN(void) const
677 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
681 __Filter<__ContactsGroup> filter;
683 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
685 __Query<__ContactsGroup> query;
687 query.SetFilter(filter);
688 query.SetSort(_contacts_group.name, true);
691 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
692 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
698 _AddressbookImpl::GetCategoriesByContactN(RecordId contactId) const
700 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
701 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));
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));
876 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
877 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
879 __Filter<__ContactsContact> filter;
881 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
882 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
883 filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
885 __Query<__ContactsContact> query;
887 query.SetFilter(filter);
888 query.SetSort(_contacts_contact.display_name, true);
889 query.SetDistinct(true);
891 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
892 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
899 _AddressbookImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
901 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));
902 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
905 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
907 int count = phoneNumber.GetLength();
908 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));
913 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
914 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
916 __Filter<__ContactsContactNumber> filter;
918 filter.AddInt(_contacts_contact_number.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
919 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
920 filter.AddString(_contacts_contact_number.normalized_number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
922 unsigned int projectionIds[1];
923 projectionIds[0] = _contacts_contact_number.contact_id;
925 __Query<__ContactsContactNumber> query;
927 query.SetProjection(projectionIds, 1);
928 query.SetFilter(filter);
929 query.SetDistinct(true);
930 query.SetSort(_contacts_contact_number.display_name, true);
932 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
933 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
939 _AddressbookImpl::GetCategoryCount(void) const
941 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
947 __Filter<__ContactsGroup> filter;
949 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
951 __Query<__ContactsGroup> query;
953 query.SetFilter(filter);
955 count = _AddressbookUtil::GetCountWithQuery(query);
956 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
962 _AddressbookImpl::GetContactCount(void) const
964 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
970 __Filter<__ContactsContact> filter;
972 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
974 __Query<__ContactsContact> query;
976 query.SetFilter(filter);
978 count = _AddressbookUtil::GetCountWithQuery(query);
979 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
985 _AddressbookImpl::GetContactN(RecordId contactId) const
987 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
988 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
991 contacts_record_h contactHandle = null;
995 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
996 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
998 int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &contactHandle);
999 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1000 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1001 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1003 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle);
1005 contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue);
1006 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1008 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
1010 return pContact.release();
1014 _AddressbookImpl::GetCategoryN(RecordId categoryId) const
1016 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
1017 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1019 contacts_record_h recordHandle = null;
1024 int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
1025 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1026 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1027 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1029 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
1030 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1032 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
1033 SysTryReturn(NID_SCL, intValue == categoryId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1035 __Filter<__ContactsGroupRelation> filter;
1037 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1039 __Query<__ContactsGroupRelation> query;
1041 query.SetFilter(filter);
1043 int count = _AddressbookUtil::GetCountWithQuery(query);
1044 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1046 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(recordHandle);
1047 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1048 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1050 return pCategory.release();
1054 _AddressbookImpl::GetLatestVersion(void) const
1056 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1058 int latestVersion = -1;
1062 int ret = contacts_db_get_current_version(&latestVersion);
1063 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, -1, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1064 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1066 return latestVersion;
1070 _AddressbookImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1072 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);
1073 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()));
1091 int latestVersion1 = 0;
1092 int latestVersion2 = 0;
1094 std::unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion1));
1095 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1097 std::unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion2));
1098 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1100 std::unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1101 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1103 result r = pChangeList->AddItems(*pChangedGroups);
1104 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1106 r = pChangeList->AddItems(*pChangedRelations);
1107 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1109 pChangedGroups->RemoveAll(false);
1110 pChangedRelations->RemoveAll(false);
1112 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1114 return pChangeList.release();
1118 _AddressbookImpl::GetChangedContactInfoListN(int version, int& latestVersion) const
1120 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);
1121 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1125 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1126 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1128 return pChangedContacts;
1132 _AddressbookImpl::GetChangedCategoryInfoListN(int version, int& latestVersion) const
1134 return GetChangedGroupsAfterN(version, latestVersion);
1138 _AddressbookImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1140 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);
1141 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1145 IList* pChangedGroups = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1146 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1148 return pChangedGroups;
1152 _AddressbookImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1154 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);
1155 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1159 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1160 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1162 return pChangedRelations;
1166 _AddressbookImpl::AddContacts(const Tizen::Base::Collection::IList& contactList, Tizen::Base::Collection::IListT<RecordId>* pContactIdList)
1168 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1169 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1171 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1172 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1174 Contact* pContact = null;
1175 int ret = CONTACTS_ERROR_NONE;
1176 int* pContactIds = null;
1177 unsigned int contactsCount = 0;
1179 contacts_record_h recordHandle = null;
1180 contacts_list_h listHandle = null;
1182 ret = contacts_list_create(&listHandle);
1183 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1185 while (pContactEnum->MoveNext() == E_SUCCESS)
1187 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1189 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1191 contacts_list_destroy(listHandle, false);
1192 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1193 return E_INVALID_ARG;
1195 if (pContact->GetRecordId() != INVALID_RECORD_ID)
1197 contacts_list_destroy(listHandle, false);
1198 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1199 return E_INVALID_ARG;
1202 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1203 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
1204 contacts_list_add(listHandle, recordHandle);
1207 ret = contacts_db_insert_records(listHandle, &pContactIds, &contactsCount);
1208 contacts_list_destroy(listHandle, false);
1209 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));
1210 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1211 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1212 SysTryReturn(NID_SCL, pContactIds, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1214 int* pTemp = pContactIds;
1216 if (pContactIdList != null)
1218 for (unsigned int i = 0; i < contactsCount; i++)
1220 pContactIdList->Add(*pTemp);
1231 _AddressbookImpl::UpdateContacts(const Tizen::Base::Collection::IList& contactList)
1233 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1234 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1236 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1237 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1239 Contact* pContact = null;
1240 int ret = CONTACTS_ERROR_NONE;
1241 contacts_record_h recordHandle = null;
1242 contacts_list_h listHandle = null;
1244 ret = contacts_list_create(&listHandle);
1245 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1247 while (pContactEnum->MoveNext() == E_SUCCESS)
1249 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1251 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1253 contacts_list_destroy(listHandle, false);
1254 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1255 return E_INVALID_ARG;
1257 if (pContact->GetRecordId() == INVALID_RECORD_ID)
1259 contacts_list_destroy(listHandle, false);
1260 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1261 return E_INVALID_ARG;
1264 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1265 contacts_list_add(listHandle, recordHandle);
1268 ret = contacts_db_update_records(listHandle);
1269 contacts_list_destroy(listHandle, false);
1270 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));
1271 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1272 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));
1273 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1279 _AddressbookImpl::RemoveContacts(const Tizen::Base::Collection::IListT<RecordId>& contactIdList)
1281 SysTryReturn(NID_SCL, contactIdList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactIdList is empty.", GetErrorMessage(E_INVALID_ARG));
1282 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1284 std::unique_ptr<IEnumeratorT<RecordId> > pContactIdEnum(contactIdList.GetEnumeratorN());
1285 SysTryReturnResult(NID_SCL, pContactIdEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1287 RecordId contactId = INVALID_RECORD_ID;
1288 int ret = CONTACTS_ERROR_NONE;
1289 int count = contactIdList.GetCount();
1290 std::unique_ptr<int[]> pRecordIds(new (std::nothrow) int[count]);
1291 int* pInt = pRecordIds.get();
1294 while (pContactIdEnum->MoveNext() == E_SUCCESS)
1296 pContactIdEnum->GetCurrent(contactId);
1297 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));
1303 ret = contacts_db_delete_records(_contacts_contact._uri, pInt, count);
1304 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));
1305 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));
1311 _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
1313 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1316 int existingRecordId = 0;
1317 int ret = CONTACTS_ERROR_NONE;
1318 result r = E_SUCCESS;
1319 contacts_record_h recordHandle = null;
1321 std::unique_ptr<UserProfile> pExistingProfile(GetUserProfileN());
1322 SysTryReturn(NID_SCL, pExistingProfile != null || GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1324 if (pExistingProfile != null)
1326 recordHandle = _UserProfileImpl::GetInstance(*pExistingProfile)->GetUserProfileHandle();
1327 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &existingRecordId);
1330 if (pUserProfile != null)
1332 SysTryReturn(NID_SCL, !((_UserProfileImpl::GetInstance(*pUserProfile))->IsEmpty()), E_SYSTEM, E_SYSTEM, "[%s] UserProfile is Empty.", GetErrorMessage(E_SYSTEM));
1334 recordHandle = _UserProfileImpl::GetInstance(*pUserProfile)->GetUserProfileHandle();
1335 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &recordId);
1338 if (pExistingProfile != null)
1340 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
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));
1342 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1345 contacts_record_h newRecordHandle = null;
1346 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1347 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));
1349 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1350 if (ret != CONTACTS_ERROR_NONE)
1352 contacts_record_destroy(newRecordHandle, true);
1353 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1357 ret = contacts_db_insert_record(newRecordHandle, &recordId);
1358 contacts_record_destroy(newRecordHandle, true);
1359 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));
1360 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1362 else if (recordId > 0)
1364 if (recordId == existingRecordId)
1366 contacts_record_h newRecordHandle = null;
1367 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1368 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));
1370 ret = contacts_db_update_record(newRecordHandle);
1371 contacts_record_destroy(newRecordHandle, true);
1372 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));
1373 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1377 if (pExistingProfile != null)
1379 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
1380 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));
1381 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1384 contacts_record_h newRecordHandle = null;
1385 ret = contacts_record_create(_contacts_my_profile._uri, &newRecordHandle);
1386 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1388 r = CopyMyProfileContents(recordHandle, newRecordHandle);
1391 contacts_record_destroy(newRecordHandle, true);
1392 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1393 return E_OUT_OF_MEMORY;
1397 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1398 if (ret != CONTACTS_ERROR_NONE)
1400 contacts_record_destroy(newRecordHandle, true);
1401 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1405 ret = contacts_db_insert_record(newRecordHandle, &recordId);
1406 contacts_record_destroy(newRecordHandle, true);
1407 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));
1408 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1414 if (pExistingProfile != null)
1416 ret = contacts_db_delete_record(_contacts_my_profile._uri, existingRecordId);
1417 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));
1418 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1426 _AddressbookImpl::GetUserProfileN(void) const
1428 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1432 __Filter<__ContactsUserProfile> filter;
1434 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
1436 __Query<__ContactsUserProfile> query;
1438 query.SetFilter(filter);
1440 std::unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
1441 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1442 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
1443 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
1445 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
1446 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
1452 _AddressbookImpl::IsUserProfileChangedAfter(int version) const
1454 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);
1455 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1457 UserProfile* pExistingProfile = GetUserProfileN();
1458 if (pExistingProfile == null)
1463 delete pExistingProfile;
1467 int latestVersion = 0;
1468 int count = _AddressbookUtil::GetChangedItemCountByVersion<__ContactsMyProfileUpdatedInfo>(__addressbookId, version, latestVersion);
1469 SysTryReturn(NID_SCL, count >= 0, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1480 _AddressbookImpl::CopyMyProfileContents(contacts_record_h srcHandle, contacts_record_h dstHandle)
1482 int ret = CONTACTS_ERROR_NONE;
1484 unsigned int count = 0;
1486 char* pCharValue = null;
1488 contacts_record_h srcRecordHandle = null;
1489 contacts_record_h dstRecordHandle = null;
1492 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.name, &count);
1495 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.name, 0, &srcRecordHandle);
1497 ret = contacts_record_create(_contacts_name._uri, &dstRecordHandle);
1498 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1500 __ContactsRecordHandle nameHandle(dstRecordHandle);
1502 contacts_record_get_str(srcRecordHandle, _contacts_name.first, &pCharValue);
1503 contacts_record_set_str(dstRecordHandle, _contacts_name.first, pCharValue);
1505 contacts_record_get_str(srcRecordHandle, _contacts_name.last, &pCharValue);
1506 contacts_record_set_str(dstRecordHandle, _contacts_name.last, pCharValue);
1508 contacts_record_get_str(srcRecordHandle, _contacts_name.addition, &pCharValue);
1509 contacts_record_set_str(dstRecordHandle, _contacts_name.addition, pCharValue);
1511 contacts_record_get_str(srcRecordHandle, _contacts_name.suffix, &pCharValue);
1512 contacts_record_set_str(dstRecordHandle, _contacts_name.suffix, pCharValue);
1514 contacts_record_get_str(srcRecordHandle, _contacts_name.prefix, &pCharValue);
1515 contacts_record_set_str(dstRecordHandle, _contacts_name.prefix, pCharValue);
1517 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_first, &pCharValue);
1518 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_first, pCharValue);
1520 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
1521 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_middle, pCharValue);
1523 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_last, &pCharValue);
1524 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_last, pCharValue);
1526 contacts_record_add_child_record(dstHandle, _contacts_my_profile.name, dstRecordHandle);
1528 nameHandle.Release();
1532 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.company, &count);
1533 for (i = 0; i < count; i++)
1535 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.company, i, &srcRecordHandle);
1537 ret = contacts_record_create(_contacts_company._uri, &dstRecordHandle);
1538 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1540 __ContactsRecordHandle companyHandle(dstRecordHandle);
1542 contacts_record_get_int(srcRecordHandle, _contacts_company.type, &intValue);
1543 contacts_record_set_int(dstRecordHandle, _contacts_company.type, intValue);
1545 contacts_record_get_str_p(srcRecordHandle, _contacts_company.name, &pCharValue);
1546 contacts_record_set_str(dstRecordHandle, _contacts_company.name, pCharValue);
1548 contacts_record_get_str_p(srcRecordHandle, _contacts_company.department, &pCharValue);
1549 contacts_record_set_str(dstRecordHandle, _contacts_company.department, pCharValue);
1551 contacts_record_get_str_p(srcRecordHandle, _contacts_company.job_title, &pCharValue);
1552 contacts_record_set_str(dstRecordHandle, _contacts_company.job_title, pCharValue);
1554 contacts_record_get_str_p(srcRecordHandle, _contacts_company.assistant_name, &pCharValue);
1555 contacts_record_set_str(dstRecordHandle, _contacts_company.assistant_name, pCharValue);
1557 contacts_record_get_str_p(srcRecordHandle, _contacts_company.role, &pCharValue);
1558 contacts_record_set_str(dstRecordHandle, _contacts_company.role, pCharValue);
1560 contacts_record_get_str_p(srcRecordHandle, _contacts_company.logo, &pCharValue);
1561 contacts_record_set_str(dstRecordHandle, _contacts_company.logo, pCharValue);
1563 contacts_record_get_str_p(srcRecordHandle, _contacts_company.location, &pCharValue);
1564 contacts_record_set_str(dstRecordHandle, _contacts_company.location, pCharValue);
1566 contacts_record_get_str_p(srcRecordHandle, _contacts_company.description, &pCharValue);
1567 contacts_record_set_str(dstRecordHandle, _contacts_company.description, pCharValue);
1569 contacts_record_get_str_p(srcRecordHandle, _contacts_company.phonetic_name, &pCharValue);
1570 contacts_record_set_str(dstRecordHandle, _contacts_company.phonetic_name, pCharValue);
1572 contacts_record_add_child_record(dstHandle, _contacts_my_profile.company, dstRecordHandle);
1574 companyHandle.Release();
1578 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.note, &count);
1579 for (i = 0; i < count; i++)
1581 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.note, i, &srcRecordHandle);
1583 ret = contacts_record_create(_contacts_note._uri, &dstRecordHandle);
1584 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1586 __ContactsRecordHandle noteHandle(dstRecordHandle);
1588 contacts_record_get_str_p(srcRecordHandle, _contacts_note.note, &pCharValue);
1589 contacts_record_set_str(dstRecordHandle, _contacts_note.note, pCharValue);
1591 contacts_record_add_child_record(dstHandle, _contacts_my_profile.note, dstRecordHandle);
1593 noteHandle.Release();
1597 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.number, &count);
1598 for (i = 0; i < count; i++)
1600 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.number, i, &srcRecordHandle);
1602 ret = contacts_record_create(_contacts_number._uri, &dstRecordHandle);
1603 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1605 __ContactsRecordHandle numberHandle(dstRecordHandle);
1607 contacts_record_get_int(srcRecordHandle, _contacts_number.type, &intValue);
1608 contacts_record_set_int(dstRecordHandle, _contacts_number.type, intValue);
1610 contacts_record_get_str_p(srcRecordHandle, _contacts_number.label, &pCharValue);
1611 contacts_record_set_str(dstRecordHandle, _contacts_number.label, pCharValue);
1613 contacts_record_get_str_p(srcRecordHandle, _contacts_number.number, &pCharValue);
1614 contacts_record_set_str(dstRecordHandle, _contacts_number.number, pCharValue);
1616 contacts_record_add_child_record(dstHandle, _contacts_my_profile.number, dstRecordHandle);
1618 numberHandle.Release();
1622 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.email, &count);
1623 for (i = 0; i < count; i++)
1625 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.email, i, &srcRecordHandle);
1627 ret = contacts_record_create(_contacts_email._uri, &dstRecordHandle);
1628 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1630 __ContactsRecordHandle emailHandle(dstRecordHandle);
1632 contacts_record_get_int(srcRecordHandle, _contacts_email.type, &intValue);
1633 contacts_record_set_int(dstRecordHandle, _contacts_email.type, intValue);
1635 contacts_record_get_str_p(srcRecordHandle, _contacts_email.label, &pCharValue);
1636 contacts_record_set_str(dstRecordHandle, _contacts_email.label, pCharValue);
1638 contacts_record_get_str_p(srcRecordHandle, _contacts_email.email, &pCharValue);
1639 contacts_record_set_str(dstRecordHandle, _contacts_email.email, pCharValue);
1641 contacts_record_add_child_record(dstHandle, _contacts_my_profile.email, dstRecordHandle);
1643 emailHandle.Release();
1648 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.event, &count);
1649 for (i = 0; i < count; i++)
1651 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.event, i, &srcRecordHandle);
1653 ret = contacts_record_create(_contacts_event._uri, &dstRecordHandle);
1654 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1656 __ContactsRecordHandle eventHandle(dstRecordHandle);
1658 contacts_record_get_int(srcRecordHandle, _contacts_event.type, &intValue);
1659 contacts_record_set_int(dstRecordHandle, _contacts_event.type, intValue);
1661 contacts_record_get_str_p(srcRecordHandle, _contacts_event.label, &pCharValue);
1662 contacts_record_set_str(dstRecordHandle, _contacts_event.label, pCharValue);
1664 contacts_record_get_int(srcRecordHandle, _contacts_event.date, &intValue);
1665 contacts_record_set_int(dstRecordHandle, _contacts_event.date, intValue);
1667 contacts_record_add_child_record(dstHandle, _contacts_my_profile.event, dstRecordHandle);
1669 eventHandle.Release();
1673 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.messenger, &count);
1674 for (i = 0; i < count; i++)
1676 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.messenger, i, &srcRecordHandle);
1678 ret = contacts_record_create(_contacts_messenger._uri, &dstRecordHandle);
1679 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1681 __ContactsRecordHandle imAddressHandle(dstRecordHandle);
1683 contacts_record_get_int(srcRecordHandle, _contacts_messenger.type, &intValue);
1684 contacts_record_set_int(dstRecordHandle, _contacts_messenger.type, intValue);
1686 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.label, &pCharValue);
1687 contacts_record_set_str(dstRecordHandle, _contacts_messenger.label, pCharValue);
1689 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.im_id, &pCharValue);
1690 contacts_record_set_str(dstRecordHandle, _contacts_messenger.im_id, pCharValue);
1692 contacts_record_add_child_record(dstHandle, _contacts_my_profile.messenger, dstRecordHandle);
1694 imAddressHandle.Release();
1698 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.address, &count);
1699 for (i = 0; i < count; i++)
1701 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.address, i, &srcRecordHandle);
1703 ret = contacts_record_create(_contacts_address._uri, &dstRecordHandle);
1704 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1706 __ContactsRecordHandle addressHandle(dstRecordHandle);
1708 contacts_record_get_int(srcRecordHandle, _contacts_address.type, &intValue);
1709 contacts_record_set_int(dstRecordHandle, _contacts_address.type, intValue);
1711 contacts_record_get_str_p(srcRecordHandle, _contacts_address.label, &pCharValue);
1712 contacts_record_set_str(dstRecordHandle, _contacts_address.label, pCharValue);
1714 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postbox, &pCharValue);
1715 contacts_record_set_str(dstRecordHandle, _contacts_address.postbox, pCharValue);
1717 contacts_record_get_str_p(srcRecordHandle, _contacts_address.extended, &pCharValue);
1718 contacts_record_set_str(dstRecordHandle, _contacts_address.extended, pCharValue);
1720 contacts_record_get_str_p(srcRecordHandle, _contacts_address.street, &pCharValue);
1721 contacts_record_set_str(dstRecordHandle, _contacts_address.street, pCharValue);
1723 contacts_record_get_str_p(srcRecordHandle, _contacts_address.locality, &pCharValue);
1724 contacts_record_set_str(dstRecordHandle, _contacts_address.locality, pCharValue);
1726 contacts_record_get_str_p(srcRecordHandle, _contacts_address.region, &pCharValue);
1727 contacts_record_set_str(dstRecordHandle, _contacts_address.region, pCharValue);
1729 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postal_code, &pCharValue);
1730 contacts_record_set_str(dstRecordHandle, _contacts_address.postal_code, pCharValue);
1732 contacts_record_get_str_p(srcRecordHandle, _contacts_address.country, &pCharValue);
1733 contacts_record_set_str(dstRecordHandle, _contacts_address.country, pCharValue);
1735 contacts_record_add_child_record(dstHandle, _contacts_my_profile.address, dstRecordHandle);
1737 addressHandle.Release();
1741 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.url, &count);
1742 for (i = 0; i < count; i++)
1744 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.url, i, &srcRecordHandle);
1746 ret = contacts_record_create(_contacts_url._uri, &dstRecordHandle);
1747 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1749 __ContactsRecordHandle urlHandle(dstRecordHandle);
1751 contacts_record_get_int(srcRecordHandle, _contacts_url.type, &intValue);
1752 contacts_record_set_int(dstRecordHandle, _contacts_url.type, intValue);
1754 contacts_record_get_str_p(srcRecordHandle, _contacts_url.label, &pCharValue);
1755 contacts_record_set_str(dstRecordHandle, _contacts_url.label, pCharValue);
1757 contacts_record_get_str_p(srcRecordHandle, _contacts_url.url, &pCharValue);
1758 contacts_record_set_str(dstRecordHandle, _contacts_url.url, pCharValue);
1760 contacts_record_add_child_record(dstHandle, _contacts_my_profile.url, dstRecordHandle);
1762 urlHandle.Release();
1766 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.nickname, &count);
1767 for (i = 0; i < count; i++)
1769 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.nickname, i, &srcRecordHandle);
1771 ret = contacts_record_create(_contacts_nickname._uri, &dstRecordHandle);
1772 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1774 __ContactsRecordHandle nicknameHandle(dstRecordHandle);
1776 contacts_record_get_str_p(srcRecordHandle, _contacts_nickname.name, &pCharValue);
1777 contacts_record_set_str(dstRecordHandle, _contacts_nickname.name, pCharValue);
1779 contacts_record_add_child_record(dstHandle, _contacts_my_profile.nickname, dstRecordHandle);
1781 nicknameHandle.Release();
1785 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.relationship, &count);
1786 for (i = 0; i < count; i++)
1788 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.relationship, i, &srcRecordHandle);
1790 ret = contacts_record_create(_contacts_relationship._uri, &dstRecordHandle);
1791 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1793 __ContactsRecordHandle relationshipHandle(dstRecordHandle);
1795 contacts_record_get_str_p(srcRecordHandle, _contacts_relationship.name, &pCharValue);
1796 contacts_record_set_str(dstRecordHandle, _contacts_relationship.name, pCharValue);
1798 contacts_record_add_child_record(dstHandle, _contacts_my_profile.relationship, dstRecordHandle);
1800 relationshipHandle.Release();
1804 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.image, &count);
1807 contacts_record_get_int(srcHandle, _contacts_my_profile.id, &recordId);
1809 if (count > 0 && recordId == 0)
1811 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.image, 0, &srcRecordHandle);
1813 ret = contacts_record_create(_contacts_image._uri, &dstRecordHandle);
1814 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1816 __ContactsRecordHandle imageHandle(dstRecordHandle);
1818 contacts_record_get_int(srcRecordHandle, _contacts_image.type, &intValue);
1819 contacts_record_set_int(dstRecordHandle, _contacts_image.type, intValue);
1821 contacts_record_get_str_p(srcRecordHandle, _contacts_image.label, &pCharValue);
1822 contacts_record_set_str(dstRecordHandle, _contacts_image.label, pCharValue);
1824 contacts_record_get_str_p(srcRecordHandle, _contacts_image.path, &pCharValue);
1825 contacts_record_set_str(dstRecordHandle, _contacts_image.path, pCharValue);
1827 contacts_record_add_child_record(dstHandle, _contacts_contact.image, dstRecordHandle);
1829 imageHandle.Release();
1836 _AddressbookImpl::OnContactChanged(void)
1838 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1843 std::unique_ptr<IList, AllElementsDeleter> pChangedContactList(GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact));
1844 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1846 if (pChangedContactList->GetCount() > 0)
1848 if (__pIAddressbookEventListener != null)
1850 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1852 else if (__pIAddressbookChangeEventListener != null)
1854 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1858 RecordEventType recordEventType = RECORD_ADDED;
1859 std::unique_ptr<IEnumerator> pEnum(pChangedContactList->GetEnumeratorN());
1860 std::unique_ptr<Contact> pContact(null);
1862 while (pEnum->MoveNext() == E_SUCCESS)
1864 ContactChangeInfo* pContactChagneInfo = static_cast<ContactChangeInfo*>(pEnum->GetCurrent());
1866 if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
1868 recordEventType = RECORD_ADDED;
1869 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
1870 if (pContact == null)
1872 if (GetLastResult() == E_OBJ_NOT_FOUND)
1882 else if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
1884 recordEventType = RECORD_UPDATED;
1885 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
1886 if (pContact == null)
1888 if (GetLastResult() == E_OBJ_NOT_FOUND)
1900 recordEventType = RECORD_REMOVED;
1901 pContact.reset(new (std::nothrow) Contact());
1902 if (pContact == null)
1904 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1908 _RecordImpl::GetInstance(*pContact)->SetRecordId(pContactChagneInfo->GetContactId());
1911 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CONTACT, *pContact, null, null);
1919 _AddressbookImpl::OnCategoryChanged(void)
1921 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1926 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup));
1927 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1929 if (pChangedCategoryList->GetCount() > 0)
1931 if (__pIAddressbookEventListener != null)
1933 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1935 else if (__pIAddressbookChangeEventListener != null)
1937 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1941 RecordEventType recordEventType = RECORD_ADDED;
1942 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
1943 std::unique_ptr<Category> pCategory(null);
1945 while (pEnum->MoveNext() == E_SUCCESS)
1947 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
1949 if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
1951 recordEventType = RECORD_ADDED;
1952 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1953 if (pCategory == null)
1955 if (GetLastResult() == E_OBJ_NOT_FOUND)
1965 else if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
1967 recordEventType = RECORD_UPDATED;
1968 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1969 if (pCategory == null)
1971 if (GetLastResult() == E_OBJ_NOT_FOUND)
1983 recordEventType = RECORD_REMOVED;
1984 pCategory.reset(new (std::nothrow) Category());
1985 if (pCategory == null)
1987 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1991 _RecordImpl::GetInstance(*pCategory)->SetRecordId(pCategoryChagneInfo->GetCategoryId());
1994 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2002 _AddressbookImpl::OnRelationChanged(void)
2004 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null)
2009 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation));
2010 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2012 if (pChangedCategoryList->GetCount() > 0)
2014 if (__pIAddressbookEventListener != null)
2016 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
2020 RecordEventType recordEventType = RECORD_ADDED;
2021 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
2022 std::unique_ptr<Category> pCategory(null);
2024 while (pEnum->MoveNext() == E_SUCCESS)
2026 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
2028 recordEventType = RECORD_UPDATED;
2029 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2030 if (pCategory == null)
2032 if (GetLastResult() == E_OBJ_NOT_FOUND)
2042 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2049 _AddressbookImpl::GetInstance(Addressbook& addressbook)
2051 return addressbook.__pAddressbookImpl;
2054 const _AddressbookImpl*
2055 _AddressbookImpl::GetInstance(const Addressbook& addressbook)
2057 return addressbook.__pAddressbookImpl;