2 * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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 <libxml/parser.h>
20 #include "magnifier_configure_parser.h"
22 #include "xml_parser_utils.h"
23 #include "simple_debug.h"
26 static SCLMagnifierStyle
27 get_content_magnifier_style(const xmlNodePtr cur_node) {
28 assert(cur_node != NULL);
30 SCLMagnifierStyle style = MAGNIFIER_STYLE_LABEL_ONLY;
32 xmlChar* key = xmlNodeGetContent(cur_node);
34 if (0 == strcmp("area_capture", (const char*)key)) {
35 style = MAGNIFIER_STYLE_SEL_AREA_CAPTURE;
43 class MagnifierConfigureParserImpl {
45 MagnifierConfigureParserImpl() {
46 memset((void*)&m_magnifier_configure, 0x00, sizeof(SclMagnifierWndConfigure));
49 ~MagnifierConfigureParserImpl() {
54 if (m_magnifier_configure.bg_image_path) {
55 xmlFree(m_magnifier_configure.bg_image_path);
56 m_magnifier_configure.bg_image_path = NULL;
58 if (m_magnifier_configure.bg_shift_image_path) {
59 xmlFree(m_magnifier_configure.bg_shift_image_path);
60 m_magnifier_configure.bg_shift_image_path = NULL;
62 if (m_magnifier_configure.bg_shift_lock_image_path) {
63 xmlFree(m_magnifier_configure.bg_shift_lock_image_path);
64 m_magnifier_configure.bg_shift_lock_image_path = NULL;
66 if (m_magnifier_configure.bg_long_key_image_path) {
67 xmlFree(m_magnifier_configure.bg_long_key_image_path);
68 m_magnifier_configure.bg_long_key_image_path = NULL;
70 if (m_magnifier_configure.label_type) {
71 xmlFree(m_magnifier_configure.label_type);
72 m_magnifier_configure.label_type = NULL;
74 for (int loop = 0; loop < MAX_WND_DECORATOR; loop++) {
75 if (m_magnifier_configure.decoration_image_path[loop]) {
76 xmlFree(m_magnifier_configure.decoration_image_path[loop]);
77 m_magnifier_configure.decoration_image_path[loop] = NULL;
81 memset((void*)&m_magnifier_configure, 0x00, sizeof(SclMagnifierWndConfigure));
84 int reload_magnifier_configure(const char* input_file) {
86 return parsing_magnifier_configure(input_file);
89 int parsing_magnifier_configure(const char* input_file) {
93 doc = xmlReadFile(input_file, NULL, 0);
95 SCLLOG(SclLog::DEBUG, "Could not load file: %s.", input_file);
99 cur_node = xmlDocGetRootElement(doc);
100 if (cur_node == NULL) {
101 SCLLOG(SclLog::DEBUG, "MagnifierConfigParser: empty document.\n");
105 if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)"magnifier_configure"))
107 SCLLOG(SclLog::DEBUG, "MagnifierConfigParser: root name error: %s\n!", (char *)cur_node->name);
112 cur_node = cur_node->xmlChildrenNode;
114 while (cur_node != NULL) {
115 if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"magnifier_style")) {
116 m_magnifier_configure.style = get_content_magnifier_style(cur_node);
117 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"width")) {
118 m_magnifier_configure.width = get_content_int(cur_node);
119 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"height")) {
120 m_magnifier_configure.height = get_content_int(cur_node);
121 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"label_area")) {
122 parsing_label_area(cur_node);
123 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"background_image_path")) {
124 parsing_background_images(cur_node);
125 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"use_window")) {
126 m_magnifier_configure.use_actual_window = get_content_bool(cur_node);
127 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"label_type")) {
128 xmlChar* temp = xmlNodeGetContent(cur_node);
129 m_magnifier_configure.label_type = (sclchar*)temp;
130 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"window_decorator")) {
131 get_prop_number(cur_node, "size", &(m_magnifier_configure.decoration_size));
132 parsing_window_decorator_image_path(cur_node);
133 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"padding")) {
134 parsing_padding_values(cur_node);
135 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)"show_shift_label")) {
136 m_magnifier_configure.show_shift_label = get_content_bool(cur_node);
138 cur_node = cur_node->next;
145 void parsing_label_area(const xmlNodePtr cur_node) {
146 assert(cur_node != NULL);
148 xmlNodePtr child_node = cur_node->xmlChildrenNode;
149 while (child_node != NULL) {
150 if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"left")) {
151 m_magnifier_configure.label_area_rect.left = get_content_int(child_node);
152 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"top")) {
153 m_magnifier_configure.label_area_rect.top = get_content_int(child_node);
154 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"right")) {
155 m_magnifier_configure.label_area_rect.right = get_content_int(child_node);
156 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"bottom")) {
157 m_magnifier_configure.label_area_rect.bottom = get_content_int(child_node);
160 child_node = child_node->next;
163 void parsing_background_images(const xmlNodePtr cur_node) {
164 assert(cur_node != NULL);
166 xmlNodePtr child_node = cur_node->xmlChildrenNode;
167 while (child_node != NULL) {
168 if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"image")) {
169 if (equal_prop(child_node, "state", "normal")) {
170 xmlChar* temp = xmlNodeGetContent(child_node);
171 m_magnifier_configure.bg_image_path = (sclchar *)temp;
172 } else if (equal_prop(child_node, "state", "shift")) {
173 xmlChar* temp = xmlNodeGetContent(child_node);
174 m_magnifier_configure.bg_shift_image_path = (sclchar *)temp;
175 } else if (equal_prop(child_node, "state", "lock")) {
176 xmlChar* temp = xmlNodeGetContent(child_node);
177 m_magnifier_configure.bg_shift_lock_image_path = (sclchar *)temp;
178 } else if (equal_prop(child_node, "state", "longkey")) {
179 xmlChar* temp = xmlNodeGetContent(child_node);
180 m_magnifier_configure.bg_long_key_image_path = (sclchar *)temp;
184 child_node = child_node->next;
187 void parsing_window_decorator_image_path(const xmlNodePtr cur_node) {
188 assert(cur_node != NULL);
189 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"window_decorator"));
190 xmlNodePtr child_node = cur_node->xmlChildrenNode;
192 while (child_node != NULL) {
193 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"image")) {
194 if (equal_prop(child_node, "direction", "top_left")) {
195 m_magnifier_configure.decoration_image_path[WND_DECORATOR_TOP_LEFT] = (sclchar *)xmlNodeGetContent(child_node);
196 } else if (equal_prop(child_node, "direction", "top_center")) {
197 m_magnifier_configure.decoration_image_path[WND_DECORATOR_TOP_CENTER] = (sclchar *)xmlNodeGetContent(child_node);
198 } else if (equal_prop(child_node, "direction", "top_right")) {
199 m_magnifier_configure.decoration_image_path[WND_DECORATOR_TOP_RIGHT] = (sclchar *)xmlNodeGetContent(child_node);
200 } else if (equal_prop(child_node, "direction", "middle_left")) {
201 m_magnifier_configure.decoration_image_path[WND_DECORATOR_MIDDLE_LEFT] = (sclchar *)xmlNodeGetContent(child_node);
202 } else if (equal_prop(child_node, "direction", "middle_center")) {
203 m_magnifier_configure.decoration_image_path[WND_DECORATOR_MIDDLE_CENTER] = (sclchar *)xmlNodeGetContent(child_node);
204 } else if (equal_prop(child_node, "direction", "middle_right")) {
205 m_magnifier_configure.decoration_image_path[WND_DECORATOR_MIDDLE_RIGHT] = (sclchar *)xmlNodeGetContent(child_node);
206 } else if (equal_prop(child_node, "direction", "bottom_left")) {
207 m_magnifier_configure.decoration_image_path[WND_DECORATOR_BOTTOM_LEFT] = (sclchar *)xmlNodeGetContent(child_node);
208 } else if (equal_prop(child_node, "direction", "bottom_center")) {
209 m_magnifier_configure.decoration_image_path[WND_DECORATOR_BOTTOM_CENTER] = (sclchar *)xmlNodeGetContent(child_node);
210 } else if (equal_prop(child_node, "direction", "bottom_right")) {
211 m_magnifier_configure.decoration_image_path[WND_DECORATOR_BOTTOM_RIGHT] = (sclchar *)xmlNodeGetContent(child_node);
214 child_node = child_node->next;
217 void parsing_padding_values(const xmlNodePtr cur_node) {
218 assert(cur_node != NULL);
220 xmlNodePtr child_node = cur_node->xmlChildrenNode;
221 while (child_node != NULL) {
222 if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"x")) {
223 m_magnifier_configure.padding_x = get_content_int(child_node);
224 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"y")) {
225 m_magnifier_configure.padding_y = get_content_int(child_node);
228 child_node = child_node->next;
231 SclMagnifierWndConfigure m_magnifier_configure;
234 MagnifierConfigParser::MagnifierConfigParser() {
235 m_impl = new MagnifierConfigureParserImpl;
238 MagnifierConfigParser::~MagnifierConfigParser() {
240 SCLLOG(SclLog::MESSAGE, "~MagnifierConfigParser() has called");
246 MagnifierConfigParser*
247 MagnifierConfigParser::get_instance() {
248 static MagnifierConfigParser instance;
253 MagnifierConfigParser::init(const char* file) {
254 return m_impl->parsing_magnifier_configure(file);
258 MagnifierConfigParser::reload(const char* file) {
259 return m_impl->reload_magnifier_configure(file);
262 PSclMagnifierWndConfigure
263 MagnifierConfigParser::get_magnifier_configure() {
264 return &m_impl->m_magnifier_configure;