NABI issues N_SE-50115, N_SE-50067, N_SE-49946, N_SE-49897, N_SE-49884, N_SE-48837...
[apps/osp/Settings.git] / src / StLocationForm.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                StLocationForm.cpp
19  * @brief               This is the implementation file for LocationForm class.
20  */
21
22 #include "StLocationForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::App;
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 char APPCONTROL_REQUEST_DEFAULT = 0x00;
37 static const char APPCONTROL_REQUEST_LOCATION = 0x20;
38
39 static const int ID_GROUP_GPS_1 = 0;
40 static const int ID_GROUP_GPS_1_ITEM_COUNT = 1;
41 static const int ID_ITEM_GPS_ON_OFF = 0;
42
43 static const int ID_GROUP_GPS_2 = 1;
44 static const int ID_GROUP_GPS_2_ITEM_COUNT = 1;
45 static const int ID_ITEM_GPS_NETWORK_POSITION = 0;
46 static const int ID_GROUP_GPS_3 = 2;
47 static const int ID_GROUP_GPS_3_ITEM_COUNT = 0;
48
49 static const int ID_GROUP_COUNT = 3;
50 static const int ID_FOOTER_ITEM_INDEX_1 = 0;
51
52 static const int IDA_FOOTER_ITEM_HELP = 100;
53
54 static const int W_RESIZE_LABEL_GAP = 170;
55
56 LocationForm::LocationForm(void)
57         : __isAppControlRequest(APPCONTROL_REQUEST_DEFAULT)
58         , __categoryCheck(L"")
59 {
60 }
61
62 LocationForm::~LocationForm(void)
63 {
64 }
65
66 void
67 LocationForm::CreateFooter(void)
68 {
69         Footer* pFooter = GetFooter();
70         AppAssert(pFooter);
71
72         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
73
74         FooterItem footerHelp;
75         footerHelp.Construct(IDA_FOOTER_ITEM_HELP);
76         footerHelp.SetText(ResourceManager::GetString(L"IDS_ST_BODY_HELP"));
77
78         pFooter->AddItem(footerHelp);
79         pFooter->AddActionEventListener(*this);
80         pFooter->SetItemEnabled(ID_FOOTER_ITEM_INDEX_1, true);
81
82         SetFormBackEventListener(this);
83 }
84
85 result
86 LocationForm::OnInitializing(void)
87 {
88         SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
89         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_LOCATIONS"));
90         CreateFooter();
91         CreateTableView();
92
93         AppLogDebug("ENTER");
94
95         return E_SUCCESS;
96 }
97
98 result
99 LocationForm::OnTerminating(void)
100 {
101         __pTableView = null;
102
103         SetFormBackEventListener(null);
104         return E_SUCCESS;
105 }
106
107 void
108 LocationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
109 {
110         bool itemStatus = false;
111         __pTableView->UpdateTableView();
112
113         SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, itemStatus);
114         if (!IsFailed(GetLastResult())
115                 && (itemStatus == true))
116         {
117                 __pTableView->SetItemChecked(ID_GROUP_GPS_1, ID_ITEM_GPS_ON_OFF, itemStatus);
118         }
119         AppLogDebug("Gps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
120
121         SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, itemStatus);
122         if (!IsFailed(GetLastResult())
123                 && (itemStatus == true))
124         {
125                 __pTableView->SetItemChecked(ID_GROUP_GPS_2, ID_ITEM_GPS_NETWORK_POSITION, itemStatus);
126         }
127         AppLogDebug("Wps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
128
129         if (pArgs != null)
130         {
131                 __categoryCheck = static_cast<String*>(pArgs->GetAt(0))->GetPointer();
132
133                 if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/gps") == 0)
134                 {
135                         __isAppControlRequest = APPCONTROL_REQUEST_LOCATION;
136                 }
137                 else if (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/wps") == 0)
138                 {
139                         __isAppControlRequest = APPCONTROL_REQUEST_LOCATION;
140                 }
141
142                 delete pArgs;
143         }
144 }
145
146 void
147 LocationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
148 {
149 }
150
151 void
152 LocationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
153 {
154         SceneManager* pSceneManager = SceneManager::GetInstance();
155         AppAssert(pSceneManager);
156
157         if (__isAppControlRequest != APPCONTROL_REQUEST_DEFAULT)
158         {
159                 UiApp* pApp = UiApp::GetInstance();
160                 AppAssert(pApp);
161                 AppControlLocationResult();
162                 pApp->Terminate();
163         }
164         else
165         {
166                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
167         }
168 }
169
170 int
171 LocationForm::GetGroupCount(void)
172 {
173         AppLogDebug("ENTER");
174         return ID_GROUP_COUNT;
175 }
176
177 int
178 LocationForm::GetItemCount(int groupIndex)
179 {
180         int itemCount = 0;
181
182         switch (groupIndex)
183         {
184         case ID_GROUP_GPS_1:
185                 {
186                         itemCount = ID_GROUP_GPS_1_ITEM_COUNT;
187                 }
188                 break;
189
190         case ID_GROUP_GPS_2:
191                 {
192                         itemCount = ID_GROUP_GPS_2_ITEM_COUNT;
193                 }
194                 break;
195
196         case ID_GROUP_GPS_3:
197                 {
198                         itemCount = ID_GROUP_GPS_3_ITEM_COUNT;
199                 }
200                 break;
201
202         default:
203                 break;
204         }
205
206         AppLogDebug("GetItemCount %d", itemCount);
207         return itemCount;
208 }
209
210 TableViewGroupItem*
211 LocationForm::CreateGroupItem(int groupIndex, int itemWidth)
212 {
213         AppLogDebug("ENTER");
214
215         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
216         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
217         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
218         Rectangle itemMainRectangle;
219         String groupText;
220         Label* pLabel = null;
221
222         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
223
224         switch (groupIndex)
225         {
226         case ID_GROUP_GPS_1:
227                 {
228                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
229                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
230                 }
231                 break;
232
233         default:
234                 {
235                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
236                         itemHeight = Y_GROUP_INDEX_DEFAULT;
237                 }
238                 break;
239         }
240
241         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
242         itemMainRectangle.y = yItemOffset;
243         itemMainRectangle.width = itemWidth;
244         itemMainRectangle.height = itemHeight;
245
246         RelativeLayout relativeLayout;
247         relativeLayout.Construct();
248
249         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
250         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
251
252         pLabel = new (std::nothrow) Label();
253         pLabel->Construct(itemMainRectangle, groupText);
254         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
255         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
256         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
257         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
258
259         pItem->AddControl(pLabel);
260         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
261         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
262         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
263         pItem->SetEnabled(false);
264
265         return pItem;
266 }
267
268 TableViewItem*
269 LocationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
270 {
271         Rectangle itemMainRectangle;
272         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
273         String itemMainText;
274         Label* pLabel = null;
275         int fontSize = GetFontSize();
276
277         style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
278         ItemTypeOneLine(itemMainRectangle);
279
280         switch (groupIndex)
281         {
282         case ID_GROUP_GPS_1:
283                 {
284                         bool gpsStatus;
285                         itemMainText = ResourceManager::GetString(L"IDS_CAM_OPT_GPS");
286                         SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
287                         if (!IsFailed(GetLastResult())
288                                 && (gpsStatus == true))
289                         {
290                                 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
291                         }
292                 }
293                 break;
294
295         case ID_GROUP_GPS_2:
296                 {
297                         switch (itemIndex)
298                         {
299                         case ID_ITEM_GPS_NETWORK_POSITION:
300                                 {
301                                         bool wpsStatus;
302                                         itemMainText = ResourceManager::GetString(L"IDS_LBS_BODY_NETWORK_POSITION");
303                                         itemMainRectangle.width -= W_RESIZE_LABEL_GAP;
304
305                                         SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
306                                         if (!IsFailed(GetLastResult())
307                                                 && (wpsStatus == true))
308                                         {
309                                                 __pTableView->SetItemChecked(groupIndex, itemIndex, true);
310                                         }
311                                 }
312                                 break;
313
314                         default:
315                                 break;
316                         }
317                 }
318                 break;
319
320         default:
321                 break;
322         }
323
324         TableViewItem* pItem = new (std::nothrow) TableViewItem();
325
326         RelativeLayout relativeLayout;
327         relativeLayout.Construct();
328
329         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
330         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
331
332         pLabel = new (std::nothrow) Label();
333         pLabel->Construct(itemMainRectangle, itemMainText);
334         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
335         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
336         pLabel->SetTextColor(COLOR_MAIN_TEXT);
337
338         pItem->AddControl(pLabel);
339         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN_ONOFF_SLIDING, 0, 0);
340         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
341         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
342
343         return pItem;
344 }
345
346 bool
347 LocationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
348 {
349         AppLogDebug("ENTER");
350
351         delete pItem;
352         pItem = null;
353
354         return true;
355 }
356
357 bool
358 LocationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
359 {
360         AppLogDebug("ENTER");
361
362         delete pItem;
363         pItem = null;
364
365         return true;
366 }
367
368 void
369 LocationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
370 {
371         bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
372
373         switch (groupIndex)
374         {
375         case ID_GROUP_GPS_1:
376                 {
377                         if (itemIndex == ID_ITEM_GPS_ON_OFF)
378                         {
379                                 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
380                                 {
381                                         itemSelectStatus = !itemSelectStatus;
382                                 }
383
384                                 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_LOCATION_GPS, itemSelectStatus) == E_SUCCESS)
385                                 {
386                                         tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
387                                 }
388                         }
389                 }
390                 break;
391
392         case ID_GROUP_GPS_2:
393                 {
394                         if (itemIndex == ID_ITEM_GPS_NETWORK_POSITION)
395                         {
396                                 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
397                                 {
398                                         itemSelectStatus = !itemSelectStatus;
399                                 }
400
401                                 if (SettingInfo::SetValueForPrivilegedKey(SETTING_INFO_KEY_LOCATION_WPS, itemSelectStatus) == E_SUCCESS)
402                                 {
403                                         tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
404                                 }
405                         }
406                 }
407                 break;
408
409         default:
410                 break;
411         }
412 }
413
414 void
415 LocationForm::OnActionPerformed(const Control& source, int actionId)
416 {
417         SceneManager* pSceneManager = SceneManager::GetInstance();
418         AppAssert(pSceneManager);
419
420         switch (actionId)
421         {
422         case IDA_FOOTER_ITEM_HELP:
423                 {
424                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_LOCATION_HELP, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
425                 }
426                 break;
427
428         default:
429                 {
430                         AppLogDebug("ID_HEADER_VOLUME Tab Selected %d", actionId);
431                 }
432                 break;
433         }
434 }
435
436 int
437 LocationForm::GetDefaultGroupItemHeight(void)
438 {
439         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
440 }
441
442 int
443 LocationForm::GetDefaultItemHeight(void)
444 {
445         return H_GROUP_ITEM_DEFAULT;
446 }
447
448 void
449 LocationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
450 {
451 }
452
453 void
454 LocationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
455 {
456 }
457
458 void
459 LocationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
460 {
461 }
462
463 void
464 LocationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
465 {
466 }
467
468 result
469 LocationForm::AppControlLocationResult(void)
470 {
471         RequestId reqId = 0;
472         String value;
473         bool gpsStatus = false;
474         bool wpsStatus = false;
475
476         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
477
478 #if 0
479         IList* pDefaultResultIList = null;
480         ArrayList* pDataList = null;
481
482         pDataList = new (std::nothrow) ArrayList();
483         pDataList->Construct();
484
485         SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
486         SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
487
488         pDataList->Add(*(new (std::nothrow) String(L"APPCONTROL_RESULT_SUCCEEDED")));
489         pDataList->Add(*(new (std::nothrow) String(L"category:Location")));
490
491         if (gpsStatus == true)
492         {
493                 value = L"GPSEnabled";
494         }
495         else
496         {
497                 value = L"GPSDisabled";
498         }
499         pDataList->Add(*(new (std::nothrow) String(value)));
500
501         if (wpsStatus == true)
502         {
503                 value = L"WPSEnabled";
504         }
505         else
506         {
507                 value = L"WPSDisabled";
508         }
509         pDataList->Add(*(new (std::nothrow) String(value)));
510
511         pDefaultResultIList = (pDataList->GetItemsN(0, pDataList->GetCount()));
512
513         pAppManager->SendAppControlResult(reqId, pDefaultResultIList);
514
515         pDataList->RemoveAll(true);
516         delete pDataList;
517         pDefaultResultIList->RemoveAll(true);
518         delete pDefaultResultIList;
519 #else
520         String status;
521         AppCtrlResult ResultValue = APP_CTRL_RESULT_FAILED;
522         HashMap* hashMap = new (std::nothrow) HashMap();
523         hashMap->Construct();
524
525         if ((__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/gps") == 0)
526                 || (__categoryCheck.CompareTo(L"http://tizen.org/appcontrol/data/location/wps") == 0)
527                 )
528         {
529                 result r = E_SUCCESS;
530                 ResultValue = APP_CTRL_RESULT_SUCCEEDED;
531                 hashMap->Add(*(new (std::nothrow) String(L"category")), *(new (std::nothrow) String(L"Location")));
532                 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, gpsStatus);
533
534                 if (r == E_SUCCESS && gpsStatus == true)
535                 {
536                         status = L"GPSEnabled";
537                 }
538                 else
539                 {
540                         status = L"GPSDisabled";
541                 }
542
543                 hashMap->Add(*(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/location/gps")), *(new (std::nothrow) String(status)));
544                 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, wpsStatus);
545
546                 if (r == E_SUCCESS && wpsStatus == true)
547                 {
548                         status = L"WPSEnabled";
549                 }
550                 else
551                 {
552                         status = L"WPSDisabled";
553                 }
554
555                 hashMap->Add(*(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/location/wps")), *(new (std::nothrow) String(status)));
556         }
557
558         pAppManager->SendAppControlResult(reqId, ResultValue, hashMap);
559
560         hashMap->RemoveAll();
561         delete hashMap;
562 #endif
563         return E_SUCCESS;
564 }
565
566 void
567 LocationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
568 {
569         AppLog("Enter");
570         bool itemStatus = false;
571         result r = E_SUCCESS;
572
573         if (requestId == REFRESH_REQUEST_EVENT)
574         {
575                 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_GPS, itemStatus);
576                 if (!IsFailed(r))
577                 {
578                         __pTableView->SetItemChecked(ID_GROUP_GPS_1, ID_ITEM_GPS_ON_OFF, itemStatus);
579                 }
580                 AppLogDebug("Gps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
581
582                 r = SettingInfo::GetValue(SETTING_INFO_KEY_LOCATION_WPS, itemStatus);
583                 if (!IsFailed(r))
584                 {
585                         __pTableView->SetItemChecked(ID_GROUP_GPS_2, ID_ITEM_GPS_NETWORK_POSITION, itemStatus);
586                 }
587                 AppLogDebug("Wps value[%d] [%s]", itemStatus, GetErrorMessage(GetLastResult()));
588                 __pTableView->UpdateTableView();
589         }
590 }