Merge "Calling g_io_channel_set_close_on_unref() after crating channel" into tizen_2.1
[platform/framework/native/appfw.git] / inc / FAppAppResource.h
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                        FAppAppResource.h
20  * @brief                       This is the header file for the %AppResource class.
21  *
22  * This header file contains the declarations of the %AppResource class.
23  */
24
25 #ifndef _FAPP_APP_RESOURCE_H_
26 #define _FAPP_APP_RESOURCE_H_
27
28 #include <FBaseObject.h>
29 #include <FBaseString.h>
30 #include <FAppTypes.h>
31 #include <FGrpBitmapCommon.h>
32
33 namespace Tizen { namespace Graphics { class Bitmap; } }
34
35 namespace Tizen { namespace App
36 {
37
38 /**
39 * @class                AppResource
40 * @brief                This class provides convenient methods to load application resources at run time.
41 *
42 * @since        2.0
43 *
44 * @final        This class is not intended for extension.
45 *
46 * The %AppResource class provides convenient methods to load application resources at run time: @n
47 * - Use AppResource::GetString() to get handle and display localized strings.
48 * - Use AppResource::GetBitmapN() to obtain a bitmap image that matches the screen density.
49 * - If the matching image does not exist, the image of the baseline density folder, ScreenDensity-High is used.
50 *
51 * The instance of this class can be obtained through App::GetAppResource().
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 is not found.
108         * @exception    E_INVALID_ARG                   The argument passed to a 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         * Then, 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 of requested image file is nine-patch image saved as ".#.png" (For example : "img.#.png"),
121         * then a bitmap instance which is value of returned pointer is not pre-scaled.
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 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 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    The image file format or specified pixel format 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      The specific error code can be accessed using the GetLastResult() method.
137         * @remarks      There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is E_OUT_OF_MEMORY or not. For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
138         */
139         Tizen::Graphics::Bitmap* GetBitmapN(const Tizen::Base::String& imagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat) const;
140
141         /**
142         * Gets the bitmap at the specified path. @n
143         * The %GetBitmapN() method interprets the given resource path and reads the best matching image file for the current device resolution. @n
144         * 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").
145         * Then, the system will first look for the image file in the folder specific to the current device resolution, such as
146         * '720x1280' and if the file does not exist, it will then search the folder that corresponds to the current screen density,
147         * such as 'screen-density-xhigh'. After searching the density folder, all the other density folders are searched in the order high to low.
148         * 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.
149         * But in case of requested image file is nine-patch image saved as ".#.png" (For example : "img.#.png"),
150         * then a bitmap instance which is value of returned pointer is not pre-scaled.
151         * Currently supported image formats are: JPEG, GIF, PNG, BMP, TIFF, and WBMP.
152         * 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>
153         *
154         * @since        2.0
155         *
156         * @return       A pointer to the Tizen::Graphics::Bitmap instance generated from the specified file
157         * @param[in]    imagePath                               The relative path starting from the density directory @b "res/screen-density-XXX/" or @b "res/AxB", @n
158         *                                                                       where A and B represent the width and height of the screen of the supported device models, respectively
159         * @exception    E_SUCCESS                               The method is successful.
160         * @exception    E_INVALID_ARG                   The specified input parameter is invalid.
161         * @exception    E_UNSUPPORTED_FORMAT    The image file format is not supported.
162         * @exception    E_FILE_NOT_FOUND                The specified file cannot be found.
163         * @exception    E_SYSTEM                                A system error has occurred.
164         * @remarks      The specific error code can be accessed using the GetLastResult() method.
165         * @remarks      There is a high probability for an occurrence of an out-of-memory exception. If possible, check whether the exception is E_OUT_OF_MEMORY or not. For more information on how to handle the out-of-memory exception, refer <a href="../org.tizen.native.appprogramming/html/basics_tizen_programming/exception_check.htm">here</a>.
166         */
167         Tizen::Graphics::Bitmap* GetBitmapN(const Tizen::Base::String& imagePath) const;
168
169         /**
170         * Gets the %AppResource instance pointer.
171         *
172         * @since  2.0
173         *
174         * @return A pointer to the %AppResource instance, @n
175         *                 else @c null if it fails
176         */
177         static AppResource* GetInstance(void);
178
179         /**
180          * Gets the resource instance of the specified resource path.
181          * @since       2.0
182          * @return              A pointer to the %AppResource instance, @n
183          *                              else @c null if it fails
184          * @param[in]   resourcePath            The relative path starting from the resource directory path of the current application
185          * @exception   E_SUCCESS                       The method is successful.
186          * @exception   E_FILE_NOT_FOUND        The specified resource path does not exist.
187          * @exception   E_INVALID_ARG           The length of the specified path is @c 0 or exceeds system limitations.
188          * @exception   E_SYSTEM                        Initializing string and bitmap resource is failed due to system error.
189          * @remarks     The specific error code can be accessed using the GetLastResult() method.
190          */
191     static AppResource* LoadAppResource(const Tizen::Base::String& resourcePath);
192
193         /**
194         * Gets the application resource instance of the specified @c appId.
195         *
196         * @since        2.0
197         *
198         * @privlevel    platform
199         * @privilege   %http://tizen.org/privilege/appsetting
200         *
201         * @return       A pointer to the %AppResource instance, @n
202         *               else @c null if it fails
203         * @param[in]    appId                The AppId of the installed application
204         * @exception    E_SUCCESS            The method is successful.
205         * @exception    E_DATA_NOT_FOUND      The instance of specified @c appId does not provide the string resource.
206         * @exception    E_OUT_OF_MEMORY      The memory is insufficient.
207         * @exception    E_APP_NOT_INSTALLED  The specified @c appId is not found in the list of installed applications.
208         * @exception    E_SYSTEM        Initializing string and bitmap resource has failed due to a system error.
209         * @exception    E_PRIVILEGE_DENIED  The application does not have the privilege to call this method.
210         * @remarks The specific error code can be accessed using the GetLastResult() method.
211         */
212         static AppResource* GetInstanceByAppId(const AppId& appId);
213
214         /**
215         * Releases the application resource instance of the specified @c appId.
216         *
217         * @since        2.0
218         *
219         * @privlevel    platform
220         * @privilege   %http://tizen.org/privilege/appsetting
221         *
222         * @return       An error code
223         * @param[in]    appId                The AppId of the installed application
224         * @exception    E_SUCCESS            The method is successful.
225         * @exception    E_OBJ_NOT_FOUND      The application resource instance of the specified @c appId is not found.
226         * @exception    E_PRIVILEGE_DENIED  The application does not have the privilege to call this method.
227         * @remarks     Individual instances are managed by the platform. @n
228         *              It is recommended to release instances to reduce memory usage.
229         */
230         static result ReleaseInstanceByAppId(const AppId& appId);
231
232 private:
233         /**
234          * This default constructor is intentionally declared as private to implement the %Singleton semantic.
235          *
236          * @since       2.0
237          */
238         AppResource(void);
239
240         /**
241          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
242          *
243          * @since       2.0
244          */
245         AppResource(const AppResource& rhs);
246
247         /**
248          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
249          *
250          * @since       2.0
251          */
252         AppResource& operator =(const AppResource& rhs);
253
254         /**
255          * This destructor is intentionally declared as private to implement the %Singleton semantic.
256          *
257          * @since       2.0
258          */
259         virtual ~AppResource(void);
260
261 private:
262         friend class _AppResourceImpl;
263         class _AppResourceImpl* __pAppResourceImpl;
264 }; // AppResource
265
266 } } // Tizen::App
267
268 #endif