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