Applied latest source code
[apps/native/preloaded/Settings.git] / src / StSettingsApp.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                StSettingsApp.cpp
19  * @brief               This is the implementation file for SettingsApp class.
20  */
21
22 #include "StMainFrame.h"
23 #include "StSettingsApp.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::System;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Controls;
33 using namespace Tizen::Ui::Scenes;
34
35 static const wchar_t* APPCONTROL_OPERATION_ID_CONFIGURE_LOCATION = L"http://tizen.org/appcontrol/operation/configure/location";
36 static const wchar_t* APPCONTROL_OPERATION_ID_CONFIGURE_BLUETOOTH_VISIBILITY = L"http://tizen.org/appcontrol/operation/configure/bluetooth/visibility";
37 static const wchar_t* APPCONTROL_OPERATION_ID_CONFIGURE_FONT_TYPE = L"http://tizen.org/appcontrol/operation/configure/font/type";
38 static const wchar_t* APPCONTROL_OPERATION_ID_CONFIGURE_FONT_SIZE = L"http://tizen.org/appcontrol/operation/configure/font/size";
39
40 typedef struct _catetory_list {
41         String category;
42         const wchar_t* sceneName;
43 }CATEGORY_LIST;
44
45 enum _appControlExtraKey
46 {
47         APPCONTROL_EXTRA_KEY_LOCATION_GPS = 0,
48         APPCONTROL_EXTRA_KEY_LOCATION_WPS,
49         APPCONTROL_EXTRA_KEY_BLUETOOTH_VISIBILITY,
50         APPCONTROL_EXTRA_KEY_FONT_TYPE,
51         APPCONTROL_EXTRA_KEY_FONT_SIZE,
52         APPCONTROL_EXTRA_KEY_MAX
53 };
54
55 CATEGORY_LIST extraDataKeyList[APPCONTROL_EXTRA_KEY_MAX] = {
56         { L"http://tizen.org/appcontrol/data/location/gps",             IDSCN_LOCATION  },
57         { L"http://tizen.org/appcontrol/data/location/wps",             IDSCN_LOCATION  },
58         { L"http://tizen.org/appcontrol/data/bluetooth/visibility", IDSCN_BLUETOOTH     },
59         { L"http://tizen.org/appcontrol/data/font/type",                        IDSCN_FONT              },
60         { L"http://tizen.org/appcontrol/data/font/size",                        IDSCN_FONT              }
61 };
62
63 SettingsApp::SettingsApp(void)
64         : __initialSceneId(IDSCN_MAIN_MENU)
65         , __pArgs(null)
66         , __requestId(0)
67 {
68 }
69
70 SettingsApp::~SettingsApp(void)
71 {
72 }
73
74 UiApp*
75 SettingsApp::CreateInstance(void)
76 {
77         return new (std::nothrow) SettingsApp();
78 }
79
80 bool
81 SettingsApp::OnAppInitializing(AppRegistry& appRegistry)
82 {
83         AppControlProviderManager* pProviderManager = AppControlProviderManager::GetInstance();
84         pProviderManager->SetAppControlProviderEventListener(this);
85
86         return true;
87 }
88
89 bool
90 SettingsApp::OnAppInitialized(void)
91 {
92         MainFrame* pSettingsFrame = new (std::nothrow) MainFrame();
93         pSettingsFrame->Construct();
94         AddFrame(*pSettingsFrame);
95
96         return true;
97 }
98
99 bool
100 SettingsApp::OnAppWillTerminate(void)
101 {
102         return true;
103 }
104
105 bool
106 SettingsApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
107 {
108         AppControlProviderManager* pProviderManager = AppControlProviderManager::GetInstance();
109         pProviderManager->SetAppControlProviderEventListener(null);
110
111         return true;
112 }
113
114 void
115 SettingsApp::OnForeground(void)
116 {
117         AppLogDebug("Foreground");
118         Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
119         pCurrentForm->SendUserEvent(REFRESH_REQUEST_EVENT, null);
120 }
121
122 void
123 SettingsApp::OnBackground(void)
124 {
125         AppLogDebug("Background");
126         Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
127         pCurrentForm->SendUserEvent(BACK_GROUND_EVENT, null);
128 }
129
130 void
131 SettingsApp::OnLowMemory(void)
132 {
133         AppLogDebug("LowMemory");
134 }
135
136 void
137 SettingsApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
138 {
139         AppLogDebug("BatteryLevelChanged");
140 }
141
142 void
143 SettingsApp::OnScreenOn(void)
144 {
145         AppLogDebug("ScreenOn");
146 }
147
148 void
149 SettingsApp::OnScreenOff(void)
150 {
151         AppLogDebug("ScreenOff");
152 }
153
154 RequestId
155 SettingsApp::GetRequestId(void)
156 {
157         return __requestId;
158 }
159
160 Tizen::Ui::Scenes::SceneId
161 SettingsApp::GetInitialSceneId(void)
162 {
163         return __initialSceneId;
164 }
165
166 Tizen::Base::Collection::IList*
167 SettingsApp::GetArguments(void)
168 {
169         return __pArgs;
170 }
171
172 void
173 SettingsApp::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData,
174                                                                                 const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData)
175 {
176         AppLogDebug("ENTER");
177         if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE_LOCATION) == 0)
178         {
179                 AppLogDebug("operationId[%ls]", operationId.GetPointer());
180
181                 const wchar_t* pSceneName = null;
182                 ArrayList* pArgs = new (std::nothrow) ArrayList();
183                 pArgs->Construct();
184
185                 pSceneName = extraDataKeyList[APPCONTROL_EXTRA_KEY_LOCATION_GPS].sceneName;
186                 pArgs->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/location/gps"));
187
188                 if (pSceneName == null)
189                 {
190                         Terminate();
191                 }
192                 else
193                 {
194                         __pArgs = pArgs;
195                         __requestId = reqId;
196                         __initialSceneId = pSceneName;
197                 }
198         }
199         else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE_BLUETOOTH_VISIBILITY) == 0)
200         {
201                 AppLogDebug("operationId[%ls]", operationId.GetPointer());
202                 const wchar_t* pSceneName = null;
203                 ArrayList* pArgs = new (std::nothrow) ArrayList();
204                 pArgs->Construct();
205
206                 pSceneName = extraDataKeyList[APPCONTROL_EXTRA_KEY_BLUETOOTH_VISIBILITY].sceneName;
207                 pArgs->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/visibility"));
208
209                 if (pSceneName == null)
210                 {
211                         Terminate();
212                 }
213                 else
214                 {
215                         __pArgs = pArgs;
216                         __requestId = reqId;
217                         __initialSceneId = pSceneName;
218                 }
219         }
220         else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE_FONT_TYPE) == 0)
221         {
222                 const wchar_t* pSceneName = null;
223                 ArrayList* pArgs = new (std::nothrow) ArrayList();
224                 pArgs->Construct();
225
226                 pSceneName = extraDataKeyList[APPCONTROL_EXTRA_KEY_FONT_TYPE].sceneName;
227                 pArgs->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/font/type"));
228
229                 if (pSceneName == null)
230                 {
231                         Terminate();
232                 }
233                 else
234                 {
235                         __pArgs = pArgs;
236                         __requestId = reqId;
237                         __initialSceneId = pSceneName;
238                 }
239         }
240         else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE_FONT_SIZE) == 0)
241         {
242                 const wchar_t* pSceneName = null;
243                 ArrayList* pArgs = new (std::nothrow) ArrayList();
244                 pArgs->Construct();
245
246                 pSceneName = extraDataKeyList[APPCONTROL_EXTRA_KEY_FONT_TYPE].sceneName;
247                 pArgs->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/font/size"));
248
249                 if (pSceneName == null)
250                 {
251                         Terminate();
252                 }
253                 else
254                 {
255                         __pArgs = pArgs;
256                         __requestId = reqId;
257                         __initialSceneId = pSceneName;
258                 }
259         }
260         else
261         {
262                 if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/main"))
263                 {
264                         AppLogDebug("operationId is not main terminate");
265                         Terminate();
266                 }
267         }
268 }