Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StMoreConnectivityForm.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                StMoreConnectivityForm.cpp
19  * @brief               This is the implementation file for MoreConnectivityForm class.
20  */
21
22 #include "StBluetoothForm.h"
23 #include "StMoreConnectivityForm.h"
24 #include "StNfcPresentationModel.h"
25 #include "StResourceManager.h"
26 #include "StSettingScenesList.h"
27 #include "StTypes.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37 static const int ID_GROUP_CONNECTIVITY_ITEM_COUNT = 2;
38 static const int ID_ITEM_CONNECTIVITY_BLUETOOTH = 0;
39 static const int ID_ITEM_CONNECTIVITY_NFC = 1;
40 static const int ID_ITEM_CONNECTIVITY_WIFI_DIRECT = 2;
41
42 static const int ID_GROUP_COUNT = 1;
43 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_CONNECTIVITY_ITEM_COUNT;
44
45 static const int BLUETOOTH_OFF_OPTION = 0;
46
47 MoreConnectivityForm::MoreConnectivityForm(void)
48 {
49 }
50
51 MoreConnectivityForm::~MoreConnectivityForm(void)
52 {
53 }
54
55 void
56 MoreConnectivityForm::CreateFooter(void)
57 {
58         Footer* pFooter = GetFooter();
59         AppAssert(pFooter);
60
61         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
62         pFooter->SetBackButton();
63         pFooter->AddActionEventListener(*this);
64
65         SetFormBackEventListener(this);
66 }
67
68 result
69 MoreConnectivityForm::OnInitializing(void)
70 {
71         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MORE_CONNECTIVITY_SETTINGS"));
72         CreateFooter();
73         CreateTableView();
74
75         AppLogDebug("ENTER");
76         return E_SUCCESS;
77 }
78
79 result
80 MoreConnectivityForm::OnTerminating(void)
81 {
82         __pTableView = null;
83
84         SetFormBackEventListener(null);
85         return E_SUCCESS;
86 }
87
88 void
89 MoreConnectivityForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
90 {
91         if (__pTableView == null)
92         {
93                 AppLogDebug("__pTableView is null");
94                 return;
95         }
96
97         __pTableView->UpdateTableView();
98
99         bool EnableStatus = false;
100         if (SystemInfo::GetValue(SYSTEM_INFO_KEY_NFC, EnableStatus) == E_SUCCESS)
101         {
102                 AppLogDebug("systeminfo::GetValue() success(%s)", GetErrorMessage(GetLastResult()));
103
104                 if (EnableStatus == true)
105                 {
106                         __pTableView->SetItemChecked(0, 1, NfcPresentationModel::GetInstance()->IsNfcActivated());
107                 }
108                 else
109                 {
110                         __pTableView->SetItemChecked(0, 1, false);
111                 }
112         }
113         else
114         {
115                 __pTableView->SetItemChecked(0, 1, false);
116         }
117 }
118
119 void
120 MoreConnectivityForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
121 {
122 }
123
124 void
125 MoreConnectivityForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
126 {
127         SceneManager* pSceneManager = SceneManager::GetInstance();
128         AppAssert(pSceneManager);
129
130         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
131 }
132
133 int
134 MoreConnectivityForm::GetGroupCount(void)
135 {
136         AppLogDebug("ENTER");
137         return ID_GROUP_COUNT;
138 }
139
140 int
141 MoreConnectivityForm::GetItemCount(int groupIndex)
142 {
143         int itemCount = ID_GROUP_MAX_ITEM_COUNT;
144
145         AppLogDebug("GetItemCount %d", itemCount);
146
147         return itemCount;
148 }
149
150 TableViewGroupItem*
151 MoreConnectivityForm::CreateGroupItem(int groupIndex, int itemWidth)
152 {
153         AppLogDebug("ENTER");
154
155         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
156         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
157         Rectangle itemRectangle;
158         String groupText;
159         Label* pLabel = null;
160
161         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
162
163         itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
164         itemRectangle.y = Y_GROUP_ITEM_DEFAULT_LABEL;
165         itemRectangle.width = itemWidth;
166         itemRectangle.height = itemHeight;
167
168         RelativeLayout relativeLayout;
169         relativeLayout.Construct();
170
171         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
172         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
173
174         pLabel = new (std::nothrow) Label();
175         pLabel->Construct(itemRectangle, groupText);
176         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
177         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
178         pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
179
180         pItem->AddControl(pLabel);
181         relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
182         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
183         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
184         pItem->SetEnabled(false);
185
186         return pItem;
187 }
188
189 TableViewItem*
190 MoreConnectivityForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
191 {
192         AppLogDebug("ENTER");
193
194         bool checkSecondText = false;
195         int itmeHeight = H_GROUP_ITEM_DEFAULT_LABEL;
196         int btEnableStatus = BLUETOOTH_OFF_OPTION;
197         Rectangle itemLabelRect;
198         Rectangle itemIconRect;
199         Rectangle itemIconLabelRect;
200         Rectangle itemSecondLineTextRect;
201         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
202         Bitmap* pBitmap = null;
203         String itemText;
204         String secondLineText;
205         bool EnableStatus = false;
206         Label* pLabel = null;
207         int fontSize = GetFontSize();
208
209         TableViewItem* pItem = new (std::nothrow) TableViewItem();
210
211         if (itemIndex == ID_ITEM_CONNECTIVITY_BLUETOOTH)
212         {
213                 checkSecondText = true;
214                 ItemTypeIconAndTwoLine(itemIconRect, itemIconLabelRect, itemSecondLineTextRect, fontSize);
215                 itmeHeight = (itemIconLabelRect.height + itemSecondLineTextRect.height);
216                 pBitmap = ResourceManager::GetBitmapN(IDB_BLUETOOTH);
217
218                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) == E_SUCCESS)
219                 {
220                         AppLogDebug("systeminfo::GetValue() fail(%s)", GetErrorMessage(GetLastResult()));
221
222                         if (EnableStatus == true)
223                         {
224                                 btEnableStatus = BluetoothPresentationModel::GetInstance()->IsBluetoothActivated();
225                                 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_ON");
226                         }
227                         else
228                         {
229                                 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
230                         }
231                 }
232                 else
233                 {
234                         secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
235                 }
236                 itemText = ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH");
237         }
238         else if (itemIndex == ID_ITEM_CONNECTIVITY_NFC)
239         {
240                 checkSecondText = true;
241                 ItemTypeIconAndTwoLine(itemIconRect, itemIconLabelRect, itemSecondLineTextRect, fontSize);
242                 itmeHeight = (itemIconLabelRect.height + itemSecondLineTextRect.height);
243                 pBitmap = ResourceManager::GetBitmapN(IDB_NFC);
244                 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
245
246                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_NFC, EnableStatus) == E_SUCCESS)
247                 {
248                         AppLogDebug("systeminfo::GetValue() success(%s)", GetErrorMessage(GetLastResult()));
249
250                         if (EnableStatus == true)
251                         {
252                                 if (NfcPresentationModel::GetInstance()->IsNfcActivated() == true)
253                                 {
254                                         secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_ON");
255                                 }
256                                 else
257                                 {
258                                         secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
259                                 }
260                         }
261                         else
262                         {
263                                 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
264                         }
265                 }
266                 else
267                 {
268                         secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
269                 }
270                 itemText = ResourceManager::GetString(L"IDS_NFC_BODY_NFC");
271         }
272         else
273         {
274                 itemText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
275                 ItemTypeIconAndOneLine(itemIconRect, itemIconLabelRect);
276         }
277
278         RelativeLayout relativeLayout;
279         relativeLayout.Construct();
280
281         pItem->Construct(relativeLayout, Dimension(itemWidth, itmeHeight), style);
282         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
283
284         if (pBitmap == null)
285         {
286                 pLabel = new (std::nothrow) Label();
287                 pLabel->Construct(itemLabelRect, itemText);
288                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
289
290                 pItem->AddControl(pLabel);
291                 relativeLayout.SetMargin(*pLabel, itemLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
292                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
293                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
294         }
295         else
296         {
297                 pLabel = new (std::nothrow) Label();
298                 pLabel->Construct(itemIconRect, L"");
299                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
300                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
301                 pLabel->SetBackgroundBitmap(*pBitmap);
302
303                 pItem->AddControl(pLabel);
304
305                 pLabel = new (std::nothrow) Label();
306                 pLabel->Construct(itemIconLabelRect, itemText);
307                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
308                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
309                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
310
311                 pItem->AddControl(pLabel);
312                 relativeLayout.SetMargin(*pLabel, itemIconLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
313                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
314                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
315
316                 if (checkSecondText == true)
317                 {
318                         pLabel = new (std::nothrow) Label();
319                         pLabel->Construct(itemSecondLineTextRect, secondLineText);
320                         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
321                         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
322                         pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
323                         pLabel->SetTextColor(COLOR_SUB_TEXT);
324
325                         pItem->AddControl(pLabel);
326                         relativeLayout.SetMargin(*pLabel, itemSecondLineTextRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
327                         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
328                         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
329                 }
330         }
331
332         return pItem;
333 }
334
335 bool
336 MoreConnectivityForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
337 {
338         AppLogDebug("ENTER");
339
340         delete pItem;
341         pItem = null;
342
343         return true;
344 }
345
346 bool
347 MoreConnectivityForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
348 {
349         AppLogDebug("ENTER");
350
351         delete pItem;
352         pItem = null;
353
354         return true;
355 }
356
357 void
358 MoreConnectivityForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
359 {
360         bool EnableStatus = false;
361         SceneManager* pSceneManager = SceneManager::GetInstance();
362         AppAssert(pSceneManager);
363
364         AppLogDebug("Group[ %d ] Index [ %d ]", groupIndex, itemIndex);
365
366         switch (itemIndex)
367         {
368         case ID_ITEM_CONNECTIVITY_BLUETOOTH:
369                 {
370                         if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) != E_SUCCESS)
371                         {
372                                 AppLogDebug("systeminfo::GetValue() fail(%s)", GetErrorMessage(GetLastResult()));
373                         }
374
375                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_BLUETOOTH, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
376                 }
377                 break;
378
379         case ID_ITEM_CONNECTIVITY_NFC:
380                 {
381                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_NFC, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
382                 }
383                 break;
384
385         case ID_ITEM_CONNECTIVITY_WIFI_DIRECT:
386                 {
387                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WIFI_DIRECT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
388                 }
389                 break;
390
391         default:
392                 break;
393         }
394 }
395
396 int
397 MoreConnectivityForm::GetDefaultGroupItemHeight(void)
398 {
399         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
400 }
401
402 int
403 MoreConnectivityForm::GetDefaultItemHeight(void)
404 {
405         return H_GROUP_ITEM_DEFAULT;
406 }
407
408 void
409 MoreConnectivityForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
410 {
411 }
412
413 void
414 MoreConnectivityForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
415 {
416         if ((groupIndex != 0)
417                 && (itemIndex != 0))
418         {
419                 AppLogDebug("UpdateItem is Error");
420                 return;
421         }
422
423         Label* pLabel = static_cast<Label*>(pItem->GetControl(2));
424         AppLogDebug("pLabel is %ls", pLabel->GetText().GetPointer());
425         if (__pTableView->IsItemChecked(groupIndex, itemIndex) == true)
426         {
427                 pLabel->SetText(ResourceManager::GetString(L"IDS_ST_BODY_ON"));
428         }
429         else
430         {
431                 pLabel->SetText(ResourceManager::GetString(L"IDS_ST_BODY_OFF"));
432         }
433         Invalidate(true);
434 }
435
436 void
437 MoreConnectivityForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
438 {
439 }
440
441 void
442 MoreConnectivityForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
443 {
444 }