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