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->AddActionEventListener(*this);
78 SetFormBackEventListener(this);
82 CertificateDetailForm::CreateTableView(void)
84 Rectangle tableViewBounds = GetClientAreaBounds();
85 tableViewBounds.y = Y_GROUP_DEFAULT;
87 __pTableView = new (std::nothrow) GroupedTableView();
89 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
90 __pTableView->SetItemProvider(this);
92 AddControl(__pTableView);
93 __pTableView->SetGroupedLookEnabled(true);
94 __pTableView->AddGroupedTableViewItemEventListener(*this);
95 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
96 if (pRelativeLayout != null)
98 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
99 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
100 delete pRelativeLayout;
105 CertificateDetailForm::OnInitializing(void)
107 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_CERTIFICATE_DETAILS"));
110 result r = InitCertificatePresentationModelInstance();
116 return LoadCertificate();
120 CertificateDetailForm::OnTerminating(void)
124 SetFormBackEventListener(null);
129 CertificateDetailForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
131 __pTableView->UpdateTableView();
135 CertificateDetailForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
140 CertificateDetailForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
142 SceneManager* pSceneManager = SceneManager::GetInstance();
143 AppAssert(pSceneManager);
145 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
149 CertificateDetailForm::GetGroupCount(void)
151 AppLogDebug("ENTER");
152 return ID_GROUP_COUNT;
156 CertificateDetailForm::GetItemCount(int groupIndex)
158 return ID_GROUP_DEFAULT_ITEM_COUNT;
161 Tizen::Ui::Controls::TableViewGroupItem*
162 CertificateDetailForm::CreateGroupItem(int groupIndex, int itemWidth)
165 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
166 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
167 Rectangle itemMainRectangle;
169 Label* pLabel = null;
171 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
173 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
176 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
177 itemMainRectangle.y = yItemOffset;
178 itemMainRectangle.width = itemWidth;
179 itemMainRectangle.height = itemHeight;
181 RelativeLayout relativeLayout;
182 relativeLayout.Construct();
184 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
185 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
187 pLabel = new (std::nothrow) Label();
188 pLabel->Construct(itemMainRectangle, groupText);
189 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
190 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
191 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
192 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
194 pItem->AddControl(pLabel);
195 pItem->SetEnabled(false);
196 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
197 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
198 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
203 Tizen::Ui::Controls::TableViewItem*
204 CertificateDetailForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
206 Rectangle itemMainRectangle;
207 Rectangle itemSubRectangle;
208 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
212 int fontSize = GetFontSize();
213 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
214 int itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
218 case CERTIFICATE_DETAIL_ITEM_OWNER_COMMON_NAME:
220 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_OWNER_C");
221 itemMainText.Remove(itemMainText.GetLength() - OWNER_TEXT_RESIZE, OWNER_TEXT_RESIZE);
222 itemMainText.Append(L"/");
223 itemMainText.Append(ResourceManager::GetString(L"IDS_ST_BODY_COMMON_NAME_C"));
224 itemSubText = CertificatePresentationModelUtility::GetCommonName(__pX509Certificate->GetSubject());
225 if (IsFailed(GetLastResult()))
227 AppLogDebug("GetCommonName failed(%s)", GetErrorMessage(GetLastResult()));
228 itemSubText = CertificatePresentationModelUtility::GetOrganisation(__pX509Certificate->GetSubject());
229 if (IsFailed(GetLastResult()))
231 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
232 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
238 case CERTIFICATE_DETAIL_ITEM_OWNER_ORGANISATION:
240 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ORGANISATION_C");
241 itemSubText = CertificatePresentationModelUtility::GetOrganisation(__pX509Certificate->GetSubject());
242 if (IsFailed(GetLastResult()))
244 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
245 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
250 case CERTIFICATE_DETAIL_ITEM_ISSUER_COMMON_NAME:
252 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ISSUER");
253 itemMainText.Append(L"/");
254 itemMainText.Append(ResourceManager::GetString(L"IDS_ST_BODY_COMMON_NAME_C"));
255 itemSubText = CertificatePresentationModelUtility::GetCommonName(__pX509Certificate->GetIssuer());
256 if (IsFailed(GetLastResult()))
258 AppLogDebug("GetCommonName failed(%s)", GetErrorMessage(GetLastResult()));
259 itemSubText = CertificatePresentationModelUtility::GetOrganisation(__pX509Certificate->GetIssuer());
260 if (IsFailed(GetLastResult()))
262 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
263 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
269 case CERTIFICATE_DETAIL_ITEM_ISSUER_ORGANISATION:
271 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_ORGANISATION_C");
272 itemSubText = CertificatePresentationModelUtility::GetOrganisation(__pX509Certificate->GetIssuer());
273 if (IsFailed(GetLastResult()))
275 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
276 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
281 case CERTIFICATE_DETAIL_ITEM_CERTIFICATE_INFORMATION_VERSION:
283 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CERTIFICATE_INFORMATION");
284 itemMainText.Append(L"/");
285 itemMainText.Append(ResourceManager::GetString(L"IDS_ST_BODY_VERSION"));
286 itemMainText.Append(L":");
287 itemSubText = Integer::ToString(__pX509Certificate->GetSpecVersion());
291 case CERTIFICATE_DETAIL_ITEM_VALID_FROM:
293 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_VALID_FROM");
294 itemMainText.Append(L":");
295 itemSubText = __pX509Certificate->GetNotBefore();
296 if (IsFailed(GetLastResult()))
298 AppLogDebug("GetNotBefore failed(%s)", GetErrorMessage(GetLastResult()));
299 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
304 case CERTIFICATE_DETAIL_ITEM_VALID_TO:
306 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_VALID_TO_C");
307 itemSubText = __pX509Certificate->GetNotAfter();
308 if (IsFailed(GetLastResult()))
310 AppLogDebug("GetNotAfter failed(%s)", GetErrorMessage(GetLastResult()));
311 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
316 case CERTIFICATE_DETAIL_ITEM_SERIAL_NUMBER:
318 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SERIAL_NUMBER");
319 itemMainText.Append(L":");
320 itemSubText = __pX509Certificate->GetSerialNumber();
321 if (IsFailed(GetLastResult()))
323 AppLogDebug("GetSerialNumber failed(%s)", GetErrorMessage(GetLastResult()));
324 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
329 case CERTIFICATE_DETAIL_ITEM_SIGNATURE_ALGORITHM:
331 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SIGNATURE_ALGORITHM");
332 itemMainText.Append(L":");
333 itemSubText = __pX509Certificate->GetSignatureAlgorithm();
334 if (IsFailed(GetLastResult()))
336 AppLogDebug("GetSignatureAlgorithm failed(%s)", GetErrorMessage(GetLastResult()));
337 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
342 case CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY:
344 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_PUBLIC_KEY_C");
345 IPublicKey* publicKey = __pX509Certificate->GetPublicKeyN();
347 itemSubText = CertificatePresentationModelUtility::GetHexPublicKeyString(*publicKey);
348 if (IsFailed(GetLastResult()))
350 AppLogDebug("GetHexPublicKeyString failed(%s)", GetErrorMessage(GetLastResult()));
351 itemSubText = ResourceManager::GetString(L"IDS_ST_BODY_NO_DATA");
355 itemSubRectangle.width = itemWidth;
356 itemSubRectangle.height = GetHeightForStringArea(itemSubText, itemSubRectangle.width, H_GROUP_INDEX_TEXT_GAP);
357 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
365 TableViewItem* pItem = new (std::nothrow) TableViewItem();
367 RelativeLayout relativeLayout;
368 relativeLayout.Construct();
370 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
371 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
373 Label* pLabel = new (std::nothrow) Label();
374 pLabel->Construct(itemMainRectangle, itemMainText);
375 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
376 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
377 pLabel->SetTextColor(COLOR_MAIN_TEXT);
379 pItem->AddControl(pLabel);
380 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
381 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
382 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
384 Label* pSecondLabel = new (std::nothrow) Label();
385 result r = pSecondLabel->Construct(itemSubRectangle, itemSubText);
388 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
393 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
394 pSecondLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
395 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
396 pSecondLabel->SetTextConfig(H_GROUP_INDEX_TEXT_GAP, LABEL_TEXT_STYLE_NORMAL);
398 pItem->AddControl(pSecondLabel);
399 pItem->SetBackgroundColor(COLOR_ID_WHITE, TABLE_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED);
400 pItem->SetBackgroundColor(COLOR_ID_WHITE, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
401 relativeLayout.SetMargin(*pSecondLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
402 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
403 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
409 CertificateDetailForm::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
411 AppLogDebug("ENTER");
420 CertificateDetailForm::DeleteItem(int groupIndex, int itemIndex,Tizen::Ui::Controls::TableViewItem* pItem)
422 AppLogDebug("ENTER");
431 CertificateDetailForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
436 CertificateDetailForm::GetDefaultGroupItemHeight(void)
438 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
442 CertificateDetailForm::GetDefaultItemHeight(void)
444 return H_GROUP_ITEM_DEFAULT;
448 CertificateDetailForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
453 CertificateDetailForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
455 if (itemIndex != CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY)
457 AppLogDebug("itemIndex is not CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY");
461 Label* pLabel = static_cast<Label*>(pItem->GetControl(CERTIFICATE_DETAIL_ITEM_FIRST_LABEL));
464 AppLogDebug("pLabel is null");
468 Label* pSecondLabel = static_cast<Label*>(pItem->GetControl(CERTIFICATE_DETAIL_ITEM_SECOND_LABEL));
469 if (pSecondLabel == null)
471 AppLogDebug("pSecondLabel is null");
475 Rectangle clientRect = GetClientAreaBounds();
476 Rectangle itemRect = pItem->GetBounds();
477 Rectangle itemMainRectangle;
478 Rectangle itemSubRectangle;
479 int fontSize = GetFontSize();
480 String groupText = pSecondLabel->GetText();
482 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
484 int itemHeight = GetHeightForStringArea(groupText, clientRect.width, H_GROUP_INDEX_TEXT_GAP);
486 itemRect.height = (itemMainRectangle.height + itemHeight);
488 pSecondLabel->SetBounds(clientRect.x, itemMainRectangle.height, clientRect.width, itemHeight);
489 pItem->SetBounds(itemRect);
493 CertificateDetailForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
498 CertificateDetailForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
503 CertificateDetailForm::InitCertificatePresentationModelInstance(void)
505 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
506 if (__pCertificatePresentationModelInstance == null)
515 CertificateDetailForm::LoadCertificate(void)
517 __pX509Certificate = dynamic_cast<X509Certificate*>(__pCertificatePresentationModelInstance->PopPendingCertificateN());
518 if (__pX509Certificate == null)
520 AppLogDebug("PopPendingCertificateN is null");
528 CertificateDetailForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
530 __pTableView->RefreshItem(0, CERTIFICATE_DETAIL_ITEM_PUBLIC_KEY, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);