Enable build with iniparser v 3.1
[platform/framework/native/appfw.git] / inc / FAppAppResource.h
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        FAppAppResource.h
19  * @brief       This is the header file for the %AppResource class.
20  *
21  * This header file contains the declarations of the %AppResource class.
22  */
23
24 #ifndef _FAPP_APP_RESOURCE_H_
25 #define _FAPP_APP_RESOURCE_H_
26
27 #include <FBaseObject.h>
28 #include <FBaseString.h>
29 #include <FAppTypes.h>
30 #include <FGrpBitmapCommon.h>
31
32 namespace Tizen { namespace Graphics { class Bitmap; } }
33
34 namespace Tizen { namespace App
35 {
36
37 /**
38 * @class        AppResource
39 * @brief        This class provides convenient methods to load application resources at run time.
40 *
41 * @since        2.0
42 *
43 * @final        This class is not intended for extension.
44 *
45 * The %AppResource class provides convenient methods to load application resources at run time: @n
46 * - Use the AppResource::GetString() method to get a handle and display localized strings.
47 * - Use the AppResource::GetBitmapN() method to obtain a bitmap image that matches the screen density.
48 * - If a matching image does not exist, the image of the baseline density folder, ScreenDensity-High is used.
49 *
50 * The instance of this class can be obtained through the App::GetAppResource() method.
51 *
52 * The following example demonstrates how to use the %AppResource class to get strings.
53 *
54 * @code
55 #include <FApp.h>
56
57 using namespace Tizen::App;
58
59 void
60 MyClass::StringResourceSample(void)
61 {
62         String hello;
63         AppResource *pAppResource = App::GetInstance()->GetAppResource();
64         if (pAppResource)
65         {
66                 pAppResource->GetString(L"IDS_HELLO", hello);
67         }
68 }
69 * @endcode
70 *
71 *
72 *
73 * The following example demonstrates how to use the %AppResource class to retrieve bitmaps.
74 * @code
75 #include <FApp.h>
76
77 using namespace Tizen::App;
78 using namespace Tizen::Graphics;
79
80 void
81 MyClass::BitmapResourceSample(void)
82 {
83         AppResource *pAppResource = App::GetInstance()->GetAppResource();
84         Bitmap* pBitmap = null;
85
86         if (pAppResource)
87         {
88                 pBitmap = pAppResource->GetBitmapN(L"Tizen.png", BITMAP_PIXEL_FORMAT_ARGB8888);
89         }
90 }
91 * @endcode
92 */
93
94 class _OSP_EXPORT_ AppResource
95         : public Tizen::Base::Object
96 {
97 public:
98         /**
99         * Gets the string at the specified resource ID.
100         *
101         * @since        2.0
102         *
103         * @return               An error code
104         * @param[in]    resourceId              The resource ID of type Tizen::Base::String that describes the resource
105         * @param[out]   loadedString    The string obtained from the loaded application resource
106         * @exception    E_SUCCESS           The method is successful.
107         * @exception    E_FAILURE               The argument passed has not been found.
108         * @exception    E_INVALID_ARG   The argument passed to the method contains an invalid resource ID.
109         */
110         result GetString(const Tizen::Base::String& resourceId, Tizen::Base::String& loadedString) const;
111
112         /**
113         * Gets the bitmap at the specified path. @n
114         * The %GetBitmapN() method interprets the given resource path and reads the best matching image file for the current device resolution. @n
115         * To load the bitmap image from a file, give the name of the file as the input parameter and not the file path (For example, "img.png").
116         * The system will first look for the image file in the folder specific to the current device resolution, such as
117         * '720x1280' and if the file does not exist, it will then search the folder that corresponds to the current screen density,
118         * such as 'screen-density-xhigh'. After searching the density folder, all the other density folders are searched in the order high to low.
119         * If the requested image file is found in a density-specific folder that is different from the current screen density, the bitmap returned from this method is pre-scaled.
120         * But in case the requested image file is saved as ".#.png" (For example, "img.#.png"), then the bitmap instance of the returned pointer is not pre-scaled.
121         * So, it is recommended to use ".#.png" as the extension (For example, "ninePatchImg.#.png") for a nine-patch image file.
122         * Currently supported image formats are: JPEG, GIF, PNG, BMP, TIFF, and WBMP.
123         * For more information on the features, see <a href="../org.tizen.native.appprogramming/html/multiple_screen/autoscale_resource_fallback.htm">Resource Fallback and Prescaling.</a>
124         *
125         * @since        2.0
126         *
127         * @return               A pointer to the Tizen::Graphics::Bitmap instance generated from the specified file
128         * @param[in]    imagePath                               The relative path starting from the directory @b "res/screen-density-XXX/" or @b "res/AxB", @n
129         *                                                                               where A and B represent the screen width and screen height of the supported device models, respectively.
130         * @param[in]    pixelFormat                             The pixel format of the resulting bitmap
131         * @exception    E_SUCCESS                               The method is successful.
132         * @exception    E_INVALID_ARG                   A specified input parameter is invalid.
133         * @exception    E_UNSUPPORTED_FORMAT    Either the image file format or the specified @c pixelFormat is not supported.
134         * @exception    E_FILE_NOT_FOUND                The specified file cannot be found.
135         * @exception    E_SYSTEM                                A system error has occurred.
136         * @remarks      
137         *                       - The specific error code can be accessed using the GetLastResult() method.
138         *                       - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
139         *                       For more information on how to handle the out-of-memory exception, refer
140         *                       <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
141         */
142         Tizen::Graphics::Bitmap* GetBitmapN(const Tizen::Base::String& imagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat) const;
143
144         /**
145         * Gets the bitmap at the specified path. @n
146         * The %GetBitmapN() method interprets the given resource path and reads the best matching image file for the current device resolution. @n
147         * To load the bitmap image from a file, give the name of the file as the input parameter and not the file path (For example, "img.png").
148         * The system will first look for the image file in the folder specific to the current device resolution, such as
149         * '720x1280' and if the file does not exist, it will then search the folder that corresponds to the current screen density,
150         * such as 'screen-density-xhigh'. After searching the density folder, all the other density folders are searched in the order high to low.
151         * If the requested image file is found in a density-specific folder that is different from the current screen density, the bitmap returned from this method is pre-scaled.
152         * But in case the requested image file is saved as ".#.png" (For example, "img.#.png"), then the bitmap instance of the returned pointer is not pre-scaled.
153         * So, it is recommended to use ".#.png" as the extension (For example, "ninePatchImg.#.png") for a nine-patch image file.
154         * Currently supported image formats are: JPEG, GIF, PNG, BMP, TIFF, and WBMP.
155         * For more information on the features, see <a href="../org.tizen.native.appprogramming/html/multiple_screen/autoscale_resource_fallback.htm">Resource Fallback and Prescaling.</a>
156         *
157         * @since        2.0
158         *
159         * @return               A pointer to the Tizen::Graphics::Bitmap instance generated from the specified file
160         * @param[in]    imagePath                               The relative path starting from the density directory @b "res/screen-density-XXX/" or @b "res/AxB", @n
161         *                                                                               where A and B represent the screen width and screen height of the supported device models, respectively
162         * @exception    E_SUCCESS                               The method is successful.
163         * @exception    E_INVALID_ARG                   The specified input parameter is invalid.
164         * @exception    E_UNSUPPORTED_FORMAT    The image file format is not supported.
165         * @exception    E_FILE_NOT_FOUND                The specified file cannot be found.
166         * @exception    E_SYSTEM                                A system error has occurred.
167         * @remarks      
168         *                       - The specific error code can be accessed using the GetLastResult() method.
169         *                       - There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is @c E_OUT_OF_MEMORY or not.
170         *                       For more information on how to handle the out-of-memory exception, refer
171         *                       <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
172         */
173         Tizen::Graphics::Bitmap* GetBitmapN(const Tizen::Base::String& imagePath) const;
174
175         /**
176         * Gets a pointer to the %AppResource instance.
177         *
178         * @since        2.0
179         *
180         * @return       A pointer to the %AppResource instance, @n
181         *                       else @c null if it fails
182         */
183         static AppResource* GetInstance(void);
184
185         /**
186          * Gets an %AppResource instance of the specified @c resourcePath.
187          * @since               2.0
188          * @return              A pointer to the %AppResource instance, @n
189          *                              else @c null if it fails
190          * @param[in]   resourcePath            The relative path starting from the resource directory path of the current application
191          * @exception   E_SUCCESS                       The method is successful.
192          * @exception   E_FILE_NOT_FOUND        The specified @c resourcePath does not exist.
193          * @exception   E_INVALID_ARG           Either of the following conditions has occured:
194          *                                                              - The length of the specified path is @c 0.
195          *                                                              - The length of the specified path exceeds system limitations.
196          * @exception   E_SYSTEM                        Initializing the string and the bitmap resource has failed due to a system error.
197          * @remarks     The specific error code can be accessed using the GetLastResult() method.
198          */
199     static AppResource* LoadAppResource(const Tizen::Base::String& resourcePath);
200
201         /**
202         * Gets an %AppResource instance of the specified @c appId.
203         *
204         * @since        2.0
205         *
206         * @privlevel    platform
207         * @privilege    %http://tizen.org/privilege/appsetting
208         *
209         * @return       A pointer to the %AppResource instance, @n
210         *               else @c null if it fails
211         * @param[in]    appId                The ID of the installed application
212         * @exception    E_SUCCESS            The method is successful.
213         * @exception    E_DATA_NOT_FOUND     The specified @c appId does not provide the required string resource.
214         * @exception    E_OUT_OF_MEMORY      The memory is insufficient.
215         * @exception    E_APP_NOT_INSTALLED  The specified @c appId has not been found in the list of installed applications.
216         * @exception    E_SYSTEM                 Initializing the string and the bitmap resource has failed due to a system error.
217         * @exception    E_PRIVILEGE_DENIED   The application does not have the privilege to call this method.
218         * @remarks The specific error code can be accessed using the GetLastResult() method.
219         */
220         static AppResource* GetInstanceByAppId(const AppId& appId);
221
222         /**
223         * Releases the %AppResource instance of the specified @c appId.
224         *
225         * @since        2.0
226         *
227         * @privlevel   platform
228         * @privilege   %http://tizen.org/privilege/appsetting
229         *
230         * @return       An error code
231         * @param[in]    appId                The ID of the installed application
232         * @exception    E_SUCCESS            The method is successful.
233         * @exception    E_OBJ_NOT_FOUND      The application resource instance of the specified @c appId has not been found.
234         * @exception    E_PRIVILEGE_DENIED   The application does not have the privilege to call this method.
235         * @remarks
236         *                       - Individual instances are managed by the platform.
237         *                       - It is recommended to release instances to reduce memory usage.
238         */
239         static result ReleaseInstanceByAppId(const AppId& appId);
240
241 private:
242         /**
243          * This default constructor is intentionally declared as private to implement the %Singleton semantic.
244          *
245          * @since       2.0
246          */
247         AppResource(void);
248
249         /**
250          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
251          *
252          * @since       2.0
253          */
254         AppResource(const AppResource& rhs);
255
256         /**
257          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
258          *
259          * @since       2.0
260          */
261         AppResource& operator =(const AppResource& rhs);
262
263         /**
264          * This destructor is intentionally declared as private to implement the %Singleton semantic.
265          *
266          * @since       2.0
267          */
268         virtual ~AppResource(void);
269
270 private:
271         friend class _AppResourceImpl;
272         class _AppResourceImpl* __pAppResourceImpl;
273 }; // AppResource
274
275 } } // Tizen::App
276
277 #endif