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