Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StCertificateUserUnInstallForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                StCertificateUserUnInstallForm.cpp
19  * @brief               This is the implementation file for CertificateUserUnInstallForm class.
20  */
21
22 #include "StCertificateUserUnInstallForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
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;
33
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;
37
38 static const int ID_GROUP_COUNT = 1;
39 static const int ID_ITEM_COUNT_MAX = 0;
40
41 static const int ID_FOOTER_UNINSTALL = 0;
42 static const int ID_FOOTER_CANCEL = 1;
43
44 static const int RELATIVE_LAYOUT_LEFT_RADIO_BUTTON_MARGIN = 80;
45
46 CertificateUserUnInstallForm::CertificateUserUnInstallForm(void)
47         : __pCertificatePresentationModelInstance(null)
48 {
49 }
50
51 CertificateUserUnInstallForm::~CertificateUserUnInstallForm(void)
52 {
53 }
54
55 void
56 CertificateUserUnInstallForm::CreateFooter(void)
57 {
58         Footer* pFooter = GetFooter();
59         AppAssert(pFooter);
60
61         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
62
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);
73
74         pFooter->SetBackButton();
75         pFooter->AddActionEventListener(*this);
76
77         SetFormBackEventListener(this);
78 }
79
80 result
81 CertificateUserUnInstallForm::OnInitializing(void)
82 {
83
84         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_USER_CERTIFICATES"));
85         CreateFooter();
86         CreateTableView();
87         EnableUnInstallFooter(true);
88         return InitCertificatePresentationModelInstance();
89 }
90
91 result
92 CertificateUserUnInstallForm::OnTerminating(void)
93 {
94         __pTableView = null;
95
96         SetFormBackEventListener(null);
97         return E_SUCCESS;
98 }
99
100 void
101 CertificateUserUnInstallForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
102 {
103         __pTableView->UpdateTableView();
104 }
105
106 void
107 CertificateUserUnInstallForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
108 {
109 }
110
111 void
112 CertificateUserUnInstallForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
113 {
114         SceneManager* pSceneManager = SceneManager::GetInstance();
115         AppAssert(pSceneManager);
116
117         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
118 }
119
120 int
121 CertificateUserUnInstallForm::GetGroupCount(void)
122 {
123         AppLogDebug("ENTER");
124         return ID_GROUP_COUNT;
125 }
126
127 int
128 CertificateUserUnInstallForm::GetItemCount(int groupIndex)
129 {
130         return GetUserCertificateStoreCount();
131 }
132
133 TableViewGroupItem*
134 CertificateUserUnInstallForm::CreateGroupItem(int groupIndex, int itemWidth)
135 {
136         int itemHeight = 0;
137
138         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
139
140         pItem->Construct(Dimension(itemWidth, itemHeight));
141         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
142
143         pItem->SetEnabled(false);
144
145         return pItem;
146 }
147
148 TableViewItem*
149 CertificateUserUnInstallForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
150 {
151         Rectangle itemMainRectangle;
152         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
153         int fontSize = GetFontSize();
154         String itemMainText = CertificatePresentationModelUtility::GetCommonName(
155                                                         __pCertificatePresentationModelInstance->GetSubjectNameFromCertifcateStore(itemIndex));
156         if (IsFailed(GetLastResult()))
157         {
158                 AppLogDebug("GetSubjectNameFromCertifcateStore(%d) failed(%s)", itemIndex, GetErrorMessage(GetLastResult()));
159                 return null;
160         }
161         TableViewItem* pItem = new (std::nothrow) TableViewItem();
162
163         ItemTypeOneLine(itemMainRectangle);
164
165         RelativeLayout relativeLayout;
166         relativeLayout.Construct();
167
168         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
169         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
170
171         Label* pLabel = new (std::nothrow) Label();
172         pLabel->Construct(itemMainRectangle, itemMainText);
173         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
174         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
175         pLabel->SetTextColor(COLOR_MAIN_TEXT);
176
177         pItem->AddControl(pLabel);
178         relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_RADIO_BUTTON_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
179         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
180         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
181
182         return pItem;
183 }
184
185 bool
186 CertificateUserUnInstallForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
187 {
188         AppLogDebug("ENTER");
189
190         delete pItem;
191         pItem = null;
192
193         return true;
194 }
195
196 bool
197 CertificateUserUnInstallForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
198 {
199         AppLogDebug("ENTER");
200
201         delete pItem;
202         pItem = null;
203
204         return true;
205 }
206
207 void
208 CertificateUserUnInstallForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
209 {
210 }
211
212 int
213 CertificateUserUnInstallForm::GetDefaultGroupItemHeight(void)
214 {
215         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
216 }
217
218 int
219 CertificateUserUnInstallForm::GetDefaultItemHeight(void)
220 {
221         return H_GROUP_ITEM_DEFAULT;
222 }
223
224 void
225 CertificateUserUnInstallForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
226 {
227 }
228
229 void
230 CertificateUserUnInstallForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
231 {
232 }
233
234 void
235 CertificateUserUnInstallForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
236 {
237 }
238
239 void
240 CertificateUserUnInstallForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
241 {
242 }
243
244 void
245 CertificateUserUnInstallForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
246 {
247         SceneManager* pSceneManager = SceneManager::GetInstance();
248         AppAssert(pSceneManager);
249
250         switch (actionId)
251         {
252         case IDA_CERTIFICATE_USER_FORM_FOOTER_CANCEL:
253                 {
254                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
255                 }
256                 break;
257
258         case IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL:
259                 {
260                         for (int i = 0; i < GetUserCertificateStoreCount(); i++)
261                         {
262                                 if (__pTableView->IsItemChecked(0, i) == true)
263                                 {
264                                         ICertificate* pICertificate =__pCertificatePresentationModelInstance->GetCertificateFromCertificateStoreN(0);
265                                         if (pICertificate == null)
266                                         {
267                                                 AppLogDebug("null");
268                                                 return;
269                                         }
270                                         AppLogDebug("Certificate info [%ls]", pICertificate->GetSubject().GetPointer());
271                                         result r = __pCertificatePresentationModelInstance->RemoveFromCertificateStore(*pICertificate);
272                                         AppLogDebug("%s", GetErrorMessage(r));
273                                 }
274                         }
275                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
276                 }
277                 break;
278
279         default:
280                 break;
281         }
282 }
283
284 result
285 CertificateUserUnInstallForm::InitCertificatePresentationModelInstance(void)
286 {
287         __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
288         if (__pCertificatePresentationModelInstance == null)
289         {
290                 return E_FAILURE;
291         }
292
293         __pCertificatePresentationModelInstance->UpdateCertificateListFromCertificateStore();
294         if (__pCertificatePresentationModelInstance->GetCertificateStoreCount() != 0)
295         {
296                 EnableCancelFooter(true);
297                 return E_SUCCESS;
298         }
299         return E_FAILURE;
300 }
301
302 int
303 CertificateUserUnInstallForm::GetUserCertificateStoreCount(void)
304 {
305         return __pCertificatePresentationModelInstance->GetCertificateStoreCount();
306 }
307
308 void
309 CertificateUserUnInstallForm::EnableUnInstallFooter(bool status)
310 {
311         Footer* pFooter = GetFooter();
312         AppAssert(pFooter);
313
314         if (status == true)
315         {
316                 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, true);
317                 pFooter->Invalidate(true);
318         }
319         else
320         {
321                 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, false);
322                 pFooter->Invalidate(false);
323         }
324 }
325
326 void
327 CertificateUserUnInstallForm::EnableCancelFooter(bool status)
328 {
329         Footer* pFooter = GetFooter();
330         AppAssert(pFooter);
331
332         if (status == true)
333         {
334                 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, true);
335                 pFooter->Invalidate(true);
336         }
337         else
338         {
339                 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, false);
340                 pFooter->Invalidate(false);
341         }
342 }
343
344 void
345 CertificateUserUnInstallForm::CreateTableView(void)
346 {
347         if (__pTableView != null)
348         {
349                 AppLogDebug("__pTableView is not null");
350                 return;
351         }
352         Rectangle tableViewBounds = GetClientAreaBounds();
353         tableViewBounds.y = Y_GROUP_DEFAULT;
354
355         __pTableView = new (std::nothrow) GroupedTableView();
356         __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
357         __pTableView->SetItemProvider(this);
358         AddControl(__pTableView);
359         __pTableView->SetGroupedLookEnabled(true);
360         __pTableView->AddGroupedTableViewItemEventListener(*this);
361         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
362         if (pRelativeLayout != null)
363         {
364                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
365                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
366                 delete pRelativeLayout;
367         }
368 }