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_SettingFontProvider.cpp
19 * @brief This is the implementation for the _SettingFontProvider class.
22 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
28 #include <FBase_StringConverter.h>
30 #include "FSys_SettingInfo.h"
31 #include "FSys_SettingFontProvider.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Utility;
39 namespace Tizen { namespace System
42 static const wchar_t* _FONT_SIZE = L"http://tizen.org/setting/font.size";
43 static const wchar_t* _FONT_TYPE = L"http://tizen.org/setting/font.type";
45 static const wchar_t* _FONT_SIZE_GIANT = L"giant";
46 static const wchar_t* _FONT_SIZE_HUGE = L"huge";
47 static const wchar_t* _FONT_SIZE_LARGE = L"large";
48 static const wchar_t* _FONT_SIZE_MEDIUM = L"medium";
49 static const wchar_t* _FONT_SIZE_SMALL = L"small";
51 static const int _FONT_SIZE_GIANT_VCONF = 4;
52 static const int _FONT_SIZE_HUGE_VCONF = 3;
53 static const int _FONT_SIZE_LARGE_VCONF = 2;
54 static const int _FONT_SIZE_MEDIUM_VCONF = 1;
55 static const int _FONT_SIZE_SMALL_VCONF = 0;
59 void operator()(char* pValue)
70 _SettingFontProvider::HasKey(const Tizen::Base::String& key)
72 if(key == _FONT_SIZE || key == _FONT_TYPE)
80 _SettingFontProvider::_SettingFontProvider()
82 int errorCode = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE, SettingEventSettingInfo, null);
85 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register font type event listener");
88 errorCode = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, SettingEventSettingInfo, null);
91 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register font size event listener");
96 _SettingFontProvider::~_SettingFontProvider()
98 int errorCode = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
101 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister font size event listener");
104 errorCode = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE);
107 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister font type event listener");
112 _SettingFontProvider::GetValue(const String& key, String& value)
114 SysTryReturnResult(NID_SYS, 0, E_SYSTEM, "[E_SYSTEM] It is not working.");
115 result r = E_OBJ_NOT_FOUND;
117 if(key == _FONT_SIZE)
121 res = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &fontSize);
122 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to get font size.");
123 SysLog(NID_SYS, "current font size is %d.", fontSize);
128 case _FONT_SIZE_GIANT_VCONF:
129 value.Append(_FONT_SIZE_GIANT);
131 case _FONT_SIZE_HUGE_VCONF:
132 value.Append(_FONT_SIZE_HUGE);
134 case _FONT_SIZE_LARGE_VCONF:
135 value.Append(_FONT_SIZE_LARGE);
137 case _FONT_SIZE_MEDIUM_VCONF:
138 value.Append(_FONT_SIZE_MEDIUM);
140 case _FONT_SIZE_SMALL_VCONF:
141 value.Append(_FONT_SIZE_SMALL);
149 else if(key == _FONT_TYPE)
154 res = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &pTemp);
155 SysTryReturnResult(NID_SYS, pTemp != null, E_SYSTEM, "It is failed to get font type.");
157 unique_ptr<char, charDeleter> pFontType(pTemp);
158 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to get font type.");
159 SysLog(NID_SYS, "current font type is %s.", pTemp);
160 r = StringUtil::Utf8ToString(pFontType.get(), value);
161 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to convert font type to Utf8.");
168 _SettingFontProvider::SetValue(const String& key, const String value)
170 SysTryReturnResult(NID_SYS, 0, E_SYSTEM, "[E_SYSTEM] It is not working.");
171 result r = E_OBJ_NOT_FOUND;
173 if(key == _FONT_SIZE)
177 String lowerValue = value;
178 lowerValue.ToLowerCase();
181 if (lowerValue == _FONT_SIZE_GIANT)
183 fontSize = _FONT_SIZE_GIANT_VCONF;
185 else if (lowerValue == _FONT_SIZE_HUGE)
187 fontSize = _FONT_SIZE_HUGE_VCONF;
189 else if (lowerValue == _FONT_SIZE_LARGE)
191 fontSize = _FONT_SIZE_LARGE_VCONF;
193 else if (lowerValue == _FONT_SIZE_MEDIUM)
195 fontSize = _FONT_SIZE_MEDIUM_VCONF;
197 else if (lowerValue == _FONT_SIZE_SMALL)
199 fontSize = _FONT_SIZE_SMALL_VCONF;
203 return E_INVALID_ARG;
205 res = system_settings_set_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, fontSize);
206 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font size.");
208 else if(key == _FONT_TYPE)
213 unique_ptr<char []> pFontType(_StringConverter::CopyToCharArrayN(value));
214 SysTryReturnResult(NID_SYS, pFontType.get() != null, E_SYSTEM, "It is failed to convert String to string.");
215 SysLog(NID_SYS, "Requested font type is %s.", pFontType.get());
216 res = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, pFontType.get());
217 if(res == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
219 return E_INVALID_ARG;
221 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font type.");
227 _SettingFontProvider::SettingEventSettingInfo(system_settings_key_e key, void* userData)
229 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
230 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
236 case SYSTEM_SETTINGS_KEY_FONT_SIZE:
238 settingKey.Append(_FONT_SIZE);
241 case SYSTEM_SETTINGS_KEY_FONT_TYPE:
243 settingKey.Append(_FONT_TYPE);
248 SysLogException(NID_SYS, E_SYSTEM, "No required key[%d] is delivered", key);
253 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
254 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());