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_SettingSpeechProvider.cpp
19 * @brief This is the implementation for the _SettingSpeechProvider class.
21 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
27 #include <FBase_StringConverter.h>
29 #include "FSys_SettingInfo.h"
30 #include "FSys_SettingSpeechProvider.h"
34 using namespace Tizen::App;
35 using namespace Tizen::App::Package;
36 using namespace Tizen::Base;
38 namespace Tizen { namespace System
41 static const wchar_t* _SPEECH_TTS_SCREEN = L"http://tizen.org/setting/speech.tts.screen";
42 static const wchar_t* _SPEECH_TTS_SCREEN_RATE = L"http://tizen.org/setting/speech.tts.screen.rate";
46 void operator()(char* pValue)
56 _SettingSpeechProvider::_SettingSpeechProvider()
58 int errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, SettingEventVConf, null);
61 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for screen reader speech rate change.");
64 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, SettingEventVConf, null);
67 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for screen reader change.");
71 _SettingSpeechProvider::~_SettingSpeechProvider()
73 int errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, SettingEventVConf);
76 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for screen reader speech rate change.");
79 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, SettingEventVConf);
82 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for screen reader change.");
88 _SettingSpeechProvider::GetValue(const String& key, bool& value)
91 result r = E_OBJ_NOT_FOUND;
92 if(key == _SPEECH_TTS_SCREEN)
94 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen reader.");
96 int current_value = 0;
97 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, ¤t_value);
98 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get VCONFKEY_SETAPPL_ACCESSIBILITY_TTS key.");
99 if(current_value == 0)
112 _SettingSpeechProvider::SetValueForPrivilegedKey(const String& key, bool value)
115 result r = E_OBJ_NOT_FOUND;
116 if(key == _SPEECH_TTS_SCREEN)
118 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen reader.");
121 int current_value = (int)value;
122 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, current_value);
123 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get VCONFKEY_SETAPPL_ACCESSIBILITY_TTS key.");
129 _SettingSpeechProvider::GetValue(const String& key, int& value)
132 result r = E_OBJ_NOT_FOUND;
133 if(key == _SPEECH_TTS_SCREEN_RATE)
135 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen reader.");
138 errorCode = vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, &value);
139 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE key.");
145 _SettingSpeechProvider::SetValue(const String& key, const int value)
148 result r = E_OBJ_NOT_FOUND;
149 if(key == _SPEECH_TTS_SCREEN_RATE)
151 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen reader.");
154 SysTryReturnResult(NID_SYS, value > -1 && value < 5, E_INVALID_ARG, "Required value[%d] is not valid.", value);
156 errorCode = vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, value);
157 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE key.");
163 _SettingSpeechProvider::HasKey(const String& key)
165 if(key == _SPEECH_TTS_SCREEN_RATE || key == _SPEECH_TTS_SCREEN)
173 _SettingSpeechProvider::SettingEventVConf(keynode_t* node, void* userData)
177 if(strcmp(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, vconf_keynode_get_name(node)) == 0)
179 settingKey.Append(_SPEECH_TTS_SCREEN_RATE);
181 else if(strcmp(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, vconf_keynode_get_name(node)) == 0)
183 settingKey.Append(_SPEECH_TTS_SCREEN);
190 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
191 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
193 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
194 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());