Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnSettingsRejectMsgsForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file    PhnSettingsRejectMsgsForm.cpp
19  * @brief   Setting Reject message form
20  */
21 #include <FApp.h>
22 #include "PhnAppUtility.h"
23 #include "PhnSettingsConstants.h"
24 #include "PhnSettingsPresentationModel.h"
25 #include "PhnSettingsRejectMsgsForm.h"
26 #include "PhnSceneRegister.h"
27
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;
35
36 //contants
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";
41
42 SettingsRejectMsgsForm::SettingsRejectMsgsForm(void)
43         : __pMsgsMap(null)
44         , __pSettingsPresentor(null)
45 {
46 }
47
48 SettingsRejectMsgsForm::~SettingsRejectMsgsForm(void)
49 {
50 }
51
52 bool
53 SettingsRejectMsgsForm::Initialize(void)
54 {
55         Construct(IDL_SETTINGS_REJECTMSGS_FORM);
56         return true;
57 }
58
59 result
60 SettingsRejectMsgsForm::OnInitializing(void)
61 {
62         result r = E_SUCCESS;
63         __pSettingsPresentor = SettingsPresentationModel::GetInstance();
64         // Setup back event listener
65         SetFormBackEventListener(this);
66         //Initialize Footer
67         InitializeFooter();
68         //initialize list view
69         r = InitializeGroupedTableView();
70         return r;
71 }
72
73 void
74 SettingsRejectMsgsForm::InitializeFooter(void)
75 {
76         Footer* pFooter = GetFooter();
77         if (pFooter != null)
78         {
79                 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
80
81                 //Add footer item
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);
88
89                 //Delete footer item
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);
96
97                 //back button
98                 pFooter->SetBackButton();
99
100                 pFooter->SetItemColor(FOOTER_ITEM_STATUS_DISABLED, pFooter->GetColor());
101                 pFooter->SetButtonColor(BUTTON_ITEM_STATUS_NORMAL, pFooter->GetColor());
102                 pFooter->AddActionEventListener(*this);
103         }
104 }
105
106 result
107 SettingsRejectMsgsForm::OnTerminating(void)
108 {
109         result r = E_SUCCESS;
110
111         if (__pMsgsMap)
112         {
113                 delete __pMsgsMap;
114                 __pMsgsMap = null;
115         }
116         __pSettingsPresentor = null;
117         return r;
118 }
119
120 void
121 SettingsRejectMsgsForm::OnActionPerformed(const Control& source, int actionId)
122 {
123         SceneManager* pSceneManager = SceneManager::GetInstance();
124         AppAssert(pSceneManager != null);
125
126         switch (actionId)
127         {
128         case IDA_ADD_FOOTER_ITEMID:
129         {
130                 //switch to Add New Reject Msg form
131                 int msgCount = 0;
132                 if (__pMsgsMap != null)
133                 {
134                         msgCount = __pMsgsMap->GetCount();
135                 }
136
137                 if(msgCount < 6)
138                 {
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);
142                 }
143         }
144         break;
145
146         case IDA_DELETE_FOOTER_ITEMID:
147         {
148                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_DEL_MESSAGE), null);
149         }
150         break;
151
152         default:
153                 break;
154         }
155 }
156
157 void
158 SettingsRejectMsgsForm::OnFormBackRequested(Form& source)
159 {
160         SceneManager* pSceneManager = SceneManager::GetInstance();
161         AppAssert(pSceneManager != null);
162         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MAIN_SETTING_MENU), null);
163 }
164
165 void
166 SettingsRejectMsgsForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
167 {
168         //Fetch the latest message list
169         FetchRejectMsgs();
170         GroupedTableView* pMenuTableView = static_cast<GroupedTableView*>(GetControl(IDC_GROUPEDTABLEVIEW));
171         if (pMenuTableView != null)
172         {
173                 pMenuTableView->UpdateTableView();
174         }
175         //Enable or Disable delete footer button
176         bool enableDelItem = true;
177         bool enableAddItem = true;
178         if (__pMsgsMap == null || __pMsgsMap->GetCount() <= 0)
179         {
180                 enableDelItem = false;
181         }
182         if(__pMsgsMap != null && __pMsgsMap->GetCount() >= 6)
183         {
184                 enableAddItem = false;
185         }
186         Footer* pFooter = GetFooter();
187         if (pFooter != null)
188         {
189                 pFooter->SetItemEnabled(IDI_DEL_FOOTER_INDEX, enableDelItem);
190                 pFooter->SetItemEnabled(IDI_ADD_FOOTER_INDEX, enableAddItem);
191         }
192 }
193
194 void
195 SettingsRejectMsgsForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
196 {
197 }
198
199 void
200 SettingsRejectMsgsForm::FetchRejectMsgs(void)
201 {
202         if (__pMsgsMap != null)
203         {
204                 __pMsgsMap->RemoveAll();
205                 delete __pMsgsMap;
206         }
207         //item to be fetched from Db
208         __pMsgsMap = __pSettingsPresentor->GetRejectMessageListN();
209 }
210
211 result
212 SettingsRejectMsgsForm::InitializeGroupedTableView(void)
213 {
214         result r = E_FAILURE;
215         GroupedTableView* pMenuTableView = static_cast<GroupedTableView*>(GetControl(IDC_GROUPEDTABLEVIEW));
216         if (pMenuTableView != null)
217         {
218                 pMenuTableView->SetGroupedLookEnabled(true);
219                 pMenuTableView->SetItemProvider(this);
220                 r = pMenuTableView->AddGroupedTableViewItemEventListener(*this);
221         }
222         return r;
223 }
224
225 void
226 SettingsRejectMsgsForm::OnGroupedTableViewItemStateChanged(GroupedTableView& tableView, int groupIndex, int itemIndex, TableViewItem* pItem, TableViewItemStatus status)
227 {
228         SceneManager* pSceneManager = SceneManager::GetInstance();
229         AppAssert(pSceneManager != null);
230
231         if(__pMsgsMap != null)
232         {
233                 int listIndex = itemIndex;
234                 IListT<String> *pRejectMsgList = __pMsgsMap->GetValuesN();
235                 if (pRejectMsgList != null && listIndex < pRejectMsgList->GetCount())
236                 {
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);
245                 }
246         }
247 }
248
249 int
250 SettingsRejectMsgsForm::GetGroupCount(void)
251 {
252         return IDI_TOTAL_GROUP_COUNT;
253 }
254
255 int
256 SettingsRejectMsgsForm::GetItemCount(int groupIndex)
257 {
258         int itemCount = 0;
259         if (__pMsgsMap != null)
260         {
261                 itemCount += __pMsgsMap->GetCount();
262         }
263         return itemCount;
264 }
265
266 TableViewGroupItem*
267 SettingsRejectMsgsForm::CreateGroupItem(int groupIndex, int itemWidth)
268 {
269         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
270         pItem->Construct(Dimension(itemWidth, H_LIST_HIDDENGROUP_ITEM));
271         pItem->SetBackgroundColor(COLOR_GROUP_ITEM_BG);
272         return pItem;
273 }
274
275 bool
276 SettingsRejectMsgsForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
277 {
278         delete pItem;
279         pItem = null;
280         return true;
281 }
282
283 void
284 SettingsRejectMsgsForm::UpdateGroupItem(int groupIndex, TableViewGroupItem* pItem)
285 {
286         return;
287 }
288
289 TableViewItem*
290 SettingsRejectMsgsForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
291 {
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);
295
296         TableViewItem* pItem = null;
297         if (__pMsgsMap != null && listIndex < __pMsgsMap->GetCount())
298         {
299                 //messages are from fetched list
300                 String itemName;
301                 __pMsgsMap->GetValue(listIndex, itemName);
302
303                 pItem = new (std::nothrow) TableViewItem();
304                 pItem->Construct(Dimension(itemWidth, H_LIST_NORMAL_MENU_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
305                 //main text
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);
314         }
315         return pItem;
316 }
317
318 bool
319 SettingsRejectMsgsForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
320 {
321         delete pItem;
322         pItem = null;
323         return true;
324 }
325
326 void
327 SettingsRejectMsgsForm::UpdateItem(int groupIndex, int itemIndex, TableViewItem* pItem)
328 {
329         return;
330 }
331
332 int
333 SettingsRejectMsgsForm::GetDefaultGroupItemHeight(void)
334 {
335         return H_LIST_HIDDENGROUP_ITEM;
336 }
337
338 int
339 SettingsRejectMsgsForm::GetDefaultItemHeight(void)
340 {
341         return H_LIST_NORMAL_MENU_ITEM;
342 }