Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StWifiConnectionForm.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                StWifiConnectionForm.cpp
19  * @brief               This is the implementation file for WifiConnectionForm class.
20  */
21
22 #include "StResourceManager.h"
23 #include "StSettingScenesList.h"
24 #include "StTypes.h"
25 #include "StWifiConnectionForm.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_WIFI_EAP_CONNECT_MAIN = 0;
34 static const int ID_GROUP_WIFI_EAP_CONNECT_MAIN_ITEM_COUNT = 8;
35 static const int ID_ITEM_WIFI_EAP_CONNECT_EAP_METHOD = 0;
36 static const int ID_ITEM_WIFI_EAP_CONNECT_PROVISIONING = 1;
37 static const int ID_ITEM_WIFI_EAP_CONNECT_PHASE_2_AUTHENTICATION = 2;
38 static const int ID_ITEM_WIFI_EAP_CONNECT_CA_CERTIFICATE = 3;
39 static const int ID_ITEM_WIFI_EAP_CONNECT_USER_CERTIFICATE = 4;
40 static const int ID_ITEM_WIFI_EAP_CONNECT_IDENTITY = 5;
41 static const int ID_ITEM_WIFI_EAP_CONNECT_ANONUMOUS_IDENTITY = 6;
42 static const int ID_ITEM_WIFI_EAP_CONNECT_PASSWORD = 7;
43
44 static const int ID_GROUP_WIFI_EAP_CONNECT_IP = 1;
45 static const int ID_GROUP_WIFI_EAP_CONNECT_IP_ITEM_COUNT = 2;
46 static const int ID_ITEM_WIFI_EAP_CONNECT_STATIC_IP = 0;
47 static const int ID_ITEM_WIFI_EAP_CONNECT_IP_ADDRESS = 1;
48
49 static const int ID_GROUP_WIFI_EAP_CONNECT_ADDRESS = 2;
50 static const int ID_GROUP_WIFI_EAP_CONNECT_ADDRESS_ITEM_COUNT = 3;
51 static const int ID_ITEM_WIFI_EAP_CONNECT_MAC_ADDRESS = 0;
52 static const int ID_ITEM_WIFI_EAP_CONNECT_PROXY_ADDRESS = 1;
53 static const int ID_ITEM_WIFI_EAP_CONNECT_PROXY_PORT = 2;
54
55 static const int ID_GROUP_COUNT = 3;
56 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_WIFI_EAP_CONNECT_MAIN_ITEM_COUNT;
57
58 WifiConnectionForm::WifiConnectionForm(void)
59 {
60 }
61
62 WifiConnectionForm::~WifiConnectionForm(void)
63 {
64 }
65
66 void
67 WifiConnectionForm::CreateFooter(void)
68 {
69         Footer* pFooter = GetFooter();
70         AppAssert(pFooter);
71
72         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
73         pFooter->SetBackButton();
74         pFooter->AddActionEventListener(*this);
75
76         SetFormBackEventListener(this);
77 }
78
79 result
80 WifiConnectionForm::OnInitializing(void)
81 {
82         CreateFooter();
83         CreateTableView();
84
85         AppLogDebug("ENTER");
86
87         return E_SUCCESS;
88 }
89
90 result
91 WifiConnectionForm::OnTerminating(void)
92 {
93         __pTableView = null;
94
95         SetFormBackEventListener(null);
96         return E_SUCCESS;
97 }
98
99 void
100 WifiConnectionForm::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 WifiConnectionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
107 {
108 }
109
110 void
111 WifiConnectionForm::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 WifiConnectionForm::GetGroupCount(void)
121 {
122         AppLogDebug("ENTER");
123         return ID_GROUP_COUNT;
124 }
125
126 int
127 WifiConnectionForm::GetItemCount(int groupIndex)
128 {
129         int itemCount = 0;
130
131         switch (groupIndex)
132         {
133         case ID_GROUP_WIFI_EAP_CONNECT_MAIN:
134                 {
135                         itemCount = ID_GROUP_WIFI_EAP_CONNECT_MAIN_ITEM_COUNT;
136                 }
137                 break;
138
139         case ID_GROUP_WIFI_EAP_CONNECT_IP:
140                 {
141                         itemCount = ID_GROUP_WIFI_EAP_CONNECT_IP_ITEM_COUNT;
142                 }
143                 break;
144
145         case ID_GROUP_WIFI_EAP_CONNECT_ADDRESS:
146                 {
147                         itemCount = ID_GROUP_WIFI_EAP_CONNECT_ADDRESS_ITEM_COUNT;
148                 }
149                 break;
150
151         default:
152                 break;
153         }
154         AppLogDebug("GetItemCount %d ", itemCount);
155
156         return itemCount;
157 }
158
159 TableViewGroupItem*
160 WifiConnectionForm::CreateGroupItem(int groupIndex, int itemWidth)
161 {
162         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
163         int itemLableTextSize = FONT_SIZE_GROUP_TITLE_TEXT;
164         Color itemBGColor = COLOR_BG_GROUP_INDEX_DEFAULT;
165         Color itemLableTextColor = COLOR_GROUP_TITLE_TEXT;
166         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
167         Rectangle itemRectLable(X_GROUP_INDEX_DEFAULT_LABEL, Y_GROUP_INDEX_DEFAULT_LABEL, itemWidth, itemHeight);
168         String groupText;
169         Label* pLabel = null;
170
171         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
172
173         if (pItem)
174         {
175                 RelativeLayout relativeLayout;
176                 relativeLayout.Construct();
177
178                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
179                 pItem->SetBackgroundColor(itemBGColor);
180                 pItem->SetEnabled(false);
181
182                 pLabel = new (std::nothrow) Label();
183                 pLabel->Construct(itemRectLable, groupText);
184                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
185                 pLabel->SetTextConfig(itemLableTextSize, style);
186                 pLabel->SetTextColor(itemLableTextColor);
187
188                 pItem->AddControl(pLabel);
189                 relativeLayout.SetMargin(*pLabel, itemRectLable.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
190                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
191                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
192         }
193
194         return pItem;
195 }
196
197 TableViewItem*
198 WifiConnectionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
199 {
200         int itemLableTextSize = FONT_SIZE_MAIN_TEXT;
201         Color itemBGColor = COLOR_BG_GROUP_ITEM_DEFAULT;
202         Color itemLableTextColor = COLOR_MAIN_TEXT;
203         Rectangle itemRectLable;
204         String itemText;
205         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
206         Label* pLabel = null;
207
208         ItemTypeOneLine(itemRectLable);
209
210         TableViewItem* pItem = new (std::nothrow) TableViewItem();
211
212         switch (groupIndex)
213         {
214         case ID_GROUP_WIFI_EAP_CONNECT_MAIN:
215                 {
216                         switch (itemIndex)
217                         {
218                         case ID_ITEM_WIFI_EAP_CONNECT_EAP_METHOD:
219                                 {
220                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_EAP_METHOD");
221                                 }
222                                 break;
223
224                         case ID_ITEM_WIFI_EAP_CONNECT_PROVISIONING:
225                                 {
226                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_PROVISIONING");
227                                 }
228                                 break;
229
230                         case ID_ITEM_WIFI_EAP_CONNECT_PHASE_2_AUTHENTICATION:
231                                 {
232                                         // Empty statement
233                                 }
234                                 break;
235
236                         case ID_ITEM_WIFI_EAP_CONNECT_CA_CERTIFICATE:
237                                 {
238                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_CA_CERTIFICATE");
239                                 }
240                                 break;
241
242                         case ID_ITEM_WIFI_EAP_CONNECT_USER_CERTIFICATE:
243                                 {
244                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_USER_CERTIFICATE");
245                                 }
246                                 break;
247
248                         case ID_ITEM_WIFI_EAP_CONNECT_IDENTITY:
249                                 {
250                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_IDENTITY");
251                                 }
252                                 break;
253
254                         case ID_ITEM_WIFI_EAP_CONNECT_ANONUMOUS_IDENTITY:
255                                 {
256                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_ANONYMOUS_IDENTITY");
257                                 }
258                                 break;
259
260                         case ID_ITEM_WIFI_EAP_CONNECT_PASSWORD:
261                                 {
262                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_PASSWORD");
263                                 }
264                                 break;
265
266                         default:
267                                 break;
268                         }
269
270                         if (itemIndex < ID_ITEM_WIFI_EAP_CONNECT_CA_CERTIFICATE)
271                         {
272                                 style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
273                         }
274                 }
275                 break;
276
277         case ID_GROUP_WIFI_EAP_CONNECT_IP:
278                 {
279                         switch (itemIndex)
280                         {
281                         case ID_ITEM_WIFI_EAP_CONNECT_STATIC_IP:
282                                 {
283                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_STATIC_IP");
284                                 }
285                                 break;
286
287                         case ID_ITEM_WIFI_EAP_CONNECT_IP_ADDRESS:
288                                 {
289                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_IP_ADDRESS");
290                                 }
291                                 break;
292
293                         default:
294                                 break;
295                         }
296
297                         if (itemIndex == ID_ITEM_WIFI_EAP_CONNECT_STATIC_IP)
298                         {
299                                 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
300                         }
301                 }
302                 break;
303
304         default:
305                 {
306                         switch (itemIndex)
307                         {
308                         case ID_ITEM_WIFI_EAP_CONNECT_MAC_ADDRESS:
309                                 {
310                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_MAC_ADDRESS");
311                                 }
312                                 break;
313
314                         case ID_ITEM_WIFI_EAP_CONNECT_PROXY_ADDRESS:
315                                 {
316                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_CONNECTIONSETTINGS_PROXY_ADDRESS");
317                                 }
318                                 break;
319
320                         case ID_ITEM_WIFI_EAP_CONNECT_PROXY_PORT:
321                                 {
322                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_PROXY_PORT");
323                                 }
324                                 break;
325
326                         default:
327                                 break;
328                         }
329                 }
330                 break;
331         }
332
333         if (pItem)
334         {
335                 RelativeLayout relativeLayout;
336                 relativeLayout.Construct();
337
338                 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
339                 pItem->SetBackgroundColor(itemBGColor);
340
341                 pLabel = new (std::nothrow) Label();
342                 pLabel->Construct(itemRectLable, itemText);
343                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
344                 pLabel->SetTextConfig(itemLableTextSize , LABEL_TEXT_STYLE_NORMAL);
345                 pLabel->SetTextColor(itemLableTextColor);
346
347                 pItem->AddControl(pLabel);
348                 if (style == TABLE_VIEW_ANNEX_STYLE_DETAILED)
349                 {
350                         relativeLayout.SetMargin(*pLabel, itemRectLable.x, RELATIVE_LAYOUT_RIGHT_MARGIN_DETAIL_BUTTON, 0, 0);
351                 }
352                 else if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
353                 {
354                         relativeLayout.SetMargin(*pLabel, itemRectLable.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
355                 }
356                 else
357                 {
358                         relativeLayout.SetMargin(*pLabel, itemRectLable.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
359                 }
360                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
361                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
362         }
363
364         return pItem;
365 }
366
367 bool
368 WifiConnectionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
369 {
370         AppLogDebug("ENTER");
371
372         delete pItem;
373         pItem = null;
374
375         return true;
376 }
377
378 bool
379 WifiConnectionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
380 {
381         AppLogDebug("ENTER");
382
383         delete pItem;
384         pItem = null;
385
386         return true;
387 }
388
389 int
390 WifiConnectionForm::GetDefaultGroupItemHeight(void)
391 {
392         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
393 }
394
395 int
396 WifiConnectionForm::GetDefaultItemHeight(void)
397 {
398         return H_GROUP_ITEM_DEFAULT;
399 }
400
401 void
402 WifiConnectionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
403 {
404 }
405
406 void
407 WifiConnectionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
408 {
409 }
410
411 void
412 WifiConnectionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
413 {
414 }
415
416 void
417 WifiConnectionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
418 {
419 }
420
421 void
422 WifiConnectionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
423 {
424 }