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 StCertificateTrustedRootForm.cpp
19 * @brief This is the implementation file for CertificateTrustedRootForm class.
22 #include "StCertificateTrustedRootForm.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 ID_GROUP_COUNT = 1;
36 CertificateTrustedRootForm::CertificateTrustedRootForm(void)
37 : __pCertificatePresentationModelInstance(null)
41 CertificateTrustedRootForm::~CertificateTrustedRootForm(void)
46 CertificateTrustedRootForm::CreateFooter(void)
48 Footer* pFooter = GetFooter();
51 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
52 pFooter->AddActionEventListener(*this);
54 SetFormBackEventListener(this);
58 CertificateTrustedRootForm::OnInitializing(void)
60 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_TRUSTED_ROOT_CERTIFICATES"));
62 result r = InitCertificatePresentationModelInstance();
65 __pCertificatePresentationModelInstance = null;
68 if (GetTrustedRootCertificateStoreCount() == 0)
76 if (__pTableView != null)
78 __pTableView->UpdateTableView();
84 CertificateTrustedRootForm::CreateTableView(void)
86 Rectangle tableViewBounds = GetClientAreaBounds();
87 tableViewBounds.y = Y_GROUP_DEFAULT;
89 __pTableView = new (std::nothrow) GroupedTableView();
91 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
92 __pTableView->SetItemProvider(this);
94 AddControl(__pTableView);
95 __pTableView->SetGroupedLookEnabled(true);
96 __pTableView->AddGroupedTableViewItemEventListener(*this);
97 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
98 if (pRelativeLayout != null)
100 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
101 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
102 delete pRelativeLayout;
107 CertificateTrustedRootForm::OnTerminating(void)
111 SetFormBackEventListener(null);
116 CertificateTrustedRootForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
118 if (GetTrustedRootCertificateStoreCount() != 0 && previousSceneId == IDSCN_CERTIFICATE_DETAIL)
120 __pTableView->RefreshAllItems();
125 CertificateTrustedRootForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
130 CertificateTrustedRootForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
132 SceneManager* pSceneManager = SceneManager::GetInstance();
133 AppAssert(pSceneManager);
135 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
139 CertificateTrustedRootForm::GetGroupCount(void)
141 AppLogDebug("ENTER");
142 return ID_GROUP_COUNT;
146 CertificateTrustedRootForm::GetItemCount(int groupIndex)
151 itemCount = GetTrustedRootCertificateStoreCount();
158 CertificateTrustedRootForm::CreateGroupItem(int groupIndex, int itemWidth)
160 AppLogDebug("ENTER");
162 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
163 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
164 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
165 Rectangle itemMainRectangle;
167 Label* pLabel = null;
169 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
171 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
172 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
174 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
175 itemMainRectangle.y = yItemOffset;
176 itemMainRectangle.width = itemWidth;
177 itemMainRectangle.height = itemHeight;
179 pItem->Construct(Dimension(itemWidth, itemHeight));
180 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
182 pLabel = new (std::nothrow) Label();
183 pLabel->Construct(itemMainRectangle, groupText);
184 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
185 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
186 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
187 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
189 pItem->AddControl(pLabel);
190 pItem->SetEnabled(false);
196 CertificateTrustedRootForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
198 AppLogDebug("GroupIndex %d, ItemIndex %d, ItemWidth %d", groupIndex, itemIndex, itemWidth);
199 Rectangle itemMainRectangle;
200 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
201 int fontSize = GetFontSize();
203 String itemMainText = L"";
204 if (__pCertificatePresentationModelInstance != null)
206 itemMainText = CertificatePresentationModelUtility::GetCommonName(
207 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
208 if (IsFailed(GetLastResult()))
210 AppLogDebug("GetCommonName failed(%s)", GetErrorMessage(GetLastResult()));
211 itemMainText = CertificatePresentationModelUtility::GetOrganisation(
212 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
214 if (IsFailed(GetLastResult()))
216 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
221 TableViewItem* pItem = new (std::nothrow) TableViewItem();
223 ItemTypeOneLine(itemMainRectangle);
225 RelativeLayout relativeLayout;
226 relativeLayout.Construct();
228 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
229 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
231 Label* pLabel = new (std::nothrow) Label();
232 pLabel->Construct(itemMainRectangle, itemMainText);
233 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
234 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
235 pLabel->SetTextColor(COLOR_MAIN_TEXT);
237 pItem->AddControl(pLabel);
238 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
239 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
240 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
246 CertificateTrustedRootForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
248 AppLogDebug("ENTER");
257 CertificateTrustedRootForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
259 AppLogDebug("ENTER");
268 CertificateTrustedRootForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
270 if (__pCertificatePresentationModelInstance == null)
272 AppLogDebug("__pCertificatePresentationModelInstance is null");
276 SceneManager* pSceneManager = SceneManager::GetInstance();
277 AppAssert(pSceneManager);
279 ICertificate* pICertificate = __pCertificatePresentationModelInstance->GetCertificateFromCertificateStoreN(itemIndex);
280 if (pICertificate == null)
282 AppLogDebug("GetCertificateFromCertificateStoreN is null");
286 __pCertificatePresentationModelInstance->ClearPendingCertificate();
287 bool isPending = __pCertificatePresentationModelInstance->PushPendingCertificate(*pICertificate);
288 if (isPending == false)
290 AppLogDebug("PushPendingCertificate failed");
294 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE_DETAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
298 CertificateTrustedRootForm::GetDefaultGroupItemHeight(void)
300 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
304 CertificateTrustedRootForm::GetDefaultItemHeight(void)
306 return H_GROUP_ITEM_DEFAULT;
310 CertificateTrustedRootForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
312 AppLogDebug("ENTER");
313 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
314 Rectangle itemMainRectangle;
316 itemMainRectangle = pItem->GetBounds();
317 itemMainRectangle.width = GetClientAreaBounds().width;
319 pItem->SetBounds(itemMainRectangle);
320 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
322 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
323 itemMainRectangle = pLabel->GetBounds();
324 itemMainRectangle.width = GetClientAreaBounds().width;
325 pLabel->SetBounds(itemMainRectangle);
326 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
327 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
328 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
329 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
330 pItem->SetEnabled(false);
331 pLabel->Invalidate(false);
332 pItem->Invalidate(false);
336 CertificateTrustedRootForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
338 AppLogDebug("GroupIndex %d, ItemIndex %d", groupIndex, itemIndex);
339 Rectangle itemMainRectangle;
340 Rectangle itemRectangle = pItem->GetBounds();
341 int fontSize = GetFontSize();
343 String itemMainText = L"";
344 if (__pCertificatePresentationModelInstance != null)
346 itemMainText = CertificatePresentationModelUtility::GetCommonName(
347 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
348 if (IsFailed(GetLastResult()))
350 AppLogDebug("GetCommonName failed(%s)", GetErrorMessage(GetLastResult()));
351 itemMainText = CertificatePresentationModelUtility::GetOrganisation(
352 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
354 if (IsFailed(GetLastResult()))
356 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
361 itemMainRectangle = pItem->GetBounds();
362 itemMainRectangle.width = GetClientAreaBounds().width;
364 pItem->SetBounds(itemMainRectangle);
365 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
367 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
370 itemMainRectangle = pLabel->GetBounds();
371 itemMainRectangle.width = GetClientAreaBounds().width;
372 pLabel->SetBounds(itemMainRectangle);
373 pLabel->SetText(itemMainText);
374 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
375 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
376 pLabel->SetTextColor(COLOR_MAIN_TEXT);
381 CertificateTrustedRootForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
386 CertificateTrustedRootForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
391 CertificateTrustedRootForm::InitCertificatePresentationModelInstance(void)
393 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
394 if (__pCertificatePresentationModelInstance == null)
399 result r = __pCertificatePresentationModelInstance->SetCertificateSelector(ROOT_CA);
402 AppLogDebug("SetCertificateSelector failed(%s", GetErrorMessage(r));
405 return __pCertificatePresentationModelInstance->UpdateCertificateListFromCertificateStore();
409 CertificateTrustedRootForm::GetTrustedRootCertificateStoreCount(void)
411 if (__pCertificatePresentationModelInstance == null)
413 AppLogDebug("__pCertificatePresentationModelInstance is null");
416 return __pCertificatePresentationModelInstance->GetCertificateStoreCount();
420 CertificateTrustedRootForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
422 if (__pTableView == null)
424 if (GetTrustedRootCertificateStoreCount() == 0)
426 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
429 Rectangle clientRect = GetClientAreaBounds();
430 Rectangle labelBound = pLabel->GetBounds();
432 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
433 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
435 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
436 yPos = yPos + pLabel->GetBounds().height;
437 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
438 if (pTextLabel != null)
440 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
446 __pTableView->RefreshAllItems();
450 CertificateTrustedRootForm::CreateNoContents(void)
452 int controlCount = GetControlCount();
453 for (int i = 0; i < controlCount; i++)
455 RemoveControl(GetControl(0));
457 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
460 Rectangle clientRect = GetClientAreaBounds();
461 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
463 int bitmapWidth = pBitmp->GetWidth();
464 int bitmapHeight = pBitmp->GetHeight();
465 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
466 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
467 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
469 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
470 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
472 Label* pLabel = new (std::nothrow) Label();
473 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
474 pLabel->SetName(NO_CONTENTS);
475 pLabel->SetBackgroundBitmap(*pBitmp);
477 yPos = yPos + bitmapHeight;
479 Label* pLabelNoContents = new (std::nothrow) Label();
480 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
481 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
482 pLabelNoContents->SetTextColor(textColor);
483 pLabelNoContents->SetText(labelText);
486 AddControl(pLabelNoContents);