2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file StCertificateUserInstallPasswordForm.cpp
19 * @brief This is the implementation file for CertificateUserInstallPasswordForm class.
22 #include "StCertificateUserInstallPasswordForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
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;
36 static const int ID_GROUP_INSTALL_PASSWORD_MAIN = 0;
37 static const int ID_GROUP_INSTALL_PASSWORD_MAIN_ITEM_COUNT = 3;
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;
43 static const int ID_GROUP_COUNT = 1;
44 static const int ID_GROUP_DEFAULT_ITEM_COUNT = ID_GROUP_INSTALL_PASSWORD_MAIN_ITEM_COUNT;
46 static const int IDA_PASSWORD_BUTTON_OK = 200;
47 static const int IDA_PASSWORD_BUTTON_CANCEL = 300;
49 static const int IDA_INSTALL_RESULT_SUCCESS = 210;
50 static const int IDA_INSTALL_RESULT_FAIL = 220;
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;
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;
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;
68 static const int W_ITEM_RESIZE_GAP = 16;
70 CertificateUserInstallPasswordForm::CertificateUserInstallPasswordForm(void)
71 : __pCertificatePresentationModelInstance(null)
72 , __pInstallFileName(null)
74 , __pInstallResultPopup(null)
79 CertificateUserInstallPasswordForm::~CertificateUserInstallPasswordForm(void)
84 CertificateUserInstallPasswordForm::CreateFooter(void)
86 Footer* pFooter = GetFooter();
89 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
90 pFooter->SetBackButton();
91 pFooter->AddActionEventListener(*this);
93 SetFormBackEventListener(this);
97 CertificateUserInstallPasswordForm::CreateTableView(void)
99 Rectangle tableViewBounds = GetClientAreaBounds();
100 tableViewBounds.y = Y_GROUP_DEFAULT;
102 __pTableView = new (std::nothrow) GroupedTableView();
104 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_NONE);
105 __pTableView->SetItemProvider(this);
107 AddControl(*__pTableView);
108 __pTableView->SetGroupedLookEnabled(true);
109 __pTableView->AddGroupedTableViewItemEventListener(*this);
110 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
111 if (pRelativeLayout != null)
113 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
114 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
115 delete pRelativeLayout;
120 CertificateUserInstallPasswordForm::OnInitializing(void)
122 CreateHeader(L"Certificate Detail");
126 result r = InitCertificatePresentationModelInstance();
136 CertificateUserInstallPasswordForm::OnTerminating(void)
138 __pTableView->SetItemProvider(null);
140 ReleaseCertificatePresentationModelInstance();
142 delete __pInstallResultPopup;
143 __pInstallResultPopup = null;
145 SetFormBackEventListener(null);
150 CertificateUserInstallPasswordForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
152 __pTableView->UpdateTableView();
156 CertificateUserInstallPasswordForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
161 CertificateUserInstallPasswordForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
163 SceneManager* pSceneManager = SceneManager::GetInstance();
164 AppAssert(pSceneManager);
166 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
170 CertificateUserInstallPasswordForm::GetGroupCount(void)
172 AppLogDebug("ENTER");
173 return ID_GROUP_COUNT;
177 CertificateUserInstallPasswordForm::GetItemCount(int groupIndex)
179 return ID_GROUP_DEFAULT_ITEM_COUNT;
183 CertificateUserInstallPasswordForm::CreateGroupItem(int groupIndex, int itemWidth)
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;
192 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
194 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
195 itemHeight = H_GROUP_INDEX_DEFAULT;
197 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
198 itemRectangle.y = yItemOffset;
199 itemRectangle.width = itemWidth;
200 itemRectangle.height = itemHeight;
202 RelativeLayout relativeLayout;
203 relativeLayout.Construct();
205 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
206 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
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);
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);
225 CertificateUserInstallPasswordForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
227 Rectangle itemRectangle;
228 Button* pButton = null;
230 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
232 String itemSecondText;
234 int fontSize = GetFontSize();
235 ItemTypeOneLine(itemRectangle);
236 int itemHeight = (itemRectangle.height);
238 itemRectangle.width = (itemWidth - W_ITEM_RESIZE_GAP);
240 TableViewItem* pItem = new (std::nothrow) TableViewItem();
242 RelativeLayout relativeLayout;
243 relativeLayout.Construct();
245 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
246 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
250 case ID_ITEM_INSTALL_PASSWORD_INPUT:
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);
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);
273 case ID_ITEM_INSTALL_PASSWORD_OK:
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);
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);
288 case ID_ITEM_INSTALL_PASSWORD_CANCEL:
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);
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);
310 CertificateUserInstallPasswordForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
312 AppLogDebug("ENTER");
321 CertificateUserInstallPasswordForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
323 AppLogDebug("ENTER");
332 CertificateUserInstallPasswordForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
334 AppLogDebug("selectItem[%d][%d]", groupIndex, itemIndex);
338 CertificateUserInstallPasswordForm::GetDefaultGroupItemHeight(void)
340 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
344 CertificateUserInstallPasswordForm::GetDefaultItemHeight(void)
346 return H_GROUP_ITEM_DEFAULT;
350 CertificateUserInstallPasswordForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
355 CertificateUserInstallPasswordForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
360 CertificateUserInstallPasswordForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
365 CertificateUserInstallPasswordForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
370 CertificateUserInstallPasswordForm::OnActionPerformed(const Control& source, int actionId)
374 case IDA_PASSWORD_BUTTON_OK:
376 __pEditField->HideKeypad();
377 __pEditField->Invalidate(false);
379 if (__pInstallFileName == null)
384 String password = __pEditField->GetText();
385 result r = __pCertificatePresentationModelInstance->InsertPkcs12FormatIntoCertificateStore(*__pInstallFileName, password);
388 CreateUserInstallResultPopup(r);
389 ShowUserInstallResultPopup();
393 //TODO : password Check...
395 SceneManager* pSceneManager = SceneManager::GetInstance();
396 AppAssert(pSceneManager);
398 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
402 case IDA_PASSWORD_BUTTON_CANCEL:
404 SceneManager* pSceneManager = SceneManager::GetInstance();
405 AppAssert(pSceneManager);
407 String password = __pEditField->GetText();
409 __pEditField->SetText(L"");
411 __pEditField->HideKeypad();
412 __pEditField->Invalidate(false);
414 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
418 case IDA_INSTALL_RESULT_SUCCESS:
420 HideUserInstallResultPopup();
424 case IDA_INSTALL_RESULT_FAIL:
426 HideUserInstallResultPopup();
436 CertificateUserInstallPasswordForm::OnTextValueChanged(const Tizen::Ui::Control& source)
438 __pPassword = __pEditField->GetText();
442 CertificateUserInstallPasswordForm::OnKeypadClosed(Tizen::Ui::Control& source)
444 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
448 CertificateUserInstallPasswordForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
450 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
454 CertificateUserInstallPasswordForm::InitCertificatePresentationModelInstance(void)
456 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
457 if (__pCertificatePresentationModelInstance == null)
462 __pInstallFileName = __pCertificatePresentationModelInstance->PopPendingUserCertificateFileNameToInstallN();
463 if (__pInstallFileName == null)
472 CertificateUserInstallPasswordForm::ReleaseCertificatePresentationModelInstance(void)
474 __pCertificatePresentationModelInstance = null;
478 CertificateUserInstallPasswordForm::CreateUserInstallResultPopup(result r)
480 int buttonId = IDA_INSTALL_RESULT_FAIL;
483 Label* pLabel = null;
484 Button* pLhsButton = null;
486 Rectangle clientRect = GetClientAreaBounds();
487 Rectangle itemRectLabel;
488 Rectangle itemRectLhsButton;
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;
496 itemRectLabel.width = clientRect.width;
497 itemRectLabel.height = H_INSERT_RESULT_POPUP_ITEM_RECT_LABEL;
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;
504 Dimension bounds = Dimension(clientRect.width, clientRect.height);
506 __pInstallResultPopup = new (std::nothrow) Popup();
507 __pInstallResultPopup->Construct(false, bounds);
508 __pInstallResultPopup->SetTitleTextColor(COLOR_SUB_TEXT);
510 buttonId = IDA_INSTALL_RESULT_FAIL;
511 popupText = ResourceManager::GetString(L"IDS_ST_BODY_INCORRECT_PASSWORD");
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);
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);
526 __pInstallResultPopup->AddControl(*pLhsButton);
530 CertificateUserInstallPasswordForm::ShowUserInstallResultPopup(void)
532 __pInstallResultPopup->SetShowState(true);
533 __pInstallResultPopup->Show();
537 CertificateUserInstallPasswordForm::HideUserInstallResultPopup(void)
539 __pInstallResultPopup->SetShowState(false);