X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgt-config.c;h=cf890efb51c3efe7a0361359bbbde3ccfad4016b;hb=7553044c59814c33763bb4b1c34664dceed68735;hp=77358fd1dbe07ceebbd758dbecdf1f6d2a74a327;hpb=63f8720a3e610c0dc37bda3138d2e8de98ec1a78;p=src%2Fapp-framework-main.git diff --git a/src/wgt-config.c b/src/wgt-config.c index 77358fd..cf890ef 100644 --- a/src/wgt-config.c +++ b/src/wgt-config.c @@ -1,5 +1,7 @@ /* - Copyright 2015 IoT.bzh + Copyright (C) 2015-2019 IoT.bzh + + author: José Bollo Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,7 +18,6 @@ #include #include -#include #include #include @@ -24,20 +25,10 @@ #include #include +#include "verbose.h" #include "wgt.h" #include "wgt-config.h" - -const char wgt_config_string_xml_file[] = "config.xml"; -const char wgt_config_string_name[] = "name"; -const char wgt_config_string_description[] = "description"; -const char wgt_config_string_author[] = "author"; -const char wgt_config_string_license[] = "license"; -const char wgt_config_string_icon[] = "icon"; -const char wgt_config_string_content[] = "content"; -const char wgt_config_string_feature[] = "feature"; -const char wgt_config_string_preference[] = "preference"; -const char wgt_config_string_width[] = "width"; -const char wgt_config_string_height[] = "height"; +#include "wgt-strings.h" static struct wgt *configwgt = NULL; @@ -45,26 +36,22 @@ static xmlDocPtr configxml = NULL; static xmlNodePtr next(xmlNodePtr node, const char *type) { - while (node && node->type != XML_ELEMENT_NODE && strcmp(type, node->name)) + while (node && (node->type != XML_ELEMENT_NODE || strcmp(type, node->name))) node = node->next; return node; } static xmlNodePtr first(const char *type) { - xmlNodePtr root; - if (configxml) { - root = xmlDocGetRootElement(configxml); - if (root) - return next(root->children, type); - } - return NULL; + assert(configxml); + assert(xmlDocGetRootElement(configxml)); + return next(xmlDocGetRootElement(configxml)->children, type); } -static int scorelang(xmlNodePtr node) +static unsigned int scorelang(xmlNodePtr node) { char *lang = xmlNodeGetLang(node); - int score = wgt_locales_score(configwgt, lang); + unsigned int score = wgt_locales_score(configwgt, lang); xmlFree(lang); return score; } @@ -72,13 +59,13 @@ static int scorelang(xmlNodePtr node) static xmlNodePtr element_based_localisation(const char *type) { xmlNodePtr resu, elem; - int sr, s; + unsigned int sr, s; resu = first(type); if (resu) { sr = scorelang(resu); elem = next(resu->next, type); - while (resu) { + while (elem) { s = scorelang(elem); if (s < sr) { resu = elem; @@ -103,78 +90,115 @@ int wgt_config_open(struct wgt *wgt) { int fd; assert(!configxml); - fd = wgt_open_read(wgt, wgt_config_string_xml_file); + fd = wgt_open_read(wgt, string_config_dot_xml); if (fd < 0) { - syslog(LOG_ERR, "can't open config file %s", wgt_config_string_xml_file); + ERROR("can't open config file %s", string_config_dot_xml); return fd; } - configxml = xmlReadFd(fd, wgt_config_string_xml_file, NULL, 0); + configxml = xmlReadFd(fd, string_config_dot_xml, NULL, 0); close(fd); if (configxml == NULL) { - syslog(LOG_ERR, "xml parse of config file %s failed", wgt_config_string_xml_file); + ERROR("xml parse of config file %s failed", string_config_dot_xml); return -1; } + assert(xmlDocGetRootElement(configxml)); configwgt = wgt; return 0; } +xmlNodePtr wgt_config_widget() +{ + xmlNodePtr root; + assert(configxml); + root = xmlDocGetRootElement(configxml); + return strcmp(string_widget, root->name) ? NULL : root; +} + /* elements based on localisation */ xmlNodePtr wgt_config_name() { - return element_based_localisation(wgt_config_string_name); + assert(configxml); + return element_based_localisation(string_name); } xmlNodePtr wgt_config_description() { - return element_based_localisation(wgt_config_string_description); + assert(configxml); + return element_based_localisation(string_description); } xmlNodePtr wgt_config_license() { - return element_based_localisation(wgt_config_string_license); + assert(configxml); + return element_based_localisation(string_license); } /* elements based on path localisation */ xmlNodePtr wgt_config_author() { - return first(wgt_config_string_author); + assert(configxml); + return first(string_author); } xmlNodePtr wgt_config_content() { - return first(wgt_config_string_content); + assert(configxml); + return first(string_content); } /* element multiple */ xmlNodePtr wgt_config_first_feature() { - return first(wgt_config_string_feature); + assert(configxml); + return first(string_feature); } xmlNodePtr wgt_config_next_feature(xmlNodePtr node) { - return next(node->next, wgt_config_string_feature); + assert(configxml); + assert(node); + return next(node->next, string_feature); } xmlNodePtr wgt_config_first_preference() { - return first(wgt_config_string_preference); + assert(configxml); + return first(string_preference); } xmlNodePtr wgt_config_next_preference(xmlNodePtr node) { - return next(node->next, wgt_config_string_preference); + assert(configxml); + assert(node); + return next(node->next, string_preference); } xmlNodePtr wgt_config_first_icon() { - return first(wgt_config_string_icon); + assert(configxml); + return first(string_icon); } xmlNodePtr wgt_config_next_icon(xmlNodePtr node) { - return next(node->next, wgt_config_string_icon); + assert(configxml); + assert(node); + return next(node->next, string_icon); +} + +xmlNodePtr wgt_config_first_param(xmlNodePtr node) +{ + assert(configxml); + assert(node); + return next(node->children, string_param); +} + +xmlNodePtr wgt_config_next_param(xmlNodePtr node) +{ + assert(configxml); + assert(node); + return next(node->next, string_param); } /* best sized icon */ @@ -229,21 +253,22 @@ static int score_dim(xmlNodePtr ref, xmlNodePtr x, const char *dim, int request) return r; } -static int better_icon(xmlNodePtr ref, xmlNodePtr x, int width, int height) +static int is_better_icon(xmlNodePtr ref, xmlNodePtr x, int width, int height) { - int sw = score_dim(ref, x, wgt_config_string_width, width); - int sh = score_dim(ref, x, wgt_config_string_height, height); + int sw = score_dim(ref, x, string_width, width); + int sh = score_dim(ref, x, string_height, height); return sw+sh < 0; } xmlNodePtr wgt_config_icon(int width, int height) { + assert(configxml); xmlNodePtr resu, icon; resu = wgt_config_first_icon(); icon = wgt_config_next_icon(resu); while (icon) { - if (better_icon(resu, icon, width, height)) + if (is_better_icon(resu, icon, width, height)) resu = icon; icon = wgt_config_next_icon(icon); }