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->SetBackButton();
53 pFooter->AddActionEventListener(*this);
55 SetFormBackEventListener(this);
59 CertificateTrustedRootForm::OnInitializing(void)
61 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_TRUSTED_ROOT_CERTIFICATES"));
64 result r = InitCertificatePresentationModelInstance();
67 __pCertificatePresentationModelInstance = null;
70 if (GetTrustedRootCertificateStoreCount() == 0)
82 CertificateTrustedRootForm::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 CertificateTrustedRootForm::OnTerminating(void)
109 SetFormBackEventListener(null);
114 CertificateTrustedRootForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
116 if (GetTrustedRootCertificateStoreCount() != 0)
118 __pTableView->UpdateTableView();
123 CertificateTrustedRootForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
128 CertificateTrustedRootForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
130 SceneManager* pSceneManager = SceneManager::GetInstance();
131 AppAssert(pSceneManager);
133 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
137 CertificateTrustedRootForm::GetGroupCount(void)
139 AppLogDebug("ENTER");
140 return ID_GROUP_COUNT;
144 CertificateTrustedRootForm::GetItemCount(int groupIndex)
149 itemCount = GetTrustedRootCertificateStoreCount();
156 CertificateTrustedRootForm::CreateGroupItem(int groupIndex, int itemWidth)
158 AppLogDebug("ENTER");
160 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
161 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
162 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
163 Rectangle itemMainRectangle;
165 Label* pLabel = null;
167 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
169 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
170 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
172 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
173 itemMainRectangle.y = yItemOffset;
174 itemMainRectangle.width = itemWidth;
175 itemMainRectangle.height = itemHeight;
177 pItem->Construct(Dimension(itemWidth, itemHeight));
178 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
180 pLabel = new (std::nothrow) Label();
181 pLabel->Construct(itemMainRectangle, groupText);
182 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
183 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
184 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
185 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
187 pItem->AddControl(pLabel);
188 pItem->SetEnabled(false);
194 CertificateTrustedRootForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
196 AppLogDebug("GroupIndex %d, ItemIndex %d, ItemWidth %d", groupIndex, itemIndex, itemWidth);
197 Rectangle itemMainRectangle;
198 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
199 int fontSize = GetFontSize();
201 String itemMainText = L"";
202 if (__pCertificatePresentationModelInstance != null)
204 itemMainText = CertificatePresentationModelUtility::GetCommonName(
205 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
206 if (IsFailed(GetLastResult()))
208 AppLogDebug("GetCommonName failed(%s)", GetErrorMessage(GetLastResult()));
209 itemMainText = CertificatePresentationModelUtility::GetOrganisation(
210 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
212 if (IsFailed(GetLastResult()))
214 AppLogDebug("GetOrganisation failed(%s)", GetErrorMessage(GetLastResult()));
219 TableViewItem* pItem = new (std::nothrow) TableViewItem();
221 ItemTypeOneLine(itemMainRectangle);
223 RelativeLayout relativeLayout;
224 relativeLayout.Construct();
226 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
227 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
229 Label* pLabel = new (std::nothrow) Label();
230 pLabel->Construct(itemMainRectangle, itemMainText);
231 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
232 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
233 pLabel->SetTextColor(COLOR_MAIN_TEXT);
235 pItem->AddControl(pLabel);
236 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
237 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
238 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
244 CertificateTrustedRootForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
246 AppLogDebug("ENTER");
255 CertificateTrustedRootForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
257 AppLogDebug("ENTER");
266 CertificateTrustedRootForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
268 if (__pCertificatePresentationModelInstance == null)
270 AppLogDebug("__pCertificatePresentationModelInstance is null");
274 SceneManager* pSceneManager = SceneManager::GetInstance();
275 AppAssert(pSceneManager);
277 ICertificate* pICertificate = __pCertificatePresentationModelInstance->GetCertificateFromCertificateStoreN(itemIndex);
278 if (pICertificate == null)
280 AppLogDebug("GetCertificateFromCertificateStoreN is null");
284 __pCertificatePresentationModelInstance->ClearPendingCertificate();
285 bool isPending = __pCertificatePresentationModelInstance->PushPendingCertificate(*pICertificate);
286 if (isPending == false)
288 AppLogDebug("PushPendingCertificate failed");
292 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE_DETAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
296 CertificateTrustedRootForm::GetDefaultGroupItemHeight(void)
298 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
302 CertificateTrustedRootForm::GetDefaultItemHeight(void)
304 return H_GROUP_ITEM_DEFAULT;
308 CertificateTrustedRootForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
313 CertificateTrustedRootForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
318 CertificateTrustedRootForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
323 CertificateTrustedRootForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
328 CertificateTrustedRootForm::InitCertificatePresentationModelInstance(void)
330 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
331 if (__pCertificatePresentationModelInstance == null)
336 result r = __pCertificatePresentationModelInstance->SetCertificateSelector(ROOT_CA);
339 AppLogDebug("SetCertificateSelector failed(%s", GetErrorMessage(r));
342 return __pCertificatePresentationModelInstance->UpdateCertificateListFromCertificateStore();
346 CertificateTrustedRootForm::GetTrustedRootCertificateStoreCount(void)
348 if (__pCertificatePresentationModelInstance == null)
350 AppLogDebug("__pCertificatePresentationModelInstance is null");
353 return __pCertificatePresentationModelInstance->GetCertificateStoreCount();
357 CertificateTrustedRootForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
359 if (__pTableView == null)
361 if (GetTrustedRootCertificateStoreCount() == 0)
363 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
366 Rectangle clientRect = GetClientAreaBounds();
367 Rectangle labelBound = pLabel->GetBounds();
369 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
370 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
372 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
373 yPos = yPos + pLabel->GetBounds().height;
374 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
375 if (pTextLabel != null)
377 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
386 CertificateTrustedRootForm::CreateNoContents(void)
388 int controlCount = GetControlCount();
389 for (int i = 0; i < controlCount; i++)
391 RemoveControl(GetControl(0));
393 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
396 Rectangle clientRect = GetClientAreaBounds();
397 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
399 int bitmapWidth = pBitmp->GetWidth();
400 int bitmapHeight = pBitmp->GetHeight();
401 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
402 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
403 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
405 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
406 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
408 Label* pLabel = new (std::nothrow) Label();
409 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
410 pLabel->SetName(NO_CONTENTS);
411 pLabel->SetBackgroundBitmap(*pBitmp);
413 yPos = yPos + bitmapHeight;
415 Label* pLabelNoContents = new (std::nothrow) Label();
416 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
417 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
418 pLabelNoContents->SetTextColor(textColor);
419 pLabelNoContents->SetText(labelText);
422 AddControl(pLabelNoContents);