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.
23 #include <libxml/parser.h>
24 #include <libxml/tree.h>
25 #include <libxml/uri.h>
30 static xmlDocPtr configxml = NULL;
32 static xmlNodePtr next(xmlNodePtr node, const char *type)
34 while (node && node->type != XML_ELEMENT_NODE && strcmp(type, node->name))
39 static xmlNodePtr first(const char *type)
43 root = xmlDocGetRootElement(configxml);
45 return next(root->children, type);
50 static int scorelang(xmlNodePtr node)
52 char *lang = xmlNodeGetLang(node);
53 int score = locales_score(lang);
58 static xmlNodePtr element_based_localisation(const char *type)
60 xmlNodePtr resu, elem;
66 elem = next(resu->next, type);
73 elem = next(elem->next, type);
82 xmlFreeDoc(configxml);
91 fd = widget_open_read(_config_xml_);
93 syslog(LOG_ERR, "can't open config file %s", _config_xml_);
96 configxml = xmlReadFd(fd, "_config_xml_", NULL, 0);
98 if (configxml == NULL) {
99 syslog(LOG_ERR, "xml parse of config file %s failed", _config_xml_);
105 /* elements based on localisation */
106 xmlNodePtr confixml_name()
108 return element_based_localisation(_name_);
111 xmlNodePtr confixml_description()
113 return element_based_localisation(_description_);
116 xmlNodePtr confixml_license()
118 return element_based_localisation(_license_);
121 /* elements based on path localisation */
122 xmlNodePtr confixml_author()
124 return first(_author_);
127 xmlNodePtr confixml_content()
129 return first(_content_);
132 /* element multiple */
134 xmlNodePtr confixml_first_feature()
136 return first(_feature_);
139 xmlNodePtr confixml_next_feature(xmlNodePtr node)
141 return next(node->next, _feature_);
144 xmlNodePtr confixml_first_preference()
146 return first(_preference_);
149 xmlNodePtr confixml_next_preference(xmlNodePtr node)
151 return next(node->next, _preference_);
154 xmlNodePtr confixml_first_icon()
156 return first(_icon_);
159 xmlNodePtr confixml_next_icon(xmlNodePtr node)
161 return next(node->next, _icon_);
164 /* best sized icon */
166 static int score_dim(xmlNodePtr ref, xmlNodePtr x, const char *dim, int request)
171 sref = xmlGetProp(ref, dim);
175 sx = xmlGetProp(x, dim);
199 sx = xmlGetProp(x, dim);
216 static int better_icon(xmlNodePtr ref, xmlNodePtr x, int width, int height)
218 int sw = score_dim(ref, x, _width_, width);
219 int sh = score_dim(ref, x, _height_, height);
223 xmlNodePtr confixml_icon(int width, int height)
225 xmlNodePtr resu, icon;
227 resu = confixml_first_icon();
228 icon = confixml_next_icon(resu);
230 if (better_icon(resu, icon, width, height))
232 icon = confixml_next_icon(icon);