# HG changeset patch # User Yoshiki Yazawa # Date 1215970077 -32400 # Node ID 084e1c6de8ca82a620fc7ca083c00b56d0e73398 # Parent 8de54d4203284e69b41a7a6a12a4647e74a72b6e icon scaling feature has been implemented. diff -r 8de54d420328 -r 084e1c6de8ca pidgin-twitter.c --- a/pidgin-twitter.c Mon Jul 14 00:17:18 2008 +0900 +++ b/pidgin-twitter.c Mon Jul 14 02:27:57 2008 +0900 @@ -19,6 +19,7 @@ #define PURPLE_PLUGINS 1 #include "pidgin-twitter.h" +#include /* globals */ static GRegex *regp[9]; @@ -1269,9 +1270,13 @@ } /* insert icon actually */ - if(purple_prefs_get_bool(OPT_SHOW_ICON)) - gtk_imhtml_insert_image_at_iter(target_imhtml, - icon_id, &insertion_point); + if(purple_prefs_get_bool(OPT_SHOW_ICON)) { + PurpleStoredImage *img = purple_imgstore_find_by_id(icon_id); + const GdkPixbuf *pixbuf = purple_imgstore_get_data(img); + gtk_text_buffer_insert_pixbuf(target_buffer, + &insertion_point, + (GdkPixbuf *)pixbuf); + } gtk_text_buffer_delete_mark(target_buffer, requested_mark); requested_mark = NULL; } @@ -1433,8 +1438,19 @@ } } - icon_id = purple_imgstore_add_with_id(g_memdup(url_text, len), len, - user_name); + /* make pixbuf */ + GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); + gdk_pixbuf_loader_write(loader, (guchar *)url_text, len, NULL); + gdk_pixbuf_loader_close(loader, NULL); + GdkPixbuf *src = gdk_pixbuf_loader_get_pixbuf(loader); + GdkPixbuf *dest = gdk_pixbuf_scale_simple(src, 48, 48, + GDK_INTERP_HYPER); + gdk_pixbuf_unref (src); + icon_id = + purple_imgstore_add_with_id(dest, + gdk_pixbuf_get_rowstride(dest) * + gdk_pixbuf_get_height(dest), + user_name); if(!data) { twitter_debug("allocate icon_data (shouldn't be called)\n"); data = g_new0(icon_data, 1); @@ -1451,7 +1467,7 @@ if(ensure_path_exists(dirname)) { gchar *filename = NULL; gchar *path = NULL; - FILE *fp = NULL; +// FILE *fp = NULL; switch(service) { case twitter_service: @@ -1471,15 +1487,7 @@ path = g_build_filename(dirname, filename, NULL); g_free(filename); filename = NULL; - fp = fopen(path, "wb"); - g_free(path); path = NULL; - - if(fp) { - int wrotelen; - wrotelen = fwrite(url_text, 1, len, fp); - } - - fclose(fp); fp = NULL; + g_file_set_contents(path, url_text, len, NULL); } twitter_debug("Downloading %s's icon has been complete.(icon_id = %d)\n", @@ -1561,7 +1569,20 @@ g_error_free(err); } - data->icon_id = purple_imgstore_add_with_id(imgdata, len, path); + /* make pixbuf */ + GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); + gdk_pixbuf_loader_write(loader, (guchar *)imgdata, len, NULL); + gdk_pixbuf_loader_close(loader, NULL); + GdkPixbuf *src = gdk_pixbuf_loader_get_pixbuf(loader); + GdkPixbuf *dest = gdk_pixbuf_scale_simple(src, 48, 48, + GDK_INTERP_HYPER); + gdk_pixbuf_unref (src); + data->icon_id = + purple_imgstore_add_with_id(dest, + gdk_pixbuf_get_rowstride(dest) * + gdk_pixbuf_get_height(dest), + user_name); + g_free(filename); g_free(path); @@ -1758,8 +1779,13 @@ } /* if we have icon for this user, insert icon immediately */ - if(purple_prefs_get_bool(OPT_SHOW_ICON)) - gtk_imhtml_insert_image_at_iter(imhtml, icon_id, &insertion_point); + if(purple_prefs_get_bool(OPT_SHOW_ICON)) { + PurpleStoredImage *img = purple_imgstore_find_by_id(icon_id); + const GdkPixbuf *pixbuf = purple_imgstore_get_data(img); + gtk_text_buffer_insert_pixbuf(text_buffer, + &insertion_point, + (GdkPixbuf *)pixbuf); + } g_free(user_name); user_name = NULL; twitter_debug("reach end of function\n");