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