2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file StNetworkForm.cpp
19 * @brief This is the implementation file for NetworkForm class.
23 #include "StNetworkForm.h"
24 #include "StResourceManager.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::System;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
34 static const int ID_GROUP_USE_PACKET_DATA = 0;
35 static const int ID_GROUP_USE_PACKET_DATA_ITEM_COUNT = 1;
36 static const int ID_ITEM_USE_PACKET_DATA = 0;
38 static const int ID_GROUP_DATA_ROAMING = 1;
39 static const int ID_GROUP_DATA_ROAMING_ITEM_COUNT = 1;
41 static const int ID_GROUP_NETWORK = 2;
42 static const int ID_GROUP_NETWORK_ITEM_COUNT = 1;
43 static const int ID_ITEM_NETWORK_NETWORK_MODE = 0;
45 static const int ID_GROUP_NETWORK_MODE_SUB = 3;
46 static const int ID_GROUP_NETWORK_MODE_SUB_ITEM_COUNT = 3;
47 static const int ID_ITEM_NETWORK_NETWORK_MODE_GSM_WCDMA = 0;
48 static const int ID_ITEM_NETWORK_NETWORK_MODE_GSM_ONLY = 1;
49 static const int ID_ITEM_NETWORK_NETWORK_MODE_WCDMA_ONLY = 2;
51 static const int ID_GROUP_NETWORK_CONNECTIONS = 4;
53 static const int ID_GROUP_COUNT = 2;
55 static const int W_RESIZE_LABEL_GAP = 170;
57 NetworkForm::NetworkForm(void)
61 NetworkForm::~NetworkForm(void)
66 NetworkForm::CreateFooter(void)
68 Footer* pFooter = GetFooter();
71 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
72 pFooter->SetBackButton();
73 pFooter->AddActionEventListener(*this);
75 SetFormBackEventListener(this);
79 NetworkForm::OnInitializing(void)
81 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_NETWORK"));
91 NetworkForm::OnTerminating(void)
95 SetFormBackEventListener(null);
100 NetworkForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
102 bool itemStatus = false;
104 __pTableView->UpdateTableView();
106 if (SettingInfo::GetValue(SETTING_INFO_KEY_NETWORK_PACKETSERVICE, itemStatus) == E_SUCCESS)
108 __pTableView->SetItemChecked(ID_GROUP_USE_PACKET_DATA, ID_ITEM_USE_PACKET_DATA, itemStatus);
110 AppLogDebug("GetValue ID_GROUP_USE_PACKET_DATA [%s]", GetErrorMessage(GetLastResult()));
112 if (SettingInfo::GetValue(SETTING_INFO_KEY_NETWORK_ROAMING, itemStatus) == E_SUCCESS)
114 __pTableView->SetItemChecked(ID_GROUP_DATA_ROAMING, ID_ITEM_NETWORK_NETWORK_MODE, itemStatus);
116 AppLogDebug("GetValue ID_GROUP_DATA_ROAMING [%s]", GetErrorMessage(GetLastResult()));
120 NetworkForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
125 NetworkForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
127 SceneManager* pSceneManager = SceneManager::GetInstance();
128 AppAssert(pSceneManager);
130 __pTableView->CollapseGroup(ID_GROUP_NETWORK_MODE_SUB);
131 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
135 NetworkForm::GetGroupCount(void)
137 AppLogDebug("GetGroupCount[ %d ]", ID_GROUP_COUNT);
138 return ID_GROUP_COUNT;
142 NetworkForm::GetItemCount(int groupIndex)
148 case ID_GROUP_USE_PACKET_DATA:
150 itemCount = ID_GROUP_USE_PACKET_DATA_ITEM_COUNT;
154 case ID_GROUP_NETWORK_CONNECTIONS:
156 case ID_GROUP_DATA_ROAMING:
158 itemCount = ID_GROUP_DATA_ROAMING_ITEM_COUNT;
162 case ID_GROUP_NETWORK:
164 itemCount = ID_GROUP_NETWORK_ITEM_COUNT;
168 case ID_GROUP_NETWORK_MODE_SUB:
170 itemCount = ID_GROUP_NETWORK_MODE_SUB_ITEM_COUNT;
178 AppLogDebug("GetItemCount %d", itemCount);
183 NetworkForm::CreateGroupItem(int groupIndex, int itemWidth)
185 AppLogDebug("ENTER");
187 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
188 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
189 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
190 Rectangle itemMainRectangle;
192 Label* pLabel = null;
194 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
198 case ID_GROUP_USE_PACKET_DATA:
200 yItemOffset = Y_GROUP_INDEX_DEFAULT;
201 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
205 case ID_GROUP_DATA_ROAMING:
211 case ID_GROUP_NETWORK:
213 yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
214 itemHeight = ((H_GROUP_INDEX_HELP_TEXT * LINE_COUNT_2) + H_GROUP_INDEX_NO_TITLE_TEXT_GAP);
215 groupText = ResourceManager::GetString(L"IDS_COM_BODY_CONNECT_TO_DATA_SERVICES_WHEN_ROAMING");
219 case ID_GROUP_NETWORK_MODE_SUB:
221 case ID_GROUP_NETWORK_CONNECTIONS:
223 yItemOffset = Y_GROUP_INDEX_DEFAULT;
225 __pTableView->CollapseGroup(ID_GROUP_NETWORK_MODE_SUB);
231 yItemOffset = Y_GROUP_INDEX_DEFAULT;
232 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
237 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
238 itemMainRectangle.y = yItemOffset;
239 itemMainRectangle.width = itemWidth;
240 itemMainRectangle.height = itemHeight;
242 RelativeLayout relativeLayout;
243 relativeLayout.Construct();
245 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
246 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
248 pLabel = new (std::nothrow) Label();
249 pLabel->Construct(itemMainRectangle, groupText);
250 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
251 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
252 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
253 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
255 pItem->AddControl(pLabel);
256 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
257 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
258 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
259 pItem->SetEnabled(false);
265 NetworkForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
267 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
268 Rectangle itemMainRectangle;
269 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
271 Label* pLabel = null;
272 int fontSize = GetFontSize();
274 TableViewItem* pItem = new (std::nothrow) TableViewItem();
276 if (groupIndex > ID_GROUP_DATA_ROAMING)
278 style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
283 case ID_GROUP_USE_PACKET_DATA:
285 bool packetStatus = false;
286 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_USE_PACKET_DATA");
287 if (SettingInfo::GetValue(SETTING_INFO_KEY_NETWORK_PACKETSERVICE, packetStatus) == E_SUCCESS)
289 __pTableView->SetItemChecked(groupIndex, itemIndex, packetStatus);
293 AppLogDebug("GetValue ID_GROUP_USE_PACKET_DATA [%s]", GetErrorMessage(GetLastResult()));
298 case ID_GROUP_DATA_ROAMING:
300 bool roamingStatus = false;
301 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DATA_ROAMING");
303 if (SettingInfo::GetValue(SETTING_INFO_KEY_NETWORK_ROAMING, roamingStatus) == E_SUCCESS)
305 __pTableView->SetItemChecked(groupIndex, itemIndex, roamingStatus);
309 AppLogDebug("GetValue ID_GROUP_DATA_ROAMING [%s]", GetErrorMessage(GetLastResult()));
314 case ID_GROUP_NETWORK:
316 if (itemIndex == ID_ITEM_NETWORK_NETWORK_MODE)
318 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_NETWORK_MODE");
323 case ID_GROUP_NETWORK_MODE_SUB:
325 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
327 SystemInfo::GetValue(SYSTEM_INFO_KEY_TELEPHONY, networkType);
328 AppLogDebug("GetValue networktype [%s]", GetErrorMessage(GetLastResult()));
332 case ID_ITEM_NETWORK_NETWORK_MODE_GSM_WCDMA:
334 if (networkType.Equals(L"emergency", false))
336 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
339 itemMainText = L"GSM/WCDMA";
340 itemMainText.Append(ResourceManager::GetString(L"IDS_KW_MBODY_AUTO_CONNECT"));
344 case ID_ITEM_NETWORK_NETWORK_MODE_GSM_ONLY:
346 itemMainText = L"GSM only";
350 case ID_ITEM_NETWORK_NETWORK_MODE_WCDMA_ONLY:
352 itemMainText = ResourceManager::GetString(L"IDS_SETTING_NETWORK_MODE_WCDMA_ONLY");
362 case ID_GROUP_NETWORK_CONNECTIONS:
364 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CONNECTIONS");
372 ItemTypeOneLine(itemMainRectangle);
373 itemMainRectangle.width -= W_RESIZE_LABEL_GAP;
374 RelativeLayout relativeLayout;
375 relativeLayout.Construct();
377 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
378 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
380 pLabel = new (std::nothrow) Label();
381 pLabel->Construct(itemMainRectangle, itemMainText);
382 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
383 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
384 pLabel->SetTextColor(COLOR_MAIN_TEXT);
386 pItem->AddControl(pLabel);
387 if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
389 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
393 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
395 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
396 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
402 NetworkForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
404 AppLogDebug("ENTER");
413 NetworkForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
415 AppLogDebug("ENTER");
424 NetworkForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
426 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
428 bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
432 case ID_GROUP_USE_PACKET_DATA:
434 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
436 itemSelectStatus = (!(itemSelectStatus));
439 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_NETWORK_PACKETSERVICE, itemSelectStatus) == E_SUCCESS)
441 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
445 AppLogDebug("GetValue ID_GROUP_USE_PACKET_DATA [%s]", GetErrorMessage(GetLastResult()));
450 case ID_GROUP_DATA_ROAMING:
452 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
454 itemSelectStatus = (!(itemSelectStatus));
457 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_NETWORK_ROAMING, itemSelectStatus) == E_SUCCESS)
459 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
463 AppLogDebug("GetValue ID_GROUP_DATA_ROAMING [%s]", GetErrorMessage(GetLastResult()));
468 case ID_GROUP_NETWORK:
470 if (__pTableView->IsGroupExpanded(ID_GROUP_NETWORK_MODE_SUB) == true)
472 __pTableView->CollapseGroup(ID_GROUP_NETWORK_MODE_SUB);
476 __pTableView->ExpandGroup(ID_GROUP_NETWORK_MODE_SUB);
481 case ID_GROUP_NETWORK_MODE_SUB:
483 int groupCount = tableView.GetItemCountAt(ID_GROUP_NETWORK_MODE_SUB);
485 for (int count = 0; count < groupCount; count++)
487 if (itemIndex == count)
489 tableView.SetItemChecked(groupIndex, count, true);
493 tableView.SetItemChecked(groupIndex, count, false);
507 NetworkForm::GetDefaultGroupItemHeight(void)
509 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
513 NetworkForm::GetDefaultItemHeight(void)
515 return H_GROUP_ITEM_DEFAULT;
519 NetworkForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
524 NetworkForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
529 NetworkForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
534 NetworkForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)