[patch] [bug 461804] don't use setlocale
- From: Christian Persch <chpe gnome org>
- To: nautilus-list gnome org
- Subject: [patch] [bug 461804] don't use setlocale
- Date: Mon, 30 Jul 2007 16:18:18 +0200
Hi;
Nautilus uses setlocale (LC_NUMERIC, "C") to print and parse a float
locale indendently; but there are glib functions for doing that without
changing the locale. Attached patch from
http://bugzilla.gnome.org/show_bug.cgi?id=461804 fixes this; ok to
commit?
Regards,
Christian
Index: src/file-manager/fm-icon-view.c
===================================================================
--- src/file-manager/fm-icon-view.c (révision 13025)
+++ src/file-manager/fm-icon-view.c (copie de travail)
@@ -255,30 +255,36 @@ get_stored_icon_position_callback (Nauti
FMIconView *icon_view)
{
char *position_string, *scale_string;
- gboolean position_good, scale_good;
- char *locale;
- char c;
+ gboolean position_good;
g_assert (NAUTILUS_IS_ICON_CONTAINER (container));
g_assert (NAUTILUS_IS_FILE (file));
g_assert (position != NULL);
g_assert (FM_IS_ICON_VIEW (icon_view));
- /* Doing parsing in the "C" locale instead of the one set
- * by the user ensures that data in the metafile is not in
- * a locale-specific format. It's only necessary for floating
- * point values since there aren't locale-specific formats for
- * integers in C stdio.
- */
- locale = g_strdup (setlocale (LC_NUMERIC, NULL));
- setlocale (LC_NUMERIC, "C");
-
/* Get the current position of this icon from the metadata. */
position_string = nautilus_file_get_metadata
(file, NAUTILUS_METADATA_KEY_ICON_POSITION, "");
- position_good = sscanf
- (position_string, " %d , %d %c",
- &position->x, &position->y, &c) == 2;
+ if (position_string && position_string[0])
+ {
+ gint64 px, py;
+ char *xendptr = NULL, *yendptr = NULL;
+
+ errno = 0;
+ px = g_ascii_strtoll (position_string, &xendptr, 0);
+ if (errno == 0 && xendptr != position_string && xendptr && *xendptr == ',')
+ {
+ xendptr++; /* jump over the ',' */
+
+ py = g_ascii_strtoll (xendptr, ¥dptr, 0);
+ if (errno == 0 && yendptr != xendptr)
+ {
+ position->x = px;
+ position->y = py;
+ position_good = TRUE;
+ }
+ }
+ }
g_free (position_string);
/* If it is the desktop directory, maybe the gnome-libs metadata has information about it */
@@ -286,17 +292,11 @@ get_stored_icon_position_callback (Nauti
/* Get the scale of the icon from the metadata. */
scale_string = nautilus_file_get_metadata
(file, NAUTILUS_METADATA_KEY_ICON_SCALE, "1");
- scale_good = sscanf
- (scale_string, " %lf",
- &position->scale) == 1;
- if (!scale_good) {
+ position->scale = g_ascii_strtod (scale_string, NULL);
+ if (errno != 0) {
position->scale = 1.0;
}
-
g_free (scale_string);
-
- setlocale (LC_NUMERIC, locale);
- g_free (locale);
return position_good;
}
@@ -2165,22 +2165,12 @@ icon_position_changed_callback (Nautilus
FMIconView *icon_view)
{
char *position_string;
- char *scale_string;
- char *locale;
+ char scale_string[G_ASCII_DTOSTR_BUF_SIZE];
g_assert (FM_IS_ICON_VIEW (icon_view));
g_assert (container == get_icon_container (icon_view));
g_assert (NAUTILUS_IS_FILE (file));
- /* Doing formatting in the "C" locale instead of the one set
- * by the user ensures that data in the metafile is not in
- * a locale-specific format. It's only necessary for floating
- * point values since there aren't locale-specific formats for
- * integers in C stdio.
- */
- locale = g_strdup (setlocale (LC_NUMERIC, NULL));
- setlocale (LC_NUMERIC, "C");
-
/* Schedule updating menus for the next idle. Doing it directly here
* noticeably slows down icon stretching. The other work here to
* store the icon position and scale does not seem to noticeably
@@ -2204,18 +2194,10 @@ icon_position_changed_callback (Nautilus
g_free (position_string);
}
- /* FIXME bugzilla.gnome.org 40662:
- * %.2f is not a good format for the scale factor. We'd like it to
- * say "2" or "2x" instead of "2.00".
- */
- scale_string = g_strdup_printf ("%.2f", position->scale);
+ g_ascii_dtostr (scale_string, sizeof (scale_string), position->scale);
nautilus_file_set_metadata
(file, NAUTILUS_METADATA_KEY_ICON_SCALE,
- "1.00", scale_string);
- g_free (scale_string);
-
- setlocale (LC_NUMERIC, locale);
- g_free (locale);
+ "1.0", scale_string);
}
/* Attempt to change the filename to the new text. Notify user if operation fails. */
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]