Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StWifiDirectConnectionForm.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                StWifiDirectConnectionForm.cpp
19  * @brief               This is the implementation file for WifiDirectConnectionForm class.
20  */
21
22 #include "StResourceManager.h"
23 #include "StTypes.h"
24 #include "StWifiDirectConnectionForm.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Runtime;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Net::Wifi;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 #define WIFI_DIRECT_CONNECTION_DEBUG_CODE
37
38 static const int Y_ITEM_COUNT_DISPLAY = 968;
39 static const int DURATION = 500;
40 static const int FRAME_COUNT = 30;
41
42 static const int X_SEARCH_ICON = 630;
43 static const int Y_SEARCH_ICON = 10;
44 static const int W_SEARCH_ICON = 62;
45 static const int H_SEARCH_ICON = 62;
46
47 static const int ID_FOOTER_ITEM_INDEX_1 = 0;
48 static const int ID_FOOTER_ITEM_INDEX_2 = 1;
49
50 static const int ID_WIFI_DIRECT_CONNECTION_COUNT_DEFAULT = 1;
51 static const int ID_WIFI_DIRECT_CONNECTION_ITEM_COUNT_TEXT_LENGTH = 5;
52 static const int ID_WIFI_DIRECT_CONNECTION_BALLOON_POPUP_TIMER_EXPIRED_TIME = 2000;
53 static const int ID_WIFI_DIRECT_IN_PROGRESS_REPEAT_COUNT = 1000;
54
55 static const int IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE = 100;
56 static const int IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 1;
57 static const int IDA_WIFI_DIRECT_CONNECTION_FOOTER_STOP = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 2;
58 static const int IDA_WIFI_DIRECT_CONNECTION_CONNECT = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 3;
59 static const int IDA_WIFI_DIRECT_CONNECTION_SELECTED_GROUP_ITEM = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 4;
60 static const int IDA_WIFI_DIRECT_CONNECTION_SELECT_ALL_GROUP_ITEM = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 4;
61 static const int IDA_WIFI_DIRECT_CONNECTION_UNSELECT_ALL_GROUP_ITEM = IDA_WIFI_DIRECT_CONNECTION_ACTION_ID_BASE + 5;
62
63 static const int ID_WIFI_DIRECT_FOOTER_SCAN = 0;
64 static const int ID_WIFI_DIRECT_FOOTER_CONNECT = 1;
65
66 WifiDirectConnectionForm::WifiDirectConnectionForm(void)
67         : __pWifiDirectManagerInstance(null)
68         , __pLabelItemCount(null)
69         , __pCheckButton(null)
70         , __pAnimationFrameList(null)
71         , __pAnimation(null)
72         , __groupScanDeviceListInfoCount(0)
73 {
74         __balloonPopuptimer.Construct(*this);
75 }
76
77 WifiDirectConnectionForm::~WifiDirectConnectionForm(void)
78 {
79 }
80
81 void
82 WifiDirectConnectionForm::CreateFooter(void)
83 {
84         Footer* pFooter = GetFooter();
85         AppAssert(pFooter);
86
87         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
88
89         FooterItem footerScan;
90         footerScan.Construct(IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN);
91         footerScan.SetText(ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
92
93         FooterItem footerConnect;
94         footerConnect.Construct(IDA_WIFI_DIRECT_CONNECTION_CONNECT);
95         footerConnect.SetText(ResourceManager::GetString(L"IDS_WIFI_BODY_CONNECT"));
96
97         pFooter->AddItem(footerScan);
98         pFooter->AddItem(footerConnect);
99         pFooter->SetBackButton();
100         pFooter->AddActionEventListener(*this);
101         pFooter->SetItemEnabled(ID_WIFI_DIRECT_FOOTER_CONNECT, false);
102
103         SetFormBackEventListener(this);
104 }
105
106 void
107 WifiDirectConnectionForm::DisableFooter(unsigned int itemIndex)
108 {
109         Footer* pFooter = GetFooter();
110         AppAssert(pFooter);
111
112         pFooter->SetItemEnabled(itemIndex, false);
113         pFooter->Invalidate(true);
114 }
115
116 void
117 WifiDirectConnectionForm::EnableFooter(unsigned int itemIndex)
118 {
119         Footer* pFooter = GetFooter();
120         AppAssert(pFooter);
121
122         pFooter->SetItemEnabled(itemIndex, true);
123         pFooter->Invalidate(true);
124 }
125
126 void
127 WifiDirectConnectionForm::SetFooterText(const int actionId, Tizen::Base::String itemText)
128 {
129         Footer* pFooter = GetFooter();
130         AppAssert(pFooter);
131
132         FooterItem footerItem;
133         footerItem.Construct(actionId);
134         footerItem.SetText(itemText);
135
136         pFooter->RemoveItemAt(0);
137         pFooter->InsertItemAt(0, footerItem);
138 }
139
140 void
141 WifiDirectConnectionForm::CreateGroupText(void)
142 {
143         Label* pLabel;
144         Rectangle itemRectLabel = GetClientAreaBounds();
145
146         itemRectLabel.y = Y_GROUP_DEFAULT;
147         itemRectLabel.height = H_GROUP_INDEX_DEFAULT;
148
149         String itemLabelText = ResourceManager::GetString(L"IDS_ST_HEADER_AVAILABLE_DEVICES");
150
151         pLabel = new (std::nothrow) Label();
152         pLabel->Construct(itemRectLabel, itemLabelText);
153         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
154         pLabel->SetTextConfig(FONT_SIZE_MAIN_TEXT, LABEL_TEXT_STYLE_BOLD);
155         pLabel->SetTextColor(COLOR_MAIN_TEXT);
156
157         AddControl(pLabel);
158 }
159
160 void
161 WifiDirectConnectionForm::CreateTableView(void)
162 {
163         Rectangle bounds = GetClientAreaBounds();
164         Rectangle itemRectSelect;
165         Rectangle itemSelectCount;
166         String itemText = ResourceManager::GetString(L"IDS_ST_BODY_SELECT_ALL");
167         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
168
169         bounds.x = X_GROUP_DEFAULT;
170         bounds.y = H_GROUP_ITEM_DEFAULT;
171         bounds.width -= (bounds.x * WIDTH_GAP);
172
173         itemRectSelect = itemSelectCount = bounds;
174
175         itemRectSelect.y = H_GROUP_INDEX_DEFAULT;
176         itemRectSelect.height = H_GROUP_ITEM_DEFAULT;
177         bounds.y = itemRectSelect.y + itemRectSelect.height;
178         bounds.height -= bounds.y;
179
180         __pCheckButton = new (std::nothrow) CheckButton();
181         __pCheckButton->Construct(itemRectSelect, CHECK_BUTTON_STYLE_MARK,
182                                                                         BACKGROUND_STYLE_DEFAULT, false, itemText, GROUP_STYLE_NONE);
183         __pCheckButton->SetActionId(IDA_WIFI_DIRECT_CONNECTION_SELECT_ALL_GROUP_ITEM,
184                                                                 IDA_WIFI_DIRECT_CONNECTION_UNSELECT_ALL_GROUP_ITEM, IDA_WIFI_DIRECT_CONNECTION_SELECTED_GROUP_ITEM);
185
186         AddControl(__pCheckButton);
187
188         __pCheckButton->AddActionEventListener(*this);
189         __pCheckButton->SetColor(CHECK_BUTTON_STATUS_NORMAL, COLOR_BG_CHECKBOX);
190
191         __pTableView = new (std::nothrow) GroupedTableView();
192         __pTableView->Construct(bounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FIXED);
193         __pTableView->SetItemProvider(this);
194
195         AddControl(__pTableView);
196
197         __pTableView->AddGroupedTableViewItemEventListener(*this);
198
199         itemSelectCount.y = Y_ITEM_COUNT_DISPLAY;
200         itemSelectCount.height = H_GROUP_INDEX_NO_TITLE_DEFAULT;
201
202         __pLabelItemCount = new (std::nothrow) Label();
203         __pLabelItemCount->Construct(itemSelectCount, itemSelectedText);
204         __pLabelItemCount->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
205         __pLabelItemCount->SetTextConfig(FONT_SIZE_MAIN_TEXT, LABEL_TEXT_STYLE_BOLD);
206         __pLabelItemCount->SetTextColor(COLOR_MAIN_TEXT);
207         __pLabelItemCount->SetBackgroundColor(COLOR_BG_CHECKBOX);
208         __pLabelItemCount->SetShowState(false);
209
210         AddControl(__pLabelItemCount);
211         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
212         if (pRelativeLayout != null)
213         {
214                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
215                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
216                 delete pRelativeLayout;
217         }
218 }
219
220 void
221 WifiDirectConnectionForm::CreateInPorgressAnimationFrame(void)
222 {
223         int count = 0;
224         long duration = DURATION / FRAME_COUNT;
225
226         Bitmap* pBitmap = null;
227         AnimationFrame* pAniFrame = null;
228
229         __pAnimationFrameList = new (std::nothrow) ArrayList(SingleObjectDeleter);
230         __pAnimationFrameList->Construct();
231
232         for (count = 0; count < FRAME_COUNT; count++)
233         {
234                 String searchIconFilePath;
235                 searchIconFilePath.Format(searchIconFilePath.GetLength(), IDB_SEARCH_ICON_SIZE_LAGER_IMAGE_PATH_FORMAT, count);
236                 pBitmap = ResourceManager::GetBitmapN(searchIconFilePath);
237                 if (pBitmap == null)
238                 {
239                         AppLogDebug("GetBitmapN fail");
240                         continue;
241                 }
242                 pAniFrame = new (std::nothrow) AnimationFrame(*pBitmap, duration);
243                 __pAnimationFrameList->Add(*pAniFrame);
244                 delete pBitmap;
245         }
246 }
247
248 void
249 WifiDirectConnectionForm::DestoryInPorgressAnimationFrame(void)
250 {
251         if (__pAnimationFrameList != null)
252         {
253                 delete __pAnimationFrameList;
254                 __pAnimationFrameList = null;
255         }
256 }
257
258 void
259 WifiDirectConnectionForm::SetHandlerInProgressAnimation(void)
260 {
261         Rectangle itemRectLabel = Rectangle(X_SEARCH_ICON, Y_SEARCH_ICON, W_SEARCH_ICON, H_SEARCH_ICON);
262
263         __pAnimation = new (std::nothrow) Animation();
264         result r = __pAnimation->Construct(itemRectLabel, *__pAnimationFrameList);
265         if (IsFailed(r))
266         {
267                 AppLogDebug("__pAnimation->Construct failed(%s)", GetErrorMessage(r));
268                 delete __pAnimation;
269                 return;
270         }
271         __pAnimation->SetRepeatCount(ID_WIFI_DIRECT_CONNECTION_COUNT_DEFAULT);
272
273         __pAnimation->AddAnimationEventListener(*this);
274         __pAnimation->SetShowState(false);
275
276         AddControl(__pAnimation);
277 }
278
279 void
280 WifiDirectConnectionForm::RemoveHandlerInProgressAnimation(void)
281 {
282         if (__pAnimation != null)
283         {
284                 __pAnimation = null;
285         }
286 }
287
288 void
289 WifiDirectConnectionForm::PlayInPorgressAnimation(void)
290 {
291         if (__pAnimation != null)
292         {
293                 __pAnimation->SetRepeatCount(ID_WIFI_DIRECT_IN_PROGRESS_REPEAT_COUNT);
294                 __pAnimation->SetShowState(true);
295                 __pAnimation->Play();
296         }
297 }
298
299 void
300 WifiDirectConnectionForm::StopInPorgressAnimation(void)
301 {
302         if (__pAnimation != null)
303         {
304                 __pAnimation->Stop();
305                 __pAnimation->SetShowState(false);
306         }
307 }
308
309 result
310 WifiDirectConnectionForm::OnInitializing(void)
311 {
312         CreateHeader(ResourceManager::GetString(L"IDS_WIFI_BUTTON_MULTI_CONNECT"));
313         CreateFooter();
314         CreateGroupText();
315
316         CreateInPorgressAnimationFrame();
317         SetHandlerInProgressAnimation();
318         CreateTableView();
319
320         __pWifiDirectManagerInstance = GetWifiDirectManagerInstance();
321         result r = E_SUCCESS;
322
323         if ((__pWifiDirectManagerInstance == null)
324                 || IsFailed(GetLastResult()))
325         {
326                 if (__pWifiDirectManagerInstance == null)
327                 {
328                         r = E_FAILURE;
329                 }
330                 return r;
331         }
332
333         if (__pWifiDirectManagerInstance->IsActivated())
334         {
335                 DisableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
336                 TableViewItemInit();
337                 ReAdjustScanDeviceListInfoCount();
338         }
339         else
340         {
341                 AppLogDebug("WifiDirect is state of Deactivated");
342                 return E_FAILURE;
343         }
344
345         return r;
346 }
347
348 result
349 WifiDirectConnectionForm::OnTerminating(void)
350 {
351         __pTableView = null;
352         __pLabelItemCount = null;
353         __pCheckButton = null;
354         __pWifiDirectManagerInstance = null;
355
356         RemoveHandlerInProgressAnimation();
357         DestoryInPorgressAnimationFrame();
358
359         SetFormBackEventListener(null);
360         return E_SUCCESS;
361 }
362
363 void
364 WifiDirectConnectionForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
365 {
366         __pTableView->UpdateTableView();
367 }
368
369 void
370 WifiDirectConnectionForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
371 {
372 }
373
374 void
375 WifiDirectConnectionForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
376 {
377         SceneManager* pSceneManager = SceneManager::GetInstance();
378         AppAssert(pSceneManager);
379
380         if ((__pWifiDirectManagerInstance != null)
381                 && (__pWifiDirectManagerInstance->IsScanInProgress()))
382         {
383                 __pWifiDirectManagerInstance->CancelRemoteDeviceScan();
384         }
385
386         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
387 }
388
389 int
390 WifiDirectConnectionForm::GetGroupCount(void)
391 {
392         return ID_WIFI_DIRECT_CONNECTION_COUNT_DEFAULT;
393 }
394
395 int
396 WifiDirectConnectionForm::GetItemCount(int groupIndex)
397 {
398         return __groupScanDeviceListInfoCount;
399 }
400
401 TableViewGroupItem*
402 WifiDirectConnectionForm::CreateGroupItem(int groupIndex, int itemWidth)
403 {
404         return null;
405 }
406
407 TableViewItem*
408 WifiDirectConnectionForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
409 {
410         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
411         Rectangle itemIconLabelRect;
412         Rectangle itemIconRect;
413         String itemText;
414         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_MOBILE_AP);
415         Label* pLabel = null;
416         int fontSize = GetFontSize();
417
418         TableViewItem* pItem = new (std::nothrow) TableViewItem();
419
420         WifiDirectDeviceInfo* pScanRemoteDevice = __pWifiDirectManagerInstance->GetScanDeviceListInfoAt(itemIndex);
421         if (pScanRemoteDevice != null)
422         {
423                 itemText = pScanRemoteDevice->GetDeviceName();
424                 if (itemText.IsEmpty() == true)
425                 {
426                         delete pItem;
427                         return null;
428                 }
429         }
430         else
431         {
432                 delete pItem;
433                 return null;
434         }
435
436         RelativeLayout relativeLayout;
437         relativeLayout.Construct();
438
439         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
440         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
441
442         ItemTypeIconAndOneLine(itemIconRect, itemIconLabelRect);
443
444         pLabel = new (std::nothrow) Label();
445         pLabel->Construct(itemIconRect, L"");
446         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
447         pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
448         pLabel->SetBackgroundBitmap(*pBitmap);
449
450         pItem->AddControl(pLabel);
451
452         pLabel = new (std::nothrow) Label();
453         pLabel->Construct(itemIconLabelRect, itemText);
454         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
455         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_BOLD);
456         pLabel->SetTextColor(COLOR_MAIN_TEXT);
457
458         pItem->AddControl(pLabel);
459         relativeLayout.SetMargin(*pLabel, itemIconLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
460         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
461         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
462
463         return pItem;
464 }
465
466 bool
467 WifiDirectConnectionForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
468 {
469         delete pItem;
470         pItem = null;   
471
472         return true;
473 }
474
475 bool
476 WifiDirectConnectionForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
477 {
478         delete pItem;
479         pItem = null;
480
481         return true;
482 }
483
484 void
485 WifiDirectConnectionForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
486 {
487         int itemCount = 0;
488         int count = 0;
489         unsigned int checkedItemCount = 0;
490         int localGroup = 0;
491         int localItem = 0;
492
493         if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
494         {
495                 tableView.SetItemChecked(groupIndex, itemIndex, true);
496         }
497         else if (status == TABLE_VIEW_ITEM_STATUS_UNCHECKED)
498         {
499                 tableView.SetItemChecked(groupIndex, itemIndex, false);
500         }
501         else
502         {
503                 return;
504         }
505
506         itemCount = tableView.GetItemCountAt(0);
507         for (count = 0; count < itemCount; count++)
508         {
509                 localGroup = 0;
510                 localItem = count;
511
512                 if (__pTableView->IsItemChecked(groupIndex, itemIndex))
513                 {
514                         checkedItemCount++;
515                 }
516         }
517
518         if (checkedItemCount != 0)
519         {
520                 EnableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
521                 ShowBalloonPopup(checkedItemCount);
522         }
523         else
524         {
525                 DisableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
526         }
527 }
528
529 void
530 WifiDirectConnectionForm::OnActionPerformed(const Control& source, int actionId)
531 {
532         result r = E_SUCCESS;
533         Footer* pFooter = GetFooter();
534         AppAssert(pFooter);
535
536         switch (actionId)
537         {
538         case IDA_WIFI_DIRECT_CONNECTION_CONNECT:
539                 {
540                         SceneManager* pSceneManager = SceneManager::GetInstance();
541                         AppAssert(pSceneManager);
542
543                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
544                 }
545                 break;
546
547         case IDA_WIFI_DIRECT_CONNECTION_SELECT_ALL_GROUP_ITEM:
548                 {
549                         SelectAllGroupItem();
550                         EnableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
551                 }
552                 break;
553
554         case IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN:
555                 {
556                         DisableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
557                         DisableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
558                         r = __pWifiDirectManagerInstance->RemoteDeviceScan();
559                         if (!IsFailed(r))
560                         {
561                                 SetFooterText(IDA_WIFI_DIRECT_CONNECTION_FOOTER_STOP, ResourceManager::GetString(L"IDS_COM_BODY_STOP"));
562                                 ReAdjustScanDeviceListInfoCount();
563                                 PlayInPorgressAnimation();
564                                 UpdateTableView();
565                         }
566                         EnableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
567                 }
568                 break;
569
570         case IDA_WIFI_DIRECT_CONNECTION_FOOTER_STOP:
571                 {
572                         DisableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
573                         __pWifiDirectManagerInstance->CancelRemoteDeviceScan();
574                         StopInPorgressAnimation();
575                         SetFooterText(IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
576                         EnableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
577                 }
578                 break;
579
580         case IDA_WIFI_DIRECT_CONNECTION_UNSELECT_ALL_GROUP_ITEM:
581                 {
582                         UnSelectAllGroupItem();
583                         DisableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
584                 }
585                 break;
586
587         default:
588                 break;
589         }
590 }
591
592 void
593 WifiDirectConnectionForm::TableViewItemInit(void)
594 {
595         __groupScanDeviceListInfoCount = 0;
596 }
597
598 void
599 WifiDirectConnectionForm::ReAdjustScanDeviceListInfoCount(void)
600 {
601         if ((__pWifiDirectManagerInstance == null)
602                 || (__pTableView == null))
603         {
604                 AppLogDebug("__pWifiDirectManagerInstance or __pTableView is null");
605                 return;
606         }
607
608         unsigned int itemCount = __pWifiDirectManagerInstance->GetScanDeviceListInfoCount();
609         if (itemCount != 0)
610         {
611                 __groupScanDeviceListInfoCount = itemCount;
612         }
613 }
614
615 void
616 WifiDirectConnectionForm::UpdateTableView(void)
617 {
618         if (__pTableView == null)
619         {
620                 AppLogDebug("__pTableView is null");
621                 return;
622         }
623         __pTableView->UpdateTableView();
624 }
625
626 void
627 WifiDirectConnectionForm::OnWifiDirectManagerEventCompleted(WifiDirectManagerEvent requestEvent, result r)
628 {
629         if (__pWifiDirectManagerInstance == null)
630         {
631                 return;
632         }
633
634         switch (requestEvent)
635         {
636         case WIFI_DIRECT_MANAGER_EVENT_SCAN_COMPLETED_N:
637                 {
638                         DisableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
639                         SetFooterText(IDA_WIFI_DIRECT_CONNECTION_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
640                         EnableFooter(ID_WIFI_DIRECT_FOOTER_SCAN);
641                         StopInPorgressAnimation();
642                         ReAdjustScanDeviceListInfoCount();
643                         UpdateTableView();
644                 }
645                 break;
646
647         default:
648                 {
649                         SceneManager* pSceneManager = SceneManager::GetInstance();
650                         AppAssert(pSceneManager);
651
652                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
653                         AppLogDebug("Requested Event : [%d], Result : [%d]", requestEvent, r);
654                 }
655                 break;
656         }
657 }
658
659 WifiDirectManager*
660 WifiDirectConnectionForm::GetWifiDirectManagerInstance(void)
661 {
662         if (WifiDirectManager::GetInstance() == null)
663         {
664                 return null;
665         }
666
667         WifiDirectManager::GetInstance()->RemoveIWifiDirectManagerEventListener();
668         WifiDirectManager::GetInstance()->SetIWifiDirectManagerEventListener(*this);
669
670         return WifiDirectManager::GetInstance();
671 }
672
673 void
674 WifiDirectConnectionForm::ShowBalloonPopup(unsigned int itemCount)
675 {
676         String itemCountText;
677         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
678
679         if (__pLabelItemCount == null)
680         {
681                 AppLogDebug("__pLabelItemCount is null");
682                 return;
683         }
684
685         itemCountText.Format(ID_WIFI_DIRECT_CONNECTION_ITEM_COUNT_TEXT_LENGTH, L" (%d)", itemCount);
686         itemSelectedText.Insert(itemCountText, itemSelectedText.GetLength());
687
688         __pLabelItemCount->SetText(itemSelectedText);
689         __pLabelItemCount->SetShowState(true);
690         __pLabelItemCount->Invalidate(true);
691
692         __balloonPopuptimer.Start(ID_WIFI_DIRECT_CONNECTION_BALLOON_POPUP_TIMER_EXPIRED_TIME);
693 }
694
695 void
696 WifiDirectConnectionForm::SelectAllGroupItem(void)
697 {
698         int groupItemCount = 0;
699         int loopCount = 0;
700         int checkedItemCount = 0;
701         int localGroup = 0;
702         int localItem = 0;
703
704         if (__pTableView == null)
705         {
706                 AppLogDebug("__pTableView is null ");
707                 return;
708         }
709
710         groupItemCount = __pTableView->GetItemCountAt(0);
711         __pTableView->UpdateTableView();
712
713         for (loopCount = 0; loopCount < groupItemCount; loopCount++)
714         {
715                 localGroup = 0;
716                 localItem = loopCount;
717                 __pTableView->SetItemChecked(localGroup, localItem, true);
718
719                 if (__pTableView->IsItemChecked(localGroup, localItem))
720                 {
721                         checkedItemCount++;
722                 }
723         }
724
725         EnableFooter(ID_WIFI_DIRECT_FOOTER_CONNECT);
726         ShowBalloonPopup(checkedItemCount);
727 }
728
729 void
730 WifiDirectConnectionForm::UnSelectAllGroupItem(void)
731 {
732         int GroupItemCount = 0;
733         int loopCount = 0;
734         int localGroup = 0;
735         int localItem = 0;
736
737         if ((__pTableView == null)
738                 || (__pCheckButton == null))
739         {
740                 AppLogDebug("__pTableView or __pCheckButton is null ");
741                 return;
742         }
743
744         GroupItemCount = __pTableView->GetItemCountAt(0);
745
746         __pTableView->UpdateTableView();
747         __pCheckButton->SetSelected(false);
748
749         for (loopCount = 0; loopCount < GroupItemCount; loopCount++)
750         {
751                 localGroup = 0;
752                 localItem = loopCount;
753
754                 __pTableView->SetItemChecked(localGroup, localItem, false);
755         }
756 }
757
758 void
759 WifiDirectConnectionForm::OnTimerExpired(Timer& timer)
760 {
761         if (__pLabelItemCount != null)
762         {
763                 __pLabelItemCount->SetShowState(false);
764                 __pLabelItemCount->Invalidate(true);
765         }
766 }
767
768 int
769 WifiDirectConnectionForm::GetDefaultGroupItemHeight(void)
770 {
771         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
772 }
773
774 int
775 WifiDirectConnectionForm::GetDefaultItemHeight(void)
776 {
777         return H_GROUP_ITEM_DEFAULT;
778 }
779
780 void
781 WifiDirectConnectionForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
782 {
783 }
784
785 void
786 WifiDirectConnectionForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
787 {
788 }
789
790 void
791 WifiDirectConnectionForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
792 {
793 }
794
795 void
796 WifiDirectConnectionForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
797 {
798 }