2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://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 PhnSettingsRejectMsgsForm.cpp
19 * @brief Setting Reject message form
22 #include "PhnAppUtility.h"
23 #include "PhnSettingsConstants.h"
24 #include "PhnSettingsPresentationModel.h"
25 #include "PhnSettingsRejectMsgsForm.h"
26 #include "PhnSceneRegister.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
37 const int IDI_TOTAL_GROUP_COUNT = 1;
38 const int IDI_ADD_FOOTER_INDEX = 0;
39 const int IDI_DEL_FOOTER_INDEX = 1;
40 static const wchar_t* IDL_SETTINGS_REJECTMSGS_FORM = L"IDL_SETTINGS_REJECTMSGS_FORM";
42 SettingsRejectMsgsForm::SettingsRejectMsgsForm(void)
44 , __pSettingsPresentor(null)
48 SettingsRejectMsgsForm::~SettingsRejectMsgsForm(void)
53 SettingsRejectMsgsForm::Initialize(void)
55 Construct(IDL_SETTINGS_REJECTMSGS_FORM);
60 SettingsRejectMsgsForm::OnInitializing(void)
63 __pSettingsPresentor = SettingsPresentationModel::GetInstance();
64 // Setup back event listener
65 SetFormBackEventListener(this);
68 //initialize list view
69 r = InitializeGroupedTableView();
74 SettingsRejectMsgsForm::InitializeFooter(void)
76 Footer* pFooter = GetFooter();
79 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
82 String footerItemName(L"");
83 footerItemName.Append(AppUtility::GetResourceString(IDS_ADD_BTN_STRING));
84 FooterItem addFooterItem;
85 addFooterItem.Construct(IDA_ADD_FOOTER_ITEMID);
86 addFooterItem.SetText(footerItemName);
87 pFooter->InsertItemAt(IDI_ADD_FOOTER_INDEX, addFooterItem);
90 footerItemName.Clear();
91 footerItemName.Append(AppUtility::GetResourceString(IDS_DELETE_BTN_STRING));
92 FooterItem delFooterItem;
93 delFooterItem.Construct(IDA_DELETE_FOOTER_ITEMID);
94 delFooterItem.SetText(footerItemName);
95 pFooter->InsertItemAt(IDI_DEL_FOOTER_INDEX, delFooterItem);
98 pFooter->SetBackButton();
100 pFooter->SetItemColor(FOOTER_ITEM_STATUS_DISABLED, pFooter->GetColor());
101 pFooter->SetButtonColor(BUTTON_ITEM_STATUS_NORMAL, pFooter->GetColor());
102 pFooter->AddActionEventListener(*this);
107 SettingsRejectMsgsForm::OnTerminating(void)
109 result r = E_SUCCESS;
116 __pSettingsPresentor = null;
121 SettingsRejectMsgsForm::OnActionPerformed(const Control& source, int actionId)
123 SceneManager* pSceneManager = SceneManager::GetInstance();
124 AppAssert(pSceneManager != null);
128 case IDA_ADD_FOOTER_ITEMID:
130 //switch to Add New Reject Msg form
132 if (__pMsgsMap != null)
134 msgCount = __pMsgsMap->GetCount();
139 IList* pArgList = new (std::nothrow) ArrayList(SingleObjectDeleter);
140 pArgList->Add((new (std::nothrow) Integer(msgCount)));
141 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_ADD_REJECT_MSG), pArgList);
146 case IDA_DELETE_FOOTER_ITEMID:
148 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_DEL_MESSAGE), null);
158 SettingsRejectMsgsForm::OnFormBackRequested(Form& source)
160 SceneManager* pSceneManager = SceneManager::GetInstance();
161 AppAssert(pSceneManager != null);
162 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MAIN_SETTING_MENU), null);
166 SettingsRejectMsgsForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
168 //Fetch the latest message list
170 GroupedTableView* pMenuTableView = static_cast<GroupedTableView*>(GetControl(IDC_GROUPEDTABLEVIEW));
171 if (pMenuTableView != null)
173 pMenuTableView->UpdateTableView();
175 //Enable or Disable delete footer button
176 bool enableDelItem = true;
177 bool enableAddItem = true;
178 if (__pMsgsMap == null || __pMsgsMap->GetCount() <= 0)
180 enableDelItem = false;
182 if(__pMsgsMap != null && __pMsgsMap->GetCount() >= 6)
184 enableAddItem = false;
186 Footer* pFooter = GetFooter();
189 pFooter->SetItemEnabled(IDI_DEL_FOOTER_INDEX, enableDelItem);
190 pFooter->SetItemEnabled(IDI_ADD_FOOTER_INDEX, enableAddItem);
195 SettingsRejectMsgsForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
200 SettingsRejectMsgsForm::FetchRejectMsgs(void)
202 if (__pMsgsMap != null)
204 __pMsgsMap->RemoveAll();
207 //item to be fetched from Db
208 __pMsgsMap = __pSettingsPresentor->GetRejectMessageListN();
212 SettingsRejectMsgsForm::InitializeGroupedTableView(void)
214 result r = E_FAILURE;
215 GroupedTableView* pMenuTableView = static_cast<GroupedTableView*>(GetControl(IDC_GROUPEDTABLEVIEW));
216 if (pMenuTableView != null)
218 pMenuTableView->SetGroupedLookEnabled(true);
219 pMenuTableView->SetItemProvider(this);
220 r = pMenuTableView->AddGroupedTableViewItemEventListener(*this);
226 SettingsRejectMsgsForm::OnGroupedTableViewItemStateChanged(GroupedTableView& tableView, int groupIndex, int itemIndex, TableViewItem* pItem, TableViewItemStatus status)
228 SceneManager* pSceneManager = SceneManager::GetInstance();
229 AppAssert(pSceneManager != null);
231 if(__pMsgsMap != null)
233 int listIndex = itemIndex;
234 IListT<String> *pRejectMsgList = __pMsgsMap->GetValuesN();
235 if (pRejectMsgList != null && listIndex < pRejectMsgList->GetCount())
237 //switch to edit message form
238 String msgToBeEdited;
239 pRejectMsgList->GetAt(listIndex, msgToBeEdited);
240 //Ownership - transferred to next form
241 IList* pArgList = new (std::nothrow) ArrayList(SingleObjectDeleter);
242 pArgList->Add((new Integer(listIndex)));
243 pArgList->Add(new String(msgToBeEdited));
244 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_EDIT_REJECT_MSG), pArgList);
250 SettingsRejectMsgsForm::GetGroupCount(void)
252 return IDI_TOTAL_GROUP_COUNT;
256 SettingsRejectMsgsForm::GetItemCount(int groupIndex)
259 if (__pMsgsMap != null)
261 itemCount += __pMsgsMap->GetCount();
267 SettingsRejectMsgsForm::CreateGroupItem(int groupIndex, int itemWidth)
269 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
270 pItem->Construct(Dimension(itemWidth, H_LIST_HIDDENGROUP_ITEM));
271 pItem->SetBackgroundColor(COLOR_GROUP_ITEM_BG);
276 SettingsRejectMsgsForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
284 SettingsRejectMsgsForm::UpdateGroupItem(int groupIndex, TableViewGroupItem* pItem)
290 SettingsRejectMsgsForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
292 int listIndex = itemIndex;
293 //main text item rectangle
294 Rectangle mainItemRect(X_LIST_MENU_TEXT_ITEM, 0, (itemWidth - X_LIST_MENU_TEXT_ITEM), H_LIST_NORMAL_MENU_ITEM);
296 TableViewItem* pItem = null;
297 if (__pMsgsMap != null && listIndex < __pMsgsMap->GetCount())
299 //messages are from fetched list
301 __pMsgsMap->GetValue(listIndex, itemName);
303 pItem = new (std::nothrow) TableViewItem();
304 pItem->Construct(Dimension(itemWidth, H_LIST_NORMAL_MENU_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
306 Label* pItemLbl = new (std::nothrow) Label();
307 pItemLbl->Construct(mainItemRect, itemName);
308 pItemLbl->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
309 pItemLbl->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
310 pItemLbl->SetTextConfig(FONT_SIZE_MAIN_TXT, LABEL_TEXT_STYLE_NORMAL);
311 pItemLbl->SetTextColor(COLOR_MAIN_TXT);
312 pItem->AddControl(*pItemLbl);
313 pItem->SetBackgroundColor(COLOR_LIST_MENU_ITEM, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
319 SettingsRejectMsgsForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
327 SettingsRejectMsgsForm::UpdateItem(int groupIndex, int itemIndex, TableViewItem* pItem)
333 SettingsRejectMsgsForm::GetDefaultGroupItemHeight(void)
335 return H_LIST_HIDDENGROUP_ITEM;
339 SettingsRejectMsgsForm::GetDefaultItemHeight(void)
341 return H_LIST_NORMAL_MENU_ITEM;