Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StSecurityForm.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                StSecurityForm.cpp
19  * @brief               This is the implementation file for SecurityForm class.
20  */
21
22 #include "StResourceManager.h"
23 #include "StSecurityForm.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_SECURITY_SCREEN_SECURITY = 0;
34 static const int ID_GROUP_SECURITY_SCREEN_SECURITY_ITEM_COUNT = 2;
35 static const int ID_ITEM_SECURITY_SCREEN_LOCK_TYPE = 0;
36 static const int ID_ITEM_SECURITY_SCREEN_LOCK_SCREEN_OPTION = 1;
37
38 static const int ID_GROUP_SECURITY_PHONE_SECURITY = 1;
39 static const int ID_GROUP_SECURITY_PHONE_SECURITY_ITEM_COUNT = 1;
40 static const int ID_ITEM_SECURITY_PHONE_SECURITY = 0;
41
42 static const int ID_GROUP_SECURITY_SIM = 2;
43 static const int ID_GROUP_SECURITY_SIM_ITEM_COUNT = 1;
44 static const int ID_ITEM_SECURITY_SIM_LOCK = 0;
45
46 static const int ID_GROUP_SECURITY_PIN = 3;
47 static const int ID_GROUP_SECURITY_PIN_ITEM_COUNT = 3;
48 static const int ID_ITEM_SECURITY_PIN_LOCK = 0;
49 static const int ID_ITEM_SECURITY_CHANGE_PIN_1 = 1;
50 static const int ID_ITEM_SECURITY_CHANGE_PIN_2 = 2;
51
52 static const int ID_GROUP_SECURITY_DEVICE = 4;
53 static const int ID_GROUP_SECURITY_DEVICE_ITEM_COUNT = 1;
54 static const int ID_ITEM_SECURITY_DEVICE_ENCRYPTION = 0;
55
56 static const int ID_GROUP_SECURITY_PASSWORD_HELP_TEXT = 5;
57
58 static const int ID_GROUP_COUNT = 6;
59 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_SECURITY_PIN_ITEM_COUNT;
60
61 SecurityForm::SecurityForm(void)
62 {
63 }
64
65 SecurityForm::~SecurityForm(void)
66 {
67 }
68
69 void
70 SecurityForm::CreateFooter(void)
71 {
72         Footer* pFooter = GetFooter();
73         AppAssert(pFooter);
74
75         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
76         pFooter->SetBackButton();
77         pFooter->AddActionEventListener(*this);
78
79         SetFormBackEventListener(this);
80 }
81
82 result
83 SecurityForm::OnInitializing(void)
84 {
85         CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_SECURITY"));
86         CreateFooter();
87         CreateTableView();
88
89         AppLogDebug("ENTER");
90
91         return E_SUCCESS;
92 }
93
94 result
95 SecurityForm::OnTerminating(void)
96 {
97         __pTableView = null;
98
99         SetFormBackEventListener(null);
100         return E_SUCCESS;
101 }
102
103 void
104 SecurityForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
105 {
106         __pTableView->UpdateTableView();
107 }
108
109 void
110 SecurityForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
111 {
112 }
113
114 void
115 SecurityForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
116 {
117         SceneManager* pSceneManager = SceneManager::GetInstance();
118         AppAssert(pSceneManager);
119
120         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
121 }
122
123 int
124 SecurityForm::GetGroupCount(void)
125 {
126         AppLogDebug("ENTER");
127         return ID_GROUP_COUNT;
128 }
129
130 int
131 SecurityForm::GetItemCount(int groupIndex)
132 {
133         int itemCount = 0;
134
135         switch (groupIndex)
136         {
137         case ID_GROUP_SECURITY_SCREEN_SECURITY:
138                 {
139                         itemCount = ID_GROUP_SECURITY_SCREEN_SECURITY_ITEM_COUNT;
140                 }
141                 break;
142
143         case ID_GROUP_SECURITY_PHONE_SECURITY:
144                 {
145                         itemCount = ID_GROUP_SECURITY_PHONE_SECURITY_ITEM_COUNT;
146                 }
147                 break;
148
149         case ID_GROUP_SECURITY_SIM:
150                 {
151                         itemCount = ID_GROUP_SECURITY_SIM_ITEM_COUNT;
152                 }
153                 break;
154
155         case ID_GROUP_SECURITY_PIN:
156                 {
157                         itemCount = ID_GROUP_SECURITY_PIN_ITEM_COUNT;
158                 }
159                 break;
160
161         case ID_GROUP_SECURITY_DEVICE:
162                 {
163                         itemCount = ID_GROUP_SECURITY_DEVICE_ITEM_COUNT;
164                 }
165                 break;
166
167         default:
168                 break;
169         }
170
171         AppLogDebug("GetItemCount %d", itemCount);
172         return itemCount;
173 }
174
175 TableViewGroupItem*
176 SecurityForm::CreateGroupItem(int groupIndex, int itemWidth)
177 {
178         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
179         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
180         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
181         Color colorText = COLOR_HELP_TEXT_TYPE_01;
182         Rectangle itemMainRectangle;
183         String groupText;
184         Label* pLabel = null;
185
186         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
187
188         switch (groupIndex)
189         {
190         case ID_GROUP_SECURITY_SCREEN_SECURITY:
191                 {
192                         style = LABEL_TEXT_STYLE_BOLD;
193                         colorText = COLOR_GROUP_TITLE_TEXT;
194                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
195                         itemHeight = H_GROUP_INDEX_DEFAULT;
196                         groupText = ResourceManager::GetString(L"IDS_ST_HEADER_SCREEN_SECURITY");
197                 }
198                 break;
199
200         case ID_GROUP_SECURITY_PHONE_SECURITY:
201                 {
202                         style = LABEL_TEXT_STYLE_BOLD;
203                         colorText = COLOR_GROUP_TITLE_TEXT;
204                         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
205                         itemHeight = H_GROUP_INDEX_DEFAULT;
206                         groupText = ResourceManager::GetString(L"IDS_ST_BODY_PHONE_SECURITY");
207                 }
208                 break;
209
210         case ID_GROUP_SECURITY_SIM:
211                 {
212                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
213                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
214                         groupText = L"";
215                 }
216                 break;
217
218         case ID_GROUP_SECURITY_PIN:
219                 {
220                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
221                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
222                         groupText = L"";
223                 }
224                 break;
225
226         case ID_GROUP_SECURITY_DEVICE:
227                 {
228                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
229                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
230                         groupText = L"";
231                 }
232                 break;
233
234         case ID_GROUP_SECURITY_PASSWORD_HELP_TEXT:
235                 {
236                         style = LABEL_TEXT_STYLE_NORMAL;
237                         colorText = COLOR_HELP_TEXT_TYPE_01;
238                         yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
239                         itemHeight = ((H_GROUP_INDEX_HELP_TEXT * LINE_COUNT_2) + H_GROUP_INDEX_NO_TITLE_TEXT_GAP);
240                         groupText = ResourceManager::GetString(L"IDS_SECURITY_DEVICE_ENCRYPTION_HELP");
241                 }
242                 break;
243
244         default:
245                 {
246                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
247                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
248                         groupText = L"";
249                 }
250                 break;
251         }
252
253         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
254         itemMainRectangle.y = yItemOffset;
255         itemMainRectangle.width = itemWidth;
256         itemMainRectangle.height = itemHeight;
257
258         RelativeLayout relativeLayout;
259         relativeLayout.Construct();
260
261         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
262         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
263
264         pLabel = new (std::nothrow) Label();
265         pLabel->Construct(itemMainRectangle, groupText);
266         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
267         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
268         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
269         pLabel->SetTextColor(colorText);
270
271         pItem->AddControl(pLabel);
272         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
273         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
274         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
275         pItem->SetEnabled(false);
276
277         return pItem;
278 }
279
280 TableViewItem*
281 SecurityForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
282 {
283         Rectangle itemMainRectangle;
284         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
285         Label* pLabel = null;
286         String itemMainText;
287         int fontSize = GetFontSize();
288
289         TableViewItem* pItem = new (std::nothrow) TableViewItem();
290
291         switch (groupIndex)
292         {
293         case ID_GROUP_SECURITY_SCREEN_SECURITY:
294                 {
295                         switch (itemIndex)
296                         {
297                         case ID_ITEM_SECURITY_SCREEN_LOCK_TYPE:
298                                 {
299                                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SCREEN_LOCK_TYPE");
300                                 }
301                                 break;
302
303                         case ID_ITEM_SECURITY_SCREEN_LOCK_SCREEN_OPTION:
304                                 {
305                                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_LOCK_SCREEN_OPTIONS");
306                                 }
307                                 break;
308
309                         default:
310                                 break;
311                         }
312                 }
313                 break;
314
315         case ID_GROUP_SECURITY_PHONE_SECURITY:
316                 {
317                         itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_FIND_MY_MOBILE");
318                 }
319                 break;
320
321         case ID_GROUP_SECURITY_SIM:
322                 {
323                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SIM_LOCK");
324                         if (itemIndex == ID_ITEM_SECURITY_PIN_LOCK)
325                         {
326                                 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
327                         }
328                 }
329                 break;
330
331         case ID_GROUP_SECURITY_PIN:
332                 {
333                         switch (itemIndex)
334                         {
335                         case ID_ITEM_SECURITY_PIN_LOCK:
336                                 {
337                                         style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
338                                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_PIN_LOCK");
339                                 }
340                                 break;
341
342                         case ID_ITEM_SECURITY_CHANGE_PIN_1:
343                                 {
344                                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CHANGE_PIN1");
345                                 }
346                                 break;
347
348                         case ID_ITEM_SECURITY_CHANGE_PIN_2:
349                                 {
350                                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CHANGE_PIN2");
351                                 }
352                                 break;
353
354                         default:
355                                 break;
356                         }
357                 }
358                 break;
359
360         case ID_GROUP_SECURITY_DEVICE:
361                 {
362                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DEVICE_ENCRYPTED");
363                 }
364                 break;
365
366         default:
367                 break;
368         }
369
370         ItemTypeOneLine(itemMainRectangle);
371
372         RelativeLayout relativeLayout;
373         relativeLayout.Construct();
374
375         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
376         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
377
378         pLabel = new (std::nothrow) Label();
379         pLabel->Construct(itemMainRectangle, itemMainText);
380         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
381         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
382         pLabel->SetTextColor(COLOR_MAIN_TEXT);
383
384         pItem->AddControl(pLabel);
385
386         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
387         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
388         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
389
390         return pItem;
391 }
392
393 bool
394 SecurityForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
395 {
396         AppLogDebug("ENTER");
397
398         delete pItem;
399         pItem = null;
400
401         return true;
402 }
403
404 bool
405 SecurityForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
406 {
407         AppLogDebug("ENTER");
408
409         delete pItem;
410         pItem = null;
411
412         return true;
413 }
414
415 void
416 SecurityForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
417 {
418         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
419
420         switch (groupIndex)
421         {
422         case ID_GROUP_SECURITY_SCREEN_SECURITY:
423                 {
424                         ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
425
426                         if (itemIndex == ID_GROUP_SECURITY_SCREEN_SECURITY)
427                         {
428                                 // Empty statement
429                         }
430                         if (itemIndex == ID_ITEM_SECURITY_SCREEN_LOCK_SCREEN_OPTION)
431                         {
432                                 // Empty statement
433                         }
434                 }
435                 break;
436
437         case ID_GROUP_SECURITY_PHONE_SECURITY:
438                 {
439                         ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
440
441                         if (itemIndex == ID_ITEM_SECURITY_PHONE_SECURITY)
442                         {
443                                 // TODO: make scene or call appControl. Find my mobile ?
444                                 // Empty statement
445                         }
446                 }
447                 break;
448
449         case ID_GROUP_SECURITY_SIM:
450                 {
451                         if (itemIndex == ID_ITEM_SECURITY_SIM_LOCK)
452                         {
453                                 // TODO: make scene or call appControl. SIM Lock.
454                                 // Empty statement
455                         }
456                 }
457                 break;
458
459         case ID_GROUP_SECURITY_PIN:
460                 {
461                         ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
462
463                         if (itemIndex == ID_ITEM_SECURITY_PIN_LOCK)
464                         {
465                                 // TODO: PIN lock
466                                 // Empty statement
467                         }
468                         if (itemIndex == ID_ITEM_SECURITY_CHANGE_PIN_1)
469                         {
470                                 // TODO: change pin 1 ?
471                                 // Empty statement
472                         }
473                         if (itemIndex == ID_ITEM_SECURITY_CHANGE_PIN_2)
474                         {
475                                 // TODO: change pin 2 ?
476                                 // Empty statement
477                         }
478                 }
479                 break;
480
481         case ID_GROUP_SECURITY_DEVICE:
482                 {
483                         ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
484
485                         if (itemIndex == ID_ITEM_SECURITY_DEVICE_ENCRYPTION)
486                         {
487                                 // TODO: Device encryption ?
488                                 // Empty statement
489                         }
490                 }
491                 break;
492
493         default:
494                 break;
495         }
496 }
497
498 int
499 SecurityForm::GetDefaultGroupItemHeight(void)
500 {
501         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
502 }
503
504 int
505 SecurityForm::GetDefaultItemHeight(void)
506 {
507         return H_GROUP_ITEM_DEFAULT;
508 }
509
510 void
511 SecurityForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
512 {
513 }
514
515 void
516 SecurityForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
517 {
518 }
519
520 void
521 SecurityForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
522 {
523 }
524
525 void
526 SecurityForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
527 {
528 }