[gnome-color-manager] Use a standard function to ensure all filenames and device id's are valid
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Use a standard function to ensure all filenames and device id's are valid
- Date: Fri, 6 Nov 2009 08:51:54 +0000 (UTC)
commit cf2b398afc8dbe8de71aaa6fd67ebe75bc68215a
Author: Richard Hughes <richard hughsie com>
Date: Fri Nov 6 08:51:08 2009 +0000
Use a standard function to ensure all filenames and device id's are valid
src/gcm-calibrate.c | 5 +----
src/gcm-client.c | 13 +++----------
src/gcm-utils.c | 21 ++++++++++++++++++++-
src/gcm-utils.h | 1 +
4 files changed, 25 insertions(+), 15 deletions(-)
---
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index f1b9c1c..89e43bc 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -304,7 +304,6 @@ gcm_calibrate_task_neutralise (GcmCalibrate *calibrate, GError **error)
GtkWidget *widget;
GnomeRROutput *output;
const guint8 *data;
- guint i;
GPtrArray *array = NULL;
gint x, y;
@@ -349,9 +348,7 @@ gcm_calibrate_task_neutralise (GcmCalibrate *calibrate, GError **error)
priv->basename = g_strdup ("custom");
/* make a suitable filename */
- g_strdelimit (priv->basename, " *?%$", '_');
- for (i=0; priv->basename[i] != '\0'; i++)
- priv->basename[i] = g_ascii_tolower (priv->basename[i]);
+ gcm_utils_alphanum_lcase (priv->basename);
egg_debug ("using filename basename of %s", priv->basename);
/* argument array */
diff --git a/src/gcm-client.c b/src/gcm-client.c
index 520d40e..b928e4a 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -130,7 +130,6 @@ static gchar *
gcm_client_get_id_for_udev_device (GUdevDevice *udev_device)
{
gchar *id;
- guint i;
/* get id */
id = g_strdup_printf ("sysfs_%s_%s",
@@ -138,10 +137,7 @@ gcm_client_get_id_for_udev_device (GUdevDevice *udev_device)
g_udev_device_get_property (udev_device, "ID_MODEL"));
/* replace unsafe chars */
- for (i=0; id[i] != '\0'; i++) {
- if (!g_ascii_isalnum (id[i]))
- id[i] = '_';
- }
+ gcm_utils_alphanum_lcase (id);
return id;
}
@@ -340,17 +336,14 @@ gcm_client_get_id_for_xrandr_device (GnomeRROutput *output)
{
gchar *id;
gchar *name;
- guint i;
/* get id */
name = gcm_utils_get_output_name (output);
id = g_strdup_printf ("xrandr_%s", name);
/* replace unsafe chars */
- for (i=0; id[i] != '\0'; i++) {
- if (!g_ascii_isalnum (id[i]))
- id[i] = '_';
- }
+ gcm_utils_alphanum_lcase (id);
+
g_free (name);
return id;
}
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index cc71d8e..401dd01 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -476,7 +476,7 @@ gcm_utils_ptr_array_to_strv (GPtrArray *array)
}
/**
- * gpk_gnome_help:
+ * gcm_gnome_help:
* @link_id: Subsection of help file, or %NULL.
**/
gboolean
@@ -508,3 +508,22 @@ gcm_gnome_help (const gchar *link_id)
return ret;
}
+/**
+ * gcm_utils_alphanum_lcase:
+ **/
+void
+gcm_utils_alphanum_lcase (gchar *data)
+{
+ guint i;
+
+ g_return_if_fail (data != NULL);
+
+ /* replace unsafe chars, and make lowercase */
+ for (i=0; data[i] != '\0'; i++) {
+ if (!g_ascii_isalnum (data[i]))
+ data[i] = '_';
+ data[i] = g_ascii_tolower (data[i]);
+ }
+}
+
+
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index 9ac5080..4f99a24 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -40,6 +40,7 @@ gchar **gcm_utils_ptr_array_to_strv (GPtrArray *array);
gboolean gcm_gnome_help (const gchar *link_id);
gboolean gcm_utils_output_is_lcd_internal (const gchar *output_name);
gboolean gcm_utils_output_is_lcd (const gchar *output_name);
+void gcm_utils_alphanum_lcase (gchar *string);
#endif /* __GCM_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]