3 * Copyright (C) 2006-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of libglabels.
7 * libglabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * libglabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with libglabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "xml-category.h"
25 #include <glib/gi18n.h>
30 #include "libglabels-private.h"
34 /*===========================================*/
36 /*===========================================*/
38 /*===========================================*/
40 /*===========================================*/
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
48 * lgl_xml_category_read_categories_from_file:
49 * @utf8_filename: Filename of categories file (name encoded as UTF-8)
51 * Read category definitions from a file.
53 * Returns: a list of #lglCategory structures.
57 lgl_xml_category_read_categories_from_file (gchar *utf8_filename)
61 xmlDocPtr categories_doc;
65 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
67 g_message ("Utf8 filename conversion error");
71 categories_doc = xmlParseFile (filename);
72 if (!categories_doc) {
73 g_message ("\"%s\" is not a glabels category file (not XML)",
78 categories = lgl_xml_category_parse_categories_doc (categories_doc);
81 xmlFreeDoc (categories_doc);
88 * lgl_xml_category_parse_categories_doc:
89 * @categories_doc: libxml #xmlDocPtr tree, representing a categories
92 * Read category definitions from a libxml #xmlDocPtr tree.
94 * Returns: a list of #lglCategory structures.
98 lgl_xml_category_parse_categories_doc (xmlDocPtr categories_doc)
100 GList *categories = NULL;
101 xmlNodePtr root, node;
102 lglCategory *category;
106 root = xmlDocGetRootElement (categories_doc);
107 if (!root || !root->name) {
108 g_message ("\"%s\" is not a glabels category file (no root node)",
109 categories_doc->name);
110 xmlFreeDoc (categories_doc);
113 if (!lgl_xml_is_node (root, "Glabels-categories")) {
114 g_message ("\"%s\" is not a glabels category file (wrong root node)",
115 categories_doc->name);
116 xmlFreeDoc (categories_doc);
120 for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
122 if (lgl_xml_is_node (node, "Category")) {
123 category = lgl_xml_category_parse_category_node (node);
124 categories = g_list_append (categories, category);
126 if ( !xmlNodeIsText(node) ) {
127 if (!lgl_xml_is_node (node, "comment")) {
128 g_message ("bad node = \"%s\"",node->name);
139 * lgl_xml_category_parse_category_node:
140 * @category_node: libxml #xmlNodePtr category node from a #xmlDocPtr tree.
142 * Read a single category definition from a libxml #xmlNodePtr node.
144 * Returns: a pointer to a newly created #lglCategory structure.
148 lgl_xml_category_parse_category_node (xmlNodePtr category_node)
150 lglCategory *category;
155 id = lgl_xml_get_prop_string (category_node, "id", NULL);
156 name = lgl_xml_get_prop_i18n_string (category_node, "name", NULL);
158 category = lgl_category_new (id, name);
169 * Local Variables: -- emacs
171 * c-basic-offset: 8 -- emacs
172 * tab-width: 8 -- emacs
173 * indent-tabs-mode: nil -- emacs