NABI issues N_SE-50115, N_SE-50067, N_SE-49946, N_SE-49897, N_SE-49884, N_SE-48837...
[apps/osp/Settings.git] / src / StResetSettingForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
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                StResetSettingForm.cpp
19  * @brief               This is the implementation file for ResetSettingForm class.
20  */
21
22 #include "StResetSettingForm.h"
23 #include "StResourceManager.h"
24 #include "StTypes.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Runtime;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
33
34 static const int ID_GROUP_RESET_SETTING_MAIN = 0;
35 static const int ID_GROUP_RESET_SETTING_ITEM_COUNT = 16;
36
37 static const int ID_GROUP_COUNT = 1;
38 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_RESET_SETTING_ITEM_COUNT;
39
40 static const int IDA_RESET = 100;
41 static const int IDA_CANCEL = 101;
42
43 static const int IDA_BUTTON_CHECKED = 200;
44 static const int IDA_BUTTON_UNCHECKED = 201;
45 static const int IDA_BUTTON_SELECTED = 202;
46 static const int Y_ITEM_COUNT_DISPLAY = 968;
47
48 static const int TICK_COUNT = 10;
49 static const int MESSAGE_TIME_OUT = 100;
50
51 static const int ID_ITEM_LOCATION = 0;
52 static const int ID_ITEM_NETWORK = 1;
53 static const int ID_ITEM_WIFI_DIRECT = 2;
54 static const int ID_ITEM_WALLPAPER = 3;
55 static const int ID_ITEM_SOUNDS = 4;
56 static const int ID_ITEM_BRIGHTNESS = 5;
57 static const int ID_ITEM_FONT = 6;
58 static const int ID_ITEM_DISPLAY = 7;
59 static const int ID_ITEM_AUTO_ROTATE_SCREEN = 8;
60 static const int ID_ITEM_DATE_TIME = 9;
61 static const int ID_ITEM_LANGUAGE_REGION = 10;
62 static const int ID_ITEM_KEYBOARD = 11;
63 static const int ID_ITEM_MANAGE_APPLICATION = 12;
64 static const int ID_ITEM_MEMORY = 13;
65 static const int ID_ITEM_DEVELOPER_OPTION = 14;
66 static const int ID_ITEM_ABOUT_PHONE = 15;
67
68 static const int STRING_SIZE_LIMIT = 20;
69
70 ResetterSettingForm::ResetterSettingForm(void)
71         : __bTimerExpired(false)
72         , __count(TICK_COUNT)
73         , __pLabelItemCount(null)
74         , __pCheckButton(null)
75 {
76          __timer.Construct(*this);
77 }
78
79 ResetterSettingForm::~ResetterSettingForm(void)
80 {
81 }
82
83 void
84 ResetterSettingForm::CreateFooter(void)
85 {
86         FooterItem footerReset;
87         FooterItem footerCancel;
88
89         Footer* pFooter = GetFooter();
90         AppAssert(pFooter);
91
92         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
93
94         footerReset.Construct(IDA_RESET);
95         footerReset.SetText(ResourceManager::GetString(L"IDS_ST_BODY_RESET"));
96
97         footerCancel.Construct(IDA_CANCEL);
98         footerCancel.SetText(ResourceManager::GetString(L"IDS_ST_BODY_CANCEL"));
99
100         pFooter->AddItem(footerReset);
101         pFooter->AddItem(footerCancel);
102 }
103
104 void
105 ResetterSettingForm::CreateTableView(void)
106 {
107         Rectangle bounds = GetClientAreaBounds();
108         Rectangle itemMainRectangle;
109         Rectangle itemSelectCount;
110
111         String itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SELECT_ALL");
112         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
113
114         bounds.x = X_GROUP_DEFAULT;
115         bounds.y = H_GROUP_ITEM_DEFAULT;
116         bounds.width -= (bounds.x * WIDTH_GAP);
117
118         itemMainRectangle = itemSelectCount = bounds;
119         itemMainRectangle.y = Y_GROUP_DEFAULT;
120         itemMainRectangle.height = H_GROUP_ITEM_DEFAULT;
121
122         __pCheckButton = new (std::nothrow) CheckButton();
123         __pCheckButton->Construct(itemMainRectangle, CHECK_BUTTON_STYLE_MARK, BACKGROUND_STYLE_NONE, false);
124         __pCheckButton->SetActionId(IDA_BUTTON_CHECKED, IDA_BUTTON_UNCHECKED, IDA_BUTTON_SELECTED);
125         __pCheckButton->SetText(itemMainText);
126
127         AddControl(__pCheckButton);
128
129         __pCheckButton->AddActionEventListener(*this);
130
131         __pTableView = new (std::nothrow) GroupedTableView();
132         __pTableView->Construct(bounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FIXED);
133         __pTableView->SetItemProvider(this);
134
135         AddControl(__pTableView);
136
137         __pTableView->AddGroupedTableViewItemEventListener(*this);
138
139         itemSelectCount.y = Y_ITEM_COUNT_DISPLAY;
140         itemSelectCount.height = H_GROUP_INDEX_NO_TITLE_DEFAULT;
141
142         __pLabelItemCount = new (std::nothrow) Label();
143         __pLabelItemCount->Construct(itemSelectCount, itemSelectedText);
144         __pLabelItemCount->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
145         __pLabelItemCount->SetTextConfig(FONT_SIZE_POPUP_TEXT, LABEL_TEXT_STYLE_BOLD);
146         __pLabelItemCount->SetTextColor(COLOR_MAIN_TEXT);
147
148         AddControl(__pLabelItemCount);
149
150         __pLabelItemCount->SetBackgroundColor(COLOR_BG_CHECKBOX);
151         __pLabelItemCount->SetShowState(false);
152
153         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
154         if (pRelativeLayout != null)
155         {
156                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
157                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
158                 delete pRelativeLayout;
159         }
160 }
161
162 result
163 ResetterSettingForm::OnInitializing(void)
164 {
165         SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
166         CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_RESET_SETTINGS"));
167         CreateFooter();
168         CreateTableView();
169
170         AppLogDebug("ENTER");
171
172         return E_SUCCESS;
173 }
174
175 result
176 ResetterSettingForm::OnTerminating(void)
177 {
178         __pLabelItemCount = null;
179         __pCheckButton = null;
180         __pTableView = null;
181
182         return E_SUCCESS;
183 }
184
185 void
186 ResetterSettingForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
187 {
188         __pTableView->UpdateTableView();
189 }
190
191 void
192 ResetterSettingForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
193 {
194 }
195
196 int
197 ResetterSettingForm::GetGroupCount(void)
198 {
199         AppLogDebug("ENTER");
200         return ID_GROUP_COUNT;
201 }
202
203 int
204 ResetterSettingForm::GetItemCount(int groupIndex)
205 {
206         int itemCount = ID_GROUP_MAX_ITEM_COUNT;
207
208         AppLogDebug("GetItemCount %d", itemCount);
209
210         return itemCount;
211 }
212
213 TableViewGroupItem*
214 ResetterSettingForm::CreateGroupItem(int groupIndex, int itemWidth)
215 {
216         AppLogDebug("ENTER");
217
218         return null;
219 }
220
221 TableViewItem*
222 ResetterSettingForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
223 {
224         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
225
226         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
227         Rectangle itemMainRectangle;
228         String itemMainText;
229         Label* pLabel = null;
230         int fontSize = GetFontSize();
231
232         switch (itemIndex)
233         {
234         case ID_ITEM_LOCATION:
235                 {
236                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_LOCATIONS");
237                 }
238                 break;
239
240         case ID_ITEM_NETWORK:
241                 {
242                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_NETWORK");
243                 }
244                 break;
245
246         case ID_ITEM_WIFI_DIRECT:
247                 {
248                         itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
249                 }
250                 break;
251
252         case ID_ITEM_WALLPAPER:
253                 {
254                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MAINDISPLAY_WALLPAPER");
255                 }
256                 break;
257
258         case ID_ITEM_SOUNDS:
259                 {
260                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SOUNDS");
261                 }
262                 break;
263
264         case ID_ITEM_BRIGHTNESS:
265                 {
266                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_BRIGHTNESS");
267                 }
268                 break;
269
270         case ID_ITEM_FONT:
271                 {
272                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_FONT");
273                 }
274                 break;
275
276         case ID_ITEM_DISPLAY:
277                 {
278                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DISPLAY");
279                 }
280                 break;
281
282         case ID_ITEM_AUTO_ROTATE_SCREEN:
283                 {
284                         itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_AUTO_ROTATE_SCREEN_ABB");
285                 }
286                 break;
287
288         case ID_ITEM_DATE_TIME:
289                 {
290                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DATE_AND_TIME");
291                 }
292                 break;
293
294         case ID_ITEM_LANGUAGE_REGION:
295                 {
296                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_LANGUAGE_AND_REGION_ABB");
297                 }
298                 break;
299
300         case ID_ITEM_KEYBOARD:
301                 {
302                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_KEYBOARD");
303                 }
304                 break;
305
306         case ID_ITEM_MANAGE_APPLICATION:
307                 {
308                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS");
309                 }
310                 break;
311
312         case ID_ITEM_MEMORY:
313                 {
314                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MEMORY");
315                 }
316                 break;
317
318         case ID_ITEM_DEVELOPER_OPTION:
319                 {
320                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DEVELOPER_OPTIONS");
321                 }
322                 break;
323
324         case ID_ITEM_ABOUT_PHONE:
325                 {
326                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ABOUT_PHONE");
327                 }
328                 break;
329
330         default:
331                 break;
332         }
333
334         ItemTypeOneLine(itemMainRectangle);
335
336         TableViewItem* pItem = new (std::nothrow) TableViewItem();
337
338         RelativeLayout relativeLayout;
339         relativeLayout.Construct();
340
341         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
342         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
343
344         pLabel = new (std::nothrow) Label();
345         pLabel->Construct(itemMainRectangle, itemMainText);
346         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
347         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
348         pLabel->SetTextColor(COLOR_MAIN_TEXT);
349
350         pItem->AddControl(pLabel);
351
352         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
353         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
354         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
355
356         return pItem;
357 }
358
359 bool
360 ResetterSettingForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
361 {
362         AppLogDebug("ENTER");
363
364         delete pItem;
365         pItem = null;
366
367         return true;
368 }
369
370 bool
371 ResetterSettingForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
372 {
373         AppLogDebug("ENTER");
374
375         delete pItem;
376         pItem = null;
377
378         return true;
379 }
380
381 void
382 ResetterSettingForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
383 {
384         int itemCount = 0;
385         int count = 0;
386         int checkedItemCount = 0;
387         int localGroup = 0;
388         int localItem = 0;
389         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
390         String countText;
391
392         itemCount = tableView.GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
393
394         if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
395         {
396                 tableView.SetItemChecked(groupIndex, itemIndex, true);
397         }
398
399         if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
400         {
401                 tableView.SetItemChecked(groupIndex, itemIndex, false);
402         }
403
404         for (count = 0; count < itemCount; count++)
405         {
406                 localGroup = ID_GROUP_RESET_SETTING_MAIN;
407                 localItem = count;
408
409                 if (__pTableView->IsItemChecked(localGroup, localItem))
410                 {
411                         checkedItemCount++;
412                 }
413         }
414
415         if (checkedItemCount)
416         {
417                 countText.Format(STRING_SIZE_LIMIT, L" (%d)", checkedItemCount);
418                 itemSelectedText.Insert(countText, itemSelectedText.GetLength());
419                 __pLabelItemCount->SetText(itemSelectedText);
420                 __pLabelItemCount->SetShowState(true);
421                 __pLabelItemCount->Invalidate(true);
422
423                 __count = TICK_COUNT;
424                 __timer.Start(MESSAGE_TIME_OUT);
425         }
426 }
427
428 void
429 ResetterSettingForm::OnActionPerformed(const Control& source, int actionId)
430 {
431         AppLogDebug("Action ID = [%d]", actionId);
432         switch (actionId)
433         {
434         case IDA_CANCEL:
435                 {
436                         SceneManager* pSceneManager = SceneManager::GetInstance();
437                         AppAssert(pSceneManager);
438
439                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
440                 }
441                 break;
442
443         case IDA_BUTTON_CHECKED:
444                 {
445                         int itemCount = 0;
446                         int count = 0;
447                         int checkedItemCount = 0;
448                         int localGroup = 0;
449                         int localItem = 0;
450                         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
451                         String countText;
452
453                         itemCount = __pTableView->GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
454
455                         __pTableView->UpdateTableView();
456
457                         for (count = 0; count < itemCount; count++)
458                         {
459                                 localGroup = ID_GROUP_RESET_SETTING_MAIN;
460                                 localItem = count;
461                                 __pTableView->SetItemChecked(localGroup, localItem, true);
462
463                                 if (__pTableView->IsItemChecked(localGroup, localItem))
464                                 {
465                                         checkedItemCount++;
466                                 }
467                         }
468                         countText.Format(STRING_SIZE_LIMIT, L" (%d)", checkedItemCount);
469                         itemSelectedText.Insert(countText, itemSelectedText.GetLength());
470
471                         __pLabelItemCount->SetText(itemSelectedText);
472                         __pLabelItemCount->SetShowState(true);
473                         __pLabelItemCount->Invalidate(true);
474
475                         __count = TICK_COUNT;
476                         __timer.Start(MESSAGE_TIME_OUT);
477                 }
478                 break;
479
480         case IDA_RESET:
481                 // fall through
482         case IDA_BUTTON_UNCHECKED:
483                 {
484                         int itemCount = 0;
485                         int count = 0;
486                         int localGroup = 0;
487                         int localItem = 0;
488
489                         itemCount = __pTableView->GetItemCountAt(ID_GROUP_RESET_SETTING_MAIN);
490
491                         __pTableView->UpdateTableView();
492                         __pCheckButton->SetSelected(false);
493
494                         for (count = 0; count < itemCount; count++)
495                         {
496                                 localGroup = ID_GROUP_RESET_SETTING_MAIN;
497                                 localItem = count;
498
499                                 __pTableView->SetItemChecked(localGroup, localItem, false);
500                         }
501                 }
502                 break;
503
504         default:
505                 {
506                         AppLogDebug("Reset setting");
507                 }
508                 break;
509         }
510 }
511
512 void
513 ResetterSettingForm::OnTimerExpired(Timer& timer)
514 {
515         if (__count > 0)
516         {
517                 __count--;
518         }
519         else
520         {
521                 __count = 0;
522         }
523
524         if (__count <= 0)
525         {
526                 __bTimerExpired = true;
527                 __pLabelItemCount->SetShowState(false);
528                 __pLabelItemCount->Invalidate(true);
529         }
530         else
531         {
532                 __timer.Start(MESSAGE_TIME_OUT);
533         }
534 }
535
536 bool
537 ResetterSettingForm::IsTimerExpired() const
538 {
539         return __bTimerExpired;
540 }
541
542 int
543 ResetterSettingForm::GetDefaultGroupItemHeight(void)
544 {
545         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
546 }
547
548 int
549 ResetterSettingForm::GetDefaultItemHeight(void)
550 {
551         return H_GROUP_ITEM_DEFAULT;
552 }
553
554 void
555 ResetterSettingForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
556 {
557 }
558
559 void
560 ResetterSettingForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
561 {
562 }
563
564 void
565 ResetterSettingForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
566 {
567 }
568
569 void
570 ResetterSettingForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
571 {
572 }