Add defensive codes for broken AppRegistry file
[platform/framework/native/appfw.git] / src / app / FApp_AppResourceImpl.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        FApp_AppResourceImpl.h
19  * @brief       This is the header file of the _AppResourceImpl class.
20  */
21
22 #ifndef _FAPP_INTERNAL_APP_RESOURCE_IMPL_H_
23 #define _FAPP_INTERNAL_APP_RESOURCE_IMPL_H_
24
25 #include <FBaseObject.h>
26 #include <FBaseString.h>
27
28 #include <FGrpBitmapCommon.h>
29
30 namespace Tizen { namespace Base { namespace Collection { class HashMap; } } }
31 namespace Tizen { namespace Graphics { class Bitmap; } }
32
33 namespace Tizen { namespace App
34 {
35
36 class AppResource;
37 class _AppResourceString;
38 class _IAppResourceBitmap;
39
40 enum AppResourceBy
41 {
42         APP_RESOURCE_DEFAULT,
43         APP_RESOURCE_BY_APP_ID,
44         APP_RESOURCE_BY_LIBRARY_NAME,
45         APP_RESOURCE_BITMAP
46 };
47
48 class _AppResourceImpl
49         : public Tizen::Base::Object
50 {
51 public:
52         /**
53         * This is the destructor for this class.
54         *
55         * @since                1.0
56         */
57         virtual ~_AppResourceImpl(void);
58
59         /**
60         * Gets the string at the specified resource ID.
61         *
62         * @since                1.0
63         * @return               An error code
64         * @param[in]    resourceId              The resource ID describing the String resource
65         * @param[out]   loadedString    The string obtained from the loaded application resource
66         * @exception    E_SUCCESS                                 The method was successful.
67         * @exception    E_FAILURE                       The argument passed is not found.
68         * @exception    E_INVALID_ARG                   The argument passed to a method contains an invalid resource ID.
69         */
70         result GetString(const Tizen::Base::String& resourceId, Tizen::Base::String& loadedString);
71
72         /**
73         * Gets the Bitmap at the specified path. @n
74         * This method interprets the given resource path and reads the best matching image file for the current device resolution. @n
75         * To load bitmap image from a file, you give the name of file as the input parameter not the file path (Ex: "img.png").
76         * Then, the system will first look for the image file in the folder specific to the current device resolution such as
77         * '320x480' and if the file does not exist, it will then search the folder that corresponds to the current screen density,
78         * such as 'ScreenDensity-Middle'. After searching density folder, all other density folders are searched in the order high to low.
79         * Currently supported image formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
80         *
81         * @since                1.1
82         *
83         * @return               A Bitmap instance generated from the specified file
84         * @param[in]    imagePath                               The relative path starting from the directory "/res/screen-density-XXX/", @n
85         *                                       where A and B represents the screen width and height of the supported device models, respectively.
86         * @param[in]    pixelFormat                             The pixel format of the resulting bitmap
87         * @exception    E_SUCCESS                               The method was successful.
88         * @exception    E_INVALID_ARG                   A specified input parameter is invalid.
89         * @exception    E_UNSUPPORTED_FORMAT    The image file format or specified pixel format is not supported.
90         * @exception    E_OUT_OF_MEMORY                 Insufficient memory.
91         * @exception    E_FILE_NOT_FOUND                The specified file could not be found.
92         * @exception    E_SYSTEM                                A system error occurred.
93         */
94         Tizen::Graphics::Bitmap* GetBitmapN(const Tizen::Base::String& imagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat);
95
96         /**
97         * Gets the Bitmap at the specified path. @n
98         * This method interprets the given resource path and reads the best matching image file for the current device resolution. @n
99         * To load bitmap image from a file, you give the name of file as the input parameter not the file path (Ex: "img.png").
100         * Then, the system will first look for the image file in the folder specific to the current device resolution such as
101         * '320x480' and if the file does not exist, it will then search the folder that corresponds to the current screen density,
102         * such as 'ScreenDensity-Middle'. After searching density folder, all other density folders are searched in the order high to low.
103         * Currently supported image formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
104         *
105         * In this method, the system decides the proper pixel format and whether to use chroma key composition to enable transparency. @n
106         * If the input image file has the alpha channel, the pixel format is set to Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888.
107         * Otherwise, the pixel format is set to BITMAP_PIXEL_FORMAT_RGB565 and the masking color of the bitmap is set to magenta, Tizen::Graphics::Color(255, 0, 255). @n
108         * Typically, a WVGA Tizen device would support alpha channel, while WQVGA device would support bitmap with masking color, to support transparency.
109         * You can place a 32-bit version of the resource and a 16-bit version in the WQVGA resource folder at the same folder. To distinguish the pixel format, you can use a postfix '@@16' such as 'image@@.bmp'.
110         * If you don't use postfix, this API would load the correct image and set the pixel format from the image file, that is appropriate for the current device. @n
111         * Currently supported image formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
112         *
113         * @since                1.1
114         *
115         * @return               A Bitmap instance generated from the specified file.
116         * @param[in]    imagePath                               The relative path starting from the density directory "/res/screen-density-XXX/", @n
117         *                                       where A and B represents the width and height of the screen of the supported device models, respectively
118         * @exception    E_SUCCESS                               The method was successful.
119         * @exception    E_INVALID_ARG                   A specified input parameter is invalid.
120         * @exception    E_UNSUPPORTED_FORMAT    The image file format is not supported.
121         * @exception    E_OUT_OF_MEMORY                 Insufficient memory.
122         * @exception    E_FILE_NOT_FOUND                The specified file could not be found.
123         * @exception    E_SYSTEM                                A system error occurred.
124         */
125         Tizen::Graphics::Bitmap* GetBitmapN(const Tizen::Base::String& imagePath);
126
127         static void Reinitialize(void);
128
129         /**
130         * Gets the AppResoruce instance pointer.
131         *
132         * @since  2.0
133         * @return An AppResoruce instance pointer, if successful @n
134         *                 @c null, if it fails
135         */
136         static _AppResourceImpl* GetInstance(void);
137
138         static AppResource* GetInstanceN(AppResourceBy type, const Tizen::Base::String& value = L"");
139         static _IAppResourceBitmap* Get_IAppResourceBitmapN(AppResourceBy type, const Tizen::Base::String& value = L"");
140
141         static void ReinitializeAll(void);
142         static result ReleaseInstance(const Tizen::Base::String& key);
143
144         static Tizen::Graphics::Bitmap* GetNonScalingBitmapN(const Tizen::Base::String& imagePath);
145 private:
146         /**
147         * This is the default constructor for this class.
148         *
149         * @since        1.0
150         */
151         _AppResourceImpl(void);
152
153         /**
154         * This is the copy constructor for this class.
155         *
156         * @since        1.0
157         */
158         _AppResourceImpl(const _AppResourceImpl& source);
159
160         /**
161          * This is the assignment operator for this class.
162          */
163         _AppResourceImpl& operator =(const _AppResourceImpl& source);
164
165         static void InitSingleton(void);
166         static void DestroySingleton(void);
167
168 private:
169         _AppResourceString* __p_AppResourceString;
170         _IAppResourceBitmap* __p_IAppResourceBitmap;
171
172         AppResourceBy __type;
173         Tizen::Base::String __value;
174
175         static Tizen::Base::Collection::HashMap* __pContainer;
176         static Tizen::Base::Runtime::Mutex* __pLock;
177 }; // _AppResourceImpl
178
179 } } // Tizen::App
180
181 #endif // _FAPP_INTERNAL_APP_RESOURCE_IMPL_H_