Remove utf8 validate check (gnome_wp_props_wp_set): If the filename we

2005-10-01  Rodney Dawes  <dobey@novell.com>

	* gnome-wp-capplet.c (gnome_wp_add_image): Remove utf8 validate check
	(gnome_wp_props_wp_set): If the filename we have for the image is not
	valid utf8, convert it to utf8 before setting the key in gconf
	(gnome_wp_load_stuffs, gnome_wp_file_changed): Make sure that the
	filename is valid utf8 and the file exists with utf8 encoding, or fall
	back to filename encoding as specified by the user with glib's
	environment variables

	* gnome-wpitem.c (gnome_wp_item_new): Make sure that the name field
	is always utf8 for displaying to the user with the tree view

	* gnome-wp-xml.c (gnome_wp_xml_load_xml): Make sure that the
	filename is valid utf8 and the file exists with utf8 encoding, or fall
	back to filename encoding as specified by the user with glib's
	environment variables
	(gnome_wp_xml_save_list): If the filename is not valid utf8, then
	convert to utf8 for storing in the XML file

	Fixes #168604
This commit is contained in:
Rodney Dawes 2005-10-01 21:29:39 +00:00 committed by Rodney Dawes
parent 3d5e4d4e75
commit 95aec817a6
4 changed files with 74 additions and 12 deletions

View file

@ -1,3 +1,25 @@
2005-10-01 Rodney Dawes <dobey@novell.com>
* gnome-wp-capplet.c (gnome_wp_add_image): Remove utf8 validate check
(gnome_wp_props_wp_set): If the filename we have for the image is not
valid utf8, convert it to utf8 before setting the key in gconf
(gnome_wp_load_stuffs, gnome_wp_file_changed): Make sure that the
filename is valid utf8 and the file exists with utf8 encoding, or fall
back to filename encoding as specified by the user with glib's
environment variables
* gnome-wpitem.c (gnome_wp_item_new): Make sure that the name field
is always utf8 for displaying to the user with the tree view
* gnome-wp-xml.c (gnome_wp_xml_load_xml): Make sure that the
filename is valid utf8 and the file exists with utf8 encoding, or fall
back to filename encoding as specified by the user with glib's
environment variables
(gnome_wp_xml_save_list): If the filename is not valid utf8, then
convert to utf8 for storing in the XML file
Fixes #168604
2005-09-06 Rodney Dawes <dobey@novell.com> 2005-09-06 Rodney Dawes <dobey@novell.com>
* gnome-wp-capplet.c (wallpaper_properties_init): Set the style * gnome-wp-capplet.c (wallpaper_properties_init): Set the style

View file

@ -95,9 +95,6 @@ static GnomeWPItem * gnome_wp_add_image (GnomeWPCapplet * capplet,
const gchar * filename) { const gchar * filename) {
GnomeWPItem * item; GnomeWPItem * item;
if (!g_utf8_validate (filename, -1, NULL))
return NULL;
item = g_hash_table_lookup (capplet->wphash, filename); item = g_hash_table_lookup (capplet->wphash, filename);
if (item != NULL) { if (item != NULL) {
if (item->deleted) { if (item->deleted) {
@ -291,7 +288,15 @@ static gboolean gnome_wp_props_wp_set (GnomeWPCapplet * capplet) {
if (!strcmp (item->filename, "(none)")) { if (!strcmp (item->filename, "(none)")) {
gconf_change_set_set_string (cs, WP_OPTIONS_KEY, "none"); gconf_change_set_set_string (cs, WP_OPTIONS_KEY, "none");
} else { } else {
gconf_change_set_set_string (cs, WP_FILE_KEY, item->filename); gchar * uri;
if (g_utf8_validate (item->filename, -1, NULL))
uri = g_strdup (item->filename);
else
uri = g_filename_to_utf8 (item->filename, -1, NULL, NULL, NULL);
gconf_change_set_set_string (cs, WP_FILE_KEY, uri);
g_free (uri);
gconf_change_set_set_string (cs, WP_OPTIONS_KEY, item->options); gconf_change_set_set_string (cs, WP_OPTIONS_KEY, item->options);
gnome_wp_option_menu_set (capplet, item->options, FALSE); gnome_wp_option_menu_set (capplet, item->options, FALSE);
} }
@ -582,7 +587,7 @@ static void gnome_wp_remove_wallpaper (GtkWidget * widget,
static gboolean gnome_wp_load_stuffs (void * data) { static gboolean gnome_wp_load_stuffs (void * data) {
GnomeWPCapplet * capplet = (GnomeWPCapplet *) data; GnomeWPCapplet * capplet = (GnomeWPCapplet *) data;
gchar * imagepath, * style; gchar * imagepath, * style, * uri;
GnomeWPItem * item; GnomeWPItem * item;
style = gconf_client_get_string (capplet->client, style = gconf_client_get_string (capplet->client,
@ -595,9 +600,15 @@ static gboolean gnome_wp_load_stuffs (void * data) {
gdk_window_set_cursor (capplet->window->window, NULL); gdk_window_set_cursor (capplet->window->window, NULL);
imagepath = gconf_client_get_string (capplet->client, uri = gconf_client_get_string (capplet->client,
WP_FILE_KEY, WP_FILE_KEY,
NULL); NULL);
if (g_utf8_validate (uri, -1, NULL) && g_file_test (uri, G_FILE_TEST_EXISTS))
imagepath = g_strdup (uri);
else
imagepath = g_filename_from_utf8 (uri, -1, NULL, NULL, NULL);
g_free (uri);
item = g_hash_table_lookup (capplet->wphash, imagepath); item = g_hash_table_lookup (capplet->wphash, imagepath);
if (item != NULL && strcmp (style, "none") != 0) { if (item != NULL && strcmp (style, "none") != 0) {
@ -680,8 +691,14 @@ static void gnome_wp_file_changed (GConfClient * client, guint id,
GtkTreeIter iter; GtkTreeIter iter;
GnomeWPItem * item; GnomeWPItem * item;
gchar * wpfile, * selected; gchar * wpfile, * selected;
const gchar * uri;
uri = gconf_value_get_string (entry->value);
if (g_utf8_validate (uri, -1, NULL) && g_file_test (uri, G_FILE_TEST_EXISTS))
wpfile = g_strdup (uri);
else
wpfile = g_filename_from_utf8 (uri, -1, NULL, NULL, NULL);
wpfile = g_strdup (gconf_value_get_string (entry->value));
item = g_hash_table_lookup (capplet->wphash, wpfile); item = g_hash_table_lookup (capplet->wphash, wpfile);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview));

View file

@ -56,7 +56,11 @@ GnomeWPItem * gnome_wp_item_new (const gchar * filename,
if (item->fileinfo != NULL && if (item->fileinfo != NULL &&
!strncmp (item->fileinfo->mime_type, "image/", strlen ("image/"))) { !strncmp (item->fileinfo->mime_type, "image/", strlen ("image/"))) {
if (item->name == NULL) { if (item->name == NULL) {
item->name = g_strdup (item->fileinfo->name); if (g_utf8_validate (item->fileinfo->name, -1, NULL))
item->name = g_strdup (item->fileinfo->name);
else
item->name = g_filename_to_utf8 (item->fileinfo->name, -1, NULL,
NULL, NULL);
} }
item->options = gconf_client_get_string (client, WP_OPTIONS_KEY, NULL); item->options = gconf_client_get_string (client, WP_OPTIONS_KEY, NULL);

View file

@ -122,7 +122,16 @@ static void gnome_wp_xml_load_xml (GnomeWPCapplet * capplet,
for (wpa = list->children; wpa != NULL; wpa = wpa->next) { for (wpa = list->children; wpa != NULL; wpa = wpa->next) {
if (!strcmp (wpa->name, "filename")) { if (!strcmp (wpa->name, "filename")) {
if (wpa->last != NULL && wpa->last->content != NULL) { if (wpa->last != NULL && wpa->last->content != NULL) {
wp->filename = g_strdup (g_strstrip (wpa->last->content)); const char * none = "(none)";
gchar *content = g_strstrip (wpa->last->content);
if (!strncmp (content, none, strlen (none)))
wp->filename = g_strdup (content);
else if (g_utf8_validate (content, -1, NULL) &&
g_file_test (content, G_FILE_TEST_EXISTS))
wp->filename = g_strdup (content);
else
wp->filename = g_filename_from_utf8 (content, -1, NULL, NULL, NULL);
} else { } else {
break; break;
} }
@ -361,15 +370,25 @@ void gnome_wp_xml_save_list (GnomeWPCapplet * capplet) {
for (wp = list; wp != NULL; wp = wp->next) { for (wp = list; wp != NULL; wp = wp->next) {
GnomeWPItem * wpitem = wp->data; GnomeWPItem * wpitem = wp->data;
const char * none = "(none)";
gchar * filename;
if (!strncmp (wpitem->filename, none, strlen (none)) ||
(g_utf8_validate (wpitem->filename, -1, NULL) &&
g_file_test (wpitem->filename, G_FILE_TEST_EXISTS)))
filename = g_strdup (wpitem->filename);
else
filename = g_filename_to_utf8 (wpitem->filename, -1, NULL, NULL, NULL);
wallpaper = xmlNewChild (root, NULL, "wallpaper", NULL); wallpaper = xmlNewChild (root, NULL, "wallpaper", NULL);
gnome_wp_xml_set_bool (wallpaper, "deleted", wpitem->deleted); gnome_wp_xml_set_bool (wallpaper, "deleted", wpitem->deleted);
item = xmlNewTextChild (wallpaper, NULL, "name", wpitem->name); item = xmlNewTextChild (wallpaper, NULL, "name", wpitem->name);
item = xmlNewTextChild (wallpaper, NULL, "filename", wpitem->filename); item = xmlNewTextChild (wallpaper, NULL, "filename", filename);
item = xmlNewTextChild (wallpaper, NULL, "options", wpitem->options); item = xmlNewTextChild (wallpaper, NULL, "options", wpitem->options);
item = xmlNewTextChild (wallpaper, NULL, "shade_type", wpitem->shade_type); item = xmlNewTextChild (wallpaper, NULL, "shade_type", wpitem->shade_type);
item = xmlNewTextChild (wallpaper, NULL, "pcolor", wpitem->pri_color); item = xmlNewTextChild (wallpaper, NULL, "pcolor", wpitem->pri_color);
item = xmlNewTextChild (wallpaper, NULL, "scolor", wpitem->sec_color); item = xmlNewTextChild (wallpaper, NULL, "scolor", wpitem->sec_color);
g_free (filename);
} }
xmlSaveFormatFile (wpfile, wplist, 1); xmlSaveFormatFile (wpfile, wplist, 1);
xmlFreeDoc (wplist); xmlFreeDoc (wplist);