Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StResetForm.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                StResetForm.cpp
19  * @brief               This is the implementation file for ResetterForm class.
20  */
21
22 #include "StResetForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
32
33 static const int ID_GROUP_RESET_MAIN = 0;
34 static const int ID_GROUP_RESET_MAIN_ITEM_COUNT = 2;
35 static const int ID_ITEM_RESET_MAIN_RESET_SETTING = 0;
36 static const int ID_ITEM_RESET_MAIN_FACTORY_RESET = 1;
37
38 static const int ID_GROUP_RESET_MAIN_TEXT = 1;
39 static const int ID_GROUP_RESET_MAIN_TEXT_ITEM_COUNT = 0;
40
41 static const int ID_GROUP_COUNT = 2;
42 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_RESET_MAIN_ITEM_COUNT;
43
44 ResetterForm::ResetterForm(void)
45 {
46 }
47
48 ResetterForm::~ResetterForm(void)
49 {
50 }
51
52 void
53 ResetterForm::CreateFooter(void)
54 {
55         Footer* pFooter = GetFooter();
56         AppAssert(pFooter);
57
58         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
59         pFooter->SetBackButton();
60         pFooter->AddActionEventListener(*this);
61
62         SetFormBackEventListener(this);
63 }
64
65 result
66 ResetterForm::OnInitializing(void)
67 {
68         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_RESET"));
69         CreateFooter();
70         CreateTableView();
71
72         AppLogDebug("ENTER");
73
74         return E_SUCCESS;
75 }
76
77 result
78 ResetterForm::OnTerminating(void)
79 {
80         __pTableView = null;
81
82         SetFormBackEventListener(null);
83         return E_SUCCESS;
84 }
85
86 void
87 ResetterForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
88 {
89         __pTableView->UpdateTableView();
90 }
91
92 void
93 ResetterForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
94 {
95 }
96
97 void
98 ResetterForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
99 {
100         SceneManager* pSceneManager = SceneManager::GetInstance();
101         AppAssert(pSceneManager);
102
103         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
104 }
105
106 int
107 ResetterForm::GetGroupCount(void)
108 {
109         AppLogDebug("ENTER");
110         return ID_GROUP_COUNT;
111 }
112
113 int
114 ResetterForm::GetItemCount(int groupIndex)
115 {
116         int itemCount = 0;
117
118         switch (groupIndex)
119         {
120         case ID_GROUP_RESET_MAIN:
121                 {
122                         itemCount = ID_GROUP_RESET_MAIN_ITEM_COUNT;
123                 }
124                 break;
125
126         default:
127                 break;
128         }
129
130         AppLogDebug("GetItemCount %d", itemCount);
131         return itemCount;
132 }
133
134 TableViewGroupItem*
135 ResetterForm::CreateGroupItem(int groupIndex, int itemWidth)
136 {
137         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
138         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
139         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
140         Rectangle itemMainRectangle;
141         String groupText;
142         Label* pLabel = null;
143
144         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
145
146         switch (groupIndex)
147         {
148         case ID_GROUP_RESET_MAIN:
149                 {
150                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
151                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
152                 }
153                 break;
154
155         case ID_GROUP_RESET_MAIN_TEXT:
156                 {
157                         yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
158                         itemHeight = ((H_GROUP_INDEX_HELP_TEXT * LINE_COUNT_2) + H_GROUP_INDEX_NO_TITLE_TEXT_GAP);
159                         groupText = ResourceManager::GetString(L"IDS_ST_BODY_AFTER_RESETTING_PHONE_WILL_RESTART_AUTOMATICALLY");
160                 }
161                 break;
162
163         default:
164                 {
165                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
166                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
167                 }
168                 break;
169         }
170
171         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
172         itemMainRectangle.y = yItemOffset;
173         itemMainRectangle.width = itemWidth;
174         itemMainRectangle.height = itemHeight;
175
176         RelativeLayout relativeLayout;
177         relativeLayout.Construct();
178
179         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
180         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
181
182         pLabel = new (std::nothrow) Label();
183         pLabel->Construct(itemMainRectangle, groupText);
184         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
185         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
186         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
187         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
188
189         pItem->AddControl(pLabel);
190         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
191         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
192         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
193         pItem->SetEnabled(false);
194
195         return pItem;
196 }
197
198 TableViewItem*
199 ResetterForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
200 {
201         Rectangle itemMainRectangle;
202         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
203         String itemMainText;
204         Label* pLabel = null;
205         int fontSize = GetFontSize();
206
207         switch (groupIndex)
208         {
209         case ID_GROUP_RESET_MAIN:
210                 {
211                         switch (itemIndex)
212                         {
213                         case ID_ITEM_RESET_MAIN_RESET_SETTING:
214                                 {
215                                         itemMainText = ResourceManager::GetString(L"IDS_ST_HEADER_RESET_SETTINGS");
216                                 }
217                                 break;
218
219                         case ID_ITEM_RESET_MAIN_FACTORY_RESET:
220                                 {
221                                         itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_FACTORY_RESET");
222                                 }
223                                 break;
224
225                         default:
226                                 break;
227                         }
228                 }
229                 break;
230
231         default:
232                 break;
233         }
234
235         ItemTypeOneLine(itemMainRectangle);
236
237         TableViewItem* pItem = new (std::nothrow) TableViewItem();
238
239         RelativeLayout relativeLayout;
240         relativeLayout.Construct();
241
242         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
243         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
244
245         pLabel = new (std::nothrow) Label();
246         pLabel->Construct(itemMainRectangle, itemMainText);
247         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
248         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
249         pLabel->SetTextColor(COLOR_MAIN_TEXT);
250
251         pItem->AddControl(pLabel);
252         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
253         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
254         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
255
256         return pItem;
257 }
258
259 bool
260 ResetterForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
261 {
262         AppLogDebug("ENTER");
263
264         delete pItem;
265         pItem = null;
266
267         return true;
268 }
269
270 bool
271 ResetterForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
272 {
273         AppLogDebug("ENTER");
274
275         delete pItem;
276         pItem = null;
277
278         return true;
279 }
280
281 void
282 ResetterForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
283 {
284         SceneManager* pSceneManager = SceneManager::GetInstance();
285         AppAssert(pSceneManager);
286
287         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
288
289         switch (groupIndex)
290         {
291         case ID_GROUP_RESET_MAIN:
292                 {
293                         if (itemIndex == ID_ITEM_RESET_MAIN_RESET_SETTING)
294                         {
295                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_RESETTER_SETTING, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
296                         }
297
298                         if (itemIndex == ID_ITEM_RESET_MAIN_FACTORY_RESET)
299                         {
300                                 // TODO: make Factory reset sequence.
301                                 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
302                         }
303                 }
304                 break;
305
306         default:
307                 break;
308         }
309 }
310
311 int
312 ResetterForm::GetDefaultGroupItemHeight(void)
313 {
314         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
315 }
316
317 int
318 ResetterForm::GetDefaultItemHeight(void)
319 {
320         return H_GROUP_ITEM_DEFAULT;
321 }
322
323 void
324 ResetterForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
325 {
326 }
327
328 void
329 ResetterForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
330 {
331 }
332
333 void
334 ResetterForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
335 {
336 }
337
338 void
339 ResetterForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
340 {
341 }