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 CtGroupPresentationModel.cpp
19 * @brief This is the implementation file for the GroupPresentationModel class.
22 #include "CtGroupPresentationModel.h"
23 #include "CtIContactEventListener.h"
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
27 using namespace Tizen::Social;
29 GroupPresentationModel::GroupPresentationModel(void)
30 : __pContactChangeListenerList(null)
31 , __pAddressbook(null)
36 GroupPresentationModel::~GroupPresentationModel(void)
38 if (__pContactChangeListenerList != null)
40 __pContactChangeListenerList->RemoveAll(false);
41 delete __pContactChangeListenerList;
44 delete __pAddressbook;
49 GroupPresentationModel::Construct(Tizen::Social::RecordId categoryId)
51 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
52 __pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
53 if (__pAddressbook == null)
58 if (categoryId != INVALID_RECORD_ID)
60 __pCategory = __pAddressbook->GetCategoryN(categoryId);
61 if (__pCategory == null)
68 __pCategory = new (std::nothrow) Category();
69 if (__pCategory == null)
75 __pContactChangeListenerList = new (std::nothrow) ArrayList();
76 __pContactChangeListenerList->Construct();
78 __pAddressbook->SetAddressbookChangeEventListener(this);
84 GroupPresentationModel::IsDuplicatedCategory(void)
86 bool isDuplicated = false;
87 Category* pCategory = null;
89 IList* pList = __pAddressbook->GetAllCategoriesN();
95 IEnumerator* pEnum = pList->GetEnumeratorN();
96 while (pEnum->MoveNext() == E_SUCCESS)
98 pCategory = static_cast<Category*>(pEnum->GetCurrent());
99 TryCatch(pCategory != null, , "Unable to cast object to category");
101 if (pCategory->IsDefault())
106 if (pCategory->GetRecordId() != __pCategory->GetRecordId() &&
107 pCategory->GetName().Equals(__pCategory->GetName()) == true)
114 pList->RemoveAll(true);
122 GroupPresentationModel::IsDefaultCategory(void)
124 return __pCategory->IsDefault();
128 GroupPresentationModel::SetCategoryName(const Tizen::Base::String& groupName)
130 return __pCategory->SetName(groupName);
134 GroupPresentationModel::SetRingtone(const Tizen::Base::String& ringtonePath)
136 return __pCategory->SetRingtonePath(ringtonePath);
140 GroupPresentationModel::AddCategory(void)
142 return __pAddressbook->AddCategory(*__pCategory);
146 GroupPresentationModel::UpdateCategory(void)
149 Category* pCategory = __pAddressbook->GetCategoryN(GetCategoryId());
151 if (pCategory && pCategory->Equals(*__pCategory))
158 // If the category is not changed, OnCategoriesChanged will not be called. But UpdateCategory() returns E_SCCUESS.
159 result r = __pAddressbook->UpdateCategory(*__pCategory);
160 return isSame ? E_FAILURE : r;
164 GroupPresentationModel::SetThumbnailPath(const Tizen::Base::String& filePath)
166 return __pCategory->SetThumbnail(filePath);
170 GroupPresentationModel::GetThumbnailPath(void)
172 return __pCategory->GetThumbnailPath();
176 GroupPresentationModel::GetCategoryName(void)
178 return __pCategory->GetName();
182 GroupPresentationModel::GetRingtone(void)
184 return __pCategory->GetRingtonePath();
188 GroupPresentationModel::GetCategoryCount(void)
190 return __pAddressbook->GetCategoryCount();
193 Tizen::Social::RecordId
194 GroupPresentationModel::GetCategoryId(void)
196 return __pCategory->GetRecordId();
200 GroupPresentationModel::AddContactChangeListener(const IContactEventListener& listener)
202 __pContactChangeListenerList->Add(listener);
206 GroupPresentationModel::RemoveContactChangeListener(const IContactEventListener& listener)
208 __pContactChangeListenerList->Remove(listener, false);
212 GroupPresentationModel::OnContactsChanged(const Tizen::Base::Collection::IList& contactChangeInfoList)
217 GroupPresentationModel::OnCategoriesChanged(const Tizen::Base::Collection::IList& contactChangeInfoList)
219 IContactEventListener* pInterface = null;
220 IEnumerator* pEnum = __pContactChangeListenerList->GetEnumeratorN();
221 while (pEnum->MoveNext() == E_SUCCESS)
223 pInterface = static_cast<IContactEventListener *>(pEnum->GetCurrent());
224 if (pInterface == null)
229 pInterface->OnCategoriesChanged();