Tizen 2.0 Release
[profile/ivi/libscl-ui.git] / sclres / sclres_manager.cpp
1 /*
2  * Copyright 2012-2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include "sclres_manager.h"
19 #include "xmlresource.h"
20 #include "binary_xmlresource.h"
21 #include <assert.h>
22 using namespace xmlresource;
23 using namespace binary_xmlresource;
24 using namespace sclres;
25 #include "put_record.h"
26
27 SclResParserManager* SclResParserManager::m_instance = NULL;
28 SclResParserManager::~SclResParserManager() {
29     if (m_cur)
30         delete m_cur;
31     m_cur = NULL;
32 }
33
34 SclResParserManager*
35 SclResParserManager::get_instance() {
36     if (m_instance == NULL) {
37         m_instance = new SclResParserManager();
38     }
39     return m_instance;
40 }
41
42 SclResParserManager::SclResParserManager() {
43     m_cur = NULL;
44 }
45
46 void
47 SclResParserManager::init(const SCLParserType parser_type, const char *entry_filepath) {
48     if (parser_type == SCL_PARSER_TYPE_XML) {
49         printf("Use text xml\n");
50         m_cur = XMLResource::get_instance();
51     }
52     else if (parser_type == SCL_PARSER_TYPE_BINARY_XML) {
53         printf("Use binary xml\n");
54         m_cur = BinXmlResource::get_instance();
55     }
56
57     /* Let's acquire the directory information from filepath */
58     std::string str = entry_filepath;
59     size_t found;
60     found = str.find_last_of("/\\");
61
62     std::string filepath = str.substr(0, found);
63     std::string filename = str.substr(found + 1);
64
65     //assert(m_cur != NULL);
66     if (m_cur != NULL) {
67         /* Assume the directory where the main entry file exists, is the default resource directory */
68         m_cur->set_resource_directory(filepath.c_str());
69         m_cur->init(filename.c_str());
70 #ifdef __SCL_TXT_DEBUG
71         put_autopopup_configure(PARSER, *(m_cur->get_autopopup_configure()));
72         put_default_configure(PARSER, *(m_cur->get_default_configure()));
73         put_input_mode_configure_table(PARSER, m_cur->get_input_mode_configure_table());
74         put_key_coordinate_frame(PARSER, m_cur->get_key_coordinate_pointer_frame());
75         put_label_properties_frame(PARSER, m_cur->get_label_properties_frame());
76         put_layout_table(PARSER, m_cur->get_layout_table());
77         put_magnifier_wnd_configure(PARSER, *(m_cur->get_magnifier_configure()));
78         put_modifier_decoration(PARSER, m_cur->get_modifier_decoration_table());
79         //put_nine_patch_info(PARSER, m_cur->get_nine_patch_file_list());
80 #endif
81     }
82 }
83
84 void
85 SclResParserManager::load(int layout_id) {
86     if (m_cur) {
87         m_cur->load(layout_id);
88     }
89 }
90
91 void
92 SclResParserManager::unload() {
93     if (m_cur) {
94         m_cur->unload();
95     }
96 }
97
98 bool
99 SclResParserManager::loaded(int layout_id) {
100     if (m_cur == NULL) return false;
101
102     return m_cur->loaded(layout_id);
103 }
104
105 PSclInputModeConfigure
106 SclResParserManager::get_input_mode_configure_table() {
107     if (m_cur == NULL) return NULL;
108
109     return m_cur->get_input_mode_configure_table();
110 }
111
112 PSclLayout
113 SclResParserManager::get_layout_table() {
114     if (m_cur == NULL) return NULL;
115
116     return m_cur->get_layout_table();
117 }
118
119 PSclLayoutKeyCoordinatePointerTable
120 SclResParserManager::get_key_coordinate_pointer_frame() {
121     if (m_cur == NULL) return NULL;
122
123     return m_cur->get_key_coordinate_pointer_frame();
124 }
125
126 PSclModifierDecoration
127 SclResParserManager::get_modifier_decoration_table() {
128     if (m_cur == NULL) return NULL;
129
130     return m_cur->get_modifier_decoration_table();
131 }
132
133 PSclLabelPropertiesTable
134 SclResParserManager::get_label_properties_frame() {
135     if (m_cur == NULL) return NULL;
136
137     return m_cur->get_label_properties_frame();
138 }
139
140 PSclDefaultConfigure
141 SclResParserManager::get_default_configure() {
142     if (m_cur == NULL) return NULL;
143
144     return m_cur->get_default_configure();
145 }
146
147 PSclAutoPopupConfigure
148 SclResParserManager::get_autopopup_configure() {
149     if (m_cur == NULL) return NULL;
150
151     return m_cur->get_autopopup_configure();
152 }
153
154 PSclMagnifierWndConfigure
155 SclResParserManager::get_magnifier_configure() {
156     if (m_cur == NULL) return NULL;
157
158     return m_cur->get_magnifier_configure();
159 }
160
161 const char*
162 SclResParserManager::get_resource_directory() {
163     if (m_cur == NULL) return NULL;
164
165     return m_cur->get_resource_directory();
166 }
167
168 int
169 SclResParserManager::get_inputmode_id(const char *name) {
170     if (m_cur == NULL) return -1;
171
172     return m_cur->get_inputmode_id(name);
173 }
174
175 const char*
176 SclResParserManager::get_inputmode_name(int id) {
177     if (m_cur == NULL) return NULL;
178
179     return m_cur->get_inputmode_name(id);
180 }
181
182 int
183 SclResParserManager::get_inputmode_size() {
184     if (m_cur == NULL) return 0;
185
186     return m_cur->get_inputmode_size();
187 }
188
189 int
190 SclResParserManager::get_layout_size() {
191     if (m_cur == NULL) return 0;
192
193     return m_cur->get_layout_size();
194 }
195
196 int
197 SclResParserManager::get_layout_id(const char *name) {
198     if (m_cur == NULL) return -1;
199
200     return m_cur->get_layout_id(name);
201 }
202
203 int
204 SclResParserManager::get_labelproperty_size() {
205     if (m_cur == NULL) return 0;
206
207     return m_cur->get_labelproperty_size();
208 }
209
210 int
211 SclResParserManager::get_modifier_decoration_id(const char *name) {
212     if (m_cur == NULL) return -1;
213
214     return m_cur->get_modifier_decoration_id(name);
215 }
216
217 bool
218 SclResParserManager::get_nine_patch_info(const char *filename, SclNinePatchInfo *info) {
219     if (m_cur == NULL) return false;
220
221     return m_cur->get_nine_patch_info(filename, info);
222 }
223
224 const char*
225 SclResParserManager::name() {
226     if (m_cur == NULL) return NULL;
227
228     return m_cur->name();
229 }