Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StCertificateForm.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                StCertificateForm.cpp
19  * @brief               This is the implementation file for CertificateForm class.
20  */
21
22 #include "StCertificateForm.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::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
32
33 static const int ID_GROUP_CERTIFICATES_MAIN = 0;
34 static const int ID_GROUP_CERTIFICATES_MAIN_ITEM_COUNT = 2;
35 static const int ID_ITEM_TRUSTED_ROOT_CERTIFICATES = 0;
36 static const int ID_ITEM_USER_CERTIFICATES = 1;
37
38 static const int ID_GROUP_COUNT = 1;
39 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_CERTIFICATES_MAIN_ITEM_COUNT;
40
41 CertificateForm::CertificateForm(void)
42 {
43 }
44
45 CertificateForm::~CertificateForm(void)
46 {
47 }
48
49 void
50 CertificateForm::CreateFooter(void)
51 {
52         Footer* pFooter = GetFooter();
53         AppAssert(pFooter);
54
55         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
56         pFooter->SetBackButton();
57         pFooter->AddActionEventListener(*this);
58
59         SetFormBackEventListener(this);
60 }
61
62 result
63 CertificateForm::OnInitializing(void)
64 {
65         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_CERTIFICATES"));
66         CreateFooter();
67         CreateTableView();
68
69         AppLogDebug("ENTER");
70
71         return E_SUCCESS;
72 }
73
74 void
75 CertificateForm::CreateTableView(void)
76 {
77         Rectangle tableViewBounds = GetClientAreaBounds();
78         tableViewBounds.y = Y_GROUP_DEFAULT;
79
80         __pTableView = new (std::nothrow) GroupedTableView();
81
82         __pTableView->Construct(tableViewBounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
83         __pTableView->SetItemProvider(this);
84
85         AddControl(__pTableView);
86         __pTableView->SetGroupedLookEnabled(true);
87         __pTableView->AddGroupedTableViewItemEventListener(*this);
88         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
89         if (pRelativeLayout != null)
90         {
91                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
92                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
93                 delete pRelativeLayout;
94         }
95 }
96
97 result
98 CertificateForm::OnTerminating(void)
99 {
100         __pTableView = null;
101
102         SetFormBackEventListener(null);
103         return E_SUCCESS;
104 }
105
106 void
107 CertificateForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
108 {
109         __pTableView->UpdateTableView();
110 }
111
112 void
113 CertificateForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
114 {
115 }
116
117 void
118 CertificateForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
119 {
120         SceneManager* pSceneManager = SceneManager::GetInstance();
121         AppAssert(pSceneManager);
122
123         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
124 }
125
126 int
127 CertificateForm::GetGroupCount(void)
128 {
129         AppLogDebug("ENTER");
130         return ID_GROUP_COUNT;
131 }
132
133 int
134 CertificateForm::GetItemCount(int groupIndex)
135 {
136         int itemCount = ID_GROUP_MAX_ITEM_COUNT;
137         return itemCount;
138 }
139
140 TableViewGroupItem*
141 CertificateForm::CreateGroupItem(int groupIndex, int itemWidth)
142 {
143         AppLogDebug("ENTER");
144
145         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
146         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
147         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
148         Rectangle itemMainRectangle;
149         String groupText;
150         Label* pLabel = null;
151
152         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
153
154         yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
155         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
156
157         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
158         itemMainRectangle.y = yItemOffset;
159         itemMainRectangle.width = itemWidth;
160         itemMainRectangle.height = itemHeight;
161
162         RelativeLayout relativeLayout;
163         relativeLayout.Construct();
164
165         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
166         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
167
168         pLabel = new (std::nothrow) Label();
169         pLabel->Construct(itemMainRectangle, groupText);
170         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
171         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
172         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
173         pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
174
175         pItem->AddControl(pLabel);
176         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 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         pItem->SetEnabled(false);
180
181         return pItem;
182 }
183
184 TableViewItem*
185 CertificateForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
186 {
187         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
188
189         Rectangle itemMainRectangle;
190         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
191         String itemMainText;
192         Label* pLabel = null;
193         int fontSize = GetFontSize();
194
195         switch (itemIndex)
196         {
197         case ID_ITEM_TRUSTED_ROOT_CERTIFICATES:
198                 {
199                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_TRUSTED_ROOT_CERTIFICATES");
200                 }
201                 break;
202
203         case ID_ITEM_USER_CERTIFICATES:
204                 {
205                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_USER_CERTIFICATES");
206                 }
207                 break;
208
209         default:
210                 break;
211         }
212         TableViewItem* pItem = new (std::nothrow) TableViewItem();
213
214         ItemTypeOneLine(itemMainRectangle);
215
216         RelativeLayout relativeLayout;
217         relativeLayout.Construct();
218
219         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
220         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
221
222         pLabel = new (std::nothrow) Label();
223         pLabel->Construct(itemMainRectangle, itemMainText);
224         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
225         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
226         pLabel->SetTextColor(COLOR_MAIN_TEXT);
227
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);
232
233         return pItem;
234 }
235
236 bool
237 CertificateForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
238 {
239         AppLogDebug("ENTER");
240
241         delete pItem;
242         pItem = null;
243
244         return true;
245 }
246
247 bool
248 CertificateForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
249 {
250         AppLogDebug("ENTER");
251
252         delete pItem;
253         pItem = null;
254
255         return true;
256 }
257
258 void
259 CertificateForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
260 {
261         SceneManager* pSceneManager = SceneManager::GetInstance();
262         AppAssert(pSceneManager);
263
264         switch (itemIndex)
265         {
266         case ID_ITEM_USER_CERTIFICATES:
267                 {
268                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE_USER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
269                 }
270                 break;
271
272         default:
273                 {
274                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE_LIST, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
275                 }
276                 break;
277         }
278         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
279 }
280
281 int
282 CertificateForm::GetDefaultGroupItemHeight(void)
283 {
284         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
285 }
286
287 int
288 CertificateForm::GetDefaultItemHeight(void)
289 {
290         return H_GROUP_ITEM_DEFAULT;
291 }
292
293 void
294 CertificateForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
295 {
296 }
297
298 void
299 CertificateForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
300 {
301 }
302
303 void
304 CertificateForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
305 {
306 }
307
308 void
309 CertificateForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
310 {
311 }