# HG changeset patch # User Yoshiki Yazawa # Date 1246517684 -32400 # Node ID aa1f0dd1a723188f2c7dc24036e3fed2be9b7c79 # Parent e922ad73c07e97873a467246aacacff23acfb245 use .dat extension for icons uniformly. diff -r e922ad73c07e -r aa1f0dd1a723 icon.c --- a/icon.c Thu Jul 02 05:54:58 2009 +0900 +++ b/icon.c Thu Jul 02 15:54:44 2009 +0900 @@ -4,14 +4,6 @@ extern GHashTable *icon_hash[]; extern GRegex *regp[]; -static gchar *ext_list[] = { - ".png", - ".gif", - ".jpg", - ".bmp", - NULL -}; - /* prototypes */ static void insert_icon_at_mark(GtkTextMark *requested_mark, gpointer user_data); static void insert_requested_icon(const gchar *user_name, gint service); @@ -294,16 +286,15 @@ data->use_count = 0; data->mtime = time(NULL); /* xxx is there a better way? */ - twitter_debug("requested url=%s\n", url); - /* request fetch image */ if(url) { + twitter_debug("request %s's icon\n", user_name); + twitter_debug("requested url = %s\n", url); /* reuse gotdata. just pass given one */ /* gotdata will be released in got_icon_cb */ data->fetch_data = purple_util_fetch_url_request(url, TRUE, NULL, TRUE, NULL, FALSE, got_icon_cb, gotdata); - twitter_debug("request %s's icon\n", user_name); g_free(url); } } @@ -440,30 +431,6 @@ if(hash) g_hash_table_insert(hash, g_strdup(user_name), data); - /* find out extension */ - gchar *slash = strrchr(url_data->url, '/'); - gchar *lower = g_ascii_strdown(purple_url_decode(slash+1), -1); - - gchar **extp; - data->img_type = NULL; - - for(extp = ext_list; *extp; extp++) { - if(g_strrstr(lower, *extp)) { - data->img_type = *extp+1; - break; - } - } - if(!data->img_type && g_strrstr(lower, ".jpeg")) - data->img_type = ext_list[2]+1; /* jpg */ - - g_free(lower); - - /* return if no suitable image found */ - if(!data->img_type) { - g_free(gotdata->user_name); - g_free(gotdata); - return; - } dirname = purple_prefs_get_string(OPT_ICON_DIR); @@ -472,7 +439,6 @@ gchar *filename = NULL; gchar *path = NULL; const gchar *suffix = NULL; - gchar **extp; switch(service) { case twitter_service: @@ -496,19 +462,17 @@ } /* remove old file first */ - for(extp = ext_list; *extp; extp++) { - filename = g_strdup_printf("%s_%s.%s", - user_name, suffix, *extp); - path = g_build_filename(dirname, filename, NULL); - g_remove(path); + filename = g_strdup_printf("%s_%s.dat", + user_name, suffix); + path = g_build_filename(dirname, filename, NULL); + g_remove(path); - g_free(filename); - g_free(path); - } + g_free(filename); + g_free(path); /* setup path */ - filename = g_strdup_printf("%s_%s.%s", - user_name, suffix, data->img_type); + filename = g_strdup_printf("%s_%s.dat", + user_name, suffix); path = g_build_filename(dirname, filename, NULL); g_free(filename); filename = NULL; @@ -581,57 +545,52 @@ /* check if saved file exists */ if(suffix && !renew) { gchar *filename = NULL; - gchar **extp; - for(extp = ext_list; *extp; extp++) { - filename = g_strdup_printf("%s_%s.%s", user_name, suffix, *extp); - path = g_build_filename(purple_prefs_get_string(OPT_ICON_DIR), - filename, NULL); - g_free(filename); + filename = g_strdup_printf("%s_%s.dat", user_name, suffix); + path = g_build_filename(purple_prefs_get_string(OPT_ICON_DIR), + filename, NULL); + g_free(filename); + + twitter_debug("path = %s\n", path); - twitter_debug("path = %s\n", path); - - /* build image from file, if file exists */ - if(g_file_test(path, G_FILE_TEST_EXISTS)) { - gchar *imgdata = NULL; - size_t len; - GError *err = NULL; - GdkPixbuf *pixbuf = NULL; - struct stat buf; + /* build image from file, if file exists */ + if(g_file_test(path, G_FILE_TEST_EXISTS)) { + gchar *imgdata = NULL; + size_t len; + GError *err = NULL; + GdkPixbuf *pixbuf = NULL; + struct stat buf; - if (!g_file_get_contents(path, &imgdata, &len, &err)) { - twitter_debug("Error reading %s: %s\n", - path, err->message); - g_error_free(err); - } + if (!g_file_get_contents(path, &imgdata, &len, &err)) { + twitter_debug("Error reading %s: %s\n", + path, err->message); + g_error_free(err); + } - if(stat(path, &buf)) - data->mtime = buf.st_mtime; - - pixbuf = make_scaled_pixbuf(imgdata, len); - g_free(imgdata); + if(stat(path, &buf)) + data->mtime = buf.st_mtime; - if(pixbuf) { - data->pixbuf = pixbuf; + pixbuf = make_scaled_pixbuf(imgdata, len); + g_free(imgdata); - twitter_debug("new icon pixbuf = %p size = %d\n", - pixbuf, - gdk_pixbuf_get_rowstride(pixbuf) * - gdk_pixbuf_get_height(pixbuf)); + if(pixbuf) { + data->pixbuf = pixbuf; - data->img_type = *extp; + twitter_debug("new icon pixbuf = %p size = %d\n", + pixbuf, + gdk_pixbuf_get_rowstride(pixbuf) * + gdk_pixbuf_get_height(pixbuf)); - twitter_debug("icon data has been loaded from file\n"); - insert_requested_icon(user_name, service); - } - - g_free(path); - return; + twitter_debug("icon data has been loaded from file\n"); + insert_requested_icon(user_name, service); } g_free(path); + return; + } - } /* for */ + g_free(path); + } /* suffix */ /* Return if user's icon has been requested already. */ @@ -648,8 +607,8 @@ case wassr_service: url = g_strdup_printf("http://wassr.jp/user/%s", user_name); break; - case identica_service: /* make use of Version0 API */ - url = g_strdup_printf("http://identi.ca/%s/avatar/96", user_name); + case identica_service: + url = g_strdup_printf("http://identi.ca/%s", user_name); break; case jisko_service: url = g_strdup_printf("http://jisko.net/%s", user_name); @@ -667,23 +626,26 @@ gotdata->user_name = g_strdup(user_name); gotdata->service = service; + twitter_debug("request %s's icon\n", user_name); + /* gotdata will be released in got_icon_cb */ if(service == twitter_service || service == wassr_service || + service == identica_service || service == jisko_service || service == ffeed_service) { data->fetch_data = purple_util_fetch_url_request(url, TRUE, NULL, TRUE, NULL, TRUE, got_page_cb, gotdata); + twitter_debug("requested url = %s\n", url); } - else { /* typically, identica_service */ + else { /* probably it is unnecessary */ data->fetch_data = purple_util_fetch_url_request(url, TRUE, NULL, TRUE, NULL, FALSE, got_icon_cb, gotdata); + twitter_debug("requested url = %s\n", url); } g_free(url); url = NULL; - - twitter_debug("request %s's icon\n", user_name); } } diff -r e922ad73c07e -r aa1f0dd1a723 pidgin-twitter.h --- a/pidgin-twitter.h Thu Jul 02 05:54:58 2009 +0900 +++ b/pidgin-twitter.h Thu Jul 02 15:54:44 2009 +0900 @@ -68,7 +68,6 @@ gboolean requested; /* TRUE if download icon has been requested */ GList *request_list; /* marker list */ PurpleUtilFetchUrlData *fetch_data; /* icon fetch data */ - const gchar *img_type; /* image type */ gchar *icon_url; /* url for the user's icon */ gint use_count; /* usage count */ time_t mtime; /* mtime of file */ @@ -189,7 +188,7 @@ #define P_GROUP_IDENTICA "!([-A-Za-z0-9_]+)" #define P_IMAGE_TWITTER "" #define P_IMAGE_WASSR "
" -#define P_IMAGE_IDENTICA "\"[A-Za-z0-9_]+\"/" +#define P_IMAGE_IDENTICA "\"Avatar\"" #define P_IMAGE_FFEED "