2 * Copyright 2012-2013 Samsung Electronics Co., Ltd.
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
8 * http://floralicense.org/license/
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.
18 #include "default_configure_parser.h"
19 #include "main_entry_parser.h"
21 #include "xml_parser_utils.h"
24 Default_Configure_Parser* Default_Configure_Parser::m_instance = NULL;
26 Default_Configure_Parser::Default_Configure_Parser() {
27 memset((void*)&m_default_configure, 0x00, sizeof(SclDefaultConfigure));
30 Default_Configure_Parser::~Default_Configure_Parser() {
31 /* Let's create de-initializing function for this resource releasement */
32 if (m_default_configure.input_mode) {
33 xmlFree(m_default_configure.input_mode);
34 m_default_configure.input_mode = NULL;
36 if (m_default_configure.input_mode) {
37 xmlFree(m_default_configure.input_mode);
38 m_default_configure.input_mode = NULL;
40 if (m_default_configure.image_file_base_path) {
41 xmlFree(m_default_configure.image_file_base_path);
42 m_default_configure.image_file_base_path = NULL;
46 Default_Configure_Parser* Default_Configure_Parser::get_instance() {
47 if (m_instance == NULL) {
48 m_instance = new Default_Configure_Parser();
53 void Default_Configure_Parser::init() {
54 parsing_default_configure();
57 void Default_Configure_Parser::parsing_touch_offset(const xmlNodePtr cur_node) {
58 assert(cur_node != NULL);
60 xmlNodePtr child_node = cur_node->xmlChildrenNode;
61 while (child_node!=NULL) {
62 if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"portrait") ) {
63 xmlNodePtr grandChildNode = child_node->xmlChildrenNode;
64 while (grandChildNode!=NULL) {
65 if (0 == xmlStrcmp(grandChildNode->name, (const xmlChar*)"x") ) {
66 m_default_configure.touch_offset[DISPLAYMODE_PORTRAIT].x = get_content_int(grandChildNode);
67 } else if (0 == xmlStrcmp(grandChildNode->name, (const xmlChar*)"y") ) {
68 m_default_configure.touch_offset[DISPLAYMODE_PORTRAIT].y = get_content_int(grandChildNode);
70 grandChildNode = grandChildNode->next;
72 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"landscape") ) {
73 xmlNodePtr grandChildNode = child_node->xmlChildrenNode;
74 while (grandChildNode!=NULL) {
75 if (0 == xmlStrcmp(grandChildNode->name, (const xmlChar*)"x") ) {
76 m_default_configure.touch_offset[DISPLAYMODE_LANDSCAPE].x = get_content_int(grandChildNode);
77 } else if (0 == xmlStrcmp(grandChildNode->name, (const xmlChar*)"y") ) {
78 m_default_configure.touch_offset[DISPLAYMODE_LANDSCAPE].y = get_content_int(grandChildNode);
80 grandChildNode = grandChildNode->next;
84 child_node = child_node->next;
88 void Default_Configure_Parser::parsing_dim_color(const xmlNodePtr cur_node) {
89 assert(cur_node != NULL);
91 xmlNodePtr child_node = cur_node->xmlChildrenNode;
92 while (child_node!=NULL) {
93 if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"r") ) {
94 m_default_configure.dim_color.r = get_content_int(child_node);
96 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"g") ) {
97 m_default_configure.dim_color.g = get_content_int(child_node);
99 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"b") ) {
100 m_default_configure.dim_color.b = get_content_int(child_node);
102 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"a") ) {
103 m_default_configure.dim_color.a = get_content_int(child_node);
106 child_node = child_node->next;
112 Default_Configure_Parser::get_content_display_mode(const xmlNodePtr cur_node) {
113 assert(cur_node != NULL);
115 SCLDisplayMode display_mode = DISPLAYMODE_PORTRAIT;
117 xmlChar* key = xmlNodeGetContent(cur_node);
119 if (0 == strcmp("landscape", (const char*)key)) {
120 display_mode = DISPLAYMODE_LANDSCAPE;
128 void Default_Configure_Parser::parsing_default_configure() {
132 char input_file[_POSIX_PATH_MAX] = {0};
133 Main_Entry_Parser::get_file_full_path(input_file, "default_configure");
135 doc = xmlReadFile(input_file, NULL, 0);
137 printf("Could not load file.\n");
141 cur_node = xmlDocGetRootElement(doc);
142 if (cur_node == NULL) {
143 printf("empty document.\n");
147 if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)"default_configure"))
149 printf("root name %s error!\n", cur_node->name);
154 cur_node = cur_node->xmlChildrenNode;
156 while (cur_node != NULL) {
157 if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"display")) {
158 m_default_configure.display_mode = get_content_display_mode(cur_node);
160 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"input_mode")) {
161 xmlChar* temp = xmlNodeGetContent(cur_node);
162 m_default_configure.input_mode = (sclchar *)temp;
164 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"base_screen_width")) {
165 m_default_configure.target_screen_width = get_content_int(cur_node);
167 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"base_screen_height")) {
168 m_default_configure.target_screen_height = get_content_int(cur_node);
170 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"image_file_base_path")) {
171 xmlChar* temp = xmlNodeGetContent(cur_node);
172 m_default_configure.image_file_base_path = (sclchar *)temp;
174 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_magnifier")) {
175 m_default_configure.use_magnifier_window = get_content_bool(cur_node);
177 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_autopopup")) {
178 m_default_configure.use_auto_popup = get_content_bool(cur_node);
180 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_zoomwindow")) {
181 m_default_configure.use_zoom_window = get_content_bool(cur_node);
183 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_error_sound")) {
184 m_default_configure.on_error_noti_send = get_content_bool(cur_node);
186 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_word_deletion")) {
187 m_default_configure.use_word_deletion = get_content_bool(cur_node);
189 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"touch_offset_level")) {
190 // Let's skip this item since it does not seem to be useful anymore
192 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"touch_offset")) {
193 // Let's skip this item since it does not seem to be useful anymore
194 parsing_touch_offset(cur_node);
196 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"default_sub_layout")) {
197 xmlChar* temp = xmlNodeGetContent(cur_node);
198 m_default_configure.default_sub_layout = (sclchar *)temp;
200 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"dim_use_window_flag")) {
201 m_default_configure.use_actual_dim_window = get_content_bool(cur_node);
203 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"dim_color")) {
204 parsing_dim_color(cur_node);
206 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_lazy_loading")) {
207 m_default_configure.use_lazy_loading = get_content_bool(cur_node);
209 cur_node = cur_node->next;
211 //print_default_configure_table();
215 PSclDefaultConfigure Default_Configure_Parser::get_default_configure() {
216 return &m_default_configure;
219 void Default_Configure_Parser::print_default_configure_table() {
220 printf("------------------\n");
221 printf("\tdisplay:\t%d\n", m_default_configure.display_mode);
222 printf("\tinputMode:\t%s\n", m_default_configure.input_mode);
223 printf("\tuse_magnifier:\t%d\n", m_default_configure.use_magnifier_window);
224 printf("\tuse_autopopup:\t%d\n", m_default_configure.use_auto_popup);
225 printf("\tuse_zoomwindow:\t%d\n", m_default_configure.use_zoom_window);
226 printf("\tuse_error_sound:\t%d\n", m_default_configure.use_zoom_window);
227 printf("\tuse_word_deletion:\t%d\n", m_default_configure.use_zoom_window);
228 printf("\ttouch_offset:\n");
229 printf("\\t\t\t%d %d %d %d\n",
230 m_default_configure.touch_offset[0].x, m_default_configure.touch_offset[0].y,
231 m_default_configure.touch_offset[1].x, m_default_configure.touch_offset[1].y);
232 printf("------------------\n");