NABI issues N_SE-50115, N_SE-50067, N_SE-49946, N_SE-49897, N_SE-49884, N_SE-48837...
[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->AddActionEventListener(*this);
75
76         SetFormBackEventListener(this);
77 }
78
79 result
80 CertificateUserUnInstallForm::OnInitializing(void)
81 {
82         SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
83         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_USER_CERTIFICATES"));
84         CreateFooter();
85         CreateTableView();
86         EnableUnInstallFooter(true);
87         return InitCertificatePresentationModelInstance();
88 }
89
90 result
91 CertificateUserUnInstallForm::OnTerminating(void)
92 {
93         __pTableView = null;
94
95         SetFormBackEventListener(null);
96         return E_SUCCESS;
97 }
98
99 void
100 CertificateUserUnInstallForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
101 {
102         __pTableView->UpdateTableView();
103 }
104
105 void
106 CertificateUserUnInstallForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
107 {
108 }
109
110 void
111 CertificateUserUnInstallForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
112 {
113         SceneManager* pSceneManager = SceneManager::GetInstance();
114         AppAssert(pSceneManager);
115
116         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
117 }
118
119 int
120 CertificateUserUnInstallForm::GetGroupCount(void)
121 {
122         AppLogDebug("ENTER");
123         return ID_GROUP_COUNT;
124 }
125
126 int
127 CertificateUserUnInstallForm::GetItemCount(int groupIndex)
128 {
129         return GetUserCertificateStoreCount();
130 }
131
132 TableViewGroupItem*
133 CertificateUserUnInstallForm::CreateGroupItem(int groupIndex, int itemWidth)
134 {
135         int itemHeight = 0;
136
137         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
138
139         pItem->Construct(Dimension(itemWidth, itemHeight));
140         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
141
142         pItem->SetEnabled(false);
143
144         return pItem;
145 }
146
147 TableViewItem*
148 CertificateUserUnInstallForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
149 {
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()))
156         {
157                 AppLogDebug("GetSubjectNameFromCertifcateStore(%d) failed(%s)", itemIndex, GetErrorMessage(GetLastResult()));
158                 return null;
159         }
160         TableViewItem* pItem = new (std::nothrow) TableViewItem();
161
162         ItemTypeOneLine(itemMainRectangle);
163
164         RelativeLayout relativeLayout;
165         relativeLayout.Construct();
166
167         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
168         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
169
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);
175
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);
180
181         return pItem;
182 }
183
184 bool
185 CertificateUserUnInstallForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
186 {
187         AppLogDebug("ENTER");
188
189         delete pItem;
190         pItem = null;
191
192         return true;
193 }
194
195 bool
196 CertificateUserUnInstallForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
197 {
198         AppLogDebug("ENTER");
199
200         delete pItem;
201         pItem = null;
202
203         return true;
204 }
205
206 void
207 CertificateUserUnInstallForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
208 {
209 }
210
211 int
212 CertificateUserUnInstallForm::GetDefaultGroupItemHeight(void)
213 {
214         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
215 }
216
217 int
218 CertificateUserUnInstallForm::GetDefaultItemHeight(void)
219 {
220         return H_GROUP_ITEM_DEFAULT;
221 }
222
223 void
224 CertificateUserUnInstallForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
225 {
226 }
227
228 void
229 CertificateUserUnInstallForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
230 {
231 }
232
233 void
234 CertificateUserUnInstallForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
235 {
236 }
237
238 void
239 CertificateUserUnInstallForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
240 {
241 }
242
243 void
244 CertificateUserUnInstallForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
245 {
246         SceneManager* pSceneManager = SceneManager::GetInstance();
247         AppAssert(pSceneManager);
248
249         switch (actionId)
250         {
251         case IDA_CERTIFICATE_USER_FORM_FOOTER_CANCEL:
252                 {
253                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
254                 }
255                 break;
256
257         case IDA_CERTIFICATE_USER_FORM_FOOTER_UNINSTALL:
258                 {
259                         for (int i = 0; i < GetUserCertificateStoreCount(); i++)
260                         {
261                                 if (__pTableView->IsItemChecked(0, i) == true)
262                                 {
263                                         ICertificate* pICertificate =__pCertificatePresentationModelInstance->GetCertificateFromCertificateStoreN(0);
264                                         if (pICertificate == null)
265                                         {
266                                                 AppLogDebug("null");
267                                                 return;
268                                         }
269                                         AppLogDebug("Certificate info [%ls]", pICertificate->GetSubject().GetPointer());
270                                         result r = __pCertificatePresentationModelInstance->RemoveFromCertificateStore(*pICertificate);
271                                         AppLogDebug("%s", GetErrorMessage(r));
272                                 }
273                         }
274                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
275                 }
276                 break;
277
278         default:
279                 break;
280         }
281 }
282
283 result
284 CertificateUserUnInstallForm::InitCertificatePresentationModelInstance(void)
285 {
286         __pCertificatePresentationModelInstance = CertificatePresentationModel::GetInstance();
287         if (__pCertificatePresentationModelInstance == null)
288         {
289                 return E_FAILURE;
290         }
291
292         __pCertificatePresentationModelInstance->UpdateCertificateListFromCertificateStore();
293         if (__pCertificatePresentationModelInstance->GetCertificateStoreCount() != 0)
294         {
295                 EnableCancelFooter(true);
296                 return E_SUCCESS;
297         }
298         return E_FAILURE;
299 }
300
301 int
302 CertificateUserUnInstallForm::GetUserCertificateStoreCount(void)
303 {
304         return __pCertificatePresentationModelInstance->GetCertificateStoreCount();
305 }
306
307 void
308 CertificateUserUnInstallForm::EnableUnInstallFooter(bool status)
309 {
310         Footer* pFooter = GetFooter();
311         AppAssert(pFooter);
312
313         if (status == true)
314         {
315                 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, true);
316                 pFooter->Invalidate(true);
317         }
318         else
319         {
320                 pFooter->SetItemEnabled(ID_FOOTER_UNINSTALL, false);
321                 pFooter->Invalidate(false);
322         }
323 }
324
325 void
326 CertificateUserUnInstallForm::EnableCancelFooter(bool status)
327 {
328         Footer* pFooter = GetFooter();
329         AppAssert(pFooter);
330
331         if (status == true)
332         {
333                 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, true);
334                 pFooter->Invalidate(true);
335         }
336         else
337         {
338                 pFooter->SetItemEnabled(ID_FOOTER_CANCEL, false);
339                 pFooter->Invalidate(false);
340         }
341 }
342
343 void
344 CertificateUserUnInstallForm::CreateTableView(void)
345 {
346         if (__pTableView != null)
347         {
348                 AppLogDebug("__pTableView is not null");
349                 return;
350         }
351         Rectangle tableViewBounds = GetClientAreaBounds();
352         tableViewBounds.y = Y_GROUP_DEFAULT;
353
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)
362         {
363                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
364                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
365                 delete pRelativeLayout;
366         }
367 }