# HG changeset patch # User mikanbako # Date 1214191114 -32400 # Node ID d1f92d980f589ad20eed7f20dd823647cbaf6a2f # Parent 41dbb74bf029b20012a2a790cc32294c22e7f370 fixed that icon had not appeard in the first message. diff -r 41dbb74bf029 -r d1f92d980f58 pidgin-twitter.c --- a/pidgin-twitter.c Mon Jun 23 11:49:43 2008 +0900 +++ b/pidgin-twitter.c Mon Jun 23 12:18:34 2008 +0900 @@ -22,7 +22,7 @@ #include "pidgin-twitter.h" /* globals */ -static GRegex *regp[8]; +static GRegex *regp[7]; static gboolean suppress_oops = FALSE; static GHashTable *icon_id_by_user; static GList *requested_users = NULL; @@ -661,10 +661,9 @@ twitter_debug("called\n"); twitter_debug("buffer = %s suppress_oops = %d\n", *buffer, suppress_oops); - /* request to attach icon to the buffer */ - request_icon(*buffer); - - /* check if the conv is not NULL and is a twitter conv. */ + /* Check if the conv is not NULL to avoid a clash. + * conv is null when the conversation window has not opened yet. + * And if check is a twitter conv. */ if(!(conv && is_twitter_conv(conv))) { return FALSE; } @@ -843,42 +842,11 @@ } static void -request_icon(const char *buffer) +request_icon(char *user_name) { - GMatchInfo *match_info = NULL; - gchar *user_name = NULL; - gchar *message = NULL; gchar *url = NULL; PurpleUtilFetchUrlData *fetch_data = NULL; - /* get user name */ - g_regex_match(regp[MESSAGE], buffer, 0, &match_info); - if(!g_match_info_matches(match_info)) { - twitter_debug("Message was not matched : %s\n", buffer); - g_match_info_free(match_info); - return; - } - - message = g_match_info_fetch(match_info, 1); - g_match_info_free(match_info); - match_info = NULL; - - g_regex_match(regp[SENDER], message, 0, &match_info); - if(!g_match_info_matches(match_info)) { - twitter_debug("user's name was not matched : %s\n", message); - g_match_info_free(match_info); - g_free(message); - return; - } - - user_name = g_match_info_fetch(match_info, 2); - g_match_info_free(match_info); - g_free(message); - - /***********************/ - /* request user's icon */ - /***********************/ - /* look local icon cache for the requested icon */ gchar *filename = NULL; gchar *path = NULL; @@ -887,6 +855,7 @@ /* if img has been registerd, just return */ icon_id = GPOINTER_TO_INT(g_hash_table_lookup(icon_id_by_user, user_name)); if(icon_id) { + g_free(user_name); return; } @@ -956,10 +925,7 @@ GtkTextIter inserting_point; int icon_id; - /* Check that conv is not null to avoid a clash. - * conv is null when the conversation window has not opened yet. - */ - if(!(conv && is_twitter_conv(conv))) { + if(!is_twitter_conv(conv)) { return; } @@ -993,7 +959,10 @@ text_buffer, NULL, &inserting_point, FALSE)); twitter_debug("%s's icon has not been downloaded.", user_name); - g_free(user_name); + /* request to attach icon to the buffer + * user_name is owned by the function. */ + request_icon(user_name); + /* user_name must not free */ return; } @@ -1025,7 +994,6 @@ regp[SENDER] = g_regex_new(P_SENDER, 0, 0, NULL); regp[COMMAND] = g_regex_new(P_COMMAND, G_REGEX_RAW, 0, NULL); regp[PSEUDO] = g_regex_new(P_PSEUDO, G_REGEX_RAW, 0, NULL); - regp[MESSAGE] = g_regex_new(P_MESSAGE, 0, 0, NULL); regp[USER] = g_regex_new(P_USER, 0, 0, NULL); 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); @@ -1074,7 +1042,6 @@ g_regex_unref(regp[SENDER]); g_regex_unref(regp[COMMAND]); g_regex_unref(regp[PSEUDO]); - g_regex_unref(regp[MESSAGE]); g_regex_unref(regp[USER]); g_regex_unref(regp[USER_FIRST_LINE]); g_regex_unref(regp[USER_FORMATTED]); diff -r 41dbb74bf029 -r d1f92d980f58 pidgin-twitter.h --- a/pidgin-twitter.h Mon Jun 23 11:49:43 2008 +0900 +++ b/pidgin-twitter.h Mon Jun 23 12:18:34 2008 +0900 @@ -21,10 +21,9 @@ #define SENDER 1 #define COMMAND 2 #define PSEUDO 3 -#define MESSAGE 4 -#define USER 5 -#define USER_FIRST_LINE 6 -#define USER_FORMATTED 7 +#define USER 4 +#define USER_FIRST_LINE 5 +#define USER_FORMATTED 6 #define PLUGIN_ID "gtk-honeyplanet-pidgin_twitter" #define PLUGIN_NAME "pidgin-twitter" @@ -56,7 +55,6 @@ #define P_SENDER "^(\\r?\\n?)([A-Za-z0-9_]+): " #define P_COMMAND "^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+)(?:\\s*\\Z)" #define P_PSEUDO "^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)" -#define P_MESSAGE "^(.*)" #define P_USER "^\\(.+?\\)\\s*([A-Za-z0-9_]+):" #define P_USER_FIRST_LINE "^\\(.+?\\)\\s*.+:\\s*([A-Za-z0-9_]+):" #define P_USER_FORMATTED "^.*?([A-Za-z0-9_]+):" @@ -86,7 +84,7 @@ static gboolean receiving_im_cb(PurpleAccount *account, char **sender, char **buffer, PurpleConversation *conv, PurpleMessageFlags *flags, void *data); static void insert_requested_icon(gpointer data, gpointer user_data); static void got_icon_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message); -static void request_icon(const char *buffer); +static void request_icon(char *user_name); static void displayed_im_cb(PurpleAccount *account, const char *who, char *message, PurpleConversation *conv, PurpleMessageFlags flags); static gboolean load_plugin(PurplePlugin *plugin); static gboolean unload_plugin(PurplePlugin *plugin);