Merge "Flow control for DataControl" into tizen_2.1
[platform/framework/native/appfw.git] / src / system / FSys_SettingInfoImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FSys_SettingInfoImpl.cpp
20  * @brief               This is the implementation file for _SysSettingInfoImpl class.
21  */
22
23 #include <FBaseColArrayList.h>
24 #include <FBaseSysLog.h>
25
26 #include <FBase_NativeError.h>
27 #include <FSys_SettingInfoImpl.h>
28 #include "FSys_SettingClient.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Io;
34
35 namespace Tizen { namespace System
36 {
37 //IDs for IPC
38 static const int _SYSTEM_RESPONSE_DATA = 2;
39
40 //Reserved key
41 static const wchar_t* _SETTING_SCREEN_WALLPAPER = L"http://tizen.org/setting/screen.wallpaper";
42 static const wchar_t* _SETTING_SYSTEM_SOUND_VOLUME = L"SystemSoundVolume";
43 static const wchar_t* _SETTING_SOUND_SYSTEM_VOLUME= L"http://tizen.org/setting/sound.system.volume";
44 static const wchar_t* _SETTING_MEDIA_SOUND_VOLUME = L"MediaSoundVolume";
45 static const wchar_t* _SETTING_SOUND_MEDIA_VOLUME = L"http://tizen.org/setting/sound.media.volume";
46 static const wchar_t* _SETTING_RINGTONE_SOUND_VOLUME = L"RingtoneSoundVolume";
47 static const wchar_t* _SETTING_SOUND_RINGTONE = L"http://tizen.org/setting/sound.ringtone";
48 static const wchar_t* _SETTING_SOUND_RINGTONE_VOLUME = L"http://tizen.org/setting/sound.ringtone.volume";
49 static const wchar_t* _SETTING_NOTIFICATION_SOUND_VOLUME = L"NotificationSoundVolume";
50 static const wchar_t* _SETTING_SOUND_NOTIFICATION_VOLUME = L"http://tizen.org/setting/sound.notification.volume";
51
52 static _SettingClient* pSettingClient = null;
53
54 void
55 _SettingInfoImpl::InitSettingClient(void)
56 {
57         if(pSettingClient == null)
58         {
59                 pSettingClient =  _SettingClient::GetInstance();
60         }
61 }
62 result
63 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::String& value)
64 {
65         InitSettingClient();
66         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
67         return pSettingClient->GetValue(key, value);
68 }
69
70 result
71 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, int& value)
72 {
73         InitSettingClient();
74         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
75         return pSettingClient->GetValue(key, value);
76 }
77
78 result
79 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, long long& value)
80 {
81         InitSettingClient();
82         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
83         return pSettingClient->GetValue(key, value);
84 }
85
86 result
87 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, double& value)
88 {
89         InitSettingClient();
90         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
91         return pSettingClient->GetValue(key, value);
92 }
93
94 result
95 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, bool& value)
96 {
97         InitSettingClient();
98         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
99         return pSettingClient->GetValue(key, value);
100 }
101
102 result
103 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::UuId& value)
104 {
105         InitSettingClient();
106         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
107         return pSettingClient->GetValue(key, value);
108 }
109
110 result
111 _SettingInfoImpl::SetWallpaper(const Tizen::Base::String& filePath)
112 {
113         InitSettingClient();
114         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
115         result r = pSettingClient->SetValue(_SETTING_SCREEN_WALLPAPER, filePath);
116
117         if(r == E_INVALID_ARG)
118                 r = E_FILE_NOT_FOUND;
119         else if(r == E_OBJ_NOT_FOUND)
120                 r = E_SYSTEM;
121         else if(r == E_UNSUPPORTED_OPERATION)
122                 r = E_SYSTEM;
123
124         return r;
125 }
126
127 result
128 _SettingInfoImpl::GetValueForPrivilegedKey(const String& key, bool& value)
129 {
130         InitSettingClient();
131         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
132         return pSettingClient->GetValueForPrivilegedKey(key, value);
133 }
134
135 result
136 _SettingInfoImpl::SetValue(const String& key, bool value)
137 {
138         InitSettingClient();
139         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
140         return pSettingClient->SetValue(key, value);
141 }
142
143 result
144 _SettingInfoImpl::SetValue(const String& key, int value)
145 {
146         InitSettingClient();
147         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
148         return pSettingClient->SetValue(key, value);
149 }
150
151
152 result
153 _SettingInfoImpl::SetValue(const String& key, String value)
154 {
155         InitSettingClient();
156         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
157         return pSettingClient->SetValue(key, value);
158 }
159
160 result
161 _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, bool value)
162 {
163         InitSettingClient();
164         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
165         return pSettingClient->SetValueForPrivilegedKey(key, value);
166 }
167
168 result
169 _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, String value)
170 {
171         InitSettingClient();
172         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
173         return pSettingClient->SetValueForPrivilegedKey(key, value);
174 }
175
176 bool
177 _SettingInfoImpl::HasKey(const String& key)
178 {
179         InitSettingClient();
180         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
181         return pSettingClient->HasKey(key);
182 }
183 result
184 _SettingInfoImpl::ResetToFactoryDefault(void)
185 {
186         InitSettingClient();
187         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
188         return pSettingClient->ResetToFactoryDefault();
189 }
190
191 result
192 _SettingInfoImpl::SetRingtone(const Tizen::Base::String& filePath)
193 {
194         InitSettingClient();
195         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
196         result r = pSettingClient->SetValue(_SETTING_SOUND_RINGTONE, filePath);
197
198         if(r == E_INVALID_ARG)
199                 r = E_FILE_NOT_FOUND;
200         else if(r == E_OBJ_NOT_FOUND)
201                 r = E_SYSTEM;
202         else if(r == E_UNSUPPORTED_OPERATION)
203                 r = E_SYSTEM;
204
205         return r;
206 }
207
208 result
209 _SettingInfoImpl::SetVolume(const Tizen::Base::String& soundCategory, int level)
210 {
211         result r = E_SUCCESS;
212         String key;
213
214         InitSettingClient();
215         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
216
217         if (soundCategory == _SETTING_SYSTEM_SOUND_VOLUME)
218         {
219                 key = _SETTING_SOUND_SYSTEM_VOLUME;
220         }
221         else if (soundCategory == _SETTING_MEDIA_SOUND_VOLUME)
222         {
223                 key = _SETTING_SOUND_MEDIA_VOLUME;
224         }
225         else if (soundCategory == _SETTING_RINGTONE_SOUND_VOLUME)
226         {
227                 key = _SETTING_SOUND_RINGTONE_VOLUME;
228         }
229         else if (soundCategory == _SETTING_NOTIFICATION_SOUND_VOLUME)
230         {
231                 key = _SETTING_SOUND_NOTIFICATION_VOLUME;
232         }
233         else
234         {
235                 key = soundCategory;
236         }
237
238         r = pSettingClient->SetValue(key, level);
239
240         if (r == E_OBJ_NOT_FOUND)
241         {
242                 r = E_INVALID_ARG;
243         }
244         else if(r == E_INVALID_ARG)
245         {
246                 r = E_OUT_OF_RANGE;
247         }
248         else if(r == E_UNSUPPORTED_OPERATION)
249         {
250                 r = E_SYSTEM;
251         }
252         return r;
253 }
254
255 result
256 _SettingInfoImpl::AddSettingEventListener(ISettingEventListener& listener)
257 {
258         InitSettingClient();
259         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
260         return pSettingClient->AddSettingEventListener(listener);
261 }
262
263 result
264 _SettingInfoImpl::RemoveSettingEventListener(ISettingEventListener& listener)
265 {
266         InitSettingClient();
267         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
268         return pSettingClient->RemoveSettingEventListener(listener);
269 }
270
271 result
272 _SettingInfoImpl::AddSettingEventListenerForInternal(ISettingEventListener& listener)
273 {
274         InitSettingClient();
275         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
276         return pSettingClient->AddSettingEventListenerForInternal(listener);
277 }
278
279 result
280 _SettingInfoImpl::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
281 {
282         InitSettingClient();
283         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
284         return pSettingClient->RemoveSettingEventListenerForInternal(listener);
285 }
286
287 result
288 _SettingInfoImpl::SetSettingEventListener(ISettingEventListener* pListener)
289 {
290         InitSettingClient();
291         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
292         return pSettingClient->SetSettingEventListener(pListener);
293 }
294
295 result
296 _SettingInfoImpl::SetValueAsyncForPrivilegedKey(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
297 {
298         InitSettingClient();
299         SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
300         return pSettingClient->SetValueAsyncForPrivilegedKey(key, value, listener);
301 }
302
303 _SettingInfoImpl*
304 _SettingInfoImpl::GetInstance(SettingInfo& settinginfo)
305 {
306         return settinginfo.__pSettingInfoImpl;
307 }
308
309 const _SettingInfoImpl*
310 _SettingInfoImpl::GetInstance(const SettingInfo& settinginfo)
311 {
312         return settinginfo.__pSettingInfoImpl;
313 }
314
315 } } // Tizen::System