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 result r = _AddressbookUtil::AddContactToCategory(categoryId, contactId);
655 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
661 _AddressbookImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
663 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);
664 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);
665 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
667 int addressbookId = 0;
668 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
669 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
670 contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.address_book_id, &addressbookId);
672 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));
674 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
675 SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
676 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.address_book_id, &addressbookId);
678 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));
680 result r = _AddressbookUtil::RemoveContactFromCategory(categoryId, contactId);
681 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
687 _AddressbookImpl::GetAllCategoriesN(void) const
689 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
693 __Filter<__ContactsGroup> filter;
695 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
697 __Query<__ContactsGroup> query;
699 query.SetFilter(filter);
700 query.SetSort(_contacts_group.name, true);
703 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
704 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
710 _AddressbookImpl::GetCategoriesByContactN(RecordId contactId) const
712 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
713 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));
717 __Filter<__ContactsGroupRelation> filter;
719 filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
721 __Query<__ContactsGroupRelation> query;
723 query.SetFilter(filter);
724 query.SetSort(_contacts_group_relation.name, true);
726 IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query);
727 SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
733 _AddressbookImpl::GetAllContactsN(void) const
735 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
739 __Filter<__ContactsContact> filter;
741 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
743 __Query<__ContactsContact> query;
745 query.SetFilter(filter);
746 query.SetSort(_contacts_contact.display_name, true);
748 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
749 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
755 _AddressbookImpl::GetContactsByCategoryN(RecordId categoryId) const
757 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));
758 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
762 __Filter<__ContactsContactGroupRel> filter;
764 if (categoryId != INVALID_RECORD_ID)
766 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
770 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
773 __Query<__ContactsContactGroupRel> query;
775 query.SetFilter(filter);
776 query.SetSort(_contacts_contact_grouprel.display_name, true);
778 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
779 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
785 _AddressbookImpl::GetContactsN(int pageNo, int countPerPage) const
787 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);
788 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
790 int offset = (pageNo - 1)*countPerPage;
791 int limit = countPerPage;
795 __Filter<__ContactsContact> filter;
797 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
799 __Query<__ContactsContact> query;
801 query.SetFilter(filter);
802 query.SetSort(_contacts_contact.display_name, true);
804 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, limit);
805 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
811 _AddressbookImpl::GetContactsInN(const Category& category, int pageNo, int countPerPage) const
813 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));
814 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);
815 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
817 int offset = (pageNo - 1)*countPerPage;
818 int limit = countPerPage;
822 __Filter<__ContactsContactGroupRel> filter;
824 filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, category.GetRecordId());
826 __Query<__ContactsContactGroupRel> query;
828 query.SetFilter(filter);
829 query.SetSort(_contacts_contact_grouprel.display_name, true);
831 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query, offset, limit);
832 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
838 _AddressbookImpl::SearchContactsByEmailN(const String& email) const
840 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));
841 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
843 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
845 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));
850 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
851 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
853 __Filter<__ContactsContactEmail> filter;
855 filter.AddInt(_contacts_contact_email.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
856 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
857 filter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
859 unsigned int projectionIds[1];
860 projectionIds[0] = _contacts_contact_email.contact_id;
862 __Query<__ContactsContactEmail> query;
864 query.SetProjection(projectionIds, 1);
865 query.SetFilter(filter);
866 query.SetDistinct(true);
867 query.SetSort(_contacts_contact_email.display_name, true);
869 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
870 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
876 _AddressbookImpl::SearchContactsByNameN(const String& name) const
878 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));
879 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
881 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
883 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));
888 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
889 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
891 __Filter<__ContactsContact> filter;
893 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
894 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
895 filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
897 __Query<__ContactsContact> query;
899 query.SetFilter(filter);
900 query.SetSort(_contacts_contact.display_name, true);
901 query.SetDistinct(true);
903 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
904 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
911 _AddressbookImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
913 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));
914 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
917 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
919 int count = phoneNumber.GetLength();
920 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));
925 std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
926 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
928 __Filter<__ContactsContactNumber> subFilter;
929 subFilter.Construct();
930 subFilter.AddString(_contacts_contact_number.normalized_number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
931 subFilter.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
932 subFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
934 __Filter<__ContactsContactNumber> filter;
936 filter.AddInt(_contacts_contact_number.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
937 filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
938 filter.AddFilter(subFilter);
940 unsigned int projectionIds[1];
941 projectionIds[0] = _contacts_contact_number.contact_id;
943 __Query<__ContactsContactNumber> query;
945 query.SetProjection(projectionIds, 1);
946 query.SetFilter(filter);
947 query.SetDistinct(true);
948 query.SetSort(_contacts_contact_number.display_name, true);
950 IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
951 SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
957 _AddressbookImpl::GetCategoryCount(void) const
959 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
965 __Filter<__ContactsGroup> filter;
967 filter.AddInt(_contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
969 __Query<__ContactsGroup> query;
971 query.SetFilter(filter);
973 count = _AddressbookUtil::GetCountWithQuery(query);
974 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
980 _AddressbookImpl::GetContactCount(void) const
982 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
988 __Filter<__ContactsContact> filter;
990 filter.AddInt(_contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
992 __Query<__ContactsContact> query;
994 query.SetFilter(filter);
996 count = _AddressbookUtil::GetCountWithQuery(query);
997 SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1003 _AddressbookImpl::GetContactN(RecordId contactId) const
1005 SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
1006 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1010 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId));
1011 SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1014 contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue);
1015 SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1017 unique_ptr<Contact> pContact(new (std::nothrow) Contact());
1018 SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1020 _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
1021 _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
1023 return pContact.release();
1027 _AddressbookImpl::GetCategoryN(RecordId categoryId) const
1029 SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
1030 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1034 unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
1035 SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1039 contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
1040 SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
1042 unique_ptr<Category> pCategory(new (std::nothrow) Category());
1043 SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1045 __Filter<__ContactsGroupRelation> filter;
1047 filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
1049 __Query<__ContactsGroupRelation> query;
1051 query.SetFilter(filter);
1053 int count = _AddressbookUtil::GetCountWithQuery(query);
1054 SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1056 _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
1057 _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
1058 _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
1060 return pCategory.release();
1064 _AddressbookImpl::GetLatestVersion(void) const
1066 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1068 int latestVersion = -1;
1072 int ret = contacts_db_get_current_version(&latestVersion);
1073 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, -1, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1074 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1076 return latestVersion;
1080 _AddressbookImpl::GetChangedContactsAfterN(int version, int& latestVersion) const
1082 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);
1083 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1087 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1088 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1090 return pChangedContacts;
1094 _AddressbookImpl::GetChangedCategoriesAfterN(int version, int& latestVersion) const
1096 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);
1097 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1101 int latestVersion1 = 0;
1102 int latestVersion2 = 0;
1104 std::unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion1));
1105 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1107 std::unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion2));
1108 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1110 std::unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
1111 SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1113 result r = pChangeList->AddItems(*pChangedGroups);
1114 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1116 r = pChangeList->AddItems(*pChangedRelations);
1117 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1119 pChangedGroups->RemoveAll(false);
1120 pChangedRelations->RemoveAll(false);
1122 latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
1124 return pChangeList.release();
1128 _AddressbookImpl::GetChangedContactInfoListN(int version, int& latestVersion) const
1130 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);
1131 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1135 IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(__addressbookId, version, latestVersion);
1136 SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1138 return pChangedContacts;
1142 _AddressbookImpl::GetChangedCategoryInfoListN(int version, int& latestVersion) const
1144 return GetChangedGroupsAfterN(version, latestVersion);
1148 _AddressbookImpl::GetChangedGroupsAfterN(int version, int& latestVersion) const
1150 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);
1151 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1155 IList* pChangedGroups = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1156 SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1158 return pChangedGroups;
1162 _AddressbookImpl::GetChangedRelationsAfterN(int version, int& latestVersion) const
1164 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);
1165 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1169 IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(__addressbookId, version, latestVersion);
1170 SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1172 return pChangedRelations;
1176 _AddressbookImpl::AddContacts(const Tizen::Base::Collection::IList& contactList, Tizen::Base::Collection::IListT<RecordId>* pContactIdList)
1178 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1179 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1181 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1182 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1184 Contact* pContact = null;
1185 int ret = CONTACTS_ERROR_NONE;
1186 int* pContactIds = null;
1187 unsigned int contactsCount = 0;
1189 contacts_record_h recordHandle = null;
1190 contacts_list_h listHandle = null;
1192 ret = contacts_list_create(&listHandle);
1193 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1195 while (pContactEnum->MoveNext() == E_SUCCESS)
1197 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1199 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1201 contacts_list_destroy(listHandle, false);
1202 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1203 return E_INVALID_ARG;
1205 if (pContact->GetRecordId() != INVALID_RECORD_ID)
1207 contacts_list_destroy(listHandle, false);
1208 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1209 return E_INVALID_ARG;
1212 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1213 contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, __addressbookId);
1214 contacts_list_add(listHandle, recordHandle);
1217 ret = contacts_db_insert_records(listHandle, &pContactIds, &contactsCount);
1218 contacts_list_destroy(listHandle, false);
1219 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));
1220 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
1221 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1222 SysTryReturn(NID_SCL, pContactIds, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1224 int* pTemp = pContactIds;
1226 if (pContactIdList != null)
1228 for (unsigned int i = 0; i < contactsCount; i++)
1230 pContactIdList->Add(*pTemp);
1241 _AddressbookImpl::UpdateContacts(const Tizen::Base::Collection::IList& contactList)
1243 SysTryReturn(NID_SCL, contactList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactList is empty.", GetErrorMessage(E_INVALID_ARG));
1244 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1246 std::unique_ptr<IEnumerator> pContactEnum(contactList.GetEnumeratorN());
1247 SysTryReturnResult(NID_SCL, pContactEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1249 Contact* pContact = null;
1250 int ret = CONTACTS_ERROR_NONE;
1251 contacts_record_h recordHandle = null;
1252 contacts_list_h listHandle = null;
1254 ret = contacts_list_create(&listHandle);
1255 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1257 while (pContactEnum->MoveNext() == E_SUCCESS)
1259 pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
1261 if (_ContactImpl::GetInstance(*pContact)->IsEmpty())
1263 contacts_list_destroy(listHandle, false);
1264 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact is empty.", GetErrorMessage(E_INVALID_ARG));
1265 return E_INVALID_ARG;
1267 if (pContact->GetRecordId() == INVALID_RECORD_ID)
1269 contacts_list_destroy(listHandle, false);
1270 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. Contact ID is invalid.", GetErrorMessage(E_INVALID_ARG));
1271 return E_INVALID_ARG;
1274 recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
1275 contacts_list_add(listHandle, recordHandle);
1278 result r = _AddressbookUtil::UpdateContactRecords(listHandle);
1279 contacts_list_destroy(listHandle, false);
1280 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1286 _AddressbookImpl::RemoveContacts(const Tizen::Base::Collection::IListT<RecordId>& contactIdList)
1288 SysTryReturn(NID_SCL, contactIdList.GetCount() != 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactIdList is empty.", GetErrorMessage(E_INVALID_ARG));
1289 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1291 std::unique_ptr<IEnumeratorT<RecordId> > pContactIdEnum(contactIdList.GetEnumeratorN());
1292 SysTryReturnResult(NID_SCL, pContactIdEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1294 RecordId contactId = INVALID_RECORD_ID;
1295 int ret = CONTACTS_ERROR_NONE;
1296 int count = contactIdList.GetCount();
1297 std::unique_ptr<int[]> pRecordIds(new (std::nothrow) int[count]);
1298 int* pInt = pRecordIds.get();
1301 while (pContactIdEnum->MoveNext() == E_SUCCESS)
1303 pContactIdEnum->GetCurrent(contactId);
1304 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));
1310 ret = contacts_db_delete_records(_contacts_contact._uri, pInt, count);
1311 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));
1312 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));
1318 _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
1320 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1323 int existingRecordId = 0;
1324 int ret = CONTACTS_ERROR_NONE;
1325 result r = E_SUCCESS;
1326 contacts_record_h recordHandle = null;
1328 std::unique_ptr<UserProfile> pExistingProfile(GetUserProfileN());
1329 SysTryReturn(NID_SCL, pExistingProfile != null || GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1331 if (pExistingProfile != null)
1333 recordHandle = _UserProfileImpl::GetInstance(*pExistingProfile)->GetUserProfileHandle();
1334 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &existingRecordId);
1337 if (pUserProfile != null)
1339 SysTryReturn(NID_SCL, !((_UserProfileImpl::GetInstance(*pUserProfile))->IsEmpty()), E_SYSTEM, E_SYSTEM, "[%s] UserProfile is Empty.", GetErrorMessage(E_SYSTEM));
1341 recordHandle = _UserProfileImpl::GetInstance(*pUserProfile)->GetUserProfileHandle();
1342 contacts_record_get_int(recordHandle, _contacts_my_profile.id, &recordId);
1345 if (pExistingProfile != null)
1347 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1348 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1351 contacts_record_h newRecordHandle = null;
1352 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1353 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1355 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(newRecordHandle);
1356 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1358 ret = contacts_record_set_int(pContactRecord.get(), _contacts_my_profile.address_book_id, __addressbookId);
1359 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1362 result r = _AddressbookUtil::InsertContactRecordN(pContactRecord.get(), recordId);
1363 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1365 else if (recordId > 0)
1367 if (recordId == existingRecordId)
1369 contacts_record_h newRecordHandle = null;
1370 ret = contacts_record_clone(recordHandle, &newRecordHandle);
1371 SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1373 result r = _AddressbookUtil::UpdateContactRecord(newRecordHandle);
1374 contacts_record_destroy(newRecordHandle, true);
1375 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1379 if (pExistingProfile != null)
1381 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1382 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1385 unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(CopyMyProfileRecordHandle(recordHandle));
1386 SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1388 ret = contacts_record_set_int(pContactRecord.get(), _contacts_my_profile.address_book_id, __addressbookId);
1389 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
1393 r = _AddressbookUtil::InsertContactRecordN(pContactRecord.get(), recordId);
1394 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1400 if (pExistingProfile != null)
1402 r = _AddressbookUtil::DeleteContactRecord(_contacts_my_profile._uri, existingRecordId);
1403 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
1411 _AddressbookImpl::GetUserProfileN(void) const
1413 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1417 __Filter<__ContactsUserProfile> filter;
1419 filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, __addressbookId);
1421 __Query<__ContactsUserProfile> query;
1423 query.SetFilter(filter);
1425 std::unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
1426 SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1427 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
1428 SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
1430 UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
1431 SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
1437 _AddressbookImpl::IsUserProfileChangedAfter(int version) const
1439 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);
1440 SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1442 UserProfile* pExistingProfile = GetUserProfileN();
1443 if (pExistingProfile == null)
1448 delete pExistingProfile;
1452 int latestVersion = 0;
1453 int count = _AddressbookUtil::GetChangedItemCountByVersion<__ContactsMyProfileUpdatedInfo>(__addressbookId, version, latestVersion);
1454 SysTryReturn(NID_SCL, count >= 0, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1465 _AddressbookImpl::CopyMyProfileRecordHandle(contacts_record_h srcHandle)
1469 int ret = CONTACTS_ERROR_NONE;
1471 unsigned int count = 0;
1473 char* pCharValue = null;
1475 contacts_record_h contactHandle = null;
1476 contacts_record_h srcRecordHandle = null;
1477 contacts_record_h dstRecordHandle = null;
1479 ret = contacts_record_create(_contacts_my_profile._uri, &contactHandle);
1480 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1483 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.name, &count);
1486 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.name, 0, &srcRecordHandle);
1488 ret = contacts_record_create(_contacts_name._uri, &dstRecordHandle);
1489 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1491 __ContactsRecordHandle nameHandle(dstRecordHandle);
1493 contacts_record_get_str_p(srcRecordHandle, _contacts_name.first, &pCharValue);
1494 contacts_record_set_str(dstRecordHandle, _contacts_name.first, pCharValue);
1496 contacts_record_get_str_p(srcRecordHandle, _contacts_name.last, &pCharValue);
1497 contacts_record_set_str(dstRecordHandle, _contacts_name.last, pCharValue);
1499 contacts_record_get_str_p(srcRecordHandle, _contacts_name.addition, &pCharValue);
1500 contacts_record_set_str(dstRecordHandle, _contacts_name.addition, pCharValue);
1502 contacts_record_get_str_p(srcRecordHandle, _contacts_name.suffix, &pCharValue);
1503 contacts_record_set_str(dstRecordHandle, _contacts_name.suffix, pCharValue);
1505 contacts_record_get_str_p(srcRecordHandle, _contacts_name.prefix, &pCharValue);
1506 contacts_record_set_str(dstRecordHandle, _contacts_name.prefix, pCharValue);
1508 contacts_record_get_str_p(srcRecordHandle, _contacts_name.phonetic_first, &pCharValue);
1509 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_first, pCharValue);
1511 contacts_record_get_str_p(srcRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
1512 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_middle, pCharValue);
1514 contacts_record_get_str_p(srcRecordHandle, _contacts_name.phonetic_last, &pCharValue);
1515 contacts_record_set_str(dstRecordHandle, _contacts_name.phonetic_last, pCharValue);
1517 contacts_record_add_child_record(contactHandle, _contacts_my_profile.name, dstRecordHandle);
1519 nameHandle.Release();
1523 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.company, &count);
1524 for (i = 0; i < count; i++)
1526 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.company, i, &srcRecordHandle);
1528 ret = contacts_record_create(_contacts_company._uri, &dstRecordHandle);
1529 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1531 __ContactsRecordHandle companyHandle(dstRecordHandle);
1533 contacts_record_get_int(srcRecordHandle, _contacts_company.type, &intValue);
1534 contacts_record_set_int(dstRecordHandle, _contacts_company.type, intValue);
1536 contacts_record_get_str_p(srcRecordHandle, _contacts_company.name, &pCharValue);
1537 contacts_record_set_str(dstRecordHandle, _contacts_company.name, pCharValue);
1539 contacts_record_get_str_p(srcRecordHandle, _contacts_company.department, &pCharValue);
1540 contacts_record_set_str(dstRecordHandle, _contacts_company.department, pCharValue);
1542 contacts_record_get_str_p(srcRecordHandle, _contacts_company.job_title, &pCharValue);
1543 contacts_record_set_str(dstRecordHandle, _contacts_company.job_title, pCharValue);
1545 contacts_record_get_str_p(srcRecordHandle, _contacts_company.assistant_name, &pCharValue);
1546 contacts_record_set_str(dstRecordHandle, _contacts_company.assistant_name, pCharValue);
1548 contacts_record_get_str_p(srcRecordHandle, _contacts_company.role, &pCharValue);
1549 contacts_record_set_str(dstRecordHandle, _contacts_company.role, pCharValue);
1551 contacts_record_get_str_p(srcRecordHandle, _contacts_company.logo, &pCharValue);
1552 contacts_record_set_str(dstRecordHandle, _contacts_company.logo, pCharValue);
1554 contacts_record_get_str_p(srcRecordHandle, _contacts_company.location, &pCharValue);
1555 contacts_record_set_str(dstRecordHandle, _contacts_company.location, pCharValue);
1557 contacts_record_get_str_p(srcRecordHandle, _contacts_company.description, &pCharValue);
1558 contacts_record_set_str(dstRecordHandle, _contacts_company.description, pCharValue);
1560 contacts_record_get_str_p(srcRecordHandle, _contacts_company.phonetic_name, &pCharValue);
1561 contacts_record_set_str(dstRecordHandle, _contacts_company.phonetic_name, pCharValue);
1563 contacts_record_add_child_record(contactHandle, _contacts_my_profile.company, dstRecordHandle);
1565 companyHandle.Release();
1569 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.note, &count);
1570 for (i = 0; i < count; i++)
1572 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.note, i, &srcRecordHandle);
1574 ret = contacts_record_create(_contacts_note._uri, &dstRecordHandle);
1575 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1577 __ContactsRecordHandle noteHandle(dstRecordHandle);
1579 contacts_record_get_str_p(srcRecordHandle, _contacts_note.note, &pCharValue);
1580 contacts_record_set_str(dstRecordHandle, _contacts_note.note, pCharValue);
1582 contacts_record_add_child_record(contactHandle, _contacts_my_profile.note, dstRecordHandle);
1584 noteHandle.Release();
1588 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.number, &count);
1589 for (i = 0; i < count; i++)
1591 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.number, i, &srcRecordHandle);
1593 ret = contacts_record_create(_contacts_number._uri, &dstRecordHandle);
1594 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1596 __ContactsRecordHandle numberHandle(dstRecordHandle);
1598 contacts_record_get_int(srcRecordHandle, _contacts_number.type, &intValue);
1599 contacts_record_set_int(dstRecordHandle, _contacts_number.type, intValue);
1601 contacts_record_get_str_p(srcRecordHandle, _contacts_number.label, &pCharValue);
1602 contacts_record_set_str(dstRecordHandle, _contacts_number.label, pCharValue);
1604 contacts_record_get_str_p(srcRecordHandle, _contacts_number.number, &pCharValue);
1605 contacts_record_set_str(dstRecordHandle, _contacts_number.number, pCharValue);
1607 contacts_record_add_child_record(contactHandle, _contacts_my_profile.number, dstRecordHandle);
1609 numberHandle.Release();
1613 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.email, &count);
1614 for (i = 0; i < count; i++)
1616 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.email, i, &srcRecordHandle);
1618 ret = contacts_record_create(_contacts_email._uri, &dstRecordHandle);
1619 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1621 __ContactsRecordHandle emailHandle(dstRecordHandle);
1623 contacts_record_get_int(srcRecordHandle, _contacts_email.type, &intValue);
1624 contacts_record_set_int(dstRecordHandle, _contacts_email.type, intValue);
1626 contacts_record_get_str_p(srcRecordHandle, _contacts_email.label, &pCharValue);
1627 contacts_record_set_str(dstRecordHandle, _contacts_email.label, pCharValue);
1629 contacts_record_get_str_p(srcRecordHandle, _contacts_email.email, &pCharValue);
1630 contacts_record_set_str(dstRecordHandle, _contacts_email.email, pCharValue);
1632 contacts_record_add_child_record(contactHandle, _contacts_my_profile.email, dstRecordHandle);
1634 emailHandle.Release();
1639 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.event, &count);
1640 for (i = 0; i < count; i++)
1642 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.event, i, &srcRecordHandle);
1644 ret = contacts_record_create(_contacts_event._uri, &dstRecordHandle);
1645 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1647 __ContactsRecordHandle eventHandle(dstRecordHandle);
1649 contacts_record_get_int(srcRecordHandle, _contacts_event.type, &intValue);
1650 contacts_record_set_int(dstRecordHandle, _contacts_event.type, intValue);
1652 contacts_record_get_str_p(srcRecordHandle, _contacts_event.label, &pCharValue);
1653 contacts_record_set_str(dstRecordHandle, _contacts_event.label, pCharValue);
1655 contacts_record_get_int(srcRecordHandle, _contacts_event.date, &intValue);
1656 contacts_record_set_int(dstRecordHandle, _contacts_event.date, intValue);
1658 contacts_record_add_child_record(contactHandle, _contacts_my_profile.event, dstRecordHandle);
1660 eventHandle.Release();
1664 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.messenger, &count);
1665 for (i = 0; i < count; i++)
1667 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.messenger, i, &srcRecordHandle);
1669 ret = contacts_record_create(_contacts_messenger._uri, &dstRecordHandle);
1670 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1672 __ContactsRecordHandle imAddressHandle(dstRecordHandle);
1674 contacts_record_get_int(srcRecordHandle, _contacts_messenger.type, &intValue);
1675 contacts_record_set_int(dstRecordHandle, _contacts_messenger.type, intValue);
1677 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.label, &pCharValue);
1678 contacts_record_set_str(dstRecordHandle, _contacts_messenger.label, pCharValue);
1680 contacts_record_get_str_p(srcRecordHandle, _contacts_messenger.im_id, &pCharValue);
1681 contacts_record_set_str(dstRecordHandle, _contacts_messenger.im_id, pCharValue);
1683 contacts_record_add_child_record(contactHandle, _contacts_my_profile.messenger, dstRecordHandle);
1685 imAddressHandle.Release();
1689 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.address, &count);
1690 for (i = 0; i < count; i++)
1692 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.address, i, &srcRecordHandle);
1694 ret = contacts_record_create(_contacts_address._uri, &dstRecordHandle);
1695 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1697 __ContactsRecordHandle addressHandle(dstRecordHandle);
1699 contacts_record_get_int(srcRecordHandle, _contacts_address.type, &intValue);
1700 contacts_record_set_int(dstRecordHandle, _contacts_address.type, intValue);
1702 contacts_record_get_str_p(srcRecordHandle, _contacts_address.label, &pCharValue);
1703 contacts_record_set_str(dstRecordHandle, _contacts_address.label, pCharValue);
1705 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postbox, &pCharValue);
1706 contacts_record_set_str(dstRecordHandle, _contacts_address.postbox, pCharValue);
1708 contacts_record_get_str_p(srcRecordHandle, _contacts_address.extended, &pCharValue);
1709 contacts_record_set_str(dstRecordHandle, _contacts_address.extended, pCharValue);
1711 contacts_record_get_str_p(srcRecordHandle, _contacts_address.street, &pCharValue);
1712 contacts_record_set_str(dstRecordHandle, _contacts_address.street, pCharValue);
1714 contacts_record_get_str_p(srcRecordHandle, _contacts_address.locality, &pCharValue);
1715 contacts_record_set_str(dstRecordHandle, _contacts_address.locality, pCharValue);
1717 contacts_record_get_str_p(srcRecordHandle, _contacts_address.region, &pCharValue);
1718 contacts_record_set_str(dstRecordHandle, _contacts_address.region, pCharValue);
1720 contacts_record_get_str_p(srcRecordHandle, _contacts_address.postal_code, &pCharValue);
1721 contacts_record_set_str(dstRecordHandle, _contacts_address.postal_code, pCharValue);
1723 contacts_record_get_str_p(srcRecordHandle, _contacts_address.country, &pCharValue);
1724 contacts_record_set_str(dstRecordHandle, _contacts_address.country, pCharValue);
1726 contacts_record_add_child_record(contactHandle, _contacts_my_profile.address, dstRecordHandle);
1728 addressHandle.Release();
1732 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.url, &count);
1733 for (i = 0; i < count; i++)
1735 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.url, i, &srcRecordHandle);
1737 ret = contacts_record_create(_contacts_url._uri, &dstRecordHandle);
1738 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1740 __ContactsRecordHandle urlHandle(dstRecordHandle);
1742 contacts_record_get_int(srcRecordHandle, _contacts_url.type, &intValue);
1743 contacts_record_set_int(dstRecordHandle, _contacts_url.type, intValue);
1745 contacts_record_get_str_p(srcRecordHandle, _contacts_url.label, &pCharValue);
1746 contacts_record_set_str(dstRecordHandle, _contacts_url.label, pCharValue);
1748 contacts_record_get_str_p(srcRecordHandle, _contacts_url.url, &pCharValue);
1749 contacts_record_set_str(dstRecordHandle, _contacts_url.url, pCharValue);
1751 contacts_record_add_child_record(contactHandle, _contacts_my_profile.url, dstRecordHandle);
1753 urlHandle.Release();
1757 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.nickname, &count);
1758 for (i = 0; i < count; i++)
1760 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.nickname, i, &srcRecordHandle);
1762 ret = contacts_record_create(_contacts_nickname._uri, &dstRecordHandle);
1763 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1765 __ContactsRecordHandle nicknameHandle(dstRecordHandle);
1767 contacts_record_get_str_p(srcRecordHandle, _contacts_nickname.name, &pCharValue);
1768 contacts_record_set_str(dstRecordHandle, _contacts_nickname.name, pCharValue);
1770 contacts_record_add_child_record(contactHandle, _contacts_my_profile.nickname, dstRecordHandle);
1772 nicknameHandle.Release();
1776 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.relationship, &count);
1777 for (i = 0; i < count; i++)
1779 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.relationship, i, &srcRecordHandle);
1781 ret = contacts_record_create(_contacts_relationship._uri, &dstRecordHandle);
1782 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1784 __ContactsRecordHandle relationshipHandle(dstRecordHandle);
1786 contacts_record_get_str_p(srcRecordHandle, _contacts_relationship.name, &pCharValue);
1787 contacts_record_set_str(dstRecordHandle, _contacts_relationship.name, pCharValue);
1789 contacts_record_add_child_record(contactHandle, _contacts_my_profile.relationship, dstRecordHandle);
1791 relationshipHandle.Release();
1795 contacts_record_get_child_record_count(srcHandle, _contacts_my_profile.image, &count);
1798 contacts_record_get_int(srcHandle, _contacts_my_profile.id, &recordId);
1800 if (count > 0 && recordId == 0)
1802 contacts_record_get_child_record_at_p(srcHandle, _contacts_my_profile.image, 0, &srcRecordHandle);
1804 ret = contacts_record_create(_contacts_image._uri, &dstRecordHandle);
1805 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1807 __ContactsRecordHandle imageHandle(dstRecordHandle);
1809 contacts_record_get_int(srcRecordHandle, _contacts_image.type, &intValue);
1810 contacts_record_set_int(dstRecordHandle, _contacts_image.type, intValue);
1812 contacts_record_get_str_p(srcRecordHandle, _contacts_image.label, &pCharValue);
1813 contacts_record_set_str(dstRecordHandle, _contacts_image.label, pCharValue);
1815 contacts_record_get_str_p(srcRecordHandle, _contacts_image.path, &pCharValue);
1816 contacts_record_set_str(dstRecordHandle, _contacts_image.path, pCharValue);
1818 contacts_record_add_child_record(contactHandle, _contacts_contact.image, dstRecordHandle);
1820 imageHandle.Release();
1823 return contactHandle;
1827 _AddressbookImpl::CopyContactRecordHandle(contacts_record_h srcHandle)
1831 int ret = CONTACTS_ERROR_NONE;
1833 unsigned int count = 0;
1834 char* pCharValue = null;
1836 bool boolValue = false;
1838 contacts_record_h contactHandle = null;
1839 contacts_record_h sourceRecordHandle = null;
1840 contacts_record_h destRecordHandle = null;
1842 ret = contacts_record_create(_contacts_contact._uri, &contactHandle);
1843 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1846 contacts_record_get_bool(srcHandle, _contacts_contact.is_favorite, &boolValue);
1847 contacts_record_set_bool(contactHandle, _contacts_contact.is_favorite, boolValue);
1850 contacts_record_get_str_p(srcHandle, _contacts_contact.uid, &pCharValue);
1851 contacts_record_set_str(contactHandle, _contacts_contact.uid, pCharValue);
1853 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1855 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1856 contacts_record_get_child_record_count(srcHandle, _contacts_contact.name, &count);
1859 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.name, 0, &sourceRecordHandle);
1861 ret = contacts_record_create(_contacts_name._uri, &destRecordHandle);
1862 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1864 __ContactsRecordHandle nameHandle(destRecordHandle);
1867 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.first, &pCharValue);
1868 contacts_record_set_str(destRecordHandle, _contacts_name.first, pCharValue);
1871 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.last, &pCharValue);
1872 contacts_record_set_str(destRecordHandle, _contacts_name.last, pCharValue);
1875 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.addition, &pCharValue);
1876 contacts_record_set_str(destRecordHandle, _contacts_name.addition, pCharValue);
1879 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.suffix, &pCharValue);
1880 contacts_record_set_str(destRecordHandle, _contacts_name.suffix, pCharValue);
1883 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.prefix, &pCharValue);
1884 contacts_record_set_str(destRecordHandle, _contacts_name.prefix, pCharValue);
1886 // 6. phonetic_first
1887 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_first, &pCharValue);
1888 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_first, pCharValue);
1891 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_last, &pCharValue);
1892 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_last, pCharValue);
1894 // 8. phonetic_middle
1895 contacts_record_get_str_p(sourceRecordHandle, _contacts_name.phonetic_middle, &pCharValue);
1896 contacts_record_set_str(destRecordHandle, _contacts_name.phonetic_middle, pCharValue);
1898 contacts_record_add_child_record(contactHandle, _contacts_contact.name, destRecordHandle);
1900 nameHandle.Release();
1903 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1905 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1906 contacts_record_get_child_record_count(srcHandle, _contacts_contact.image, &count);
1907 for (i = 0; i < count; i++)
1909 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.image, i, &sourceRecordHandle);
1911 ret = contacts_record_create(_contacts_image._uri, &destRecordHandle);
1912 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1914 __ContactsRecordHandle imageHandle(destRecordHandle);
1916 contacts_record_get_int(sourceRecordHandle, _contacts_image.type, &intValue);
1917 contacts_record_set_int(destRecordHandle, _contacts_image.type, intValue);
1919 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.label, &pCharValue);
1920 contacts_record_set_str(destRecordHandle, _contacts_image.label, pCharValue);
1922 contacts_record_get_str_p(sourceRecordHandle, _contacts_image.path, &pCharValue);
1923 contacts_record_set_str(destRecordHandle, _contacts_image.path, pCharValue);
1925 contacts_record_add_child_record(contactHandle, _contacts_contact.image, destRecordHandle);
1927 imageHandle.Release();
1930 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1932 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1933 contacts_record_get_child_record_count(srcHandle, _contacts_contact.company, &count);
1934 for (i = 0; i < count; i++)
1936 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.company, i, &sourceRecordHandle);
1938 ret = contacts_record_create(_contacts_company._uri, &destRecordHandle);
1939 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1941 __ContactsRecordHandle companyHandle(destRecordHandle);
1943 contacts_record_get_int(sourceRecordHandle, _contacts_company.type, &intValue);
1944 contacts_record_set_int(destRecordHandle, _contacts_company.type, intValue);
1946 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.name, &pCharValue);
1947 contacts_record_set_str(destRecordHandle, _contacts_company.name, pCharValue);
1949 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.department, &pCharValue);
1950 contacts_record_set_str(destRecordHandle, _contacts_company.department, pCharValue);
1952 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.job_title, &pCharValue);
1953 contacts_record_set_str(destRecordHandle, _contacts_company.job_title, pCharValue);
1955 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.assistant_name, &pCharValue);
1956 contacts_record_set_str(destRecordHandle, _contacts_company.assistant_name, pCharValue);
1958 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.role, &pCharValue);
1959 contacts_record_set_str(destRecordHandle, _contacts_company.role, pCharValue);
1961 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.logo, &pCharValue);
1962 contacts_record_set_str(destRecordHandle, _contacts_company.logo, pCharValue);
1964 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.location, &pCharValue);
1965 contacts_record_set_str(destRecordHandle, _contacts_company.location, pCharValue);
1967 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.description, &pCharValue);
1968 contacts_record_set_str(destRecordHandle, _contacts_company.description, pCharValue);
1970 contacts_record_get_str_p(sourceRecordHandle, _contacts_company.phonetic_name, &pCharValue);
1971 contacts_record_set_str(destRecordHandle, _contacts_company.phonetic_name, pCharValue);
1973 contacts_record_add_child_record(contactHandle, _contacts_contact.company, destRecordHandle);
1975 companyHandle.Release();
1978 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1980 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
1981 contacts_record_get_child_record_count(srcHandle, _contacts_contact.note, &count);
1982 for (i = 0; i < count; i++)
1984 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.note, i, &sourceRecordHandle);
1986 ret = contacts_record_create(_contacts_note._uri, &destRecordHandle);
1987 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1989 __ContactsRecordHandle noteHandle(destRecordHandle);
1991 contacts_record_get_str_p(sourceRecordHandle, _contacts_note.note, &pCharValue);
1992 contacts_record_set_str(destRecordHandle, _contacts_note.note, pCharValue);
1994 contacts_record_add_child_record(contactHandle, _contacts_contact.note, destRecordHandle);
1996 noteHandle.Release();
1999 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2002 contacts_record_get_child_record_count(srcHandle, _contacts_contact.number, &count);
2003 for (i = 0; i < count; i++)
2005 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.number, i, &sourceRecordHandle);
2007 ret = contacts_record_create(_contacts_number._uri, &destRecordHandle);
2008 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2010 __ContactsRecordHandle numberHandle(destRecordHandle);
2012 contacts_record_get_int(sourceRecordHandle, _contacts_number.type, &intValue);
2013 contacts_record_set_int(destRecordHandle, _contacts_number.type, intValue);
2015 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.label, &pCharValue);
2016 contacts_record_set_str(destRecordHandle, _contacts_number.label, pCharValue);
2018 contacts_record_get_str_p(sourceRecordHandle, _contacts_number.number, &pCharValue);
2019 contacts_record_set_str(destRecordHandle, _contacts_number.number, pCharValue);
2021 contacts_record_add_child_record(contactHandle, _contacts_contact.number, destRecordHandle);
2023 numberHandle.Release();
2026 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2028 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2029 contacts_record_get_child_record_count(srcHandle, _contacts_contact.email, &count);
2030 for (i = 0; i < count; i++)
2032 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.email, i, &sourceRecordHandle);
2034 ret = contacts_record_create(_contacts_email._uri, &destRecordHandle);
2035 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2037 __ContactsRecordHandle emailHandle(destRecordHandle);
2039 contacts_record_get_int(sourceRecordHandle, _contacts_email.type, &intValue);
2040 contacts_record_set_int(destRecordHandle, _contacts_email.type, intValue);
2042 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.label, &pCharValue);
2043 contacts_record_set_str(destRecordHandle, _contacts_email.label, pCharValue);
2045 contacts_record_get_str_p(sourceRecordHandle, _contacts_email.email, &pCharValue);
2046 contacts_record_set_str(destRecordHandle, _contacts_email.email, pCharValue);
2048 contacts_record_add_child_record(contactHandle, _contacts_contact.email, destRecordHandle);
2050 emailHandle.Release();
2054 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2056 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2057 contacts_record_get_child_record_count(srcHandle, _contacts_contact.event, &count);
2058 for (i = 0; i < count; i++)
2060 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.event, i, &sourceRecordHandle);
2062 ret = contacts_record_create(_contacts_event._uri, &destRecordHandle);
2063 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2065 __ContactsRecordHandle eventHandle(destRecordHandle);
2067 contacts_record_get_int(sourceRecordHandle, _contacts_event.type, &intValue);
2068 contacts_record_set_int(destRecordHandle, _contacts_event.type, intValue);
2070 contacts_record_get_str_p(sourceRecordHandle, _contacts_event.label, &pCharValue);
2071 contacts_record_set_str(destRecordHandle, _contacts_event.label, pCharValue);
2073 contacts_record_get_int(sourceRecordHandle, _contacts_event.date, &intValue);
2074 contacts_record_set_int(destRecordHandle, _contacts_event.date, intValue);
2076 contacts_record_add_child_record(contactHandle, _contacts_contact.event, destRecordHandle);
2078 eventHandle.Release();
2081 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2083 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2084 contacts_record_get_child_record_count(srcHandle, _contacts_contact.messenger, &count);
2085 for (i = 0; i < count; i++)
2087 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.messenger, i, &sourceRecordHandle);
2089 ret = contacts_record_create(_contacts_messenger._uri, &destRecordHandle);
2090 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2092 __ContactsRecordHandle imAddressHandle(destRecordHandle);
2094 contacts_record_get_int(sourceRecordHandle, _contacts_messenger.type, &intValue);
2095 contacts_record_set_int(destRecordHandle, _contacts_messenger.type, intValue);
2097 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.label, &pCharValue);
2098 contacts_record_set_str(destRecordHandle, _contacts_messenger.label, pCharValue);
2100 contacts_record_get_str_p(sourceRecordHandle, _contacts_messenger.im_id, &pCharValue);
2101 contacts_record_set_str(destRecordHandle, _contacts_messenger.im_id, pCharValue);
2103 contacts_record_add_child_record(contactHandle, _contacts_contact.messenger, destRecordHandle);
2105 imAddressHandle.Release();
2108 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2110 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2111 contacts_record_get_child_record_count(srcHandle, _contacts_contact.address, &count);
2112 for (i = 0; i < count; i++)
2114 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.address, i, &sourceRecordHandle);
2116 ret = contacts_record_create(_contacts_address._uri, &destRecordHandle);
2117 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2119 __ContactsRecordHandle addressHandle(destRecordHandle);
2121 contacts_record_get_int(sourceRecordHandle, _contacts_address.type, &intValue);
2122 contacts_record_set_int(destRecordHandle, _contacts_address.type, intValue);
2124 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.label, &pCharValue);
2125 contacts_record_set_str(destRecordHandle, _contacts_address.label, pCharValue);
2127 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postbox, &pCharValue);
2128 contacts_record_set_str(destRecordHandle, _contacts_address.postbox, pCharValue);
2130 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.extended, &pCharValue);
2131 contacts_record_set_str(destRecordHandle, _contacts_address.extended, pCharValue);
2133 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.street, &pCharValue);
2134 contacts_record_set_str(destRecordHandle, _contacts_address.street, pCharValue);
2136 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.locality, &pCharValue);
2137 contacts_record_set_str(destRecordHandle, _contacts_address.locality, pCharValue);
2139 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.region, &pCharValue);
2140 contacts_record_set_str(destRecordHandle, _contacts_address.region, pCharValue);
2142 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.postal_code, &pCharValue);
2143 contacts_record_set_str(destRecordHandle, _contacts_address.postal_code, pCharValue);
2145 contacts_record_get_str_p(sourceRecordHandle, _contacts_address.country, &pCharValue);
2146 contacts_record_set_str(destRecordHandle, _contacts_address.country, pCharValue);
2148 contacts_record_add_child_record(contactHandle, _contacts_contact.address, destRecordHandle);
2150 addressHandle.Release();
2153 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2155 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2156 contacts_record_get_child_record_count(srcHandle, _contacts_contact.url, &count);
2157 for (i = 0; i < count; i++)
2159 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.url, i, &sourceRecordHandle);
2161 ret = contacts_record_create(_contacts_url._uri, &destRecordHandle);
2162 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2164 __ContactsRecordHandle urlHandle(destRecordHandle);
2166 contacts_record_get_int(sourceRecordHandle, _contacts_url.type, &intValue);
2167 contacts_record_set_int(destRecordHandle, _contacts_url.type, intValue);
2169 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.label, &pCharValue);
2170 contacts_record_set_str(destRecordHandle, _contacts_url.label, pCharValue);
2172 contacts_record_get_str_p(sourceRecordHandle, _contacts_url.url, &pCharValue);
2173 contacts_record_set_str(destRecordHandle, _contacts_url.url, pCharValue);
2175 contacts_record_add_child_record(contactHandle, _contacts_contact.url, destRecordHandle);
2177 urlHandle.Release();
2180 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2182 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2183 contacts_record_get_child_record_count(srcHandle, _contacts_contact.nickname, &count);
2184 for (i = 0; i < count; i++)
2186 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.nickname, i, &sourceRecordHandle);
2188 ret = contacts_record_create(_contacts_nickname._uri, &destRecordHandle);
2189 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2191 __ContactsRecordHandle nicknameHandle(destRecordHandle);
2193 contacts_record_get_str_p(sourceRecordHandle, _contacts_nickname.name, &pCharValue);
2194 contacts_record_set_str(destRecordHandle, _contacts_nickname.name, pCharValue);
2196 contacts_record_add_child_record(contactHandle, _contacts_contact.nickname, destRecordHandle);
2198 nicknameHandle.Release();
2201 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2203 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2204 contacts_record_get_child_record_count(srcHandle, _contacts_contact.relationship, &count);
2205 for (i = 0; i < count; i++)
2207 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.relationship, i, &sourceRecordHandle);
2209 ret = contacts_record_create(_contacts_relationship._uri, &destRecordHandle);
2210 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2212 __ContactsRecordHandle relationshipHandle(destRecordHandle);
2214 contacts_record_get_str_p(sourceRecordHandle, _contacts_relationship.name, &pCharValue);
2215 contacts_record_set_str(destRecordHandle, _contacts_relationship.name, pCharValue);
2217 contacts_record_add_child_record(contactHandle, _contacts_contact.relationship, destRecordHandle);
2219 relationshipHandle.Release();
2222 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2224 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
2225 contacts_record_get_child_record_count(srcHandle, _contacts_contact.profile, &count);
2226 for (i = 0; i < count; i++)
2228 contacts_record_get_child_record_at_p(srcHandle, _contacts_contact.profile, i, &sourceRecordHandle);
2230 ret = contacts_record_create(_contacts_profile._uri, &destRecordHandle);
2231 SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2233 __ContactsRecordHandle profileHandle(destRecordHandle);
2235 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.text, &pCharValue);
2236 contacts_record_set_str(destRecordHandle, _contacts_profile.text, pCharValue);
2238 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uid, &pCharValue);
2239 contacts_record_set_str(destRecordHandle, _contacts_profile.uid, pCharValue);
2241 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.app_id, &pCharValue);
2242 contacts_record_set_str(destRecordHandle, _contacts_profile.app_id, pCharValue);
2244 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.service_operation, &pCharValue);
2245 contacts_record_set_str(destRecordHandle, _contacts_profile.service_operation, pCharValue);
2247 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.uri, &pCharValue);
2248 contacts_record_set_str(destRecordHandle, _contacts_profile.uri, pCharValue);
2250 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.category, &pCharValue);
2251 contacts_record_set_str(destRecordHandle, _contacts_profile.category, pCharValue);
2253 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.mime, &pCharValue);
2254 contacts_record_set_str(destRecordHandle, _contacts_profile.mime, pCharValue);
2256 contacts_record_get_str_p(sourceRecordHandle, _contacts_profile.extra_data, &pCharValue);
2257 contacts_record_set_str(destRecordHandle, _contacts_profile.extra_data, pCharValue);
2259 contacts_record_add_child_record(contactHandle, _contacts_contact.profile, destRecordHandle);
2261 profileHandle.Release();
2264 return contactHandle;
2268 _AddressbookImpl::OnContactChanged(void)
2270 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
2275 std::unique_ptr<IList, AllElementsDeleter> pChangedContactList(GetChangedContactsAfterN(__dbVersionForContact, __dbVersionForContact));
2276 SysTryReturnVoidResult(NID_SCL, pChangedContactList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2278 if (pChangedContactList->GetCount() > 0)
2280 if (__pIAddressbookEventListener != null)
2282 __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
2284 else if (__pIAddressbookChangeEventListener != null)
2286 __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
2290 RecordEventType recordEventType = RECORD_ADDED;
2291 std::unique_ptr<IEnumerator> pEnum(pChangedContactList->GetEnumeratorN());
2292 std::unique_ptr<Contact> pContact(null);
2294 while (pEnum->MoveNext() == E_SUCCESS)
2296 ContactChangeInfo* pContactChagneInfo = static_cast<ContactChangeInfo*>(pEnum->GetCurrent());
2298 if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
2300 recordEventType = RECORD_ADDED;
2301 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
2302 if (pContact == null)
2304 if (GetLastResult() == E_OBJ_NOT_FOUND)
2314 else if (pContactChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
2316 recordEventType = RECORD_UPDATED;
2317 pContact.reset(GetContactN(pContactChagneInfo->GetContactId()));
2318 if (pContact == null)
2320 if (GetLastResult() == E_OBJ_NOT_FOUND)
2332 recordEventType = RECORD_REMOVED;
2333 pContact.reset(new (std::nothrow) Contact());
2334 if (pContact == null)
2336 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2340 _RecordImpl::GetInstance(*pContact)->SetRecordId(pContactChagneInfo->GetContactId());
2343 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CONTACT, *pContact, null, null);
2351 _AddressbookImpl::OnCategoryChanged(void)
2353 if (__pIRecordEventListener == null && __pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
2358 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedGroupsAfterN(__dbVersionForGroup, __dbVersionForGroup));
2359 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2361 if (pChangedCategoryList->GetCount() > 0)
2363 if (__pIAddressbookEventListener != null)
2365 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
2367 else if (__pIAddressbookChangeEventListener != null)
2369 __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
2373 RecordEventType recordEventType = RECORD_ADDED;
2374 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
2375 std::unique_ptr<Category> pCategory(null);
2377 while (pEnum->MoveNext() == E_SUCCESS)
2379 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
2381 if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_ADDED)
2383 recordEventType = RECORD_ADDED;
2384 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2385 if (pCategory == null)
2387 if (GetLastResult() == E_OBJ_NOT_FOUND)
2397 else if (pCategoryChagneInfo->GetChangeType() == RECORD_CHANGE_TYPE_UPDATED)
2399 recordEventType = RECORD_UPDATED;
2400 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2401 if (pCategory == null)
2403 if (GetLastResult() == E_OBJ_NOT_FOUND)
2415 recordEventType = RECORD_REMOVED;
2416 pCategory.reset(new (std::nothrow) Category());
2417 if (pCategory == null)
2419 SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2423 _RecordImpl::GetInstance(*pCategory)->SetRecordId(pCategoryChagneInfo->GetCategoryId());
2426 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2434 _AddressbookImpl::OnRelationChanged(void)
2436 if (__pIAddressbookEventListener == null && __pIRecordEventListener == null)
2441 std::unique_ptr<IList, AllElementsDeleter> pChangedCategoryList(GetChangedRelationsAfterN(__dbVersionForRelation, __dbVersionForRelation));
2442 SysTryReturnVoidResult(NID_SCL, pChangedCategoryList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2444 if (pChangedCategoryList->GetCount() > 0)
2446 if (__pIAddressbookEventListener != null)
2448 __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
2452 RecordEventType recordEventType = RECORD_ADDED;
2453 std::unique_ptr<IEnumerator> pEnum(pChangedCategoryList->GetEnumeratorN());
2454 std::unique_ptr<Category> pCategory(null);
2456 while (pEnum->MoveNext() == E_SUCCESS)
2458 CategoryChangeInfo* pCategoryChagneInfo = static_cast<CategoryChangeInfo*>(pEnum->GetCurrent());
2460 recordEventType = RECORD_UPDATED;
2461 pCategory.reset(GetCategoryN(pCategoryChagneInfo->GetCategoryId()));
2462 if (pCategory == null)
2464 if (GetLastResult() == E_OBJ_NOT_FOUND)
2474 __pIRecordEventListener->OnRecordChangedN(recordEventType, RECORD_TYPE_CATEGORY, *pCategory, null, null);
2481 _AddressbookImpl::GetInstance(Addressbook& addressbook)
2483 return addressbook.__pAddressbookImpl;
2486 const _AddressbookImpl*
2487 _AddressbookImpl::GetInstance(const Addressbook& addressbook)
2489 return addressbook.__pAddressbookImpl;