Make desktop-entry an attribute rather than a child node

2001-04-27  Bradford Hovinen  <hovinen@ximian.com>

	* capplets/wm-properties/wm-list.c (wm_read_from_xml): Make
	desktop-entry an attribute rather than a child node

	* capplets/*/main.c: Do not try to load preferences from XML if
	there was not XML data
This commit is contained in:
Bradford Hovinen 2001-04-29 16:22:27 +00:00 committed by Bradford Hovinen (Gdict maintainer)
parent 78636aecbc
commit fc7487ef4f
16 changed files with 653 additions and 370 deletions

View file

@ -1,3 +1,11 @@
2001-04-27 Bradford Hovinen <hovinen@ximian.com>
* capplets/wm-properties/wm-list.c (wm_read_from_xml): Make
desktop-entry an attribute rather than a child node
* capplets/*/main.c: Do not try to load preferences from XML if
there was not XML data
2001-04-24 Bradford Hovinen <hovinen@ximian.com>
* capplets/*/main.c:

View file

@ -135,28 +135,31 @@ do_set_xml (gboolean apply_settings)
xmlDocPtr doc;
char *buffer = NULL;
int len = 0;
int bytes_read;
int bytes_read = 0;
while (!feof (stdin)) {
if (!len) buffer = g_new (char, 16384);
else buffer = g_renew (char, buffer, len + 16384);
if (!len) buffer = g_new (char, 16385);
else buffer = g_renew (char, buffer, len + 16385);
bytes_read = fread (buffer + len, 1, 16384, stdin);
buffer[len + bytes_read] = '\0';
len += 16384;
}
doc = xmlParseMemory (buffer, strlen (buffer));
if (len > 0 && bytes_read + len - 16384 > 0) {
doc = xmlParseMemory (buffer, strlen (buffer));
prefs = preferences_read_xml (doc);
prefs = preferences_read_xml (doc);
if (prefs) {
preferences_save (prefs);
if (prefs) {
preferences_save (prefs);
if (apply_settings)
preferences_apply_now (prefs);
} else {
g_warning ("Error while reading the screensaver config file");
if (apply_settings)
preferences_apply_now (prefs);
return;
}
}
g_warning ("Error while reading the background config file");
return;
}
static void

View file

@ -40,11 +40,12 @@ static Applier *applier = NULL;
static void preferences_init (Preferences *prefs);
static void preferences_class_init (PreferencesClass *class);
static gint xml_read_int (xmlNodePtr node,
gchar *propname);
static gint xml_read_int (xmlNodePtr node);
static xmlNodePtr xml_write_int (gchar *name,
gchar *propname,
gint number);
static gboolean xml_read_bool (xmlNodePtr node);
static xmlNodePtr xml_write_bool (gchar *name,
gboolean value);
static gint apply_timeout_cb (Preferences *prefs);
@ -284,7 +285,7 @@ preferences_save (Preferences *prefs)
gnome_config_set_string ("/Background/Default/wallpaper",
(prefs->wallpaper_enabled) ?
prefs->wallpaper_filename : "none");
prefs->wallpaper_filename : "(none)");
gnome_config_set_int ("/Background/Default/wallpaperAlign",
prefs->wallpaper_type);
@ -395,11 +396,11 @@ preferences_read_xml (xmlDocPtr xml_doc)
prefs->color2 = read_color_from_string
(xmlNodeGetContent (node));
else if (!strcmp (node->name, "enabled"))
prefs->enabled = TRUE;
prefs->enabled = xml_read_bool (node);
else if (!strcmp (node->name, "wallpaper"))
prefs->wallpaper_enabled = TRUE;
prefs->wallpaper_enabled = xml_read_bool (node);
else if (!strcmp (node->name, "gradient"))
prefs->gradient_enabled = TRUE;
prefs->gradient_enabled = xml_read_bool (node);
else if (!strcmp (node->name, "orientation")) {
str = xmlNodeGetContent (node);
@ -409,7 +410,7 @@ preferences_read_xml (xmlDocPtr xml_doc)
prefs->orientation = ORIENTATION_VERT;
}
else if (!strcmp (node->name, "wallpaper-type"))
prefs->wallpaper_type = xml_read_int (node, NULL);
prefs->wallpaper_type = xml_read_int (node);
else if (!strcmp (node->name, "wallpaper-filename"))
prefs->wallpaper_filename =
g_strdup (xmlNodeGetContent (node));
@ -417,11 +418,11 @@ preferences_read_xml (xmlDocPtr xml_doc)
prefs->wallpaper_sel_path =
g_strdup (xmlNodeGetContent (node));
else if (!strcmp (node->name, "auto-apply"))
prefs->auto_apply = TRUE;
prefs->auto_apply = xml_read_bool (node);
else if (!strcmp (node->name, "adjust-opacity"))
prefs->adjust_opacity = TRUE;
prefs->adjust_opacity = xml_read_bool (node);
else if (!strcmp (node->name, "opacity"))
prefs->opacity = xml_read_int (node, NULL);
prefs->opacity = xml_read_int (node);
}
return prefs;
@ -450,20 +451,17 @@ preferences_write_xml (Preferences *prefs)
prefs->color2->blue >> 8);
xmlNewChild (node, NULL, "bg-color2", tmp);
if (prefs->enabled)
xmlNewChild (node, NULL, "enabled", NULL);
if (prefs->wallpaper_enabled)
xmlNewChild (node, NULL, "wallpaper", NULL);
if (prefs->gradient_enabled)
xmlNewChild (node, NULL, "gradient", NULL);
xmlAddChild (node, xml_write_bool ("enabled", prefs->enabled));
xmlAddChild (node, xml_write_bool ("wallpaper",
prefs->wallpaper_enabled));
xmlAddChild (node, xml_write_bool ("gradient",
prefs->gradient_enabled));
xmlNewChild (node, NULL, "orientation",
(prefs->orientation == ORIENTATION_VERT) ?
"vertical" : "horizontal");
xmlAddChild (node, xml_write_int ("wallpaper-type", NULL,
xmlAddChild (node, xml_write_int ("wallpaper-type",
prefs->wallpaper_type));
xmlNewChild (node, NULL, "wallpaper-filename",
@ -471,12 +469,12 @@ preferences_write_xml (Preferences *prefs)
xmlNewChild (node, NULL, "wallpaper-sel-path",
prefs->wallpaper_sel_path);
if (prefs->auto_apply)
xmlNewChild (node, NULL, "auto-apply", NULL);
xmlAddChild (node, xml_write_bool ("auto-apply",
prefs->auto_apply));
if (prefs->adjust_opacity)
xmlNewChild (node, NULL, "adjust-opacity", NULL);
xmlAddChild (node, xml_write_int ("opacity", NULL,
xmlAddChild (node, xml_write_int ("opacity",
prefs->opacity));
xmlDocSetRootElement (doc, node);
@ -487,14 +485,11 @@ preferences_write_xml (Preferences *prefs)
/* Read a numeric value from a node */
static gint
xml_read_int (xmlNodePtr node, char *propname)
xml_read_int (xmlNodePtr node)
{
char *text;
if (propname == NULL)
text = xmlNodeGetContent (node);
else
text = xmlGetProp (node, propname);
text = xmlNodeGetContent (node);
if (text == NULL)
return 0;
@ -505,7 +500,7 @@ xml_read_int (xmlNodePtr node, char *propname)
/* Write out a numeric value in a node */
static xmlNodePtr
xml_write_int (gchar *name, gchar *propname, gint number)
xml_write_int (gchar *name, gint number)
{
xmlNodePtr node;
gchar *str;
@ -513,15 +508,43 @@ xml_write_int (gchar *name, gchar *propname, gint number)
g_return_val_if_fail (name != NULL, NULL);
str = g_strdup_printf ("%d", number);
node = xmlNewNode (NULL, name);
xmlNodeSetContent (node, str);
g_free (str);
return node;
}
/* Read a boolean value from a node */
static gboolean
xml_read_bool (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (!g_strcasecmp (text, "true"))
return TRUE;
else
return FALSE;
}
/* Write out a boolean value in a node */
static xmlNodePtr
xml_write_bool (gchar *name, gboolean value)
{
xmlNodePtr node;
g_return_val_if_fail (name != NULL, NULL);
node = xmlNewNode (NULL, name);
if (propname == NULL)
xmlNodeSetContent (node, str);
if (value)
xmlNodeSetContent (node, "true");
else
xmlSetProp (node, propname, str);
g_free (str);
xmlNodeSetContent (node, "false");
return node;
}

View file

@ -117,28 +117,38 @@ do_get_xml (void)
gtk_object_destroy (GTK_OBJECT (prefs));
}
static void
do_set_xml (gboolean apply_settings)
{
xmlDocPtr doc;
char *buffer;
char *buffer = NULL;
int len = 0;
int bytes_read = 0;
while (!feof (stdin)) {
if (!len) buffer = g_new (char, 16384);
else buffer = g_renew (char, buffer, len + 16384);
fread (buffer + len, 1, 16384, stdin);
if (!len) buffer = g_new (char, 16385);
else buffer = g_renew (char, buffer, len + 16385);
bytes_read = fread (buffer + len, 1, 16384, stdin);
buffer[len + bytes_read] = '\0';
len += 16384;
}
doc = xmlParseMemory (buffer, strlen (buffer));
if (len > 0 && bytes_read + len - 16384 > 0) {
doc = xmlParseMemory (buffer, strlen (buffer));
prefs = preferences_read_xml (doc);
prefs = preferences_read_xml (doc);
if (prefs) {
preferences_save (prefs);
if (prefs && apply_settings)
preferences_save (prefs);
else if (prefs == NULL)
g_warning ("Error while reading the screensaver config file");
if (apply_settings)
preferences_apply_now (prefs);
return;
}
}
g_warning ("Error while reading the keyboard config file");
return;
}
int

View file

@ -49,11 +49,12 @@ static XF86MiscKbdSettings kbdsettings;
static void preferences_init (Preferences *prefs);
static void preferences_class_init (PreferencesClass *class);
static gint xml_read_int (xmlNodePtr node,
gchar *propname);
static gint xml_read_int (xmlNodePtr node);
static xmlNodePtr xml_write_int (gchar *name,
gchar *propname,
gint number);
static gboolean xml_read_bool (xmlNodePtr node);
static xmlNodePtr xml_write_bool (gchar *name,
gboolean value);
static gint apply_timeout_cb (Preferences *prefs);
@ -285,15 +286,15 @@ preferences_read_xml (xmlDocPtr xml_doc)
for (node = root_node->childs; node; node = node->next) {
if (!strcmp (node->name, "rate"))
prefs->rate = xml_read_int (node, NULL);
prefs->rate = xml_read_int (node);
else if (!strcmp (node->name, "delay"))
prefs->delay = xml_read_int (node, NULL);
prefs->delay = xml_read_int (node);
else if (!strcmp (node->name, "repeat"))
prefs->repeat = TRUE;
prefs->repeat = xml_read_bool (node);
else if (!strcmp (node->name, "volume"))
prefs->volume = xml_read_int (node, NULL);
prefs->volume = xml_read_int (node);
else if (!strcmp (node->name, "click"))
prefs->click = TRUE;
prefs->click = xml_read_bool (node);
}
return prefs;
@ -304,23 +305,16 @@ preferences_write_xml (Preferences *prefs)
{
xmlDocPtr doc;
xmlNodePtr node;
char *tmp;
doc = xmlNewDoc ("1.0");
node = xmlNewDocNode (doc, NULL, "keyboard-properties", NULL);
xmlAddChild (node, xml_write_int ("rate", NULL, prefs->rate));
xmlAddChild (node, xml_write_int ("delay", NULL, prefs->delay));
if (prefs->repeat)
xmlNewChild (node, NULL, "repeat", NULL);
xmlAddChild (node, xml_write_int ("volume", NULL,
prefs->volume));
if (prefs->click)
xmlNewChild (node, NULL, "click", NULL);
xmlAddChild (node, xml_write_int ("rate", prefs->rate));
xmlAddChild (node, xml_write_int ("delay", prefs->delay));
xmlAddChild (node, xml_write_bool ("repeat", prefs->repeat));
xmlAddChild (node, xml_write_int ("volume", prefs->volume));
xmlAddChild (node, xml_write_bool ("click", prefs->click));
xmlDocSetRootElement (doc, node);
@ -330,14 +324,11 @@ preferences_write_xml (Preferences *prefs)
/* Read a numeric value from a node */
static gint
xml_read_int (xmlNodePtr node, char *propname)
xml_read_int (xmlNodePtr node)
{
char *text;
if (propname == NULL)
text = xmlNodeGetContent (node);
else
text = xmlGetProp (node, propname);
text = xmlNodeGetContent (node);
if (text == NULL)
return 0;
@ -348,7 +339,7 @@ xml_read_int (xmlNodePtr node, char *propname)
/* Write out a numeric value in a node */
static xmlNodePtr
xml_write_int (gchar *name, gchar *propname, gint number)
xml_write_int (gchar *name, gint number)
{
xmlNodePtr node;
gchar *str;
@ -356,15 +347,43 @@ xml_write_int (gchar *name, gchar *propname, gint number)
g_return_val_if_fail (name != NULL, NULL);
str = g_strdup_printf ("%d", number);
node = xmlNewNode (NULL, name);
xmlNodeSetContent (node, str);
g_free (str);
return node;
}
/* Read a boolean value from a node */
static gboolean
xml_read_bool (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (!g_strcasecmp (text, "true"))
return TRUE;
else
return FALSE;
}
/* Write out a boolean value in a node */
static xmlNodePtr
xml_write_bool (gchar *name, gboolean value)
{
xmlNodePtr node;
g_return_val_if_fail (name != NULL, NULL);
node = xmlNewNode (NULL, name);
if (propname == NULL)
xmlNodeSetContent (node, str);
if (value)
xmlNodeSetContent (node, "true");
else
xmlSetProp (node, propname, str);
g_free (str);
xmlNodeSetContent (node, "false");
return node;
}

View file

@ -117,28 +117,39 @@ do_get_xml (void)
gtk_object_destroy (GTK_OBJECT (prefs));
}
static void
do_set_xml (gboolean apply_settings)
{
xmlDocPtr doc;
char *buffer;
char *buffer = NULL;
int len = 0;
int bytes_read = 0;
while (!feof (stdin)) {
if (!len) buffer = g_new (char, 16384);
else buffer = g_renew (char, buffer, len + 16384);
fread (buffer + len, 1, 16384, stdin);
if (!len) buffer = g_new (char, 16385);
else buffer = g_renew (char, buffer, len + 16385);
bytes_read = fread (buffer + len, 1, 16384, stdin);
buffer[len + bytes_read] = '\0';
len += 16384;
}
doc = xmlParseMemory (buffer, strlen (buffer));
if (len > 0 && bytes_read + len - 16384 > 0) {
doc = xmlParseMemory (buffer, strlen (buffer));
prefs = preferences_read_xml (doc);
prefs = preferences_read_xml (doc);
if (prefs && apply_settings) {
preferences_save (prefs);
return;
}
else if (prefs) {
return;
}
}
if (prefs && apply_settings)
preferences_save (prefs);
else if (prefs == NULL)
g_warning ("Error while reading the screensaver config file");
g_warning ("Error while reading the keyboard config file");
return;
}
int

View file

@ -50,11 +50,12 @@ static GtkObjectClass *parent_class;
static void preferences_init (Preferences *prefs);
static void preferences_class_init (PreferencesClass *class);
static gint xml_read_int (xmlNodePtr node,
gchar *propname);
static gint xml_read_int (xmlNodePtr node);
static xmlNodePtr xml_write_int (gchar *name,
gchar *propname,
gint number);
static gboolean xml_read_bool (xmlNodePtr node);
static xmlNodePtr xml_write_bool (gchar *name,
gboolean value);
static gint apply_timeout_cb (Preferences *prefs);
@ -300,11 +301,11 @@ preferences_read_xml (xmlDocPtr xml_doc)
for (node = root_node->childs; node; node = node->next) {
if (!strcmp (node->name, "acceleration"))
prefs->acceleration = atoi (xmlNodeGetContent (node));
prefs->acceleration = xml_read_int (node);
else if (!strcmp (node->name, "threshold"))
prefs->threshold = atoi (xmlNodeGetContent (node));
prefs->threshold = xml_read_int (node);
else if (!strcmp (node->name, "right-to-left"))
prefs->rtol = TRUE;
prefs->rtol = xml_read_bool (node);
}
return prefs;
@ -321,14 +322,13 @@ preferences_write_xml (Preferences *prefs)
node = xmlNewDocNode (doc, NULL, "mouse-properties", NULL);
xmlAddChild (node, xml_write_int ("acceleration", NULL,
xmlAddChild (node, xml_write_int ("acceleration",
prefs->acceleration));
xmlAddChild (node, xml_write_int ("threshold", NULL,
xmlAddChild (node, xml_write_int ("threshold",
prefs->threshold));
if (prefs->rtol)
xmlNewChild (node, NULL, "right-to-left", NULL);
xmlAddChild (node, xml_write_bool ("right-to-left", prefs->rtol));
xmlDocSetRootElement (doc, node);
@ -338,14 +338,11 @@ preferences_write_xml (Preferences *prefs)
/* Read a numeric value from a node */
static gint
xml_read_int (xmlNodePtr node, char *propname)
xml_read_int (xmlNodePtr node)
{
char *text;
if (propname == NULL)
text = xmlNodeGetContent (node);
else
text = xmlGetProp (node, propname);
text = xmlNodeGetContent (node);
if (text == NULL)
return 0;
@ -356,7 +353,7 @@ xml_read_int (xmlNodePtr node, char *propname)
/* Write out a numeric value in a node */
static xmlNodePtr
xml_write_int (gchar *name, gchar *propname, gint number)
xml_write_int (gchar *name, gint number)
{
xmlNodePtr node;
gchar *str;
@ -364,15 +361,43 @@ xml_write_int (gchar *name, gchar *propname, gint number)
g_return_val_if_fail (name != NULL, NULL);
str = g_strdup_printf ("%d", number);
node = xmlNewNode (NULL, name);
xmlNodeSetContent (node, str);
g_free (str);
return node;
}
/* Read a boolean value from a node */
static gboolean
xml_read_bool (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (!g_strcasecmp (text, "true"))
return TRUE;
else
return FALSE;
}
/* Write out a boolean value in a node */
static xmlNodePtr
xml_write_bool (gchar *name, gboolean value)
{
xmlNodePtr node;
g_return_val_if_fail (name != NULL, NULL);
node = xmlNewNode (NULL, name);
if (propname == NULL)
xmlNodeSetContent (node, str);
if (value)
xmlNodeSetContent (node, "true");
else
xmlSetProp (node, propname, str);
g_free (str);
xmlNodeSetContent (node, "false");
return node;
}

View file

@ -1,3 +1,14 @@
2001-04-27 Bradford Hovinen <hovinen@ximian.com>
* preferences.c (screensaver_read_xml): Make label an attribute of
the node rather than a child node
(preferences_write_xml): Use xml_write_int rather than rolling our
own
(xml_read_int):
(xml_write_int):
(xml_read_bool):
(xml_write_bool): Implement
2001-03-12 Bradford Hovinen <hovinen@ximian.com>
* main.c (store_archive_data): Fix call to location_store_xml

View file

@ -235,34 +235,33 @@ static void
do_set_xml (gboolean apply_settings)
{
xmlDocPtr doc;
Preferences *old_prefs, *new_prefs;
char *buffer = NULL;
int len = 0;
int bytes_read;
while (!feof (stdin)) {
if (!len) buffer = g_new (char, 16384);
else buffer = g_renew (char, buffer, len + 16384);
fread (buffer + len, 1, 16384, stdin);
if (!len) buffer = g_new (char, 16385);
else buffer = g_renew (char, buffer, len + 16385);
bytes_read = fread (buffer + len, 1, 16384, stdin);
buffer[len + bytes_read] = '\0';
len += 16384;
}
doc = xmlParseMemory (buffer, strlen (buffer));
if (len > 0 && bytes_read + len - 16384 > 0) {
doc = xmlParseMemory (buffer, strlen (buffer));
prefs = preferences_read_xml (doc);
old_prefs = preferences_new ();
preferences_load (old_prefs);
new_prefs = preferences_read_xml (doc);
if (new_prefs) {
new_prefs->config_db = old_prefs->config_db;
if (apply_settings)
preferences_save (new_prefs);
else
prefs = new_prefs;
} else {
g_warning ("Error while reading the screensaver config file");
if (prefs && apply_settings) {
preferences_save (prefs);
return;
}
else if (prefs) {
return;
}
}
g_warning ("Error while reading the screensaver config file");
return;
}
int

View file

@ -39,6 +39,13 @@
#include "resources.h"
#include "rc-parse.h"
static gint xml_read_int (xmlNodePtr node);
static xmlNodePtr xml_write_int (gchar *name,
gint number);
static gboolean xml_read_bool (xmlNodePtr node);
static xmlNodePtr xml_write_bool (gchar *name,
gboolean value);
static void
remove_entry (GTree *config_db, gchar *entry)
{
@ -217,12 +224,6 @@ preferences_save (Preferences *prefs)
gnome_config_sync ();
}
static gint
xml_get_number (xmlNodePtr node)
{
return atoi (xmlNodeGetContent (node));
}
static GList *
xml_get_programs_list (xmlNodePtr programs_node)
{
@ -260,39 +261,39 @@ preferences_read_xml (xmlDocPtr xml_doc)
for (node = root_node->childs; node; node = node->next) {
if (!strcmp (node->name, "verbose"))
prefs->verbose = TRUE;
prefs->verbose = xml_read_bool (node);
else if (!strcmp (node->name, "lock"))
prefs->lock = TRUE;
prefs->lock = xml_read_bool (node);
else if (!strcmp (node->name, "fade"))
prefs->fade = TRUE;
prefs->fade = xml_read_bool (node);
else if (!strcmp (node->name, "unfade"))
prefs->unfade = TRUE;
prefs->unfade = xml_read_bool (node);
else if (!strcmp (node->name, "fade-seconds"))
prefs->fade_seconds = xml_get_number (node);
prefs->fade_seconds = xml_read_int (node);
else if (!strcmp (node->name, "fade-ticks"))
prefs->fade_ticks = xml_get_number (node);
prefs->fade_ticks = xml_read_int (node);
else if (!strcmp (node->name, "install-colormap"))
prefs->install_colormap = TRUE;
prefs->install_colormap = xml_read_bool (node);
else if (!strcmp (node->name, "nice"))
prefs->nice = xml_get_number (node);
prefs->nice = xml_read_int (node);
else if (!strcmp (node->name, "timeout"))
prefs->timeout = xml_get_number (node);
prefs->timeout = xml_read_int (node);
else if (!strcmp (node->name, "lock-timeout"))
prefs->lock_timeout = xml_get_number (node);
prefs->lock_timeout = xml_read_int (node);
else if (!strcmp (node->name, "cycle"))
prefs->cycle = xml_get_number (node);
prefs->cycle = xml_read_int (node);
else if (!strcmp (node->name, "programs"))
prefs->screensavers = xml_get_programs_list (node);
else if (!strcmp (node->name, "selection-mode"))
prefs->selection_mode = xml_get_number (node);
prefs->selection_mode = xml_read_int (node);
else if (!strcmp (node->name, "use-dpms"))
prefs->power_management = TRUE;
prefs->power_management = xml_read_bool (node);
else if (!strcmp (node->name, "standby-time"))
prefs->standby_time = xml_get_number (node);
prefs->standby_time = xml_read_int (node);
else if (!strcmp (node->name, "suspend-time"))
prefs->suspend_time = xml_get_number (node);
prefs->suspend_time = xml_read_int (node);
else if (!strcmp (node->name, "shutdown-time"))
prefs->power_down_time = xml_get_number (node);
prefs->power_down_time = xml_read_int (node);
}
return prefs;
@ -317,68 +318,32 @@ preferences_write_xml (Preferences *prefs)
{
xmlDocPtr doc;
xmlNodePtr node;
char *tmp;
doc = xmlNewDoc ("1.0");
node = xmlNewDocNode (doc, NULL, "screensaver-prefs", NULL);
if (prefs->verbose)
xmlNewChild (node, NULL, "verbose", NULL);
if (prefs->lock)
xmlNewChild (node, NULL, "lock", NULL);
if (prefs->fade)
xmlNewChild (node, NULL, "fade", NULL);
if (prefs->unfade)
xmlNewChild (node, NULL, "unfade", NULL);
tmp = g_strdup_printf ("%d", (int) prefs->fade_seconds);
xmlNewChild (node, NULL, "fade-seconds", tmp);
g_free (tmp);
tmp = g_strdup_printf ("%d", prefs->fade_ticks);
xmlNewChild (node, NULL, "fade-ticks", tmp);
g_free (tmp);
if (prefs->install_colormap)
xmlNewChild (node, NULL, "install-colormap", NULL);
tmp = g_strdup_printf ("%d", prefs->nice);
xmlNewChild (node, NULL, "nice", tmp);
g_free (tmp);
tmp = g_strdup_printf ("%d", (int) prefs->timeout);
xmlNewChild (node, NULL, "timeout", tmp);
g_free (tmp);
tmp = g_strdup_printf ("%d", (int) prefs->lock_timeout);
xmlNewChild (node, NULL, "lock-timeout", tmp);
g_free (tmp);
tmp = g_strdup_printf ("%d", (int) prefs->cycle);
xmlNewChild (node, NULL, "cycle", tmp);
g_free (tmp);
xmlAddChild (node, xml_write_bool ("verbose", prefs->verbose));
xmlAddChild (node, xml_write_bool ("lock", prefs->lock));
xmlAddChild (node, xml_write_bool ("fade", prefs->fade));
xmlAddChild (node, xml_write_bool ("unfade", prefs->unfade));
xmlAddChild (node, xml_write_int ("fade-seconds", prefs->fade_seconds));
xmlAddChild (node, xml_write_int ("fade-ticks", prefs->fade_ticks));
xmlAddChild (node, xml_write_bool ("install-colormap",
prefs->install_colormap));
xmlAddChild (node, xml_write_int ("nice", prefs->nice));
xmlAddChild (node, xml_write_int ("timeout", prefs->timeout));
xmlAddChild (node, xml_write_int ("lock-timeout", prefs->lock_timeout));
xmlAddChild (node, xml_write_int ("cycle", prefs->cycle));
xmlAddChild (node, xml_write_programs_list (prefs->screensavers));
tmp = g_strdup_printf ("%d", prefs->selection_mode);
xmlNewChild (node, NULL, "selection-mode", tmp);
g_free (tmp);
if (prefs->power_management)
xmlNewChild (node, NULL, "use-dpms", NULL);
tmp = g_strdup_printf ("%d", (int) prefs->standby_time);
xmlNewChild (node, NULL, "standby-time", tmp);
g_free (tmp);
tmp = g_strdup_printf ("%d", (int) prefs->suspend_time);
xmlNewChild (node, NULL, "suspend-time", tmp);
g_free (tmp);
tmp = g_strdup_printf ("%d", (int) prefs->power_down_time);
xmlNewChild (node, NULL, "shutdown-time", tmp);
g_free (tmp);
xmlAddChild (node, xml_write_int ("selection-mode",
prefs->selection_mode));
xmlAddChild (node, xml_write_bool ("use-dpms",
prefs->power_management));
xmlAddChild (node, xml_write_int ("standby-time", prefs->standby_time));
xmlAddChild (node, xml_write_int ("suspend-time", prefs->suspend_time));
xmlAddChild (node, xml_write_int ("shutdown-time",
prefs->power_down_time));
xmlDocSetRootElement (doc, node);
@ -454,18 +419,18 @@ screensaver_read_xml (xmlNodePtr saver_node)
saver = screensaver_new ();
saver->enabled = FALSE;
saver->label = g_strdup (xmlGetProp (saver_node, "label"));
for (node = saver_node->childs; node; node = node->next) {
if (!strcmp (node->name, "name"))
saver->name = g_strdup (xmlNodeGetContent (node));
else if (!strcmp (node->name, "label"))
saver->label = g_strdup (xmlNodeGetContent (node));
else if (!strcmp (node->name, "command-line"))
saver->command_line =
g_strdup (xmlNodeGetContent (node));
else if (!strcmp (node->name, "visual"))
saver->visual = g_strdup (xmlNodeGetContent (node));
else if (!strcmp (node->name, "enabled"))
saver->enabled = TRUE;
saver->enabled = xml_read_bool (node);
}
return saver;
@ -478,13 +443,11 @@ screensaver_write_xml (Screensaver *saver)
saver_node = xmlNewNode (NULL, "screensaver");
xmlNewProp (saver_node, "label", saver->label);
xmlNewChild (saver_node, NULL, "name", saver->name);
xmlNewChild (saver_node, NULL, "label", saver->label);
xmlNewChild (saver_node, NULL, "command-line", saver->command_line);
xmlNewChild (saver_node, NULL, "visual", saver->visual);
if (saver->enabled)
xmlNewChild (saver_node, NULL, "enabled", NULL);
xmlAddChild (saver_node, xml_write_bool ("enabled", saver->enabled));
return saver_node;
}
@ -527,3 +490,71 @@ screensaver_get_label (gchar *name)
return label;
}
/* Read a numeric value from a node */
static gint
xml_read_int (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (text == NULL)
return 0;
else
return atoi (text);
}
/* Write out a numeric value in a node */
static xmlNodePtr
xml_write_int (gchar *name, gint number)
{
xmlNodePtr node;
gchar *str;
g_return_val_if_fail (name != NULL, NULL);
str = g_strdup_printf ("%d", number);
node = xmlNewNode (NULL, name);
xmlNodeSetContent (node, str);
g_free (str);
return node;
}
/* Read a boolean value from a node */
static gboolean
xml_read_bool (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (!g_strcasecmp (text, "true"))
return TRUE;
else
return FALSE;
}
/* Write out a boolean value in a node */
static xmlNodePtr
xml_write_bool (gchar *name, gboolean value)
{
xmlNodePtr node;
g_return_val_if_fail (name != NULL, NULL);
node = xmlNewNode (NULL, name);
if (value)
xmlNodeSetContent (node, "true");
else
xmlNodeSetContent (node, "false");
return node;
}

View file

@ -1,3 +1,10 @@
2001-04-27 Bradford Hovinen <hovinen@ximian.com>
* preferences.c (category_read_xml): Make description a child node
rather than an attribute
(sound_event_read_xml): Make name an attribute rather than a child
node
2000-10-08 Bradford Hovinen <hovinen@helixcode.com>
* Makefile.am (EXTRA_DIST): Add translation file

View file

@ -121,24 +121,33 @@ static void
do_set_xml (gboolean apply_settings)
{
xmlDocPtr doc;
char *buffer;
char *buffer = NULL;
int len = 0;
int bytes_read = 0;
while (!feof (stdin)) {
if (!len) buffer = g_new (char, 16384);
else buffer = g_renew (char, buffer, len + 16384);
fread (buffer + len, 1, 16384, stdin);
if (!len) buffer = g_new (char, 16385);
else buffer = g_renew (char, buffer, len + 16385);
bytes_read = fread (buffer + len, 1, 16384, stdin);
buffer[len + bytes_read] = '\0';
len += 16384;
}
doc = xmlParseMemory (buffer, strlen (buffer));
if (len > 0 && bytes_read + len - 16384 > 0) {
doc = xmlParseMemory (buffer, strlen (buffer));
prefs = preferences_read_xml (doc);
prefs = preferences_read_xml (doc);
if (prefs && apply_settings) {
preferences_save (prefs);
return;
}
else if (prefs) {
return;
}
}
if (prefs && apply_settings)
preferences_save (prefs);
else if (prefs == NULL)
g_warning ("Error while reading the screensaver config file");
g_warning ("Error while reading the sound config file");
return;
}
int

View file

@ -42,11 +42,12 @@ typedef struct _triple_t { gpointer a; gpointer b; gpointer c; } triple_t;
static void preferences_init (Preferences *prefs);
static void preferences_class_init (PreferencesClass *class);
static gint xml_read_int (xmlNodePtr node,
gchar *propname);
static gint xml_read_int (xmlNodePtr node);
static xmlNodePtr xml_write_int (gchar *name,
gchar *propname,
gint number);
static gboolean xml_read_bool (xmlNodePtr node);
static xmlNodePtr xml_write_bool (gchar *name,
gboolean value);
static gint apply_timeout_cb (Preferences *prefs);
@ -325,9 +326,9 @@ preferences_read_xml (xmlDocPtr xml_doc)
for (node = root_node->childs; node; node = node->next) {
if (!strcmp (node->name, "enable-esd"))
prefs->enable_esd = TRUE;
prefs->enable_esd = xml_read_bool (node);
else if (!strcmp (node->name, "enable-sound-events"))
prefs->enable_sound_events = TRUE;
prefs->enable_sound_events = xml_read_bool (node);
else if (!strcmp (node->name, "categories"))
read_sound_events_from_xml (node, prefs->categories);
}
@ -345,11 +346,9 @@ preferences_write_xml (Preferences *prefs)
node = xmlNewDocNode (doc, NULL, "sound-properties", NULL);
if (prefs->enable_esd)
xmlNewChild (node, NULL, "enable-esd", NULL);
if (prefs->enable_sound_events)
xmlNewChild (node, NULL, "enable-sound-events", NULL);
xmlAddChild (node, xml_write_bool ("enable-esd", prefs->enable_esd));
xmlAddChild (node, xml_write_bool ("enable-sound-events",
prefs->enable_sound_events));
xmlAddChild (node, write_sound_events_to_xml (prefs->categories));
xmlDocSetRootElement (doc, node);
@ -711,10 +710,11 @@ category_read_xml (xmlNodePtr cat_node)
category = category_new ();
category->file = xmlGetProp (cat_node, "file");
category->description = xmlGetProp (cat_node, "description");
for (node = cat_node->childs; node; node = node->next) {
if (!strcmp (node->name, "event")) {
if (!strcmp (node->name, "description"))
category->description = xmlNodeGetContent (node);
else if (!strcmp (node->name, "event")) {
event = sound_event_read_xml (node);
list_tail = g_list_append (list_tail, event);
if (list_head == NULL)
@ -745,7 +745,7 @@ category_write_xml (Category *category)
node = xmlNewNode (NULL, "category");
xmlNewProp (node, "file", category->file);
xmlNewProp (node, "description", category->description);
xmlNewChild (node, NULL, "description", category->description);
g_tree_traverse (category->events,
(GTraverseFunc) event_tree_write_xml_cb, G_IN_ORDER,
@ -808,7 +808,7 @@ sound_event_write_xml (SoundEvent *event)
g_return_val_if_fail (event->name != NULL, NULL);
node = xmlNewNode (NULL, "event");
xmlNewChild (node, NULL, "name", event->name);
xmlNewProp (node, "name", event->name);
if (event->file != NULL)
xmlNewChild (node, NULL, "file", event->file);
@ -826,11 +826,10 @@ sound_event_read_xml (xmlNodePtr event_node)
return NULL;
event = sound_event_new ();
event->name = g_strdup (xmlGetProp (event_node, "name"));
for (node = event_node->childs; node; node = node->next) {
if (!strcmp (node->name, "name"))
event->name = g_strdup (xmlNodeGetContent (node));
else if (!strcmp (node->name, "file"))
if (!strcmp (node->name, "file"))
event->file = g_strdup (xmlNodeGetContent (node));
}
@ -840,14 +839,11 @@ sound_event_read_xml (xmlNodePtr event_node)
/* Read a numeric value from a node */
static gint
xml_read_int (xmlNodePtr node, char *propname)
xml_read_int (xmlNodePtr node)
{
char *text;
if (propname == NULL)
text = xmlNodeGetContent (node);
else
text = xmlGetProp (node, propname);
text = xmlNodeGetContent (node);
if (text == NULL)
return 0;
@ -858,7 +854,7 @@ xml_read_int (xmlNodePtr node, char *propname)
/* Write out a numeric value in a node */
static xmlNodePtr
xml_write_int (gchar *name, gchar *propname, gint number)
xml_write_int (gchar *name, gint number)
{
xmlNodePtr node;
gchar *str;
@ -866,15 +862,43 @@ xml_write_int (gchar *name, gchar *propname, gint number)
g_return_val_if_fail (name != NULL, NULL);
str = g_strdup_printf ("%d", number);
node = xmlNewNode (NULL, name);
xmlNodeSetContent (node, str);
g_free (str);
return node;
}
/* Read a boolean value from a node */
static gboolean
xml_read_bool (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (!g_strcasecmp (text, "true"))
return TRUE;
else
return FALSE;
}
/* Write out a boolean value in a node */
static xmlNodePtr
xml_write_bool (gchar *name, gboolean value)
{
xmlNodePtr node;
g_return_val_if_fail (name != NULL, NULL);
node = xmlNewNode (NULL, name);
if (propname == NULL)
xmlNodeSetContent (node, str);
if (value)
xmlNodeSetContent (node, "true");
else
xmlSetProp (node, propname, str);
g_free (str);
xmlNodeSetContent (node, "false");
return node;
}

View file

@ -122,22 +122,31 @@ do_set_xml (gboolean apply_settings)
xmlDocPtr doc;
char *buffer = NULL;
int len = 0;
int bytes_read = 0;
while (!feof (stdin)) {
if (!len) buffer = g_new (char, 16384);
else buffer = g_renew (char, buffer, len + 16384);
fread (buffer + len, 1, 16384, stdin);
if (!len) buffer = g_new (char, 16385);
else buffer = g_renew (char, buffer, len + 16385);
bytes_read = fread (buffer + len, 1, 16384, stdin);
buffer[len + bytes_read] = '\0';
len += 16384;
}
doc = xmlParseMemory (buffer, strlen (buffer));
if (len > 0 && bytes_read + len - 16384 > 0) {
doc = xmlParseMemory (buffer, strlen (buffer));
prefs = preferences_read_xml (doc);
prefs = preferences_read_xml (doc);
if (prefs && apply_settings) {
preferences_save (prefs);
return;
}
else if (prefs) {
return;
}
}
if (prefs && apply_settings)
preferences_save (prefs);
else if (prefs == NULL)
g_warning ("Error while reading the screensaver config file");
g_warning ("Error while reading the ui config file");
return;
}
int

View file

@ -36,11 +36,12 @@ static GtkObjectClass *parent_class;
static void preferences_init (Preferences *prefs);
static void preferences_class_init (PreferencesClass *class);
static gint xml_read_int (xmlNodePtr node,
gchar *propname);
static gint xml_read_int (xmlNodePtr node);
static xmlNodePtr xml_write_int (gchar *name,
gchar *propname,
gint number);
static gboolean xml_read_bool (xmlNodePtr node);
static xmlNodePtr xml_write_bool (gchar *name,
gboolean value);
static gint apply_timeout_cb (Preferences *prefs);
@ -216,57 +217,72 @@ preferences_read_xml (xmlDocPtr xml_doc)
for (node = root_node->childs; node; node = node->next) {
if (!strcmp (node->name, "dialog-buttons-style"))
prefs->gnome_prefs->dialog_buttons_style =
xml_read_int (node, "style");
xml_read_int (node);
else if (!strcmp (node->name, "property-box-buttons-ok"))
prefs->gnome_prefs->property_box_buttons_ok = TRUE;
prefs->gnome_prefs->property_box_buttons_ok =
xml_read_bool (node);
else if (!strcmp (node->name, "property-box-buttons-apply"))
prefs->gnome_prefs->property_box_buttons_apply = TRUE;
prefs->gnome_prefs->property_box_buttons_apply =
xml_read_bool (node);
else if (!strcmp (node->name, "property-box-buttons-close"))
prefs->gnome_prefs->property_box_buttons_close = TRUE;
prefs->gnome_prefs->property_box_buttons_close =
xml_read_bool (node);
else if (!strcmp (node->name, "property-box-buttons-help"))
prefs->gnome_prefs->property_box_buttons_help = TRUE;
prefs->gnome_prefs->property_box_buttons_help =
xml_read_bool (node);
else if (!strcmp (node->name, "statusbar-not-dialog"))
prefs->gnome_prefs->statusbar_not_dialog = TRUE;
prefs->gnome_prefs->statusbar_not_dialog =
xml_read_bool (node);
else if (!strcmp (node->name, "statusbar-is-interactive"))
prefs->gnome_prefs->statusbar_is_interactive = TRUE;
prefs->gnome_prefs->statusbar_is_interactive =
xml_read_bool (node);
else if (!strcmp (node->name, "statusbar-meter-on-right"))
prefs->gnome_prefs->statusbar_meter_on_right = TRUE;
prefs->gnome_prefs->statusbar_meter_on_right =
xml_read_bool (node);
else if (!strcmp (node->name, "menubar-detachable"))
prefs->gnome_prefs->menubar_detachable = TRUE;
prefs->gnome_prefs->menubar_detachable =
xml_read_bool (node);
else if (!strcmp (node->name, "menubar-relief"))
prefs->gnome_prefs->menubar_relief = TRUE;
prefs->gnome_prefs->menubar_relief =
xml_read_bool (node);
else if (!strcmp (node->name, "toolbar-detachable"))
prefs->gnome_prefs->toolbar_detachable = TRUE;
prefs->gnome_prefs->toolbar_detachable =
xml_read_bool (node);
else if (!strcmp (node->name, "toolbar-relief"))
prefs->gnome_prefs->toolbar_relief = TRUE;
prefs->gnome_prefs->toolbar_relief =
xml_read_bool (node);
else if (!strcmp (node->name, "toolbar-relief-btn"))
prefs->gnome_prefs->toolbar_relief_btn = TRUE;
prefs->gnome_prefs->toolbar_relief_btn =
xml_read_bool (node);
else if (!strcmp (node->name, "toolbar-lines"))
prefs->gnome_prefs->toolbar_lines = TRUE;
prefs->gnome_prefs->toolbar_lines =
xml_read_bool (node);
else if (!strcmp (node->name, "toolbar-labels"))
prefs->gnome_prefs->toolbar_labels = TRUE;
prefs->gnome_prefs->toolbar_labels =
xml_read_bool (node);
else if (!strcmp (node->name, "dialog-centered"))
prefs->gnome_prefs->dialog_centered = TRUE;
prefs->gnome_prefs->dialog_centered =
xml_read_bool (node);
else if (!strcmp (node->name, "menus-have-tearoff"))
prefs->gnome_prefs->menus_have_tearoff = TRUE;
prefs->gnome_prefs->menus_have_tearoff =
xml_read_bool (node);
else if (!strcmp (node->name, "menus-have-icons"))
prefs->gnome_prefs->menus_have_icons = TRUE;
prefs->gnome_prefs->menus_have_icons =
xml_read_bool (node);
else if (!strcmp (node->name, "disable-imlib-cache"))
prefs->gnome_prefs->disable_imlib_cache = TRUE;
prefs->gnome_prefs->disable_imlib_cache =
xml_read_bool (node);
else if (!strcmp (node->name, "dialog-type"))
prefs->gnome_prefs->dialog_type =
xml_read_int (node, "type");
prefs->gnome_prefs->dialog_type = xml_read_int (node);
else if (!strcmp (node->name, "dialog-position"))
prefs->gnome_prefs->dialog_position =
xml_read_int (node, "position");
prefs->gnome_prefs->dialog_position =
xml_read_int (node);
else if (!strcmp (node->name, "mdi-mode"))
prefs->gnome_prefs->mdi_mode =
xml_read_int (node, "mode");
prefs->gnome_prefs->mdi_mode = xml_read_int (node);
else if (!strcmp (node->name, "mdi-tab-pos"))
prefs->gnome_prefs->mdi_tab_pos =
xml_read_int (node, "pos");
prefs->gnome_prefs->mdi_tab_pos = xml_read_int (node);
else if (!strcmp (node->name, "dialog-use-icons"))
prefs->dialog_use_icons = TRUE;
prefs->dialog_use_icons = xml_read_bool (node);
}
return prefs;
@ -283,61 +299,80 @@ preferences_write_xml (Preferences *prefs)
node = xmlNewDocNode (doc, NULL, "ui-properties", NULL);
xmlAddChild (node,
xml_write_int ("dialog-buttons-style", "style",
xml_write_int ("dialog-buttons-style",
prefs->gnome_prefs->dialog_buttons_style));
if (prefs->gnome_prefs->property_box_buttons_ok)
xmlNewChild (node, NULL, "property-box-buttons-ok", NULL);
if (prefs->gnome_prefs->property_box_buttons_apply)
xmlNewChild (node, NULL, "property-box-buttons-apply", NULL);
if (prefs->gnome_prefs->property_box_buttons_close)
xmlNewChild (node, NULL, "property-box-buttons-close", NULL);
if (prefs->gnome_prefs->property_box_buttons_help)
xmlNewChild (node, NULL, "property-box-buttons-help", NULL);
if (prefs->gnome_prefs->statusbar_not_dialog)
xmlNewChild (node, NULL, "statusbar-not-dialog", NULL);
if (prefs->gnome_prefs->statusbar_is_interactive)
xmlNewChild (node, NULL, "statusbar-is-interactive", NULL);
if (prefs->gnome_prefs->statusbar_meter_on_right)
xmlNewChild (node, NULL, "statusbar-meter-on-right", NULL);
if (prefs->gnome_prefs->menubar_detachable)
xmlNewChild (node, NULL, "menubar-detachable", NULL);
if (prefs->gnome_prefs->menubar_relief)
xmlNewChild (node, NULL, "menubar-relief", NULL);
if (prefs->gnome_prefs->toolbar_detachable)
xmlNewChild (node, NULL, "toolbar-detachable", NULL);
if (prefs->gnome_prefs->toolbar_relief)
xmlNewChild (node, NULL, "toolbar-relief", NULL);
if (prefs->gnome_prefs->toolbar_relief_btn)
xmlNewChild (node, NULL, "toolbar-relief-btn", NULL);
if (prefs->gnome_prefs->toolbar_lines)
xmlNewChild (node, NULL, "toolbar-lines", NULL);
if (prefs->gnome_prefs->toolbar_labels)
xmlNewChild (node, NULL, "toolbar-labels", NULL);
if (prefs->gnome_prefs->dialog_centered)
xmlNewChild (node, NULL, "dialog-centered", NULL);
if (prefs->gnome_prefs->menus_have_tearoff)
xmlNewChild (node, NULL, "menus-have-tearoff", NULL);
if (prefs->gnome_prefs->menus_have_icons)
xmlNewChild (node, NULL, "menus-have-icons", NULL);
if (prefs->gnome_prefs->disable_imlib_cache)
xmlNewChild (node, NULL, "disable-imlib-cache", NULL);
xmlAddChild (node,
xml_write_bool ("property-box-buttons-ok",
prefs->gnome_prefs->property_box_buttons_ok));
xmlAddChild (node,
xml_write_bool ("property-box-buttons-apply",
prefs->gnome_prefs->property_box_buttons_apply));
xmlAddChild (node,
xml_write_bool ("property-box-buttons-close",
prefs->gnome_prefs->property_box_buttons_close));
xmlAddChild (node,
xml_write_bool ("property-box-buttons-help",
prefs->gnome_prefs->property_box_buttons_help));
xmlAddChild (node,
xml_write_bool ("statusbar-not-dialog",
prefs->gnome_prefs->statusbar_not_dialog));
xmlAddChild (node,
xml_write_bool ("statusbar-is-interactive",
prefs->gnome_prefs->statusbar_is_interactive));
xmlAddChild (node,
xml_write_bool ("statusbar-meter-on-right",
prefs->gnome_prefs->statusbar_meter_on_right));
xmlAddChild (node,
xml_write_bool ("menubar-detachable",
prefs->gnome_prefs->menubar_detachable));
xmlAddChild (node,
xml_write_bool ("menubar-relief",
prefs->gnome_prefs->menubar_relief));
xmlAddChild (node,
xml_write_bool ("toolbar-detachable",
prefs->gnome_prefs->toolbar_detachable));
xmlAddChild (node,
xml_write_bool ("toolbar-relief",
prefs->gnome_prefs->toolbar_relief));
xmlAddChild (node,
xml_write_bool ("toolbar-relief-btn",
prefs->gnome_prefs->toolbar_relief_btn));
xmlAddChild (node,
xml_write_bool ("toolbar-lines",
prefs->gnome_prefs->toolbar_lines));
xmlAddChild (node,
xml_write_bool ("toolbar-labels",
prefs->gnome_prefs->toolbar_labels));
xmlAddChild (node,
xml_write_bool ("dialog-centered",
prefs->gnome_prefs->dialog_centered));
xmlAddChild (node,
xml_write_bool ("menus-have-tearoff",
prefs->gnome_prefs->menus_have_tearoff));
xmlAddChild (node,
xml_write_bool ("menus-have-icons",
prefs->gnome_prefs->menus_have_icons));
xmlAddChild (node,
xml_write_bool ("disable-imlib-cache",
prefs->gnome_prefs->disable_imlib_cache));
xmlAddChild (node,
xml_write_int ("dialog-type", "type",
xml_write_int ("dialog-type",
prefs->gnome_prefs->dialog_type));
xmlAddChild (node,
xml_write_int ("dialog-position", "position",
xml_write_int ("dialog-position",
prefs->gnome_prefs->dialog_position));
xmlAddChild (node,
xml_write_int ("mdi-mode", "mode",
xml_write_int ("mdi-mode",
prefs->gnome_prefs->mdi_mode));
xmlAddChild (node,
xml_write_int ("mdi-tab-pos", "pos",
xml_write_int ("mdi-tab-pos",
prefs->gnome_prefs->mdi_tab_pos));
if (prefs->dialog_use_icons)
xmlNewChild (node, NULL, "dialog-use-icons", NULL);
xmlAddChild (node,
xml_write_bool ("dialog-use-icons",
prefs->dialog_use_icons));
xmlDocSetRootElement (doc, node);
@ -347,14 +382,11 @@ preferences_write_xml (Preferences *prefs)
/* Read a numeric value from a node */
static gint
xml_read_int (xmlNodePtr node, char *propname)
xml_read_int (xmlNodePtr node)
{
char *text;
if (propname == NULL)
text = xmlNodeGetContent (node);
else
text = xmlGetProp (node, propname);
text = xmlNodeGetContent (node);
if (text == NULL)
return 0;
@ -365,7 +397,7 @@ xml_read_int (xmlNodePtr node, char *propname)
/* Write out a numeric value in a node */
static xmlNodePtr
xml_write_int (gchar *name, gchar *propname, gint number)
xml_write_int (gchar *name, gint number)
{
xmlNodePtr node;
gchar *str;
@ -373,15 +405,43 @@ xml_write_int (gchar *name, gchar *propname, gint number)
g_return_val_if_fail (name != NULL, NULL);
str = g_strdup_printf ("%d", number);
node = xmlNewNode (NULL, name);
xmlNodeSetContent (node, str);
g_free (str);
return node;
}
/* Read a boolean value from a node */
static gboolean
xml_read_bool (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (!g_strcasecmp (text, "true"))
return TRUE;
else
return FALSE;
}
/* Write out a boolean value in a node */
static xmlNodePtr
xml_write_bool (gchar *name, gboolean value)
{
xmlNodePtr node;
g_return_val_if_fail (name != NULL, NULL);
node = xmlNewNode (NULL, name);
if (propname == NULL)
xmlNodeSetContent (node, str);
if (value)
xmlNodeSetContent (node, "true");
else
xmlSetProp (node, propname, str);
g_free (str);
xmlNodeSetContent (node, "false");
return node;
}

View file

@ -24,6 +24,10 @@ static WindowManager *current_wm = NULL;
/* Window manager on startup */
static WindowManager *current_wm_save = NULL;
static gboolean xml_read_bool (xmlNodePtr node);
static xmlNodePtr xml_write_bool (gchar *name,
gboolean value);
gboolean
is_blank (gchar *str)
{
@ -417,21 +421,20 @@ wm_read_from_xml (xmlNodePtr wm_node)
wm = g_new0 (WindowManager, 1);
wm->dentry = gnome_desktop_entry_load_unconditional
(xmlGetProp (wm_node, "desktop-entry"));
for (node = wm_node->childs; node; node = node->next) {
if (!strcmp (node->name, "desktop-entry"))
wm->dentry =
gnome_desktop_entry_load_unconditional
(xmlNodeGetContent (node));
else if (!strcmp (node->name, "config-exec"))
if (!strcmp (node->name, "config-exec"))
wm->config_exec = xmlNodeGetContent (node);
else if (!strcmp (node->name, "config-tryexec"))
wm->config_tryexec = xmlNodeGetContent (node);
else if (!strcmp (node->name, "session-managed"))
wm->session_managed = TRUE;
wm->session_managed = xml_read_bool (node);
else if (!strcmp (node->name, "is-user"))
wm->is_user = TRUE;
wm->is_user = xml_read_bool (node);
else if (!strcmp (node->name, "is-current"))
is_current = TRUE; /* FIXME: sanity check */
is_current = xml_read_bool (node); /* FIXME: sanity check */
}
wm_check_present (wm);
@ -476,19 +479,16 @@ wm_write_to_xml (WindowManager *wm)
node = xmlNewNode (NULL, "window-manager");
xmlNewChild (node, NULL, "desktop-entry", wm->dentry->location);
xmlNewProp (node, "desktop-entry", wm->dentry->location);
if (wm->config_exec != NULL)
xmlNewChild (node, NULL, "config-exec", wm->config_exec);
if (wm->session_managed)
xmlNewChild (node, NULL, "session-managed", NULL);
xmlAddChild (node, xml_write_bool ("session-managed",
wm->session_managed));
if (wm->is_user)
xmlNewChild (node, NULL, "is-user", NULL);
if (wm == current_wm)
xmlNewChild (node, NULL, "is-current", NULL);
xmlAddChild (node, xml_write_bool ("is-user", wm->is_user));
xmlAddChild (node, xml_write_bool ("is-current", wm == current_wm));
return node;
}
@ -512,3 +512,37 @@ wm_list_write_to_xml (void)
return doc;
}
/* Read a boolean value from a node */
static gboolean
xml_read_bool (xmlNodePtr node)
{
char *text;
text = xmlNodeGetContent (node);
if (!g_strcasecmp (text, "true"))
return TRUE;
else
return FALSE;
}
/* Write out a boolean value in a node */
static xmlNodePtr
xml_write_bool (gchar *name, gboolean value)
{
xmlNodePtr node;
g_return_val_if_fail (name != NULL, NULL);
node = xmlNewNode (NULL, name);
if (value)
xmlNodeSetContent (node, "true");
else
xmlNodeSetContent (node, "false");
return node;
}