3
* Copyright (C) 2002 Jasper Huijsmans (huysmans@users.sourceforge.net)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
#ifdef HAVE_SYS_STAT_H
33
#include <libxml/parser.h>
34
#include <libxml/tree.h>
43
#define NS "http://www.xfce.org/xfce4/panel/1.0"
45
gboolean disable_user_config = FALSE;
47
xmlDocPtr xmlconfig = NULL;
53
check_disable_user_config (void)
55
const char *var = g_getenv ("XFCE_DISABLE_USER_CONFIG");
57
return (var && !strequal (var, "0"));
69
xmlKeepBlanksDefault (0);
71
rcfile = get_read_file (XFCERC);
75
doc = xmlParseFile (rcfile);
85
xmlNodePtr node = NULL;
87
/* global xmlDocPtr */
89
xmlconfig = read_xml_file ();
93
g_message ("%s: No config file found", PACKAGE);
97
node = xmlDocGetRootElement (xmlconfig);
101
g_warning ("%s: empty document: %s\n", PACKAGE, xmlconfig->name);
103
xmlFreeDoc (xmlconfig);
108
if (!xmlStrEqual (node->name, (const xmlChar *) ROOT))
110
g_warning ("%s: wrong document type: %s\n", PACKAGE, xmlconfig->name);
112
xmlFreeDoc (xmlconfig);
121
get_global_prefs (void)
125
node = get_xml_root ();
130
/* Now parse the xml tree */
131
for (node = node->children; node; node = node->next)
133
if (xmlStrEqual (node->name, (const xmlChar *) "Panel"))
135
panel_parse_xml (node);
141
/* leave the xmldoc open for get_panel_config() */
145
get_panel_config (void)
149
disable_user_config = check_disable_user_config ();
151
node = get_xml_root ();
155
/* create empty items */
156
groups_set_from_xml (NULL);
160
/* Now parse the xml tree */
161
for (node = node->children; node; node = node->next)
163
if (xmlStrEqual (node->name, (const xmlChar *) "Groups"))
165
groups_set_from_xml (node);
170
if (xmlStrEqual (node->name, (const xmlChar *) "Left"))
171
old_groups_set_from_xml (LEFT, node);
172
else if (xmlStrEqual (node->name, (const xmlChar *) "Right"))
173
old_groups_set_from_xml (RIGHT, node);
176
xmlFreeDoc (xmlconfig);
181
write_panel_config (void)
186
static gboolean backup = TRUE;
188
disable_user_config = check_disable_user_config ();
190
if (disable_user_config)
193
rcfile = get_save_file (XFCERC);
195
if (g_file_test (rcfile, G_FILE_TEST_EXISTS))
199
write_backup_file (rcfile);
206
dir = g_path_get_dirname (rcfile);
208
if (!g_file_test (dir, G_FILE_TEST_IS_DIR))
209
mkdir (dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
214
xmlconfig = xmlNewDoc ("1.0");
215
xmlconfig->children = xmlNewDocRawNode (xmlconfig, NULL, ROOT, NULL);
217
root = (xmlNodePtr) xmlconfig->children;
218
xmlDocSetRootElement (xmlconfig, root);
220
panel_write_xml (root);
222
groups_write_xml (root);
224
xmlSaveFormatFile (rcfile, xmlconfig, 1);
226
xmlFreeDoc (xmlconfig);