Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / data / my_tools / jj / rsa / apps / osp / Settings / src / StMoreConnectivityForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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 "StResourceManager.h"
25 #include "StSettingScenesList.h"
26 #include "StTypes.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::System;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 static const int ID_GROUP_CONNECTIVITY = 0;
37 #ifdef DISPLAY_SETTING_MENU_FOR_R0
38 static const int ID_GROUP_CONNECTIVITY_ITEM_COUNT = 1;
39 #else
40 static const int ID_GROUP_CONNECTIVITY_ITEM_COUNT = 2;
41 #endif
42 static const int ID_ITEM_CONNECTIVITY_BLUETOOTH = 0;
43 static const int ID_ITEM_CONNECTIVITY_WIFI_DIRECT = 1;
44
45 static const int ID_GROUP_COUNT = 1;
46 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_CONNECTIVITY_ITEM_COUNT;
47
48 static const int BLUETOOTH_ON_OFF_OPTION = 2;
49 static const int BLUETOOTH_OFF_OPTION = 0;
50 static const int BLUETOOTH_ON_OPTION = 1;
51
52 MoreConnectivityForm::MoreConnectivityForm(void)
53 {
54 }
55
56 MoreConnectivityForm::~MoreConnectivityForm(void)
57 {
58 }
59
60 void
61 MoreConnectivityForm::CreateFooter(void)
62 {
63         Footer* pFooter = GetFooter();
64         AppAssert(pFooter);
65
66         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
67         pFooter->SetBackButton();
68         pFooter->AddActionEventListener(*this);
69
70         SetFormBackEventListener(this);
71 }
72
73 result
74 MoreConnectivityForm::OnInitializing(void)
75 {
76         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MORE_CONNECTIVITY_SETTINGS"));
77         CreateFooter();
78         CreateTableView();
79
80         AppLogDebug("ENTER");
81         return E_SUCCESS;
82 }
83
84 result
85 MoreConnectivityForm::OnTerminating(void)
86 {
87         __pTableView = null;
88
89         SetFormBackEventListener(null);
90         return E_SUCCESS;
91 }
92
93 void
94 MoreConnectivityForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
95 {
96         if (__pTableView != null)
97         {
98                 __pTableView->UpdateTableView();
99         }
100 }
101
102 void
103 MoreConnectivityForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
104 {
105 }
106
107 void
108 MoreConnectivityForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
109 {
110         SceneManager* pSceneManager = SceneManager::GetInstance();
111         AppAssert(pSceneManager);
112
113         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
114 }
115
116 int
117 MoreConnectivityForm::GetGroupCount(void)
118 {
119         AppLogDebug("ENTER");
120         return ID_GROUP_COUNT;
121 }
122
123 int
124 MoreConnectivityForm::GetItemCount(int groupIndex)
125 {
126         int itemCount = ID_GROUP_MAX_ITEM_COUNT;
127
128         AppLogDebug("GetItemCount %d", itemCount);
129
130         return itemCount;
131 }
132
133 TableViewGroupItem*
134 MoreConnectivityForm::CreateGroupItem(int groupIndex, int itemWidth)
135 {
136         AppLogDebug("ENTER");
137
138         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
139         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
140         Rectangle itemRectangle;
141         String groupText;
142         Label* pLabel = null;
143
144         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
145
146         itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
147         itemRectangle.y = Y_GROUP_ITEM_DEFAULT_LABEL;
148         itemRectangle.width = itemWidth;
149         itemRectangle.height = itemHeight;
150
151         RelativeLayout relativeLayout;
152         relativeLayout.Construct();
153
154         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
155         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
156
157         pLabel = new (std::nothrow) Label();
158         pLabel->Construct(itemRectangle, groupText);
159         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
160         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
161         pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
162
163         pItem->AddControl(*pLabel);
164         relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
165         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
166         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
167         pItem->SetEnabled(false);
168
169         return pItem;
170 }
171
172 TableViewItem*
173 MoreConnectivityForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
174 {
175         AppLogDebug("ENTER");
176
177         bool checkSecondText = false;
178         int itmeHeight = H_GROUP_ITEM_DEFAULT_LABEL;
179         int btEnableStatus = BLUETOOTH_OFF_OPTION;
180         Rectangle itemLabelRect;
181         Rectangle itemIconRect;
182         Rectangle itemIconLabelRect;
183         Rectangle itemSecondLineTextRect;
184         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
185         Bitmap* pBitmap = null;
186         String itemText;
187         String secondLineText;
188         bool EnableStatus = false;
189         Label* pLabel = null;
190         int fontSize = GetFontSize();
191
192         TableViewItem* pItem = new (std::nothrow) TableViewItem();
193
194         if (itemIndex == ID_ITEM_CONNECTIVITY_BLUETOOTH)
195         {
196                 checkSecondText = true;
197                 ItemTypeIconAndTwoLine(itemIconRect, itemIconLabelRect, itemSecondLineTextRect, fontSize);
198                 itmeHeight = (itemIconLabelRect.height + itemSecondLineTextRect.height);
199
200                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) == E_SUCCESS)
201                 {
202                         AppLogDebug("systeminfo::GetValue() fail(%s)", GetErrorMessage(GetLastResult()));
203
204                         if (EnableStatus == true)
205                         {
206                                 btEnableStatus = BluetoothPresentationModel::GetInstance()->IsBluetoothActivated();
207                                 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_ON");
208                         }
209                         else
210                         {
211                                 secondLineText = ResourceManager::GetString(L"IDS_ST_BODY_OFF");
212                         }
213                 }
214                 itemText = ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH");
215         }
216         else
217         {
218                 itemText = ResourceManager::GetString(L"IDS_ST_HEADER_WI_FI_DIRECT");
219                 ItemTypeIconAndOneLine(itemIconRect, itemIconLabelRect);
220         }
221
222         RelativeLayout relativeLayout;
223         relativeLayout.Construct();
224
225         pItem->Construct(relativeLayout, Dimension(itemWidth, itmeHeight), style);
226         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
227
228         pBitmap = ResourceManager::GetBitmapN(IDB_BLUETOOTH);
229
230         if (pBitmap == null)
231         {
232                 pLabel = new (std::nothrow) Label();
233                 pLabel->Construct(itemLabelRect, itemText);
234                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
235
236                 pItem->AddControl(*pLabel);
237                 relativeLayout.SetMargin(*pLabel, itemLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
238                 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
239                 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
240         }
241         else
242         {
243                 pLabel = new (std::nothrow) Label();
244                 pLabel->Construct(itemIconRect, L"");
245                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
246                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
247                 pLabel->SetBackgroundBitmap(*pBitmap);
248
249                 pItem->AddControl(*pLabel);
250
251                 pLabel = new (std::nothrow) Label();
252                 pLabel->Construct(itemIconLabelRect, itemText);
253                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
254                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
255                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
256
257                 pItem->AddControl(*pLabel);
258                 relativeLayout.SetMargin(*pLabel, itemIconLabelRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
259                 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
260                 relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
261
262                 if (checkSecondText == true)
263                 {
264                         pLabel = new (std::nothrow) Label();
265                         pLabel->Construct(itemSecondLineTextRect, secondLineText);
266                         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
267                         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
268                         pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
269                         pLabel->SetTextColor(COLOR_SUB_TEXT);
270
271                         pItem->AddControl(*pLabel);
272                         relativeLayout.SetMargin(*pLabel, itemSecondLineTextRect.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
273                         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
274                         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
275                 }
276         }
277
278         return pItem;
279 }
280
281 bool
282 MoreConnectivityForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
283 {
284         AppLogDebug("ENTER");
285
286         delete pItem;
287         pItem = null;
288
289         return true;
290 }
291
292 bool
293 MoreConnectivityForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
294 {
295         AppLogDebug("ENTER");
296
297         delete pItem;
298         pItem = null;
299
300         return true;
301 }
302
303 void
304 MoreConnectivityForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
305 {
306         bool EnableStatus = false;
307         SceneManager* pSceneManager = SceneManager::GetInstance();
308         AppAssert(pSceneManager);
309
310         AppLogDebug("Group[ %d ] Index [ %d ]", groupIndex, itemIndex);
311
312         switch (itemIndex)
313         {
314         case ID_ITEM_CONNECTIVITY_BLUETOOTH:
315                 {
316                         if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) != E_SUCCESS)
317                         {
318                                 AppLogDebug("systeminfo::GetValue() fail(%s)", GetErrorMessage(GetLastResult()));
319                         }
320
321                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_BLUETOOTH, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
322                 }
323                 break;
324
325         case ID_ITEM_CONNECTIVITY_WIFI_DIRECT:
326                 {
327                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_WIFI_DIRECT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
328                 }
329                 break;
330
331         default:
332                 break;
333         }
334 }
335
336 int
337 MoreConnectivityForm::GetDefaultGroupItemHeight(void)
338 {
339         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
340 }
341
342 int
343 MoreConnectivityForm::GetDefaultItemHeight(void)
344 {
345         return H_GROUP_ITEM_DEFAULT;
346 }
347
348 void
349 MoreConnectivityForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
350 {
351 }
352
353 void
354 MoreConnectivityForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
355 {
356 }
357
358 void
359 MoreConnectivityForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
360 {
361 }
362
363 void
364 MoreConnectivityForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
365 {
366 }