2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <Commons/Exception.h>
19 #include <CommonsJavaScript/Converter.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include "SystemSetting.h"
23 #include <arpa/inet.h>
25 #include <system_settings.h>
28 using namespace WrtDeviceApis::CommonsJavaScript;
29 using namespace WrtDeviceApis::Commons;
33 namespace SystemSetting {
35 SystemSetting::SystemSetting()
39 SystemSetting::~SystemSetting()
43 void SystemSetting::setWallpaper(const EventSetWallpaperPtr &event)
46 EventRequestReceiver<EventSetWallpaper>::PostRequest(event);
49 void SystemSetting::setRingtone(const EventSetRingtonePtr &event)
52 EventRequestReceiver<EventSetRingtone>::PostRequest(event);
55 void SystemSetting::setProperty(const EventSetSettingPtr &event)
58 EventRequestReceiver<EventSetSetting>::PostRequest(event);
61 void SystemSetting::getProperty(const EventGetSettingPtr &event)
64 EventRequestReceiver<EventGetSetting>::PostRequest(event);
67 std::string SystemSetting::getProperty(const SettingType settingType)
70 int ret = SYSTEM_SETTINGS_ERROR_NONE;
73 std::string gettingValue;
75 if(settingType == HOME_SCREEN )
77 LoggerD("home screen");
78 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
79 LoggerD("result : " << ret << " value: "<< value);
81 else if(settingType == LOCK_SCREEN )
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 )
89 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
90 LoggerD("result : " << ret << " value: "<< value);
92 else if(settingType == NOTIFICATION_EMAIL )
95 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
96 LoggerD("result : " << ret << " value: "<< value);
100 if(ret == SYSTEM_SETTINGS_ERROR_NONE)
103 gettingValue = value;
108 LoggerD("PlatformException");
109 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "PlatformException");
113 void SystemSetting::OnRequestReceived(const EventSetWallpaperPtr &event)
116 int ret = SYSTEM_SETTINGS_ERROR_NONE;
118 std::string wallpaperUri = event->getWallpaperURI();
119 std::string wallpaperType = event->getWallpaperType();
121 if(strcmp(wallpaperType.c_str(), "HOME_SCREEN") == 0 )
123 LoggerD("home screen : " << wallpaperUri.c_str());
124 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, wallpaperUri.c_str());
126 else if(strcmp(wallpaperType.c_str(), "LOCK_SCREEN") == 0 )
128 LoggerD("lock screen : " << wallpaperUri.c_str());
129 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, wallpaperUri.c_str());
132 if(ret == SYSTEM_SETTINGS_ERROR_NONE)
135 event->setExceptionCode(ExceptionCodes::None);
139 LoggerD("PlatformException");
140 event->setExceptionCode(ExceptionCodes::PlatformException);
145 void SystemSetting::OnRequestReceived(const EventSetRingtonePtr &event)
148 int ret = SYSTEM_SETTINGS_ERROR_NONE;
150 std::string ringtoneUri = event->getRingtoneURI();
151 std::string ringtoneType = event->getRingtoneType();
153 if(strcmp(ringtoneType.c_str(), "INCOMING_CALL") == 0 )
155 LoggerD("call : " << ringtoneUri.c_str());
156 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, ringtoneUri.c_str());
158 else if(strcmp(ringtoneType.c_str(), "NOTIFICATION_EMAIL") == 0 )
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());
165 if(ret == SYSTEM_SETTINGS_ERROR_NONE)
168 event->setExceptionCode(ExceptionCodes::None);
172 LoggerD("PlatformException");
173 event->setExceptionCode(ExceptionCodes::PlatformException);
178 void SystemSetting::OnRequestReceived(const EventSetSettingPtr &event)
181 int ret = SYSTEM_SETTINGS_ERROR_NONE;
183 std::string settingValue = event->getSettingValue();
184 SettingType settingType = event->getSettingType();
186 if(settingType == HOME_SCREEN )
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);
192 else if(settingType == LOCK_SCREEN )
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 )
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);
203 else if(settingType == NOTIFICATION_EMAIL )
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);
211 if(ret == SYSTEM_SETTINGS_ERROR_NONE)
214 event->setExceptionCode(ExceptionCodes::None);
218 LoggerD("PlatformException");
219 event->setExceptionCode(ExceptionCodes::PlatformException);
224 void SystemSetting::OnRequestReceived(const EventGetSettingPtr &event)
227 int ret = SYSTEM_SETTINGS_ERROR_NONE;
229 std::string settingValue;
230 SettingType settingType = event->getSettingType();
233 if(settingType == HOME_SCREEN )
235 LoggerD("home screen");
236 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
237 LoggerD("result : " << ret);
239 else if(settingType == LOCK_SCREEN )
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 )
247 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
248 LoggerD("result : " << ret);
250 else if(settingType == NOTIFICATION_EMAIL )
253 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
254 LoggerD("result : " << ret);
258 if(ret == SYSTEM_SETTINGS_ERROR_NONE)
261 event->setExceptionCode(ExceptionCodes::None);
265 LoggerD("PlatformException");
266 event->setExceptionCode(ExceptionCodes::PlatformException);
269 settingValue = value;
270 event->setSettingValue(settingValue);