]> icculus.org git repositories - dana/openbox.git/blob - obt/xml.h
Add obt_xml_file_path() and obt_xml_node_string_raw() and don't return text in child...
[dana/openbox.git] / obt / xml.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    obt/xml.h for the Openbox window manager
4    Copyright (c) 2003-2007   Dana Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #ifndef __obt_xml_h
20 #define __obt_xml_h
21
22 #include <libxml/parser.h>
23 #include <glib.h>
24
25 G_BEGIN_DECLS
26
27 typedef struct _ObtXmlInst ObtXmlInst;
28
29 typedef void (*ObtXmlCallback)(xmlNodePtr node, gpointer data);
30
31 ObtXmlInst* obt_xml_instance_new(void);
32 void obt_xml_instance_ref(ObtXmlInst *inst);
33 void obt_xml_instance_unref(ObtXmlInst *inst);
34
35 void obt_xml_new_file(ObtXmlInst *inst,
36                       const gchar *root_node);
37
38 gboolean obt_xml_load_file(ObtXmlInst *inst,
39                            const gchar *path,
40                            const gchar *root_node);
41 gboolean obt_xml_load_cache_file(ObtXmlInst *inst,
42                                  const gchar *domain,
43                                  const gchar *filename,
44                                  const gchar *root_node);
45 gboolean obt_xml_load_config_file(ObtXmlInst *inst,
46                                   const gchar *domain,
47                                   const gchar *filename,
48                                   const gchar *root_node);
49 gboolean obt_xml_load_data_file(ObtXmlInst *inst,
50                                 const gchar *domain,
51                                 const gchar *filename,
52                                 const gchar *root_node);
53 gboolean obt_xml_load_theme_file(ObtXmlInst *inst,
54                                  const gchar *theme,
55                                  const gchar *domain,
56                                  const gchar *filename,
57                                  const gchar *root_node);
58 gboolean obt_xml_load_mem(ObtXmlInst *inst,
59                           gpointer data, guint len, const gchar *root_node);
60
61 gboolean obt_xml_save_file(ObtXmlInst *inst,
62                            const gchar *path,
63                            gboolean pretty);
64 gboolean obt_xml_save_cache_file(ObtXmlInst *inst,
65                                  const gchar *domain,
66                                  const gchar *filename,
67                                  gboolean pretty);
68
69 xmlDocPtr obt_xml_doc(ObtXmlInst *inst);
70 xmlNodePtr obt_xml_root(ObtXmlInst *inst);
71
72 /*! Returns the path to the file loaded by @inst, if one exists, or NULL.
73   The returned string is owned by @inst and will be freed along with it.
74  */
75 const gchar* obt_xml_file_path(ObtXmlInst *inst);
76
77 void obt_xml_close(ObtXmlInst *inst);
78
79 void obt_xml_register(ObtXmlInst *inst, const gchar *tag,
80                       ObtXmlCallback func, gpointer data);
81 void obt_xml_unregister(ObtXmlInst *inst, const gchar *tag);
82 void obt_xml_tree(ObtXmlInst *i, xmlNodePtr node);
83 void obt_xml_tree_from_root(ObtXmlInst *i);
84
85
86 /* helpers */
87
88 xmlNodePtr obt_xml_find_sibling(xmlNodePtr node, const gchar *name);
89
90 guint    obt_xml_node_line     (xmlNodePtr node);
91 gboolean obt_xml_node_contains (xmlNodePtr node, const gchar *val);
92 gchar   *obt_xml_node_string   (xmlNodePtr node);  /* strips whitespace */
93 gchar   *obt_xml_node_string_raw(xmlNodePtr node); /* unstripped version */
94 gint     obt_xml_node_int      (xmlNodePtr node);
95 gboolean obt_xml_node_bool     (xmlNodePtr node);
96
97 void obt_xml_node_set_string(xmlNodePtr node, const gchar *s);
98 void obt_xml_node_set_int(xmlNodePtr node, gint i);
99 void obt_xml_node_set_bool(xmlNodePtr node, gboolean b);
100
101 gboolean obt_xml_attr_contains (xmlNodePtr node, const gchar *name,
102                                 const gchar *val);
103 gboolean obt_xml_attr_string   (xmlNodePtr node, const gchar *name,
104                                 gchar **value);
105 gboolean obt_xml_attr_int      (xmlNodePtr node, const gchar *name,
106                                 gint *value);
107 gboolean obt_xml_attr_bool     (xmlNodePtr node, const gchar *name,
108                                 gboolean *value);
109
110 /* path based operations */
111
112 /*! Returns the node in the given @subtree, at the given @path.  If the node is
113   not found, it is created, along with any parents.
114
115   The path has a structure follows.
116   - <name> - specifies a child of the current position in the subtree
117   - :foo=bar - specifies an attribute and its value.  this can be appended to
118     a <name> or to another attribute
119   - / - specifies to move one level deeper in the tree
120
121   An example:
122   - theme/font:place=ActiveWindow/size refers to the size node at this
123     position:
124     - <theme><font place="ActiveWindow"><size /></font></theme>
125
126   @subtree The root of the search.
127   @path A string specifying the search path.
128   @default_value If the node is not found, it is created with this value
129     contained within.
130 */
131 xmlNodePtr obt_xml_path_get_node(xmlNodePtr subtree, const gchar *path,
132                                  const gchar *default_value);
133 /*! Similar to obt_xml_path_get_node(), but returns a list of nodes that
134   match the given path.
135   Given xml as <a><b>1</b><b>2</b><b>3</b></a>, the path "a/b" would return
136   the list of all nodes named b.
137 */
138 GList* obt_xml_path_get_list(xmlNodePtr subtree, const gchar *path);
139 /*! Removes a specified node from the tree. */
140 void obt_xml_path_delete_node(xmlNodePtr subtree, const gchar *path);
141
142 gchar* obt_xml_path_string(xmlNodePtr subtree, const gchar *path,
143                           const gchar *default_value);
144 int obt_xml_path_int(xmlNodePtr subtree, const gchar *path,
145                      const gchar *default_value);
146 gboolean obt_xml_path_bool(xmlNodePtr subtree, const gchar *path,
147                            const gchar *default_value);
148
149 void obt_xml_path_set_string(xmlNodePtr subtree, const gchar *path,
150                              const gchar *value);
151 void obt_xml_path_set_int(xmlNodePtr subtree, const gchar *path,
152                           gint value);
153 void obt_xml_path_set_bool(xmlNodePtr subtree, const gchar *path,
154                            gboolean value);
155
156 G_END_DECLS
157
158 #endif