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 StCertificateUserInstallForm.cpp
19 * @brief This is the implementation file for CertificateUserInstallForm class.
23 #include "StCertificateUserInstallForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Security::Cert;
31 using namespace Tizen::System;
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;
38 CertificateUserInstallForm::CertificateUserInstallForm(void)
39 : __pCertificatePresentationModelInstance(null)
43 CertificateUserInstallForm::~CertificateUserInstallForm(void)
48 CertificateUserInstallForm::CreateFooter(void)
50 Footer* pFooter = GetFooter();
53 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
54 pFooter->SetBackButton();
55 pFooter->AddActionEventListener(*this);
57 SetFormBackEventListener(this);
61 CertificateUserInstallForm::OnInitializing(void)
63 return InitCertificatePresentationModelInstance();
67 CertificateUserInstallForm::OnTerminating(void)
69 ReleaseCertificatePresentationModelInstance();
73 SetFormBackEventListener(null);
78 CertificateUserInstallForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
80 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_SELECT_CERTIFICATE_TO_INSTALL"));
83 if (__pTableView != null)
85 int tableViewControlCount = __pTableView->GetControlCount();
86 for (int i = 0; i < tableViewControlCount; i++)
88 __pTableView->RemoveControl(__pTableView->GetControl(0));
90 // __pTableView->RemoveAllControls();
93 int controlCount = GetControlCount();
94 for (int i = 0; i < controlCount; i++)
96 RemoveControl(GetControl(0));
98 // RemoveAllControls();
99 result r = __pCertificatePresentationModelInstance->FindUserCertificateToInstallFromStorage();
102 AppLogDebug("FindUserCertificateToInstallFromStorage is error %s", GetErrorMessage(r));
106 if (__pCertificatePresentationModelInstance->GetFoundUserCertificateToInstallListCount() != 0)
109 __pTableView->UpdateTableView();
113 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
116 Rectangle clientRect = GetClientAreaBounds();
117 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
119 int bitmapWidth = pBitmp->GetWidth();
120 int bitmapHeight = pBitmp->GetHeight();
121 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
122 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
123 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
125 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
126 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
128 Label* pLabel = new (std::nothrow) Label();
129 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
130 pLabel->SetName(NO_CONTENTS);
131 pLabel->SetBackgroundBitmap(*pBitmp);
133 yPos = yPos + bitmapHeight;
135 Label* pLabelNoContents = new (std::nothrow) Label();
136 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
137 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
138 pLabelNoContents->SetTextColor(textColor);
139 pLabelNoContents->SetText(labelText);
142 AddControl(pLabelNoContents);
148 CertificateUserInstallForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
153 CertificateUserInstallForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
155 SceneManager* pSceneManager = SceneManager::GetInstance();
156 AppAssert(pSceneManager);
158 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
162 CertificateUserInstallForm::GetGroupCount(void)
164 AppLogDebug("ENTER");
165 return ID_GROUP_COUNT;
169 CertificateUserInstallForm::GetItemCount(int groupIndex)
171 return __pCertificatePresentationModelInstance->GetFoundUserCertificateToInstallListCount();
175 CertificateUserInstallForm::CreateGroupItem(int groupIndex, int itemWidth)
179 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
181 pItem->Construct(Dimension(itemWidth, itemHeight));
182 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
183 pItem->SetEnabled(false);
189 CertificateUserInstallForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
191 Rectangle itemMainRectangle;
192 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
193 int fontSize = GetFontSize();
195 String itemMainText = __pCertificatePresentationModelInstance->GetFileNameInFoundUserCertificateToInstallListAt(itemIndex);
196 if (IsFailed(GetLastResult()))
198 AppLogDebug("GetFileNameInFoundUserCertificateToInstallListAt failed(%s)", GetErrorMessage(GetLastResult()));
201 TableViewItem* pItem = new (std::nothrow) TableViewItem();
203 RelativeLayout relativeLayout;
204 relativeLayout.Construct();
206 result r = pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
209 AppLogDebug("Construct failed(%s)", GetErrorMessage(r));
213 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
215 ItemTypeOneLine(itemMainRectangle);
216 Label* pLabel = new (std::nothrow) Label();
217 r = pLabel->Construct(itemMainRectangle, itemMainText);
220 AppLogDebug("Construct failed(%s)", GetErrorMessage(r));
224 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
225 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
226 pLabel->SetTextColor(COLOR_MAIN_TEXT);
228 pItem->AddControl(pLabel);
229 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
230 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
231 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
237 CertificateUserInstallForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
239 AppLogDebug("ENTER");
248 CertificateUserInstallForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
250 AppLogDebug("ENTER");
259 CertificateUserInstallForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
261 SceneManager* pSceneManager = SceneManager::GetInstance();
262 AppAssert(pSceneManager);
263 String fileName = __pCertificatePresentationModelInstance->GetFileNameInFoundUserCertificateToInstallListAt(itemIndex);
264 if (IsFailed(GetLastResult()))
266 AppLogDebug("GetFileNameInFoundUserCertificateToInstallListAt failed(%s)", GetErrorMessage(GetLastResult()));
269 String extrnalStoragePath = Environment::GetExternalStoragePath();
270 extrnalStoragePath.Append(fileName);
271 __pCertificatePresentationModelInstance->ClearPendingUserCertificateFileNameToInstall();
272 bool isPending = __pCertificatePresentationModelInstance->PushPendingUserCertificateFileNameToInstall(extrnalStoragePath);
273 if (isPending == false)
275 AppLogDebug("PushPendingCertificate failed");
278 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE_USER_INSTALL_PASSWORD, SCENE_TRANSITION_ANIMATION_TYPE_LEFT,
279 SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), null);
283 CertificateUserInstallForm::GetDefaultGroupItemHeight(void)
285 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
289 CertificateUserInstallForm::GetDefaultItemHeight(void)
291 return H_GROUP_ITEM_DEFAULT;
295 CertificateUserInstallForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
300 CertificateUserInstallForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
305 CertificateUserInstallForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
310 CertificateUserInstallForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
315 CertificateUserInstallForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
317 BaseForm::OnOrientationChanged(source, orientationStatus);
318 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
321 Rectangle clientRect = GetClientAreaBounds();
322 Rectangle labelBound = pLabel->GetBounds();
324 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
325 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
327 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
328 yPos = yPos + pLabel->GetBounds().height;
329 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
330 if (pTextLabel != null)
332 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
339 CertificateUserInstallForm::InitCertificatePresentationModelInstance(void)
341 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
342 if (__pCertificatePresentationModelInstance == null)
346 CertificateType certufucatetype = __pCertificatePresentationModelInstance->GetCertificateSelectorType();
347 if (certufucatetype != USER_CERT)
349 result r = __pCertificatePresentationModelInstance->SetCertificateSelector(USER_CERT);
352 AppLogDebug("SetCertificateSelector failed(%s)", GetErrorMessage(r));
360 CertificateUserInstallForm::ReleaseCertificatePresentationModelInstance(void)
362 __pCertificatePresentationModelInstance = null;
366 CertificateUserInstallForm::CreateTableView(void)
368 if (__pTableView != null)
370 AppLogDebug("__pTableView is not null");
373 Rectangle tableViewBounds = GetClientAreaBounds();
374 tableViewBounds.y = Y_GROUP_DEFAULT;
376 __pTableView = new (std::nothrow) GroupedTableView();
377 __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
378 __pTableView->SetItemProvider(this);
379 __pTableView->SetGroupedLookEnabled(true);
380 __pTableView->AddGroupedTableViewItemEventListener(*this);
381 RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
382 if (pRelativeLayout != null)
384 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
385 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
386 delete pRelativeLayout;
389 AddControl(__pTableView);