/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * e-xml-utils.c * Copyright (C) 2000 Helix Code, Inc. * Author: Chris Lahey * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include #include "gal/util/e-i18n.h" #include #include #include #include #include #include "e-xml-utils.h" xmlNode * e_xml_get_child_by_name (const xmlNode *parent, const xmlChar *child_name) { xmlNode *child; g_return_val_if_fail (parent != NULL, NULL); g_return_val_if_fail (child_name != NULL, NULL); for (child = parent->childs; child != NULL; child = child->next) { if (xmlStrcmp (child->name, child_name) == 0) { return child; } } return NULL; } /* Returns the first child with the name child_name and the "lang" * attribute that matches the current LC_MESSAGES, or else, the first * child with the name child_name and no "lang" attribute. */ xmlNode * e_xml_get_child_by_name_by_lang (const xmlNode *parent, const xmlChar *child_name, const gchar *lang) { xmlNode *child; /* This is the default version of the string. */ xmlNode *C = NULL; g_return_val_if_fail (parent != NULL, NULL); g_return_val_if_fail (child_name != NULL, NULL); if (lang == NULL) { #ifdef HAVE_LC_MESSAGES lang = setlocale (LC_MESSAGES, NULL); #else lang = setlocale (LC_CTYPE, NULL); #endif } for (child = parent->childs; child != NULL; child = child->next) { if (xmlStrcmp (child->name, child_name) == 0) { xmlChar *this_lang = xmlGetProp (child, "lang"); if (this_lang == NULL) { C = child; } else if (xmlStrcmp(this_lang, "lang") == 0) { return child; } } } return C; } static xmlNode * e_xml_get_child_by_name_by_lang_list_with_score (const xmlNode *parent, const gchar *name, GList *lang_list, gint *best_lang_score) { xmlNodePtr best_node = NULL, node; for (node = parent->childs; node != NULL; node = node->next) { xmlChar *lang; if (node->name == NULL || strcmp (node->name, name) != 0) { continue; } lang = xmlGetProp (node, "xml:lang"); if (lang != NULL) { GList *l; gint i; for (l = lang_list, i = 0; l != NULL && i < *best_lang_score; l = l->next, i++) { if (strcmp ((gchar *) l->data, lang) == 0) { best_node = node; *best_lang_score = i; } } } else { if (best_node == NULL) { best_node = node; } } xmlFree (lang); if (*best_lang_score == 0) { return best_node; } } return best_node; } /* * e_xml_get_child_by_name_by_lang_list: * */ xmlNode * e_xml_get_child_by_name_by_lang_list (const xmlNode *parent, const gchar *name, GList *lang_list) { gint best_lang_score = INT_MAX; g_return_val_if_fail (parent != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); if (lang_list == NULL) { lang_list = gnome_i18n_get_language_list ("LC_MESSAGES"); } return e_xml_get_child_by_name_by_lang_list_with_score (parent, name, lang_list, &best_lang_score); } /* * e_xml_get_child_by_name_no_lang * */ xmlNode * e_xml_get_child_by_name_no_lang (const xmlNode *parent, const gchar *name) { xmlNodePtr node; g_return_val_if_fail (parent != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); for (node = parent->childs; node != NULL; node = node->next) { xmlChar *lang; if (node->name == NULL || strcmp (node->name, name) != 0) { continue; } lang = xmlGetProp (node, "xml:lang"); if (lang == NULL) { return node; } xmlFree (lang); } return NULL; } gint e_xml_get_integer_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) { g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); return e_xml_get_integer_prop_by_name_with_default (parent, prop_name, 0); } gint e_xml_get_integer_prop_by_name_with_default (const xmlNode *parent, const xmlChar *prop_name, gint def) { xmlChar *prop; gint ret_val = def; g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); prop = xmlGetProp ((xmlNode *) parent, prop_name); if (prop != NULL) { (void) sscanf (prop, "%d", &ret_val); xmlFree (prop); } return ret_val; } void e_xml_set_integer_prop_by_name (xmlNode *parent, const xmlChar *prop_name, gint value) { gchar *valuestr; g_return_if_fail (parent != NULL); g_return_if_fail (prop_name != NULL); valuestr = g_strdup_printf ("%d", value); xmlSetProp (parent, prop_name, valuestr); g_free (valuestr); } guint e_xml_get_uint_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) { g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); return e_xml_get_uint_prop_by_name_with_default (parent, prop_name, 0); } guint e_xml_get_uint_prop_by_name_with_default (const xmlNode *parent, const xmlChar *prop_name, guint def) { xmlChar *prop; guint ret_val = def; g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); prop = xmlGetProp ((xmlNode *) parent, prop_name); if (prop != NULL) { (void) sscanf (prop, "%u", &ret_val); xmlFree (prop); } return ret_val; } void e_xml_set_uint_prop_by_name (xmlNode *parent, const xmlChar *prop_name, guint value) { gchar *valuestr; g_return_if_fail (parent != NULL); g_return_if_fail (prop_name != NULL); valuestr = g_strdup_printf ("%u", value); xmlSetProp (parent, prop_name, valuestr); g_free (valuestr); } gboolean e_xml_get_bool_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) { g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); return e_xml_get_bool_prop_by_name_with_default (parent, prop_name, FALSE); } gboolean e_xml_get_bool_prop_by_name_with_default(const xmlNode *parent, const xmlChar *prop_name, gboolean def) { xmlChar *prop; gboolean ret_val = def; g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); prop = xmlGetProp ((xmlNode *) parent, prop_name); if (prop != NULL) { if (strcasecmp (prop, "true") == 0) { ret_val = TRUE; } else if (strcasecmp (prop, "false") == 0) { ret_val = FALSE; } xmlFree(prop); } return ret_val; } void e_xml_set_bool_prop_by_name (xmlNode *parent, const xmlChar *prop_name, gboolean value) { g_return_if_fail (parent != NULL); g_return_if_fail (prop_name != NULL); if (value) { xmlSetProp (parent, prop_name, "true"); } else { xmlSetProp (parent, prop_name, "false"); } } gdouble e_xml_get_double_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) { g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); return e_xml_get_double_prop_by_name_with_default (parent, prop_name, 0.0); } gdouble e_xml_get_double_prop_by_name_with_default (const xmlNode *parent, const xmlChar *prop_name, gdouble def) { xmlChar *prop; gdouble ret_val = def; g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); prop = xmlGetProp ((xmlNode *) parent, prop_name); if (prop != NULL) { (void) sscanf (prop, "%lf", &ret_val); xmlFree (prop); } return ret_val; } void e_xml_set_double_prop_by_name(xmlNode *parent, const xmlChar *prop_name, gdouble value) { gchar *valuestr; g_return_if_fail (parent != NULL); g_return_if_fail (prop_name != NULL); if (fabs (value) < 1e9 && fabs (value) > 1e-5) { valuestr = g_strdup_printf ("%f", value); } else { valuestr = g_strdup_printf ("%.*g", DBL_DIG, value); } xmlSetProp (parent, prop_name, valuestr); g_free (valuestr); } gchar * e_xml_get_string_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) { g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); return e_xml_get_string_prop_by_name_with_default (parent, prop_name, NULL); } gchar * e_xml_get_string_prop_by_name_with_default (const xmlNode *parent, const xmlChar *prop_name, const gchar *def) { xmlChar *prop; gchar *ret_val; g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); prop = xmlGetProp ((xmlNode *) parent, prop_name); if (prop != NULL) { ret_val = g_strdup (prop); xmlFree (prop); } else { ret_val = g_strdup (def); } return ret_val; } void e_xml_set_string_prop_by_name (xmlNode *parent, const xmlChar *prop_name, const gchar *value) { g_return_if_fail (parent != NULL); g_return_if_fail (prop_name != NULL); if (value != NULL) { xmlSetProp (parent, prop_name, value); } } gchar * e_xml_get_translated_string_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) { xmlChar *prop; gchar *ret_val = NULL; g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); prop = xmlGetProp ((xmlNode *) parent, prop_name); if (prop != NULL) { ret_val = g_strdup (_(prop)); xmlFree (prop); } return ret_val; } b0371f94d7ca7c6a66'>Update KDE Applications (release-service) to 20.04Tobias C. Berner2020-04-241-1/+0 * devel/qca: update to 2.3Tobias C. Berner2020-03-211-2/+2 * KDE's December 2019 Apps UpdateTobias C. Berner2019-12-131-1/+0 * devel/boost-*: update to 1.72.0Jan Beich2019-12-121-1/+1 * Follow-up to r514669: bump consumers of moved portsTobias C. Berner2019-10-181-0/+1 * KDE Applications: update to 19.08.2Tobias C. Berner2019-10-161-1/+0 * devel/boost-*: update to 1.71.0Jan Beich2019-08-191-0/+1 * Update KDE Applications to latest upstream release, 19.08Adriaan de Groot2019-08-151-1/+0 * Bump PORTREVISION for ports depending on the canonical version of GCCGerald Pfeifer2019-07-271-1/+1 * KDE Applications: complete dependency listsTobias C. Berner2019-06-231-2/+4 * Update KDE Applications to 19.04.2Tobias C. Berner2019-06-071-1/+0 * - Add missed qca-qt5 cryptoengine dependency to enable public key authenticationDima Panov2019-05-131-0/+2 * deskutils/kdepim-runtime: don't use ninjaTobias C. Berner2019-04-271-1/+1 * Update KDE Applications to 19.04.0Tobias C. Berner2019-04-191-2/+1 * devel/boost-*: update to 1.70.0Jan Beich2019-04-121-0/+1 * Update KDE Applications to 18.12.2Tobias C. Berner2019-02-081-1/+0 * Fix Qt5 symbol version scripts to put the catch-all clause first. WhenTijl Coosemans2019-01-161-0/+1 * Change cmake default behaviour to outsource.Tobias C. Berner2018-12-261-1/+1 * Update KDE Applications to 18.12.0Tobias C. Berner2018-12-141-1/+0 * Bump PORTREVISION for ports depending on the canonical version of GCCGerald Pfeifer2018-12-121-1/+1 * devel/boost-*: update to 1.69.0Jan Beich2018-12-121-1/+1 * Merge lang/qt5-qml and x11-toolkits/qt5-quick into x11-toolkits/qt5-declarativeTobias C. Berner2018-11-051-1/+2 * Add DOCS options to ports that should have one.Mathieu Arnold2018-09-101-0/+2 * Update KDE Applications to 18.08Tobias C. Berner2018-08-251-1/+0 * devel/boost-*: update to 1.68.0Jan Beich2018-08-091-1/+1 * Bump PORTREVISION for ports depending on the canonical version of GCCGerald Pfeifer2018-07-301-0/+1 * Replace bsd.qt.mk by Uses/qt.mk and Uses/qt-dist.mkTobias C. Berner2018-06-291-2/+2 * Update KDE Applications to 18.04.0Tobias C. Berner2018-04-291-1/+0 * devel/boost-*: update to 1.67.0Jan Beich2018-04-181-0/+1