Tizen 2.0 Release
[profile/ivi/libscl-ui.git] / xmlresource / default_configure_parser.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 "default_configure_parser.h"
19 #include "main_entry_parser.h"
20 #include <assert.h>
21 #include "xml_parser_utils.h"
22 using namespace std;
23
24 Default_Configure_Parser* Default_Configure_Parser::m_instance = NULL;
25
26 Default_Configure_Parser::Default_Configure_Parser() {
27     memset((void*)&m_default_configure, 0x00, sizeof(SclDefaultConfigure));
28 }
29
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;
35     }
36     if (m_default_configure.input_mode) {
37         xmlFree(m_default_configure.input_mode);
38         m_default_configure.input_mode = NULL;
39     }
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;
43     }
44 }
45
46 Default_Configure_Parser* Default_Configure_Parser::get_instance() {
47     if (m_instance == NULL) {
48         m_instance = new Default_Configure_Parser();
49     }
50     return m_instance;
51 }
52
53 void Default_Configure_Parser::init() {
54     parsing_default_configure();
55 }
56
57 void Default_Configure_Parser::parsing_touch_offset(const xmlNodePtr cur_node) {
58     assert(cur_node != NULL);
59
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);
69                 }
70                 grandChildNode = grandChildNode->next;
71             }
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);
79                 }
80                 grandChildNode = grandChildNode->next;
81             }
82         }
83
84         child_node = child_node->next;
85     }
86 }
87
88 void Default_Configure_Parser::parsing_dim_color(const xmlNodePtr cur_node) {
89     assert(cur_node != NULL);
90
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);
95         }
96         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"g") ) {
97             m_default_configure.dim_color.g = get_content_int(child_node);
98         }
99         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"b") ) {
100             m_default_configure.dim_color.b = get_content_int(child_node);
101         }
102         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"a") ) {
103             m_default_configure.dim_color.a = get_content_int(child_node);
104         }
105
106         child_node = child_node->next;
107     }
108 }
109
110
111 SCLDisplayMode
112 Default_Configure_Parser::get_content_display_mode(const xmlNodePtr cur_node) {
113     assert(cur_node != NULL);
114
115     SCLDisplayMode display_mode = DISPLAYMODE_PORTRAIT;
116
117     xmlChar* key = xmlNodeGetContent(cur_node);
118     if (key!= NULL) {
119         if (0 == strcmp("landscape", (const char*)key)) {
120             display_mode = DISPLAYMODE_LANDSCAPE;
121         }
122         xmlFree(key);
123     }
124
125     return display_mode;
126 }
127
128 void Default_Configure_Parser::parsing_default_configure() {
129     xmlDocPtr doc;
130     xmlNodePtr cur_node;
131
132     char input_file[_POSIX_PATH_MAX] = {0};
133     Main_Entry_Parser::get_file_full_path(input_file, "default_configure");
134
135     doc = xmlReadFile(input_file, NULL, 0);
136     if (doc == NULL) {
137         printf("Could not load file.\n");
138         exit(1);
139     }
140
141     cur_node = xmlDocGetRootElement(doc);
142     if (cur_node == NULL) {
143         printf("empty document.\n");
144         xmlFreeDoc(doc);
145         exit(1);
146     }
147     if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)"default_configure"))
148     {
149         printf("root name %s error!\n", cur_node->name);
150         xmlFreeDoc(doc);
151         exit(1);
152     }
153
154     cur_node = cur_node->xmlChildrenNode;
155
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);
159         }
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;
163         }
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);
166         }
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);
169         }
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;
173         }
174         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_magnifier")) {
175             m_default_configure.use_magnifier_window = get_content_bool(cur_node);
176         }
177         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_autopopup")) {
178             m_default_configure.use_auto_popup = get_content_bool(cur_node);
179         }
180         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_zoomwindow")) {
181             m_default_configure.use_zoom_window = get_content_bool(cur_node);
182         }
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);
185         }
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);
188         }
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
191         }
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);
195         }
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;
199         }
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);
202         }
203         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"dim_color")) {
204             parsing_dim_color(cur_node);
205         }
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);
208         }
209         cur_node = cur_node->next;
210     }
211     //print_default_configure_table();
212     xmlFreeDoc(doc);
213 }
214
215 PSclDefaultConfigure Default_Configure_Parser::get_default_configure() {
216     return &m_default_configure;
217 }
218
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");
233 }