wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / SystemSetting / SystemSetting.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <Commons/Exception.h>
19 #include <CommonsJavaScript/Converter.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include "SystemSetting.h"
22 #include <netdb.h>
23 #include <arpa/inet.h>
24 #include <string.h>
25 #include <system_settings.h>
26 #include <Logger.h>
27
28 using namespace WrtDeviceApis::CommonsJavaScript;
29 using namespace WrtDeviceApis::Commons;
30 using namespace DPL;
31
32 namespace DeviceAPI {
33 namespace SystemSetting {
34     
35 SystemSetting::SystemSetting()
36 {
37 }
38
39 SystemSetting::~SystemSetting()
40 {
41 }
42
43 void SystemSetting::setWallpaper(const EventSetWallpaperPtr &event)
44 {
45     LoggerD("enter");
46     EventRequestReceiver<EventSetWallpaper>::PostRequest(event);
47 }
48
49 void SystemSetting::setRingtone(const EventSetRingtonePtr &event)
50 {
51     LoggerD("enter");
52     EventRequestReceiver<EventSetRingtone>::PostRequest(event);
53 }
54
55 void SystemSetting::setProperty(const EventSetSettingPtr &event)
56 {
57     LoggerD("enter");
58     EventRequestReceiver<EventSetSetting>::PostRequest(event);
59 }
60
61 void SystemSetting::getProperty(const EventGetSettingPtr &event)
62 {
63     LoggerD("enter");
64     EventRequestReceiver<EventGetSetting>::PostRequest(event);
65 }
66
67 std::string SystemSetting::getProperty(const SettingType settingType)
68 {
69         LoggerD("enter");
70         int ret = SYSTEM_SETTINGS_ERROR_NONE;
71
72         char *value = NULL;
73         std::string gettingValue;
74
75         if(settingType == HOME_SCREEN )
76         {
77                 LoggerD("home screen");
78                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
79                 LoggerD("result : " << ret << " value: "<< value);
80         }
81         else if(settingType == LOCK_SCREEN )
82         {
83                 LoggerD("lock screen");
84                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &value);
85                 LoggerD("result : " << ret << " value: "<< value);
86         }else if(settingType == INCOMMING_CALL )
87         {
88                 LoggerD("call");
89                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
90                 LoggerD("result : " << ret << " value: "<< value);
91         }
92         else if(settingType == NOTIFICATION_EMAIL )
93         {
94                 LoggerD("email");
95                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
96                 LoggerD("result : " << ret << " value: "<< value);
97         }
98
99
100         if(ret == SYSTEM_SETTINGS_ERROR_NONE)
101         {
102                 LoggerD("success");
103                 gettingValue = value;
104                 return value;
105         }
106         else
107         {
108                 LoggerD("PlatformException");
109                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "PlatformException");
110         }
111 }
112
113 void SystemSetting::OnRequestReceived(const EventSetWallpaperPtr &event)
114 {
115         LoggerD("enter");
116         int ret = SYSTEM_SETTINGS_ERROR_NONE;
117
118         std::string wallpaperUri = event->getWallpaperURI();
119         std::string wallpaperType = event->getWallpaperType();
120
121         if(strcmp(wallpaperType.c_str(), "HOME_SCREEN") == 0 )
122         {
123                 LoggerD("home screen : " << wallpaperUri.c_str());
124                 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, wallpaperUri.c_str());
125         }
126         else if(strcmp(wallpaperType.c_str(), "LOCK_SCREEN") == 0 )
127         {
128                 LoggerD("lock screen : " << wallpaperUri.c_str());
129                 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, wallpaperUri.c_str());
130         }
131
132         if(ret == SYSTEM_SETTINGS_ERROR_NONE)
133         {
134                 LoggerD("success");
135                 event->setExceptionCode(ExceptionCodes::None);
136         }
137         else
138         {
139                 LoggerD("PlatformException");
140                 event->setExceptionCode(ExceptionCodes::PlatformException);
141         }
142         LoggerD("end");
143 }
144
145 void SystemSetting::OnRequestReceived(const EventSetRingtonePtr &event)
146 {
147         LoggerD("enter");
148         int ret = SYSTEM_SETTINGS_ERROR_NONE;
149
150         std::string ringtoneUri = event->getRingtoneURI();
151         std::string ringtoneType = event->getRingtoneType();
152
153         if(strcmp(ringtoneType.c_str(), "INCOMING_CALL") == 0 )
154         {
155                 LoggerD("call  : " << ringtoneUri.c_str());
156                 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, ringtoneUri.c_str());
157         }
158         else if(strcmp(ringtoneType.c_str(), "NOTIFICATION_EMAIL") == 0 )
159         {
160                 // TODO need manage-api
161                 LoggerD("email  : " << ringtoneUri.c_str());
162                 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, ringtoneUri.c_str());
163         }
164
165         if(ret == SYSTEM_SETTINGS_ERROR_NONE)
166         {
167                 LoggerD("success");
168                 event->setExceptionCode(ExceptionCodes::None);
169         }
170         else
171         {
172                 LoggerD("PlatformException");
173                 event->setExceptionCode(ExceptionCodes::PlatformException);
174         }
175         LoggerD("end");
176 }
177
178 void SystemSetting::OnRequestReceived(const EventSetSettingPtr &event)
179 {
180         LoggerD("enter");
181         int ret = SYSTEM_SETTINGS_ERROR_NONE;
182
183         std::string settingValue = event->getSettingValue();
184         SettingType settingType = event->getSettingType();
185
186         if(settingType == HOME_SCREEN )
187         {
188                 LoggerD("home screen : " << settingValue.c_str());
189                 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, settingValue.c_str());
190                 LoggerD("result : " << ret);
191         }
192         else if(settingType == LOCK_SCREEN )
193         {
194                 LoggerD("lock screen : " << settingValue.c_str());
195                 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, settingValue.c_str());
196                 LoggerD("result : " << ret);
197         }else if(settingType == INCOMMING_CALL )
198         {
199                 LoggerD("call  : " << settingValue.c_str());
200                 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, settingValue.c_str());
201                 LoggerD("result : " << ret);
202         }
203         else if(settingType == NOTIFICATION_EMAIL )
204         {
205                 LoggerD("email  : " << settingValue.c_str());
206                 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, settingValue.c_str());
207                 LoggerD("result : " << ret);
208         }
209
210
211         if(ret == SYSTEM_SETTINGS_ERROR_NONE)
212         {
213                 LoggerD("success");
214                 event->setExceptionCode(ExceptionCodes::None);
215         }
216         else
217         {
218                 LoggerD("PlatformException");
219                 event->setExceptionCode(ExceptionCodes::PlatformException);
220         }
221         LoggerD("end");
222 }
223
224 void SystemSetting::OnRequestReceived(const EventGetSettingPtr &event)
225 {
226         LoggerD("enter");
227         int ret = SYSTEM_SETTINGS_ERROR_NONE;
228
229         std::string settingValue;
230         SettingType settingType = event->getSettingType();
231         char *value = NULL;
232
233         if(settingType == HOME_SCREEN )
234         {
235                 LoggerD("home screen");
236                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
237                 LoggerD("result : " << ret);
238         }
239         else if(settingType == LOCK_SCREEN )
240         {
241                 LoggerD("lock screen");
242                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &value);
243                 LoggerD("result : " << ret);
244         }else if(settingType == INCOMMING_CALL )
245         {
246                 LoggerD("call");
247                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
248                 LoggerD("result : " << ret);
249         }
250         else if(settingType == NOTIFICATION_EMAIL )
251         {
252                 LoggerD("email");
253                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
254                 LoggerD("result : " << ret);
255         }
256
257
258         if(ret == SYSTEM_SETTINGS_ERROR_NONE)
259         {
260                 LoggerD("success");
261                 event->setExceptionCode(ExceptionCodes::None);
262         }
263         else
264         {
265                 LoggerD("PlatformException");
266                 event->setExceptionCode(ExceptionCodes::PlatformException);
267         }
268
269         settingValue = value;
270         event->setSettingValue(settingValue);
271
272         LoggerD("end");
273 }
274
275
276 }
277 }