2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FAppAppSetting.h
20 * @brief This is the header file for the %AppSetting class.
22 * This header file contains the declarations of the %AppSetting class.
25 #ifndef _FAPP_APP_SETTING_H_
26 #define _FAPP_APP_SETTING_H_
28 #include <FBaseTypes.h>
29 #include <FBaseString.h>
30 #include <FBaseObject.h>
31 #include <FAppTypes.h>
34 namespace Tizen { namespace Base { namespace Collection
40 namespace Tizen { namespace App
43 class IAppSettingEventListener;
47 * @brief This class manages an application's settings.
51 * @final This class is not intended for extension.
53 * The %AppSetting class lets an application to save or restore its settings.
56 * The following example demonstrates how to use the %AppSetting class.
60 * AppSettingForm::RefreshSetting(void)
62 * AppSetting* pAppSetting = AppSetting::GetInstance();
63 * AppAssert(pAppSetting);
65 * bool valueBool = false;
67 * const String strLn(L"\n");
71 * AppAssert(pAppSetting->GetValue(L"checkbox1", valueBool) == E_SUCCESS);
72 * settingText += L"checkbox1: ";
73 * settingText += strFalseTrue[valueBool ? 1 : 0];
74 * settingText += strLn;
76 * AppAssert(pAppSetting->GetValue(L"slider1", valueInt) == E_SUCCESS);
77 * settingText += L"slider1: ";
78 * settingText += Integer(valueInt).ToString();
79 * settingText += strLn;
81 * AppAssert(pAppSetting->GetValue(L"editbox1", valueString) == E_SUCCESS);
82 * settingText += L"editbox1: ";
83 * settingText += valueString;
84 * settingText += strLn;
89 * AppSettingForm::SetSettingValueSet1(void)
91 * AppSetting* pAppSetting = AppSetting::GetInstance();
92 * AppAssert(pAppSetting);
94 * AppAssert(pAppSetting->SetValue(L"checkbox1", false) == E_SUCCESS);
95 * AppAssert(pAppSetting->SetValue(L"slider1", 100) == E_SUCCESS);
96 * AppAssert(pAppSetting->SetValue(L"editbox1", String(L"AppSetting working!")) == E_SUCCESS);
97 * AppAssert(pAppSetting->SetValue(L"expanditem1", String(L"1 minute")) == E_SUCCESS);
98 * AppAssert(pAppSetting->SetValue(L"expanditem1", false) == E_SUCCESS);
99 * AppAssert(pAppSetting->SetValue(L"slider2", 0) == E_SUCCESS);
100 * AppAssert(pAppSetting->SetValue(L"editbox2", String(L"AppSetting running!")) == E_SUCCESS);
106 class _OSP_EXPORT_ AppSetting
107 : public Tizen::Base::Object
111 * Gets the application setting instance.
115 * @return A pointer to the %AppSetting instance, @n
116 * else @c null if it fails
117 * @exception E_SUCCESS The method is successful.
118 * @exception E_OUT_OF_MEMORY The memory is insufficient.
119 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
120 * @remarks It returns an instance for the latest setting. @n
121 * The specific error code can be accessed using the GetLastResult() method.
123 static AppSetting* GetInstance(void);
126 * Gets the application setting instance of the specified version.
130 * @return A pointer to the %AppSetting instance, @n
131 * else @c null if it fails
132 * @param[in] settingVersion The version of setting is retrieved from GetAppSettingVersionListN()
133 * @exception E_SUCCESS The method is successful.
134 * @exception E_OBJ_NOT_FOUND The specified version is not found.
135 * @exception E_OUT_OF_MEMORY The memory is insufficient.
136 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
137 * @remarks The specific error code can be accessed using the GetLastResult() method.
138 * @see GetAppSettingVersionListN()
140 static AppSetting* GetInstance(const Tizen::Base::String& settingVersion);
143 * Gets the application setting instance of the specified AppId.
148 * @privilege %http://tizen.org/privilege/appsetting
150 * @return A pointer to the %AppSetting instance, @n
151 * else @c null if it fails
152 * @param[in] appId The AppId of the application that has a valid application setting
153 * @exception E_SUCCESS The method is successful.
154 * @exception E_OBJ_NOT_FOUND The instance of specified AppId does not have setting information.
155 * @exception E_OUT_OF_MEMORY The memory is insufficient.
156 * @exception E_INVALID_ARG The specified input parameter is invalid.
157 * @exception E_APP_NOT_INSTALLED The AppId is not found.
158 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
159 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
160 * @remarks The specific error code can be accessed using the GetLastResult() method.
161 * @see ReleaseInstanceByAppId()
163 static AppSetting* GetInstanceByAppId(const AppId& appId);
166 * Releases the specified application setting instance.
171 * @privilege %http://tizen.org/privilege/appsetting
173 * @return An error code
174 * @param[in] appId The AppId of the application that has a valid application setting
175 * @exception E_SUCCESS The method is successful.
176 * @exception E_OBJ_NOT_FOUND The specified instance of AppId is not found or already released.
177 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
178 * @remarks Individual instances are managed by the platform. @n
179 * It is recommended to release instances to reduce memory usage.
180 * @see GetInstanceByAppId()
182 static result ReleaseInstanceByAppId(const AppId& appId);
185 * Gets a list of all the versions that existed prior to the current version. @n
186 * The versions listed are based on the setting.xml file, which is generated when an application is installed.
190 * @return A pointer to the list that contains the Tizen::Base::String instances of version list
191 * @exception E_SUCCESS The method is successful.
192 * @exception E_OUT_OF_MEMORY The memory is insufficient.
193 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
194 * @remarks The latest version string is located in the first position.
195 * If the old version does not exist then return empty collection. @n
196 * The specific error code can be accessed using the GetLastResult() method.
198 static Tizen::Base::Collection::IList* GetAppSettingVersionListN(void);
201 * Gets a @c bool value associated with the specified @c id.
205 * @return An error code
206 * @param[in] id The ID of the value to retrieve
207 * @param[out] value A boolean value to retrieve
208 * @exception E_SUCCESS The method is successful.
209 * @exception E_OUT_OF_MEMORY The memory is insufficient.
210 * @exception E_OBJ_NOT_FOUND The specified @c id is not found in the application setting.
211 * @exception E_INVALID_ARG A specified input parameter is invalid.
212 * @exception E_TYPE_MISMATCH The operation has attempted to access different types.
214 result GetValue(const Tizen::Base::String& id, bool& value) const;
217 * Gets an integer value associated with the specified @c id.
221 * @return An error code
222 * @param[in] id The ID of the value to retrieve
223 * @param[out] value An integer value to retrieve
224 * @exception E_SUCCESS The method is successful.
225 * @exception E_OUT_OF_MEMORY The memory is insufficient.
226 * @exception E_OBJ_NOT_FOUND The specified @c id is not found in the application setting.
227 * @exception E_INVALID_ARG A specified input parameter is invalid.
228 * @exception E_TYPE_MISMATCH The operation has attempted to access different types.
230 result GetValue(const Tizen::Base::String& id, int& value) const;
233 * Gets a string value associated with the specified @c id.
237 * @return An error code
238 * @param[in] id The id of the value to retrieve
239 * @param[out] value A string value to retrieve
240 * @exception E_SUCCESS The method is successful.
241 * @exception E_OUT_OF_MEMORY The memory is insufficient.
242 * @exception E_OBJ_NOT_FOUND The specified @c id is not found in the application setting.
243 * @exception E_INVALID_ARG A specified input parameter is invalid.
244 * @exception E_TYPE_MISMATCH The operation has attempted to access different types.
246 result GetValue(const Tizen::Base::String& id, Tizen::Base::String& value) const;
249 * Sets a @c bool value associated with the specified @c id.
253 * @return An error code
254 * @param[in] id The ID of the value to modify
255 * @param[in] value A boolean value
256 * @exception E_SUCCESS The method is successful.
257 * @exception E_OUT_OF_MEMORY The memory is insufficient.
258 * @exception E_OBJ_NOT_FOUND The specified @c id is not found in the application setting.
259 * @exception E_INVALID_ARG A specified input parameter is invalid.
260 * @exception E_TYPE_MISMATCH The operation has attempted to access different types.
261 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
263 result SetValue(const Tizen::Base::String& id, bool value);
266 * Sets an integer value associated with the specified @c id.
270 * @return An error code
271 * @param[in] id The ID of the value to modify
272 * @param[in] value An integer value
273 * @exception E_SUCCESS The method is successful.
274 * @exception E_OUT_OF_MEMORY The memory is insufficient.
275 * @exception E_OBJ_NOT_FOUND The specified @c id is not found in the application setting.
276 * @exception E_OUT_OF_RANGE The specified @c value is out of range.
277 * @exception E_INVALID_ARG A specified input parameter is invalid.
278 * @exception E_TYPE_MISMATCH The operation has attempted to access different types.
279 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
281 result SetValue(const Tizen::Base::String& id, int value);
284 * Sets a string value associated with the specified @c id.
288 * @return An error code
289 * @param[in] id The ID of the value to modify
290 * @param[in] value A string value
291 * @exception E_SUCCESS The method is successful.
292 * @exception E_OUT_OF_MEMORY The memory is insufficient.
293 * @exception E_OBJ_NOT_FOUND The specified @c id is not found in the application setting.
294 * @exception E_OUT_OF_RANGE The specified string length is out of range.
295 * @exception E_INVALID_ARG A specified input parameter is invalid.
296 * @exception E_TYPE_MISMATCH The operation has attempted to access different types.
297 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
299 result SetValue(const Tizen::Base::String& id, const Tizen::Base::String& value);
302 * Sets a setting event listener.
306 * @return An error code
307 * @param[in] pListener An instance of IAppSettingEventListener to set, @n
308 * else @c null to clear a previous one
309 * @exception E_SUCCESS The method is successful.
311 result SetAppSettingEventListener(IAppSettingEventListener* pListener);
315 * This default constructor is intentionally declared as private to implement the Singleton semantic.
322 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
326 AppSetting(const AppSetting& rhs);
329 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
333 AppSetting& operator =(const AppSetting& rhs);
336 * This destructor is intentionally declared as private to implement the Singleton semantic.
340 virtual ~AppSetting(void);
342 static void InitSingleton(void);
343 static void DestroySingleton(void);
346 friend class _AppSettingImpl;
347 class _AppSettingImpl* __pAppSettingImpl;
348 static AppSetting* __pAppSettingInstance;
353 #endif // _FAPP_APP_SETTING_H_