7f487831ddf52a4d150d2b862e866d97676deb66
[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->AddActionEventListener(*this);
100         pFooter->SetItemEnabled(ID_WIFI_DIRECT_FOOTER_CONNECT, false);
101
102         SetFormBackEventListener(this);
103 }
104
105 void
106 WifiDirectConnectionForm::DisableFooter(unsigned int itemIndex)
107 {
108         Footer* pFooter = GetFooter();
109         AppAssert(pFooter);
110
111         pFooter->SetItemEnabled(itemIndex, false);
112         pFooter->Invalidate(true);
113 }
114
115 void
116 WifiDirectConnectionForm::EnableFooter(unsigned int itemIndex)
117 {
118         Footer* pFooter = GetFooter();
119         AppAssert(pFooter);
120
121         pFooter->SetItemEnabled(itemIndex, true);
122         pFooter->Invalidate(true);
123 }
124
125 void
126 WifiDirectConnectionForm::SetFooterText(const int actionId, Tizen::Base::String itemText)
127 {
128         Footer* pFooter = GetFooter();
129         AppAssert(pFooter);
130
131         FooterItem footerItem;
132         footerItem.Construct(actionId);
133         footerItem.SetText(itemText);
134
135         pFooter->RemoveItemAt(0);
136         pFooter->InsertItemAt(0, footerItem);
137 }
138
139 void
140 WifiDirectConnectionForm::CreateGroupText(void)
141 {
142         Label* pLabel;
143         Rectangle itemRectLabel = GetClientAreaBounds();
144
145         itemRectLabel.y = Y_GROUP_DEFAULT;
146         itemRectLabel.height = H_GROUP_INDEX_DEFAULT;
147
148         String itemLabelText = ResourceManager::GetString(L"IDS_ST_HEADER_AVAILABLE_DEVICES");
149
150         pLabel = new (std::nothrow) Label();
151         pLabel->Construct(itemRectLabel, itemLabelText);
152         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
153         pLabel->SetTextConfig(FONT_SIZE_MAIN_TEXT, LABEL_TEXT_STYLE_BOLD);
154         pLabel->SetTextColor(COLOR_MAIN_TEXT);
155
156         AddControl(pLabel);
157 }
158
159 void
160 WifiDirectConnectionForm::CreateTableView(void)
161 {
162         Rectangle bounds = GetClientAreaBounds();
163         Rectangle itemRectSelect;
164         Rectangle itemSelectCount;
165         String itemText = ResourceManager::GetString(L"IDS_ST_BODY_SELECT_ALL");
166         String itemSelectedText = ResourceManager::GetString(L"IDS_ST_OPT_SELECTED");
167
168         bounds.x = X_GROUP_DEFAULT;
169         bounds.y = H_GROUP_ITEM_DEFAULT;
170         bounds.width -= (bounds.x * WIDTH_GAP);
171
172         itemRectSelect = itemSelectCount = bounds;
173
174         itemRectSelect.y = H_GROUP_INDEX_DEFAULT;
175         itemRectSelect.height = H_GROUP_ITEM_DEFAULT;
176         bounds.y = itemRectSelect.y + itemRectSelect.height;
177         bounds.height -= bounds.y;
178
179         __pCheckButton = new (std::nothrow) CheckButton();
180         __pCheckButton->Construct(itemRectSelect, CHECK_BUTTON_STYLE_MARK,
181                                                                         BACKGROUND_STYLE_DEFAULT, false, itemText, GROUP_STYLE_NONE);
182         __pCheckButton->SetActionId(IDA_WIFI_DIRECT_CONNECTION_SELECT_ALL_GROUP_ITEM,
183                                                                 IDA_WIFI_DIRECT_CONNECTION_UNSELECT_ALL_GROUP_ITEM, IDA_WIFI_DIRECT_CONNECTION_SELECTED_GROUP_ITEM);
184
185         AddControl(__pCheckButton);
186
187         __pCheckButton->AddActionEventListener(*this);
188         __pCheckButton->SetColor(CHECK_BUTTON_STATUS_NORMAL, COLOR_BG_CHECKBOX);
189
190         __pTableView = new (std::nothrow) GroupedTableView();
191         __pTableView->Construct(bounds, true, TABLE_VIEW_SCROLL_BAR_STYLE_FIXED);
192         __pTableView->SetItemProvider(this);
193
194         AddControl(__pTableView);
195
196         __pTableView->AddGroupedTableViewItemEventListener(*this);
197
198         itemSelectCount.y = Y_ITEM_COUNT_DISPLAY;
199         itemSelectCount.height = H_GROUP_INDEX_NO_TITLE_DEFAULT;
200
201         __pLabelItemCount = new (std::nothrow) Label();
202         __pLabelItemCount->Construct(itemSelectCount, itemSelectedText);
203         __pLabelItemCount->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
204         __pLabelItemCount->SetTextConfig(FONT_SIZE_MAIN_TEXT, LABEL_TEXT_STYLE_BOLD);
205         __pLabelItemCount->SetTextColor(COLOR_MAIN_TEXT);
206         __pLabelItemCount->SetBackgroundColor(COLOR_BG_CHECKBOX);
207         __pLabelItemCount->SetShowState(false);
208
209         AddControl(__pLabelItemCount);
210         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
211         if (pRelativeLayout != null)
212         {
213                 pRelativeLayout->SetHorizontalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
214                 pRelativeLayout->SetVerticalFitPolicy(*__pTableView, FIT_POLICY_PARENT);
215                 delete pRelativeLayout;
216         }
217 }
218
219 void
220 WifiDirectConnectionForm::CreateInPorgressAnimationFrame(void)
221 {
222         int count = 0;
223         long duration = DURATION / FRAME_COUNT;
224
225         Bitmap* pBitmap = null;
226         AnimationFrame* pAniFrame = null;
227
228         __pAnimationFrameList = new (std::nothrow) ArrayList(SingleObjectDeleter);
229         __pAnimationFrameList->Construct();
230
231         for (count = 0; count < FRAME_COUNT; count++)
232         {
233                 String searchIconFilePath;
234                 searchIconFilePath.Format(searchIconFilePath.GetLength(), IDB_SEARCH_ICON_SIZE_LAGER_IMAGE_PATH_FORMAT, count);
235                 pBitmap = ResourceManager::GetBitmapN(searchIconFilePath);
236                 if (pBitmap == null)
237                 {
238                         AppLogDebug("GetBitmapN fail");
239                         continue;
240                 }
241                 pAniFrame = new (std::nothrow) AnimationFrame(*pBitmap, duration);
242                 __pAnimationFrameList->Add(*pAniFrame);
243                 delete pBitmap;
244         }
245 }
246
247 void
248 WifiDirectConnectionForm::DestoryInPorgressAnimationFrame(void)
249 {
250         if (__pAnimationFrameList != null)
251         {
252                 delete __pAnimationFrameList;
253                 __pAnimationFrameList = null;
254         }
255 }
256
257 void
258 WifiDirectConnectionForm::SetHandlerInProgressAnimation(void)
259 {
260         Rectangle itemRectLabel = Rectangle(X_SEARCH_ICON, Y_SEARCH_ICON, W_SEARCH_ICON, H_SEARCH_ICON);
261
262         __pAnimation = new (std::nothrow) Animation();
263         result r = __pAnimation->Construct(itemRectLabel, *__pAnimationFrameList);
264         if (IsFailed(r))
265         {
266                 AppLogDebug("__pAnimation->Construct failed(%s)", GetErrorMessage(r));
267                 delete __pAnimation;
268                 return;
269         }
270         __pAnimation->SetRepeatCount(ID_WIFI_DIRECT_CONNECTION_COUNT_DEFAULT);
271
272         __pAnimation->AddAnimationEventListener(*this);
273         __pAnimation->SetShowState(false);
274
275         AddControl(__pAnimation);
276 }
277
278 void
279 WifiDirectConnectionForm::RemoveHandlerInProgressAnimation(void)
280 {
281         if (__pAnimation != null)
282         {
283                 __pAnimation = null;
284         }
285 }
286
287 void
288 WifiDirectConnectionForm::PlayInPorgressAnimation(void)
289 {
290         if (__pAnimation != null)
291         {
292                 __pAnimation->SetRepeatCount(ID_WIFI_DIRECT_IN_PROGRESS_REPEAT_COUNT);
293                 __pAnimation->SetShowState(true);
294                 __pAnimation->Play();
295         }
296 }
297
298 void
299 WifiDirectConnectionForm::StopInPorgressAnimation(void)
300 {
301         if (__pAnimation != null)
302         {
303                 __pAnimation->Stop();
304                 __pAnimation->SetShowState(false);
305         }
306 }
307
308 result
309 WifiDirectConnectionForm::OnInitializing(void)
310 {
311         SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
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 }