1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 tree.c for ObConf, the configuration tool for Openbox
4 Copyright (c) 2003-2007 Dana Jansens
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.
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.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "openbox/parse.h"
23 #include <sys/types.h>
26 xmlNodePtr tree_get_node(const gchar *path, const gchar *def)
34 nodes = g_strsplit(path, "/", 0);
35 for (it = nodes; *it; it = next) {
39 attrs = g_strsplit(*it, ":", 0);
42 /* match attributes */
43 c = parse_find_node(attrs[0], n->children);
48 for (i = 1; attrs[i]; ++i) {
49 gchar **eq = g_strsplit(attrs[i], "=", 2);
50 if (eq[1] && !parse_attr_contains(eq[1], c, eq[0]))
55 c = parse_find_node(attrs[0], c->next);
61 c = xmlNewTextChild(n, NULL, *it, *next ? NULL : def);
63 for (i = 1; attrs[i]; ++i) {
64 gchar **eq = g_strsplit(attrs[i], "=", 2);
66 xmlNewProp(c, eq[0], eq[1]);
85 p = g_build_filename(parse_xdg_config_home_path(), "openbox", NULL);
86 parse_mkdir_path(p, 0700);
89 p = g_build_filename(parse_xdg_config_home_path(), "openbox",
91 err = xmlSaveFormatFile(p, doc, 1) == -1;
94 s = g_strdup_printf("An error occured while saving the "
95 "config file '%s'", p);
108 (gdk_screen_get_root_window(gdk_screen_get_default()),
109 gdk_atom_intern("_OPENBOX_PID", FALSE),
110 gdk_atom_intern("CARDINAL", FALSE),
111 0, 4, FALSE, &type, &format, &length, (guchar**)&pid)) {
118 void tree_set_string(const gchar *node, const gchar *value)
122 n = tree_get_node(node, NULL);
123 xmlNodeSetContent(n, (const xmlChar*) value);
128 void tree_set_int(const gchar *node, const gint value)
133 n = tree_get_node(node, NULL);
134 s = g_strdup_printf("%d", value);
135 xmlNodeSetContent(n, (const xmlChar*) s);
141 void tree_set_bool(const gchar *node, const gboolean value)
145 n = tree_get_node(node, NULL);
146 xmlNodeSetContent(n, (const xmlChar*) (value ? "yes" : "no"));
151 gchar* tree_get_string(const gchar *node, const gchar *def)
155 n = tree_get_node(node, def);
156 return parse_string(doc, n);
159 gint tree_get_int(const gchar *node, gint def)
164 d = g_strdup_printf("%d", def);
165 n = tree_get_node(node, d);
167 return parse_int(doc, n);
170 gboolean tree_get_bool(const gchar *node, gboolean def)
174 n = tree_get_node(node, (def ? "yes" : "no"));
175 return parse_bool(doc, n);