2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
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(ResourceManager::GetString(L"IDS_ST_BODY_PASSWORD"));
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 itemMainRectangle;
189 String groupText = ResourceManager::GetString(L"IDS_WIFI_BODY_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 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
198 itemMainRectangle.y = yItemOffset;
199 itemMainRectangle.width = itemWidth;
200 itemMainRectangle.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(itemMainRectangle, 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, itemMainRectangle.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 itemMainRectangle;
228 Button* pButton = null;
230 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
231 int fontSize = GetFontSize();
232 ItemTypeOneLine(itemMainRectangle);
233 int itemHeight = (itemMainRectangle.height);
235 itemMainRectangle.width = (itemWidth - W_ITEM_RESIZE_GAP);
237 TableViewItem* pItem = new (std::nothrow) TableViewItem();
239 RelativeLayout relativeLayout;
240 relativeLayout.Construct();
242 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
243 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
247 case ID_ITEM_INSTALL_PASSWORD_INPUT:
249 __pEditField = new (std::nothrow) EditField();
250 __pEditField->Construct(itemMainRectangle, EDIT_FIELD_STYLE_PASSWORD, INPUT_STYLE_OVERLAY, EDIT_FIELD_TITLE_STYLE_NONE, false, LIMIT_EDITFIELD, GROUP_STYLE_SINGLE);
251 __pEditField->SetTextSize(fontSize);
252 __pEditField->SetTitleTextColor(EDIT_STATUS_NORMAL, COLOR_HELP_TEXT_TYPE_01);
253 __pEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_BG_GROUP_INDEX_DEFAULT);
254 __pEditField->SetColor(EDIT_STATUS_PRESSED, COLOR_BG_GROUP_INDEX_DEFAULT);
255 __pEditField->SetColor(EDIT_STATUS_HIGHLIGHTED, COLOR_BG_GROUP_INDEX_DEFAULT);
257 __pEditField->SetOverlayKeypadCommandButtonVisible(false);
258 __pEditField->AddActionEventListener(*this);
259 __pEditField->AddKeypadEventListener(*this);
260 __pEditField->AddTextEventListener(*this);
261 __pEditField->SetText(__pPassword);
262 pItem->SetIndividualSelectionEnabled(__pEditField, true);
263 pItem->AddControl(__pEditField);
264 relativeLayout.SetMargin(*__pEditField, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
265 relativeLayout.SetRelation(*__pEditField, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
266 relativeLayout.SetRelation(*__pEditField, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
270 case ID_ITEM_INSTALL_PASSWORD_OK:
272 pButton = new (std::nothrow) Button();
273 pButton->Construct(itemMainRectangle, ResourceManager::GetString(L"IDS_ST_BUTTON_OK"));
274 pButton->SetActionId(IDA_PASSWORD_BUTTON_OK);
275 pButton->AddActionEventListener(*this);
277 pItem->SetIndividualSelectionEnabled(pButton, true);
278 pItem->AddControl(pButton);
279 relativeLayout.SetMargin(*pButton, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
280 relativeLayout.SetRelation(*pButton, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
281 relativeLayout.SetRelation(*pButton, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
285 case ID_ITEM_INSTALL_PASSWORD_CANCEL:
287 pButton = new (std::nothrow) Button();
288 pButton->Construct(itemMainRectangle, ResourceManager::GetString(L"IDS_ST_BODY_CANCEL"));
289 pButton->SetActionId(IDA_PASSWORD_BUTTON_CANCEL);
290 pButton->AddActionEventListener(*this);
292 pItem->SetIndividualSelectionEnabled(pButton, true);
293 pItem->AddControl(pButton);
294 relativeLayout.SetMargin(*pButton, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
295 relativeLayout.SetRelation(*pButton, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
296 relativeLayout.SetRelation(*pButton, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
307 CertificateUserInstallPasswordForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
309 AppLogDebug("ENTER");
318 CertificateUserInstallPasswordForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
320 AppLogDebug("ENTER");
329 CertificateUserInstallPasswordForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
331 AppLogDebug("selectItem[%d][%d]", groupIndex, itemIndex);
335 CertificateUserInstallPasswordForm::GetDefaultGroupItemHeight(void)
337 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
341 CertificateUserInstallPasswordForm::GetDefaultItemHeight(void)
343 return H_GROUP_ITEM_DEFAULT;
347 CertificateUserInstallPasswordForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
352 CertificateUserInstallPasswordForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
357 CertificateUserInstallPasswordForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
362 CertificateUserInstallPasswordForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
367 CertificateUserInstallPasswordForm::OnActionPerformed(const Control& source, int actionId)
371 case IDA_PASSWORD_BUTTON_OK:
373 __pEditField->HideKeypad();
374 __pEditField->Invalidate(false);
376 if (__pInstallFileName == null)
381 String password = __pEditField->GetText();
382 result r = __pCertificatePresentationModelInstance->InsertPkcs12FormatIntoCertificateStore(*__pInstallFileName, password);
385 CreateUserInstallResultPopup(r);
386 ShowUserInstallResultPopup();
390 //TODO : password Check...
392 SceneManager* pSceneManager = SceneManager::GetInstance();
393 AppAssert(pSceneManager);
395 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
399 case IDA_PASSWORD_BUTTON_CANCEL:
401 SceneManager* pSceneManager = SceneManager::GetInstance();
402 AppAssert(pSceneManager);
404 String password = __pEditField->GetText();
406 __pEditField->SetText(L"");
408 __pEditField->HideKeypad();
409 __pEditField->Invalidate(false);
411 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
415 case IDA_INSTALL_RESULT_SUCCESS:
417 HideUserInstallResultPopup();
421 case IDA_INSTALL_RESULT_FAIL:
423 HideUserInstallResultPopup();
433 CertificateUserInstallPasswordForm::OnTextValueChanged(const Tizen::Ui::Control& source)
435 __pPassword = __pEditField->GetText();
439 CertificateUserInstallPasswordForm::InitCertificatePresentationModelInstance(void)
441 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
442 if (__pCertificatePresentationModelInstance == null)
447 __pInstallFileName = __pCertificatePresentationModelInstance->PopPendingUserCertificateFileNameToInstallN();
448 if (__pInstallFileName == null)
457 CertificateUserInstallPasswordForm::ReleaseCertificatePresentationModelInstance(void)
459 __pCertificatePresentationModelInstance = null;
463 CertificateUserInstallPasswordForm::CreateUserInstallResultPopup(result r)
465 int buttonId = IDA_INSTALL_RESULT_FAIL;
468 Label* pLabel = null;
469 Button* pLhsButton = null;
471 Rectangle clientRect = GetClientAreaBounds();
472 Rectangle itemRectLabel;
473 Rectangle itemRectLhsButton;
475 clientRect.y = Y_INSERT_RESULT_POPUP_CLIENT_RECT;
476 clientRect.width = W_INSERT_RESULT_POPUP_CLIENT_RECT;
477 clientRect.height = H_INSERT_RESULT_POPUP_CLIENT_RECT;
481 itemRectLabel.width = clientRect.width;
482 itemRectLabel.height = H_INSERT_RESULT_POPUP_ITEM_RECT_LABEL;
484 itemRectLhsButton.x = X_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON;
485 itemRectLhsButton.y = Y_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON;
486 itemRectLhsButton.width = W_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON;
487 itemRectLhsButton.height = H_INSERT_RESULT_POPUP_ITEM_RECT_LHS_BUTTON;
489 Dimension bounds = Dimension(clientRect.width, clientRect.height);
491 __pInstallResultPopup = new (std::nothrow) Popup();
492 __pInstallResultPopup->Construct(false, bounds);
493 __pInstallResultPopup->SetTitleTextColor(COLOR_SUB_TEXT);
495 buttonId = IDA_INSTALL_RESULT_FAIL;
496 popupText = ResourceManager::GetString(L"IDS_COM_POP_FAILED");
498 pLabel = new (std::nothrow) Label();
499 pLabel->Construct(itemRectLabel, popupText);
500 pLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
501 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
502 pLabel->SetTextConfig(INSERT_RESULT_POPUP_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
503 __pInstallResultPopup->AddControl(pLabel);
505 buttonText = ResourceManager::GetString(L"IDS_ST_BUTTON_OK");
506 pLhsButton = new (std::nothrow) Button();
507 pLhsButton->Construct(itemRectLhsButton, buttonText);
508 pLhsButton->SetActionId(buttonId);
509 pLhsButton->AddActionEventListener(*this);
511 __pInstallResultPopup->AddControl(pLhsButton);
515 CertificateUserInstallPasswordForm::ShowUserInstallResultPopup(void)
517 __pInstallResultPopup->SetShowState(true);
518 __pInstallResultPopup->Show();
522 CertificateUserInstallPasswordForm::HideUserInstallResultPopup(void)
524 __pInstallResultPopup->SetShowState(false);