Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / data / my_tools / jj / rsa / apps / osp / Settings / src / StCertificateUserInstallPasswordForm.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                StCertificateUserInstallPasswordForm.cpp
19  * @brief               This is the implementation file for CertificateUserInstallPasswordForm class.
20  */
21
22 #include "StCertificateUserInstallPasswordForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Utility;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Security;
31 using namespace Tizen::Security::Cert;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 static const int ID_GROUP_INSTALL_PASSWORD_MAIN = 0;
37 static const int ID_GROUP_INSTALL_PASSWORD_MAIN_ITEM_COUNT = 3;
38
39 static const int ID_ITEM_INSTALL_PASSWORD_INPUT = 0;
40 static const int ID_ITEM_INSTALL_PASSWORD_OK = 1;
41 static const int ID_ITEM_INSTALL_PASSWORD_CANCEL = 2;
42
43 static const int ID_GROUP_COUNT = 1;
44 static const int ID_GROUP_DEFAULT_ITEM_COUNT = ID_GROUP_INSTALL_PASSWORD_MAIN_ITEM_COUNT;
45
46 static const int IDA_PASSWORD_BUTTON_OK = 200;
47 static const int IDA_PASSWORD_BUTTON_CANCEL = 300;
48
49 static const int IDA_INSTALL_RESULT_SUCCESS = 210;
50 static const int IDA_INSTALL_RESULT_FAIL = 220;
51
52 static const int LIMIT_EDITFIELD = 100;
53 static const int ITEM_RECT_BUTTON_DEFAULT_X = 20;
54 static const int ITEM_RECT_BUTTON_DEFAULT_WIDTH_MULTIPLY = 2;
55 static const int ITEM_RECTANGLE_RESIZE_5 = 5;
56
57 static const int Y_INSERT_RESULT_POPUP_CLIENT_RECT = 160;
58 static const int H_INSERT_RESULT_POPUP_CLIENT_RECT = 380;
59 static const int W_INSERT_RESULT_POPUP_CLIENT_RECT = 700;
60
61 static const int H_INSERT_RESULT_POPUP_ITEM_RECT_LABEL = 340;
62 static const int X_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON = 180;
63 static const int Y_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON = 250;
64 static const int W_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON = 310;
65 static const int H_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON = 80;
66 static const int INSERT_RESULT_POPUP_FONT_SIZE = 40;
67
68 static const int W_ITEM_RESIZE_GAP = 16;
69
70 CertificateUserInstallPasswordForm::CertificateUserInstallPasswordForm(void)
71         : __pCertificatePresentationModelInstance(null)
72         , __pInstallFileName(null)
73         , __pEditField(null)
74         , __pInstallResultPopup(null)
75         , __pPassword(null)
76 {
77 }
78
79 CertificateUserInstallPasswordForm::~CertificateUserInstallPasswordForm(void)
80 {
81 }
82
83 void
84 CertificateUserInstallPasswordForm::CreateFooter(void)
85 {
86         Footer* pFooter = GetFooter();
87         AppAssert(pFooter);
88
89         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
90         pFooter->SetBackButton();
91         pFooter->AddActionEventListener(*this);
92
93         SetFormBackEventListener(this);
94 }
95
96 void
97 CertificateUserInstallPasswordForm::CreateTableView(void)
98 {
99         Rectangle tableViewBounds = GetClientAreaBounds();
100         tableViewBounds.y = Y_GROUP_DEFAULT;
101
102         __pTableView = new (std::nothrow) GroupedTableView();
103
104         __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_NONE);
105         __pTableView->SetItemProvider(this);
106
107         AddControl(*__pTableView);
108         __pTableView->SetGroupedLookEnabled(true);
109         __pTableView->AddGroupedTableViewItemEventListener(*this);
110         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
111         if (pRelativeLayout != null)
112         {
113                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
114                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
115                 delete pRelativeLayout;
116         }
117 }
118
119 result
120 CertificateUserInstallPasswordForm::OnInitializing(void)
121 {
122         CreateHeader(L"Certificate Detail");
123         CreateFooter();
124         CreateTableView();
125
126         result r = InitCertificatePresentationModelInstance();
127         if (IsFailed(r))
128         {
129                 return r;
130         }
131
132         return E_SUCCESS;
133 }
134
135 result
136 CertificateUserInstallPasswordForm::OnTerminating(void)
137 {
138         __pTableView->SetItemProvider(null);
139
140         ReleaseCertificatePresentationModelInstance();
141
142         delete __pInstallResultPopup;
143         __pInstallResultPopup = null;
144
145         SetFormBackEventListener(null);
146         return E_SUCCESS;
147 }
148
149 void
150 CertificateUserInstallPasswordForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
151 {
152         __pTableView->UpdateTableView();
153 }
154
155 void
156 CertificateUserInstallPasswordForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
157 {
158 }
159
160 void
161 CertificateUserInstallPasswordForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
162 {
163         SceneManager* pSceneManager = SceneManager::GetInstance();
164         AppAssert(pSceneManager);
165
166         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
167 }
168
169 int
170 CertificateUserInstallPasswordForm::GetGroupCount(void)
171 {
172         AppLogDebug("ENTER");
173         return ID_GROUP_COUNT;
174 }
175
176 int
177 CertificateUserInstallPasswordForm::GetItemCount(int groupIndex)
178 {
179         return ID_GROUP_DEFAULT_ITEM_COUNT;
180 }
181
182 TableViewGroupItem*
183 CertificateUserInstallPasswordForm::CreateGroupItem(int groupIndex, int itemWidth)
184 {
185         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
186         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
187         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
188         Rectangle itemRectangle;
189         String groupText = L"Enter password";
190         Label* pLabel = null;
191
192         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
193
194         yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
195         itemHeight = H_GROUP_INDEX_DEFAULT;
196
197         itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
198         itemRectangle.y = yItemOffset;
199         itemRectangle.width = itemWidth;
200         itemRectangle.height = itemHeight;
201
202         RelativeLayout relativeLayout;
203         relativeLayout.Construct();
204
205         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
206         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
207
208         pLabel = new (std::nothrow) Label();
209         pLabel->Construct(itemRectangle, groupText);
210         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
211         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
212         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
213         pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
214
215         pItem->AddControl(*pLabel);
216         relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
217         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
218         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
219         pItem->SetEnabled(false);
220
221         return pItem;
222 }
223
224 TableViewItem*
225 CertificateUserInstallPasswordForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
226 {
227         Rectangle itemRectangle;
228         Button* pButton = null;
229
230         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
231         String itemText;
232         String itemSecondText;
233
234         int fontSize = GetFontSize();
235         ItemTypeOneLine(itemRectangle);
236         int itemHeight = (itemRectangle.height);
237
238         itemRectangle.width = (itemWidth - W_ITEM_RESIZE_GAP);
239
240         TableViewItem* pItem = new (std::nothrow) TableViewItem();
241
242         RelativeLayout relativeLayout;
243         relativeLayout.Construct();
244
245         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
246         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
247
248         switch (itemIndex)
249         {
250         case ID_ITEM_INSTALL_PASSWORD_INPUT:
251                 {
252                         __pEditField = new (std::nothrow) EditField();
253                         __pEditField->Construct(itemRectangle, EDIT_FIELD_STYLE_PASSWORD, INPUT_STYLE_OVERLAY, EDIT_FIELD_TITLE_STYLE_NONE, false, LIMIT_EDITFIELD, GROUP_STYLE_SINGLE);
254                         __pEditField->SetTextSize(fontSize);
255                         __pEditField->SetTitleTextColor(EDIT_STATUS_NORMAL, COLOR_HELP_TEXT_TYPE_01);
256                         __pEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_BG_GROUP_INDEX_DEFAULT);
257                         __pEditField->SetColor(EDIT_STATUS_PRESSED, COLOR_BG_GROUP_INDEX_DEFAULT);
258                         __pEditField->SetColor(EDIT_STATUS_HIGHLIGHTED, COLOR_BG_GROUP_INDEX_DEFAULT);
259
260                         __pEditField->SetOverlayKeypadCommandButtonVisible(false);
261                         __pEditField->AddActionEventListener(*this);
262                         __pEditField->AddKeypadEventListener(*this);
263                         __pEditField->AddTextEventListener(*this);
264                         __pEditField->SetText(__pPassword);
265                         pItem->SetIndividualSelectionEnabled(__pEditField, true);
266                         pItem->AddControl(*__pEditField);
267                         relativeLayout.SetMargin(*__pEditField, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
268                         relativeLayout.SetRelation(*__pEditField, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
269                         relativeLayout.SetRelation(*__pEditField, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
270                 }
271                 break;
272
273         case ID_ITEM_INSTALL_PASSWORD_OK:
274                 {
275                         pButton = new (std::nothrow) Button();
276                         pButton->Construct(itemRectangle, ResourceManager::GetString(L"IDS_ST_BUTTON_OK"));
277                         pButton->SetActionId(IDA_PASSWORD_BUTTON_OK);
278                         pButton->AddActionEventListener(*this);
279
280                         pItem->SetIndividualSelectionEnabled(pButton, true);
281                         pItem->AddControl(*pButton);
282                         relativeLayout.SetMargin(*pButton, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
283                         relativeLayout.SetRelation(*pButton, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
284                         relativeLayout.SetRelation(*pButton, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
285                 }
286                 break;
287
288         case ID_ITEM_INSTALL_PASSWORD_CANCEL:
289                 {
290                         pButton = new (std::nothrow) Button();
291                         pButton->Construct(itemRectangle, ResourceManager::GetString(L"IDS_ST_BODY_CANCEL"));
292                         pButton->SetActionId(IDA_PASSWORD_BUTTON_CANCEL);
293                         pButton->AddActionEventListener(*this);
294
295                         pItem->SetIndividualSelectionEnabled(pButton, true);
296                         pItem->AddControl(*pButton);
297                         relativeLayout.SetMargin(*pButton, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
298                         relativeLayout.SetRelation(*pButton, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
299                         relativeLayout.SetRelation(*pButton, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
300                 }
301                 break;
302
303         default:
304                 break;
305         }
306         return pItem;
307 }
308
309 bool
310 CertificateUserInstallPasswordForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
311 {
312         AppLogDebug("ENTER");
313
314         delete pItem;
315         pItem = null;
316
317         return true;
318 }
319
320 bool
321 CertificateUserInstallPasswordForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
322 {
323         AppLogDebug("ENTER");
324
325         delete pItem;
326         pItem = null;
327
328         return true;
329 }
330
331 void
332 CertificateUserInstallPasswordForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
333 {
334         AppLogDebug("selectItem[%d][%d]", groupIndex, itemIndex);
335 }
336
337 int
338 CertificateUserInstallPasswordForm::GetDefaultGroupItemHeight(void)
339 {
340         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
341 }
342
343 int
344 CertificateUserInstallPasswordForm::GetDefaultItemHeight(void)
345 {
346         return H_GROUP_ITEM_DEFAULT;
347 }
348
349 void
350 CertificateUserInstallPasswordForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
351 {
352 }
353
354 void
355 CertificateUserInstallPasswordForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
356 {
357 }
358
359 void
360 CertificateUserInstallPasswordForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
361 {
362 }
363
364 void
365 CertificateUserInstallPasswordForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
366 {
367 }
368
369 void
370 CertificateUserInstallPasswordForm::OnActionPerformed(const Control& source, int actionId)
371 {
372         switch (actionId)
373         {
374         case IDA_PASSWORD_BUTTON_OK:
375                 {
376                         __pEditField->HideKeypad();
377                         __pEditField->Invalidate(false);
378
379                         if (__pInstallFileName == null)
380                         {
381                                 return;
382                         }
383
384                         String password = __pEditField->GetText();
385                         result r = __pCertificatePresentationModelInstance->InsertPkcs12FormatIntoCertificateStore(*__pInstallFileName, password);
386                         if (IsFailed(r))
387                         {
388                                 CreateUserInstallResultPopup(r);
389                                 ShowUserInstallResultPopup();
390                                 return;
391                         }
392
393                         //TODO : password Check...
394
395                         SceneManager* pSceneManager = SceneManager::GetInstance();
396                         AppAssert(pSceneManager);
397
398                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
399                 }
400                 break;
401
402         case IDA_PASSWORD_BUTTON_CANCEL:
403                 {
404                         SceneManager* pSceneManager = SceneManager::GetInstance();
405                         AppAssert(pSceneManager);
406
407                         String password = __pEditField->GetText();
408
409                         __pEditField->SetText(L"");
410                         __pPassword = L"";
411                         __pEditField->HideKeypad();
412                         __pEditField->Invalidate(false);
413
414                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
415                 }
416                 break;
417
418         case IDA_INSTALL_RESULT_SUCCESS:
419                 {
420                         HideUserInstallResultPopup();
421                 }
422                 break;
423
424         case IDA_INSTALL_RESULT_FAIL:
425                 {
426                         HideUserInstallResultPopup();
427                 }
428                 break;
429
430         default:
431                 break;
432         }
433 }
434
435 void
436 CertificateUserInstallPasswordForm::OnTextValueChanged(const Tizen::Ui::Control& source)
437 {
438         __pPassword = __pEditField->GetText();
439 }
440
441 void
442 CertificateUserInstallPasswordForm::OnKeypadClosed(Tizen::Ui::Control& source)
443 {
444         SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
445 }
446
447 void
448 CertificateUserInstallPasswordForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
449 {
450         SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
451 }
452
453 result
454 CertificateUserInstallPasswordForm::InitCertificatePresentationModelInstance(void)
455 {
456         __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
457         if (__pCertificatePresentationModelInstance == null)
458         {
459                 return E_FAILURE;
460         }
461
462         __pInstallFileName = __pCertificatePresentationModelInstance->PopPendingUserCertificateFileNameToInstallN();
463         if (__pInstallFileName == null)
464         {
465                 return E_FAILURE;
466         }
467
468         return E_SUCCESS;
469 }
470
471 void
472 CertificateUserInstallPasswordForm::ReleaseCertificatePresentationModelInstance(void)
473 {
474         __pCertificatePresentationModelInstance = null;
475 }
476
477 void
478 CertificateUserInstallPasswordForm::CreateUserInstallResultPopup(result r)
479 {
480         int buttonId = IDA_INSTALL_RESULT_FAIL;
481         String buttonText;
482         String popupText;
483         Label* pLabel = null;
484         Button* pLhsButton = null;
485
486         Rectangle clientRect = GetClientAreaBounds();
487         Rectangle itemRectLabel;
488         Rectangle itemRectLhsButton;
489         clientRect.x = 0;
490         clientRect.y = Y_INSERT_RESULT_POPUP_CLIENT_RECT;
491         clientRect.width = W_INSERT_RESULT_POPUP_CLIENT_RECT;
492         clientRect.height = H_INSERT_RESULT_POPUP_CLIENT_RECT;
493
494         itemRectLabel.x = 0;
495         itemRectLabel.y = 0;
496         itemRectLabel.width = clientRect.width;
497         itemRectLabel.height = H_INSERT_RESULT_POPUP_ITEM_RECT_LABEL;
498
499         itemRectLhsButton.x = X_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON;
500         itemRectLhsButton.y = Y_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON;
501         itemRectLhsButton.width = W_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON;
502         itemRectLhsButton.height = H_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON;
503
504         Dimension bounds = Dimension(clientRect.width, clientRect.height);
505
506         __pInstallResultPopup = new (std::nothrow) Popup();
507         __pInstallResultPopup->Construct(false, bounds);
508         __pInstallResultPopup->SetTitleTextColor(COLOR_SUB_TEXT);
509
510         buttonId = IDA_INSTALL_RESULT_FAIL;
511         popupText = ResourceManager::GetString(L"IDS_ST_BODY_INCORRECT_PASSWORD");
512
513         pLabel = new (std::nothrow) Label();
514         pLabel->Construct(itemRectLabel, popupText);
515         pLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
516         pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
517         pLabel->SetTextConfig(INSERT_RESULT_POPUP_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
518         __pInstallResultPopup->AddControl(*pLabel);
519
520         buttonText = ResourceManager::GetString(L"IDS_ST_BUTTON_OK");
521         pLhsButton = new (std::nothrow) Button();
522         pLhsButton->Construct(itemRectLhsButton, buttonText);
523         pLhsButton->SetActionId(buttonId);
524         pLhsButton->AddActionEventListener(*this);
525
526         __pInstallResultPopup->AddControl(*pLhsButton);
527 }
528
529 void
530 CertificateUserInstallPasswordForm::ShowUserInstallResultPopup(void)
531 {
532         __pInstallResultPopup->SetShowState(true);
533         __pInstallResultPopup->Show();
534 }
535
536 void
537 CertificateUserInstallPasswordForm::HideUserInstallResultPopup(void)
538 {
539         __pInstallResultPopup->SetShowState(false);
540         Invalidate(true);
541 }