Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnSettingsMainMenuForm.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    PhnSettingsMainMenuForm.cpp
19  * @brief   Setting Main menu form
20  */
21 #include <FApp.h>
22 #include "PhnAppUtility.h"
23 #include "PhnSceneRegister.h"
24 #include "PhnSettingsConstants.h"
25 #include "PhnSettingsMainMenuForm.h"
26 #include "PhnSettingsPresentationModel.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::App;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Controls;
33 using namespace Tizen::Ui::Scenes;
34 using namespace Tizen::Graphics;
35
36 static const wchar_t* IDL_SETTINGS_MAINMENU_FORM = L"IDL_SETTINGS_MAINMENU_FORM";
37
38 SettingsMainMenuForm::SettingsMainMenuForm(void)
39 {
40 }
41
42 SettingsMainMenuForm::~SettingsMainMenuForm(void)
43 {
44 }
45
46 bool
47 SettingsMainMenuForm::Initialize(void)
48 {
49         Construct(IDL_SETTINGS_MAINMENU_FORM);
50         return true;
51 }
52
53 result
54 SettingsMainMenuForm::OnInitializing(void)
55 {
56         result r = E_SUCCESS;
57         //Footer
58         Footer* pFooter = GetFooter();
59         if (pFooter)
60         {
61                 pFooter->SetBackButton();
62                 pFooter->SetButtonColor(BUTTON_ITEM_STATUS_NORMAL, pFooter->GetColor());
63                 // Setup back event listener
64                 SetFormBackEventListener(this);
65                 pFooter->AddActionEventListener(*this);
66         }
67
68         //initialize table view
69         r = InitializeGroupedTableView();
70
71         return r;
72 }
73
74 result
75 SettingsMainMenuForm::OnTerminating(void)
76 {
77         result r = E_SUCCESS;
78         return r;
79 }
80
81 void
82 SettingsMainMenuForm::OnActionPerformed(const Control& source, int actionId)
83 {
84         switch (actionId)
85         {
86         default:
87                 break;
88         }
89 }
90
91 void
92 SettingsMainMenuForm::OnFormBackRequested(Form& source)
93 {
94         UiApp* pApp = UiApp::GetInstance();
95         AppAssert(pApp);
96         pApp->Terminate();
97 }
98
99 void
100 SettingsMainMenuForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
101 {
102 }
103
104 void
105 SettingsMainMenuForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
106 {
107 }
108
109 result
110 SettingsMainMenuForm::InitializeGroupedTableView(void)
111 {
112         result r = E_FAILURE;
113         GroupedTableView* pMainMenuTableView = static_cast<GroupedTableView*>(GetControl(IDC_GROUPEDTABLEVIEW));
114         if (pMainMenuTableView != null)
115         {
116                 pMainMenuTableView->SetGroupedLookEnabled(true);
117                 pMainMenuTableView->SetItemProvider(this);
118                 r = pMainMenuTableView->AddGroupedTableViewItemEventListener(*this);
119                 pMainMenuTableView->UpdateTableView();
120                 //disabling "call forwarding" option on emulator
121                 pMainMenuTableView->SetItemEnabled(GROUP_MAIN_CALL_SETTINGS, MAINCALLSETTINGS_CALLFORWARDING, false);
122         }
123         return r;
124 }
125
126 void
127 SettingsMainMenuForm::OnGroupedTableViewItemStateChanged(GroupedTableView& tableView, int groupIndex, int itemIndex, TableViewItem* pItem, TableViewItemStatus status)
128 {
129         SceneManager* pSceneManager = SceneManager::GetInstance();
130         AppAssert(pSceneManager != null);
131
132         if(groupIndex == GROUP_CALL_REJECTION)
133         {
134                 //switch to call reject list form
135                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALL_REJECTLIST_MENU), null);
136         }
137         else if(groupIndex == GROUP_REJECT_MSG)
138         {
139                 //switch to reject msg list form
140                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALL_REJECTMSGS_MENU), null);
141         }
142         else if(groupIndex == GROUP_MAIN_CALL_SETTINGS)
143         {
144                 switch (itemIndex)
145                 {
146                 case MAINCALLSETTINGS_SPEEDDIAL:
147                 {
148                         //switch to speed dial form
149                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_SPEED_DIAL), null);
150                 }
151                 break;
152
153                 case MAINCALLSETTINGS_CALLFORWARDING:
154                 {
155                         //switch to form
156                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALLTYPE_FORWARD), null);
157                 }
158                 break;
159
160                 case MAINCALLSETTINGS_MORECALLSETTINGS:
161                 {
162                         //switch to speed dial form
163                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MORE_OPTIONS), null);
164                 }
165                 break;
166
167                 default:
168                 break;
169                 }
170         }
171 }
172
173 int
174 SettingsMainMenuForm::GetGroupCount(void)
175 {
176         return GROUP_TOTALCOUNT;
177 }
178
179 int
180 SettingsMainMenuForm::GetItemCount(int groupIndex)
181 {
182         int itemCount = 0;
183         switch (groupIndex)
184         {
185         case GROUP_CALL_REJECTION:
186                 itemCount = CALLREJECTION_TOTALCOUNT;
187                 break;
188
189         case GROUP_REJECT_MSG:
190                 itemCount = REJECTMSG_TOTALCOUNT;
191                 break;
192
193         case GROUP_MAIN_CALL_SETTINGS:
194                 itemCount = MAINCALLSETTINGS_TOTALCOUNT;
195                 break;
196
197         case GROUP_CALL_REJECTION_HLPTXT:
198         case GROUP_REJECT_MSG_HLPTXT:
199                 itemCount = 0;
200                 break;
201
202         default:
203                 break;
204         }
205         return itemCount;
206 }
207
208 TableViewGroupItem*
209 SettingsMainMenuForm::CreateGroupItem(int groupIndex, int itemWidth)
210 {
211         String helpText(L"");
212         switch (groupIndex)
213         {
214         case GROUP_CALL_REJECTION_HLPTXT:
215         {
216                 helpText.Append(AppUtility::GetResourceString(IDS_SETTING_REJECT_HLP_STRING));
217         }
218         break;
219
220         case GROUP_REJECT_MSG_HLPTXT:
221         {
222                 helpText.Append(AppUtility::GetResourceString(IDS_SETTING_REJECT_MSG_HLP_STRING));
223         }
224         break;
225
226         default:
227         break;
228         }
229
230         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
231         if (helpText.IsEmpty() == true)
232         {
233                 pItem->Construct(Dimension(itemWidth, H_LIST_HIDDENGROUP_ITEM));
234                 pItem->SetBackgroundColor(COLOR_GROUP_ITEM_BG);
235         }
236         else
237         {
238                 //help text item rectangle
239                 Rectangle helpItemRect(X_LIST_MENU_HLPTXT_ITEM, Y_LIST_MENU_HLPTXT_ITEM, (itemWidth - X_LIST_MENU_HLPTXT_ITEM),
240                                                            (H_LIST_MENU_SINGLELINE_HLPTXT_ITEM - Y_LIST_MENU_HLPTXT_ITEM));
241                 pItem->Construct(Dimension(itemWidth, H_LIST_MENU_SINGLELINE_HLPTXT_ITEM));
242                 Label* pItemLbl = new (std::nothrow) Label();
243                 pItemLbl->Construct(helpItemRect, helpText);
244                 pItemLbl->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
245                 pItemLbl->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
246                 pItemLbl->SetTextConfig(FONT_SIZE_HELP_TXT, LABEL_TEXT_STYLE_NORMAL);
247                 pItemLbl->SetTextColor(COLOR_HELP_TXT);
248                 pItem->AddControl(*pItemLbl);
249                 pItem->SetEnabled(false);
250                 pItem->SetBackgroundColor(COLOR_HELP_ITEM_BG, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
251                 pItem->SetBackgroundColor(COLOR_HELP_ITEM_BG, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
252         }
253         return pItem;
254 }
255
256 bool
257 SettingsMainMenuForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
258 {
259         delete pItem;
260         pItem = null;
261         return true;
262 }
263
264 void
265 SettingsMainMenuForm::UpdateGroupItem(int groupIndex, TableViewGroupItem* pItem)
266 {
267         return;
268 }
269
270 TableViewItem*
271 SettingsMainMenuForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
272 {
273         TableViewItem* pItem = new (std::nothrow) TableViewItem();
274         pItem->Construct(Dimension(itemWidth, H_LIST_NORMAL_MENU_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
275
276         //text item rectangle
277         Rectangle itemNameRect(X_LIST_MENU_TEXT_ITEM, 0, (itemWidth - X_LIST_MENU_TEXT_ITEM), H_LIST_NORMAL_MENU_ITEM);
278         //description text rectangle
279         Rectangle descriptionTxtRect(X_LIST_MENU_TEXT_ITEM, H_LIST_NORMAL_TXT_ITEM,
280                                                                   (itemWidth - X_LIST_MENU_TEXT_ITEM), H_LIST_SUB_TXT_ITEM);
281         String itemName(L"");
282         String descriptionText(L"");
283         if(groupIndex == GROUP_CALL_REJECTION)
284         {
285                 itemName.Append(AppUtility::GetResourceString(IDS_SETTING_REJECT_STRING));
286         }
287         else if(groupIndex == GROUP_REJECT_MSG)
288         {
289                 itemName.Append(AppUtility::GetResourceString(IDS_SETTING_REJECT_MSG_STRING));
290         }
291         else if(groupIndex == GROUP_MAIN_CALL_SETTINGS)
292         {
293                 switch (itemIndex)
294                 {
295                 case MAINCALLSETTINGS_SPEEDDIAL:
296                 {
297                         itemName.Append(AppUtility::GetResourceString(IDS_SETTING_SPEEDDIAL_STRING));
298                 }
299                 break;
300
301                 case MAINCALLSETTINGS_CALLFORWARDING:
302                 {
303                         itemName.Append(AppUtility::GetResourceString(IDS_SETTING_FORWARDING_STRING));
304                 }
305                 break;
306
307                 case MAINCALLSETTINGS_MORECALLSETTINGS:
308                 {
309                         itemName.Append(AppUtility::GetResourceString(IDS_SETTING_MORE_MAIN_STRING));
310                         descriptionText.Append(AppUtility::GetResourceString(IDS_SETTING_MORE_SUB_STRING));
311                         //update item Name rectangle
312                         itemNameRect.y = Y_LIST_MENU_TEXT_ITEM;
313                         itemNameRect.height = H_LIST_NORMAL_TXT_ITEM;
314                 }
315                 break;
316
317                 default:
318                 break;
319                 }
320         }
321
322         //Item Name
323         Label* pItemLbl = new (std::nothrow) Label();
324         pItemLbl->Construct(itemNameRect, itemName);
325         pItemLbl->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
326         pItemLbl->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
327         pItemLbl->SetTextConfig(FONT_SIZE_MAIN_TXT, LABEL_TEXT_STYLE_NORMAL);
328         pItemLbl->SetTextColor(COLOR_NORMAL_MAIN_TXT);//COLOR_PRESS_MAIN_TXT
329         pItem->AddControl(*pItemLbl);
330         //description text
331         if(descriptionText.IsEmpty() == false)
332         {
333                 Label* pDescriptionLbl = new (std::nothrow) Label();
334                 pDescriptionLbl->Construct(descriptionTxtRect, descriptionText);
335                 pDescriptionLbl->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
336                 pDescriptionLbl->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
337                 pDescriptionLbl->SetTextConfig(FONT_SIZE_SUB_TXT, LABEL_TEXT_STYLE_NORMAL);
338                 pDescriptionLbl->SetTextColor(COLOR_NORMAL_SUB_TXT);
339                 pItem->AddControl(*pDescriptionLbl);
340         }
341         pItem->SetBackgroundColor(COLOR_LIST_MENU_ITEM, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
342         return pItem;
343 }
344
345 bool
346 SettingsMainMenuForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
347 {
348         delete pItem;
349         pItem = null;
350         return true;
351 }
352
353 void
354 SettingsMainMenuForm::UpdateItem(int groupIndex, int itemIndex, TableViewItem* pItem)
355 {
356         return;
357 }
358
359 int
360 SettingsMainMenuForm::GetDefaultGroupItemHeight(void)
361 {
362         return H_LIST_HIDDENGROUP_ITEM;
363 }
364
365 int
366 SettingsMainMenuForm::GetDefaultItemHeight(void)
367 {
368         return H_LIST_NORMAL_MENU_ITEM;
369 }