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 StCertificateUserForm.cpp
19 * @brief This is the implementation file for CertificateUserForm class.
22 #include "StCertificateUserForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Security::Cert;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
34 static const int IDA_CERTIFICATE_USER_FORM_FOOTER_BASE = 100;
35 static const int IDA_CERTIFICATE_USER_FORM_FOOTER_INSTALL = IDA_CERTIFICATE_USER_FORM_FOOTER_BASE + 1;
36 static const int IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL = IDA_CERTIFICATE_USER_FORM_FOOTER_BASE + 2;
37 static const int ID_CERTIFICATE_USER_FORM_FOOTER_INSTALL = 0;
38 static const int ID_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL = 1;
40 static const int ID_GROUP_COUNT = 1;
42 static const int IDA_SD_INSTALL_POPUP_OK = 200;
43 static const int IDA_SD_INSTALL_POPUP_CANCEL = 300;
45 static const int Y_ALERT_POPUP_CLIENT_RECT_DEFAULT = 50;
46 static const int H_ALERT_POPUP_CLIENT_RECT_RESIZE = 470;
47 static const int W_ALERT_POPUP_CLIENT_RECT_RESIZE = 720;
48 static const int Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 20;
49 static const int H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 340;
50 static const int X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 20;
51 static const int Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 350;
52 static const int W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 310;
53 static const int H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 80;
54 static const int X_ALERT_POPUP_ITEM_RECT_RHS_BUTTON_RESIZE = 20;
56 static const int ALERT_POPUP_LABEL_FONT_SIZE = 40;
58 CertificateUserForm::CertificateUserForm(void)
59 : __pCertificatePresentationModelInstance(null)
60 , __installFromSDCardPopup(null)
61 , __isPopupVisible(false)
65 CertificateUserForm::~CertificateUserForm(void)
70 CertificateUserForm::CreateFooter(void)
72 Footer* pFooter = GetFooter();
75 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
77 FooterItem footerInstall;
78 FooterItem footerUninstall;
79 footerInstall.Construct(IDA_CERTIFICATE_USER_FORM_FOOTER_INSTALL);
80 footerInstall.SetText(ResourceManager::GetString(L"IDS_ST_BUTTON_INSTALL"));
81 footerUninstall.Construct(IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL);
82 footerUninstall.SetText(ResourceManager::GetString(L"IDS_ST_BUTTON_UNINSTALL"));
83 pFooter->AddItem(footerInstall);
84 pFooter->AddItem(footerUninstall);
85 pFooter->SetItemEnabled(ID_CERTIFICATE_USER_FORM_FOOTER_INSTALL, true);
86 pFooter->SetItemEnabled(ID_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL, false);
88 pFooter->AddActionEventListener(*this);
90 SetFormBackEventListener(this);
94 CertificateUserForm::OnInitializing(void)
96 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
97 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_USER_CERTIFICATES"));
100 return InitCertificatePresentationModelInstance();
104 CertificateUserForm::OnTerminating(void)
106 delete __installFromSDCardPopup;
107 __installFromSDCardPopup = null;
109 __isPopupVisible = false;
111 SetFormBackEventListener(null);
116 CertificateUserForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
118 __isPopupVisible = false;
119 if (__pTableView != null)
121 int tableViewControlCount = __pTableView->GetControlCount();
122 for (int i = 0; i < tableViewControlCount; i++)
124 __pTableView->RemoveControl(__pTableView->GetControl(0));
126 // __pTableView->RemoveAllControls();
129 int controlCount = GetControlCount();
130 for (int i = 0; i < controlCount; i++)
132 RemoveControl(GetControl(0));
134 // RemoveAllControls();
135 if (GetUserCertificateStoreCount() != 0)
137 AppLogDebug("GetUserCertificateStoreCount %d", GetUserCertificateStoreCount());
139 EnableUninstallFooter();
140 __pTableView->UpdateTableView();
144 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
147 Rectangle clientRect = GetClientAreaBounds();
148 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
150 int bitmapWidth = pBitmp->GetWidth();
151 int bitmapHeight = pBitmp->GetHeight();
152 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
153 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
154 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
156 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
157 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
159 Label* pLabel = new (std::nothrow) Label();
160 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
161 pLabel->SetName(NO_CONTENTS);
162 pLabel->SetBackgroundBitmap(*pBitmp);
164 yPos = yPos + bitmapHeight;
166 Label* pLabelNoContents = new (std::nothrow) Label();
167 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
168 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
169 pLabelNoContents->SetTextColor(textColor);
170 pLabelNoContents->SetText(labelText);
173 AddControl(pLabelNoContents);
175 DisableUninstallFooter();
180 CertificateUserForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
185 CertificateUserForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
187 SceneManager* pSceneManager = SceneManager::GetInstance();
188 AppAssert(pSceneManager);
190 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
194 CertificateUserForm::GetGroupCount(void)
196 AppLogDebug("ENTER");
197 return ID_GROUP_COUNT;
201 CertificateUserForm::GetItemCount(int groupIndex)
203 return GetUserCertificateStoreCount();
207 CertificateUserForm::CreateGroupItem(int groupIndex, int itemWidth)
211 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
213 pItem->Construct(Dimension(itemWidth, itemHeight));
214 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
216 pItem->SetEnabled(false);
222 CertificateUserForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
224 Rectangle itemMainRectangle;
225 Rectangle itemSubRectangle;
227 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
228 String itemText = CertificatePresentationModelUtility::GetCommonName(
229 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
230 if (IsFailed(GetLastResult()))
232 AppLogDebug("GetSubjectNameFromCertifcateStore(%d) failed(%s)", itemIndex, GetErrorMessage(GetLastResult()));
236 String itemSecondText = CertificatePresentationModelUtility::GetOrganisation(
237 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
238 if (IsFailed(GetLastResult()))
240 AppLogDebug("GetSubjectNameFromCertifcateStore(%d) failed(%s)", itemIndex, GetErrorMessage(GetLastResult()));
241 itemSecondText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
243 TableViewItem* pItem = new (std::nothrow) TableViewItem();
245 int fontSize = GetFontSize();
246 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
247 int itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
249 RelativeLayout relativeLayout;
250 relativeLayout.Construct();
252 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
253 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
255 Label* pLabel = new (std::nothrow) Label();
256 pLabel->Construct(itemMainRectangle, itemText);
257 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
258 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
259 pLabel->SetTextColor(COLOR_MAIN_TEXT);
261 pItem->AddControl(pLabel);
262 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
263 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
264 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
266 Label* pSecondLabel = new (std::nothrow) Label();
267 result r = pSecondLabel->Construct(itemSubRectangle, itemSecondText);
270 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
275 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
276 pSecondLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
277 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
278 pSecondLabel->SetTextConfig(H_GROUP_INDEX_TEXT_GAP, LABEL_TEXT_STYLE_NORMAL);
280 pItem->AddControl(pSecondLabel);
281 relativeLayout.SetMargin(*pSecondLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
282 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
283 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
289 CertificateUserForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
291 AppLogDebug("ENTER");
300 CertificateUserForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
302 AppLogDebug("ENTER");
311 CertificateUserForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
313 SceneManager* pSceneManager = SceneManager::GetInstance();
314 AppAssert(pSceneManager);
315 ICertificate* pICertificate = __pCertificatePresentationModelInstance->GetCertificateFromCertificateStoreN(itemIndex);
316 if (pICertificate == null)
318 AppLogDebug("GetCertificateFromCertificateStoreN is null");
321 __pCertificatePresentationModelInstance->ClearPendingCertificate();
322 bool isPending = __pCertificatePresentationModelInstance->PushPendingCertificate(*pICertificate);
323 if (isPending == false)
325 AppLogDebug("PushPendingCertificate failed");
328 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE_DETAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
332 CertificateUserForm::GetDefaultGroupItemHeight(void)
334 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
338 CertificateUserForm::GetDefaultItemHeight(void)
340 return H_GROUP_ITEM_DEFAULT;
344 CertificateUserForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
349 CertificateUserForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
354 CertificateUserForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
359 CertificateUserForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
364 CertificateUserForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
366 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
369 Rectangle clientRect = GetClientAreaBounds();
370 Rectangle labelBound = pLabel->GetBounds();
372 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
373 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
375 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
376 yPos = yPos + pLabel->GetBounds().height;
377 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
378 if (pTextLabel != null)
380 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
387 CertificateUserForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
389 SceneManager* pSceneManager = SceneManager::GetInstance();
390 AppAssert(pSceneManager);
394 case IDA_CERTIFICATE_USER_FORM_FOOTER_INSTALL:
396 if (__isPopupVisible == false)
404 case IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL:
406 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE_USER_UNINSTALL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
410 case IDA_SD_INSTALL_POPUP_OK:
413 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE_USER_INSTALL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
417 case IDA_SD_INSTALL_POPUP_CANCEL:
428 CertificateUserForm::InitCertificatePresentationModelInstance(void)
430 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
431 if (__pCertificatePresentationModelInstance == null)
435 result r = __pCertificatePresentationModelInstance->SetCertificateSelector(USER_CERT);
438 AppLogDebug("SetCertificateSelector failed(%s)", GetErrorMessage(r));
440 __pCertificatePresentationModelInstance->UpdateCertificateListFromCertificateStore();
441 if (__pCertificatePresentationModelInstance->GetCertificateStoreCount() != 0)
443 EnableUninstallFooter();
447 DisableUninstallFooter();
453 CertificateUserForm::GetUserCertificateStoreCount(void)
455 return __pCertificatePresentationModelInstance->GetCertificateStoreCount();
459 CertificateUserForm::DisableUninstallFooter(void)
461 Footer* pFooter = GetFooter();
463 pFooter->SetItemEnabled(ID_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL, false);
464 pFooter->Invalidate(false);
468 CertificateUserForm::EnableUninstallFooter(void)
470 Footer* pFooter = GetFooter();
472 pFooter->SetItemEnabled(ID_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL, true);
473 pFooter->Invalidate(true);
477 CertificateUserForm::CreateAlertPopup(void)
480 Label* pLabel = null;
481 Button* pLhsButton = null;
482 Button* pRhslButton = null;
484 Rectangle clientRect = GetClientAreaBounds();
485 Rectangle itemRectLabel;
486 Rectangle itemRectLhsButton;
487 Rectangle itemRectRhsButton;
490 clientRect.y = Y_ALERT_POPUP_CLIENT_RECT_DEFAULT;
491 clientRect.width = W_ALERT_POPUP_CLIENT_RECT_RESIZE;
492 clientRect.height = H_ALERT_POPUP_CLIENT_RECT_RESIZE;
494 itemRectLabel.x = X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
495 itemRectLabel.y = Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
496 itemRectLabel.width = clientRect.width;
497 itemRectLabel.height = H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
499 itemRectLhsButton.x = X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT + itemRectLabel.x;
500 itemRectLhsButton.y = Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
501 itemRectLhsButton.width = W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
502 itemRectLhsButton.height = H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
504 itemRectRhsButton = itemRectLhsButton;
505 itemRectRhsButton.x = itemRectLhsButton.x + itemRectLhsButton.width + X_ALERT_POPUP_ITEM_RECT_RHS_BUTTON_RESIZE;
507 Dimension bounds = Dimension(clientRect.width, clientRect.height);
509 __installFromSDCardPopup = new (std::nothrow) Popup();
510 __installFromSDCardPopup->Construct(false, bounds);
512 pLabel = new (std::nothrow) Label();
513 pLabel->Construct(itemRectLabel, ResourceManager::GetString(L"IDS_ST_BODY_INSTALL_CERTIFICATES_FROM_SD_CARD_Q"));
514 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
515 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
516 pLabel->SetTextConfig(ALERT_POPUP_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
517 __installFromSDCardPopup->AddControl(pLabel);
519 buttonText = ResourceManager::GetString(L"IDS_COM_SK_NO");
520 pLhsButton = new (std::nothrow) Button();
521 pLhsButton->Construct(itemRectLhsButton, buttonText);
522 pLhsButton->SetActionId(IDA_SD_INSTALL_POPUP_CANCEL);
524 __installFromSDCardPopup->AddControl(pLhsButton);
526 buttonText = ResourceManager::GetString(L"IDS_ST_BUTTON_YES");
528 pRhslButton = new (std::nothrow) Button();
529 pRhslButton->Construct(itemRectRhsButton, buttonText);
530 pRhslButton->SetActionId(IDA_SD_INSTALL_POPUP_OK);
532 __installFromSDCardPopup->AddControl(pRhslButton);
533 __installFromSDCardPopup->SetPropagatedKeyEventListener(this);
535 pLhsButton->AddActionEventListener(*this);
536 pRhslButton->AddActionEventListener(*this);
542 CertificateUserForm::ShowAlertPopup(void)
544 __isPopupVisible = true;
545 __installFromSDCardPopup->SetShowState(true);
546 __installFromSDCardPopup->Show();
550 CertificateUserForm::HideAlertPopup(void)
552 __isPopupVisible = false;
553 __installFromSDCardPopup->SetShowState(false);
554 __installFromSDCardPopup->Invalidate(true);
558 CertificateUserForm::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
564 CertificateUserForm::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
566 if (__installFromSDCardPopup && __installFromSDCardPopup->GetShowState() == true && (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC))
575 CertificateUserForm::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
581 CertificateUserForm::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)