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->AddActionEventListener(*this);
56 SetFormBackEventListener(this);
60 CertificateUserInstallForm::OnInitializing(void)
62 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
63 return InitCertificatePresentationModelInstance();
67 CertificateUserInstallForm::OnTerminating(void)
69 ReleaseCertificatePresentationModelInstance();
71 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
74 SetFormBackEventListener(null);
79 CertificateUserInstallForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
81 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_ADD_HISTORY, SCENE_DESTROY_OPTION_KEEP), 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)
297 Rectangle itemBounds = pItem->GetBounds();
298 Rectangle areaBounds = GetClientAreaBounds();
299 itemBounds.width = areaBounds.width;
300 pItem->SetBounds(itemBounds);
301 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
302 pItem->SetEnabled(false);
303 pItem->Invalidate(false);
307 CertificateUserInstallForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
309 Rectangle itemMainRectangle;
310 Rectangle itemBounds = pItem->GetBounds();
311 Rectangle areaBounds = GetClientAreaBounds();
312 itemBounds.width = areaBounds.width;
313 Rectangle pLabelBounds;
314 int fontSize = GetFontSize();
316 String itemMainText = __pCertificatePresentationModelInstance->GetFileNameInFoundUserCertificateToInstallListAt(itemIndex);
317 if (IsFailed(GetLastResult()))
319 AppLogDebug("GetFileNameInFoundUserCertificateToInstallListAt failed(%s)", GetErrorMessage(GetLastResult()));
322 itemBounds.height = H_ITEM_TYPE_1_LABEL;
323 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
324 pItem->SetBounds(itemBounds);
326 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
327 pLabelBounds = pLabel->GetBounds();
328 pLabelBounds.width = areaBounds.width;
329 pLabelBounds.height = itemBounds.height;
331 pLabel->SetBounds(pLabelBounds);
332 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
333 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
334 pLabel->SetTextColor(COLOR_MAIN_TEXT);
335 pLabel->SetText(itemMainText);
336 pLabel->Invalidate(false);
337 pItem->Invalidate(false);
341 CertificateUserInstallForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
346 CertificateUserInstallForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
351 CertificateUserInstallForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
353 BaseForm::OnOrientationChanged(source, orientationStatus);
354 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
357 Rectangle clientRect = GetClientAreaBounds();
358 Rectangle labelBound = pLabel->GetBounds();
360 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
361 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
363 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
364 yPos = yPos + pLabel->GetBounds().height;
365 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
366 if (pTextLabel != null)
368 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
372 __pTableView->RefreshAllItems();
377 CertificateUserInstallForm::InitCertificatePresentationModelInstance(void)
379 __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
380 if (__pCertificatePresentationModelInstance == null)
384 CertificateType certufucatetype = __pCertificatePresentationModelInstance->GetCertificateSelectorType();
385 if (certufucatetype != USER_CERT)
387 result r = __pCertificatePresentationModelInstance->SetCertificateSelector(USER_CERT);
390 AppLogDebug("SetCertificateSelector failed(%s)", GetErrorMessage(r));
398 CertificateUserInstallForm::ReleaseCertificatePresentationModelInstance(void)
400 __pCertificatePresentationModelInstance = null;
404 CertificateUserInstallForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
407 if (deviceType == DEVICE_TYPE_STORAGE_CARD)
409 result r = __pCertificatePresentationModelInstance->FindUserCertificateToInstallFromStorage();
412 AppLogDebug("FindUserCertificateToInstallFromStorage is error %s", GetErrorMessage(r));
415 if (__pCertificatePresentationModelInstance->GetFoundUserCertificateToInstallListCount() != 0)
418 __pTableView->UpdateTableView();
419 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
422 pLabel->SetShowState(false);
423 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
424 if (pTextLabel != null)
426 pTextLabel->SetShowState(false);
432 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
435 pLabel->SetShowState(true);
437 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
438 if (pTextLabel != null)
440 pTextLabel->SetShowState(true);
443 if (__pTableView != null)
445 __pTableView->UpdateTableView();