Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / data / my_tools / jj / rsa / apps / osp / Settings / src / StWifiForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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                StWifiForm.cpp
19  * @brief               This is the implementation file for WifiForm class.
20  */
21
22 #include <FSystem.h>
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26 #include "StWifiForm.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Net::Wifi;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37 static const int IDA_POPUP_ACTION_ID_BASE = 200;
38 static const int IDA_FOOTER_WIFI_SCAN = IDA_POPUP_ACTION_ID_BASE + 1;
39
40 static const int W_RESIZE_LABEL_GAP = 170;
41 static const int DIVIDE_BY_TWO = 2;
42
43 static const int ID_GROUP_STATUS_COUNT_TURN_OFF = 2;
44 static const int ID_GROUP_STATUS_COUNT_TURN_ON = 4;
45 static const int ID_WIFI_STATUS_GROUP_ITEM_ONOFF = 0;
46 static const int WIFI_STATUS_GROUP_ITEM_TOTAL_COUNT = 1;
47 static const int WIFI_NOTIFICATION_GROUP_ITEM_NETOWRK_NOTI = 0;
48 static const int WIFI_NOTIFICATION_GROUP_ITEM_TOTAL_COUNT = 1;
49 static const int WIFI_NETWORK_GROUP_ITEM_BASE = 0;
50
51 static const int WIFI_DEFAULT_COUNT = 1;
52
53 static const int WIFI_RSSI_DETAIL_MAX = -70;
54 static const int WIFI_RSSI_DETAIL_MID = -80;
55 static const int WIFI_RSSI_DETAIL_MIN = -90;
56 static const int RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING = 140;
57
58 enum GroupIndex
59 {
60         GROUP_INDEX_WIFI_BASE,
61         GROUP_INDEX_0_WIFI_ACTIVATE = GROUP_INDEX_WIFI_BASE,
62         GROUP_INDEX_1_WIFI_NOTIFICATION,
63         GROUP_INDEX_2_WIFI_NETWORK,
64         GROUP_INDEX_3_WIFI_HIDDEN_NETWORK,
65         GROUP_INDEX_MAX
66 };
67
68 enum WifiHiddenNetworkGroupItem
69 {
70         WIFI_HIDDEN_NETWORK_GROUP_ITEM_BASE,
71         WIFI_HIDDEN_NETWORK_GROUP_ITEM_FIND = WIFI_HIDDEN_NETWORK_GROUP_ITEM_BASE,
72         WIFI_HIDDEN_NETWORK_GROUP_ITEM_TOTAL_COUNT,
73         WIFI_HIDDEN_NETWORK_GROUP_ITEM_MAX
74 };
75
76 WifiForm::WifiForm(void)
77         : __pWifiPresentationModelInstance(null)
78         , __groupTotalCount(ID_GROUP_STATUS_COUNT_TURN_OFF)
79         , __networkGroupItemTotalCount(WIFI_NETWORK_GROUP_ITEM_BASE)
80 {
81 }
82
83 WifiForm::~WifiForm(void)
84 {
85 }
86
87 void
88 WifiForm::CreateFooter(void)
89 {
90         Footer* pFooter = GetFooter();
91         AppAssert(pFooter);
92
93         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
94
95         FooterItem footerScan;
96         footerScan.Construct(IDA_FOOTER_WIFI_SCAN);
97         footerScan.SetText(ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
98
99         pFooter->AddItem(footerScan);
100         pFooter->SetBackButton();
101         pFooter->AddActionEventListener(*this);
102         pFooter->SetItemEnabled(0, false);
103
104         SetFormBackEventListener(this);
105 }
106
107 void
108 WifiForm::DisableScanFooter(void)
109 {
110         Footer* pFooter = GetFooter();
111         AppAssert(pFooter);
112
113         pFooter->SetItemEnabled(0, false);
114 }
115
116 void
117 WifiForm::EnableScanFooter(void)
118 {
119         Footer* pFooter = GetFooter();
120         AppAssert(pFooter);
121
122         pFooter->SetItemEnabled(0, true);
123 }
124
125 result
126 WifiForm::InitWifiPresentationModelInstance(void)
127 {
128         __pWifiPresentationModelInstance = WifiPresentationModel::GetInstance();
129         if (__pWifiPresentationModelInstance == null)
130         {
131                 return E_FAILURE;
132         }
133
134         __pWifiPresentationModelInstance->SetWifiEventListener(this);
135         if (__pWifiPresentationModelInstance->IsWifiActivated() == true)
136         {
137                 EnableScanFooter();
138         }
139
140         return E_SUCCESS;
141 }
142
143 WifiPresentationModelEvent
144 WifiForm::GetWifiCurrentStatus(void)
145 {
146         WifiPresentationModelEvent eStatus = WIFI_PRESENTATION_MODEL_EVENT_DEACTIVATED;
147
148         if (__pWifiPresentationModelInstance->IsWifiActivated())
149         {
150                 if (__pWifiPresentationModelInstance->IsWifiConnected())
151                 {
152                         eStatus = WIFI_PRESENTATION_MODEL_EVENT_CONNECTED;
153                 }
154                 else
155                 {
156                         eStatus = WIFI_PRESENTATION_MODEL_EVENT_ACTIVATED;
157                 }
158         }
159         else
160         {
161                 eStatus = WIFI_PRESENTATION_MODEL_EVENT_DEACTIVATED;
162         }
163
164         return eStatus;
165 }
166
167 result
168 WifiForm::OnInitializing(void)
169 {
170         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_WI_FI"));
171         CreateFooter();
172         CreateTableView();
173
174         ChangeGroupIndexCount(ID_GROUP_STATUS_COUNT_TURN_OFF, false);
175
176         bool supportedWifi;
177         if (SystemInfo::GetValue(SYSTEM_INFO_KEY_WIFI, supportedWifi) != E_SUCCESS)
178         {
179                 AppLogDebug("GetValue Fail.. %d - %s", supportedWifi, GetErrorMessage(GetLastResult()));
180         }
181         else
182         {
183                 AppLogDebug("current Value = %d - %s", supportedWifi, GetErrorMessage(GetLastResult()));
184         }
185
186         if (!supportedWifi)
187         {
188                 return E_SUCCESS;
189         }
190
191         result r = InitWifiPresentationModelInstance();
192
193         if (!IsFailed(r))
194         {
195                 if (__pWifiPresentationModelInstance->IsWifiActivated())
196                 {
197                         __pWifiPresentationModelInstance->ScanWifi();
198                         ChangeGroupIndexCount(ID_GROUP_STATUS_COUNT_TURN_ON, true);
199                 }
200                 else
201                 {
202                         ChangeGroupIndexCount(ID_GROUP_STATUS_COUNT_TURN_OFF, true);
203                 }
204         }
205         return r;
206 }
207
208 result
209 WifiForm::OnTerminating(void)
210 {
211         if (__pWifiPresentationModelInstance != null)
212         {
213                 __pWifiPresentationModelInstance = null;
214         }
215         __pTableView = null;
216
217         AppLogDebug("ENTER");
218         SetFormBackEventListener(null);
219         return E_SUCCESS;
220 }
221
222 void
223 WifiForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
224 {
225         if (__pWifiPresentationModelInstance == null)
226         {
227                 AppLogDebug("__pWifiPresentationModelInstance is null");
228                 return;
229         }
230
231         if (previousSceneId.Equals(IDSCN_WIFI_AP_DETAIL, false))
232         {
233                 __pWifiPresentationModelInstance->SetWifiEventListener(this);
234         }
235         __pWifiPresentationModelInstance->SetWifiActivateScanMode(WIFI_SYSTEM_SCAN_MODE_ACTIVE);
236
237         __pTableView->UpdateTableView();
238 }
239
240 void
241 WifiForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
242 {
243         if (__pWifiPresentationModelInstance != null)
244         {
245                 __pWifiPresentationModelInstance->SetWifiActivateScanMode(WIFI_SYSTEM_SCAN_MODE_PASSIVE);
246         }
247 }
248
249 void
250 WifiForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
251 {
252         SceneManager* pSceneManager = SceneManager::GetInstance();
253         AppAssert(pSceneManager);
254
255         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
256 }
257
258 int
259 WifiForm::GetGroupCount(void)
260 {
261         AppLogDebug("GetGroupCount[%d]", __groupTotalCount);
262         return __groupTotalCount;
263 }
264
265 int
266 WifiForm::GetItemCount(int groupIndex)
267 {
268         int itemCount = 0;
269
270         switch (groupIndex)
271         {
272         case GROUP_INDEX_0_WIFI_ACTIVATE:
273                 {
274                         itemCount = WIFI_STATUS_GROUP_ITEM_TOTAL_COUNT;
275                 }
276                 break;
277
278         case GROUP_INDEX_1_WIFI_NOTIFICATION:
279                 {
280                         itemCount = WIFI_NOTIFICATION_GROUP_ITEM_TOTAL_COUNT;
281                 }
282                 break;
283
284         case GROUP_INDEX_2_WIFI_NETWORK:
285                 {
286                         itemCount = __networkGroupItemTotalCount;
287                 }
288                 break;
289
290         case GROUP_INDEX_3_WIFI_HIDDEN_NETWORK:
291                 {
292                         itemCount = WIFI_HIDDEN_NETWORK_GROUP_ITEM_TOTAL_COUNT;
293                 }
294                 break;
295
296         default:
297                 break;
298         }
299
300         AppLogDebug("GetItemCount %d", itemCount);
301         return itemCount;
302 }
303
304 TableViewGroupItem*
305 WifiForm::CreateGroupItem(int groupIndex, int itemWidth)
306 {
307         Color itemBGColor = COLOR_BG_GROUP_INDEX_DEFAULT;
308         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
309         String groupText;
310         int itemLabelTextSize = GetFontSize();
311         Color itemLabelTextColor = COLOR_GROUP_TITLE_TEXT;
312         Rectangle itemRectLabel(X_GROUP_INDEX_DEFAULT_LABEL, Y_GROUP_INDEX_DEFAULT_LABEL, itemWidth, itemHeight);
313         Label* pLabel = null;
314         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
315
316         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
317
318         switch (groupIndex)
319         {
320         case GROUP_INDEX_0_WIFI_ACTIVATE:
321                 {
322                         groupText = L"";
323                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
324                 }
325                 break;
326
327         case GROUP_INDEX_1_WIFI_NOTIFICATION:
328                 {
329                         groupText = L"";
330                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
331                 }
332                 break;
333
334         case GROUP_INDEX_3_WIFI_HIDDEN_NETWORK:
335                 {
336                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
337                 }
338                 break;
339
340         case GROUP_INDEX_2_WIFI_NETWORK:
341                 {
342                         groupText = ResourceManager::GetString(L"IDS_ST_BODY_WI_FI_NETWORKS");
343                         itemHeight = itemLabelTextSize / DIVIDE_BY_TWO + itemLabelTextSize + H_GROUP_INDEX_TITLE_TEXT_BOTTOM_GAP;
344                         itemRectLabel = Rectangle(X_GROUP_INDEX_DEFAULT_LABEL, 0
345                                                                         , itemWidth, itemLabelTextSize/DIVIDE_BY_TWO + itemLabelTextSize + H_GROUP_INDEX_TITLE_TEXT_BOTTOM_GAP);
346                 }
347                 break;
348
349         default:
350                 {
351                         // Empty statement
352                 }
353                 break;
354         }
355
356         RelativeLayout relativeLayout;
357         relativeLayout.Construct();
358
359         result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
360         if (IsFailed(r))
361         {
362                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
363                 delete pItem;
364                 return null;
365         }
366
367         pItem->SetBackgroundColor(itemBGColor);
368         pItem->SetEnabled(false);
369
370         pLabel = new (std::nothrow) Label();
371         pLabel->Construct(itemRectLabel, groupText);
372         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
373         pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
374         pLabel->SetTextConfig(itemLabelTextSize, style);
375         pLabel->SetTextColor(itemLabelTextColor);
376
377         pItem->AddControl(*pLabel);
378         relativeLayout.SetMargin(*pLabel, itemRectLabel.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
379         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
380         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
381
382         return pItem;
383 }
384
385 TableViewItem*
386 WifiForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
387 {
388         bool isButton = false;
389         bool isCreateIcon = false;
390         bool isConnectState = false;
391         bool isTwoLineItemText = false;
392         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
393         Bitmap* pBitmap = null;
394         int itemHeight = H_GROUP_ITEM_DEFAULT;
395         int fontSize = GetFontSize();
396         Rectangle itemRectangle;
397         Rectangle itemRectSecondLabel;
398         Rectangle itemIconRect;
399         result r = E_FAILURE;
400
401         String itemText;
402         String itemTextTwoLine;
403
404         ItemTypeOneLine(itemRectangle);
405
406         TableViewItem* pItem = new (std::nothrow) TableViewItem();
407
408         switch (groupIndex)
409         {
410         case GROUP_INDEX_0_WIFI_ACTIVATE:
411                 {
412                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_WI_FI");
413                         if (__pWifiPresentationModelInstance != null)
414                         {
415                                 if (GetWifiCurrentStatus() != WIFI_PRESENTATION_MODEL_EVENT_DEACTIVATED)
416                                 {
417                                         EnableScanFooter();
418                                         __pTableView->SetItemChecked(groupIndex, itemIndex, true);
419                                 }
420                         }
421                         else
422                         {
423                                 __pTableView->SetItemChecked(groupIndex, itemIndex, false);
424                                 DisableScanFooter();
425                         }
426                         style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
427                 }
428                 break;
429
430         case GROUP_INDEX_1_WIFI_NOTIFICATION:
431                 {
432                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_NETWORK_NOTIFICATION");
433
434                         style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
435                         itemRectangle.width -= W_RESIZE_LABEL_GAP;
436                 }
437                 break;
438
439         case GROUP_INDEX_2_WIFI_NETWORK:
440                 {
441                         itemText = ResourceManager::GetString(L"IDS_WIFI_BODY_NO_DEVICES_FOUND");
442
443                         int wifiScanBssCount = __pWifiPresentationModelInstance->GetAccessPointCount();
444                         if (wifiScanBssCount == 0)
445                         {
446                                 delete pItem;
447                                 return null;
448                         }
449
450                         String tempText;
451
452                         isConnectState = __pWifiPresentationModelInstance->IsWifiBssInfoConnect(itemIndex);
453
454                         pBitmap = GetMajorAuthenticationTypeInWifiRssiValueAtBitmapN(itemIndex);
455                         if (pBitmap != null)
456                         {
457                                 isCreateIcon = true;
458                         }
459
460                         itemText = __pWifiPresentationModelInstance->GetSsidInAccessPointListAt(itemIndex);
461                         if (IsFailed(GetLastResult()))
462                         {
463                                 delete pItem;
464                                 return null;
465                         }
466
467                         if (isConnectState == true)
468                         {
469                                 itemTextTwoLine = ResourceManager::GetString(L"IDS_WIFI_BODY_CONNECTED");
470                         }
471                         else
472                         {
473                                 WifiAuthenticationType majorType = __pWifiPresentationModelInstance->GetAuthenticationtypeInAccessPointListAt(itemIndex);
474                                 switch (majorType)
475                                 {
476                                 case WIFI_AUTHENTICATION_OPEN:
477                                         {
478                                                 itemTextTwoLine = ResourceManager::GetString(L"IDS_ST_BUTTON_OPEN");
479                                         }
480                                         break;
481
482                                 case WIFI_AUTHENTICATION_SHARED:
483                                         {
484                                                 itemTextTwoLine = ResourceManager::GetString(L"IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY");
485                                                 itemTextTwoLine.Append(L" (");
486                                                 itemTextTwoLine.Append(ResourceManager::GetString(L"IDS_WIFI_BODY_EAP"));
487                                                 itemTextTwoLine.Append(L")");
488                                         }
489                                         break;
490
491                                 case WIFI_AUTHENTICATION_WPA:
492                                         // fall through
493                                 case WIFI_AUTHENTICATION_WPA_PSK:
494                                         // fall through
495                                 case WIFI_AUTHENTICATION_WPA2:
496                                         // fall through
497                                 case WIFI_AUTHENTICATION_WPA2_PSK:
498                                         // fall through
499                                 case WIFI_AUTHENTICATION_WPA_WPA2_MIXED_PSK:
500                                         {
501                                                 itemTextTwoLine = ResourceManager::GetString(L"IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY");
502                                                 itemTextTwoLine.Append(L" ");
503                                                 itemTextTwoLine.Append(ResourceManager::GetString(L"IDS_WIFI_BODY_HWPS_AVAILABLE"));
504                                         }
505                                         break;
506
507                                 case WIFI_AUTHENTICATION_MAX:
508                                         // fall through
509                                 default:
510                                         {
511                                                 AppLogDebug("majorType is Invalid");
512                                         }
513                                         break;
514                                 }
515                         }
516                         isTwoLineItemText = true;
517                         style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
518
519                         ItemTypeIconAndTwoLine(itemIconRect, itemRectangle, itemRectSecondLabel, fontSize);
520                         itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
521                 }
522                 break;
523
524         case GROUP_INDEX_3_WIFI_HIDDEN_NETWORK:
525                 {
526                         switch (itemIndex)
527                         {
528                         case WIFI_HIDDEN_NETWORK_GROUP_ITEM_FIND:
529                                 {
530                                         itemText = ResourceManager::GetString(L"IDS_WIFI_OPT_FIND_HIDDEN_NETWORK");
531                                         isButton = true;
532                                         style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
533                                 }
534                                 break;
535
536                         default:
537                                 break;
538                         }
539                 }
540                 break;
541
542         default:
543                 break;
544         }
545
546         RelativeLayout relativeLayout;
547         relativeLayout.Construct();
548
549         r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
550         if (IsFailed(r))
551         {
552                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
553                 delete pItem;
554                 return null;
555         }
556
557         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
558
559         if (isCreateIcon)
560         {
561                 Label* pLabel = new (std::nothrow) Label();
562                 if (pLabel == null)
563                 {
564                         AppLogDebug("pLabel is null");
565                         return pItem;
566                 }
567
568                 r = pLabel->Construct(itemIconRect, L"");
569                 if (IsFailed(r))
570                 {
571                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
572                         delete pLabel;
573                         return pItem;
574                 }
575
576                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
577                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
578                 pLabel->SetBackgroundBitmap(*pBitmap);
579
580                 pItem->AddControl(*pLabel);
581
582                 delete pBitmap;
583         }
584
585         if (isButton == false)
586         {
587                 Label* pLabel = new (std::nothrow) Label();
588                 if (pLabel == null)
589                 {
590                         AppLogDebug("pLabel is null");
591                         return pItem;
592                 }
593
594                 r = pLabel->Construct(itemRectangle, itemText);
595                 if (IsFailed(r))
596                 {
597                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
598                         delete pLabel;
599                         return pItem;
600                 }
601
602                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
603                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
604                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
605
606                 pItem->AddControl(*pLabel);
607                 if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
608                 {
609                         relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
610                 }
611                 else
612                 {
613                         relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
614                 }
615                 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
616                 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
617         }
618
619         if (isTwoLineItemText == true)
620         {
621                 Label* pSecondLabel = new (std::nothrow) Label();
622                 if (pSecondLabel == null)
623                 {
624                         AppLogDebug("pLabel is null");
625                         return pItem;
626                 }
627
628                 r = pSecondLabel->Construct(itemRectSecondLabel, itemTextTwoLine);
629                 if (IsFailed(r))
630                 {
631                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
632                         delete pSecondLabel;
633                         return pItem;
634                 }
635
636                 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
637                 pSecondLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
638                 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
639
640                 pItem->AddControl(*pSecondLabel);
641                 relativeLayout.SetMargin(*pSecondLabel, itemRectSecondLabel.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
642                 relativeLayout.SetRelation(*pSecondLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
643                 relativeLayout.SetRelation(*pSecondLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
644         }
645
646         if (isButton == true)
647         {
648                 Button* pButton = new (std::nothrow) Button();
649                 r = pButton->Construct(itemRectangle, itemText);
650
651                 if(IsFailed(r))
652                 {
653                         AppLogDebug("pButton construct error");
654                         delete pButton;
655                         return pItem;
656                 }
657
658                 pItem->AddControl(*pButton);
659                 relativeLayout.SetMargin(*pButton, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
660                 relativeLayout.SetRelation(*pButton, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
661                 relativeLayout.SetRelation(*pButton, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
662         }
663
664         return pItem;
665 }
666
667 bool
668 WifiForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
669 {
670         AppLogDebug("ENTER");
671
672         delete pItem;
673         pItem = null;
674
675         return true;
676 }
677
678 bool
679 WifiForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
680 {
681         AppLogDebug("[itemTag.groupIndex=%d][itemTag.itemIndex=%d]", groupIndex, itemIndex);
682
683         delete pItem;
684         pItem = null;
685
686         return true;
687 }
688
689 void
690 WifiForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
691 {
692         result r = E_FAILURE;
693         SceneManager* pSceneManager = SceneManager::GetInstance();
694         AppAssert(pSceneManager);
695
696         switch (groupIndex)
697         {
698         case GROUP_INDEX_0_WIFI_ACTIVATE:
699                 {
700                         if (__pWifiPresentationModelInstance != null)
701                         {
702                                 r = ToggleWifiActivateStatus(status);
703                                 if (IsFailed(r))
704                                 {
705                                         AppLogDebug("ToggleWifiActivateStatus is Fail");
706                                 }
707                         }
708                         else
709                         {
710                                 __pTableView->SetItemChecked(groupIndex, itemIndex, false);
711                                 // Not supported in the Emulator
712                                 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
713                                 return;
714                         }
715                 }
716                 break;
717
718         case GROUP_INDEX_1_WIFI_NOTIFICATION:
719                 {
720                         if (__pWifiPresentationModelInstance != null)
721                         {
722                                 if (itemIndex == WIFI_NOTIFICATION_GROUP_ITEM_NETOWRK_NOTI)
723                                 {
724                                         TogleWifiNotificationStatus(status);
725                                 }
726                         }
727                         else
728                         {
729                                 __pTableView->SetItemChecked(groupIndex, itemIndex, false);
730                                 // Not supported in the Emulator
731                                 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
732                                 return;
733                         }
734                 }
735                 break;
736
737         case GROUP_INDEX_2_WIFI_NETWORK:
738                 {
739                         if (status == TABLE_VIEW_ITEM_STATUS_MORE) // more
740                         {
741                                 ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
742                                 if (pArgs == null)
743                                 {
744                                         AppLogDebug("pArgs is null");
745                                         break;
746                                 }
747
748                                 r = pArgs->Construct();
749                                 if (IsFailed(r))
750                                 {
751                                         delete pArgs;
752                                         pArgs = null;
753                                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
754                                         break;
755                                 }
756
757                                 pArgs->Add(*(new (std::nothrow) String(Integer::ToString(itemIndex))));
758                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WIFI_AP_DETAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
759                         }
760                         else if (status == TABLE_VIEW_ITEM_STATUS_SELECTED) // select
761                         {
762                                 // Empty statement
763                         }
764                         else // error
765                         {
766                                 AppLogDebug("Error status (%d)",status);
767                         }
768                 }
769                 break;
770
771         case GROUP_INDEX_3_WIFI_HIDDEN_NETWORK:
772                 {
773                         // Empty statement
774                 }
775                 break;
776
777         default:
778                 break;
779         }
780
781         AppLogDebug("OnTableViewItemStateChanged group[%d] index[%d], status[%d]", groupIndex, itemIndex, status);
782 }
783
784 void
785 WifiForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
786 {
787         AppLogDebug("ENTER");
788         result r = E_FAILURE;
789
790         if (actionId == IDA_FOOTER_WIFI_SCAN)
791         {
792                 r = __pWifiPresentationModelInstance->ScanWifi();
793
794                 if (IsFailed(r))
795                 {
796                         AppLogDebug("Scan Failed");
797                 }
798         }
799         AppLogDebug("EXIT");
800 }
801
802 Tizen::Graphics::Bitmap*
803 WifiForm::GetMajorAuthenticationTypeInWifiRssiValueAtBitmapN(int itemIndex)
804 {
805         if (__pWifiPresentationModelInstance == null)
806         {
807                 AppLogDebug("__pWifiPresentationModelInstance is null");
808                 return null;
809         }
810
811         Bitmap* pBitmap = null;
812
813         WifiAuthenticationType majorType = __pWifiPresentationModelInstance->GetAuthenticationtypeInAccessPointListAt(itemIndex);
814
815         if (IsFailed(GetLastResult()))
816         {
817                 AppLogDebug("GetAuthenticationType fail [%s]", GetErrorMessage(GetLastResult()));
818                 return null;
819         }
820
821         long wifiBssInfoRssi = __pWifiPresentationModelInstance->GetRssiInAccessPointListAt(itemIndex);
822         switch (majorType)
823         {
824         case WIFI_AUTHENTICATION_OPEN:
825                 {
826                         if (wifiBssInfoRssi > WIFI_RSSI_DETAIL_MAX)
827                         {
828                                 pBitmap = ResourceManager::GetBitmapN(IDB_WIFI_RSSI_UNLOCK_03);
829                         }
830                         else if ((wifiBssInfoRssi <= WIFI_RSSI_DETAIL_MAX)
831                                 && (wifiBssInfoRssi > WIFI_RSSI_DETAIL_MID))
832                         {
833                                 pBitmap = ResourceManager::GetBitmapN(IDB_WIFI_RSSI_UNLOCK_02);
834                         }
835                         else if ((wifiBssInfoRssi <= WIFI_RSSI_DETAIL_MID)
836                                 && (wifiBssInfoRssi > WIFI_RSSI_DETAIL_MIN))
837                         {
838                                 pBitmap = ResourceManager::GetBitmapN(IDB_WIFI_RSSI_UNLOCK_01);
839                         }
840                         else if (wifiBssInfoRssi <= WIFI_RSSI_DETAIL_MIN)
841                         {
842                                 pBitmap = ResourceManager::GetBitmapN(IDB_WIFI_RSSI_UNLOCK_00);
843                         }
844                         else
845                         {
846                                 AppLogDebug("wifiBssInfoRssi is high (%d)", wifiBssInfoRssi);
847                         }
848                 }
849                 break;
850
851         case WIFI_AUTHENTICATION_SHARED:
852                 // fall through
853         case WIFI_AUTHENTICATION_WPA:
854                 // fall through
855         case WIFI_AUTHENTICATION_WPA_PSK:
856                 // fall through
857         case WIFI_AUTHENTICATION_WPA2:
858                 // fall through
859         case WIFI_AUTHENTICATION_WPA2_PSK:
860                 // fall through
861         case WIFI_AUTHENTICATION_WPA_WPA2_MIXED_PSK:
862                 {
863                         if (wifiBssInfoRssi > WIFI_RSSI_DETAIL_MAX)
864                         {
865                                 pBitmap = ResourceManager::GetBitmapN(IDB_WIFI_RSSI_LOCK_03);
866                         }
867                         else if ((wifiBssInfoRssi <= WIFI_RSSI_DETAIL_MAX)
868                                         && (wifiBssInfoRssi > WIFI_RSSI_DETAIL_MID))
869                         {
870                                 pBitmap = ResourceManager::GetBitmapN(IDB_WIFI_RSSI_LOCK_02);
871                         }
872                         else if ((wifiBssInfoRssi <= WIFI_RSSI_DETAIL_MID)
873                                         && (wifiBssInfoRssi > WIFI_RSSI_DETAIL_MIN))
874                         {
875                                 pBitmap = ResourceManager::GetBitmapN(IDB_WIFI_RSSI_LOCK_01);
876                         }
877                         else if (wifiBssInfoRssi <= WIFI_RSSI_DETAIL_MIN)
878                         {
879                                 pBitmap = ResourceManager::GetBitmapN(IDB_WIFI_RSSI_LOCK_00);
880                         }
881                         else
882                         {
883                                 AppLogDebug("wifiBssInfoRssi is high (%d)", wifiBssInfoRssi);
884                         }
885                 }
886                 break;
887
888         case WIFI_AUTHENTICATION_MAX:
889                 // fall through
890         default:
891                 {
892                         AppLogDebug("majorType is Invalid");
893                 }
894                 break;
895         }
896
897         return pBitmap;
898 }
899
900 result
901 WifiForm::ConnectAp(int itemIndex)
902 {
903         if (__pWifiPresentationModelInstance == null)
904         {
905                 AppLogDebug("__pWifiPresentationModelInstance is null");
906                 return E_FAILURE;
907         }
908
909         __pWifiPresentationModelInstance->ConnectToAccessPointListAt(itemIndex);
910
911         return E_SUCCESS;
912 }
913
914 result
915 WifiForm::ToggleWifiActivateStatus(Tizen::Ui::Controls::TableViewItemStatus itemStatus)
916 {
917         if (__pWifiPresentationModelInstance == null)
918         {
919                 AppLogDebug("__pWifiPresentationModelInstance is null");
920                 return E_FAILURE;
921         }
922
923         switch (itemStatus)
924         {
925         case TABLE_VIEW_ITEM_STATUS_CHECKED:
926                 {
927                         if (!__pWifiPresentationModelInstance->IsWifiActivated())
928                         {
929                                 __pWifiPresentationModelInstance->ActivateWifi();
930                         }
931                 }
932                 break;
933
934         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
935                 {
936                         if (__pWifiPresentationModelInstance->IsWifiActivated())
937                         {
938                                 __pWifiPresentationModelInstance->DeactivateWifi();
939                         }
940                 }
941                 break;
942
943         default:
944                 break;
945         }
946
947         return E_SUCCESS;
948 }
949
950 result
951 WifiForm::TogleWifiNotificationStatus(Tizen::Ui::Controls::TableViewItemStatus itemStatus)
952 {
953         if (__pWifiPresentationModelInstance == null)
954         {
955                 AppLogDebug("__pWifiPresentationModelInstance is null");
956                 return E_FAILURE;
957         }
958
959 #if 0
960         switch (itemStatus)
961         {
962         case TABLE_VIEW_ITEM_STATUS_CHECKED:
963                 {
964                         if (!__pWifiPresentationModelInstance->IsActivated())
965                         {
966                                 __pWifiPresentationModelInstance->Activate();
967                         }
968                 }
969                 break;
970
971         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
972                 {
973                         if (__pWifiPresentationModelInstance->IsActivated())
974                         {
975                                 __pWifiPresentationModelInstance->Deactivate();
976                         }
977                 }
978                 break;
979
980         default:
981                 break;
982         }
983 #endif
984
985         return E_SUCCESS;
986 }
987
988 result
989 WifiForm::ChangeGroupIndexCount(unsigned int grpIndexStatus, bool update)
990 {
991         if ((grpIndexStatus + WIFI_DEFAULT_COUNT) > ID_GROUP_STATUS_COUNT_TURN_ON)
992         {
993                 __groupTotalCount = ID_GROUP_STATUS_COUNT_TURN_ON;
994         }
995         else
996         {
997                 __groupTotalCount = grpIndexStatus;
998         }
999
1000         if (update)
1001         {
1002                 __pTableView->UpdateTableView();
1003         }
1004
1005         return E_SUCCESS;
1006 }
1007
1008 int
1009 WifiForm::ChangeNetworkGroupItemCount(unsigned int itemCount, bool isAdd)
1010 {
1011         if (isAdd)
1012         {
1013                 __networkGroupItemTotalCount = itemCount;
1014         }
1015         else
1016         {
1017                 __networkGroupItemTotalCount = GetGroupItemTotalCount(GROUP_INDEX_2_WIFI_NETWORK) - itemCount;
1018                 if ( __networkGroupItemTotalCount <= 0)
1019                 {
1020                         __networkGroupItemTotalCount = WIFI_NETWORK_GROUP_ITEM_BASE;
1021                 }
1022         }
1023
1024         return __networkGroupItemTotalCount;
1025 }
1026
1027 int
1028 WifiForm::GetGroupItemTotalCount(int groupIndex)
1029 {
1030         int retItemCount = 0;
1031
1032         if (__pTableView)
1033         {
1034                 retItemCount = __pTableView->GetItemCountAt(groupIndex);
1035         }
1036
1037         return retItemCount;
1038 }
1039
1040 int
1041 WifiForm::GetDefaultGroupItemHeight(void)
1042 {
1043         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
1044 }
1045
1046 int
1047 WifiForm::GetDefaultItemHeight(void)
1048 {
1049         return H_GROUP_ITEM_DEFAULT;
1050 }
1051
1052 void
1053 WifiForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
1054 {
1055 }
1056
1057 void
1058 WifiForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
1059 {
1060 }
1061
1062 void
1063 WifiForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
1064 {
1065 }
1066
1067 void
1068 WifiForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1069 {
1070         switch (groupIndex)
1071         {
1072         case GROUP_INDEX_0_WIFI_ACTIVATE:
1073                 {
1074                 }
1075                 break;
1076
1077         case GROUP_INDEX_1_WIFI_NOTIFICATION:
1078                 {
1079                 }
1080                 break;
1081
1082         case GROUP_INDEX_2_WIFI_NETWORK:
1083                 {
1084                 }
1085                 break;
1086
1087         case GROUP_INDEX_3_WIFI_HIDDEN_NETWORK:
1088                 {
1089                 }
1090                 break;
1091
1092         default:
1093                 break;
1094         }
1095 }
1096
1097 void
1098 WifiForm::OnWifiPresentationModelEventCompleted(WifiPresentationModelEvent requestEvent, result r)
1099 {
1100         int wifiScanBssCount = 0;
1101         if (__pWifiPresentationModelInstance == null)
1102         {
1103                 AppLogDebug("__pWifiPresentationModelInstance is null");
1104                 return;
1105         }
1106         if (__pTableView == null)
1107         {
1108                 AppLogDebug("__tableView is null");
1109                 return;
1110         }
1111         switch (requestEvent)
1112         {
1113         case WIFI_PRESENTATION_MODEL_EVENT_NONE:
1114                 {
1115                 }
1116                 break;
1117
1118         case WIFI_PRESENTATION_MODEL_EVENT_ACTIVATED:
1119                 {
1120                         EnableScanFooter();
1121                         int localGroup = 0;
1122                         int localItem = 0;
1123                         localGroup = GROUP_INDEX_0_WIFI_ACTIVATE;
1124                         localItem = ID_WIFI_STATUS_GROUP_ITEM_ONOFF;
1125
1126                         if (!__pTableView->IsItemChecked(localGroup, localItem))
1127                         {
1128                                 __pTableView->SetItemChecked(localGroup, localItem, true);
1129                                 __pTableView->RefreshItem(localGroup, localItem, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1130                         }
1131                         ChangeGroupIndexCount(ID_GROUP_STATUS_COUNT_TURN_ON, true);
1132                 }
1133                 break;
1134
1135         case WIFI_PRESENTATION_MODEL_EVENT_ACTIVATING:
1136                 {
1137                 }
1138                 break;
1139
1140         case WIFI_PRESENTATION_MODEL_EVENT_DEACTIVATED:
1141                 {
1142                         DisableScanFooter();
1143                         int localGroup = 0;
1144                         int localItem = 0;
1145                         localGroup = GROUP_INDEX_0_WIFI_ACTIVATE;
1146                         localItem = ID_WIFI_STATUS_GROUP_ITEM_ONOFF;
1147                         __pTableView->SetItemChecked(localGroup, localItem, false);
1148                         __pTableView->RefreshItem(localGroup, localItem, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1149                         ChangeGroupIndexCount(ID_GROUP_STATUS_COUNT_TURN_OFF, true);
1150                 }
1151                 break;
1152
1153         case WIFI_PRESENTATION_MODEL_EVENT_DEACTIVATING:
1154                 {
1155                 }
1156                 break;
1157
1158         case WIFI_PRESENTATION_MODEL_EVENT_CONNECTED:
1159                 {
1160                 }
1161                 break;
1162
1163         case WIFI_PRESENTATION_MODEL_EVENT_SCAN_COMPLETED_N:
1164                 {
1165                         int localGroup = 0;
1166                         int localItem = 0;
1167                         localGroup = GROUP_INDEX_0_WIFI_ACTIVATE;
1168                         localItem = ID_WIFI_STATUS_GROUP_ITEM_ONOFF;
1169
1170                         if (!__pTableView->IsItemChecked(localGroup, localItem))
1171                         {
1172                                 __pTableView->SetItemChecked(localGroup, localItem, true);
1173                                 __pTableView->RefreshItem(localGroup, localItem, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1174                         }
1175                         wifiScanBssCount = __pWifiPresentationModelInstance->GetAccessPointCount();
1176                         if (wifiScanBssCount == 0)
1177                         {
1178                                 AppLogDebug("Scan Error");
1179                                 ChangeNetworkGroupItemCount(0, true);
1180                         }
1181                         else
1182                         {
1183                                 ChangeNetworkGroupItemCount(wifiScanBssCount + WIFI_DEFAULT_COUNT, true);
1184                         }
1185                         ChangeGroupIndexCount(ID_GROUP_STATUS_COUNT_TURN_ON, true);
1186                 }
1187                 break;
1188
1189         case WIFI_PRESENTATION_MODEL_EVENT_SCANNING:
1190                 {
1191                 }
1192                 break;
1193
1194         case WIFI_PRESENTATION_MODEL_EVENT_RSSI_CHANGED:
1195                 {
1196                         if (__pWifiPresentationModelInstance->IsWifiActivated())
1197                         {
1198                                 __pWifiPresentationModelInstance->ScanWifi();
1199                         }
1200                 }
1201                 break;
1202
1203         case WIFI_PRESENTATION_MODEL_EVENT_MAX:
1204                 {
1205                 }
1206                 break;
1207
1208         default:
1209                 break;
1210         }
1211 }