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 StCertificateUserUnInstallForm.cpp
19 * @brief This is the implementation file for CertificateUserUnInstallForm class.
22 #include "StCertificateUserUnInstallForm.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_UNINSTALL = IDA_CERTIFICATE_USER_FORM_FOOTER_BASE + 1;
36 static const int IDA_CERTIFICATE_USER_FORM_FOOTER_CANCEL = IDA_CERTIFICATE_USER_FORM_FOOTER_BASE + 2;
38 static const int ID_GROUP_COUNT = 1;
40 static const int ID_FOOTER_UNINSTALL = 0;
41 static const int ID_FOOTER_CANCEL = 1;
43 static const int RELATIVE_LAYOUT_LEFT_RADIO_BUTTON_MARGIN = 80;
45 CertificateUserUnInstallForm::CertificateUserUnInstallForm(void)
46 : __pCertificatePresentationModelInstance(null)
50 CertificateUserUnInstallForm::~CertificateUserUnInstallForm(void)
55 CertificateUserUnInstallForm::CreateFooter(void)
57 Footer* pFooter = GetFooter();
60 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
62 FooterItem footerUnInstall;
63 FooterItem footerCancel;
64 footerUnInstall.Construct(IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL);
65 footerUnInstall.SetText(ResourceManager::GetString(L"IDS_ST_BUTTON_UNINSTALL"));
66 footerCancel.Construct(IDA_CERTIFICATE_USER_FORM_FOOTER_CANCEL);
67 footerCancel.SetText(ResourceManager::GetString(L"IDS_ST_BODY_CANCEL"));
68 pFooter->AddItem(footerUnInstall);
69 pFooter->AddItem(footerCancel);
70 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, true);
71 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, false);
73 pFooter->AddActionEventListener(*this);
75 SetFormBackEventListener(this);
79 CertificateUserUnInstallForm::OnInitializing(void)
81 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
82 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_USER_CERTIFICATES"));
85 EnableUnInstallFooter(true);
86 return InitCertificatePresentationModelInstance();
90 CertificateUserUnInstallForm::OnTerminating(void)
94 SetFormBackEventListener(null);
99 CertificateUserUnInstallForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
101 __pTableView->UpdateTableView();
105 CertificateUserUnInstallForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
110 CertificateUserUnInstallForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
112 SceneManager* pSceneManager = SceneManager::GetInstance();
113 AppAssert(pSceneManager);
115 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
119 CertificateUserUnInstallForm::GetGroupCount(void)
121 AppLogDebug("ENTER");
122 return ID_GROUP_COUNT;
126 CertificateUserUnInstallForm::GetItemCount(int groupIndex)
128 return GetUserCertificateStoreCount();
132 CertificateUserUnInstallForm::CreateGroupItem(int groupIndex, int itemWidth)
136 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
138 pItem->Construct(Dimension(itemWidth, itemHeight));
139 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
141 pItem->SetEnabled(false);
147 CertificateUserUnInstallForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
149 Rectangle itemMainRectangle;
150 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
151 int fontSize = GetFontSize();
152 String itemMainText = CertificatePresentationModelUtility::GetCommonName(
153 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
154 if (IsFailed(GetLastResult()))
156 AppLogDebug("GetSubjectNameFromCertifcateStore(%d) failed(%s)", itemIndex, GetErrorMessage(GetLastResult()));
159 TableViewItem* pItem = new (std::nothrow) TableViewItem();
161 ItemTypeOneLine(itemMainRectangle);
163 RelativeLayout relativeLayout;
164 relativeLayout.Construct();
166 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
167 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
169 Label* pLabel = new (std::nothrow) Label();
170 pLabel->Construct(itemMainRectangle, itemMainText);
171 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
172 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
173 pLabel->SetTextColor(COLOR_MAIN_TEXT);
175 pItem->AddControl(pLabel);
176 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_RADIO_BUTTON_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
177 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
178 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
184 CertificateUserUnInstallForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
186 AppLogDebug("ENTER");
195 CertificateUserUnInstallForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
197 AppLogDebug("ENTER");
206 CertificateUserUnInstallForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
211 CertificateUserUnInstallForm::GetDefaultGroupItemHeight(void)
213 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
217 CertificateUserUnInstallForm::GetDefaultItemHeight(void)
219 return H_GROUP_ITEM_DEFAULT;
223 CertificateUserUnInstallForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
228 CertificateUserUnInstallForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
233 CertificateUserUnInstallForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
238 CertificateUserUnInstallForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
243 CertificateUserUnInstallForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
245 SceneManager* pSceneManager = SceneManager::GetInstance();
246 AppAssert(pSceneManager);
250 case IDA_CERTIFICATE_USER_FORM_FOOTER_CANCEL:
252 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
256 case IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL:
258 for (int i = 0; i < GetUserCertificateStoreCount(); i++)
260 if (__pTableView->IsItemChecked(0, i) == true)
262 ICertificate* pICertificate =__pCertificatePresentationModelInstance->GetCertificateFromCertificateStoreN(0);
263 if (pICertificate == null)
268 AppLogDebug("Certificate info [%ls]", pICertificate->GetSubject().GetPointer());
269 result r = __pCertificatePresentationModelInstance->RemoveFromCertificateStore(*pICertificate);
270 AppLogDebug("%s", GetErrorMessage(r));
273 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
283 CertificateUserUnInstallForm::InitCertificatePresentationModelInstance(void)
285 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
286 if (__pCertificatePresentationModelInstance == null)
291 __pCertificatePresentationModelInstance->UpdateCertificateListFromCertificateStore();
292 if (__pCertificatePresentationModelInstance->GetCertificateStoreCount() != 0)
294 EnableCancelFooter(true);
301 CertificateUserUnInstallForm::GetUserCertificateStoreCount(void)
303 return __pCertificatePresentationModelInstance->GetCertificateStoreCount();
307 CertificateUserUnInstallForm::EnableUnInstallFooter(bool status)
309 Footer* pFooter = GetFooter();
314 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, true);
315 pFooter->Invalidate(true);
319 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, false);
320 pFooter->Invalidate(false);
325 CertificateUserUnInstallForm::EnableCancelFooter(bool status)
327 Footer* pFooter = GetFooter();
332 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, true);
333 pFooter->Invalidate(true);
337 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, false);
338 pFooter->Invalidate(false);
343 CertificateUserUnInstallForm::CreateTableView(void)
345 if (__pTableView != null)
347 AppLogDebug("__pTableView is not null");
350 Rectangle tableViewBounds = GetClientAreaBounds();
351 tableViewBounds.y = Y_GROUP_DEFAULT;
353 __pTableView = new (std::nothrow) GroupedTableView();
354 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
355 __pTableView->SetItemProvider(this);
356 AddControl(__pTableView);
357 __pTableView->SetGroupedLookEnabled(true);
358 __pTableView->AddGroupedTableViewItemEventListener(*this);
359 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
360 if (pRelativeLayout != null)
362 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
363 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
364 delete pRelativeLayout;