changeset 24375:95f0895f6c56

Use basename() instead of splitting a path and then taking the last element. And get rid of an error dialog that never happened. 1 file changed, 6 insertions(+), 27 deletions(-)
author Mark Doliner <mark@kingant.net>
date Fri, 14 Nov 2008 20:06:55 +0000
parents 75545fdf8944
children 40141d227b27
files libpurple/protocols/qq/buddy_info.c
diffstat 1 files changed, 6 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/qq/buddy_info.c	Fri Nov 14 19:58:32 2008 +0000
+++ b/libpurple/protocols/qq/buddy_info.c	Fri Nov 14 20:06:55 2008 +0000
@@ -483,43 +483,22 @@
 
 void qq_change_icon_cb(PurpleConnection *gc, const char *filepath)
 {
-	gchar **segments;
-	const gchar *filename;
-	gint index;
+	gchar *basename;
+	size_t index;
 	gint face;
 	gchar *error;
 
 	g_return_if_fail(filepath != NULL);
 
 	purple_debug_info("QQ", "Change my icon to %s\n", filepath);
-	segments = g_strsplit_set(filepath, G_DIR_SEPARATOR_S, 0);
 
-#if 0
-	for (index = 0; segments[index] != NULL; index++) {
-		purple_debug_info("QQ", "Split to %s\n", segments[index]);
-	}
-#endif
-
-	index = g_strv_length(segments) - 1;
-	if (index < 0) {
-		g_strfreev(segments);
-		return;
-	}
-
-	filename = segments[index];
-	index = strcspn (filename, "0123456789");
-	if (index < 0 || index >= strlen(filename)) {
-		error = g_strdup_printf(_("Can not get face number from filename '%s'"), filename);
-		purple_notify_error(gc, _("QQ Buddy"), _("Unable to Change Icon"), error);
-		g_free(error);
-		return;
-	}
-	face = strtol(filename+index, NULL, 10);
+	basename = g_path_get_basename(filepath);
+	index = strcspn(basename, "0123456789");
+	face = strtol(basename + index, NULL, 10);
+	g_free(basename);
 	purple_debug_info("QQ", "Set face to %d\n", face);
 
 	request_set_buddy_icon(gc, face);
-
-	g_strfreev(segments);
 }
 
 void qq_set_custom_icon(PurpleConnection *gc, PurpleStoredImage *img)