Applied latest source code
[apps/native/preloaded/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->AddActionEventListener(*this);
74
75         SetFormBackEventListener(this);
76 }
77
78 result
79 WifiConnectionForm::OnInitializing(void)
80 {
81         CreateTableView();
82
83         AppLogDebug("ENTER");
84
85         return E_SUCCESS;
86 }
87
88 result
89 WifiConnectionForm::OnTerminating(void)
90 {
91         __pTableView = null;
92
93         SetFormBackEventListener(null);
94         return E_SUCCESS;
95 }
96
97 void
98 WifiConnectionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
99 {
100         __pTableView->UpdateTableView();
101 }
102
103 void
104 WifiConnectionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
105 {
106 }
107
108 void
109 WifiConnectionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
110 {
111         SceneManager* pSceneManager = SceneManager::GetInstance();
112         AppAssert(pSceneManager);
113
114         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
115 }
116
117 int
118 WifiConnectionForm::GetGroupCount(void)
119 {
120         AppLogDebug("ENTER");
121         return ID_GROUP_COUNT;
122 }
123
124 int
125 WifiConnectionForm::GetItemCount(int groupIndex)
126 {
127         int itemCount = 0;
128
129         switch (groupIndex)
130         {
131         case ID_GROUP_WIFI_EAP_CONNECT_MAIN:
132                 {
133                         itemCount = ID_GROUP_WIFI_EAP_CONNECT_MAIN_ITEM_COUNT;
134                 }
135                 break;
136
137         case ID_GROUP_WIFI_EAP_CONNECT_IP:
138                 {
139                         itemCount = ID_GROUP_WIFI_EAP_CONNECT_IP_ITEM_COUNT;
140                 }
141                 break;
142
143         case ID_GROUP_WIFI_EAP_CONNECT_ADDRESS:
144                 {
145                         itemCount = ID_GROUP_WIFI_EAP_CONNECT_ADDRESS_ITEM_COUNT;
146                 }
147                 break;
148
149         default:
150                 break;
151         }
152         AppLogDebug("GetItemCount %d ", itemCount);
153
154         return itemCount;
155 }
156
157 TableViewGroupItem*
158 WifiConnectionForm::CreateGroupItem(int groupIndex, int itemWidth)
159 {
160         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
161         int itemLableTextSize = FONT_SIZE_GROUP_TITLE_TEXT;
162         Color itemBGColor = COLOR_BG_GROUP_INDEX_DEFAULT;
163         Color itemLableTextColor = COLOR_GROUP_TITLE_TEXT;
164         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
165         Rectangle itemRectLable(X_GROUP_INDEX_DEFAULT_LABEL, Y_GROUP_INDEX_DEFAULT_LABEL, itemWidth, itemHeight);
166         String groupText;
167         Label* pLabel = null;
168
169         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
170
171         if (pItem)
172         {
173                 RelativeLayout relativeLayout;
174                 relativeLayout.Construct();
175
176                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
177                 pItem->SetBackgroundColor(itemBGColor);
178                 pItem->SetEnabled(false);
179
180                 pLabel = new (std::nothrow) Label();
181                 pLabel->Construct(itemRectLable, groupText);
182                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
183                 pLabel->SetTextConfig(itemLableTextSize, style);
184                 pLabel->SetTextColor(itemLableTextColor);
185
186                 pItem->AddControl(pLabel);
187                 relativeLayout.SetMargin(*pLabel, itemRectLable.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
188                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
189                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
190         }
191
192         return pItem;
193 }
194
195 TableViewItem*
196 WifiConnectionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
197 {
198         int itemLableTextSize = FONT_SIZE_MAIN_TEXT;
199         Color itemBGColor = COLOR_BG_GROUP_ITEM_DEFAULT;
200         Color itemLableTextColor = COLOR_MAIN_TEXT;
201         Rectangle itemRectLable;
202         String itemText;
203         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
204         Label* pLabel = null;
205
206         ItemTypeOneLine(itemRectLable);
207
208         TableViewItem* pItem = new (std::nothrow) TableViewItem();
209
210         switch (groupIndex)
211         {
212         case ID_GROUP_WIFI_EAP_CONNECT_MAIN:
213                 {
214                         switch (itemIndex)
215                         {
216                         case ID_ITEM_WIFI_EAP_CONNECT_EAP_METHOD:
217                                 {
218                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_EAP_METHOD");
219                                 }
220                                 break;
221
222                         case ID_ITEM_WIFI_EAP_CONNECT_PROVISIONING:
223                                 {
224                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_PROVISIONING");
225                                 }
226                                 break;
227
228                         case ID_ITEM_WIFI_EAP_CONNECT_PHASE_2_AUTHENTICATION:
229                                 {
230                                         // Empty statement
231                                 }
232                                 break;
233
234                         case ID_ITEM_WIFI_EAP_CONNECT_CA_CERTIFICATE:
235                                 {
236                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_CA_CERTIFICATE");
237                                 }
238                                 break;
239
240                         case ID_ITEM_WIFI_EAP_CONNECT_USER_CERTIFICATE:
241                                 {
242                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_USER_CERTIFICATE");
243                                 }
244                                 break;
245
246                         case ID_ITEM_WIFI_EAP_CONNECT_IDENTITY:
247                                 {
248                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_IDENTITY");
249                                 }
250                                 break;
251
252                         case ID_ITEM_WIFI_EAP_CONNECT_ANONUMOUS_IDENTITY:
253                                 {
254                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_ANONYMOUS_IDENTITY");
255                                 }
256                                 break;
257
258                         case ID_ITEM_WIFI_EAP_CONNECT_PASSWORD:
259                                 {
260                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_PASSWORD");
261                                 }
262                                 break;
263
264                         default:
265                                 break;
266                         }
267
268                         if (itemIndex < ID_ITEM_WIFI_EAP_CONNECT_CA_CERTIFICATE)
269                         {
270                                 style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
271                         }
272                 }
273                 break;
274
275         case ID_GROUP_WIFI_EAP_CONNECT_IP:
276                 {
277                         switch (itemIndex)
278                         {
279                         case ID_ITEM_WIFI_EAP_CONNECT_STATIC_IP:
280                                 {
281                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_STATIC_IP");
282                                 }
283                                 break;
284
285                         case ID_ITEM_WIFI_EAP_CONNECT_IP_ADDRESS:
286                                 {
287                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_IP_ADDRESS");
288                                 }
289                                 break;
290
291                         default:
292                                 break;
293                         }
294
295                         if (itemIndex == ID_ITEM_WIFI_EAP_CONNECT_STATIC_IP)
296                         {
297                                 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
298                         }
299                 }
300                 break;
301
302         default:
303                 {
304                         switch (itemIndex)
305                         {
306                         case ID_ITEM_WIFI_EAP_CONNECT_MAC_ADDRESS:
307                                 {
308                                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_MAC_ADDRESS");
309                                 }
310                                 break;
311
312                         case ID_ITEM_WIFI_EAP_CONNECT_PROXY_ADDRESS:
313                                 {
314                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_CONNECTIONSETTINGS_PROXY_ADDRESS");
315                                 }
316                                 break;
317
318                         case ID_ITEM_WIFI_EAP_CONNECT_PROXY_PORT:
319                                 {
320                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_PROXY_PORT");
321                                 }
322                                 break;
323
324                         default:
325                                 break;
326                         }
327                 }
328                 break;
329         }
330
331         if (pItem)
332         {
333                 RelativeLayout relativeLayout;
334                 relativeLayout.Construct();
335
336                 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
337                 pItem->SetBackgroundColor(itemBGColor);
338
339                 pLabel = new (std::nothrow) Label();
340                 pLabel->Construct(itemRectLable, itemText);
341                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
342                 pLabel->SetTextConfig(itemLableTextSize , LABEL_TEXT_STYLE_NORMAL);
343                 pLabel->SetTextColor(itemLableTextColor);
344
345                 pItem->AddControl(pLabel);
346                 if (style == TABLE_VIEW_ANNEX_STYLE_DETAILED)
347                 {
348                         relativeLayout.SetMargin(*pLabel, itemRectLable.x, RELATIVE_LAYOUT_RIGHT_MARGIN_DETAIL_BUTTON, 0, 0);
349                 }
350                 else if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
351                 {
352                         relativeLayout.SetMargin(*pLabel, itemRectLable.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
353                 }
354                 else
355                 {
356                         relativeLayout.SetMargin(*pLabel, itemRectLable.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
357                 }
358                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
359                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
360         }
361
362         return pItem;
363 }
364
365 bool
366 WifiConnectionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
367 {
368         AppLogDebug("ENTER");
369
370         delete pItem;
371         pItem = null;
372
373         return true;
374 }
375
376 bool
377 WifiConnectionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
378 {
379         AppLogDebug("ENTER");
380
381         delete pItem;
382         pItem = null;
383
384         return true;
385 }
386
387 int
388 WifiConnectionForm::GetDefaultGroupItemHeight(void)
389 {
390         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
391 }
392
393 int
394 WifiConnectionForm::GetDefaultItemHeight(void)
395 {
396         return H_GROUP_ITEM_DEFAULT;
397 }
398
399 void
400 WifiConnectionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
401 {
402 }
403
404 void
405 WifiConnectionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
406 {
407 }
408
409 void
410 WifiConnectionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
411 {
412 }
413
414 void
415 WifiConnectionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
416 {
417 }
418
419 void
420 WifiConnectionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
421 {
422 }