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 StCertificateDetailForm.cpp
19 * @brief This is the implementation file for CertificateDetailForm class.
22 #include "StCertificateDetailForm.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_COUNT = 1;
37 static const int ID_GROUP_DEFAULT_ITEM_COUNT = 10;
38 static const int OWNER_TEXT_RESIZE = 1;
40 static const int CERTIFICATE_DETAIL_ITEM_FIRST_LABEL = 0;
41 static const int CERTIFICATE_DETAIL_ITEM_SECOND_LABEL = 1;
43 enum CertificateDetailItem
45 CERTIFICATE_DETAIL_ITEM_BASE,
46 CERTIFICATE_DETAIL_ITEM_OWNER_COMMON_NAME = CERTIFICATE_DETAIL_ITEM_BASE,
47 CERTIFICATE_DETAIL_ITEM_OWNER_ORGANISATION,
48 CERTIFICATE_DETAIL_ITEM_ISSUER_COMMON_NAME,
49 CERTIFICATE_DETAIL_ITEM_ISSUER_ORGANISATION,
50 CERTIFICATE_DETAIL_ITEM_CERTIFICATE_INFORMATION_VERSION,
51 CERTIFICATE_DETAIL_ITEM_VALID_FROM,
52 CERTIFICATE_DETAIL_ITEM_VALID_TO,
53 CERTIFICATE_DETAIL_ITEM_SERIAL_NUMBER,
54 CERTIFICATE_DETAIL_ITEM_SIGNATURE_ALGORITHM,
55 CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY,
56 CERTIFICATE_DETAIL_ITEM_MAX
59 CertificateDetailForm::CertificateDetailForm(void)
60 : __pCertificatePresentationModelInstance(null)
61 , __pX509Certificate(null)
65 CertificateDetailForm::~CertificateDetailForm(void)
70 CertificateDetailForm::CreateFooter(void)
72 Footer* pFooter = GetFooter();
75 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
76 pFooter->SetBackButton();
77 pFooter->AddActionEventListener(*this);
79 SetFormBackEventListener(this);
83 CertificateDetailForm::CreateTableView(void)
85 Rectangle tableViewBounds = GetClientAreaBounds();
86 tableViewBounds.y = Y_GROUP_DEFAULT;
88 __pTableView = new (std::nothrow) GroupedTableView();
90 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
91 __pTableView->SetItemProvider(this);
93 AddControl(__pTableView);
94 __pTableView->SetGroupedLookEnabled(true);
95 __pTableView->AddGroupedTableViewItemEventListener(*this);
96 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
97 if (pRelativeLayout != null)
99 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
100 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
101 delete pRelativeLayout;
106 CertificateDetailForm::OnInitializing(void)
108 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_CERTIFICATE_DETAILS"));
112 result r = InitCertificatePresentationModelInstance();
118 return LoadCertificate();
122 CertificateDetailForm::OnTerminating(void)
126 SetFormBackEventListener(null);
131 CertificateDetailForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
133 __pTableView->UpdateTableView();
137 CertificateDetailForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
142 CertificateDetailForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
144 SceneManager* pSceneManager = SceneManager::GetInstance();
145 AppAssert(pSceneManager);
147 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
151 CertificateDetailForm::GetGroupCount(void)
153 AppLogDebug("ENTER");
154 return ID_GROUP_COUNT;
158 CertificateDetailForm::GetItemCount(int groupIndex)
160 return ID_GROUP_DEFAULT_ITEM_COUNT;
163 Tizen::Ui::Controls::TableViewGroupItem*
164 CertificateDetailForm::CreateGroupItem(int groupIndex, int itemWidth)
166 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
167 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
168 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
169 Rectangle itemMainRectangle;
171 Label* pLabel = null;
173 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
175 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
176 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
178 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
179 itemMainRectangle.y = yItemOffset;
180 itemMainRectangle.width = itemWidth;
181 itemMainRectangle.height = itemHeight;
183 RelativeLayout relativeLayout;
184 relativeLayout.Construct();
186 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
187 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
189 pLabel = new (std::nothrow) Label();
190 pLabel->Construct(itemMainRectangle, groupText);
191 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
192 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
193 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
194 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
196 pItem->AddControl(pLabel);
197 pItem->SetEnabled(false);
198 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
199 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
200 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
205 Tizen::Ui::Controls::TableViewItem*
206 CertificateDetailForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
208 Rectangle itemMainRectangle;
209 Rectangle itemSubRectangle;
210 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
214 int fontSize = GetFontSize();
215 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
216 int itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
220 case CERTIFICATE_DETAIL_ITEM_OWNER_COMMON_NAME:
222 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_OWNER_C");
223 itemMainText.Remove(itemMainText.GetLength() - OWNER_TEXT_RESIZE, OWNER_TEXT_RESIZE);
224 itemMainText.Append(L"/");
225 itemMainText.Append(ResourceManager::GetString(L"IDS_ST_BODY_COMMON_NAME_C"));
226 itemSubText = CertificatePresentationModelUtility::GetCommonName(__pX509Certificate->GetSubject());
227 if (IsFailed(GetLastResult()))
229 AppLogDebug("GetCommonName failed(%s)", GetErrorMessage(GetLastResult()));
230 itemSubText = CertificatePresentationModelUtility::GetOrganisation(__pX509Certificate->GetSubject());
231 if (IsFailed(GetLastResult()))
233 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
234 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
240 case CERTIFICATE_DETAIL_ITEM_OWNER_ORGANISATION:
242 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ORGANISATION_C");
243 itemSubText = CertificatePresentationModelUtility::GetOrganisation(__pX509Certificate->GetSubject());
244 if (IsFailed(GetLastResult()))
246 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
247 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
252 case CERTIFICATE_DETAIL_ITEM_ISSUER_COMMON_NAME:
254 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ISSUER");
255 itemMainText.Append(L"/");
256 itemMainText.Append(ResourceManager::GetString(L"IDS_ST_BODY_COMMON_NAME_C"));
257 itemSubText = CertificatePresentationModelUtility::GetCommonName(__pX509Certificate->GetIssuer());
258 if (IsFailed(GetLastResult()))
260 AppLogDebug("GetCommonName failed(%s)", GetErrorMessage(GetLastResult()));
261 itemSubText = CertificatePresentationModelUtility::GetOrganisation(__pX509Certificate->GetIssuer());
262 if (IsFailed(GetLastResult()))
264 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
265 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
271 case CERTIFICATE_DETAIL_ITEM_ISSUER_ORGANISATION:
273 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ORGANISATION_C");
274 itemSubText = CertificatePresentationModelUtility::GetOrganisation(__pX509Certificate->GetIssuer());
275 if (IsFailed(GetLastResult()))
277 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
278 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
283 case CERTIFICATE_DETAIL_ITEM_CERTIFICATE_INFORMATION_VERSION:
285 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CERTIFICATE_INFORMATION");
286 itemMainText.Append(L"/");
287 itemMainText.Append(ResourceManager::GetString(L"IDS_ST_BODY_VERSION"));
288 itemMainText.Append(L":");
289 itemSubText = Integer::ToString(__pX509Certificate->GetSpecVersion());
293 case CERTIFICATE_DETAIL_ITEM_VALID_FROM:
295 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_VALID_FROM");
296 itemMainText.Append(L":");
297 itemSubText = __pX509Certificate->GetNotBefore();
298 if (IsFailed(GetLastResult()))
300 AppLogDebug("GetNotBefore failed(%s)", GetErrorMessage(GetLastResult()));
301 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
306 case CERTIFICATE_DETAIL_ITEM_VALID_TO:
308 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_VALID_TO_C");
309 itemSubText = __pX509Certificate->GetNotAfter();
310 if (IsFailed(GetLastResult()))
312 AppLogDebug("GetNotAfter failed(%s)", GetErrorMessage(GetLastResult()));
313 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
318 case CERTIFICATE_DETAIL_ITEM_SERIAL_NUMBER:
320 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SERIAL_NUMBER");
321 itemMainText.Append(L":");
322 itemSubText = __pX509Certificate->GetSerialNumber();
323 if (IsFailed(GetLastResult()))
325 AppLogDebug("GetSerialNumber failed(%s)", GetErrorMessage(GetLastResult()));
326 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
331 case CERTIFICATE_DETAIL_ITEM_SIGNATURE_ALGORITHM:
333 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SIGNATURE_ALGORITHM");
334 itemMainText.Append(L":");
335 itemSubText = __pX509Certificate->GetSignatureAlgorithm();
336 if (IsFailed(GetLastResult()))
338 AppLogDebug("GetSignatureAlgorithm failed(%s)", GetErrorMessage(GetLastResult()));
339 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
344 case CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY:
346 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_PUBLIC_KEY_C");
347 IPublicKey* publicKey = __pX509Certificate->GetPublicKeyN();
349 itemSubText = CertificatePresentationModelUtility::GetHexPublicKeyString(*publicKey);
350 if (IsFailed(GetLastResult()))
352 AppLogDebug("GetHexPublicKeyString failed(%s)", GetErrorMessage(GetLastResult()));
353 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
357 itemSubRectangle.width = itemWidth;
358 itemSubRectangle.height = GetHeightForStringArea(itemSubText, itemSubRectangle.width, H_GROUP_INDEX_TEXT_GAP);
359 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
367 TableViewItem* pItem = new (std::nothrow) TableViewItem();
369 RelativeLayout relativeLayout;
370 relativeLayout.Construct();
372 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
373 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
375 Label* pLabel = new (std::nothrow) Label();
376 pLabel->Construct(itemMainRectangle, itemMainText);
377 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
378 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
379 pLabel->SetTextColor(COLOR_MAIN_TEXT);
381 pItem->AddControl(pLabel);
382 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
383 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
384 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
386 Label* pSecondLabel = new (std::nothrow) Label();
387 result r = pSecondLabel->Construct(itemSubRectangle, itemSubText);
390 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
395 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
396 pSecondLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
397 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
398 pSecondLabel->SetTextConfig(H_GROUP_INDEX_TEXT_GAP, LABEL_TEXT_STYLE_NORMAL);
400 pItem->SetEnabled(false);
401 pItem->AddControl(pSecondLabel);
402 relativeLayout.SetMargin(*pSecondLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
403 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
404 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
410 CertificateDetailForm::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
412 AppLogDebug("ENTER");
421 CertificateDetailForm::DeleteItem(int groupIndex, int itemIndex,Tizen::Ui::Controls::TableViewItem* pItem)
423 AppLogDebug("ENTER");
432 CertificateDetailForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
437 CertificateDetailForm::GetDefaultGroupItemHeight(void)
439 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
443 CertificateDetailForm::GetDefaultItemHeight(void)
445 return H_GROUP_ITEM_DEFAULT;
449 CertificateDetailForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
454 CertificateDetailForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
456 if (itemIndex != CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY)
458 AppLogDebug("itemIndex is not CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY");
462 Label* pLabel = static_cast<Label*>(pItem->GetControl(CERTIFICATE_DETAIL_ITEM_FIRST_LABEL));
465 AppLogDebug("pLabel is null");
469 Label* pSecondLabel = static_cast<Label*>(pItem->GetControl(CERTIFICATE_DETAIL_ITEM_SECOND_LABEL));
470 if (pSecondLabel == null)
472 AppLogDebug("pSecondLabel is null");
476 Rectangle clientRect = GetClientAreaBounds();
477 Rectangle itemRect = pItem->GetBounds();
478 Rectangle itemMainRectangle;
479 Rectangle itemSubRectangle;
480 int fontSize = GetFontSize();
481 String groupText = pSecondLabel->GetText();
483 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
485 int itemHeight = GetHeightForStringArea(groupText, clientRect.width, H_GROUP_INDEX_TEXT_GAP);
487 itemRect.height = (itemMainRectangle.height + itemHeight);
489 pSecondLabel->SetBounds(clientRect.x, itemMainRectangle.height, clientRect.width, itemHeight);
490 pItem->SetBounds(itemRect);
494 CertificateDetailForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
499 CertificateDetailForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
504 CertificateDetailForm::InitCertificatePresentationModelInstance(void)
506 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
507 if (__pCertificatePresentationModelInstance == null)
516 CertificateDetailForm::LoadCertificate(void)
518 __pX509Certificate = dynamic_cast<X509Certificate*>(__pCertificatePresentationModelInstance->PopPendingCertificateN());
519 if (__pX509Certificate == null)
521 AppLogDebug("PopPendingCertificateN is null");
529 CertificateDetailForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
531 __pTableView->RefreshItem(0, CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);