2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSys_SettingInfoImpl.cpp
19 * @brief This is the implementation file for _SysSettingInfoImpl class.
21 #include <unique_ptr.h>
22 #include <system/system_settings.h>
24 #include <FBaseColArrayList.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseUtilStringUtil.h>
29 #include <FIo_FileImpl.h>
30 #include <FApp_AppInfo.h>
31 #include <FBase_StringConverter.h>
32 #include <FBase_NativeError.h>
33 #include <FSys_SettingInfoImpl.h>
35 #include "FSys_SettingClient.h"
39 using namespace Tizen::App;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Io;
43 using namespace Tizen::Base::Utility;
45 namespace Tizen { namespace System
48 static const wchar_t* _SETTING_SCREEN_WALLPAPER = L"http://tizen.org/setting/screen.wallpaper";
49 static const wchar_t* _SETTING_SYSTEM_SOUND_VOLUME = L"SystemSoundVolume";
50 static const wchar_t* _SETTING_SOUND_SYSTEM_VOLUME= L"http://tizen.org/setting/sound.system.volume";
51 static const wchar_t* _SETTING_MEDIA_SOUND_VOLUME = L"MediaSoundVolume";
52 static const wchar_t* _SETTING_SOUND_MEDIA_VOLUME = L"http://tizen.org/setting/sound.media.volume";
53 static const wchar_t* _SETTING_RINGTONE_SOUND_VOLUME = L"RingtoneSoundVolume";
54 static const wchar_t* _SETTING_SOUND_RINGTONE = L"http://tizen.org/setting/sound.ringtone";
55 static const wchar_t* _SETTING_SOUND_RINGTONE_VOLUME = L"http://tizen.org/setting/sound.ringtone.volume";
56 static const wchar_t* _SETTING_NOTIFICATION_SOUND_VOLUME = L"NotificationSoundVolume";
57 static const wchar_t* _SETTING_SOUND_NOTIFICATION_VOLUME = L"http://tizen.org/setting/sound.notification.volume";
60 static const wchar_t* _FONT_SIZE = L"http://tizen.org/setting/font.size";
61 static const wchar_t* _FONTSIZE = L"FontSize";
62 static const wchar_t* _FONT_TYPE = L"http://tizen.org/setting/font.type";
63 static const wchar_t* _FONTTYPE = L"FontType";
65 static const wchar_t* _FONT_SIZE_GIANT = L"giant";
66 static const wchar_t* _FONT_SIZE_HUGE = L"huge";
67 static const wchar_t* _FONT_SIZE_LARGE = L"large";
68 static const wchar_t* _FONT_SIZE_MEDIUM = L"medium";
69 static const wchar_t* _FONT_SIZE_SMALL = L"small";
71 static const int _FONT_SIZE_GIANT_VCONF = 4;
72 static const int _FONT_SIZE_HUGE_VCONF = 3;
73 static const int _FONT_SIZE_LARGE_VCONF = 2;
74 static const int _FONT_SIZE_MEDIUM_VCONF = 1;
75 static const int _FONT_SIZE_SMALL_VCONF = 0;
78 static _SettingClient* pSettingClient = null;
81 _SettingInfoImpl::InitSettingClient(void)
83 if(pSettingClient == null)
85 pSettingClient = _SettingClient::GetInstance();
89 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::String& value)
93 if (key == _FONT_SIZE || key == _FONT_TYPE || key == _FONTSIZE || key == _FONTTYPE)
96 if(tizenKey == _FONTSIZE)
98 tizenKey = _FONT_SIZE;
100 else if(tizenKey == _FONTTYPE)
102 tizenKey = _FONT_TYPE;
105 r = GetValueForFont(tizenKey, value);
109 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
111 if(value == _FONT_SIZE_GIANT || value == _FONT_SIZE_HUGE)
113 value = _FONT_SIZE_LARGE; //OSP not support giant or huge size of font.
121 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
122 r = pSettingClient->GetValue(key, value);
124 if(key == L"Wallpaper")
126 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
128 String physicalFilePath = value;
129 r = Tizen::Io::_FileImpl::ConvertPhysicalToVirtualPath(physicalFilePath, value);
130 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] It is failed to converting virtual path", GetErrorMessage(r));
138 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, int& value)
141 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
142 return pSettingClient->GetValue(key, value);
146 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, long long& value)
149 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
150 return pSettingClient->GetValue(key, value);
154 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, double& value)
157 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
158 return pSettingClient->GetValue(key, value);
162 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, bool& value)
165 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
166 return pSettingClient->GetValue(key, value);
170 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::UuId& value)
173 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
174 return pSettingClient->GetValue(key, value);
178 _SettingInfoImpl::SetWallpaper(const Tizen::Base::String& filePath)
181 result r = E_SUCCESS;
183 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
185 String physicalFilePath = filePath;
187 if(Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
189 r = Tizen::Io::_FileImpl::ConvertVirtualToPhysicalPath(filePath, physicalFilePath);
190 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] It is failed to converting physical path", GetErrorMessage(r));
193 r = pSettingClient->SetValue(_SETTING_SCREEN_WALLPAPER, physicalFilePath);
195 if(r == E_INVALID_ARG)
196 r = E_FILE_NOT_FOUND;
197 else if(r == E_OBJ_NOT_FOUND)
199 else if(r == E_UNSUPPORTED_OPERATION)
206 _SettingInfoImpl::GetValueForPrivilegedKey(const String& key, bool& value)
210 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
211 return pSettingClient->GetValueForPrivilegedKey(key, value);
215 _SettingInfoImpl::SetValue(const String& key, bool value)
218 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
219 return pSettingClient->SetValue(key, value);
223 _SettingInfoImpl::SetValue(const String& key, int value)
226 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
227 return pSettingClient->SetValue(key, value);
232 _SettingInfoImpl::SetValue(const String& key, String value)
234 result r = E_SUCCESS;
235 if (key == _FONT_SIZE || key == _FONT_TYPE)
237 r = SetValueForFont(key, value);
242 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
244 if(key == _SETTING_SCREEN_WALLPAPER)
246 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
248 String virtualFilePath = value;
249 r = Tizen::Io::_FileImpl::ConvertVirtualToPhysicalPath(virtualFilePath, value);
250 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] It is failed to converting physical path", GetErrorMessage(r));
253 return pSettingClient->SetValue(key, value);
259 _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, bool value)
262 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
263 return pSettingClient->SetValueForPrivilegedKey(key, value);
267 _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, String value)
270 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
271 return pSettingClient->SetValueForPrivilegedKey(key, value);
275 _SettingInfoImpl::HasKey(const String& key)
278 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
279 return pSettingClient->HasKey(key);
282 _SettingInfoImpl::ResetToFactoryDefault(void)
285 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
286 return pSettingClient->ResetToFactoryDefault();
290 _SettingInfoImpl::SetRingtone(const Tizen::Base::String& filePath)
292 result r = E_SUCCESS;
294 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
295 r = pSettingClient->SetValue(_SETTING_SOUND_RINGTONE, filePath);
297 if(r == E_INVALID_ARG)
298 r = E_FILE_NOT_FOUND;
299 else if(r == E_OBJ_NOT_FOUND)
301 else if(r == E_UNSUPPORTED_OPERATION)
308 _SettingInfoImpl::SetVolume(const Tizen::Base::String& soundCategory, int level)
310 result r = E_SUCCESS;
313 if (soundCategory == _SETTING_SYSTEM_SOUND_VOLUME)
315 key = _SETTING_SOUND_SYSTEM_VOLUME;
317 else if (soundCategory == _SETTING_MEDIA_SOUND_VOLUME)
319 key = _SETTING_SOUND_MEDIA_VOLUME;
321 else if (soundCategory == _SETTING_RINGTONE_SOUND_VOLUME)
323 key = _SETTING_SOUND_RINGTONE_VOLUME;
325 else if (soundCategory == _SETTING_NOTIFICATION_SOUND_VOLUME)
327 key = _SETTING_SOUND_NOTIFICATION_VOLUME;
335 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
336 r = pSettingClient->SetValue(key, level);
338 if (r == E_OBJ_NOT_FOUND)
342 else if(r == E_INVALID_ARG)
346 else if(r == E_UNSUPPORTED_OPERATION)
354 _SettingInfoImpl::AddSettingEventListener(ISettingEventListener& listener)
357 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
358 return pSettingClient->AddSettingEventListener(listener);
362 _SettingInfoImpl::RemoveSettingEventListener(ISettingEventListener& listener)
365 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
366 return pSettingClient->RemoveSettingEventListener(listener);
370 _SettingInfoImpl::AddSettingEventListenerForInternal(ISettingEventListener& listener)
373 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
374 return pSettingClient->AddSettingEventListenerForInternal(listener);
378 _SettingInfoImpl::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
381 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
382 return pSettingClient->RemoveSettingEventListenerForInternal(listener);
386 _SettingInfoImpl::SetSettingEventListener(ISettingEventListener* pListener)
389 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
390 return pSettingClient->SetSettingEventListener(pListener);
394 _SettingInfoImpl::SetValueAsync(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
397 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
398 return pSettingClient->SetValueAsync(key, value, listener);
402 _SettingInfoImpl::SetValueAsyncForPrivilegedKey(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
405 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
406 return pSettingClient->SetValueAsyncForPrivilegedKey(key, value, listener);
410 _SettingInfoImpl::GetInstance(SettingInfo& settinginfo)
412 return settinginfo.__pSettingInfoImpl;
415 const _SettingInfoImpl*
416 _SettingInfoImpl::GetInstance(const SettingInfo& settinginfo)
418 return settinginfo.__pSettingInfoImpl;
422 _SettingInfoImpl::GetValueForFont(const Tizen::Base::String& key, Tizen::Base::String& value)
424 result r = E_OBJ_NOT_FOUND;
426 if (key == _FONT_SIZE)
430 res = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &fontSize);
432 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to get font size.");
437 case _FONT_SIZE_GIANT_VCONF:
438 value.Append(_FONT_SIZE_GIANT);
440 case _FONT_SIZE_HUGE_VCONF:
441 value.Append(_FONT_SIZE_HUGE);
443 case _FONT_SIZE_LARGE_VCONF:
444 value.Append(_FONT_SIZE_LARGE);
446 case _FONT_SIZE_MEDIUM_VCONF:
447 value.Append(_FONT_SIZE_MEDIUM);
449 case _FONT_SIZE_SMALL_VCONF:
450 value.Append(_FONT_SIZE_SMALL);
458 else if (key == _FONT_TYPE)
461 char* pFontType = null;
463 res = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &pFontType);
464 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "Failed to get font type");
465 r = StringUtil::Utf8ToString(pFontType, value);
466 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::Utf8ToString failed", GetErrorMessage(r));
474 _SettingInfoImpl::SetValueForFont(const Tizen::Base::String& key, Tizen::Base::String value)
476 result r = E_OBJ_NOT_FOUND;
478 if(key == _FONT_SIZE)
482 String lowerValue = value;
483 lowerValue.ToLowerCase();
486 if (lowerValue == _FONT_SIZE_GIANT)
488 fontSize = _FONT_SIZE_GIANT_VCONF;
490 else if (lowerValue == _FONT_SIZE_HUGE)
492 fontSize = _FONT_SIZE_HUGE_VCONF;
494 else if (lowerValue == _FONT_SIZE_LARGE)
496 fontSize = _FONT_SIZE_LARGE_VCONF;
498 else if (lowerValue == _FONT_SIZE_MEDIUM)
500 fontSize = _FONT_SIZE_MEDIUM_VCONF;
502 else if (lowerValue == _FONT_SIZE_SMALL)
504 fontSize = _FONT_SIZE_SMALL_VCONF;
508 return E_INVALID_ARG;
510 res = system_settings_set_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, fontSize);
511 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font size.");
513 else if(key == _FONT_TYPE)
518 unique_ptr<char[]> pFontType(_StringConverter::CopyToCharArrayN(value));
519 SysTryReturnResult(NID_SYS, pFontType.get() != null, E_SYSTEM, "It is failed to convert String to string.");
520 SysLog(NID_SYS, "Requested font type is %s.", pFontType.get());
521 res = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, pFontType.get());
522 SysTryReturnResult(NID_SYS, res != SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, "It is not valid font type.");
523 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font type.");