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>
25 #include <FBaseColIListT.h>
26 #include <FBaseColArrayListT.h>
27 #include <FBaseResult.h>
28 #include <FBaseLongLong.h>
29 #include <FBaseInteger.h>
31 #include <FSclContact.h>
32 #include <FSclCategory.h>
33 #include <FSclUserProfile.h>
34 #include <FSclContactChangeInfo.h>
35 #include <FSclCategoryChangeInfo.h>
36 #include <FSclAddressbook.h>
37 #include <FSclIAddressbookEventListener.h>
38 #include <FSclIAddressbookChangeEventListener.h>
39 #include <FSclIRecordEventListener.h>
40 #include <FApp_AppInfo.h>
41 #include <FBaseSysLog.h>
42 #include <FBase_StringConverter.h>
43 #include "FScl_AddressbookImpl.h"
44 #include "FScl_AddressbookUtil.h"
45 #include "FScl_CategoryChangeInfoImpl.h"
46 #include "FScl_CategoryImpl.h"
47 #include "FScl_ContactChangeInfoImpl.h"
48 #include "FScl_ContactDbMonitor.h"
49 #include "FScl_ContactImpl.h"
50 #include "FScl_RecordImpl.h"
51 #include "FScl_UserProfileImpl.h"
52 #include "FScl_ContactDbConnector.h"
55 using namespace Tizen::App;
56 using namespace Tizen::Base;
57 using namespace Tizen::Base::Collection;
58 using namespace Tizen::Graphics;
59 using namespace Tizen::Io;
61 namespace Tizen { namespace Social
64 _AddressbookImpl::_AddressbookImpl(void)
65 : __pIRecordEventListener(null)
66 , __pIAddressbookEventListener(null)
67 , __pIAddressbookChangeEventListener(null)
68 , __dbVersionForContact(0)
69 , __dbVersionForGroup(0)
70 , __dbVersionForRelation(0)
71 , __addressbookId(INVALID_ADDRESSBOOK_ID)
77 _AddressbookImpl::~_AddressbookImpl(void)
79 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
81 _ContactDbMonitor* pDbMonitor = _ContactDbMonitor::GetInstance();
82 if (pDbMonitor != null)
84 pDbMonitor->RemoveListener(*this);
90 _AddressbookImpl::Construct(void)
92 static AccountId accountId = 0;
97 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
100 unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, DEFAULT_ADDRESSBOOK_ID));
101 SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
102 contacts_record_get_str_p(pAbRecord.get(), _contacts_address_book.name, &pName);
103 contacts_record_get_int(pAbRecord.get(), _contacts_address_book.account_id, &accountId);
107 __addressbookId = DEFAULT_ADDRESSBOOK_ID;
108 __accountId = accountId;
115 _AddressbookImpl::SetRecordEventListener(IRecordEventListener* pListener)
117 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
119 result r = E_SUCCESS;
121 if (pListener != null)
123 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null)
125 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
126 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
128 r = pContactDbMonitor->AddListener(*this);
129 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
132 __dbVersionForContact = GetLatestVersion();
133 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
135 __dbVersionForGroup = __dbVersionForContact;
136 __dbVersionForRelation = __dbVersionForContact;
138 __pIAddressbookEventListener = null;
139 __pIAddressbookChangeEventListener = null;
140 __pIRecordEventListener = pListener;
144 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
146 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
147 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()))
148 pContactDbMonitor->RemoveListener(*this);
151 __pIAddressbookEventListener = null;
152 __pIAddressbookChangeEventListener = null;
153 __pIRecordEventListener = null;
160 _AddressbookImpl::SetAddressbookEventListener(IAddressbookEventListener* pListener)
162 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
164 result r = E_SUCCESS;
166 if (pListener != null)
168 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null && __pIAddressbookChangeEventListener == null)
170 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
171 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
173 r = pContactDbMonitor->AddListener(*this);
174 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
177 __dbVersionForContact = GetLatestVersion();
178 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
180 __dbVersionForGroup = __dbVersionForContact;
181 __dbVersionForRelation = __dbVersionForContact;
183 __pIRecordEventListener = null;
184 __pIAddressbookChangeEventListener = null;
185 __pIAddressbookEventListener = pListener;
189 if (__pIAddressbookEventListener != null || __pIRecordEventListener != null || __pIAddressbookChangeEventListener != null)
191 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
192 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
194 pContactDbMonitor->RemoveListener(*this);
197 __pIAddressbookEventListener = null;
198 __pIAddressbookChangeEventListener = null;
199 __pIRecordEventListener = null;
206 _AddressbookImpl::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
208 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
210 result r = E_SUCCESS;
212 if (pListener != null)
214 if (__pIAddressbookEventListener == null && __pIAddressbookChangeEventListener == null && __pIRecordEventListener == null)
216 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
217 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
219 r = pContactDbMonitor->AddListener(*this);
220 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
223 __dbVersionForContact = GetLatestVersion();
224 SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
226 __dbVersionForGroup = __dbVersionForContact;
227 __dbVersionForRelation = __dbVersionForContact;
229 __pIRecordEventListener = null;
230 __pIAddressbookEventListener = null;
231 __pIAddressbookChangeEventListener = pListener;
235 if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null || __pIRecordEventListener != null)
237 _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
238 SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
240 pContactDbMonitor->RemoveListener(*this);
243 __pIAddressbookEventListener = null;
244 __pIAddressbookChangeEventListener = null;
245 __pIRecordEventListener = null;
252 _AddressbookImpl::SetId(AddressbookId addressbookId)
254 __addressbookId = addressbookId;
258 _AddressbookImpl::SetAccountId(AccountId accountId)
260 __accountId = accountId;
264 _AddressbookImpl::SetName(const String& name)
270 _AddressbookImpl::GetId(void) const
272 return __addressbookId;
276 _AddressbookImpl::GetAccountId(void) const
282 _AddressbookImpl::GetName(void) const
288 _AddressbookImpl::AddContact(Contact& contact)
290 if (_ContactImpl::GetInstance(contact)->IsRemoved())
292 result r = _ContactImpl::GetInstance(contact)->Invalidate();
293 SysTryReturn(NID_SCL, r == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
296 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));
297 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));
298 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
300 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
301 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
304 result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
305 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
307 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, recordId));
308 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
310 _ContactImpl::GetInstance(contact)->SetContactRecordHandle(pContactRecord.release());
311 _RecordImpl::GetInstance(contact)->SetRecordId(recordId);
317 _AddressbookImpl::AddCategory(Category& category)
319 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));
320 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
322 contacts_record_h recordHandle = null;
323 unique_ptr<IListT<int> > pList(null);
325 recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
326 contacts_record_set_int(recordHandle, _contacts_group.address_book_id, __addressbookId);
328 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
330 // It is not allowed to have a same name with other.
332 char* pCharValue = null;
333 contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue);
335 __Filter<__ContactsGroup> filter;
337 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
338 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
339 filter.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue);
341 __Query<__ContactsGroup> query;
343 query.SetFilter(filter);
345 count = _AddressbookUtil::GetCountWithQuery(query);
346 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
347 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));
351 result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
352 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
354 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, recordId));
355 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
357 _CategoryImpl::GetInstance(category)->SetRecordHandle(pCategoryRecord.release());
358 _RecordImpl::GetInstance(category)->SetRecordId(recordId);
360 pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
361 if (pList != null && pList->GetCount() > 0)
363 unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
365 while (pEnum->MoveNext() == E_SUCCESS)
368 pEnum->GetCurrent(tableId);
370 AddMemberToCategory(category.GetRecordId(), tableId);
373 _CategoryImpl::GetInstance(category)->ClearAddedMemberList();
380 _AddressbookImpl::RemoveContact(RecordId contactId)
382 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));
383 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
384 result r = _AddressbookUtil::DeleteContactRecord(_contacts_contact._uri, contactId);
385 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
391 _AddressbookImpl::RemoveContact(Contact& contact)
393 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));
394 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
396 result r = RemoveContact(contact.GetRecordId());
397 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
399 _ContactImpl::GetInstance(contact)->SetAsRemoved();
400 _RecordImpl::GetInstance(contact)->SetRecordId(INVALID_RECORD_ID);
406 _AddressbookImpl::RemoveCategory(RecordId categoryId)
408 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);
409 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
410 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
411 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
413 bool isReadOnly = false;
414 contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly);
415 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));
417 result r = _AddressbookUtil::DeleteContactRecord(_contacts_group._uri, categoryId);
418 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
424 _AddressbookImpl::UpdateContact(const Contact& contact)
426 RecordId contactId = contact.GetRecordId();
427 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
428 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));
429 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
431 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
432 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
435 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
436 SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
438 contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
439 SysTryReturn(NID_SCL, recordHandle != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
441 result r = _AddressbookUtil::UpdateContactRecord(recordHandle);
442 if (r == E_OBJ_NOT_FOUND)
444 unsigned int count = 0;
445 unsigned int count2 = 0;
447 contacts_record_h newRecordHandle = null;
448 int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &newRecordHandle);
449 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));
450 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
452 contacts_record_get_child_record_count(newRecordHandle, _contacts_contact.image, &count);
453 contacts_record_get_child_record_count(recordHandle, _contacts_contact.image, &count2);
455 contacts_record_h imageHandle = null;
456 contacts_record_h imageHandle2 = null;
461 for (int i = (int)count2 - 1; i >= 0; i--)
463 contacts_record_get_child_record_at_p(recordHandle, _contacts_contact.image, i, &imageHandle);
464 contacts_record_get_int(imageHandle, _contacts_image.id, &imageId);
470 bool matchFound = false;
472 for (unsigned int j = 0; j < count; j++)
474 contacts_record_get_child_record_at_p(newRecordHandle, _contacts_contact.image, i, &imageHandle2);
475 contacts_record_get_int(imageHandle2, _contacts_image.id, &imageId2);
476 if (imageId == imageId2)
485 contacts_record_remove_child_record(recordHandle, _contacts_contact.image, imageHandle);
489 contacts_record_destroy(newRecordHandle, true);
491 contacts_record_h copyRecordHandle = CopyContactRecordHandle(recordHandle);
492 SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
494 contacts_record_h tempHandle = null;
495 contacts_record_get_child_record_count(copyRecordHandle, _contacts_contact.image, &count);
497 char* pCharValue = null;
500 for (unsigned int i = 0; i < count; i++)
502 contacts_record_get_child_record_at_p(copyRecordHandle, _contacts_contact.image, i, &tempHandle);
503 contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue);
505 tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp";
506 tempPath.Append((int)i);
507 tempPath.Append(L".jpg");
508 String servicePath(pCharValue);
510 File::Copy(servicePath, tempPath, true);
512 std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(tempPath));
513 SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
515 contacts_record_set_str(tempHandle, _contacts_image.path, pCharArray.get());
516 contacts_record_get_str(tempHandle, _contacts_image.path, &pCharValue);
521 ret = contacts_db_replace_record(copyRecordHandle, contactId);
522 contacts_record_destroy(copyRecordHandle, true);
524 for (unsigned int i = 0; i < count; i++)
526 tempPath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/temp";
527 tempPath.Append((int)i);
528 tempPath.Append(L".jpg");
530 File::Remove(tempPath);
534 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));
535 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
536 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
540 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
542 pContactRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contact.GetRecordId()));
543 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
545 _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(pContactRecord.release());
551 _AddressbookImpl::UpdateCategory(const Category& category)
553 RecordId categoryId = category.GetRecordId();
554 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));
555 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));
556 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
558 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
559 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
562 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
563 SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
565 contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
567 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
570 char* pCharValue = null;
572 contacts_record_get_str_p(recordHandle, _contacts_group.name, &pCharValue);
573 contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
575 __Filter<__ContactsGroup> filter1;
577 filter1.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
578 filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
579 filter1.AddString(_contacts_group.name, CONTACTS_MATCH_EXACTLY, pCharValue);
581 __Filter<__ContactsGroup> filter2;
583 filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_LESS_THAN, intValue);
584 filter2.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
585 filter2.AddInt(_contacts_group.id, CONTACTS_MATCH_GREATER_THAN, intValue);
587 filter1.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
588 filter1.AddFilter(filter2);
590 __Query<__ContactsGroup> query;
592 query.SetFilter(filter1);
594 count = _AddressbookUtil::GetCountWithQuery(query);
595 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
596 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));
599 result r = _AddressbookUtil::UpdateContactRecord(recordHandle);
600 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
602 pCategoryRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
603 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
605 _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(pCategoryRecord.release());
607 std::unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
608 if (pList != null && pList->GetCount() > 0)
611 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
612 while (pEnum->MoveNext() == E_SUCCESS)
614 pEnum->GetCurrent(tableId);
616 AddMemberToCategory(category.GetRecordId(), tableId);
619 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearAddedMemberList();
622 pList.reset(_CategoryImpl::GetInstance(category)->GetRemovedMembersN());
623 if (pList != null && pList->GetCount() > 0)
626 std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
627 while (pEnum->MoveNext() == E_SUCCESS)
629 pEnum->GetCurrent(tableId);
631 RemoveMemberFromCategory(category.GetRecordId(), tableId);
634 const_cast<_CategoryImpl*>(_CategoryImpl::GetInstance(category))->ClearRemovedMemberList();
641 _AddressbookImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
643 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);
644 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);
645 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
647 int addressbookId = 0;
648 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
649 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
650 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.address_book_id, &addressbookId);
652 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));
654 int ret = contacts_group_add_contact(categoryId, contactId);
655 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
656 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));
657 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
663 _AddressbookImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
665 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);
666 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);
667 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
669 int addressbookId = 0;
670 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
671 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
672 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.address_book_id, &addressbookId);
674 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));
676 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
677 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
678 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.address_book_id, &addressbookId);
680 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));
682 int ret = contacts_group_remove_contact(categoryId, contactId);
683 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
684 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));
685 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
691 _AddressbookImpl::GetAllCategoriesN(void) const
693 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
697 __Filter<__ContactsGroup> filter;
699 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
701 __Query<__ContactsGroup> query;
703 query.SetFilter(filter);
704 query.SetSort(_contacts_group.name, true);
707 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
708 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
714 _AddressbookImpl::GetCategoriesByContactN(RecordId contactId) const
716 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
717 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));
721 __Filter<__ContactsGroupRelation> filter;
723 filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
725 __Query<__ContactsGroupRelation> query;
727 query.SetFilter(filter);
728 query.SetSort(_contacts_group_relation.name, true);
730 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query);
731 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
737 _AddressbookImpl::GetAllContactsN(void) const
739 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
743 __Filter<__ContactsContact> filter;
745 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
747 __Query<__ContactsContact> query;
749 query.SetFilter(filter);
750 query.SetSort(_contacts_contact.display_name, true);
752 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
753 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
759 _AddressbookImpl::GetContactsByCategoryN(RecordId categoryId) const
761 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));
762 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
766 __Filter<__ContactsContactGroupRel> filter;
768 if (categoryId != INVALID_RECORD_ID)
770 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
774 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
777 __Query<__ContactsContactGroupRel> query;
779 query.SetFilter(filter);
780 query.SetSort(_contacts_contact_grouprel.display_name, true);
782 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
783 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
789 _AddressbookImpl::GetContactsN(int pageNo, int countPerPage) const
791 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);
792 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
794 int offset = (pageNo - 1)*countPerPage;
795 int limit = countPerPage;
799 __Filter<__ContactsContact> filter;
801 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
803 __Query<__ContactsContact> query;
805 query.SetFilter(filter);
806 query.SetSort(_contacts_contact.display_name, true);
808 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, limit);
809 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
815 _AddressbookImpl::GetContactsInN(const Category& category, int pageNo, int countPerPage) const
817 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));
818 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);
819 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
821 int offset = (pageNo - 1)*countPerPage;
822 int limit = countPerPage;
826 __Filter<__ContactsContactGroupRel> filter;
828 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, category.GetRecordId());
830 __Query<__ContactsContactGroupRel> query;
832 query.SetFilter(filter);
833 query.SetSort(_contacts_contact_grouprel.display_name, true);
835 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query, offset, limit);
836 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
842 _AddressbookImpl::SearchContactsByEmailN(const String& email) const
844 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));
845 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
847 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
849 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));
854 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
855 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
857 __Filter<__ContactsContactEmail> filter;
859 filter.AddInt(_contacts_contact_email.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
860 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
861 filter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
863 unsigned int projectionIds[1];
864 projectionIds[0] = _contacts_contact_email.contact_id;
866 __Query<__ContactsContactEmail> query;
868 query.SetProjection(projectionIds, 1);
869 query.SetFilter(filter);
870 query.SetDistinct(true);
871 query.SetSort(_contacts_contact_email.display_name, true);
873 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
874 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
880 _AddressbookImpl::SearchContactsByNameN(const String& name) const
882 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));
883 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
885 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
887 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));
892 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
893 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
895 __Filter<__ContactsContact> filter;
897 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
898 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
899 filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
901 __Query<__ContactsContact> query;
903 query.SetFilter(filter);
904 query.SetSort(_contacts_contact.display_name, true);
905 query.SetDistinct(true);
907 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
908 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
915 _AddressbookImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
917 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));
918 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
921 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
923 int count = phoneNumber.GetLength();
924 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));
929 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
930 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
932 __Filter<__ContactsContactNumber> subFilter;
933 subFilter.Construct();
934 subFilter.AddString(_contacts_contact_number.normalized_number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
935 subFilter.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
936 subFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
938 __Filter<__ContactsContactNumber> filter;
940 filter.AddInt(_contacts_contact_number.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
941 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
942 filter.AddFilter(subFilter);
944 unsigned int projectionIds[1];
945 projectionIds[0] = _contacts_contact_number.contact_id;
947 __Query<__ContactsContactNumber> query;
949 query.SetProjection(projectionIds, 1);
950 query.SetFilter(filter);
951 query.SetDistinct(true);
952 query.SetSort(_contacts_contact_number.display_name, true);
954 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
955 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
961 _AddressbookImpl::GetCategoryCount(void) const
963 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
969 __Filter<__ContactsGroup> filter;
971 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
973 __Query<__ContactsGroup> query;
975 query.SetFilter(filter);
977 count = _AddressbookUtil::GetCountWithQuery(query);
978 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
984 _AddressbookImpl::GetContactCount(void) const
986 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
992 __Filter<__ContactsContact> filter;
994 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
996 __Query<__ContactsContact> query;
998 query.SetFilter(filter);
1000 count = _AddressbookUtil::GetCountWithQuery(query);
1001 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1007 _AddressbookImpl::GetContactN(RecordId contactId) const
1009 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
1010 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1014 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId));
1015 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1018 contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue);
1019 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1021 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
1022 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1024 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
1025 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
1027 return pContact.release();
1031 _AddressbookImpl::GetCategoryN(RecordId categoryId) const
1033 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
1034 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1038 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
1039 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1043 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
1044 SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1046 unique_ptr<Category> pCategory(new (std::nothrow) Category());
1047 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1049 __Filter<__ContactsGroupRelation> filter;
1051 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1053 __Query<__ContactsGroupRelation> query;
1055 query.SetFilter(filter);
1057 int count = _AddressbookUtil::GetCountWithQuery(query);
1058 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1060 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
1061 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1062 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1064 return pCategory.release();
1068 _AddressbookImpl::GetLatestVersion(void) const
1070 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1072 int latestVersion = -1;
1076 int ret = contacts_db_get_current_version(&latestVersion);
1077 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, -1, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1078 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1080 return latestVersion;
1084 _AddressbookImpl::GetChangedContactsAfterN(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 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1092 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1094 return pChangedContacts;
1098 _AddressbookImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1100 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);
1101 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1105 int latestVersion1 = 0;
1106 int latestVersion2 = 0;
1108 std::unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion1));
1109 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1111 std::unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion2));
1112 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1114 std::unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1115 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1117 result r = pChangeList->AddItems(*pChangedGroups);
1118 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1120 r = pChangeList->AddItems(*pChangedRelations);
1121 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1123 pChangedGroups->RemoveAll(false);
1124 pChangedRelations->RemoveAll(false);
1126 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1128 return pChangeList.release();
1132 _AddressbookImpl::GetChangedContactInfoListN(int version, int& latestVersion) const
1134 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);
1135 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1139 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1140 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1142 return pChangedContacts;
1146 _AddressbookImpl::GetChangedCategoryInfoListN(int version, int& latestVersion) const
1148 return GetChangedGroupsAfterN(version, latestVersion);
1152 _AddressbookImpl::GetChangedGroupsAfterN(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* pChangedGroups = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1160 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1162 return pChangedGroups;
1166 _AddressbookImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1168 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);
1169 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1173 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1174 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1176 return pChangedRelations;
1180 _AddressbookImpl::AddContacts(const Tizen::Base::Collection::IList& contactList, Tizen::Base::Collection::IListT<RecordId>* pContactIdList)
1182 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1183 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1185 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1186 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1188 Contact* pContact = null;
1189 int ret = CONTACTS_ERROR_NONE;
1190 int* pContactIds = null;
1191 unsigned int contactsCount = 0;
1193 contacts_record_h recordHandle = null;
1194 contacts_list_h listHandle = null;
1196 ret = contacts_list_create(&listHandle);
1197 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1199 while (pContactEnum->MoveNext() == E_SUCCESS)
1201 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1203 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1205 contacts_list_destroy(listHandle, false);
1206 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1207 return E_INVALID_ARG;
1209 if (pContact->GetRecordId() != INVALID_RECORD_ID)
1211 contacts_list_destroy(listHandle, false);
1212 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1213 return E_INVALID_ARG;
1216 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1217 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
1218 contacts_list_add(listHandle, recordHandle);
1221 ret = contacts_db_insert_records(listHandle, &pContactIds, &contactsCount);
1222 contacts_list_destroy(listHandle, false);
1223 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));
1224 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1225 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1226 SysTryReturn(NID_SCL, pContactIds, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1228 int* pTemp = pContactIds;
1230 if (pContactIdList != null)
1232 for (unsigned int i = 0; i < contactsCount; i++)
1234 pContactIdList->Add(*pTemp);
1245 _AddressbookImpl::UpdateContacts(const Tizen::Base::Collection::IList& contactList)
1247 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1248 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1250 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1251 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1253 Contact* pContact = null;
1254 int ret = CONTACTS_ERROR_NONE;
1255 contacts_record_h recordHandle = null;
1256 contacts_list_h listHandle = null;
1258 ret = contacts_list_create(&listHandle);
1259 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1261 while (pContactEnum->MoveNext() == E_SUCCESS)
1263 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1265 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1267 contacts_list_destroy(listHandle, false);
1268 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1269 return E_INVALID_ARG;
1271 if (pContact->GetRecordId() == INVALID_RECORD_ID)
1273 contacts_list_destroy(listHandle, false);
1274 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1275 return E_INVALID_ARG;
1278 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1279 contacts_list_add(listHandle, recordHandle);
1282 result r = _AddressbookUtil::UpdateContactRecords(listHandle);
1283 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1284 contacts_list_destroy(listHandle, false);
1290 _AddressbookImpl::RemoveContacts(const Tizen::Base::Collection::IListT<RecordId>& contactIdList)
1292 SysTryReturn(NID_SCL, contactIdList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactIdList is empty.", GetErrorMessage(E_INVALID_ARG));
1293 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1295 std::unique_ptr<IEnumeratorT<RecordId> > pContactIdEnum(contactIdList.GetEnumeratorN());
1296 SysTryReturnResult(NID_SCL, pContactIdEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1298 RecordId contactId = INVALID_RECORD_ID;
1299 int ret = CONTACTS_ERROR_NONE;
1300 int count = contactIdList.GetCount();
1301 std::unique_ptr<int[]> pRecordIds(new (std::nothrow) int[count]);
1302 int* pInt = pRecordIds.get();
1305 while (pContactIdEnum->MoveNext() == E_SUCCESS)
1307 pContactIdEnum->GetCurrent(contactId);
1308 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));
1314 ret = contacts_db_delete_records(_contacts_contact._uri, pInt, count);
1315 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));
1316 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));
1322 _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
1324 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1327 int existingRecordId = 0;
1328 int ret = CONTACTS_ERROR_NONE;
1329 result r = E_SUCCESS;
1330 contacts_record_h recordHandle = null;
1332 std::unique_ptr<UserProfile> pExistingProfile(GetUserProfileN());
1333 SysTryReturn(NID_SCL, pExistingProfile != null || GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1335 if (pExistingProfile != null)
1337 recordHandle = _UserProfileImpl::GetInstance(*pExistingProfile)->GetUserProfileHandle();
1338 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &existingRecordId);
1341 if (pUserProfile != null)
1343 SysTryReturn(NID_SCL, !((_UserProfileImpl::GetInstance(*pUserProfile))->IsEmpty()), E_SYSTEM, E_SYSTEM, "[%s] UserProfile is Empty.", GetErrorMessage(E_SYSTEM));
1345 recordHandle = _UserProfileImpl::GetInstance(*pUserProfile)->GetUserProfileHandle();
1346 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &recordId);
1349 if (pExistingProfile != null)
1351 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1352 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1355 contacts_record_h newRecordHandle = null;
1356 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1357 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));
1359 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1360 if (ret != CONTACTS_ERROR_NONE)
1362 contacts_record_destroy(newRecordHandle, true);
1363 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1368 result r = _AddressbookUtil::InsertContactRecordN(newRecordHandle, recordId);
1369 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1371 else if (recordId > 0)
1373 if (recordId == existingRecordId)
1375 contacts_record_h newRecordHandle = null;
1376 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1377 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));
1379 result r = _AddressbookUtil::UpdateContactRecord(newRecordHandle);
1380 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1381 contacts_record_destroy(newRecordHandle, true);
1385 if (pExistingProfile != null)
1387 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1388 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1391 contacts_record_h newRecordHandle = null;
1392 ret = contacts_record_create(_contacts_my_profile._uri, &newRecordHandle);
1393 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1395 r = CopyMyProfileContents(recordHandle, newRecordHandle);
1398 contacts_record_destroy(newRecordHandle, true);
1399 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1400 return E_OUT_OF_MEMORY;
1404 ret = contacts_record_set_int(newRecordHandle, _contacts_my_profile.address_book_id, __addressbookId);
1405 if (ret != CONTACTS_ERROR_NONE)
1407 contacts_record_destroy(newRecordHandle, true);
1408 SysLogException(NID_SCL, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1413 result r = _AddressbookUtil::InsertContactRecordN(newRecordHandle, recordId);
1414 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1420 if (pExistingProfile != null)
1422 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1423 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1431 _AddressbookImpl::GetUserProfileN(void) const
1433 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1437 __Filter<__ContactsUserProfile> filter;
1439 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
1441 __Query<__ContactsUserProfile> query;
1443 query.SetFilter(filter);
1445 std::unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
1446 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1447 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
1448 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
1450 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
1451 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
1457 _AddressbookImpl::IsUserProfileChangedAfter(int version) const
1459 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);
1460 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1462 UserProfile* pExistingProfile = GetUserProfileN();
1463 if (pExistingProfile == null)
1468 delete pExistingProfile;
1472 int latestVersion = 0;
1473 int count = _AddressbookUtil::GetChangedItemCountByVersion<__ContactsMyProfileUpdatedInfo>(__addressbookId, version, latestVersion);
1474 SysTryReturn(NID_SCL, count >= 0, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1485 _AddressbookImpl::CopyMyProfileContents(contacts_record_h srcHandle, contacts_record_h dstHandle)
1487 int ret = CONTACTS_ERROR_NONE;
1489 unsigned int count = 0;
1491 char* pCharValue = null;
1493 contacts_record_h srcRecordHandle = null;
1494 contacts_record_h dstRecordHandle = null;
1497 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.name, &count);
1500 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.name, 0, &srcRecordHandle);
1502 ret = contacts_record_create(_contacts_name._uri, &dstRecordHandle);
1503 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1505 __ContactsRecordHandle nameHandle(dstRecordHandle);
1507 contacts_record_get_str(srcRecordHandle, _contacts_name.first, &pCharValue);
1508 contacts_record_set_str(dstRecordHandle, _contacts_name.first, pCharValue);
1510 contacts_record_get_str(srcRecordHandle, _contacts_name.last, &pCharValue);
1511 contacts_record_set_str(dstRecordHandle, _contacts_name.last, pCharValue);
1513 contacts_record_get_str(srcRecordHandle, _contacts_name.addition, &pCharValue);
1514 contacts_record_set_str(dstRecordHandle, _contacts_name.addition, pCharValue);
1516 contacts_record_get_str(srcRecordHandle, _contacts_name.suffix, &pCharValue);
1517 contacts_record_set_str(dstRecordHandle, _contacts_name.suffix, pCharValue);
1519 contacts_record_get_str(srcRecordHandle, _contacts_name.prefix, &pCharValue);
1520 contacts_record_set_str(dstRecordHandle, _contacts_name.prefix, pCharValue);
1522 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_first, &pCharValue);
1523 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_first, pCharValue);
1525 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
1526 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_middle, pCharValue);
1528 contacts_record_get_str(srcRecordHandle, _contacts_name.phonetic_last, &pCharValue);
1529 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_last, pCharValue);
1531 contacts_record_add_child_record(dstHandle, _contacts_my_profile.name, dstRecordHandle);
1533 nameHandle.Release();
1537 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.company, &count);
1538 for (i = 0; i < count; i++)
1540 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.company, i, &srcRecordHandle);
1542 ret = contacts_record_create(_contacts_company._uri, &dstRecordHandle);
1543 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1545 __ContactsRecordHandle companyHandle(dstRecordHandle);
1547 contacts_record_get_int(srcRecordHandle, _contacts_company.type, &intValue);
1548 contacts_record_set_int(dstRecordHandle, _contacts_company.type, intValue);
1550 contacts_record_get_str_p(srcRecordHandle, _contacts_company.name, &pCharValue);
1551 contacts_record_set_str(dstRecordHandle, _contacts_company.name, pCharValue);
1553 contacts_record_get_str_p(srcRecordHandle, _contacts_company.department, &pCharValue);
1554 contacts_record_set_str(dstRecordHandle, _contacts_company.department, pCharValue);
1556 contacts_record_get_str_p(srcRecordHandle, _contacts_company.job_title, &pCharValue);
1557 contacts_record_set_str(dstRecordHandle, _contacts_company.job_title, pCharValue);
1559 contacts_record_get_str_p(srcRecordHandle, _contacts_company.assistant_name, &pCharValue);
1560 contacts_record_set_str(dstRecordHandle, _contacts_company.assistant_name, pCharValue);
1562 contacts_record_get_str_p(srcRecordHandle, _contacts_company.role, &pCharValue);
1563 contacts_record_set_str(dstRecordHandle, _contacts_company.role, pCharValue);
1565 contacts_record_get_str_p(srcRecordHandle, _contacts_company.logo, &pCharValue);
1566 contacts_record_set_str(dstRecordHandle, _contacts_company.logo, pCharValue);
1568 contacts_record_get_str_p(srcRecordHandle, _contacts_company.location, &pCharValue);
1569 contacts_record_set_str(dstRecordHandle, _contacts_company.location, pCharValue);
1571 contacts_record_get_str_p(srcRecordHandle, _contacts_company.description, &pCharValue);
1572 contacts_record_set_str(dstRecordHandle, _contacts_company.description, pCharValue);
1574 contacts_record_get_str_p(srcRecordHandle, _contacts_company.phonetic_name, &pCharValue);
1575 contacts_record_set_str(dstRecordHandle, _contacts_company.phonetic_name, pCharValue);
1577 contacts_record_add_child_record(dstHandle, _contacts_my_profile.company, dstRecordHandle);
1579 companyHandle.Release();
1583 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.note, &count);
1584 for (i = 0; i < count; i++)
1586 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.note, i, &srcRecordHandle);
1588 ret = contacts_record_create(_contacts_note._uri, &dstRecordHandle);
1589 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1591 __ContactsRecordHandle noteHandle(dstRecordHandle);
1593 contacts_record_get_str_p(srcRecordHandle, _contacts_note.note, &pCharValue);
1594 contacts_record_set_str(dstRecordHandle, _contacts_note.note, pCharValue);
1596 contacts_record_add_child_record(dstHandle, _contacts_my_profile.note, dstRecordHandle);
1598 noteHandle.Release();
1602 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.number, &count);
1603 for (i = 0; i < count; i++)
1605 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.number, i, &srcRecordHandle);
1607 ret = contacts_record_create(_contacts_number._uri, &dstRecordHandle);
1608 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1610 __ContactsRecordHandle numberHandle(dstRecordHandle);
1612 contacts_record_get_int(srcRecordHandle, _contacts_number.type, &intValue);
1613 contacts_record_set_int(dstRecordHandle, _contacts_number.type, intValue);
1615 contacts_record_get_str_p(srcRecordHandle, _contacts_number.label, &pCharValue);
1616 contacts_record_set_str(dstRecordHandle, _contacts_number.label, pCharValue);
1618 contacts_record_get_str_p(srcRecordHandle, _contacts_number.number, &pCharValue);
1619 contacts_record_set_str(dstRecordHandle, _contacts_number.number, pCharValue);
1621 contacts_record_add_child_record(dstHandle, _contacts_my_profile.number, dstRecordHandle);
1623 numberHandle.Release();
1627 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.email, &count);
1628 for (i = 0; i < count; i++)
1630 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.email, i, &srcRecordHandle);
1632 ret = contacts_record_create(_contacts_email._uri, &dstRecordHandle);
1633 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1635 __ContactsRecordHandle emailHandle(dstRecordHandle);
1637 contacts_record_get_int(srcRecordHandle, _contacts_email.type, &intValue);
1638 contacts_record_set_int(dstRecordHandle, _contacts_email.type, intValue);
1640 contacts_record_get_str_p(srcRecordHandle, _contacts_email.label, &pCharValue);
1641 contacts_record_set_str(dstRecordHandle, _contacts_email.label, pCharValue);
1643 contacts_record_get_str_p(srcRecordHandle, _contacts_email.email, &pCharValue);
1644 contacts_record_set_str(dstRecordHandle, _contacts_email.email, pCharValue);
1646 contacts_record_add_child_record(dstHandle, _contacts_my_profile.email, dstRecordHandle);
1648 emailHandle.Release();
1653 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.event, &count);
1654 for (i = 0; i < count; i++)
1656 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.event, i, &srcRecordHandle);
1658 ret = contacts_record_create(_contacts_event._uri, &dstRecordHandle);
1659 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1661 __ContactsRecordHandle eventHandle(dstRecordHandle);
1663 contacts_record_get_int(srcRecordHandle, _contacts_event.type, &intValue);
1664 contacts_record_set_int(dstRecordHandle, _contacts_event.type, intValue);
1666 contacts_record_get_str_p(srcRecordHandle, _contacts_event.label, &pCharValue);
1667 contacts_record_set_str(dstRecordHandle, _contacts_event.label, pCharValue);
1669 contacts_record_get_int(srcRecordHandle, _contacts_event.date, &intValue);
1670 contacts_record_set_int(dstRecordHandle, _contacts_event.date, intValue);
1672 contacts_record_add_child_record(dstHandle, _contacts_my_profile.event, dstRecordHandle);
1674 eventHandle.Release();
1678 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.messenger, &count);
1679 for (i = 0; i < count; i++)
1681 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.messenger, i, &srcRecordHandle);
1683 ret = contacts_record_create(_contacts_messenger._uri, &dstRecordHandle);
1684 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1686 __ContactsRecordHandle imAddressHandle(dstRecordHandle);
1688 contacts_record_get_int(srcRecordHandle, _contacts_messenger.type, &intValue);
1689 contacts_record_set_int(dstRecordHandle, _contacts_messenger.type, intValue);
1691 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.label, &pCharValue);
1692 contacts_record_set_str(dstRecordHandle, _contacts_messenger.label, pCharValue);
1694 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.im_id, &pCharValue);
1695 contacts_record_set_str(dstRecordHandle, _contacts_messenger.im_id, pCharValue);
1697 contacts_record_add_child_record(dstHandle, _contacts_my_profile.messenger, dstRecordHandle);
1699 imAddressHandle.Release();
1703 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.address, &count);
1704 for (i = 0; i < count; i++)
1706 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.address, i, &srcRecordHandle);
1708 ret = contacts_record_create(_contacts_address._uri, &dstRecordHandle);
1709 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1711 __ContactsRecordHandle addressHandle(dstRecordHandle);
1713 contacts_record_get_int(srcRecordHandle, _contacts_address.type, &intValue);
1714 contacts_record_set_int(dstRecordHandle, _contacts_address.type, intValue);
1716 contacts_record_get_str_p(srcRecordHandle, _contacts_address.label, &pCharValue);
1717 contacts_record_set_str(dstRecordHandle, _contacts_address.label, pCharValue);
1719 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postbox, &pCharValue);
1720 contacts_record_set_str(dstRecordHandle, _contacts_address.postbox, pCharValue);
1722 contacts_record_get_str_p(srcRecordHandle, _contacts_address.extended, &pCharValue);
1723 contacts_record_set_str(dstRecordHandle, _contacts_address.extended, pCharValue);
1725 contacts_record_get_str_p(srcRecordHandle, _contacts_address.street, &pCharValue);
1726 contacts_record_set_str(dstRecordHandle, _contacts_address.street, pCharValue);
1728 contacts_record_get_str_p(srcRecordHandle, _contacts_address.locality, &pCharValue);
1729 contacts_record_set_str(dstRecordHandle, _contacts_address.locality, pCharValue);
1731 contacts_record_get_str_p(srcRecordHandle, _contacts_address.region, &pCharValue);
1732 contacts_record_set_str(dstRecordHandle, _contacts_address.region, pCharValue);
1734 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postal_code, &pCharValue);
1735 contacts_record_set_str(dstRecordHandle, _contacts_address.postal_code, pCharValue);
1737 contacts_record_get_str_p(srcRecordHandle, _contacts_address.country, &pCharValue);
1738 contacts_record_set_str(dstRecordHandle, _contacts_address.country, pCharValue);
1740 contacts_record_add_child_record(dstHandle, _contacts_my_profile.address, dstRecordHandle);
1742 addressHandle.Release();
1746 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.url, &count);
1747 for (i = 0; i < count; i++)
1749 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.url, i, &srcRecordHandle);
1751 ret = contacts_record_create(_contacts_url._uri, &dstRecordHandle);
1752 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1754 __ContactsRecordHandle urlHandle(dstRecordHandle);
1756 contacts_record_get_int(srcRecordHandle, _contacts_url.type, &intValue);
1757 contacts_record_set_int(dstRecordHandle, _contacts_url.type, intValue);
1759 contacts_record_get_str_p(srcRecordHandle, _contacts_url.label, &pCharValue);
1760 contacts_record_set_str(dstRecordHandle, _contacts_url.label, pCharValue);
1762 contacts_record_get_str_p(srcRecordHandle, _contacts_url.url, &pCharValue);
1763 contacts_record_set_str(dstRecordHandle, _contacts_url.url, pCharValue);
1765 contacts_record_add_child_record(dstHandle, _contacts_my_profile.url, dstRecordHandle);
1767 urlHandle.Release();
1771 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.nickname, &count);
1772 for (i = 0; i < count; i++)
1774 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.nickname, i, &srcRecordHandle);
1776 ret = contacts_record_create(_contacts_nickname._uri, &dstRecordHandle);
1777 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1779 __ContactsRecordHandle nicknameHandle(dstRecordHandle);
1781 contacts_record_get_str_p(srcRecordHandle, _contacts_nickname.name, &pCharValue);
1782 contacts_record_set_str(dstRecordHandle, _contacts_nickname.name, pCharValue);
1784 contacts_record_add_child_record(dstHandle, _contacts_my_profile.nickname, dstRecordHandle);
1786 nicknameHandle.Release();
1790 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.relationship, &count);
1791 for (i = 0; i < count; i++)
1793 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.relationship, i, &srcRecordHandle);
1795 ret = contacts_record_create(_contacts_relationship._uri, &dstRecordHandle);
1796 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1798 __ContactsRecordHandle relationshipHandle(dstRecordHandle);
1800 contacts_record_get_str_p(srcRecordHandle, _contacts_relationship.name, &pCharValue);
1801 contacts_record_set_str(dstRecordHandle, _contacts_relationship.name, pCharValue);
1803 contacts_record_add_child_record(dstHandle, _contacts_my_profile.relationship, dstRecordHandle);
1805 relationshipHandle.Release();
1809 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.image, &count);
1812 contacts_record_get_int(srcHandle, _contacts_my_profile.id, &recordId);
1814 if (count > 0 && recordId == 0)
1816 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.image, 0, &srcRecordHandle);
1818 ret = contacts_record_create(_contacts_image._uri, &dstRecordHandle);
1819 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1821 __ContactsRecordHandle imageHandle(dstRecordHandle);
1823 contacts_record_get_int(srcRecordHandle, _contacts_image.type, &intValue);
1824 contacts_record_set_int(dstRecordHandle, _contacts_image.type, intValue);
1826 contacts_record_get_str_p(srcRecordHandle, _contacts_image.label, &pCharValue);
1827 contacts_record_set_str(dstRecordHandle, _contacts_image.label, pCharValue);
1829 contacts_record_get_str_p(srcRecordHandle, _contacts_image.path, &pCharValue);
1830 contacts_record_set_str(dstRecordHandle, _contacts_image.path, pCharValue);
1832 contacts_record_add_child_record(dstHandle, _contacts_contact.image, dstRecordHandle);
1834 imageHandle.Release();
1841 _AddressbookImpl::CopyContactRecordHandle(contacts_record_h srcHandle)
1845 int ret = CONTACTS_ERROR_NONE;
1847 unsigned int count = 0;
1848 char* pCharValue = null;
1850 bool boolValue = false;
1852 contacts_record_h contactHandle = null;
1853 contacts_record_h sourceRecordHandle = null;
1854 contacts_record_h destRecordHandle = null;
1856 ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
1857 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1860 contacts_record_get_bool(srcHandle, _contacts_contact.is_favorite, &boolValue);
1861 contacts_record_set_bool(contactHandle, _contacts_contact.is_favorite, boolValue);
1864 contacts_record_get_str_p(srcHandle, _contacts_contact.uid, &pCharValue);
1865 contacts_record_set_str(contactHandle, _contacts_contact.uid, pCharValue);
1867 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1869 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1870 contacts_record_get_child_record_count(srcHandle, _contacts_contact.name, &count);
1873 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.name, 0, &sourceRecordHandle);
1875 ret = contacts_record_create(_contacts_name._uri, &destRecordHandle);
1876 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1878 __ContactsRecordHandle nameHandle(destRecordHandle);
1881 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.first, &pCharValue);
1882 contacts_record_set_str(destRecordHandle, _contacts_name.first, pCharValue);
1885 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.last, &pCharValue);
1886 contacts_record_set_str(destRecordHandle, _contacts_name.last, pCharValue);
1889 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.addition, &pCharValue);
1890 contacts_record_set_str(destRecordHandle, _contacts_name.addition, pCharValue);
1893 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.suffix, &pCharValue);
1894 contacts_record_set_str(destRecordHandle, _contacts_name.suffix, pCharValue);
1897 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.prefix, &pCharValue);
1898 contacts_record_set_str(destRecordHandle, _contacts_name.prefix, pCharValue);
1900 // 6. phonetic_first
1901 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_first, &pCharValue);
1902 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_first, pCharValue);
1905 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_last, &pCharValue);
1906 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_last, pCharValue);
1908 // 8. phonetic_middle
1909 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
1910 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_middle, pCharValue);
1912 contacts_record_add_child_record(contactHandle, _contacts_contact.name, destRecordHandle);
1914 nameHandle.Release();
1917 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1919 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1920 contacts_record_get_child_record_count(srcHandle, _contacts_contact.image, &count);
1921 for (i = 0; i < count; i++)
1923 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.image, i, &sourceRecordHandle);
1925 ret = contacts_record_create(_contacts_image._uri, &destRecordHandle);
1926 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1928 __ContactsRecordHandle imageHandle(destRecordHandle);
1930 contacts_record_get_int(sourceRecordHandle, _contacts_image.type, &intValue);
1931 contacts_record_set_int(destRecordHandle, _contacts_image.type, intValue);
1933 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.label, &pCharValue);
1934 contacts_record_set_str(destRecordHandle, _contacts_image.label, pCharValue);
1936 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.path, &pCharValue);
1937 contacts_record_set_str(destRecordHandle, _contacts_image.path, pCharValue);
1939 contacts_record_add_child_record(contactHandle, _contacts_contact.image, destRecordHandle);
1941 imageHandle.Release();
1944 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1946 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1947 contacts_record_get_child_record_count(srcHandle, _contacts_contact.company, &count);
1948 for (i = 0; i < count; i++)
1950 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.company, i, &sourceRecordHandle);
1952 ret = contacts_record_create(_contacts_company._uri, &destRecordHandle);
1953 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1955 __ContactsRecordHandle companyHandle(destRecordHandle);
1957 contacts_record_get_int(sourceRecordHandle, _contacts_company.type, &intValue);
1958 contacts_record_set_int(destRecordHandle, _contacts_company.type, intValue);
1960 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.name, &pCharValue);
1961 contacts_record_set_str(destRecordHandle, _contacts_company.name, pCharValue);
1963 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.department, &pCharValue);
1964 contacts_record_set_str(destRecordHandle, _contacts_company.department, pCharValue);
1966 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.job_title, &pCharValue);
1967 contacts_record_set_str(destRecordHandle, _contacts_company.job_title, pCharValue);
1969 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.assistant_name, &pCharValue);
1970 contacts_record_set_str(destRecordHandle, _contacts_company.assistant_name, pCharValue);
1972 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.role, &pCharValue);
1973 contacts_record_set_str(destRecordHandle, _contacts_company.role, pCharValue);
1975 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.logo, &pCharValue);
1976 contacts_record_set_str(destRecordHandle, _contacts_company.logo, pCharValue);
1978 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.location, &pCharValue);
1979 contacts_record_set_str(destRecordHandle, _contacts_company.location, pCharValue);
1981 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.description, &pCharValue);
1982 contacts_record_set_str(destRecordHandle, _contacts_company.description, pCharValue);
1984 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.phonetic_name, &pCharValue);
1985 contacts_record_set_str(destRecordHandle, _contacts_company.phonetic_name, pCharValue);
1987 contacts_record_add_child_record(contactHandle, _contacts_contact.company, destRecordHandle);
1989 companyHandle.Release();
1992 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1994 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1995 contacts_record_get_child_record_count(srcHandle, _contacts_contact.note, &count);
1996 for (i = 0; i < count; i++)
1998 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.note, i, &sourceRecordHandle);
2000 ret = contacts_record_create(_contacts_note._uri, &destRecordHandle);
2001 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2003 __ContactsRecordHandle noteHandle(destRecordHandle);
2005 contacts_record_get_str_p(sourceRecordHandle, _contacts_note.note, &pCharValue);
2006 contacts_record_set_str(destRecordHandle, _contacts_note.note, pCharValue);
2008 contacts_record_add_child_record(contactHandle, _contacts_contact.note, destRecordHandle);
2010 noteHandle.Release();
2013 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2015 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2016 contacts_record_get_child_record_count(srcHandle, _contacts_contact.number, &count);
2017 for (i = 0; i < count; i++)
2019 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.number, i, &sourceRecordHandle);
2021 ret = contacts_record_create(_contacts_number._uri, &destRecordHandle);
2022 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2024 __ContactsRecordHandle numberHandle(destRecordHandle);
2026 contacts_record_get_int(sourceRecordHandle, _contacts_number.type, &intValue);
2027 contacts_record_set_int(destRecordHandle, _contacts_number.type, intValue);
2029 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.label, &pCharValue);
2030 contacts_record_set_str(destRecordHandle, _contacts_number.label, pCharValue);
2032 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.number, &pCharValue);
2033 contacts_record_set_str(destRecordHandle, _contacts_number.number, pCharValue);
2035 contacts_record_add_child_record(contactHandle, _contacts_contact.number, destRecordHandle);
2037 numberHandle.Release();
2040 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2042 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2043 contacts_record_get_child_record_count(srcHandle, _contacts_contact.email, &count);
2044 for (i = 0; i < count; i++)
2046 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.email, i, &sourceRecordHandle);
2048 ret = contacts_record_create(_contacts_email._uri, &destRecordHandle);
2049 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2051 __ContactsRecordHandle emailHandle(destRecordHandle);
2053 contacts_record_get_int(sourceRecordHandle, _contacts_email.type, &intValue);
2054 contacts_record_set_int(destRecordHandle, _contacts_email.type, intValue);
2056 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.label, &pCharValue);
2057 contacts_record_set_str(destRecordHandle, _contacts_email.label, pCharValue);
2059 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.email, &pCharValue);
2060 contacts_record_set_str(destRecordHandle, _contacts_email.email, pCharValue);
2062 contacts_record_add_child_record(contactHandle, _contacts_contact.email, destRecordHandle);
2064 emailHandle.Release();
2068 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2070 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2071 contacts_record_get_child_record_count(srcHandle, _contacts_contact.event, &count);
2072 for (i = 0; i < count; i++)
2074 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.event, i, &sourceRecordHandle);
2076 ret = contacts_record_create(_contacts_event._uri, &destRecordHandle);
2077 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2079 __ContactsRecordHandle eventHandle(destRecordHandle);
2081 contacts_record_get_int(sourceRecordHandle, _contacts_event.type, &intValue);
2082 contacts_record_set_int(destRecordHandle, _contacts_event.type, intValue);
2084 contacts_record_get_str_p(sourceRecordHandle, _contacts_event.label, &pCharValue);
2085 contacts_record_set_str(destRecordHandle, _contacts_event.label, pCharValue);
2087 contacts_record_get_int(sourceRecordHandle, _contacts_event.date, &intValue);
2088 contacts_record_set_int(destRecordHandle, _contacts_event.date, intValue);
2090 contacts_record_add_child_record(contactHandle, _contacts_contact.event, destRecordHandle);
2092 eventHandle.Release();
2095 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2097 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2098 contacts_record_get_child_record_count(srcHandle, _contacts_contact.messenger, &count);
2099 for (i = 0; i < count; i++)
2101 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.messenger, i, &sourceRecordHandle);
2103 ret = contacts_record_create(_contacts_messenger._uri, &destRecordHandle);
2104 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2106 __ContactsRecordHandle imAddressHandle(destRecordHandle);
2108 contacts_record_get_int(sourceRecordHandle, _contacts_messenger.type, &intValue);
2109 contacts_record_set_int(destRecordHandle, _contacts_messenger.type, intValue);
2111 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.label, &pCharValue);
2112 contacts_record_set_str(destRecordHandle, _contacts_messenger.label, pCharValue);
2114 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.im_id, &pCharValue);
2115 contacts_record_set_str(destRecordHandle, _contacts_messenger.im_id, pCharValue);
2117 contacts_record_add_child_record(contactHandle, _contacts_contact.messenger, destRecordHandle);
2119 imAddressHandle.Release();
2122 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2124 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2125 contacts_record_get_child_record_count(srcHandle, _contacts_contact.address, &count);
2126 for (i = 0; i < count; i++)
2128 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.address, i, &sourceRecordHandle);
2130 ret = contacts_record_create(_contacts_address._uri, &destRecordHandle);
2131 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2133 __ContactsRecordHandle addressHandle(destRecordHandle);
2135 contacts_record_get_int(sourceRecordHandle, _contacts_address.type, &intValue);
2136 contacts_record_set_int(destRecordHandle, _contacts_address.type, intValue);
2138 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.label, &pCharValue);
2139 contacts_record_set_str(destRecordHandle, _contacts_address.label, pCharValue);
2141 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postbox, &pCharValue);
2142 contacts_record_set_str(destRecordHandle, _contacts_address.postbox, pCharValue);
2144 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.extended, &pCharValue);
2145 contacts_record_set_str(destRecordHandle, _contacts_address.extended, pCharValue);
2147 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.street, &pCharValue);
2148 contacts_record_set_str(destRecordHandle, _contacts_address.street, pCharValue);
2150 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.locality, &pCharValue);
2151 contacts_record_set_str(destRecordHandle, _contacts_address.locality, pCharValue);
2153 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.region, &pCharValue);
2154 contacts_record_set_str(destRecordHandle, _contacts_address.region, pCharValue);
2156 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postal_code, &pCharValue);
2157 contacts_record_set_str(destRecordHandle, _contacts_address.postal_code, pCharValue);
2159 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.country, &pCharValue);
2160 contacts_record_set_str(destRecordHandle, _contacts_address.country, pCharValue);
2162 contacts_record_add_child_record(contactHandle, _contacts_contact.address, destRecordHandle);
2164 addressHandle.Release();
2167 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2169 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2170 contacts_record_get_child_record_count(srcHandle, _contacts_contact.url, &count);
2171 for (i = 0; i < count; i++)
2173 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.url, i, &sourceRecordHandle);
2175 ret = contacts_record_create(_contacts_url._uri, &destRecordHandle);
2176 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2178 __ContactsRecordHandle urlHandle(destRecordHandle);
2180 contacts_record_get_int(sourceRecordHandle, _contacts_url.type, &intValue);
2181 contacts_record_set_int(destRecordHandle, _contacts_url.type, intValue);
2183 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.label, &pCharValue);
2184 contacts_record_set_str(destRecordHandle, _contacts_url.label, pCharValue);
2186 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.url, &pCharValue);
2187 contacts_record_set_str(destRecordHandle, _contacts_url.url, pCharValue);
2189 contacts_record_add_child_record(contactHandle, _contacts_contact.url, destRecordHandle);
2191 urlHandle.Release();
2194 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2196 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2197 contacts_record_get_child_record_count(srcHandle, _contacts_contact.nickname, &count);
2198 for (i = 0; i < count; i++)
2200 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.nickname, i, &sourceRecordHandle);
2202 ret = contacts_record_create(_contacts_nickname._uri, &destRecordHandle);
2203 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2205 __ContactsRecordHandle nicknameHandle(destRecordHandle);
2207 contacts_record_get_str_p(sourceRecordHandle, _contacts_nickname.name, &pCharValue);
2208 contacts_record_set_str(destRecordHandle, _contacts_nickname.name, pCharValue);
2210 contacts_record_add_child_record(contactHandle, _contacts_contact.nickname, destRecordHandle);
2212 nicknameHandle.Release();
2215 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2217 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2218 contacts_record_get_child_record_count(srcHandle, _contacts_contact.relationship, &count);
2219 for (i = 0; i < count; i++)
2221 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.relationship, i, &sourceRecordHandle);
2223 ret = contacts_record_create(_contacts_relationship._uri, &destRecordHandle);
2224 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2226 __ContactsRecordHandle relationshipHandle(destRecordHandle);
2228 contacts_record_get_str_p(sourceRecordHandle, _contacts_relationship.name, &pCharValue);
2229 contacts_record_set_str(destRecordHandle, _contacts_relationship.name, pCharValue);
2231 contacts_record_add_child_record(contactHandle, _contacts_contact.relationship, destRecordHandle);
2233 relationshipHandle.Release();
2236 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2238 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2239 contacts_record_get_child_record_count(srcHandle, _contacts_contact.profile, &count);
2240 for (i = 0; i < count; i++)
2242 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.profile, i, &sourceRecordHandle);
2244 ret = contacts_record_create(_contacts_profile._uri, &destRecordHandle);
2245 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2247 __ContactsRecordHandle profileHandle(destRecordHandle);
2249 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.text, &pCharValue);
2250 contacts_record_set_str(destRecordHandle, _contacts_profile.text, pCharValue);
2252 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uid, &pCharValue);
2253 contacts_record_set_str(destRecordHandle, _contacts_profile.uid, pCharValue);
2255 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.app_id, &pCharValue);
2256 contacts_record_set_str(destRecordHandle, _contacts_profile.app_id, pCharValue);
2258 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.service_operation, &pCharValue);
2259 contacts_record_set_str(destRecordHandle, _contacts_profile.service_operation, pCharValue);
2261 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uri, &pCharValue);
2262 contacts_record_set_str(destRecordHandle, _contacts_profile.uri, pCharValue);
2264 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.category, &pCharValue);
2265 contacts_record_set_str(destRecordHandle, _contacts_profile.category, pCharValue);
2267 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.mime, &pCharValue);
2268 contacts_record_set_str(destRecordHandle, _contacts_profile.mime, pCharValue);
2270 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.extra_data, &pCharValue);
2271 contacts_record_set_str(destRecordHandle, _contacts_profile.extra_data, pCharValue);
2273 contacts_record_add_child_record(contactHandle, _contacts_contact.profile, destRecordHandle);
2275 profileHandle.Release();
2278 return contactHandle;
2282 _AddressbookImpl::OnContactChanged(void)
2284 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
2289 std::unique_ptr<IList, AllElementsDeleter> pChangedContactList(GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact));
2290 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2292 if (pChangedContactList->GetCount() > 0)
2294 if (__pIAddressbookEventListener != null)
2296 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
2298 else if (__pIAddressbookChangeEventListener != null)
2300 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
2304 RecordEventType recordEventType = RECORD_ADDED;
2305 std::unique_ptr<IEnumerator> pEnum(pChangedContactList->GetEnumeratorN());
2306 std::unique_ptr<Contact> pContact(null);
2308 while (pEnum->MoveNext() == E_SUCCESS)
2310 ContactChangeInfo* pContactChagneInfo = static_cast<ContactChangeInfo*>(pEnum->GetCurrent());
2312 if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
2314 recordEventType = RECORD_ADDED;
2315 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
2316 if (pContact == null)
2318 if (GetLastResult() == E_OBJ_NOT_FOUND)
2328 else if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
2330 recordEventType = RECORD_UPDATED;
2331 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
2332 if (pContact == null)
2334 if (GetLastResult() == E_OBJ_NOT_FOUND)
2346 recordEventType = RECORD_REMOVED;
2347 pContact.reset(new (std::nothrow) Contact());
2348 if (pContact == null)
2350 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2354 _RecordImpl::GetInstance(*pContact)->SetRecordId(pContactChagneInfo->GetContactId());
2357 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CONTACT, *pContact, null, null);
2365 _AddressbookImpl::OnCategoryChanged(void)
2367 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
2372 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup));
2373 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2375 if (pChangedCategoryList->GetCount() > 0)
2377 if (__pIAddressbookEventListener != null)
2379 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
2381 else if (__pIAddressbookChangeEventListener != null)
2383 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
2387 RecordEventType recordEventType = RECORD_ADDED;
2388 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
2389 std::unique_ptr<Category> pCategory(null);
2391 while (pEnum->MoveNext() == E_SUCCESS)
2393 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
2395 if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
2397 recordEventType = RECORD_ADDED;
2398 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2399 if (pCategory == null)
2401 if (GetLastResult() == E_OBJ_NOT_FOUND)
2411 else if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
2413 recordEventType = RECORD_UPDATED;
2414 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2415 if (pCategory == null)
2417 if (GetLastResult() == E_OBJ_NOT_FOUND)
2429 recordEventType = RECORD_REMOVED;
2430 pCategory.reset(new (std::nothrow) Category());
2431 if (pCategory == null)
2433 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2437 _RecordImpl::GetInstance(*pCategory)->SetRecordId(pCategoryChagneInfo->GetCategoryId());
2440 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2448 _AddressbookImpl::OnRelationChanged(void)
2450 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null)
2455 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation));
2456 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2458 if (pChangedCategoryList->GetCount() > 0)
2460 if (__pIAddressbookEventListener != null)
2462 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
2466 RecordEventType recordEventType = RECORD_ADDED;
2467 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
2468 std::unique_ptr<Category> pCategory(null);
2470 while (pEnum->MoveNext() == E_SUCCESS)
2472 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
2474 recordEventType = RECORD_UPDATED;
2475 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2476 if (pCategory == null)
2478 if (GetLastResult() == E_OBJ_NOT_FOUND)
2488 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2495 _AddressbookImpl::GetInstance(Addressbook& addressbook)
2497 return addressbook.__pAddressbookImpl;
2500 const _AddressbookImpl*
2501 _AddressbookImpl::GetInstance(const Addressbook& addressbook)
2503 return addressbook.__pAddressbookImpl;