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