Mercurial > pidgin-twitter
changeset 198:85484ddf8823
- changed the way of fetching icons for wassr. now pidgin-twitter downloads html first even for wassr.
- implemented new icon update scheme. now pidign-twitter carries the url of each icon and checks update by comparing url.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sun, 10 Aug 2008 23:00:48 +0900 |
parents | b436d72447e8 |
children | 5ddf8bee768d |
files | pidgin-twitter.c pidgin-twitter.h |
diffstat | 2 files changed, 54 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin-twitter.c Sat Aug 09 13:42:12 2008 +0900 +++ b/pidgin-twitter.c Sun Aug 10 23:00:48 2008 +0900 @@ -24,7 +24,7 @@ /***********/ /* globals */ /***********/ -#define NUM_REGPS 11 +#define NUM_REGPS 12 #define NUM_SERVICES 4 /* twitter, wassr, identica, jisko. */ static GRegex *regp[NUM_REGPS]; static gboolean suppress_oops = FALSE; @@ -1691,20 +1691,6 @@ /* in this function, we put an icon for pending marks. we should * not invalidate the icon here, otherwise it may result in * thrashing. --yaz */ -#if 0 - /* check validity of icon */ - int count_thres = purple_prefs_get_int(OPT_ICON_MAX_COUNT); - int days_thres = DAYS_TO_SECONDS(purple_prefs_get_int(OPT_ICON_MAX_DAYS)); - - if(data->use_count > count_thres || - (data->mtime && ((time(NULL) - data->mtime)) > days_thres)) { - twitter_debug("count=%d mtime=%ld\n", data->use_count, data->mtime); - icon_id = 0; - data->icon_id = 0; - data->use_count = 0; - data->mtime = time(NULL); //xxx not good - } -#endif if(!data || !data->pixbuf) { return; @@ -1791,6 +1777,11 @@ icon_hash[twitter_service], user_name); regp_id = IMAGE_TWITTER; } + else if(service == wassr_service) { + data = (icon_data *)g_hash_table_lookup( + icon_hash[wassr_service], user_name); + regp_id = IMAGE_WASSR; + } else if(service == identica_service) { data = (icon_data *)g_hash_table_lookup( icon_hash[identica_service], user_name); @@ -1837,11 +1828,9 @@ g_match_info_free(match_info); } + /* find out basename */ gchar *slash = strrchr(url, '/'); *slash = '\0'; - gchar *tmp = g_strdup_printf("%s/%s", url, - purple_url_encode(slash+1)); - gchar *lower = g_ascii_strdown(slash+1, -1); @@ -1854,9 +1843,41 @@ g_free(lower); + gchar *tmp; + /* url encode basename. twitter needs this. */ + if(service == twitter_service) + tmp = g_strdup_printf("%s/%s", url, + purple_url_encode(slash+1)); + else if(service == wassr_service) { + tmp = g_strdup_printf("http://wassr.jp%s/%s", url, slash+1); + } + else { + tmp = g_strdup_printf("%s/%s", url, slash+1); + } + g_free(url); url = tmp; + /* if requesting icon url is the same as old, return. */ + if(url && data->icon_url && !strcmp(data->icon_url, url)) { + twitter_debug("old url = %s new url = %s\n", data->icon_url, url); + data->requested = FALSE; + data->fetch_data = NULL; + g_free(url); + return; + } + + if(data && data->pixbuf) { + gdk_pixbuf_unref(data->pixbuf); + data->pixbuf = NULL; + } + + g_free(data->icon_url); + data->icon_url = g_strdup(url); + + data->use_count = 0; + data->mtime = time(NULL); /* xxx is there a better way? */ + twitter_debug("requested url=%s\n", url); /* request fetch image */ @@ -2091,7 +2112,7 @@ data = (icon_data *)g_hash_table_lookup(hash, user_name); /* if img has been registerd, just return */ - if(data && data->pixbuf) + if(data && data->pixbuf && !renew) return; /* check if saved file exists */ @@ -2156,12 +2177,9 @@ switch(service) { case twitter_service: url = g_strdup_printf("http://twitter.com/%s", user_name); - break; case wassr_service: - url = g_strdup_printf("http://wassr.jp/user/%s/profile_img.png.64", - user_name); - data->img_type = "png"; + url = g_strdup_printf("http://wassr.jp/user/%s", user_name); break; case identica_service: url = g_strdup_printf("http://identi.ca/%s", user_name); @@ -2180,8 +2198,9 @@ gotdata->service = service; /* gotdata will be released in got_icon_cb */ - if(service == identica_service || - service == twitter_service || + if(service == twitter_service || + service == wassr_service || + service == identica_service || service == jisko_service) { data->fetch_data = purple_util_fetch_url(url, TRUE, NULL, TRUE, got_page_cb, gotdata); @@ -2337,11 +2356,9 @@ (data->mtime && ((time(NULL) - data->mtime)) > days_thres)) { twitter_debug("count=%d mtime=%d\n", data->use_count, (int)(data->mtime)); - g_object_unref(data->pixbuf); - data->pixbuf = NULL; - data->use_count = 0; - data->mtime = time(NULL); //xxx not good renew = TRUE; + request_icon(user_name, service, renew); + g_free(user_name); user_name = NULL; } } @@ -2467,8 +2484,9 @@ regp[USER_FIRST_LINE] = g_regex_new(P_USER_FIRST_LINE, 0, 0, NULL); regp[USER_FORMATTED] = g_regex_new(P_USER_FORMATTED, G_REGEX_RAW, 0, NULL); regp[CHANNEL] = g_regex_new(P_CHANNEL, 0, 0, NULL); + regp[IMAGE_TWITTER] = g_regex_new(P_IMAGE_TWITTER, 0, 0, NULL); + regp[IMAGE_WASSR] = g_regex_new(P_IMAGE_WASSR, 0, 0, NULL); regp[IMAGE_IDENTICA] = g_regex_new(P_IMAGE_IDENTICA, 0, 0, NULL); - regp[IMAGE_TWITTER] = g_regex_new(P_IMAGE_TWITTER, 0, 0, NULL); regp[IMAGE_JISKO] = g_regex_new(P_IMAGE_JISKO, 0, 0, NULL); for(i = twitter_service; i < NUM_SERVICES; i++) { @@ -2976,7 +2994,7 @@ purple_prefs_get_bool(OPT_COUNTER)); g_signal_connect(e, "toggled", G_CALLBACK(bool_toggled_cb), &e); - purple_prefs_connect_callback(plugin, OPT_COUNTER, /* xxx */ + purple_prefs_connect_callback(plugin, OPT_COUNTER, counter_prefs_cb, NULL); e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_pseudo"));
--- a/pidgin-twitter.h Sat Aug 09 13:42:12 2008 +0900 +++ b/pidgin-twitter.h Sun Aug 10 23:00:48 2008 +0900 @@ -34,8 +34,9 @@ USER_FIRST_LINE, USER_FORMATTED, CHANNEL, + IMAGE_TWITTER, + IMAGE_WASSR, IMAGE_IDENTICA, - IMAGE_TWITTER, IMAGE_JISKO }; @@ -55,6 +56,7 @@ 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 */ } icon_data; @@ -144,8 +146,9 @@ #define P_USER_FIRST_LINE "^\\(.+?\\)\\s*.+:\\s*([A-Za-z0-9_]+):" #define P_USER_FORMATTED "^.*?<a .+?>([A-Za-z0-9_]+)</a>:" #define P_CHANNEL "^(.*?<a .+?>[A-Za-z0-9_]+</a>: \\r?\\n?#)([A-Za-z0-9_]+) " +#define P_IMAGE_TWITTER "<a href=\"/account/profile_image/.+?\"><img .+? id=\"profile-image\".*src=\"(http://.+)\" .+?/>" +#define P_IMAGE_WASSR "<div class=\"image\"><a href=\".+\"><img src=\"(.+)\" width=\".+?\" /></a></div>" #define P_IMAGE_IDENTICA "<img src=\"(http://avatar.identi.ca/[A-Za-z0-9-.]+)\" class=\"avatar profile\" width=\"96\" height=\"96\" alt=\"[A-Za-z0-0_]+\"/>" -#define P_IMAGE_TWITTER "<a href=\"/account/profile_image/.+?\"><img .+? id=\"profile-image\".*src=\"(http://.+)\" .+?/>" #define P_IMAGE_JISKO "<img src=\"(http://jisko.net/users/.+/img/avatar/thumb_side\\..+)\" alt=\"Avatar\" />" /* twitter API specific macros */