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 <unique_ptr.h>
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"
53 using namespace Tizen::App;
54 using namespace Tizen::Base;
55 using namespace Tizen::Base::Collection;
56 using namespace Tizen::Graphics;
58 namespace Tizen { namespace Social
61 _AddressbookImpl::_AddressbookImpl(void)
62 : __pIRecordEventListener(null)
63 , __pIAddressbookEventListener(null)
64 , __pIAddressbookChangeEventListener(null)
65 , __dbVersionForContact(0)
66 , __dbVersionForGroup(0)
67 , __dbVersionForRelation(0)
68 , __addressbookId(INVALID_ADDRESSBOOK_ID)
74 _AddressbookImpl::~_AddressbookImpl(void)
76 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
78 _ContactDbMonitor* pDbMonitor = _ContactDbMonitor::GetInstance();
79 if (pDbMonitor != null)
81 pDbMonitor->RemoveListener(*this);
87 _AddressbookImpl::Construct(void)
89 static AccountId accountId = 0;
94 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
97 contacts_record_h recordHandle = null;
98 int ret = contacts_db_get_record(_contacts_address_book._uri, DEFAULT_ADDRESSBOOK_ID, &recordHandle);
99 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
100 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);
102 contacts_record_get_str_p(recordHandle, _contacts_address_book.name, &pName);
103 contacts_record_get_int(recordHandle, _contacts_address_book.account_id, &accountId);
107 contacts_record_destroy(recordHandle, true);
110 __addressbookId = DEFAULT_ADDRESSBOOK_ID;
111 __accountId = accountId;
118 _AddressbookImpl::SetRecordEventListener(IRecordEventListener* pListener)
120 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
122 result r = E_SUCCESS;
124 if (pListener != null)
126 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null)
128 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
129 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
131 r = pContactDbMonitor->AddListener(*this);
132 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
135 __dbVersionForContact = GetLatestVersion();
136 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
138 __dbVersionForGroup = __dbVersionForContact;
139 __dbVersionForRelation = __dbVersionForContact;
141 __pIAddressbookEventListener = null;
142 __pIAddressbookChangeEventListener = null;
143 __pIRecordEventListener = pListener;
147 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
149 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
150 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()))
151 pContactDbMonitor->RemoveListener(*this);
154 __pIAddressbookEventListener = null;
155 __pIAddressbookChangeEventListener = null;
156 __pIRecordEventListener = null;
163 _AddressbookImpl::SetAddressbookEventListener(IAddressbookEventListener* pListener)
165 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
167 result r = E_SUCCESS;
169 if (pListener != null)
171 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null)
173 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
174 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
176 r = pContactDbMonitor->AddListener(*this);
177 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
180 __dbVersionForContact = GetLatestVersion();
181 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
183 __dbVersionForGroup = __dbVersionForContact;
184 __dbVersionForRelation = __dbVersionForContact;
186 __pIRecordEventListener = null;
187 __pIAddressbookChangeEventListener = null;
188 __pIAddressbookEventListener = pListener;
192 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
194 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
195 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
197 pContactDbMonitor->RemoveListener(*this);
200 __pIAddressbookEventListener = null;
201 __pIAddressbookChangeEventListener = null;
202 __pIRecordEventListener = null;
209 _AddressbookImpl::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
211 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
213 result r = E_SUCCESS;
215 if (pListener != null)
217 if (__pIAddressbookEventListener == null && __pIAddressbookChangeEventListener == null && __pIRecordEventListener == null)
219 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
220 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
222 r = pContactDbMonitor->AddListener(*this);
223 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
226 __dbVersionForContact = GetLatestVersion();
227 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
229 __dbVersionForGroup = __dbVersionForContact;
230 __dbVersionForRelation = __dbVersionForContact;
232 __pIRecordEventListener = null;
233 __pIAddressbookEventListener = null;
234 __pIAddressbookChangeEventListener = pListener;
238 if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null || __pIRecordEventListener != null)
240 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
241 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
243 pContactDbMonitor->RemoveListener(*this);
246 __pIAddressbookEventListener = null;
247 __pIAddressbookChangeEventListener = null;
248 __pIRecordEventListener = null;
255 _AddressbookImpl::SetId(AddressbookId addressbookId)
257 __addressbookId = addressbookId;
261 _AddressbookImpl::SetAccountId(AccountId accountId)
263 __accountId = accountId;
267 _AddressbookImpl::SetName(const String& name)
273 _AddressbookImpl::GetId(void) const
275 return __addressbookId;
279 _AddressbookImpl::GetAccountId(void) const
285 _AddressbookImpl::GetName(void) const
291 _AddressbookImpl::AddContact(Contact& contact)
293 if (_ContactImpl::GetInstance(contact)->IsRemoved())
295 result r = _ContactImpl::GetInstance(contact)->Invalidate();
296 SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
299 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));
300 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));
301 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
304 contacts_record_h recordHandle = null;
306 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
308 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
310 int ret = contacts_db_insert_record(recordHandle, &recordId);
311 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));
312 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
313 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
315 ret = contacts_db_get_record(_contacts_contact._uri, recordId, &recordHandle);
316 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.");
317 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));
318 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
320 _ContactImpl::GetInstance(contact)->SetContactRecordHandle(recordHandle);
321 _RecordImpl::GetInstance(contact)->SetRecordId(recordId);
327 _AddressbookImpl::AddCategory(Category& category)
329 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));
330 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
333 contacts_record_h recordHandle = null;
334 unique_ptr<IListT<int> > pList(null);
336 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
338 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
340 // It is not allowed to have a same name with other.
342 char* pCharValue = null;
343 contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue);
345 __Filter<__ContactsGroup> filter;
347 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
348 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
349 filter.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue);
351 __Query<__ContactsGroup> query;
353 query.SetFilter(filter);
355 count = _AddressbookUtil::GetCountWithQuery(query);
356 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
357 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));
360 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
362 contacts_record_set_int(recordHandle, _contacts_group.address_book_id, __addressbookId);
364 int ret = contacts_db_insert_record(recordHandle, &recordId);
365 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));
366 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
367 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
369 ret = contacts_db_get_record(_contacts_group._uri, recordId, &recordHandle);
370 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));
371 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));
372 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%d] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
374 _CategoryImpl::GetInstance(category)->SetRecordHandle(recordHandle);
375 _RecordImpl::GetInstance(category)->SetRecordId(recordId);
377 pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
378 if (pList != null && pList->GetCount() > 0)
380 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
382 while (pEnum->MoveNext() == E_SUCCESS)
385 pEnum->GetCurrent(tableId);
387 AddMemberToCategory(category.GetRecordId(), tableId);
390 _CategoryImpl::GetInstance(category)->ClearAddedMemberList();
397 _AddressbookImpl::RemoveContact(RecordId contactId)
399 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contactId is invalid", GetErrorMessage(E_INVALID_ARG));
400 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
401 result r = _AddressbookUtil::DeleteContactRecord(_contacts_contact._uri, contactId);
402 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
408 _AddressbookImpl::RemoveContact(Contact& contact)
410 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));
411 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
413 result r = RemoveContact(contact.GetRecordId());
414 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
416 _ContactImpl::GetInstance(contact)->SetAsRemoved();
417 _RecordImpl::GetInstance(contact)->SetRecordId(INVALID_RECORD_ID);
423 _AddressbookImpl::RemoveCategory(RecordId categoryId)
425 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);
426 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
427 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
428 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
430 bool isReadOnly = false;
431 contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly);
432 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));
434 result r = _AddressbookUtil::DeleteContactRecord(_contacts_group._uri, categoryId);
435 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
441 _AddressbookImpl::UpdateContact(const Contact& contact)
443 RecordId contactId = contact.GetRecordId();
444 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
445 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));
446 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
448 contacts_record_h recordHandle = null;
451 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
452 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));
453 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));
454 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
456 contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
458 contacts_record_destroy(recordHandle, true);
459 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
461 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
463 ret = contacts_db_update_record(recordHandle);
464 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));
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_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
467 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
469 ret = contacts_db_get_record(_contacts_contact._uri, contact.GetRecordId(), &recordHandle);
470 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));
471 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
472 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
474 _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(recordHandle);
480 _AddressbookImpl::UpdateCategory(const Category& category)
482 RecordId categoryId = category.GetRecordId();
483 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));
484 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));
485 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
487 contacts_record_h recordHandle = null;
489 int ret = CONTACTS_ERROR_NONE;
491 ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
492 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));
493 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));
494 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
496 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
498 contacts_record_destroy(recordHandle, true);
500 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
502 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
504 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
507 char* pCharValue = null;
509 contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue);
510 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
512 __Filter<__ContactsGroup> filter1;
514 filter1.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
515 filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
516 filter1.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue);
518 __Filter<__ContactsGroup> filter2;
520 filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_LESS_THAN, intValue);
521 filter2.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
522 filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_GREATER_THAN, intValue);
524 filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
525 filter1.AddFilter(filter2);
527 __Query<__ContactsGroup> query;
529 query.SetFilter(filter1);
531 count = _AddressbookUtil::GetCountWithQuery(query);
532 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
533 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));
536 ret = contacts_db_update_record(recordHandle);
537 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));
538 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));
539 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
540 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
542 ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
543 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));
544 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));
545 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
547 _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(recordHandle);
549 std::unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
550 if (pList != null && pList->GetCount() > 0)
553 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
554 while (pEnum->MoveNext() == E_SUCCESS)
556 pEnum->GetCurrent(tableId);
558 AddMemberToCategory(category.GetRecordId(), tableId);
561 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList();
564 pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN());
565 if (pList != null && pList->GetCount() > 0)
568 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
569 while (pEnum->MoveNext() == E_SUCCESS)
571 pEnum->GetCurrent(tableId);
573 RemoveMemberFromCategory(category.GetRecordId(), tableId);
576 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList();
583 _AddressbookImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
585 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);
586 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);
587 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
589 contacts_record_h recordHandle = null;
590 int addressbookId = 0;
591 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
592 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));
593 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));
594 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
595 contacts_record_get_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId);
596 contacts_record_destroy(recordHandle, true);
598 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));
600 ret = contacts_group_add_contact(categoryId, contactId);
601 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
602 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));
603 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
609 _AddressbookImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
611 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);
612 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);
613 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
615 contacts_record_h recordHandle = null;
616 int addressbookId = 0;
617 int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
618 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));
619 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));
620 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
621 contacts_record_get_int(recordHandle, _contacts_simple_contact.address_book_id, &addressbookId);
622 contacts_record_destroy(recordHandle, true);
624 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));
626 ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
627 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));
628 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));
629 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
631 contacts_record_get_int(recordHandle, _contacts_group.address_book_id, &addressbookId);
632 contacts_record_destroy(recordHandle, true);
634 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));
636 ret = contacts_group_remove_contact(categoryId, contactId);
637 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
638 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));
639 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
645 _AddressbookImpl::GetAllCategoriesN(void) const
647 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
651 __Filter<__ContactsGroup> filter;
653 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
655 __Query<__ContactsGroup> query;
657 query.SetFilter(filter);
658 query.SetSort(_contacts_group.name, true);
661 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
662 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
668 _AddressbookImpl::GetCategoriesByContactN(RecordId contactId) const
670 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
671 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));
675 __Filter<__ContactsGroupRelation> filter;
677 filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
679 __Query<__ContactsGroupRelation> query;
681 query.SetFilter(filter);
682 query.SetSort(_contacts_group_relation.name, true);
684 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query);
685 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
691 _AddressbookImpl::GetAllContactsN(void) const
693 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
697 __Filter<__ContactsContact> filter;
699 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
701 __Query<__ContactsContact> query;
703 query.SetFilter(filter);
704 query.SetSort(_contacts_contact.display_name, true);
706 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
707 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
713 _AddressbookImpl::GetContactsByCategoryN(RecordId categoryId) const
715 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));
716 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
720 __Filter<__ContactsContactGroupRel> filter;
722 if (categoryId != INVALID_RECORD_ID)
724 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
728 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
731 __Query<__ContactsContactGroupRel> query;
733 query.SetFilter(filter);
734 query.SetSort(_contacts_contact_grouprel.display_name, true);
736 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
737 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
743 _AddressbookImpl::GetContactsN(int pageNo, int countPerPage) const
745 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);
746 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
748 int offset = (pageNo - 1)*countPerPage;
749 int limit = countPerPage;
753 __Filter<__ContactsContact> filter;
755 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
757 __Query<__ContactsContact> query;
759 query.SetFilter(filter);
760 query.SetSort(_contacts_contact.display_name, true);
762 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, limit);
763 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
769 _AddressbookImpl::GetContactsInN(const Category& category, int pageNo, int countPerPage) const
771 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));
772 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);
773 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
775 int offset = (pageNo - 1)*countPerPage;
776 int limit = countPerPage;
780 __Filter<__ContactsContactGroupRel> filter;
782 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, category.GetRecordId());
784 __Query<__ContactsContactGroupRel> query;
786 query.SetFilter(filter);
787 query.SetSort(_contacts_contact_grouprel.display_name, true);
789 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query, offset, limit);
790 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
796 _AddressbookImpl::SearchContactsByEmailN(const String& email) const
798 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));
799 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
801 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
803 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));
808 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
809 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
811 __Filter<__ContactsContactEmail> filter;
813 filter.AddInt(_contacts_contact_email.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
814 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
815 filter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
817 unsigned int projectionIds[1];
818 projectionIds[0] = _contacts_contact_email.contact_id;
820 __Query<__ContactsContactEmail> query;
822 query.SetProjection(projectionIds, 1);
823 query.SetFilter(filter);
824 query.SetDistinct(true);
825 query.SetSort(_contacts_contact_email.display_name, true);
827 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
828 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
834 _AddressbookImpl::SearchContactsByNameN(const String& name) const
836 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));
837 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
839 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
841 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));
846 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
847 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
849 __Filter<__ContactsContact> filter;
851 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
852 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
853 filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
855 __Query<__ContactsContact> query;
857 query.SetFilter(filter);
858 query.SetSort(_contacts_contact.display_name, true);
859 query.SetDistinct(true);
861 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
862 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
869 _AddressbookImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
871 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));
872 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
875 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
877 int count = phoneNumber.GetLength();
878 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));
883 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
884 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
886 __Filter<__ContactsContactNumber> filter;
888 filter.AddInt(_contacts_contact_number.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
889 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
890 filter.AddString(_contacts_contact_number.normalized_number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
892 unsigned int projectionIds[1];
893 projectionIds[0] = _contacts_contact_number.contact_id;
895 __Query<__ContactsContactNumber> query;
897 query.SetProjection(projectionIds, 1);
898 query.SetFilter(filter);
899 query.SetDistinct(true);
900 query.SetSort(_contacts_contact_number.display_name, true);
902 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
903 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
909 _AddressbookImpl::GetCategoryCount(void) const
911 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
917 __Filter<__ContactsGroup> filter;
919 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
921 __Query<__ContactsGroup> query;
923 query.SetFilter(filter);
925 count = _AddressbookUtil::GetCountWithQuery(query);
926 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
932 _AddressbookImpl::GetContactCount(void) const
934 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
940 __Filter<__ContactsContact> filter;
942 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
944 __Query<__ContactsContact> query;
946 query.SetFilter(filter);
948 count = _AddressbookUtil::GetCountWithQuery(query);
949 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
955 _AddressbookImpl::GetContactN(RecordId contactId) const
957 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
958 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
961 contacts_record_h contactHandle = null;
965 std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
966 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
968 int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &contactHandle);
969 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
970 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
971 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
973 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle);
975 contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue);
976 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
978 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
980 return pContact.release();
984 _AddressbookImpl::GetCategoryN(RecordId categoryId) const
986 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
987 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
989 contacts_record_h recordHandle = null;
994 int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
995 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
996 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
997 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
999 std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
1000 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1002 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
1003 SysTryReturn(NID_SCL, intValue == categoryId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1005 __Filter<__ContactsGroupRelation> filter;
1007 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1009 __Query<__ContactsGroupRelation> query;
1011 query.SetFilter(filter);
1013 int count = _AddressbookUtil::GetCountWithQuery(query);
1014 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1016 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(recordHandle);
1017 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1018 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1020 return pCategory.release();
1024 _AddressbookImpl::GetLatestVersion(void) const
1026 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1028 int latestVersion = -1;
1032 int ret = contacts_db_get_current_version(&latestVersion);
1033 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, -1, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1034 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1036 return latestVersion;
1040 _AddressbookImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1042 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);
1043 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1047 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1048 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1050 return pChangedContacts;
1054 _AddressbookImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1056 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);
1057 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1061 int latestVersion1 = 0;
1062 int latestVersion2 = 0;
1064 std::unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion1));
1065 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1067 std::unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion2));
1068 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1070 std::unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1071 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1073 result r = pChangeList->AddItems(*pChangedGroups);
1074 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1076 r = pChangeList->AddItems(*pChangedRelations);
1077 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1079 pChangedGroups->RemoveAll(false);
1080 pChangedRelations->RemoveAll(false);
1082 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1084 return pChangeList.release();
1088 _AddressbookImpl::GetChangedContactInfoListN(int version, int& latestVersion) const
1090 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);
1091 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1095 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1096 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1098 return pChangedContacts;
1102 _AddressbookImpl::GetChangedCategoryInfoListN(int version, int& latestVersion) const
1104 return GetChangedGroupsAfterN(version, latestVersion);
1108 _AddressbookImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1110 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);
1111 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1115 IList* pChangedGroups = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1116 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1118 return pChangedGroups;
1122 _AddressbookImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1124 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);
1125 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1129 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1130 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1132 return pChangedRelations;
1136 _AddressbookImpl::AddContacts(const Tizen::Base::Collection::IList& contactList, Tizen::Base::Collection::IListT<RecordId>* pContactIdList)
1138 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1139 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1141 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1142 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1144 Contact* pContact = null;
1145 int ret = CONTACTS_ERROR_NONE;
1146 int* pContactIds = null;
1147 unsigned int contactsCount = 0;
1149 contacts_record_h recordHandle = null;
1150 contacts_list_h listHandle = null;
1152 ret = contacts_list_create(&listHandle);
1153 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1155 while (pContactEnum->MoveNext() == E_SUCCESS)
1157 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1159 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1161 contacts_list_destroy(listHandle, false);
1162 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1163 return E_INVALID_ARG;
1165 if (pContact->GetRecordId() != INVALID_RECORD_ID)
1167 contacts_list_destroy(listHandle, false);
1168 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1169 return E_INVALID_ARG;
1172 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1173 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
1174 contacts_list_add(listHandle, recordHandle);
1177 ret = contacts_db_insert_records(listHandle, &pContactIds, &contactsCount);
1178 contacts_list_destroy(listHandle, false);
1179 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));
1180 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1181 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1182 SysTryReturn(NID_SCL, pContactIds, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1184 int* pTemp = pContactIds;
1186 if (pContactIdList != null)
1188 for (unsigned int i = 0; i < contactsCount; i++)
1190 pContactIdList->Add(*pTemp);
1201 _AddressbookImpl::UpdateContacts(const Tizen::Base::Collection::IList& contactList)
1203 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1204 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1206 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1207 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1209 Contact* pContact = null;
1210 int ret = CONTACTS_ERROR_NONE;
1211 contacts_record_h recordHandle = null;
1212 contacts_list_h listHandle = null;
1214 ret = contacts_list_create(&listHandle);
1215 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1217 while (pContactEnum->MoveNext() == E_SUCCESS)
1219 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1221 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1223 contacts_list_destroy(listHandle, false);
1224 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1225 return E_INVALID_ARG;
1227 if (pContact->GetRecordId() == INVALID_RECORD_ID)
1229 contacts_list_destroy(listHandle, false);
1230 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1231 return E_INVALID_ARG;
1234 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1235 contacts_list_add(listHandle, recordHandle);
1238 ret = contacts_db_update_records(listHandle);
1239 contacts_list_destroy(listHandle, false);
1240 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));
1241 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1242 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));
1243 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1249 _AddressbookImpl::RemoveContacts(const Tizen::Base::Collection::IListT<RecordId>& contactIdList)
1251 SysTryReturn(NID_SCL, contactIdList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactIdList is empty.", GetErrorMessage(E_INVALID_ARG));
1252 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1254 std::unique_ptr<IEnumeratorT<RecordId> > pContactIdEnum(contactIdList.GetEnumeratorN());
1255 SysTryReturnResult(NID_SCL, pContactIdEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1257 RecordId contactId = INVALID_RECORD_ID;
1258 int ret = CONTACTS_ERROR_NONE;
1259 int count = contactIdList.GetCount();
1260 std::unique_ptr<int[]> pRecordIds(new (std::nothrow) int[count]);
1261 int* pInt = pRecordIds.get();
1264 while (pContactIdEnum->MoveNext() == E_SUCCESS)
1266 pContactIdEnum->GetCurrent(contactId);
1267 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));
1273 ret = contacts_db_delete_records(_contacts_contact._uri, pInt, count);
1274 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));
1275 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));
1281 _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
1283 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1286 int existingRecordId = 0;
1287 int ret = CONTACTS_ERROR_NONE;
1288 result r = E_SUCCESS;
1289 contacts_record_h recordHandle = null;
1291 std::unique_ptr<UserProfile> pExistingProfile(GetUserProfileN());
1292 SysTryReturn(NID_SCL, pExistingProfile != null || GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1294 if (pExistingProfile != null)
1296 recordHandle = _UserProfileImpl::GetInstance(*pExistingProfile)->GetUserProfileHandle();
1297 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &existingRecordId);
1300 if (pUserProfile != null)
1302 SysTryReturn(NID_SCL, !((_UserProfileImpl::GetInstance(*pUserProfile))->IsEmpty()), E_SYSTEM, E_SYSTEM, "[%s] UserProfile is Empty.", GetErrorMessage(E_SYSTEM));
1304 recordHandle = _UserProfileImpl::GetInstance(*pUserProfile)->GetUserProfileHandle();
1305 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &recordId);
1308 if (pExistingProfile != null)
1310 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1311 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1314 contacts_record_h newRecordHandle = null;
1315 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1316 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));
1318 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1319 if (ret != CONTACTS_ERROR_NONE)
1321 contacts_record_destroy(newRecordHandle, true);
1322 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1326 ret = contacts_db_insert_record(newRecordHandle, &recordId);
1327 contacts_record_destroy(newRecordHandle, true);
1328 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));
1329 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1331 else if (recordId > 0)
1333 if (recordId == existingRecordId)
1335 contacts_record_h newRecordHandle = null;
1336 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1337 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));
1339 ret = contacts_db_update_record(newRecordHandle);
1340 contacts_record_destroy(newRecordHandle, true);
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));
1346 if (pExistingProfile != null)
1348 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1349 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1352 contacts_record_h newRecordHandle = null;
1353 ret = contacts_record_create(_contacts_my_profile._uri, &newRecordHandle);
1354 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1356 r = CopyMyProfileContents(recordHandle, newRecordHandle);
1359 contacts_record_destroy(newRecordHandle, true);
1360 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1361 return E_OUT_OF_MEMORY;
1365 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1366 if (ret != CONTACTS_ERROR_NONE)
1368 contacts_record_destroy(newRecordHandle, true);
1369 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1373 ret = contacts_db_insert_record(newRecordHandle, &recordId);
1374 contacts_record_destroy(newRecordHandle, true);
1375 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));
1376 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1382 if (pExistingProfile != null)
1384 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1385 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1393 _AddressbookImpl::GetUserProfileN(void) const
1395 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1399 __Filter<__ContactsUserProfile> filter;
1401 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
1403 __Query<__ContactsUserProfile> query;
1405 query.SetFilter(filter);
1407 std::unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
1408 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1409 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
1410 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
1412 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
1413 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
1419 _AddressbookImpl::IsUserProfileChangedAfter(int version) const
1421 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);
1422 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1424 UserProfile* pExistingProfile = GetUserProfileN();
1425 if (pExistingProfile == null)
1430 delete pExistingProfile;
1434 int latestVersion = 0;
1435 int count = _AddressbookUtil::GetChangedItemCountByVersion<__ContactsMyProfileUpdatedInfo>(__addressbookId, version, latestVersion);
1436 SysTryReturn(NID_SCL, count >= 0, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1447 _AddressbookImpl::CopyMyProfileContents(contacts_record_h srcHandle, contacts_record_h dstHandle)
1449 int ret = CONTACTS_ERROR_NONE;
1451 unsigned int count = 0;
1453 char* pCharValue = null;
1455 contacts_record_h srcRecordHandle = null;
1456 contacts_record_h dstRecordHandle = null;
1459 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.name, &count);
1462 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.name, 0, &srcRecordHandle);
1464 ret = contacts_record_create(_contacts_name._uri, &dstRecordHandle);
1465 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1467 __ContactsRecordHandle nameHandle(dstRecordHandle);
1469 contacts_record_get_str(srcRecordHandle, _contacts_name.first, &pCharValue);
1470 contacts_record_set_str(dstRecordHandle, _contacts_name.first, pCharValue);
1472 contacts_record_get_str(srcRecordHandle, _contacts_name.last, &pCharValue);
1473 contacts_record_set_str(dstRecordHandle, _contacts_name.last, pCharValue);
1475 contacts_record_get_str(srcRecordHandle, _contacts_name.addition, &pCharValue);
1476 contacts_record_set_str(dstRecordHandle, _contacts_name.addition, pCharValue);
1478 contacts_record_get_str(srcRecordHandle, _contacts_name.suffix, &pCharValue);
1479 contacts_record_set_str(dstRecordHandle, _contacts_name.suffix, pCharValue);
1481 contacts_record_get_str(srcRecordHandle, _contacts_name.prefix, &pCharValue);
1482 contacts_record_set_str(dstRecordHandle, _contacts_name.prefix, pCharValue);
1484 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_first, &pCharValue);
1485 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_first, pCharValue);
1487 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
1488 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_middle, pCharValue);
1490 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_last, &pCharValue);
1491 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_last, pCharValue);
1493 contacts_record_add_child_record(dstHandle, _contacts_my_profile.name, dstRecordHandle);
1495 nameHandle.Release();
1499 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.company, &count);
1500 for (i = 0; i < count; i++)
1502 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.company, i, &srcRecordHandle);
1504 ret = contacts_record_create(_contacts_company._uri, &dstRecordHandle);
1505 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1507 __ContactsRecordHandle companyHandle(dstRecordHandle);
1509 contacts_record_get_int(srcRecordHandle, _contacts_company.type, &intValue);
1510 contacts_record_set_int(dstRecordHandle, _contacts_company.type, intValue);
1512 contacts_record_get_str_p(srcRecordHandle, _contacts_company.name, &pCharValue);
1513 contacts_record_set_str(dstRecordHandle, _contacts_company.name, pCharValue);
1515 contacts_record_get_str_p(srcRecordHandle, _contacts_company.department, &pCharValue);
1516 contacts_record_set_str(dstRecordHandle, _contacts_company.department, pCharValue);
1518 contacts_record_get_str_p(srcRecordHandle, _contacts_company.job_title, &pCharValue);
1519 contacts_record_set_str(dstRecordHandle, _contacts_company.job_title, pCharValue);
1521 contacts_record_get_str_p(srcRecordHandle, _contacts_company.assistant_name, &pCharValue);
1522 contacts_record_set_str(dstRecordHandle, _contacts_company.assistant_name, pCharValue);
1524 contacts_record_get_str_p(srcRecordHandle, _contacts_company.role, &pCharValue);
1525 contacts_record_set_str(dstRecordHandle, _contacts_company.role, pCharValue);
1527 contacts_record_get_str_p(srcRecordHandle, _contacts_company.logo, &pCharValue);
1528 contacts_record_set_str(dstRecordHandle, _contacts_company.logo, pCharValue);
1530 contacts_record_get_str_p(srcRecordHandle, _contacts_company.location, &pCharValue);
1531 contacts_record_set_str(dstRecordHandle, _contacts_company.location, pCharValue);
1533 contacts_record_get_str_p(srcRecordHandle, _contacts_company.description, &pCharValue);
1534 contacts_record_set_str(dstRecordHandle, _contacts_company.description, pCharValue);
1536 contacts_record_get_str_p(srcRecordHandle, _contacts_company.phonetic_name, &pCharValue);
1537 contacts_record_set_str(dstRecordHandle, _contacts_company.phonetic_name, pCharValue);
1539 contacts_record_add_child_record(dstHandle, _contacts_my_profile.company, dstRecordHandle);
1541 companyHandle.Release();
1545 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.note, &count);
1546 for (i = 0; i < count; i++)
1548 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.note, i, &srcRecordHandle);
1550 ret = contacts_record_create(_contacts_note._uri, &dstRecordHandle);
1551 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1553 __ContactsRecordHandle noteHandle(dstRecordHandle);
1555 contacts_record_get_str_p(srcRecordHandle, _contacts_note.note, &pCharValue);
1556 contacts_record_set_str(dstRecordHandle, _contacts_note.note, pCharValue);
1558 contacts_record_add_child_record(dstHandle, _contacts_my_profile.note, dstRecordHandle);
1560 noteHandle.Release();
1564 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.number, &count);
1565 for (i = 0; i < count; i++)
1567 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.number, i, &srcRecordHandle);
1569 ret = contacts_record_create(_contacts_number._uri, &dstRecordHandle);
1570 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1572 __ContactsRecordHandle numberHandle(dstRecordHandle);
1574 contacts_record_get_int(srcRecordHandle, _contacts_number.type, &intValue);
1575 contacts_record_set_int(dstRecordHandle, _contacts_number.type, intValue);
1577 contacts_record_get_str_p(srcRecordHandle, _contacts_number.label, &pCharValue);
1578 contacts_record_set_str(dstRecordHandle, _contacts_number.label, pCharValue);
1580 contacts_record_get_str_p(srcRecordHandle, _contacts_number.number, &pCharValue);
1581 contacts_record_set_str(dstRecordHandle, _contacts_number.number, pCharValue);
1583 contacts_record_add_child_record(dstHandle, _contacts_my_profile.number, dstRecordHandle);
1585 numberHandle.Release();
1589 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.email, &count);
1590 for (i = 0; i < count; i++)
1592 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.email, i, &srcRecordHandle);
1594 ret = contacts_record_create(_contacts_email._uri, &dstRecordHandle);
1595 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1597 __ContactsRecordHandle emailHandle(dstRecordHandle);
1599 contacts_record_get_int(srcRecordHandle, _contacts_email.type, &intValue);
1600 contacts_record_set_int(dstRecordHandle, _contacts_email.type, intValue);
1602 contacts_record_get_str_p(srcRecordHandle, _contacts_email.label, &pCharValue);
1603 contacts_record_set_str(dstRecordHandle, _contacts_email.label, pCharValue);
1605 contacts_record_get_str_p(srcRecordHandle, _contacts_email.email, &pCharValue);
1606 contacts_record_set_str(dstRecordHandle, _contacts_email.email, pCharValue);
1608 contacts_record_add_child_record(dstHandle, _contacts_my_profile.email, dstRecordHandle);
1610 emailHandle.Release();
1615 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.event, &count);
1616 for (i = 0; i < count; i++)
1618 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.event, i, &srcRecordHandle);
1620 ret = contacts_record_create(_contacts_event._uri, &dstRecordHandle);
1621 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1623 __ContactsRecordHandle eventHandle(dstRecordHandle);
1625 contacts_record_get_int(srcRecordHandle, _contacts_event.type, &intValue);
1626 contacts_record_set_int(dstRecordHandle, _contacts_event.type, intValue);
1628 contacts_record_get_str_p(srcRecordHandle, _contacts_event.label, &pCharValue);
1629 contacts_record_set_str(dstRecordHandle, _contacts_event.label, pCharValue);
1631 contacts_record_get_int(srcRecordHandle, _contacts_event.date, &intValue);
1632 contacts_record_set_int(dstRecordHandle, _contacts_event.date, intValue);
1634 contacts_record_add_child_record(dstHandle, _contacts_my_profile.event, dstRecordHandle);
1636 eventHandle.Release();
1640 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.messenger, &count);
1641 for (i = 0; i < count; i++)
1643 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.messenger, i, &srcRecordHandle);
1645 ret = contacts_record_create(_contacts_messenger._uri, &dstRecordHandle);
1646 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1648 __ContactsRecordHandle imAddressHandle(dstRecordHandle);
1650 contacts_record_get_int(srcRecordHandle, _contacts_messenger.type, &intValue);
1651 contacts_record_set_int(dstRecordHandle, _contacts_messenger.type, intValue);
1653 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.label, &pCharValue);
1654 contacts_record_set_str(dstRecordHandle, _contacts_messenger.label, pCharValue);
1656 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.im_id, &pCharValue);
1657 contacts_record_set_str(dstRecordHandle, _contacts_messenger.im_id, pCharValue);
1659 contacts_record_add_child_record(dstHandle, _contacts_my_profile.messenger, dstRecordHandle);
1661 imAddressHandle.Release();
1665 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.address, &count);
1666 for (i = 0; i < count; i++)
1668 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.address, i, &srcRecordHandle);
1670 ret = contacts_record_create(_contacts_address._uri, &dstRecordHandle);
1671 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1673 __ContactsRecordHandle addressHandle(dstRecordHandle);
1675 contacts_record_get_int(srcRecordHandle, _contacts_address.type, &intValue);
1676 contacts_record_set_int(dstRecordHandle, _contacts_address.type, intValue);
1678 contacts_record_get_str_p(srcRecordHandle, _contacts_address.label, &pCharValue);
1679 contacts_record_set_str(dstRecordHandle, _contacts_address.label, pCharValue);
1681 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postbox, &pCharValue);
1682 contacts_record_set_str(dstRecordHandle, _contacts_address.postbox, pCharValue);
1684 contacts_record_get_str_p(srcRecordHandle, _contacts_address.extended, &pCharValue);
1685 contacts_record_set_str(dstRecordHandle, _contacts_address.extended, pCharValue);
1687 contacts_record_get_str_p(srcRecordHandle, _contacts_address.street, &pCharValue);
1688 contacts_record_set_str(dstRecordHandle, _contacts_address.street, pCharValue);
1690 contacts_record_get_str_p(srcRecordHandle, _contacts_address.locality, &pCharValue);
1691 contacts_record_set_str(dstRecordHandle, _contacts_address.locality, pCharValue);
1693 contacts_record_get_str_p(srcRecordHandle, _contacts_address.region, &pCharValue);
1694 contacts_record_set_str(dstRecordHandle, _contacts_address.region, pCharValue);
1696 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postal_code, &pCharValue);
1697 contacts_record_set_str(dstRecordHandle, _contacts_address.postal_code, pCharValue);
1699 contacts_record_get_str_p(srcRecordHandle, _contacts_address.country, &pCharValue);
1700 contacts_record_set_str(dstRecordHandle, _contacts_address.country, pCharValue);
1702 contacts_record_add_child_record(dstHandle, _contacts_my_profile.address, dstRecordHandle);
1704 addressHandle.Release();
1708 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.url, &count);
1709 for (i = 0; i < count; i++)
1711 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.url, i, &srcRecordHandle);
1713 ret = contacts_record_create(_contacts_url._uri, &dstRecordHandle);
1714 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1716 __ContactsRecordHandle urlHandle(dstRecordHandle);
1718 contacts_record_get_int(srcRecordHandle, _contacts_url.type, &intValue);
1719 contacts_record_set_int(dstRecordHandle, _contacts_url.type, intValue);
1721 contacts_record_get_str_p(srcRecordHandle, _contacts_url.label, &pCharValue);
1722 contacts_record_set_str(dstRecordHandle, _contacts_url.label, pCharValue);
1724 contacts_record_get_str_p(srcRecordHandle, _contacts_url.url, &pCharValue);
1725 contacts_record_set_str(dstRecordHandle, _contacts_url.url, pCharValue);
1727 contacts_record_add_child_record(dstHandle, _contacts_my_profile.url, dstRecordHandle);
1729 urlHandle.Release();
1733 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.nickname, &count);
1734 for (i = 0; i < count; i++)
1736 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.nickname, i, &srcRecordHandle);
1738 ret = contacts_record_create(_contacts_nickname._uri, &dstRecordHandle);
1739 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1741 __ContactsRecordHandle nicknameHandle(dstRecordHandle);
1743 contacts_record_get_str_p(srcRecordHandle, _contacts_nickname.name, &pCharValue);
1744 contacts_record_set_str(dstRecordHandle, _contacts_nickname.name, pCharValue);
1746 contacts_record_add_child_record(dstHandle, _contacts_my_profile.nickname, dstRecordHandle);
1748 nicknameHandle.Release();
1752 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.relationship, &count);
1753 for (i = 0; i < count; i++)
1755 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.relationship, i, &srcRecordHandle);
1757 ret = contacts_record_create(_contacts_relationship._uri, &dstRecordHandle);
1758 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1760 __ContactsRecordHandle relationshipHandle(dstRecordHandle);
1762 contacts_record_get_str_p(srcRecordHandle, _contacts_relationship.name, &pCharValue);
1763 contacts_record_set_str(dstRecordHandle, _contacts_relationship.name, pCharValue);
1765 contacts_record_add_child_record(dstHandle, _contacts_my_profile.relationship, dstRecordHandle);
1767 relationshipHandle.Release();
1771 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.image, &count);
1774 contacts_record_get_int(srcHandle, _contacts_my_profile.id, &recordId);
1776 if (count > 0 && recordId == 0)
1778 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.image, 0, &srcRecordHandle);
1780 ret = contacts_record_create(_contacts_image._uri, &dstRecordHandle);
1781 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1783 __ContactsRecordHandle imageHandle(dstRecordHandle);
1785 contacts_record_get_int(srcRecordHandle, _contacts_image.type, &intValue);
1786 contacts_record_set_int(dstRecordHandle, _contacts_image.type, intValue);
1788 contacts_record_get_str_p(srcRecordHandle, _contacts_image.label, &pCharValue);
1789 contacts_record_set_str(dstRecordHandle, _contacts_image.label, pCharValue);
1791 contacts_record_get_str_p(srcRecordHandle, _contacts_image.path, &pCharValue);
1792 contacts_record_set_str(dstRecordHandle, _contacts_image.path, pCharValue);
1794 contacts_record_add_child_record(dstHandle, _contacts_contact.image, dstRecordHandle);
1796 imageHandle.Release();
1803 _AddressbookImpl::OnContactChanged(void)
1805 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1810 std::unique_ptr<IList, AllElementsDeleter> pChangedContactList(GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact));
1811 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1813 if (pChangedContactList->GetCount() > 0)
1815 if (__pIAddressbookEventListener != null)
1817 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
1819 else if (__pIAddressbookChangeEventListener != null)
1821 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
1825 RecordEventType recordEventType = RECORD_ADDED;
1826 std::unique_ptr<IEnumerator> pEnum(pChangedContactList->GetEnumeratorN());
1827 std::unique_ptr<Contact> pContact(null);
1829 while (pEnum->MoveNext() == E_SUCCESS)
1831 ContactChangeInfo* pContactChagneInfo = static_cast<ContactChangeInfo*>(pEnum->GetCurrent());
1833 if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
1835 recordEventType = RECORD_ADDED;
1836 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
1837 if (pContact == null)
1839 if (GetLastResult() == E_OBJ_NOT_FOUND)
1849 else if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
1851 recordEventType = RECORD_UPDATED;
1852 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
1853 if (pContact == null)
1855 if (GetLastResult() == E_OBJ_NOT_FOUND)
1867 recordEventType = RECORD_REMOVED;
1868 pContact.reset(new (std::nothrow) Contact());
1869 if (pContact == null)
1871 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1875 _RecordImpl::GetInstance(*pContact)->SetRecordId(pContactChagneInfo->GetContactId());
1878 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CONTACT, *pContact, null, null);
1886 _AddressbookImpl::OnCategoryChanged(void)
1888 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
1893 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup));
1894 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1896 if (pChangedCategoryList->GetCount() > 0)
1898 if (__pIAddressbookEventListener != null)
1900 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1902 else if (__pIAddressbookChangeEventListener != null)
1904 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
1908 RecordEventType recordEventType = RECORD_ADDED;
1909 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
1910 std::unique_ptr<Category> pCategory(null);
1912 while (pEnum->MoveNext() == E_SUCCESS)
1914 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
1916 if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
1918 recordEventType = RECORD_ADDED;
1919 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1920 if (pCategory == null)
1922 if (GetLastResult() == E_OBJ_NOT_FOUND)
1932 else if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
1934 recordEventType = RECORD_UPDATED;
1935 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1936 if (pCategory == null)
1938 if (GetLastResult() == E_OBJ_NOT_FOUND)
1950 recordEventType = RECORD_REMOVED;
1951 pCategory.reset(new (std::nothrow) Category());
1952 if (pCategory == null)
1954 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1958 _RecordImpl::GetInstance(*pCategory)->SetRecordId(pCategoryChagneInfo->GetCategoryId());
1961 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
1969 _AddressbookImpl::OnRelationChanged(void)
1971 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null)
1976 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation));
1977 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1979 if (pChangedCategoryList->GetCount() > 0)
1981 if (__pIAddressbookEventListener != null)
1983 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
1987 RecordEventType recordEventType = RECORD_ADDED;
1988 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
1989 std::unique_ptr<Category> pCategory(null);
1991 while (pEnum->MoveNext() == E_SUCCESS)
1993 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
1995 recordEventType = RECORD_UPDATED;
1996 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
1997 if (pCategory == null)
1999 if (GetLastResult() == E_OBJ_NOT_FOUND)
2009 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2016 _AddressbookImpl::GetInstance(Addressbook& addressbook)
2018 return addressbook.__pAddressbookImpl;
2021 const _AddressbookImpl*
2022 _AddressbookImpl::GetInstance(const Addressbook& addressbook)
2024 return addressbook.__pAddressbookImpl;