]> git.sur5r.net Git - glabels/blob - glabels2/src/xml-paper.c
eee5db6104ebbb8d5054f33c7557a62e7c674a09
[glabels] / glabels2 / src / xml-paper.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  xml-paper.c:  paper xml module
5  *
6  *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #include <config.h>
24
25 #include <string.h>
26 #include <libintl.h>
27
28 #include "xml.h"
29 #include "xml-paper.h"
30
31 #include "debug.h"
32
33 /*===========================================*/
34 /* Private types                             */
35 /*===========================================*/
36
37 /*===========================================*/
38 /* Private globals                           */
39 /*===========================================*/
40
41 /*===========================================*/
42 /* Local function prototypes                 */
43 /*===========================================*/
44
45 glPaper *gl_xml_paper_parse_paper (xmlNodePtr paper_node);
46
47
48 \f
49 /*****************************************************************************/
50 /* Read papers from paper file.                                        */
51 /*****************************************************************************/
52 GList *
53 gl_xml_paper_read_papers_from_file (GList *papers,
54                                     gchar *xml_filename)
55 {
56         xmlDocPtr   doc;
57         xmlNodePtr  root, node;
58         glPaper *paper;
59
60         gl_debug (DEBUG_PAPER, "START");
61
62         LIBXML_TEST_VERSION;
63
64         doc = xmlParseFile (xml_filename);
65         if (!doc) {
66                 g_warning ("\"%s\" is not a glabels paper file (not XML)",
67                       xml_filename);
68                 return papers;
69         }
70
71         root = xmlDocGetRootElement (doc);
72         if (!root || !root->name) {
73                 g_warning ("\"%s\" is not a glabels paper file (no root node)",
74                       xml_filename);
75                 xmlFreeDoc (doc);
76                 return papers;
77         }
78         if (!xmlStrEqual (root->name, "Glabels-paper-sizes")) {
79                 g_warning ("\"%s\" is not a glabels paper file (wrong root node)",
80                       xml_filename);
81                 xmlFreeDoc (doc);
82                 return papers;
83         }
84
85         for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
86
87                 if (xmlStrEqual (node->name, "Paper-size")) {
88                         paper = gl_xml_paper_parse_paper (node);
89                         papers = g_list_append (papers, paper);
90                 } else {
91                         if ( !xmlNodeIsText(node) ) {
92                                 if (!xmlStrEqual (node->name,"comment")) {
93                                         g_warning ("bad node =  \"%s\"",node->name);
94                                 }
95                         }
96                 }
97         }
98
99         xmlFreeDoc (doc);
100
101         gl_debug (DEBUG_PAPER, "END");
102         return papers;
103 }
104
105 /*****************************************************************************/
106 /* Parse XML paper Node.                                                  */
107 /*****************************************************************************/
108 glPaper *
109 gl_xml_paper_parse_paper (xmlNodePtr paper_node)
110 {
111         glPaper               *paper;
112         gchar                 *name;
113
114         gl_debug (DEBUG_PAPER, "START");
115
116         paper = g_new0 (glPaper, 1);
117
118         paper->id   = xmlGetProp (paper_node, "id");
119
120         name = xmlGetProp (paper_node, "_name");
121         if (name != NULL) {
122                 paper->name = gettext (name);
123         } else {
124                 paper->name = xmlGetProp (paper_node, "name");
125         }
126
127         paper->width  = gl_xml_get_prop_length (paper_node, "width", 0);
128         paper->height = gl_xml_get_prop_length (paper_node, "height", 0);
129
130         gl_debug (DEBUG_PAPER, "END");
131
132         return paper;
133 }
134