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 "autopopup_configure_parser.h"
19 #include "main_entry_parser.h"
21 #include "xml_parser_utils.h"
24 AutoPopup_Configure_Parser* AutoPopup_Configure_Parser::m_instance = NULL;
26 AutoPopup_Configure_Parser::AutoPopup_Configure_Parser() {
27 memset((void*)&m_autopopup_configure, 0x00, sizeof(SclAutoPopupConfigure));
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;
35 AutoPopup_Configure_Parser::~AutoPopup_Configure_Parser() {
36 /* Let's create de-initializing function for this resource releasement */
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;
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;
50 if (m_autopopup_configure.label_type) {
51 xmlFree(m_autopopup_configure.label_type);
52 m_autopopup_configure.label_type = NULL;
56 AutoPopup_Configure_Parser* AutoPopup_Configure_Parser::get_instance() {
57 if (m_instance == NULL) {
58 m_instance = new AutoPopup_Configure_Parser();
64 AutoPopup_Configure_Parser::get_button_state_prop(const xmlNodePtr cur_node) {
65 assert(cur_node != NULL);
66 int button_state = -1;
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;
73 else if (equal_prop(cur_node, "button_state", "disabled")) {
74 button_state = BUTTON_STATE_DISABLED;
80 AutoPopup_Configure_Parser::get_content_displaymode(const xmlNodePtr cur_node) {
81 assert(cur_node != NULL);
83 SCLDisplayMode display_mode = DISPLAYMODE_PORTRAIT;
85 xmlChar* key = xmlNodeGetContent(cur_node);
87 if (0 == strcmp("landscape", (const char*)key)) {
88 display_mode = DISPLAYMODE_LANDSCAPE;
96 void AutoPopup_Configure_Parser::init() {
97 parsing_autopopup_configure();
100 void AutoPopup_Configure_Parser::parsing_background_color(const xmlNodePtr cur_node) {
101 assert(cur_node != NULL);
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);
108 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"g") ) {
109 m_autopopup_configure.bg_color.g = get_content_int(child_node);
111 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"b") ) {
112 m_autopopup_configure.bg_color.b = get_content_int(child_node);
114 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"a") ) {
115 m_autopopup_configure.bg_color.a = get_content_int(child_node);
118 child_node = child_node->next;
122 void AutoPopup_Configure_Parser::parsing_background_line_color(const xmlNodePtr cur_node) {
123 assert(cur_node != NULL);
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);
130 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"g") ) {
131 m_autopopup_configure.bg_line_color.g = get_content_int(child_node);
133 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"b") ) {
134 m_autopopup_configure.bg_line_color.b = get_content_int(child_node);
136 else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"a") ) {
137 m_autopopup_configure.bg_line_color.a = get_content_int(child_node);
140 child_node = child_node->next;
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;
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);
157 child_node = child_node->next;
161 void AutoPopup_Configure_Parser::parsing_button_size(const xmlNodePtr cur_node) {
162 assert(cur_node != NULL);
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);
171 child_node = child_node->next;
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;
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);;
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);;
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);;
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);;
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);;
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);;
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);;
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);;
208 child_node = child_node->next;
212 void AutoPopup_Configure_Parser::parsing_grab_area(const xmlNodePtr cur_node) {
213 assert(cur_node != NULL);
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);
220 else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"right") ) {
221 m_autopopup_configure.add_grab_right = get_content_int(child_node);
223 else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"top") ) {
224 m_autopopup_configure.add_grab_top = get_content_int(child_node);
226 else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"bottom") ) {
227 m_autopopup_configure.add_grab_bottom = get_content_int(child_node);
229 child_node = child_node->next;
233 void AutoPopup_Configure_Parser::parsing_autopopup_configure() {
237 char input_file[_POSIX_PATH_MAX] = {0};
238 Main_Entry_Parser::get_file_full_path(input_file, "autopopup_configure");
240 doc = xmlReadFile(input_file, NULL, 0);
242 printf("Could not load file.\n");
246 cur_node = xmlDocGetRootElement(doc);
247 if (cur_node == NULL) {
248 printf("empty document.\n");
252 if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)"autopopup_configure"))
254 printf("root name %s error!\n", cur_node->name);
259 cur_node = cur_node->xmlChildrenNode;
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;
266 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_color")) {
267 parsing_background_color(cur_node);
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);
272 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_line_color")) {
273 parsing_background_line_color(cur_node);
275 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_padding")) {
276 m_autopopup_configure.bg_padding = get_content_int(cur_node);
278 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"button_image_path")) {
279 parsing_button_image_path(cur_node);
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);
284 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"button_size")) {
285 parsing_button_size(cur_node);
287 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"button_spacing")) {
288 m_autopopup_configure.button_spacing = get_content_int(cur_node);
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;
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);
298 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"max_column")) {
299 m_autopopup_configure.max_column = get_content_int(cur_node);
301 else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"grab_area")) {
302 parsing_grab_area(cur_node);
305 cur_node = cur_node->next;
307 //print_default_configure_table();
311 PSclAutoPopupConfigure AutoPopup_Configure_Parser::get_autopopup_configure() {
312 return &m_autopopup_configure;
315 void AutoPopup_Configure_Parser::print_default_configure_table() {