2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
18 * @file CtContactListPresentationModel.cpp
19 * @brief This is the implementation file for the ContactListPresentationModel class.
23 #include <FGraphics.h>
26 #include "CtContactListPresentationModel.h"
27 #include "CtContactsApp.h"
28 #include "CtIContactEventListener.h"
29 #include "CtResourceManager.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Media;
36 using namespace Tizen::Social;
37 using namespace Tizen::System;
39 static const int VCARD_STRING_LENGTH = 26;
41 static const wchar_t* VCARD_PATH_FORMAT = L"data/Ct%04d%02d%02d%02d%02d%02d.vcf";
42 static const wchar_t* KEY_SHARP = L"#";
44 ContactListPresentationModel* ContactListPresentationModel::__pInstance = null;
46 ContactListPresentationModel*
47 ContactListPresentationModel::GetInstance(void)
49 if (__pInstance == null)
58 ContactListPresentationModel::CreateInstance(void)
60 __pInstance = new (std::nothrow) ContactListPresentationModel();
61 result r = __pInstance->Construct();
62 TryCatch(r == E_SUCCESS, , "[%s] Construction failed", GetErrorMessage(r));
64 std::atexit(DestroyInstance);
73 ContactListPresentationModel::DestroyInstance(void)
78 ContactListPresentationModel::ContactListPresentationModel(void)
80 , _pContactChangeListenerList(null)
81 , _pGroupIndexList(null)
83 , __pSearchedContactList(null)
84 , __pExcludedContactIdList(null)
86 , __isContactChanged(true)
90 ContactListPresentationModel::~ContactListPresentationModel(void)
92 if (_pContactList != null)
94 _pContactList->RemoveAll(true);
98 if (__pSearchedContactList != null)
100 __pSearchedContactList->RemoveAll(true);
101 delete __pSearchedContactList;
104 if (__pExcludedContactIdList != null)
106 __pExcludedContactIdList->RemoveAll(true);
107 delete __pExcludedContactIdList;
110 if (_pContactChangeListenerList != null)
112 _pContactChangeListenerList->RemoveAll(false);
113 delete _pContactChangeListenerList;
116 delete _pAddressbook;
117 delete _pGroupIndexList;
121 ContactListPresentationModel::Construct(void)
123 if (_pAddressbook != null)
125 AppLogDebug("ContactListPresentationModel is already constructed.");
129 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
131 _pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
132 TryReturn(_pAddressbook != null, E_FAILURE, "No address book")
134 _pAddressbook->SetAddressbookChangeEventListener(this);
136 _pContactChangeListenerList = new (std::nothrow) ArrayList();
137 _pContactChangeListenerList->Construct();
143 ContactListPresentationModel::InitializeContactList(Tizen::Base::Collection::IList* pContactIdList)
145 if (__pExcludedContactIdList != null)
147 delete __pExcludedContactIdList;
149 __pExcludedContactIdList = pContactIdList;
151 return CreateContactList();
155 ContactListPresentationModel::CreateContactList(void)
157 result r = E_SUCCESS;
159 if (_pContactList == null)
161 _pContactList = new (std::nothrow) MultiHashMap();
162 _pContactList->Construct();
166 _pContactList->RemoveAll(true);
169 if (_pGroupIndexList == null)
171 _pGroupIndexList = new (std::nothrow) ArrayList();
172 _pGroupIndexList->Construct();
176 _pGroupIndexList->RemoveAll(false);
179 IList* pContactList = AddressbookManager::GetInstance()->GetAllPersonsN();
180 TryReturn(pContactList != null, E_FAILURE, "[E_FAILURE] Unable to get persons.");
182 if (__pExcludedContactIdList != null)
184 IBidirectionalEnumerator* pIdEnum = __pExcludedContactIdList->GetBidirectionalEnumeratorN();
185 pIdEnum->ResetLast();
186 while (pIdEnum->MovePrevious() == E_SUCCESS)
188 Integer* pPersonId = static_cast<Integer*>(pIdEnum->GetCurrent());
190 for (int index = pContactList->GetCount() - 1; index >= 0; index--)
192 Person* pPerson = static_cast<Person *>(pContactList->GetAt(index));
193 if (pPerson != null && pPersonId != null &&
194 pPerson->GetId() == pPersonId->ToInt())
196 pContactList->RemoveAt(index, true);
205 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
206 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
208 TrimListForAppControl(pContactList);
211 IEnumerator* pEnum = pContactList->GetEnumeratorN();
212 TryReturn(pEnum, E_FAILURE, "No contact");
214 bool isNotUsedSharpKey = true;
216 String* pSharpKey = new (std::nothrow) String(KEY_SHARP);
218 while (pEnum->MoveNext() == E_SUCCESS)
220 Person* pPerson = static_cast<Person*>(pEnum->GetCurrent());
227 String displayName = pPerson->GetDisplayName();
228 String firstCharacter;
230 displayName.SubString(0, 1, firstCharacter);
231 firstCharacter.ToUpper();
233 if (pKey == null || firstCharacter.CompareTo(*pKey) != 0)
235 if (firstCharacter[0] >= L'A' && firstCharacter[0] <= L'Z')
237 if (_pGroupIndexList->Contains(firstCharacter))
241 _pGroupIndexList->IndexOf(firstCharacter, index);
242 pKey = static_cast<String *>(_pGroupIndexList->GetAt(index));
250 pKey = new (std::nothrow) String(firstCharacter);
251 _pGroupIndexList->Add(*pKey);
256 isNotUsedSharpKey = false;
259 if (_pGroupIndexList->Contains(*pKey) == false)
261 _pGroupIndexList->Add(*pKey);
265 _pContactList->Add(*pKey, *pPerson);
268 _pGroupIndexList->Sort(StringComparer());
273 if (isNotUsedSharpKey)
282 ContactListPresentationModel::TrimListForAppControl(Tizen::Base::Collection::IList*& pContactList)
284 TryReturn(pContactList != null, E_INVALID_ARG, "Invalid argument");
286 IList* pSelectedList = null;
287 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
288 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
289 AddressbookFilter mainFilter(AB_FI_TYPE_PERSON);
291 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
293 mainFilter.AppendBool(FI_CONJ_OP_NONE, PERSON_FI_PR_HAS_PHONE, FI_CMP_OP_EQUAL, true);
295 pSelectedList = pAddressbookManager->SearchN(mainFilter);
296 TryReturn(pSelectedList != null, E_FAILURE, "Unable to get the list contained phone number");
298 pContactList->RemoveAll(true);
299 pContactList->AddItems(*pSelectedList);
301 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
303 mainFilter.AppendBool(FI_CONJ_OP_NONE, PERSON_FI_PR_HAS_EMAIL, FI_CMP_OP_EQUAL, true);
305 pSelectedList = pAddressbookManager->SearchN(mainFilter);
306 TryReturn(pSelectedList != null, E_FAILURE, "Unable to get the list contained email");
308 pContactList->RemoveAll(true);
309 pContactList->AddItems(*pSelectedList);
316 ContactListPresentationModel::GetKey(int groupIndex)
318 String* key = static_cast<String *>(_pGroupIndexList->GetAt(groupIndex));
329 ContactListPresentationModel::GetAllKeys(void)
332 IEnumerator* pEnum = _pGroupIndexList->GetEnumeratorN();
339 while (pEnum->MoveNext() == E_SUCCESS)
341 String* pKey = static_cast<String *>(pEnum->GetCurrent());
343 allKeys.Append(*pKey);
352 ContactListPresentationModel::GetKeyCount(void)
354 return _pGroupIndexList->GetCount();
358 ContactListPresentationModel::GetKeyIndex(const Tizen::Base::String& key)
362 _pGroupIndexList->IndexOf(key, index);
367 Tizen::Social::Person*
368 ContactListPresentationModel::GetPersonAt(int groupIndex, int itemIndex)
371 Person* pPerson = null;
372 IEnumerator* pEnum = _pContactList->GetValuesN(GetKey(groupIndex));
379 while (pEnum->MoveNext() == E_SUCCESS)
381 if (itemIndex == count++)
383 pPerson = static_cast<Person *>(pEnum->GetCurrent());
394 ContactListPresentationModel::GetContactItemInfoN(int groupIndex, int itemIndex, Tizen::Base::String& name, Tizen::Graphics::Bitmap*& pThumbnail)
396 Person* pPerson = GetPersonAt(groupIndex, itemIndex);
403 name = pPerson->GetDisplayName();
406 Email email = pPerson->GetPrimaryEmail();
407 name.Append(email.GetEmail());
409 String thumbnailPath = pPerson->GetThumbnailPath();
411 if (thumbnailPath.IsEmpty() == false)
413 ImageBuffer thumbnailImageBuffer;
414 result r = thumbnailImageBuffer.Construct(thumbnailPath);
417 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_NONE);
425 ContactListPresentationModel::GetContactCount(void)
427 return _pContactList->GetCount();
431 ContactListPresentationModel::GetContactCount(int groupIndex)
435 _pContactList->GetCount(GetKey(groupIndex), count);
441 ContactListPresentationModel::RemoveContact(int groupIndex, int itemIndex, bool isUpdated)
443 __isContactChanged = isUpdated;
445 Person* pPerson = GetPersonAt(groupIndex, itemIndex);
452 return AddressbookManager::GetInstance()->RemovePerson(pPerson->GetId());
455 Tizen::Social::RecordId
456 ContactListPresentationModel::GetContactId(int groupIndex, int itemIndex)
458 Person* pPerson = GetPersonAt(groupIndex, itemIndex);
462 return INVALID_RECORD_ID;
465 IList* pContactList = AddressbookManager::GetInstance()->GetContactsByPersonN(pPerson->GetId());
466 if (pContactList == null)
468 return INVALID_RECORD_ID;
471 Contact* pContact = static_cast<Contact *>(pContactList->GetAt(0));
472 if (pContact == null)
474 return INVALID_RECORD_ID;
477 RecordId contactId = pContact->GetRecordId();
479 pContactList->RemoveAll(true);
487 ContactListPresentationModel::GetName(int groupIndex, int itemIndex)
489 Person* pPerson = GetPersonAt(groupIndex, itemIndex);
496 return pPerson->GetDisplayName();
500 ContactListPresentationModel::GetDefaultPhoneNumber(int groupIndex, int itemIndex)
502 Person* pPerson = GetPersonAt(groupIndex, itemIndex);
508 PhoneNumber phoneNumber = pPerson->GetPrimaryPhoneNumber();
510 return phoneNumber.GetPhoneNumber();
514 ContactListPresentationModel::GetDefaultEmail(int groupIndex, int itemIndex)
518 Contact* pContact = _pAddressbook->GetContactN(GetContactId(groupIndex, itemIndex));
519 if (pContact == null)
524 //[TODO] should change to default email or rename this function
525 IList* pEmailList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_EMAILS);
526 if (pEmailList == null)
533 Email* pEmail = static_cast<Email*>(pEmailList->GetAt(0));
536 pEmailList->RemoveAll(true);
543 emailString = pEmail->GetEmail();
545 pEmailList->RemoveAll(true);
552 Tizen::Base::Collection::IList*
553 ContactListPresentationModel::GetAllPhoneNumbersN(int groupIndex, int itemIndex)
555 Contact* pContact = _pAddressbook->GetContactN(GetContactId(groupIndex, itemIndex));
556 if (pContact == null)
560 IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
561 if (pPhoneNumberList == null)
567 ArrayList* pPhoneNumberInfoList = new (std::nothrow) ArrayList();
568 pPhoneNumberInfoList->Construct();
569 PhoneNumber* pPhoneNumber = null;
571 IEnumerator* pEnum = pPhoneNumberList->GetEnumeratorN();
572 while (pEnum->MoveNext() == E_SUCCESS)
574 pPhoneNumber = static_cast<PhoneNumber *>(pEnum->GetCurrent());
575 if (pPhoneNumber != null)
577 String phoneNumbersInfo(L"");
579 switch (pPhoneNumber->GetType())
581 case PHONENUMBER_TYPE_HOME:
582 phoneNumbersInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_HOME"));
584 case PHONENUMBER_TYPE_WORK:
585 phoneNumbersInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_WORK"));
587 case PHONENUMBER_TYPE_MOBILE:
588 phoneNumbersInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_MOBILE"));
590 case PHONENUMBER_TYPE_HOME_FAX:
591 phoneNumbersInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_FAX_HHOME"));
593 case PHONENUMBER_TYPE_WORK_FAX:
594 phoneNumbersInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_FAX_HWORK"));
596 case PHONENUMBER_TYPE_PAGER:
597 phoneNumbersInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_PAGER"));
599 case PHONENUMBER_TYPE_OTHER:
600 phoneNumbersInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_OTHER"));
605 phoneNumbersInfo.Append(CHARACTER_SPACE);
606 phoneNumbersInfo.Append(pPhoneNumber->GetPhoneNumber());
608 pPhoneNumberInfoList->Add(*(new (std::nothrow) String(phoneNumbersInfo)));
614 pPhoneNumberList->RemoveAll(true);
615 delete pPhoneNumberList;
617 return pPhoneNumberInfoList;
620 Tizen::Base::Collection::IList*
621 ContactListPresentationModel::GetAllEmailsN(int groupIndex, int itemIndex)
623 Contact* pContact = _pAddressbook->GetContactN(GetContactId(groupIndex, itemIndex));
624 if (pContact == null)
628 IList* pEmailList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_EMAILS);
629 if (pEmailList == null)
635 ArrayList* pEmailInfoList = new (std::nothrow) ArrayList();
636 pEmailInfoList->Construct();
637 Email* pEmail = null;
639 IEnumerator* pEnum = pEmailList->GetEnumeratorN();
640 while (pEnum->MoveNext() == E_SUCCESS)
642 pEmail = static_cast<Email *>(pEnum->GetCurrent());
645 String EmailsInfo(L"");
647 switch (pEmail->GetType())
649 case EMAIL_TYPE_PERSONAL:
650 EmailsInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_HOME"));
652 case EMAIL_TYPE_WORK:
653 EmailsInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_WORK"));
655 case EMAIL_TYPE_OTHER:
656 EmailsInfo.Append(ResourceManager::GetString(L"IDS_PB_BODY_OTHER"));
661 EmailsInfo.Append(CHARACTER_SPACE);
662 EmailsInfo.Append(pEmail->GetEmail());
664 pEmailInfoList->Add(*(new (std::nothrow) String(EmailsInfo)));
670 pEmailList->RemoveAll(true);
673 return pEmailInfoList;
677 ContactListPresentationModel::SetSearchText(const Tizen::Base::String& searchText, SearchType searchType)
679 result r = E_SUCCESS;
681 if (__pSearchedContactList != null)
683 __pSearchedContactList->RemoveAll(true);
684 delete __pSearchedContactList;
685 __pSearchedContactList = null;
688 __pSearchedContactList = GetSearchedContactListN(searchText, searchType);
690 if (__pSearchedContactList != null)
692 r = searchText.ToLowerCase(__searchedText);
699 ContactListPresentationModel::GetSearchedContactItemInfo(int index, Tizen::Base::String& name, Tizen::Graphics::Bitmap*& pThumbnail)
701 if (__pSearchedContactList == null)
705 Person* pPerson = static_cast<Person *>(__pSearchedContactList->GetAt(index));
711 name = pPerson->GetDisplayName();
712 String thumbnailPath = pPerson->GetThumbnailPath();
714 if (thumbnailPath.IsEmpty() == false)
716 ImageBuffer thumbnailImageBuffer;
717 result r = thumbnailImageBuffer.Construct(pPerson->GetThumbnailPath());
720 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_NONE);
727 Tizen::Base::Collection::IList*
728 ContactListPresentationModel::GetSearchedContactListN(const Tizen::Base::String& searchText, SearchType searchType)
730 if (searchText.GetLength() == 0)
735 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
737 IList* pSearchedList = null;
739 if (searchType != SEARCH_TYPE_HAS_EMAIL_ONLY)
741 IList* pSearchingPhoneNumberList = null;
742 AddressbookFilter phoneNumberFilter(AB_FI_TYPE_PHONE_CONTACT);
743 phoneNumberFilter.AppendString(FI_CONJ_OP_NONE, PHONE_CONTACT_FI_PR_PHONE, FI_STR_OP_CONTAIN, searchText);
744 phoneNumberFilter.AppendString(FI_CONJ_OP_OR, PHONE_CONTACT_FI_PR_DISPLAY_NAME, FI_STR_OP_CONTAIN, searchText);
746 pSearchingPhoneNumberList = pAddressbookManager->SearchN(phoneNumberFilter);
747 if (pSearchingPhoneNumberList == null)
752 IEnumerator* pEnum = pSearchingPhoneNumberList->GetEnumeratorN();
755 pSearchingPhoneNumberList->RemoveAll(true);
756 delete pSearchingPhoneNumberList;
761 ArrayList* pSearchedPersonsList = new (std::nothrow) ArrayList();
762 pSearchedPersonsList->Construct();
764 while (pEnum->MoveNext() == E_SUCCESS)
766 PhoneNumberContact* pPhoneNumberContact = static_cast<PhoneNumberContact *>(pEnum->GetCurrent());
767 Person* pPerson = pAddressbookManager->GetPersonN(pPhoneNumberContact->GetPersonId());
769 if (pPerson != null && pSearchedPersonsList->Contains(*pPerson) == false)
771 pSearchedPersonsList->Add(*pPerson);
775 pSearchingPhoneNumberList->RemoveAll(true);
776 delete pSearchingPhoneNumberList;
779 pSearchedList = pSearchedPersonsList;
781 if (searchType != SEARCH_TYPE_HAS_PHONE_ONLY)
783 IList* pDisplayNameSearchedList = null;
784 AddressbookFilter mainFilter(AB_FI_TYPE_PERSON);
785 mainFilter.AppendString(FI_CONJ_OP_NONE, PERSON_FI_PR_DISPLAY_NAME, FI_STR_OP_CONTAIN, searchText);
786 mainFilter.AppendBool(FI_CONJ_OP_AND, PERSON_FI_PR_HAS_PHONE, FI_CMP_OP_EQUAL, false);
788 pDisplayNameSearchedList = pAddressbookManager->SearchN(mainFilter);
789 pSearchedList->InsertItemsFrom(*pDisplayNameSearchedList, 0);
794 AddressbookFilter mainFilter(AB_FI_TYPE_PERSON);
795 mainFilter.AppendString(FI_CONJ_OP_NONE, PERSON_FI_PR_DISPLAY_NAME, FI_STR_OP_CONTAIN, searchText);
797 if (searchType == SEARCH_TYPE_HAS_PHONE_ONLY)
799 mainFilter.AppendBool(FI_CONJ_OP_AND, PERSON_FI_PR_HAS_PHONE, FI_CMP_OP_EQUAL, true);
801 else if (searchType == SEARCH_TYPE_HAS_EMAIL_ONLY)
803 mainFilter.AppendBool(FI_CONJ_OP_AND, PERSON_FI_PR_HAS_EMAIL, FI_CMP_OP_EQUAL, true);
806 pSearchedList = pAddressbookManager->SearchN(mainFilter);
809 for (int index = pSearchedList->GetCount() - 1; index >= 0; index--)
811 Person* pPerson = static_cast<Person *>(pSearchedList->GetAt(index));
812 if (__pExcludedContactIdList != null && pPerson != null)
814 for (int idIndex = __pExcludedContactIdList->GetCount() - 1; idIndex >= 0; idIndex--)
816 Integer* pPersonId = static_cast<Integer*>(__pExcludedContactIdList->GetAt(idIndex));
817 if (pPersonId != null && pPersonId->ToInt() == pPerson->GetId())
819 pSearchedList->RemoveAt(index, true);
826 return pSearchedList;
830 ContactListPresentationModel::GetSearchText(void)
832 return __searchedText;
836 ContactListPresentationModel::ResetSearchedContactList(void)
838 if (__pSearchedContactList != null)
840 __pSearchedContactList->RemoveAll(true);
841 delete __pSearchedContactList;
842 __pSearchedContactList = null;
847 ContactListPresentationModel::GetSearchedContactCount(void)
849 if (__pSearchedContactList != null)
851 return __pSearchedContactList->GetCount();
858 ContactListPresentationModel::GetItemMainIndex(int searchedItemIndex, int& groupIndex, int& itemIndex)
860 Person* pSearchedPerson = static_cast<Person *>(__pSearchedContactList->GetAt(searchedItemIndex));
862 if (pSearchedPerson == null)
868 String firstCharacter;
869 String displayName = pSearchedPerson->GetDisplayName();
870 displayName.ToUpper();
872 if (displayName[0] >= L'A' && displayName[0] <= L'Z')
874 displayName.SubString(0, 1, firstCharacter);
878 firstCharacter.Append(KEY_SHARP);
881 IEnumerator* pEnum = _pContactList->GetValuesN(firstCharacter);
887 while (pEnum->MoveNext() == E_SUCCESS)
889 Person* pPerson = static_cast<Person *>(pEnum->GetCurrent());
895 if (pSearchedPerson->GetId() == pPerson->GetId())
897 _pGroupIndexList->IndexOf(firstCharacter, groupIndex);
911 ContactListPresentationModel::GetAddressbookCount(void)
913 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
915 IList* pAddressbookList = pAddressbookManager->GetAllAddressbooksN();
916 if (pAddressbookList == null)
921 int count = pAddressbookList->GetCount();
922 pAddressbookList->RemoveAll(true);
923 delete pAddressbookList;
929 ContactListPresentationModel::GetAddressbookName(int index)
933 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
935 IList* pAddressbookList = pAddressbookManager->GetAllAddressbooksN();
936 if (pAddressbookList == null)
941 Addressbook* pAddressbook = static_cast<Addressbook *>(pAddressbookList->GetAt(index));
942 TryCatch(pAddressbook != null, , "Unable to get addressbook form addressbook manager");
944 //Todo : Return AccountId temporarily.
945 if (pAddressbook->GetId() == DEFAULT_ADDRESSBOOK_ID)
947 returnString.Append(ResourceManager::GetString(L"IDS_PB_BODY_PHONE"));
951 returnString.Append(pAddressbook->GetId());
955 pAddressbookList->RemoveAll(true);
956 delete pAddressbookList;
962 ContactListPresentationModel::GetCurrentAddressbook(void)
964 String addressbookName;
966 if (_pAddressbook->GetId() == DEFAULT_ADDRESSBOOK_ID)
968 addressbookName.Append(ResourceManager::GetString(L"IDS_PB_BODY_PHONE"));
972 addressbookName.Append(_pAddressbook->GetId());
975 return addressbookName;
979 ContactListPresentationModel::IsContactInCategory(int groupIndex, int itemIndex, Tizen::Social::RecordId categoryId)
981 bool isContactInCategory = false;
982 Person* pPerson = GetPersonAt(groupIndex, itemIndex);
989 AddressbookFilter mainFilter(AB_FI_TYPE_PERSON);
990 mainFilter.AppendInt(FI_CONJ_OP_NONE, PERSON_FI_PR_PERSON_ID, FI_CMP_OP_EQUAL, pPerson->GetId());
991 mainFilter.AppendInt(FI_CONJ_OP_AND, PERSON_FI_PR_CATEGORY_ID, FI_CMP_OP_EQUAL, categoryId);
993 IList* pList = AddressbookManager::GetInstance()->SearchN(mainFilter);
1000 if (pList->GetCount() > 0)
1002 isContactInCategory = true;
1006 isContactInCategory = false;
1009 pList->RemoveAll(true);
1012 return isContactInCategory;
1016 ContactListPresentationModel::IsContactInCategory(int groupIndex, Tizen::Social::RecordId categoryId)
1018 String key = GetKey(groupIndex);
1021 _pContactList->GetCount(key, count);
1023 for (int i = 0; i < count; i++)
1025 if (IsContactInCategory(groupIndex, i, categoryId) == false)
1035 ContactListPresentationModel::IsSearchedContactInCategory(int index, Tizen::Social::RecordId categoryId)
1037 bool isContactInCategory = false;
1038 Person* pPerson = static_cast<Person *>(__pSearchedContactList->GetAt(index));
1040 if (pPerson == null)
1045 AddressbookFilter mainFilter(AB_FI_TYPE_PERSON);
1046 mainFilter.AppendInt(FI_CONJ_OP_NONE, PERSON_FI_PR_PERSON_ID, FI_CMP_OP_EQUAL, pPerson->GetId());
1047 mainFilter.AppendInt(FI_CONJ_OP_AND, PERSON_FI_PR_CATEGORY_ID, FI_CMP_OP_EQUAL, categoryId);
1049 IList* pList = AddressbookManager::GetInstance()->SearchN(mainFilter);
1056 if (pList->GetCount() > 0)
1058 isContactInCategory = true;
1062 isContactInCategory = false;
1065 pList->RemoveAll(true);
1068 return isContactInCategory;
1072 ContactListPresentationModel::ExportToVcard(int groupIndex, int itemIndex)
1075 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
1076 Contact* pContact = pAddressbookManager->GetContactN(GetContactId(groupIndex, itemIndex));
1077 TryReturn(pContact != null, vCardPath, "[E_FAILURE] Unable to get the specific contact.");
1079 DateTime currentDateTime;
1080 SystemTime::GetCurrentTime(TIME_MODE_WALL, currentDateTime);
1082 vCardPath.Format(VCARD_STRING_LENGTH, VCARD_PATH_FORMAT, currentDateTime.GetYear(), currentDateTime.GetMonth(), currentDateTime.GetDay(),
1083 currentDateTime.GetHour(), currentDateTime.GetMinute(), currentDateTime.GetSecond());
1085 vCardPath = Application::GetInstance()->GetAppSharedPath() + vCardPath;
1087 result r = pAddressbookManager->ExportContactToVcard(*pContact, vCardPath);
1100 ContactListPresentationModel::AddContactChangeListener(const IContactEventListener& listener)
1102 _pContactChangeListenerList->Add(listener);
1106 ContactListPresentationModel::RemoveContactChangeListener(const IContactEventListener& listener)
1108 _pContactChangeListenerList->Remove(listener, false);
1112 ContactListPresentationModel::OnContactsChanged(const Tizen::Base::Collection::IList& contactChangeInfoList)
1114 if (__isContactChanged == false)
1116 __isContactChanged = true;
1121 IContactEventListener* pInterface = null;
1122 IEnumerator* pEnum = _pContactChangeListenerList->GetEnumeratorN();
1123 while (pEnum->MoveNext() == E_SUCCESS)
1125 pInterface = static_cast<IContactEventListener *>(pEnum->GetCurrent());
1126 if (pInterface == null)
1131 pInterface->OnContactsChanged();
1138 ContactListPresentationModel::OnCategoriesChanged(const Tizen::Base::Collection::IList& contactChangeInfoList)