Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StNetworkForm.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                StNetworkForm.cpp
19  * @brief               This is the implementation file for NetworkForm class.
20  */
21
22 #include <FSystem.h>
23 #include "StNetworkForm.h"
24 #include "StResourceManager.h"
25 #include "StTypes.h"
26
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;
33
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;
37
38 static const int ID_GROUP_DATA_ROAMING = 1;
39 static const int ID_GROUP_DATA_ROAMING_ITEM_COUNT = 1;
40
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;
44
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;
50
51 static const int ID_GROUP_NETWORK_CONNECTIONS = 4;
52
53 static const int ID_GROUP_COUNT = 2;
54
55 static const int W_RESIZE_LABEL_GAP = 170;
56
57 NetworkForm::NetworkForm(void)
58 {
59 }
60
61 NetworkForm::~NetworkForm(void)
62 {
63 }
64
65 void
66 NetworkForm::CreateFooter(void)
67 {
68         Footer* pFooter = GetFooter();
69         AppAssert(pFooter);
70
71         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
72         pFooter->SetBackButton();
73         pFooter->AddActionEventListener(*this);
74
75         SetFormBackEventListener(this);
76 }
77
78 result
79 NetworkForm::OnInitializing(void)
80 {
81         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_NETWORK"));
82         CreateFooter();
83         CreateTableView();
84
85         AppLogDebug("ENTER");
86
87         return E_SUCCESS;
88 }
89
90 result
91 NetworkForm::OnTerminating(void)
92 {
93         __pTableView = null;
94
95         SetFormBackEventListener(null);
96         return E_SUCCESS;
97 }
98
99 void
100 NetworkForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
101 {
102         bool itemStatus = false;
103
104         __pTableView->UpdateTableView();
105
106         if (SettingInfo::GetValue(SETTING_INFO_KEY_NETWORK_PACKETSERVICE, itemStatus) == E_SUCCESS)
107         {
108                 __pTableView->SetItemChecked(ID_GROUP_USE_PACKET_DATA, ID_ITEM_USE_PACKET_DATA, itemStatus);
109         }
110         AppLogDebug("GetValue ID_GROUP_USE_PACKET_DATA [%s]", GetErrorMessage(GetLastResult()));
111
112         if (SettingInfo::GetValue(SETTING_INFO_KEY_NETWORK_ROAMING, itemStatus) == E_SUCCESS)
113         {
114                 __pTableView->SetItemChecked(ID_GROUP_DATA_ROAMING, ID_ITEM_NETWORK_NETWORK_MODE, itemStatus);
115         }
116         AppLogDebug("GetValue ID_GROUP_DATA_ROAMING [%s]", GetErrorMessage(GetLastResult()));
117 }
118
119 void
120 NetworkForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
121 {
122 }
123
124 void
125 NetworkForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
126 {
127         SceneManager* pSceneManager = SceneManager::GetInstance();
128         AppAssert(pSceneManager);
129
130         __pTableView->CollapseGroup(ID_GROUP_NETWORK_MODE_SUB);
131         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
132 }
133
134 int
135 NetworkForm::GetGroupCount(void)
136 {
137         AppLogDebug("GetGroupCount[ %d ]", ID_GROUP_COUNT);
138         return ID_GROUP_COUNT;
139 }
140
141 int
142 NetworkForm::GetItemCount(int groupIndex)
143 {
144         int itemCount = 0;
145
146         switch (groupIndex)
147         {
148         case ID_GROUP_USE_PACKET_DATA:
149                 {
150                         itemCount = ID_GROUP_USE_PACKET_DATA_ITEM_COUNT;
151                 }
152                 break;
153
154         case ID_GROUP_NETWORK_CONNECTIONS:
155                 // fall through
156         case ID_GROUP_DATA_ROAMING:
157                 {
158                         itemCount = ID_GROUP_DATA_ROAMING_ITEM_COUNT;
159                 }
160                 break;
161
162         case ID_GROUP_NETWORK:
163                 {
164                         itemCount = ID_GROUP_NETWORK_ITEM_COUNT;
165                 }
166                 break;
167
168         case ID_GROUP_NETWORK_MODE_SUB:
169                 {
170                         itemCount = ID_GROUP_NETWORK_MODE_SUB_ITEM_COUNT;
171                 }
172                 break;
173
174         default:
175                 break;
176         }
177
178         AppLogDebug("GetItemCount %d", itemCount);
179         return itemCount;
180 }
181
182 TableViewGroupItem*
183 NetworkForm::CreateGroupItem(int groupIndex, int itemWidth)
184 {
185         AppLogDebug("ENTER");
186
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;
191         String groupText;
192         Label* pLabel = null;
193
194         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
195
196         switch (groupIndex)
197         {
198         case ID_GROUP_USE_PACKET_DATA:
199                 {
200                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
201                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
202                 }
203                 break;
204
205         case ID_GROUP_DATA_ROAMING:
206                 {
207                         itemHeight = 0;
208                 }
209                 break;
210
211         case ID_GROUP_NETWORK:
212                 {
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");
216                 }
217                 break;
218
219         case ID_GROUP_NETWORK_MODE_SUB:
220                 // fall through
221         case ID_GROUP_NETWORK_CONNECTIONS:
222                 {
223                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
224                         itemHeight = 0;
225                         __pTableView->CollapseGroup(ID_GROUP_NETWORK_MODE_SUB);
226                 }
227                 break;
228
229         default:
230                 {
231                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
232                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
233                 }
234                 break;
235         }
236
237         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
238         itemMainRectangle.y = yItemOffset;
239         itemMainRectangle.width = itemWidth;
240         itemMainRectangle.height = itemHeight;
241
242         RelativeLayout relativeLayout;
243         relativeLayout.Construct();
244
245         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
246         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
247
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);
254
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);
260
261         return pItem;
262 }
263
264 TableViewItem*
265 NetworkForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
266 {
267         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
268         Rectangle itemMainRectangle;
269         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
270         String itemMainText;
271         Label* pLabel = null;
272         int fontSize = GetFontSize();
273
274         TableViewItem* pItem = new (std::nothrow) TableViewItem();
275
276         if (groupIndex > ID_GROUP_DATA_ROAMING)
277         {
278                 style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
279         }
280
281         switch (groupIndex)
282         {
283         case ID_GROUP_USE_PACKET_DATA:
284                 {
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)
288                         {
289                                 __pTableView->SetItemChecked(groupIndex, itemIndex, packetStatus);
290                         }
291                         else
292                         {
293                                 AppLogDebug("GetValue ID_GROUP_USE_PACKET_DATA [%s]", GetErrorMessage(GetLastResult()));
294                         }
295                 }
296                 break;
297
298         case ID_GROUP_DATA_ROAMING:
299                 {
300                         bool roamingStatus = false;
301                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DATA_ROAMING");
302
303                         if (SettingInfo::GetValue(SETTING_INFO_KEY_NETWORK_ROAMING, roamingStatus) == E_SUCCESS)
304                         {
305                                 __pTableView->SetItemChecked(groupIndex, itemIndex, roamingStatus);
306                         }
307                         else
308                         {
309                                 AppLogDebug("GetValue ID_GROUP_DATA_ROAMING [%s]", GetErrorMessage(GetLastResult()));
310                         }
311                 }
312                 break;
313
314         case ID_GROUP_NETWORK:
315                 {
316                         if (itemIndex == ID_ITEM_NETWORK_NETWORK_MODE)
317                         {
318                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_NETWORK_MODE");
319                         }
320                 }
321                 break;
322
323         case ID_GROUP_NETWORK_MODE_SUB:
324                 {
325                         style = TABLE_VIEW_ANNEX_STYLE_RADIO;
326                         String networkType;
327                         SystemInfo::GetValue(SYSTEM_INFO_KEY_TELEPHONY, networkType);
328                         AppLogDebug("GetValue networktype [%s]", GetErrorMessage(GetLastResult()));
329
330                         switch (itemIndex)
331                         {
332                         case ID_ITEM_NETWORK_NETWORK_MODE_GSM_WCDMA:
333                                 {
334                                         if (networkType.Equals(L"emergency", false))
335                                         {
336                                                 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
337                                         }
338
339                                         itemMainText = L"GSM/WCDMA";
340                                         itemMainText.Append(ResourceManager::GetString(L"IDS_KW_MBODY_AUTO_CONNECT"));
341                                 }
342                                 break;
343
344                         case ID_ITEM_NETWORK_NETWORK_MODE_GSM_ONLY:
345                                 {
346                                         itemMainText = L"GSM only";
347                                 }
348                                 break;
349
350                         case ID_ITEM_NETWORK_NETWORK_MODE_WCDMA_ONLY:
351                                 {
352                                         itemMainText = ResourceManager::GetString(L"IDS_SETTING_NETWORK_MODE_WCDMA_ONLY");
353                                 }
354                                 break;
355
356                         default:
357                                 break;
358                         }
359                 }
360                 break;
361
362         case ID_GROUP_NETWORK_CONNECTIONS:
363                 {
364                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CONNECTIONS");
365                 }
366                 break;
367
368         default:
369                 break;
370         }
371
372         ItemTypeOneLine(itemMainRectangle);
373         itemMainRectangle.width -= W_RESIZE_LABEL_GAP;
374         RelativeLayout relativeLayout;
375         relativeLayout.Construct();
376
377         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
378         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
379
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);
385
386         pItem->AddControl(pLabel);
387         if (style == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
388         {
389                 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
390         }
391         else
392         {
393                 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
394         }
395         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
396         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
397
398         return pItem;
399 }
400
401 bool
402 NetworkForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
403 {
404         AppLogDebug("ENTER");
405
406         delete pItem;
407         pItem = null;
408
409         return true;
410 }
411
412 bool
413 NetworkForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
414 {
415         AppLogDebug("ENTER");
416
417         delete pItem;
418         pItem = null;
419
420         return true;
421 }
422
423 void
424 NetworkForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
425 {
426         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
427
428         bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
429
430         switch (groupIndex)
431         {
432         case ID_GROUP_USE_PACKET_DATA:
433                 {
434                         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
435                         {
436                                 itemSelectStatus = (!(itemSelectStatus));
437                         }
438
439                         if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_NETWORK_PACKETSERVICE, itemSelectStatus) == E_SUCCESS)
440                         {
441                                 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
442                         }
443                         else
444                         {
445                                 AppLogDebug("GetValue ID_GROUP_USE_PACKET_DATA [%s]", GetErrorMessage(GetLastResult()));
446                         }
447                 }
448                 break;
449
450         case ID_GROUP_DATA_ROAMING:
451                 {
452                         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
453                         {
454                                 itemSelectStatus = (!(itemSelectStatus));
455                         }
456
457                         if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_NETWORK_ROAMING, itemSelectStatus) == E_SUCCESS)
458                         {
459                                 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
460                         }
461                         else
462                         {
463                                 AppLogDebug("GetValue ID_GROUP_DATA_ROAMING [%s]", GetErrorMessage(GetLastResult()));
464                         }
465                 }
466                 break;
467
468         case ID_GROUP_NETWORK:
469                 {
470                         if (__pTableView->IsGroupExpanded(ID_GROUP_NETWORK_MODE_SUB) == true)
471                         {
472                                 __pTableView->CollapseGroup(ID_GROUP_NETWORK_MODE_SUB);
473                         }
474                         else
475                         {
476                                 __pTableView->ExpandGroup(ID_GROUP_NETWORK_MODE_SUB);
477                         }
478                 }
479                 break;
480
481         case ID_GROUP_NETWORK_MODE_SUB:
482                 {
483                         int groupCount = tableView.GetItemCountAt(ID_GROUP_NETWORK_MODE_SUB);
484
485                         for (int count = 0; count < groupCount; count++)
486                         {
487                                 if (itemIndex == count)
488                                 {
489                                         tableView.SetItemChecked(groupIndex, count, true);
490                                 }
491                                 else
492                                 {
493                                         tableView.SetItemChecked(groupIndex, count, false);
494                                 }
495
496                                 Invalidate(true);
497                         }
498                 }
499                 break;
500
501         default:
502                 break;
503         }
504 }
505
506 int
507 NetworkForm::GetDefaultGroupItemHeight(void)
508 {
509         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
510 }
511
512 int
513 NetworkForm::GetDefaultItemHeight(void)
514 {
515         return H_GROUP_ITEM_DEFAULT;
516 }
517
518 void
519 NetworkForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
520 {
521 }
522
523 void
524 NetworkForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
525 {
526 }
527
528 void
529 NetworkForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
530 {
531 }
532
533 void
534 NetworkForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
535 {
536 }