Tizen 2.0 Release
[profile/ivi/libscl-ui.git] / xmlresource / autopopup_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 "autopopup_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 AutoPopup_Configure_Parser* AutoPopup_Configure_Parser::m_instance = NULL;
25
26 AutoPopup_Configure_Parser::AutoPopup_Configure_Parser() {
27     memset((void*)&m_autopopup_configure, 0x00, sizeof(SclAutoPopupConfigure));
28
29     m_autopopup_configure.add_grab_left = NOT_USED;
30     m_autopopup_configure.add_grab_right = NOT_USED;
31     m_autopopup_configure.add_grab_top = NOT_USED;
32     m_autopopup_configure.add_grab_bottom= NOT_USED;
33 }
34
35 AutoPopup_Configure_Parser::~AutoPopup_Configure_Parser() {
36     /* Let's create de-initializing function for this resource releasement */
37     sclint loop;
38     for(loop = 0;loop < SCL_BUTTON_STATE_MAX;loop++) {
39         if (m_autopopup_configure.button_image_path[loop]) {
40             xmlFree(m_autopopup_configure.button_image_path[loop]);
41             m_autopopup_configure.button_image_path[loop] = NULL;
42         }
43     }
44     for(loop = 0;loop < MAX_WND_DECORATOR;loop++) {
45         if (m_autopopup_configure.decoration_image_path[loop]) {
46             xmlFree(m_autopopup_configure.decoration_image_path[loop]);
47             m_autopopup_configure.decoration_image_path[loop] = NULL;
48         }
49     }
50     if (m_autopopup_configure.label_type) {
51         xmlFree(m_autopopup_configure.label_type);
52         m_autopopup_configure.label_type = NULL;
53     }
54 }
55
56 AutoPopup_Configure_Parser* AutoPopup_Configure_Parser::get_instance() {
57     if (m_instance == NULL) {
58         m_instance = new AutoPopup_Configure_Parser();
59     }
60     return m_instance;
61 }
62
63 int
64 AutoPopup_Configure_Parser::get_button_state_prop(const xmlNodePtr cur_node) {
65     assert(cur_node != NULL);
66     int button_state = -1;
67
68     if (equal_prop(cur_node, "button_state", "pressed")) {
69         button_state = BUTTON_STATE_PRESSED;
70     } else if (equal_prop(cur_node, "button_state", "normal")) {
71         button_state = BUTTON_STATE_NORMAL;
72     }
73     else if (equal_prop(cur_node, "button_state", "disabled")) {
74         button_state = BUTTON_STATE_DISABLED;
75     }
76     return button_state;
77 }
78
79 SCLDisplayMode
80 AutoPopup_Configure_Parser::get_content_displaymode(const xmlNodePtr cur_node) {
81     assert(cur_node != NULL);
82
83     SCLDisplayMode display_mode = DISPLAYMODE_PORTRAIT;
84
85     xmlChar* key = xmlNodeGetContent(cur_node);
86     if (key!= NULL) {
87         if (0 == strcmp("landscape", (const char*)key)) {
88             display_mode = DISPLAYMODE_LANDSCAPE;
89         }
90         xmlFree(key);
91     }
92
93     return display_mode;
94 }
95
96 void AutoPopup_Configure_Parser::init() {
97     parsing_autopopup_configure();
98 }
99
100 void AutoPopup_Configure_Parser::parsing_background_color(const xmlNodePtr cur_node) {
101     assert(cur_node != NULL);
102
103     xmlNodePtr child_node = cur_node->xmlChildrenNode;
104     while (child_node!=NULL) {
105         if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"r") ) {
106             m_autopopup_configure.bg_color.r = get_content_int(child_node);
107         }
108         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"g") ) {
109             m_autopopup_configure.bg_color.g = get_content_int(child_node);
110         }
111         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"b") ) {
112             m_autopopup_configure.bg_color.b = get_content_int(child_node);
113         }
114         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"a") ) {
115             m_autopopup_configure.bg_color.a = get_content_int(child_node);
116         }
117
118         child_node = child_node->next;
119     }
120 }
121
122 void AutoPopup_Configure_Parser::parsing_background_line_color(const xmlNodePtr cur_node) {
123     assert(cur_node != NULL);
124
125     xmlNodePtr child_node = cur_node->xmlChildrenNode;
126     while (child_node!=NULL) {
127         if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"r") ) {
128             m_autopopup_configure.bg_line_color.r = get_content_int(child_node);
129         }
130         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"g") ) {
131             m_autopopup_configure.bg_line_color.g = get_content_int(child_node);
132         }
133         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"b") ) {
134             m_autopopup_configure.bg_line_color.b = get_content_int(child_node);
135         }
136         else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"a") ) {
137             m_autopopup_configure.bg_line_color.a = get_content_int(child_node);
138         }
139
140         child_node = child_node->next;
141     }
142 }
143
144 void
145 AutoPopup_Configure_Parser::parsing_button_image_path(const xmlNodePtr cur_node) {
146     assert(cur_node != NULL);
147     assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"button_image_path"));
148     xmlNodePtr child_node = cur_node->xmlChildrenNode;
149
150     while (child_node != NULL) {
151         if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"image") ) {
152             int button_state = get_button_state_prop(child_node);
153             if (button_state >= 0 && button_state < SCL_BUTTON_STATE_MAX) {
154                 m_autopopup_configure.button_image_path[button_state] = (sclchar*)xmlNodeGetContent(child_node);
155             }
156         }
157         child_node = child_node->next;
158     }
159 }
160
161 void AutoPopup_Configure_Parser::parsing_button_size(const xmlNodePtr cur_node) {
162     assert(cur_node != NULL);
163
164     xmlNodePtr child_node = cur_node->xmlChildrenNode;
165     while (child_node!=NULL) {
166         if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"width") ) {
167             m_autopopup_configure.button_width = get_content_int(child_node);
168         } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"height") ) {
169             m_autopopup_configure.button_height = get_content_int(child_node);
170         }
171         child_node = child_node->next;
172     }
173 }
174
175 void
176 AutoPopup_Configure_Parser::parsing_window_decorator_iamge_path(const xmlNodePtr cur_node) {
177     assert(cur_node != NULL);
178     assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"window_decorator"));
179     xmlNodePtr child_node = cur_node->xmlChildrenNode;
180
181     while (child_node != NULL) {
182         if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"image") ) {
183             if (equal_prop(cur_node, "direction", "top_left")) {
184                 m_autopopup_configure.decoration_image_path[WND_DECORATOR_TOP_LEFT] = (sclchar *)xmlNodeGetContent(cur_node);;
185             }
186             else if (equal_prop(cur_node, "direction", "top_center")) {
187                 m_autopopup_configure.decoration_image_path[WND_DECORATOR_TOP_CENTER] = (sclchar *)xmlNodeGetContent(cur_node);;
188             }
189             else if (equal_prop(cur_node, "direction", "top_right")) {
190                 m_autopopup_configure.decoration_image_path[WND_DECORATOR_TOP_RIGHT] = (sclchar *)xmlNodeGetContent(cur_node);;
191             }
192             else if (equal_prop(cur_node, "direction", "middle_left")) {
193                 m_autopopup_configure.decoration_image_path[WND_DECORATOR_MIDDLE_LEFT] = (sclchar *)xmlNodeGetContent(cur_node);;
194             }
195             else if (equal_prop(cur_node, "direction", "middle_right")) {
196                 m_autopopup_configure.decoration_image_path[WND_DECORATOR_MIDDLE_RIGHT] = (sclchar *)xmlNodeGetContent(cur_node);;
197             }
198             else if (equal_prop(cur_node, "direction", "bottom_left")) {
199                 m_autopopup_configure.decoration_image_path[WND_DECORATOR_BOTTOM_LEFT] = (sclchar *)xmlNodeGetContent(cur_node);;
200             }
201             else if (equal_prop(cur_node, "direction", "bottom_center")) {
202                 m_autopopup_configure.decoration_image_path[WND_DECORATOR_BOTTOM_CENTER] = (sclchar *)xmlNodeGetContent(cur_node);;
203             }
204             else if (equal_prop(cur_node, "direction", "bottom_right")) {
205                 m_autopopup_configure.decoration_image_path[WND_DECORATOR_BOTTOM_RIGHT] = (sclchar *)xmlNodeGetContent(cur_node);;
206             }
207         }
208         child_node = child_node->next;
209     }
210 }
211
212 void AutoPopup_Configure_Parser::parsing_grab_area(const xmlNodePtr cur_node) {
213     assert(cur_node != NULL);
214
215     xmlNodePtr child_node = cur_node->xmlChildrenNode;
216     while (child_node!=NULL) {
217         if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"left") ) {
218             m_autopopup_configure.add_grab_left = get_content_int(child_node);
219         }
220         else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"right") ) {
221             m_autopopup_configure.add_grab_right = get_content_int(child_node);
222         }
223         else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"top") ) {
224             m_autopopup_configure.add_grab_top = get_content_int(child_node);
225         }
226         else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"bottom") ) {
227             m_autopopup_configure.add_grab_bottom = get_content_int(child_node);
228         }
229         child_node = child_node->next;
230     }
231 }
232
233 void AutoPopup_Configure_Parser::parsing_autopopup_configure() {
234     xmlDocPtr doc;
235     xmlNodePtr cur_node;
236
237     char input_file[_POSIX_PATH_MAX] = {0};
238     Main_Entry_Parser::get_file_full_path(input_file, "autopopup_configure");
239
240     doc = xmlReadFile(input_file, NULL, 0);
241     if (doc == NULL) {
242         printf("Could not load file.\n");
243         exit(1);
244     }
245
246     cur_node = xmlDocGetRootElement(doc);
247     if (cur_node == NULL) {
248         printf("empty document.\n");
249         xmlFreeDoc(doc);
250         exit(1);
251     }
252     if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)"autopopup_configure"))
253     {
254         printf("root name %s error!\n", cur_node->name);
255         xmlFreeDoc(doc);
256         exit(1);
257     }
258
259     cur_node = cur_node->xmlChildrenNode;
260
261     while (cur_node != NULL) {
262         if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_image_path")) {
263             xmlChar* temp = xmlNodeGetContent(cur_node);
264             m_autopopup_configure.bg_image_path = (sclchar *)temp;
265         }
266         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_color")) {
267             parsing_background_color(cur_node);
268         }
269         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_line_width")) {
270             m_autopopup_configure.bg_line_width = get_content_int(cur_node);
271         }
272         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_line_color")) {
273             parsing_background_line_color(cur_node);
274         }
275         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_padding")) {
276             m_autopopup_configure.bg_padding = get_content_int(cur_node);
277         }
278         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"button_image_path")) {
279             parsing_button_image_path(cur_node);
280         }
281         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"sw_button_style")) {
282             m_autopopup_configure.sw_button_style = get_content_int(cur_node);
283         }
284         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"button_size")) {
285             parsing_button_size(cur_node);
286         }
287         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"button_spacing")) {
288             m_autopopup_configure.button_spacing = get_content_int(cur_node);
289         }
290         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"label_type")) {
291             xmlChar* temp = xmlNodeGetContent(cur_node);
292             m_autopopup_configure.label_type = (sclchar *)temp;
293         }
294         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"window_decorator")) {
295             get_prop_number(cur_node, "size", &(m_autopopup_configure.decoration_size));
296             parsing_window_decorator_iamge_path(cur_node);
297         }
298         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"max_column")) {
299             m_autopopup_configure.max_column = get_content_int(cur_node);
300         }
301         else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"grab_area")) {
302             parsing_grab_area(cur_node);
303         }
304
305         cur_node = cur_node->next;
306     }
307     //print_default_configure_table();
308     xmlFreeDoc(doc);
309 }
310
311 PSclAutoPopupConfigure AutoPopup_Configure_Parser::get_autopopup_configure() {
312     return &m_autopopup_configure;
313 }
314
315 void AutoPopup_Configure_Parser::print_default_configure_table() {
316
317 }