pidgin: e2bbe819: Use basename() instead of splitting a pa...

markdoliner at pidgin.im markdoliner at pidgin.im
Fri Nov 14 15:10:22 EST 2008


-----------------------------------------------------------------
Revision: e2bbe819a07e75ca524863421955fc9fdc66efab
Ancestor: 4d24837d2aa60fa9273795d61abd66a4a39ba4bd
Author: markdoliner at pidgin.im
Date: 2008-11-14T20:06:55
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/e2bbe819a07e75ca524863421955fc9fdc66efab

Modified files:
        libpurple/protocols/qq/buddy_info.c

ChangeLog: 

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(-)

-------------- next part --------------
============================================================
--- libpurple/protocols/qq/buddy_info.c	3d85c12cb9f540a534b6709f5bf158199ec25899
+++ libpurple/protocols/qq/buddy_info.c	2564ab18a00291f82530bf6c91232909c062771a
@@ -483,43 +483,22 @@ void qq_change_icon_cb(PurpleConnection 
 
 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)


More information about the Commits mailing list