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 / StBluetoothForm.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                StBluetoothForm.cpp
19  * @brief               This is the implementation file for BluetoothForm class.
20  */
21
22 #include <FSystem.h>
23 #include "StBluetoothForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
26 #include "StTypes.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Net::Bluetooth;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
37
38 static const char APPCONTROL_REQUEST_DEFAULT = 0x00;
39 static const char APPCONTROL_REQUEST_BLUETOOTH = 0x20;
40
41 static const int ID_BLUETOOTH_COUNT_DEFAULT = 1;
42 static const int ID_BLUETOOTH_TABLEVIEW_ITEM_SPECIFIED_INPUT_PARMETER = -1;
43 static const int ID_FOOTER_ITEM_INDEX_1 = 0;
44
45 static const int IDA_BLUETOOTH_FOOTER_BASE = 100;
46 static const int IDA_BLUETOOTH_FOOTER_SCAN = IDA_BLUETOOTH_FOOTER_BASE + 1;
47 static const int IDA_BLUETOOTH_FOOTER_CANCEL = IDA_BLUETOOTH_FOOTER_BASE + 2;
48
49 static const int X_IN_PROGRESS_ANIMATION = 600;
50 static const int Y_IN_PROGRESS_ANIMATION = 31;
51 static const int W_IN_PROGRESS_ANIMATION = 62;
52 static const int H_IN_PROGRESS_ANIMATION = 62;
53 static const int ID_IN_PROGRESS_DURATION = 500;
54 static const int ID_IN_PROGRESS_FRAME_COUNT = 30;
55 static const int ID_IN_PROGRESS__REPEAT_COUNT = 1000;
56
57 static const int ID_BLUETOOTH_VISIBLE_GROUP_ITEM_CONUNT = 5;
58 static const int SEARCH_ICON_FILE_PATH_NAME_LENGTH_MAX = 100;
59
60 enum BluetoothTurnOnOffStatusItem
61 {
62         BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_BASE,
63         BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_TOGGLE = BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_BASE,
64         BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_VISIBLE_STATUS,
65         BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_MAX
66 };
67
68 enum BluetoothGroupItem
69 {
70         BLUETOOTH_GROUP_ITEM_BASE,
71         BLUETOOTH_GROUP_ITEM_TURN_ON_OFF_STATUS,
72         BLUETOOTH_GROUP_ITEM_VISIBLE,
73         BLUETOOTH_GROUP_ITEM_PAIRED_DEVICES,
74         BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES,
75         BLUETOOTH_GROUP_ITEM_MAX
76 };
77
78 enum BluetoothGroupIndex
79 {
80         BLUETOOTH_GROUP_INDEX_BASE,
81         BLUETOOTH_GROUP_INDEX_0 = BLUETOOTH_GROUP_INDEX_BASE,
82         BLUETOOTH_GROUP_INDEX_1,
83         BLUETOOTH_GROUP_INDEX_2,
84         BLUETOOTH_GROUP_INDEX_3,
85         BLUETOOTH_GROUP_INDEX_MAX
86 };
87
88 BluetoothForm::BluetoothForm(void)
89         : __pBluetoothPresentationModelInstance(null)
90         , __pPendingEventReceivedForm(null)
91         , __pAnimationFrameList(null)
92         , __isVisibleGroupExpanded(false)
93         , __isAppControlRequest(APPCONTROL_REQUEST_DEFAULT)
94         , __categoryCheck(L"")
95 {
96         InitStateChangedTabviewItemTag();
97 }
98
99 BluetoothForm::~BluetoothForm(void)
100 {
101 }
102
103 void
104 BluetoothForm::CreateFooter(void)
105 {
106         Footer* pFooter = GetFooter();
107         AppAssert(pFooter);
108
109         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
110
111         FooterItem footerScan;
112         footerScan.Construct(IDA_BLUETOOTH_FOOTER_SCAN);
113         footerScan.SetText(ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
114
115         pFooter->AddItem(footerScan);
116         pFooter->AddActionEventListener(*this);
117         pFooter->SetItemEnabled(ID_FOOTER_ITEM_INDEX_1, false);
118
119         SetFormBackEventListener(this);
120 }
121
122 result
123 BluetoothForm::OnInitializing(void)
124 {
125         SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
126         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH"));
127         CreateFooter();
128         CreateTableView();
129         CreateSearchAnimationFrame();
130
131         bool EnableStatus = false;
132         if (0)//SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) != E_SUCCESS)
133         {
134                 AppLogDebug("Bluetooth is not supported");
135                 DisableScanFooter();
136         }
137
138         result r = E_FAILURE;
139         if (EnableStatus == true)
140         {
141                 r = BluetoothPresentationModelInit();
142                 if (IsFailed(r))
143                 {
144                         AppLogDebug("BluetoothPresentationModelInit fail [%s]", GetErrorMessage(r));
145                         return r;
146                 }
147
148                 SetUserPendingEventReceivedForm(this);
149         }
150
151         RefreshGroupIndexTranslateTable();
152
153         if (EnableStatus == true)
154         {
155                 if (__pBluetoothPresentationModelInstance->IsBluetoothActivated() == true)
156                 {
157                         EnableScanFooter();
158                 }
159                 return r;
160         }
161         __pTableView->UpdateTableView();
162         __pTableView->CollapseGroup(BLUETOOTH_GROUP_INDEX_1);
163         return E_SUCCESS;
164 }
165
166 result
167 BluetoothForm::OnTerminating(void)
168 {
169         __pBluetoothPresentationModelInstance = null;
170         __pTableView = null;
171         __pPendingEventReceivedForm = null;
172
173         DestorySearchAnimationFrame();
174
175         SetFormBackEventListener(null);
176         return E_SUCCESS;
177 }
178
179 void
180 BluetoothForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
181 {
182         if (__pBluetoothPresentationModelInstance == null)
183         {
184                 if (pArgs != null)
185                 {
186                         __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
187
188                         if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/bluetooth/visibility") == 0)
189                         {
190                                 __isAppControlRequest = APPCONTROL_REQUEST_BLUETOOTH;
191                         }
192                         delete pArgs;
193                         pArgs = null;
194                 }
195                 __pTableView->SetItemEnabled(BLUETOOTH_GROUP_INDEX_0, BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_VISIBLE_STATUS, false);
196                 return;
197         }
198
199         if (previousSceneId.Equals(String(IDSCN_BLUETOOTH_DETAIL)))
200         {
201                 __pBluetoothPresentationModelInstance->SetEventListener(this);
202
203                 RefreshGroupIndexTranslateTable();
204                 UpdateTableView();
205         }
206         else if (pArgs != null)
207         {
208                 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
209
210                 if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/bluetooth/visibility") == 0)
211                 {
212                         __isAppControlRequest = APPCONTROL_REQUEST_BLUETOOTH;
213                 }
214                 delete pArgs;
215                 pArgs = null;
216         }
217         __pTableView->UpdateTableView();
218 }
219
220 void
221 BluetoothForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
222 {
223 }
224
225 void
226 BluetoothForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
227 {
228         SceneManager* pSceneManager = SceneManager::GetInstance();
229         AppAssert(pSceneManager);
230
231         __pTableView->CollapseGroup(BLUETOOTH_GROUP_INDEX_1);
232         if (__pBluetoothPresentationModelInstance != null)
233         {
234                 __pBluetoothPresentationModelInstance->SetBluetoothEventInProgress(BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_EXIT);
235                 __pBluetoothPresentationModelInstance->CancelBluetoothDiscovery();
236         }
237
238         if (__isAppControlRequest != APPCONTROL_REQUEST_DEFAULT)
239         {
240                 UiApp* pApp = UiApp::GetInstance();
241                 AppAssert(pApp);
242                 AppControlBluetoothResult();
243                 pApp->Terminate();
244         }
245         else
246         {
247                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
248         }
249 }
250
251 int
252 BluetoothForm::GetGroupCount(void)
253 {
254         return __groupIndexTranslateTable[ID_GROUP_TOTAL_COUNT];
255 }
256
257 int
258 BluetoothForm::GetItemCount(int groupIndex)
259 {
260         int itemCount = 0;
261
262         switch (groupIndex)
263         {
264         case BLUETOOTH_GROUP_INDEX_0:
265                 {
266                         itemCount = __groupItemCount[BLUETOOTH_GROUP_INDEX_0];
267                 }
268                 break;
269
270         case BLUETOOTH_GROUP_INDEX_1:
271                 {
272                         itemCount = __groupItemCount[BLUETOOTH_GROUP_INDEX_1];
273                 }
274                 break;
275
276         case BLUETOOTH_GROUP_INDEX_2:
277                 {
278                         itemCount = __groupItemCount[BLUETOOTH_GROUP_INDEX_2];
279                 }
280                 break;
281
282         case BLUETOOTH_GROUP_INDEX_3:
283                 {
284                         itemCount = __groupItemCount[BLUETOOTH_GROUP_INDEX_3];
285                 }
286                 break;
287
288         default:
289                 break;
290         }
291
292         AppLogDebug("[groupIndex:%d]GetItemCount %d", groupIndex, itemCount);
293         return itemCount;
294 }
295
296 TableViewGroupItem*
297 BluetoothForm::CreateGroupItem(int groupIndex, int itemWidth)
298 {
299         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
300         Rectangle itemRectangle(X_GROUP_ITEM_DEFAULT_LABEL, Y_GROUP_ITEM_DEFAULT_LABEL, itemWidth, itemHeight);
301         String groupText;
302
303         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
304         if (pItem == null)
305         {
306                 AppLogDebug("__pBluetoothPresentationModelInstance or pItem is null");
307                 return null;
308         }
309
310         switch (__groupIndexTranslateTable[groupIndex])
311         {
312         case BLUETOOTH_GROUP_ITEM_VISIBLE:
313                 {
314                         itemRectangle.y = H_GROUP_INDEX_TITLE_TEXT;
315                         itemHeight = itemRectangle.height = 0;
316
317                         __pTableView->CollapseGroup(groupIndex);
318                 }
319                 break;
320
321         case BLUETOOTH_GROUP_ITEM_PAIRED_DEVICES:
322                 {
323                         groupText = ResourceManager::GetString(L"IDS_BT_BODY_PAIRED_DEVICES");
324                         itemHeight = H_GROUP_INDEX_DEFAULT;
325                         itemRectangle.y = H_GROUP_INDEX_TITLE_TEXT;
326                         itemRectangle.height = H_GROUP_INDEX_DEFAULT - H_GROUP_INDEX_TITLE_TEXT;
327                 }
328                 break;
329
330         case BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES:
331                 {
332                         groupText = ResourceManager::GetString(L"IDS_ST_HEADER_AVAILABLE_DEVICES");
333                         itemHeight = H_GROUP_INDEX_DEFAULT;
334                         itemRectangle.y = H_GROUP_INDEX_TITLE_TEXT;
335                         itemRectangle.height = H_GROUP_INDEX_DEFAULT - H_GROUP_INDEX_TITLE_TEXT;
336                 }
337                 break;
338
339         default:
340                 break;
341         }
342
343         RelativeLayout relativeLayout;
344         relativeLayout.Construct();
345
346         result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
347         if (IsFailed(r))
348         {
349                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
350                 delete pItem;
351                 return null;
352         }
353
354         Label* pLabel = new (std::nothrow) Label();
355         if (pLabel == null)
356         {
357                 AppLogDebug("pLabel is null");
358                 return pItem;
359         }
360
361         r = pLabel->Construct(itemRectangle, groupText);
362         if (IsFailed(r))
363         {
364                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
365                 delete pLabel;
366                 return pItem;
367         }
368
369         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
370         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
371         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
372         pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
373         pLabel->SetName(groupText);
374
375         pItem->AddControl(pLabel);
376         relativeLayout.SetMargin(*pLabel, itemRectangle.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         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
380         pItem->SetEnabled(false);
381
382         if ((__groupIndexTranslateTable[ID_GROUP_TOTAL_COUNT] == groupIndex + ID_BLUETOOTH_COUNT_DEFAULT)
383                 && (__groupItemCount[groupIndex] == 0))
384         {
385                 ToggleGroupExpanded(BLUETOOTH_GROUP_INDEX_1, __isVisibleGroupExpanded);
386         }
387
388         return pItem;
389 }
390
391 TableViewItem*
392 BluetoothForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
393 {
394         bool isCreateIcon = false;
395         bool isTwoLineItemText = false;
396         int itemHeight = H_GROUP_ITEM_DEFAULT;
397         int fontSize = GetFontSize();
398         Rectangle itemRectangle;
399         Rectangle itemRectSecondLabel;
400         Rectangle itemIconRect;
401
402         String itemText;
403         String itemTextTwoLine;
404         String itemSetname;
405
406         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
407         Bitmap* pBitmap = null;
408
409         TableViewItem* pItem = new (std::nothrow) TableViewItem();
410         if (pItem == null)
411         {
412                 return null;
413         }
414
415         switch (__groupIndexTranslateTable[groupIndex])
416         {
417         case BLUETOOTH_GROUP_ITEM_TURN_ON_OFF_STATUS:
418                 {
419                         if (itemIndex == BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_TOGGLE)
420                         {
421                                 if (__pBluetoothPresentationModelInstance == null)
422                                 {
423                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH");
424                                         style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
425                                         __pTableView->SetItemChecked(groupIndex, itemIndex, false);
426
427                                         isTwoLineItemText = true;
428                                         itemTextTwoLine = L"";
429                                         ItemTypeTwoLine(itemRectangle, itemRectSecondLabel, fontSize);
430                                         itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
431                                         break;
432                                 }
433
434                                 BluetoothPresentationModelEvent lastBluetoothEvent = __pBluetoothPresentationModelInstance->GetBluetoothEventInProgress();
435                                 if (lastBluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_ACTIVATING)
436                                 {
437                                         itemText = ResourceManager::GetString(L"IDS_BT_BODY_TURNING_ON_BLUETOOTH_ING");
438                                         style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
439                                 }
440                                 else if (lastBluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_DEACTIVATING)
441                                 {
442                                         itemText = ResourceManager::GetString(L"IDS_BT_BODY_TURNING_OFF_BLUETOOTH_ING");
443                                         style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
444                                 }
445                                 else
446                                 {
447                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH");
448                                         style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
449                                 }
450
451                                 if (__pBluetoothPresentationModelInstance->IsBluetoothActivated() == true)
452                                 {
453                                         __pTableView->SetItemChecked(groupIndex, itemIndex, true);
454                                 }
455
456                                 isTwoLineItemText = true;
457                                 itemTextTwoLine = __pBluetoothPresentationModelInstance->GetBluetoothLocalDeviceName();
458                                 ItemTypeTwoLine(itemRectangle, itemRectSecondLabel, fontSize);
459                                 itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
460                         }
461                         else
462                         {
463                                 itemText = ResourceManager::GetString(L"IDS_BT_BODY_VISIBLE");
464                                 if (__pBluetoothPresentationModelInstance == null)
465                                 {
466                                         itemTextTwoLine = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
467                                 }
468                                 else
469                                 {
470                                         itemTextTwoLine = __pBluetoothPresentationModelInstance->GetBluetoothRemainingVisibleTime();
471                                 }
472                                 itemSetname.Append(itemText);
473                                 isTwoLineItemText = true;
474                                 ItemTypeTwoLine(itemRectangle, itemRectSecondLabel, fontSize);
475                                 itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
476                         }
477                 }
478                 break;
479
480         case BLUETOOTH_GROUP_ITEM_VISIBLE:
481                 {
482                         switch (itemIndex)
483                         {
484                         case BLUETOOTH_VISIBLE_MODE_OFF:
485                                 {
486                                         if (__pBluetoothPresentationModelInstance == null)
487                                         {
488                                                 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
489                                         }
490                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
491                                 }
492                                 break;
493
494                         case BLUETOOTH_VISIBLE_MDOE_2_MINUTES:
495                                 {
496                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_2_MINUTES");
497                                 }
498                                 break;
499
500                         case BLUETOOTH_VISIBLE_MODE_5_MINUTES:
501                                 {
502                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_5_MINUTES");
503                                 }
504                                 break;
505
506                         case BLUETOOTH_VISIBLE_MODE_1_HOUR:
507                                 {
508                                         itemText = ResourceManager::GetString(L"IDS_BT_BODY_1_HOUR");
509                                 }
510                                 break;
511
512                         case BLUETOOTH_VISIBLE_MODE_ALWAYS_ON:
513                                 {
514                                         itemText = ResourceManager::GetString(L"IDS_ST_BODY_ALWAYS_ON");
515                                 }
516                                 break;
517
518                         default:
519                                 break;
520                         }
521
522                         if (__pBluetoothPresentationModelInstance != null)
523                         {
524                                 if (itemIndex == static_cast<int>(__pBluetoothPresentationModelInstance->GetBluetoothVisibleMode()))
525                                 {
526                                         __pTableView->SetItemChecked(groupIndex, itemIndex, true);
527                                 }
528                         }
529
530                         style = TABLE_VIEW_ANNEX_STYLE_RADIO;
531                         ItemTypeOneLine(itemRectangle);
532                 }
533                 break;
534
535         case BLUETOOTH_GROUP_ITEM_PAIRED_DEVICES:
536                 {
537                         itemText = __pBluetoothPresentationModelInstance->GetPairedDeviceNameAt(itemIndex);
538                         if (itemText.IsEmpty() == true)
539                         {
540                                 AppLogDebug("GetFoundDeviceListAt[%d] fail", itemIndex);
541                                 delete pItem;
542                                 return null;
543                         }
544
545                         pBitmap = GetMajorDeviceClassTypeInPairedDeviceAtBitmapN(itemIndex);
546                         if (pBitmap != null)
547                         {
548                                 isCreateIcon = true;
549                         }
550
551                         isTwoLineItemText = true;
552                         style = TABLE_VIEW_ANNEX_STYLE_DETAILED;
553                         itemTextTwoLine = ResourceManager::GetString(L"IDS_BT_BODY_PAIRED");
554
555                         ItemTypeIconAndTwoLine(itemIconRect, itemRectangle, itemRectSecondLabel, fontSize);
556                         itemHeight = (itemRectangle.height + itemRectSecondLabel.height);
557                 }
558                 break;
559
560         case BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES:
561                 {
562                         if (__pBluetoothPresentationModelInstance->GetFoundRemoteDeviceListCount() == 0)
563                         {
564                                 itemText = ResourceManager::GetString(L"IDS_BT_BODY_NO_BLUETOOTH_DEVICE_FOUND");
565                                 ItemTypeOneLine(itemRectangle);
566                                 break;
567                         }
568
569                         itemText = __pBluetoothPresentationModelInstance->GetFoundDeviceListAt(itemIndex);
570                         if (itemText.IsEmpty() == true)
571                         {
572                                 AppLogDebug("GetFoundDeviceListAt[%d] fail", itemIndex);
573                                 delete pItem;
574                                 return null;
575                         }
576
577                         pBitmap = GetMajorDeviceClassTypeInFoundDeviceAtBitmapN(itemIndex);
578                         if (pBitmap != null)
579                         {
580                                 isCreateIcon = true;
581                         }
582
583                         ItemTypeIconAndOneLine(itemIconRect, itemRectangle);
584                 }
585                 break;
586
587         default:
588                 break;
589         }
590
591         RelativeLayout relativeLayout;
592         relativeLayout.Construct();
593
594         result r = pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
595         if (IsFailed(r))
596         {
597                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
598                 delete pItem;
599                 return null;
600         }
601
602         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
603
604         if (isCreateIcon)
605         {
606                 Label* pLabel = new (std::nothrow) Label();
607                 if (pLabel == null)
608                 {
609                         AppLogDebug("pLabel is null");
610                         return pItem;
611                 }
612
613                 pLabel->Construct(itemIconRect, L"");
614                 if (IsFailed(r))
615                 {
616                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
617                         delete pLabel;
618                         return pItem;
619                 }
620
621                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
622                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
623                 pLabel->SetBackgroundBitmap(*pBitmap);
624
625                 pItem->AddControl(pLabel);
626                 relativeLayout.SetMargin(*pLabel, itemIconRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
627                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
628                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
629
630                 delete pBitmap;
631         }
632
633         Label* pLabel = new (std::nothrow) Label();
634         if (pLabel == null)
635         {
636                 AppLogDebug("pLabel is null");
637                 return pItem;
638         }
639
640         r = pLabel->Construct(itemRectangle, itemText);
641         if (IsFailed(r))
642         {
643                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
644                 delete pLabel;
645                 return pItem;
646         }
647
648         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
649         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
650         pLabel->SetTextColor(COLOR_MAIN_TEXT);
651
652         pItem->AddControl(pLabel);
653         if (style == TABLE_VIEW_ANNEX_STYLE_RADIO)
654         {
655                 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
656         }
657         else if (style == TABLE_VIEW_ANNEX_STYLE_DETAILED)
658         {
659                 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_DETAIL_BUTTON, 0, 0);
660         }
661         else
662         {
663                 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
664         }
665         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
666         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
667
668         if (isTwoLineItemText == true)
669         {
670                 Label* pSecondLabel = new (std::nothrow) Label();
671                 if (pSecondLabel == null)
672                 {
673                         AppLogDebug("pLabel is null");
674                         return pItem;
675                 }
676
677                 r = pSecondLabel->Construct(itemRectSecondLabel, itemTextTwoLine);
678                 if (IsFailed(r))
679                 {
680                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
681                         delete pSecondLabel;
682                         return pItem;
683                 }
684
685                 pSecondLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
686                 pSecondLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
687                 pSecondLabel->SetTextColor(COLOR_SUB_TEXT);
688                 pSecondLabel->SetName(itemSetname);
689
690                 pItem->AddControl(pSecondLabel);
691                 relativeLayout.SetMargin(*pSecondLabel, itemRectSecondLabel.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
692                 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
693                 relativeLayout.SetRelation(*pSecondLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
694         }
695
696         if ((__groupIndexTranslateTable[ID_GROUP_TOTAL_COUNT] == groupIndex + ID_BLUETOOTH_COUNT_DEFAULT)
697                 && (__groupItemCount[groupIndex] == itemIndex + ID_BLUETOOTH_COUNT_DEFAULT))
698         {
699                 ToggleGroupExpanded(BLUETOOTH_GROUP_INDEX_1, __isVisibleGroupExpanded);
700         }
701
702         return pItem;
703 }
704
705 bool
706 BluetoothForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
707 {
708         AppLogDebug("ENTER");
709
710         delete pItem;
711         pItem = null;
712
713         return true;
714 }
715
716 bool
717 BluetoothForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
718 {
719         AppLogDebug("ENTER");
720
721         delete pItem;
722         pItem = null;
723
724         return true;
725 }
726
727 void
728 BluetoothForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
729 {
730         SceneManager* pSceneManager = SceneManager::GetInstance();
731         AppAssert(pSceneManager);
732
733         if (__pBluetoothPresentationModelInstance != null)
734         {
735                 __pBluetoothPresentationModelInstance->CancelBluetoothDiscovery();
736         }
737
738         switch (__groupIndexTranslateTable[groupIndex])
739         {
740         case BLUETOOTH_GROUP_ITEM_TURN_ON_OFF_STATUS:
741                 {
742                         switch (itemIndex)
743                         {
744                         case BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_TOGGLE:
745                                 {
746                                         if (__pBluetoothPresentationModelInstance == null)
747                                         {
748                                                 __pTableView->SetItemChecked(groupIndex, itemIndex, false);
749                                                 // Not supported in the Emulator
750                                                 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
751                                                 break;
752                                         }
753                                         BluetoothPresentationModelEvent lastBluetoothEvent = __pBluetoothPresentationModelInstance->GetBluetoothEventInProgress();
754                                         if ((lastBluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_ACTIVATING)
755                                                 || (lastBluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_DEACTIVATING))
756                                         {
757                                                 AppLogDebug("Bluetooth is status of Activating or Deactivating");
758                                                 break;
759                                         }
760
761                                         if (tableView.IsItemChecked(groupIndex, itemIndex) == false)
762                                         {
763                                                 result r = __pBluetoothPresentationModelInstance->DeactivateBluetooth();
764                                                 if (IsFailed(r))
765                                                 {
766                                                         AppLogDebug("BluetoothDeactivate fail [%s]", GetErrorMessage(r));
767                                                         break;
768                                                 }
769                                         }
770                                         else
771                                         {
772                                                 result r = __pBluetoothPresentationModelInstance->ActivateBluetooth();
773                                                 if (IsFailed(r))
774                                                 {
775                                                         AppLogDebug("BluetoothActivate fail [%s]", GetErrorMessage(r));
776                                                         break;
777                                                 }
778                                         }
779
780                                         RefreshGroupIndexTranslateTable();
781                                         UpdateTableView();
782                                         DisableScanFooter();
783                                 }
784                                 break;
785
786                         case BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_VISIBLE_STATUS:
787                                 {
788                                         if (__pBluetoothPresentationModelInstance == null)
789                                         {
790                                                 // Not supported in the Emulator
791                                                 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
792                                                 break;
793                                         }
794                                         if (__isVisibleGroupExpanded == true)
795                                         {
796                                                 __isVisibleGroupExpanded = false;
797                                                 ToggleGroupExpanded(BLUETOOTH_GROUP_INDEX_1, __isVisibleGroupExpanded);
798                                         }
799                                         else
800                                         {
801                                                 __isVisibleGroupExpanded = true;
802                                                 ToggleGroupExpanded(BLUETOOTH_GROUP_INDEX_1, __isVisibleGroupExpanded);
803                                         }
804                                 }
805                                 break;
806
807                         default:
808                                 break;
809                         }
810                 }
811                 break;
812
813         case BLUETOOTH_GROUP_ITEM_VISIBLE:
814                 {
815                         if (__pBluetoothPresentationModelInstance == null)
816                         {
817                                 __pTableView->SetItemChecked(groupIndex, itemIndex, false);
818                                 __pTableView->SetItemChecked(ID_BLUETOOTH_COUNT_DEFAULT, 0, true);
819                                 // Not supported in the Emulator
820                                 ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
821                                 break;
822                         }
823                         result r = __pBluetoothPresentationModelInstance->SetBluetoothVisibleMode(static_cast<BluetoothVisibleMode>(itemIndex));
824                         if (!IsFailed(r))
825                         {
826                                 SingleSelectAnnexStyleRadio(groupIndex, itemIndex);
827                                 SetStateChangedTableviewItemTag(groupIndex, itemIndex);
828                         }
829                 }
830                 break;
831
832         case BLUETOOTH_GROUP_ITEM_PAIRED_DEVICES:
833                 {
834                 //      if (status == TABLE_VIEW_ITEM_STATUS_MORE)
835                         {
836                                 ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
837                                 if (pArgs == null)
838                                 {
839                                         AppLogDebug("pArgs is null");
840                                         break;
841                                 }
842
843                                 result r = pArgs->Construct();
844                                 if (IsFailed(r))
845                                 {
846                                         delete pArgs;
847                                         pArgs = null;
848                                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
849                                         break;
850                                 }
851
852                                 pArgs->Add(*(new (std::nothrow) String(Integer::ToString(itemIndex))));
853                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_BLUETOOTH_DETAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
854                         }
855                 }
856                 break;
857
858         case BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES:
859                 {
860                         if (__pBluetoothPresentationModelInstance != null)
861                         {
862                                 if (__pBluetoothPresentationModelInstance->GetBluetoothEventInProgress() == BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIRING)
863                                 {
864                                         result r = __pBluetoothPresentationModelInstance->CancelBluetoothPair();
865                                         if (IsFailed(r))
866                                         {
867                                                 AppLogDebug("BluetoothCancelPair fail [%s]", GetErrorMessage(r));
868                                                 break;
869                                         }
870
871                                         ModifyTableViewItem(groupIndex, itemIndex);
872                                         break;
873                                 }
874                                 result r = __pBluetoothPresentationModelInstance->PairToFoundBluetoothDeviceAt(itemIndex);
875                                 if (IsFailed(r))
876                                 {
877                                         AppLogDebug("BluetoothPairToFoundDeviceList fail [%s]", GetErrorMessage(r));
878                                         break;
879                                 }
880
881                                 SetStateChangedTableviewItemTag(groupIndex, itemIndex);
882                                 ModifyTableViewItem(groupIndex, itemIndex);
883                         }
884                         else
885                         {
886                                 AppLogDebug("__pBluetoothPresentationModelInstance is null.");
887                         }
888                 }
889                 break;
890
891         default:
892                 break;
893         }
894 }
895
896 void
897 BluetoothForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
898 {
899         if (__pBluetoothPresentationModelInstance == null)
900         {
901                 AppLogDebug("__pBluetoothPresentationModelInstance is null");
902                 return;
903         }
904
905         switch (actionId)
906         {
907         case IDA_BLUETOOTH_FOOTER_SCAN:
908                 {
909                         result r = __pBluetoothPresentationModelInstance->StartBluetoothDiscovery();
910                         if (IsFailed(r))
911                         {
912                                 AppLogDebug("BluetoothStartDiscovery fail [%s]", GetErrorMessage(r));
913                                 return;
914                         }
915
916                         DisableScanFooter();
917                 }
918                 break;
919
920         case IDA_BLUETOOTH_FOOTER_CANCEL:
921                 {
922                         result r = __pBluetoothPresentationModelInstance->CancelBluetoothDiscovery();
923                         if (IsFailed(r))
924                         {
925                                 AppLogDebug("BluetoothStartDiscovery fail [%s]", GetErrorMessage(r));
926                                 return;
927                         }
928
929                         DisableScanFooter();
930                 }
931                 break;
932
933         default:
934                 break;
935         }
936 }
937
938 void
939 BluetoothForm::DisableScanFooter(void)
940 {
941         Footer* pFooter = GetFooter();
942         AppAssert(pFooter);
943
944         pFooter->SetItemEnabled(0, false);
945         pFooter->Invalidate(false);
946 }
947
948 void
949 BluetoothForm::EnableScanFooter(void)
950 {
951         Footer* pFooter = GetFooter();
952         AppAssert(pFooter);
953
954         pFooter->SetItemEnabled(0, true);
955         pFooter->Invalidate(true);
956 }
957
958 void
959 BluetoothForm::SetFooterText(const int actionId, Tizen::Base::String itemText)
960 {
961         Footer* pFooter = GetFooter();
962         AppAssert(pFooter);
963
964         FooterItem footerItem;
965         footerItem.Construct(actionId);
966         footerItem.SetText(itemText);
967
968         pFooter->RemoveItemAt(0);
969         pFooter->InsertItemAt(0, footerItem);
970 }
971
972 void
973 BluetoothForm::ShowMessageBox(const Tizen::Base::String& title, const Tizen::Base::String& text)
974 {
975         MessageBox messageBox;
976         int result = E_SUCCESS;
977
978         messageBox.Construct(title, text, MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_2_SEC);
979         messageBox.ShowAndWait(result);
980 }
981
982 result
983 BluetoothForm::BluetoothPresentationModelInit(void)
984 {
985         __pBluetoothPresentationModelInstance = BluetoothPresentationModel::GetInstance();
986         if (__pBluetoothPresentationModelInstance == null)
987         {
988                 AppLogDebug("__pBluetoothPresentationModelInstance is null");
989                 return E_FAILURE;
990         }
991
992         __pBluetoothPresentationModelInstance->SetEventListener(this);
993         return E_SUCCESS;
994 }
995
996 Tizen::Graphics::Bitmap*
997 BluetoothForm::GetMajorDeviceClassTypeInPairedDeviceAtBitmapN(int pairedDeviceListIndex, bool isConnected)
998 {
999         if (__pBluetoothPresentationModelInstance == null)
1000         {
1001                 AppLogDebug("__pBluetoothPresentationModelInstance is null");
1002                 return null;
1003         }
1004
1005         Bitmap* pBitmap = null;
1006         BluetoothMajorDeviceClassType majorType = __pBluetoothPresentationModelInstance->GetMajorDeviceClassTypeInPairedDeviceAt(pairedDeviceListIndex);
1007
1008         if (IsFailed(GetLastResult()))
1009         {
1010                 AppLogDebug("GetMajorDeviceClassTypeInPairedDeviceListAt fail [%s]", GetErrorMessage(GetLastResult()));
1011                 return null;
1012         }
1013
1014         switch (majorType)
1015         {
1016         case BT_COD_MAJ_DEV_CLS_COMPUTER:
1017                 {
1018                         if (isConnected == true)
1019                         {
1020                                 pBitmap = ResourceManager::GetBitmapN(IDB_BT_DEVICE_COMPUTER_CONNECT);
1021                         }
1022                         else
1023                         {
1024                                 pBitmap = ResourceManager::GetBitmapN(IDB_BT_DEVICE_COMPUTER);
1025                         }
1026                 }
1027                 break;
1028
1029         case BT_COD_MAJ_DEV_CLS_PHONE:
1030                 {
1031                         if (isConnected == true)
1032                         {
1033                                 pBitmap = ResourceManager::GetBitmapN(IDB_BT_DEVICE_MOBILE_CONNECT);
1034                         }
1035                         else
1036                         {
1037                                 pBitmap = ResourceManager::GetBitmapN(IDB_BT_DEVICE_MOBILE);
1038                         }
1039                 }
1040                 break;
1041
1042         case BT_COD_MAJ_DEV_CLS_MISC:
1043                 // fall through
1044         case BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT:
1045                 // fall through
1046         case BT_COD_MAJ_DEV_CLS_AUDIO:
1047                 // fall through
1048         case BT_COD_MAJ_DEV_CLS_PERIPHERAL:
1049                 // fall through
1050         case BT_COD_MAJ_DEV_CLS_IMAGING:
1051                 // fall through
1052         case BT_COD_MAJ_DEV_CLS_UNCLASSIFIED:
1053                 {
1054                         if (isConnected == true)
1055                         {
1056                                 pBitmap = ResourceManager::GetBitmapN(IDB_BT_BUTTON_UNKNOWN_CONNECT);
1057                         }
1058                         else
1059                         {
1060                                 pBitmap = ResourceManager::GetBitmapN(IDB_BT_BUTTON_UNKNOWN);
1061                         }
1062                 }
1063                 break;
1064
1065         default:
1066                 break;
1067         }
1068
1069         return pBitmap;
1070 }
1071
1072 Tizen::Graphics::Bitmap*
1073 BluetoothForm::GetMajorDeviceClassTypeInFoundDeviceAtBitmapN(int foundDeviceListIndex)
1074 {
1075         if (__pBluetoothPresentationModelInstance == null)
1076         {
1077                 AppLogDebug("__pBluetoothPresentationModelInstance is null");
1078                 return null;
1079         }
1080
1081         Bitmap* pBitmap = null;
1082         BluetoothMajorDeviceClassType majorType = __pBluetoothPresentationModelInstance->GetMajorDeviceClasstypeInFoundDeviceAt(foundDeviceListIndex);
1083
1084         if (IsFailed(GetLastResult()))
1085         {
1086                 AppLogDebug("GetMajorDeviceClasstypeInFoundDeviceListAt fail [%s]", GetErrorMessage(GetLastResult()));
1087                 return null;
1088         }
1089
1090         switch (majorType)
1091         {
1092         case BT_COD_MAJ_DEV_CLS_COMPUTER:
1093                 {
1094                         pBitmap = ResourceManager::GetBitmapN(IDB_BT_DEVICE_COMPUTER);
1095                 }
1096                 break;
1097
1098         case BT_COD_MAJ_DEV_CLS_PHONE:
1099                 {
1100                         pBitmap = ResourceManager::GetBitmapN(IDB_BT_DEVICE_MOBILE);
1101                 }
1102                 break;
1103
1104         case BT_COD_MAJ_DEV_CLS_MISC:
1105                 // fall through
1106         case BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT:
1107                 // fall through
1108         case BT_COD_MAJ_DEV_CLS_AUDIO:
1109                 // fall through
1110         case BT_COD_MAJ_DEV_CLS_PERIPHERAL:
1111                 // fall through
1112         case BT_COD_MAJ_DEV_CLS_IMAGING:
1113                 // fall through
1114         case BT_COD_MAJ_DEV_CLS_UNCLASSIFIED:
1115                 {
1116                         pBitmap = ResourceManager::GetBitmapN(IDB_BT_BUTTON_UNKNOWN);
1117                 }
1118                 break;
1119
1120         default:
1121                 break;
1122         }
1123
1124         return pBitmap;
1125 }
1126
1127 void
1128 BluetoothForm::SetUserPendingEventReceivedForm(Tizen::Ui::Controls::Form* pEventReveivedForm)
1129 {
1130         __pPendingEventReceivedForm = pEventReveivedForm;
1131 }
1132
1133 void
1134 BluetoothForm::SendToUserPendingEvent(RequestId requestId)
1135 {
1136         if (__pPendingEventReceivedForm)
1137         {
1138                 __pPendingEventReceivedForm->SendUserEvent(requestId, null);
1139         }
1140 }
1141
1142 void
1143 BluetoothForm::CreateSearchAnimationFrame(void)
1144 {
1145         int count = 0;
1146         long duration = ID_IN_PROGRESS_DURATION / ID_IN_PROGRESS_FRAME_COUNT;
1147
1148         Bitmap* pBitmap = null;
1149         AnimationFrame* pAniFrame = null;
1150
1151         __pAnimationFrameList = new (std::nothrow) ArrayList();
1152         __pAnimationFrameList->Construct();
1153
1154         for (count = ID_BLUETOOTH_COUNT_DEFAULT; count <= ID_IN_PROGRESS_FRAME_COUNT; count++)
1155         {
1156                 String searchIconFilePath;
1157                 searchIconFilePath.Format(SEARCH_ICON_FILE_PATH_NAME_LENGTH_MAX, IDB_SEARCH_ICON_SIZE_LAGER_IMAGE_PATH_FORMAT, count);
1158                 AppLogDebug("%ls", searchIconFilePath.GetPointer());
1159                 pBitmap = ResourceManager::GetBitmapN(searchIconFilePath);
1160                 if (pBitmap == null)
1161                 {
1162                         AppLogDebug("GetBitmapN fail");
1163                         continue;
1164                 }
1165                 pAniFrame = new (std::nothrow) AnimationFrame(*pBitmap, duration);
1166                 __pAnimationFrameList->Add(*pAniFrame);
1167                 delete pBitmap;
1168         }
1169 }
1170
1171 void
1172 BluetoothForm::DestorySearchAnimationFrame(void)
1173 {
1174         if (__pAnimationFrameList != null)
1175         {
1176                 __pAnimationFrameList->RemoveAll();
1177                 delete __pAnimationFrameList;
1178                 __pAnimationFrameList = null;
1179         }
1180 }
1181
1182 void
1183 BluetoothForm::AddTableViewItemInSpecificGroupItem(int groupItem)
1184 {
1185         if (__pTableView == null)
1186         {
1187                 AppLogDebug("__pTableView is null");
1188                 return;
1189         }
1190
1191         bool isFoundGroupItem = false;
1192         int groupIndex = 0;
1193         for (groupIndex = 0; groupIndex < ID_GROUP_TOTAL_COUNT; groupIndex++)
1194         {
1195                 if (__groupIndexTranslateTable[groupIndex] == groupItem)
1196                 {
1197                         isFoundGroupItem = true;
1198                         break;
1199                 }
1200         }
1201
1202         if (isFoundGroupItem == false)
1203         {
1204                 AppLogDebug("gorup item is not found");
1205                 return;
1206         }
1207
1208         __pTableView->RefreshItem(groupIndex, __pTableView->GetItemCountAt(groupIndex), TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
1209 }
1210
1211 void
1212 BluetoothForm::ModifyTableViewItem(int groupIndex, int itemIndex)
1213 {
1214         if (__pTableView == null)
1215         {
1216                 AppLogDebug("__pTableView is null");
1217                 return;
1218         }
1219
1220         __pTableView->RefreshItem(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1221 }
1222
1223 void
1224 BluetoothForm::ModifyTableViewSpecificGroupItem(int groupItem)
1225 {
1226         if (__pTableView == null)
1227         {
1228                 AppLogDebug("__pTableView is null");
1229                 return;
1230         }
1231
1232         bool isFoundGroupItem = false;
1233         int groupIndex = 0;
1234         for (groupIndex = 0; groupIndex < ID_GROUP_TOTAL_COUNT; groupIndex++)
1235         {
1236                 if (__groupIndexTranslateTable[groupIndex] == groupItem)
1237                 {
1238                         isFoundGroupItem = true;
1239                         break;
1240                 }
1241         }
1242
1243         if (isFoundGroupItem == false)
1244         {
1245                 AppLogDebug("gorup item is not found");
1246                 return;
1247         }
1248
1249         __pTableView->RefreshItem(groupIndex, ID_BLUETOOTH_TABLEVIEW_ITEM_SPECIFIED_INPUT_PARMETER, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1250 }
1251
1252 void
1253 BluetoothForm::RefreshGroupIndexTranslateTable(void)
1254 {
1255         if (__pTableView == null)
1256         {
1257                 AppLogDebug("__pBluetoothMgr or __pTableView is null");
1258                 return;
1259         }
1260
1261         int itemCount = 0;
1262         int groupIndex = 0;
1263
1264         __groupItemCount[groupIndex] = BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_MAX;
1265         __groupIndexTranslateTable[groupIndex] = BLUETOOTH_GROUP_ITEM_TURN_ON_OFF_STATUS;
1266         groupIndex = groupIndex + ID_BLUETOOTH_COUNT_DEFAULT;
1267
1268         __groupItemCount[groupIndex] = ID_BLUETOOTH_VISIBLE_GROUP_ITEM_CONUNT;
1269         __groupIndexTranslateTable[groupIndex] = BLUETOOTH_GROUP_ITEM_VISIBLE;
1270         groupIndex = groupIndex + ID_BLUETOOTH_COUNT_DEFAULT;
1271
1272         if (__pBluetoothPresentationModelInstance == null)
1273         {
1274                 __groupIndexTranslateTable[ID_GROUP_TOTAL_COUNT] = groupIndex;
1275                 return;
1276         }
1277
1278         itemCount = __pBluetoothPresentationModelInstance->GetPairedDeviceListCount();
1279         if (itemCount != 0)
1280         {
1281                 __groupItemCount[groupIndex] = itemCount;
1282                 __groupIndexTranslateTable[groupIndex] = BLUETOOTH_GROUP_ITEM_PAIRED_DEVICES;
1283                 groupIndex = groupIndex + ID_BLUETOOTH_COUNT_DEFAULT;
1284         }
1285
1286         itemCount = __pBluetoothPresentationModelInstance->GetFoundRemoteDeviceListCount();
1287         BluetoothPresentationModelEvent lastbluetoothEvent = __pBluetoothPresentationModelInstance->GetBluetoothEventInProgress();
1288
1289         if ((itemCount != 0)
1290                 || (lastbluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_STARTED)
1291                 || (lastbluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_CANCELED)
1292                 || (lastbluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_DONE))
1293         {
1294                 __groupIndexTranslateTable[groupIndex] = BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES;
1295                 if (itemCount != 0)
1296                 {
1297                         __groupItemCount[groupIndex] = itemCount;
1298                 }
1299                 else if (lastbluetoothEvent == BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_DONE)
1300                 {
1301                         __groupItemCount[groupIndex] = ID_BLUETOOTH_COUNT_DEFAULT;
1302                 }
1303                 else
1304                 {
1305                         __groupItemCount[groupIndex] = 0;
1306                 }
1307                 groupIndex = groupIndex + ID_BLUETOOTH_COUNT_DEFAULT;
1308         }
1309
1310         __groupIndexTranslateTable[ID_GROUP_TOTAL_COUNT] = groupIndex;
1311 }
1312
1313 void
1314 BluetoothForm::ToggleGroupExpanded(int groupIndex, bool isExpand)
1315 {
1316         if (__pTableView == null)
1317         {
1318                 AppLogDebug("__pTableView is null");
1319                 return;
1320         }
1321
1322         if (isExpand == true)
1323         {
1324                 if (__pTableView->IsGroupExpanded(groupIndex) == false)
1325                 {
1326                         __pTableView->ExpandGroup(groupIndex);
1327                 }
1328         }
1329         else
1330         {
1331                 if (__pTableView->IsGroupExpanded(groupIndex) == true)
1332                 {
1333                         __pTableView->CollapseGroup(groupIndex);
1334                 }
1335         }
1336 }
1337
1338 void
1339 BluetoothForm::SingleSelectAnnexStyleRadio(int groupIndex, int itemIndex)
1340 {
1341         if (__pTableView == null)
1342         {
1343                 AppLogDebug("__pTableView is null");
1344                 return;
1345         }
1346
1347         int itemCount = __pTableView->GetItemCountAt(groupIndex);
1348         for (int i = 0; i < itemCount; i++)
1349         {
1350                 if (i != itemIndex)
1351                 {
1352                         __pTableView->SetItemChecked(groupIndex, i, false);
1353                 }
1354                 else
1355                 {
1356                         __pTableView->SetItemChecked(groupIndex, i, true);
1357                 }
1358         }
1359         __pTableView->RequestRedraw(true);
1360 }
1361
1362 void
1363 BluetoothForm::InitStateChangedTabviewItemTag(void)
1364 {
1365         __stateChangedTableViewItemTag.groupIndex = ID_BLUETOOTH_TABLEVIEW_ITEM_SPECIFIED_INPUT_PARMETER;
1366         __stateChangedTableViewItemTag.itemIndex = ID_BLUETOOTH_TABLEVIEW_ITEM_SPECIFIED_INPUT_PARMETER;
1367 }
1368
1369 void
1370 BluetoothForm::SetStateChangedTableviewItemTag(int groupIndex, int itemIndex)
1371 {
1372         __stateChangedTableViewItemTag.groupIndex = groupIndex;
1373         __stateChangedTableViewItemTag.itemIndex = itemIndex;
1374 }
1375
1376 void
1377 BluetoothForm::UpdateTableView(void)
1378 {
1379         if (__pTableView == null)
1380         {
1381                 AppLogDebug("__pTableView is null");
1382                 return;
1383         }
1384         __pTableView->UpdateTableView();
1385 }
1386
1387 #if 0
1388 Tizen::Base::Collection::IList*
1389 BluetoothForm::ResultBluetoothDeviceFromAppControlRequestN(void)
1390 {
1391         BluetoothForm* pBluetoothForm = null;
1392         ArrayList* pDataList = null;
1393         BluetoothDevice* pDevice = null;
1394
1395         pDataList = new (std::nothrow) ArrayList();
1396
1397         if (__pStaticBluetoothMgr != null)
1398         {
1399                 delete __pStaticBluetoothMgr;
1400                 __pStaticBluetoothMgr = null;
1401         }
1402
1403         __pStaticBluetoothMgr = new (std::nothrow) BluetoothManager();
1404
1405         pBluetoothForm = new (std::nothrow) BluetoothForm();
1406
1407         __pStaticBluetoothMgr->Construct(*pBluetoothForm);
1408
1409         pDevice = const_cast<BluetoothDevice*>(__pStaticBluetoothMgr->GetLocalDevice());
1410
1411         pDataList->Add(*(new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED)));
1412         pDataList->Add(*(new (std::nothrow) String(__pStaticBluetoothMgr->GetLocalDeviceName())));
1413         pDataList->Add(*(new (std::nothrow) String(__pStaticBluetoothMgr->GetLocalDeviceAddress())));
1414         pDataList->Add(*(new (std::nothrow) String(Integer::ToString(pDevice->GetMajorDeviceClassType()))));
1415         pDataList->Add(*(new (std::nothrow) String(Integer::ToString(pDevice->GetMinorDeviceClassType()))));
1416         pDataList->Add(*(new (std::nothrow) String(Integer::ToString(pDevice->GetServiceClassList()))));
1417         pDataList->Add(*(new (std::nothrow) String(Integer::ToString(pDevice->GetServiceList()))));
1418
1419         pDevice = null;
1420
1421         delete __pStaticBluetoothMgr;
1422         __pStaticBluetoothMgr = null;
1423         delete pBluetoothForm;
1424         pBluetoothForm = null;
1425
1426         return pDataList;
1427 }
1428 #endif
1429
1430 int
1431 BluetoothForm::GetDefaultGroupItemHeight(void)
1432 {
1433         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
1434 }
1435
1436 int
1437 BluetoothForm::GetDefaultItemHeight(void)
1438 {
1439         return H_GROUP_ITEM_DEFAULT;
1440 }
1441
1442 void
1443 BluetoothForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
1444 {
1445         if (__pBluetoothPresentationModelInstance == null)
1446         {
1447                 AppLogDebug("__pBluetoothPresentationModelInstance is null");
1448                 return;
1449         }
1450
1451         switch (__groupIndexTranslateTable[groupIndex])
1452         {
1453         case BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES:
1454                 {
1455                         Label* pLabel = static_cast<Label*>(pItem->GetControl(ResourceManager::GetString(L"IDS_ST_HEADER_AVAILABLE_DEVICES")));
1456                         if (pLabel == null)
1457                         {
1458                                 AppLogDebug("pLabel is null");
1459                                 return;
1460                         }
1461
1462                         if (__pBluetoothPresentationModelInstance->GetFoundRemoteDeviceListCount() == 0)
1463                         {
1464                                 pLabel->SetText(ResourceManager::GetString(L"IDS_BT_BODY_BLUETOOTH_DEVICES"));
1465                         }
1466                         else
1467                         {
1468                                 pLabel->SetText(ResourceManager::GetString(L"IDS_ST_HEADER_AVAILABLE_DEVICES"));
1469                         }
1470                         pLabel->Invalidate(false);
1471                 }
1472                 break;
1473
1474         case BLUETOOTH_GROUP_ITEM_PAIRED_DEVICES:
1475                 {
1476                         // to do
1477                 }
1478                 break;
1479
1480         default:
1481                 break;
1482         }
1483
1484         return;
1485 }
1486
1487 void
1488 BluetoothForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
1489 {
1490         if ((pItem == null)
1491                 || (__pBluetoothPresentationModelInstance == null))
1492         {
1493                 AppLogDebug("pItem or __pBluetoothPresentationModelInstance is null");
1494                 return;
1495         }
1496
1497         switch (__groupIndexTranslateTable[groupIndex])
1498         {
1499         case BLUETOOTH_GROUP_ITEM_TURN_ON_OFF_STATUS:
1500                 {
1501                         if (itemIndex != BLUETOOTH_TURN_ON_OFF_STATUS_ITEM_VISIBLE_STATUS)
1502                         {
1503                                 break;
1504                         }
1505
1506                         Label* pLabel = static_cast<Label*>(pItem->GetControl(ResourceManager::GetString(L"IDS_BT_BODY_VISIBLE")));
1507                         if (pLabel == null)
1508                         {
1509                                 AppLogDebug("pLabel is null");
1510                                 return;
1511                         }
1512
1513                         pLabel->SetText( __pBluetoothPresentationModelInstance->GetBluetoothRemainingVisibleTime());
1514                         pLabel->Invalidate(false);
1515                 }
1516                 break;
1517
1518         case BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES:
1519                 {
1520                         if (__pBluetoothPresentationModelInstance->GetBluetoothEventInProgress() == BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIRING)
1521                         {
1522                                 Rectangle itemAnimationRect(X_IN_PROGRESS_ANIMATION, Y_IN_PROGRESS_ANIMATION, W_IN_PROGRESS_ANIMATION, H_IN_PROGRESS_ANIMATION);
1523
1524                                 Animation* pAnimation = new (std::nothrow) Animation();
1525                                 result r = pAnimation->Construct(itemAnimationRect, *__pAnimationFrameList);
1526                                 if (IsFailed(r))
1527                                 {
1528                                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
1529                                         delete pAnimation;
1530                                         return;
1531                                 }
1532
1533                                 pAnimation->SetRepeatCount(ID_IN_PROGRESS__REPEAT_COUNT);
1534                                 pAnimation->SetName(L"SearchAnimation");
1535                                 pAnimation->SetShowState(true);
1536                                 pItem->AddControl(pAnimation);
1537                                 pAnimation->Play();
1538                         }
1539                         else
1540                         {
1541                                 Animation* pAnimation = static_cast<Animation*>(pItem->GetControl(L"SearchAnimation"));
1542                                 if (pAnimation == null)
1543                                 {
1544                                         AppLogDebug("pAnimation is null");
1545                                         return;
1546                                 }
1547                                 pItem->RemoveControl(pAnimation);
1548                         }
1549                 }
1550                 break;
1551
1552         case BLUETOOTH_GROUP_ITEM_PAIRED_DEVICES:
1553                 {
1554                         // to do
1555                 }
1556                 break;
1557
1558         default:
1559                 break;
1560         }
1561
1562         return;
1563 }
1564
1565 void
1566 BluetoothForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
1567 {
1568 }
1569
1570 void
1571 BluetoothForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1572 {
1573 }
1574
1575 void
1576 BluetoothForm::AppControlBluetoothResult(void)
1577 {
1578         String value;
1579         RequestId reqId = 0;
1580         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
1581
1582         HashMap* hashMap = new (std::nothrow) HashMap();
1583         hashMap->Construct();
1584
1585         if (__isAppControlRequest & APPCONTROL_REQUEST_BLUETOOTH)
1586         {
1587                 hashMap->Add(*(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/visibility")), *(new (std::nothrow) String(L"Off")));
1588         }
1589         pAppManager->SendAppControlResult(reqId, APP_CTRL_RESULT_SUCCEEDED, hashMap);
1590
1591         hashMap->RemoveAll();
1592         delete hashMap;
1593 }
1594
1595 void
1596 BluetoothForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
1597 {
1598 }
1599
1600 void
1601 BluetoothForm::OnBluetoothPresentationModelEventCompletedN(BluetoothPresentationModelEvent bluetoothEvent, result r, Tizen::Net::Bluetooth::BluetoothDevice* pDevice)
1602 {
1603         if (__pBluetoothPresentationModelInstance == null)
1604         {
1605                 AppLogDebug("__pBluetoothPresentationModelInstance is null");
1606                 return;
1607         }
1608
1609         switch (bluetoothEvent)
1610         {
1611         case BLUETOOTH_PRESENTATION_MODEL_EVENT_ACTIVATED:
1612                 {
1613                         if (IsFailed(r))
1614                         {
1615                                 AppLogDebug("result fail [%s]", GetErrorMessage(r));
1616                                 return;
1617                         }
1618
1619                         result r = __pBluetoothPresentationModelInstance->StartBluetoothDiscovery();
1620                         if (IsFailed(r))
1621                         {
1622                                 AppLogDebug("BluetoothStartDiscovery fail [%s]", GetErrorMessage(r));
1623                                 EnableScanFooter();
1624                                 return;
1625                         }
1626
1627                         DisableScanFooter();
1628                 }
1629                 break;
1630
1631         case BLUETOOTH_PRESENTATION_MODEL_EVENT_DEACTIVATED:
1632                 {
1633                         if (IsFailed(r))
1634                         {
1635                                 AppLogDebug("result fail [%s]", GetErrorMessage(r));
1636                                 EnableScanFooter();
1637                                 return;
1638                         }
1639
1640                         SetFooterText(IDA_BLUETOOTH_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
1641                         DisableScanFooter();
1642
1643                         RefreshGroupIndexTranslateTable();
1644                         UpdateTableView();
1645                 }
1646                 break;
1647
1648         case BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_DONE:
1649                 // fall through
1650         case BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_CANCELED:
1651                 {
1652                         SetFooterText(IDA_BLUETOOTH_FOOTER_SCAN, ResourceManager::GetString(L"IDS_ST_BODY_SCAN"));
1653                         EnableScanFooter();
1654
1655                         RefreshGroupIndexTranslateTable();
1656                         int itemCount = __pBluetoothPresentationModelInstance->GetFoundRemoteDeviceListCount();
1657                         if (itemCount == 0)
1658                         {
1659                                 ModifyTableViewSpecificGroupItem(BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES);
1660                                 AddTableViewItemInSpecificGroupItem(BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES);
1661                         }
1662                 }
1663                 break;
1664
1665         case BLUETOOTH_PRESENTATION_MODEL_EVENT_DISCOVERY_STARTED:
1666                 {
1667                         if (IsFailed(r))
1668                         {
1669                                 AppLogDebug("result fail [%s]", GetErrorMessage(r));
1670                                 EnableScanFooter();
1671                                 return;
1672                         }
1673
1674                         SetFooterText(IDA_BLUETOOTH_FOOTER_CANCEL, ResourceManager::GetString(L"IDS_COM_BODY_STOP"));
1675                         EnableScanFooter();
1676
1677                         RefreshGroupIndexTranslateTable();
1678                         UpdateTableView();
1679                 }
1680                 break;
1681
1682         case BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIRED:
1683                 {
1684                         RefreshGroupIndexTranslateTable();
1685                         UpdateTableView();
1686                 }
1687                 break;
1688
1689         case BLUETOOTH_PRESENTATION_MODEL_EVENT_PAIRING_FAILED:
1690                 {
1691                         ModifyTableViewItem(__stateChangedTableViewItemTag.groupIndex, __stateChangedTableViewItemTag.itemIndex);
1692                         InitStateChangedTabviewItemTag();
1693                 }
1694                 break;
1695
1696         case BLUETOOTH_PRESENTATION_MODEL_EVENT_REMOTE_DEVICE_FOUND:
1697                 {
1698                         if (IsFailed(r))
1699                         {
1700                                 AppLogDebug("BLUETOOTH_PRESENTATION_MODEL_EVENT_REMOTE_DEVICE_FOUND fail [%s]", GetErrorMessage(r));
1701                                 break;
1702                         }
1703                         AddTableViewItemInSpecificGroupItem(BLUETOOTH_GROUP_ITEM_AVAILABLE_DEVICES);
1704                 }
1705                 break;
1706
1707         case BLUETOOTH_PRESENTATION_MODEL_EVENT_VISIBLE_MODE_CHANGED:
1708                 {
1709                         ModifyTableViewItem(__stateChangedTableViewItemTag.groupIndex, __stateChangedTableViewItemTag.itemIndex);
1710                         InitStateChangedTabviewItemTag();
1711                 }
1712                 break;
1713
1714         case BLUETOOTH_PRESENTATION_MODEL_EVENT_UNPAIRED:
1715                 {
1716                         RefreshGroupIndexTranslateTable();
1717                         UpdateTableView();
1718                 }
1719                 break;
1720
1721         default:
1722                 break;
1723         }
1724 }