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