static void twitter_conv_icon_displayed_chat_cb(PurpleAccount * account, const char *who, char *message, PurpleConversation * conv, PurpleMessageFlags flags, void *account_signal) { GtkIMHtml *imhtml; GtkTextBuffer *text_buffer; GtkTextIter insertion_point; gint linenumber; TwitterConvIcon *conv_icon; PurpleConnection *gc; TwitterConnectionData *twitter; if (account != account_signal) return; gc = purple_account_get_connection(account); if (!gc) { return; } twitter = gc->proto_data; purple_debug_info(PLUGIN_ID, "%s\n", G_STRFUNC); /* insert icon */ imhtml = GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml); text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml)); /* get GtkTextIter in the target line */ linenumber = GPOINTER_TO_INT(purple_conversation_get_data(conv, PLUGIN_ID "-icon-ln")); gtk_text_buffer_get_iter_at_line(text_buffer, &insertion_point, linenumber); conv_icon = twitter_conv_icon_find(account, who); /* if we don't have the icon for this user, put a mark instead and * request the icon */ if (!conv_icon) { conv_icon = twitter_conv_icon_new(account, who); twitter_conv_icon_add_conv(conv_icon, conv); g_hash_table_insert(twitter->icons, g_strdup(purple_normalize(account, who)), conv_icon); mark_icon_for_user(gtk_text_buffer_create_mark(text_buffer, NULL, &insertion_point, FALSE), conv_icon); return; } twitter_conv_icon_add_conv(conv_icon, conv); /* if we have the icon for this user, insert the icon immediately */ if (TRUE) { if (conv_icon->pixbuf) { gtk_text_buffer_insert_pixbuf(text_buffer, &insertion_point, conv_icon->pixbuf); } else { mark_icon_for_user(gtk_text_buffer_create_mark(text_buffer, NULL, &insertion_point, FALSE), conv_icon); } } purple_debug_info(PLUGIN_ID, "end %s\n", G_STRFUNC); }
static void displayed_im_cb(PurpleAccount *account, const char *who, char *message, PurpleConversation *conv, PurpleMessageFlags flags) { GMatchInfo *match_info = NULL; gchar *user_name = NULL; GtkIMHtml *imhtml; GtkTextBuffer *text_buffer; GtkTextIter insertion_point; gint service = get_service_type(conv); icon_data *data = NULL; gint linenumber; GHashTable *hash = NULL; gboolean renew = FALSE; twitter_debug("called\n"); if(service == unknown_service) { twitter_debug("unknown service\n"); return; } /* get user's name */ g_regex_match(regp[USER], message, 0, &match_info); if(!g_match_info_matches(match_info)) { twitter_debug("message was not matched : %s\n", message); g_match_info_free(match_info); return; } user_name = g_match_info_fetch(match_info, 1); g_match_info_free(match_info); /* insert icon */ imhtml = GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml); text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml)); /* get GtkTextIter in the target line */ linenumber = GPOINTER_TO_INT(g_hash_table_lookup(conv_hash, conv)); gtk_text_buffer_get_iter_at_line(text_buffer, &insertion_point, linenumber); switch(service) { case twitter_service: case wassr_service: case identica_service: case jisko_service: case ffeed_service: hash = icon_hash[service]; break; default: twitter_debug("unknown service\n"); break; } if(hash) data = g_hash_table_lookup(hash, user_name); if(data) { /* 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=%d\n", data->use_count, (int)(data->mtime)); renew = TRUE; request_icon(user_name, service, renew); } } /* if we don't have the icon for this user, put a mark instead and * request the icon */ if(!data || !data->pixbuf) { twitter_debug("%s's icon is not in memory.\n", user_name); mark_icon_for_user(gtk_text_buffer_create_mark( text_buffer, NULL, &insertion_point, FALSE), user_name, service); /* request to attach icon to the buffer */ request_icon(user_name, service, renew); g_free(user_name); user_name = NULL; return; } /* if we have the icon for this user, insert the icon immediately */ if(purple_prefs_get_bool(OPT_SHOW_ICON)) { gtk_text_buffer_insert_pixbuf(text_buffer, &insertion_point, data->pixbuf); data->use_count++; } g_free(user_name); user_name = NULL; twitter_debug("reach end of function\n"); }