Apply string localization for web
[platform/framework/native/appfw.git] / src / system-server / setting / providers / FSys_SettingSpeechProvider.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FSys_SettingSpeechProvider.cpp
19  * @brief       This is the implementation for the _SettingSpeechProvider class.
20  */
21 #include <unique_ptr.h>
22
23 #include <FApp.h>
24 #include <FBase.h>
25 #include <FBaseSysLog.h>
26
27 #include <FBase_StringConverter.h>
28
29 #include "FSys_SettingInfo.h"
30 #include "FSys_SettingSpeechProvider.h"
31
32 using namespace std;
33
34 using namespace Tizen::App;
35 using namespace Tizen::App::Package;
36 using namespace Tizen::Base;
37
38 namespace Tizen { namespace System
39 {
40
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";
43
44 struct charDeleter
45 {
46         void operator()(char* pValue)
47         {
48                 if(pValue != null)
49                 {
50                         free(pValue);
51                         pValue = null;
52                 }
53         }
54 };
55
56 _SettingSpeechProvider::_SettingSpeechProvider()
57 {
58         int errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, SettingEventVConf, null);
59         if(errorCode != 0)
60         {
61                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for screen reader speech rate change.");
62         }
63
64         errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, SettingEventVConf, null);
65         if(errorCode != 0)
66         {
67                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for screen reader change.");
68         }
69 }
70
71 _SettingSpeechProvider::~_SettingSpeechProvider()
72 {
73         int errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, SettingEventVConf);
74         if(errorCode != 0)
75         {
76                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for screen reader speech rate change.");
77         }
78
79         errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, SettingEventVConf);
80         if(errorCode != 0)
81         {
82                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for screen reader change.");
83         }
84
85 }
86
87 result
88 _SettingSpeechProvider::GetValue(const String& key, bool& value)
89 {
90         int errorCode = 0;
91         result r = E_OBJ_NOT_FOUND;
92         if(key == _SPEECH_TTS_SCREEN)
93         {
94                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen reader.");
95                 r = E_SUCCESS;
96                 int current_value = 0;
97                 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &current_value);
98                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get VCONFKEY_SETAPPL_ACCESSIBILITY_TTS key.");
99                 if(current_value == 0)
100                 {
101                         value = false;
102                 }
103                 else
104                 {
105                         value = true;
106                 }
107         }
108         return r;
109 }
110
111 result
112 _SettingSpeechProvider::SetValueForPrivilegedKey(const String& key, bool value)
113 {
114         int errorCode = 0;
115         result r = E_OBJ_NOT_FOUND;
116         if(key == _SPEECH_TTS_SCREEN)
117         {
118                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen reader.");
119                 r = E_SUCCESS;
120
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.");
124         }
125         return r;
126 }
127
128 result
129 _SettingSpeechProvider::GetValue(const String& key, int& value)
130 {
131         int errorCode = 0;
132         result r = E_OBJ_NOT_FOUND;
133         if(key == _SPEECH_TTS_SCREEN_RATE)
134         {
135                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen reader.");
136                 r = E_SUCCESS;
137
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.");
140         }
141         return r;
142 }
143
144 result
145 _SettingSpeechProvider::SetValue(const String& key, const int value)
146 {
147         int errorCode = 0;
148         result r = E_OBJ_NOT_FOUND;
149         if(key == _SPEECH_TTS_SCREEN_RATE)
150         {
151                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen reader.");
152                 r = E_SUCCESS;
153
154                 SysTryReturnResult(NID_SYS, value > -1 && value < 5, E_INVALID_ARG, "Required value[%d] is not valid.", value);
155
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.");
158         }
159         return r;
160 }
161
162 bool
163 _SettingSpeechProvider::HasKey(const String& key)
164 {
165         if(key == _SPEECH_TTS_SCREEN_RATE || key == _SPEECH_TTS_SCREEN)
166         {
167                 return true;
168         }
169         return false;
170 }
171
172 void
173 _SettingSpeechProvider::SettingEventVConf(keynode_t* node, void* userData)
174 {
175         String settingKey;
176
177         if(strcmp(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, vconf_keynode_get_name(node)) == 0)
178         {
179                 settingKey.Append(_SPEECH_TTS_SCREEN_RATE);
180         }
181         else if(strcmp(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, vconf_keynode_get_name(node)) == 0)
182         {
183                 settingKey.Append(_SPEECH_TTS_SCREEN);
184         }
185         else
186         {
187                 return;
188         }
189         
190         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
191         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
192
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());
195 }
196
197 }}