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;
39 static const int ID_ITEM_COUNT_MAX = 0;
41 static const int ID_FOOTER_UNINSTALL = 0;
42 static const int ID_FOOTER_CANCEL = 1;
44 static const int RELATIVE_LAYOUT_LEFT_RADIO_BUTTON_MARGIN = 80;
46 CertificateUserUnInstallForm::CertificateUserUnInstallForm(void)
47 : __pCertificatePresentationModelInstance(null)
51 CertificateUserUnInstallForm::~CertificateUserUnInstallForm(void)
56 CertificateUserUnInstallForm::CreateFooter(void)
58 Footer* pFooter = GetFooter();
61 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
63 FooterItem footerUnInstall;
64 FooterItem footerCancel;
65 footerUnInstall.Construct(IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL);
66 footerUnInstall.SetText(ResourceManager::GetString(L"IDS_ST_BUTTON_UNINSTALL"));
67 footerCancel.Construct(IDA_CERTIFICATE_USER_FORM_FOOTER_CANCEL);
68 footerCancel.SetText(ResourceManager::GetString(L"IDS_ST_BODY_CANCEL"));
69 pFooter->AddItem(footerUnInstall);
70 pFooter->AddItem(footerCancel);
71 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, true);
72 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, false);
74 pFooter->AddActionEventListener(*this);
76 SetFormBackEventListener(this);
80 CertificateUserUnInstallForm::OnInitializing(void)
82 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
83 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_USER_CERTIFICATES"));
86 EnableUnInstallFooter(true);
87 return InitCertificatePresentationModelInstance();
91 CertificateUserUnInstallForm::OnTerminating(void)
95 SetFormBackEventListener(null);
100 CertificateUserUnInstallForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
102 __pTableView->UpdateTableView();
106 CertificateUserUnInstallForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
111 CertificateUserUnInstallForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
113 SceneManager* pSceneManager = SceneManager::GetInstance();
114 AppAssert(pSceneManager);
116 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
120 CertificateUserUnInstallForm::GetGroupCount(void)
122 AppLogDebug("ENTER");
123 return ID_GROUP_COUNT;
127 CertificateUserUnInstallForm::GetItemCount(int groupIndex)
129 return GetUserCertificateStoreCount();
133 CertificateUserUnInstallForm::CreateGroupItem(int groupIndex, int itemWidth)
137 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
139 pItem->Construct(Dimension(itemWidth, itemHeight));
140 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
142 pItem->SetEnabled(false);
148 CertificateUserUnInstallForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
150 Rectangle itemMainRectangle;
151 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
152 int fontSize = GetFontSize();
153 String itemMainText = CertificatePresentationModelUtility::GetCommonName(
154 __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
155 if (IsFailed(GetLastResult()))
157 AppLogDebug("GetSubjectNameFromCertifcateStore(%d) failed(%s)", itemIndex, GetErrorMessage(GetLastResult()));
160 TableViewItem* pItem = new (std::nothrow) TableViewItem();
162 ItemTypeOneLine(itemMainRectangle);
164 RelativeLayout relativeLayout;
165 relativeLayout.Construct();
167 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
168 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
170 Label* pLabel = new (std::nothrow) Label();
171 pLabel->Construct(itemMainRectangle, itemMainText);
172 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
173 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
174 pLabel->SetTextColor(COLOR_MAIN_TEXT);
176 pItem->AddControl(pLabel);
177 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_RADIO_BUTTON_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
178 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
179 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
185 CertificateUserUnInstallForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
187 AppLogDebug("ENTER");
196 CertificateUserUnInstallForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
198 AppLogDebug("ENTER");
207 CertificateUserUnInstallForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
212 CertificateUserUnInstallForm::GetDefaultGroupItemHeight(void)
214 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
218 CertificateUserUnInstallForm::GetDefaultItemHeight(void)
220 return H_GROUP_ITEM_DEFAULT;
224 CertificateUserUnInstallForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
229 CertificateUserUnInstallForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
234 CertificateUserUnInstallForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
239 CertificateUserUnInstallForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
244 CertificateUserUnInstallForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
246 SceneManager* pSceneManager = SceneManager::GetInstance();
247 AppAssert(pSceneManager);
251 case IDA_CERTIFICATE_USER_FORM_FOOTER_CANCEL:
253 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
257 case IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL:
259 for (int i = 0; i < GetUserCertificateStoreCount(); i++)
261 if (__pTableView->IsItemChecked(0, i) == true)
263 ICertificate* pICertificate =__pCertificatePresentationModelInstance->GetCertificateFromCertificateStoreN(0);
264 if (pICertificate == null)
269 AppLogDebug("Certificate info [%ls]", pICertificate->GetSubject().GetPointer());
270 result r = __pCertificatePresentationModelInstance->RemoveFromCertificateStore(*pICertificate);
271 AppLogDebug("%s", GetErrorMessage(r));
274 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
284 CertificateUserUnInstallForm::InitCertificatePresentationModelInstance(void)
286 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
287 if (__pCertificatePresentationModelInstance == null)
292 __pCertificatePresentationModelInstance->UpdateCertificateListFromCertificateStore();
293 if (__pCertificatePresentationModelInstance->GetCertificateStoreCount() != 0)
295 EnableCancelFooter(true);
302 CertificateUserUnInstallForm::GetUserCertificateStoreCount(void)
304 return __pCertificatePresentationModelInstance->GetCertificateStoreCount();
308 CertificateUserUnInstallForm::EnableUnInstallFooter(bool status)
310 Footer* pFooter = GetFooter();
315 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, true);
316 pFooter->Invalidate(true);
320 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, false);
321 pFooter->Invalidate(false);
326 CertificateUserUnInstallForm::EnableCancelFooter(bool status)
328 Footer* pFooter = GetFooter();
333 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, true);
334 pFooter->Invalidate(true);
338 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, false);
339 pFooter->Invalidate(false);
344 CertificateUserUnInstallForm::CreateTableView(void)
346 if (__pTableView != null)
348 AppLogDebug("__pTableView is not null");
351 Rectangle tableViewBounds = GetClientAreaBounds();
352 tableViewBounds.y = Y_GROUP_DEFAULT;
354 __pTableView = new (std::nothrow) GroupedTableView();
355 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
356 __pTableView->SetItemProvider(this);
357 AddControl(__pTableView);
358 __pTableView->SetGroupedLookEnabled(true);
359 __pTableView->AddGroupedTableViewItemEventListener(*this);
360 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
361 if (pRelativeLayout != null)
363 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
364 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
365 delete pRelativeLayout;