be more careful when reading background information from GConf and make
2007-11-03 Jens Granseuer <jensgr@gmx.net> * appearance-desktop.c: (wp_color_changed), (wp_props_wp_set): * gnome-wp-item.c: (gnome_wp_item_new), (gnome_wp_item_free), (gnome_wp_item_dup): * gnome-wp-item.h: * gnome-wp-xml.c: (gnome_wp_xml_load_xml), (gnome_wp_xml_save_list): be more careful when reading background information from GConf and make sure we don't choke on NULL values later on (bug #492903) svn path=/trunk/; revision=8249
This commit is contained in:
parent
071af09ea6
commit
73ed731cc2
5 changed files with 78 additions and 62 deletions
|
@ -1,3 +1,13 @@
|
|||
2007-11-03 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
* appearance-desktop.c: (wp_color_changed), (wp_props_wp_set):
|
||||
* gnome-wp-item.c: (gnome_wp_item_new), (gnome_wp_item_free),
|
||||
(gnome_wp_item_dup):
|
||||
* gnome-wp-item.h:
|
||||
* gnome-wp-xml.c: (gnome_wp_xml_load_xml), (gnome_wp_xml_save_list):
|
||||
be more careful when reading background information from GConf and make
|
||||
sure we don't choke on NULL values later on (bug #492903)
|
||||
|
||||
2007-11-01 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
Patch by: Joel Pfaff <joel.pfaff@gmail.com>
|
||||
|
|
|
@ -401,24 +401,19 @@ wp_color_changed (AppearanceData *data,
|
|||
if (item == NULL)
|
||||
return;
|
||||
|
||||
g_free (item->pri_color);
|
||||
|
||||
gtk_color_button_get_color (GTK_COLOR_BUTTON (data->wp_pcpicker), item->pcolor);
|
||||
|
||||
item->pri_color = gdk_color_to_string (item->pcolor);
|
||||
|
||||
g_free (item->sec_color);
|
||||
|
||||
gtk_color_button_get_color (GTK_COLOR_BUTTON (data->wp_scpicker), item->scolor);
|
||||
|
||||
item->sec_color = gdk_color_to_string (item->scolor);
|
||||
|
||||
if (update)
|
||||
{
|
||||
gconf_client_set_string (data->client, WP_PCOLOR_KEY,
|
||||
item->pri_color, NULL);
|
||||
gconf_client_set_string (data->client, WP_SCOLOR_KEY,
|
||||
item->sec_color, NULL);
|
||||
gchar *pcolor, *scolor;
|
||||
|
||||
pcolor = gdk_color_to_string (item->pcolor);
|
||||
scolor = gdk_color_to_string (item->scolor);
|
||||
gconf_client_set_string (data->client, WP_PCOLOR_KEY, pcolor, NULL);
|
||||
gconf_client_set_string (data->client, WP_SCOLOR_KEY, scolor, NULL);
|
||||
g_free (pcolor);
|
||||
g_free (scolor);
|
||||
}
|
||||
|
||||
wp_shade_type_changed (NULL, data);
|
||||
|
@ -583,6 +578,7 @@ static gboolean
|
|||
wp_props_wp_set (AppearanceData *data, GnomeWPItem *item)
|
||||
{
|
||||
GConfChangeSet *cs;
|
||||
gchar *pcolor, *scolor;
|
||||
|
||||
cs = gconf_change_set_new ();
|
||||
|
||||
|
@ -612,8 +608,12 @@ wp_props_wp_set (AppearanceData *data, GnomeWPItem *item)
|
|||
|
||||
gconf_change_set_set_string (cs, WP_SHADING_KEY, item->shade_type);
|
||||
|
||||
gconf_change_set_set_string (cs, WP_PCOLOR_KEY, item->pri_color);
|
||||
gconf_change_set_set_string (cs, WP_SCOLOR_KEY, item->sec_color);
|
||||
pcolor = gdk_color_to_string (item->pcolor);
|
||||
scolor = gdk_color_to_string (item->scolor);
|
||||
gconf_change_set_set_string (cs, WP_PCOLOR_KEY, pcolor);
|
||||
gconf_change_set_set_string (cs, WP_SCOLOR_KEY, scolor);
|
||||
g_free (pcolor);
|
||||
g_free (scolor);
|
||||
|
||||
gconf_client_commit_change_set (data->client, cs, TRUE, NULL);
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@ GnomeWPItem * gnome_wp_item_new (const gchar * filename,
|
|||
GHashTable * wallpapers,
|
||||
GnomeThumbnailFactory * thumbnails) {
|
||||
GnomeWPItem * item = NULL;
|
||||
GdkColor color1, color2;
|
||||
GdkColor color1 = { 0, 0, 0, 0 }, color2 = { 0, 0, 0, 0 };
|
||||
gchar * col_str;
|
||||
GConfClient * client;
|
||||
|
||||
client = gconf_client_get_default ();
|
||||
|
@ -44,18 +45,8 @@ GnomeWPItem * gnome_wp_item_new (const gchar * filename,
|
|||
|
||||
item->fileinfo = gnome_wp_info_new (item->filename, thumbnails);
|
||||
|
||||
item->shade_type = gconf_client_get_string (client, WP_SHADING_KEY, NULL);
|
||||
item->pri_color = gconf_client_get_string (client, WP_PCOLOR_KEY, NULL);
|
||||
item->sec_color = gconf_client_get_string (client, WP_SCOLOR_KEY, NULL);
|
||||
|
||||
gdk_color_parse (item->pri_color, &color1);
|
||||
gdk_color_parse (item->sec_color, &color2);
|
||||
|
||||
item->pcolor = gdk_color_copy (&color1);
|
||||
item->scolor = gdk_color_copy (&color2);
|
||||
|
||||
if (item->fileinfo != NULL &&
|
||||
!strncmp (item->fileinfo->mime_type, "image/", strlen ("image/"))) {
|
||||
!strcmp (item->fileinfo->mime_type, "image/")) {
|
||||
if (item->name == NULL) {
|
||||
if (g_utf8_validate (item->fileinfo->name, -1, NULL))
|
||||
item->name = g_strdup (item->fileinfo->name);
|
||||
|
@ -63,11 +54,32 @@ GnomeWPItem * gnome_wp_item_new (const gchar * filename,
|
|||
item->name = g_filename_to_utf8 (item->fileinfo->name, -1, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
item->options = gconf_client_get_string (client, WP_OPTIONS_KEY, NULL);
|
||||
|
||||
if (!strcmp (item->options, "none")) {
|
||||
item->options = gconf_client_get_string (client, WP_OPTIONS_KEY, NULL);
|
||||
if (item->options == NULL || !strcmp (item->options, "none")) {
|
||||
g_free (item->options);
|
||||
item->options = g_strdup ("scaled");
|
||||
}
|
||||
|
||||
item->shade_type = gconf_client_get_string (client, WP_SHADING_KEY, NULL);
|
||||
if (item->shade_type == NULL)
|
||||
item->shade_type = g_strdup ("solid");
|
||||
|
||||
col_str = gconf_client_get_string (client, WP_PCOLOR_KEY, NULL);
|
||||
if (col_str != NULL) {
|
||||
gdk_color_parse (col_str, &color1);
|
||||
g_free (col_str);
|
||||
}
|
||||
|
||||
col_str = gconf_client_get_string (client, WP_SCOLOR_KEY, NULL);
|
||||
if (col_str != NULL) {
|
||||
gdk_color_parse (col_str, &color2);
|
||||
g_free (col_str);
|
||||
}
|
||||
|
||||
item->pcolor = gdk_color_copy (&color1);
|
||||
item->scolor = gdk_color_copy (&color2);
|
||||
|
||||
gnome_wp_item_update_description (item);
|
||||
|
||||
g_hash_table_insert (wallpapers, item->filename, item);
|
||||
|
@ -92,9 +104,6 @@ void gnome_wp_item_free (GnomeWPItem * item) {
|
|||
g_free (item->options);
|
||||
g_free (item->shade_type);
|
||||
|
||||
g_free (item->pri_color);
|
||||
g_free (item->sec_color);
|
||||
|
||||
if (item->pcolor != NULL)
|
||||
gdk_color_free (item->pcolor);
|
||||
|
||||
|
@ -111,7 +120,6 @@ void gnome_wp_item_free (GnomeWPItem * item) {
|
|||
|
||||
GnomeWPItem * gnome_wp_item_dup (GnomeWPItem * item) {
|
||||
GnomeWPItem * new_item;
|
||||
GdkColor color1, color2;
|
||||
|
||||
if (item == NULL) {
|
||||
return NULL;
|
||||
|
@ -125,14 +133,8 @@ GnomeWPItem * gnome_wp_item_dup (GnomeWPItem * item) {
|
|||
new_item->options = g_strdup (item->options);
|
||||
new_item->shade_type = g_strdup (item->shade_type);
|
||||
|
||||
new_item->pri_color = g_strdup (item->pri_color);
|
||||
new_item->sec_color = g_strdup (item->sec_color);
|
||||
|
||||
gdk_color_parse (item->pri_color, &color1);
|
||||
gdk_color_parse (item->sec_color, &color2);
|
||||
|
||||
item->pcolor = gdk_color_copy (&color1);
|
||||
item->scolor = gdk_color_copy (&color2);
|
||||
new_item->pcolor = gdk_color_copy (item->pcolor);
|
||||
new_item->scolor = gdk_color_copy (item->scolor);
|
||||
|
||||
new_item->fileinfo = gnome_wp_info_dup (item->fileinfo);
|
||||
new_item->uriinfo = gnome_wp_info_dup (item->uriinfo);
|
||||
|
|
|
@ -36,8 +36,6 @@ struct _GnomeWPItem {
|
|||
gchar * description;
|
||||
gchar * options;
|
||||
gchar * shade_type;
|
||||
gchar * pri_color;
|
||||
gchar * sec_color;
|
||||
|
||||
/* Where the Item is in the List */
|
||||
GtkTreeRowReference * rowref;
|
||||
|
|
|
@ -118,6 +118,7 @@ static void gnome_wp_xml_load_xml (AppearanceData *data,
|
|||
for (list = root->children; list != NULL; list = list->next) {
|
||||
if (!strcmp ((gchar *)list->name, "wallpaper")) {
|
||||
GnomeWPItem * wp;
|
||||
gchar *pcolor = NULL, *scolor = NULL;
|
||||
|
||||
wp = g_new0 (GnomeWPItem, 1);
|
||||
|
||||
|
@ -172,11 +173,11 @@ static void gnome_wp_xml_load_xml (AppearanceData *data,
|
|||
}
|
||||
} else if (!strcmp ((gchar *)wpa->name, "pcolor")) {
|
||||
if (wpa->last != NULL) {
|
||||
wp->pri_color = g_strdup (g_strstrip ((gchar *)wpa->last->content));
|
||||
pcolor = g_strdup (g_strstrip ((gchar *)wpa->last->content));
|
||||
}
|
||||
} else if (!strcmp ((gchar *)wpa->name, "scolor")) {
|
||||
if (wpa->last != NULL) {
|
||||
wp->sec_color = g_strdup (g_strstrip ((gchar *)wpa->last->content));
|
||||
scolor = g_strdup (g_strstrip ((gchar *)wpa->last->content));
|
||||
}
|
||||
} else if (!strcmp ((gchar *)wpa->name, "text")) {
|
||||
/* Do nothing here, libxml2 is being weird */
|
||||
|
@ -186,15 +187,12 @@ static void gnome_wp_xml_load_xml (AppearanceData *data,
|
|||
}
|
||||
|
||||
/* Make sure we don't already have this one and that filename exists */
|
||||
if (wp->filename != NULL) {
|
||||
item = g_hash_table_lookup (data->wp_hash, wp->filename);
|
||||
if (wp->filename == NULL ||
|
||||
g_hash_table_lookup (data->wp_hash, wp->filename) != NULL) {
|
||||
|
||||
if (item != NULL) {
|
||||
gnome_wp_item_free (wp);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
gnome_wp_item_free (wp);
|
||||
g_free (pcolor);
|
||||
g_free (scolor);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -203,16 +201,18 @@ static void gnome_wp_xml_load_xml (AppearanceData *data,
|
|||
wp->shade_type = gconf_client_get_string (data->client,
|
||||
WP_SHADING_KEY, NULL);
|
||||
}
|
||||
if (wp->pri_color == NULL) {
|
||||
wp->pri_color = gconf_client_get_string (data->client,
|
||||
WP_PCOLOR_KEY, NULL);
|
||||
if (pcolor == NULL) {
|
||||
pcolor = gconf_client_get_string (data->client,
|
||||
WP_PCOLOR_KEY, NULL);
|
||||
}
|
||||
if (wp->sec_color == NULL) {
|
||||
wp->sec_color = gconf_client_get_string (data->client,
|
||||
WP_SCOLOR_KEY, NULL);
|
||||
if (scolor == NULL) {
|
||||
scolor = gconf_client_get_string (data->client,
|
||||
WP_SCOLOR_KEY, NULL);
|
||||
}
|
||||
gdk_color_parse (wp->pri_color, &color1);
|
||||
gdk_color_parse (wp->sec_color, &color2);
|
||||
gdk_color_parse (pcolor, &color1);
|
||||
gdk_color_parse (scolor, &color2);
|
||||
g_free (pcolor);
|
||||
g_free (scolor);
|
||||
|
||||
wp->pcolor = gdk_color_copy (&color1);
|
||||
wp->scolor = gdk_color_copy (&color2);
|
||||
|
@ -379,6 +379,7 @@ void gnome_wp_xml_save_list (AppearanceData *data) {
|
|||
GnomeWPItem * wpitem = list->data;
|
||||
const char * none = "(none)";
|
||||
gchar * filename;
|
||||
gchar * pcolor, * scolor;
|
||||
|
||||
if (!strcmp (wpitem->filename, none) ||
|
||||
(g_utf8_validate (wpitem->filename, -1, NULL) &&
|
||||
|
@ -387,14 +388,19 @@ void gnome_wp_xml_save_list (AppearanceData *data) {
|
|||
else
|
||||
filename = g_filename_to_utf8 (wpitem->filename, -1, NULL, NULL, NULL);
|
||||
|
||||
pcolor = gdk_color_to_string (wpitem->pcolor);
|
||||
scolor = gdk_color_to_string (wpitem->scolor);
|
||||
|
||||
wallpaper = xmlNewChild (root, NULL, (xmlChar *)"wallpaper", NULL);
|
||||
gnome_wp_xml_set_bool (wallpaper, (xmlChar *)"deleted", wpitem->deleted);
|
||||
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"name", (xmlChar *)wpitem->name);
|
||||
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"filename", (xmlChar *)filename);
|
||||
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"options", (xmlChar *)wpitem->options);
|
||||
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"shade_type", (xmlChar *)wpitem->shade_type);
|
||||
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"pcolor", (xmlChar *)wpitem->pri_color);
|
||||
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"scolor", (xmlChar *)wpitem->sec_color);
|
||||
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"pcolor", (xmlChar *)pcolor);
|
||||
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"scolor", (xmlChar *)scolor);
|
||||
g_free (pcolor);
|
||||
g_free (scolor);
|
||||
g_free (filename);
|
||||
|
||||
list = g_slist_delete_link (list, list);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue