Mercurial > pidgin.yaz
changeset 9308:b3bda982996b
[gaim-migrate @ 10116]
Yikes.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 19 Jun 2004 04:57:43 +0000 |
parents | 2138b3a07cb8 |
children | ade6b9c0dc8a |
files | src/gtkaccount.c src/protocols/gg/gg.c src/protocols/irc/irc.c src/protocols/jabber/jabber.c src/protocols/msn/msn.c src/protocols/napster/napster.c src/protocols/novell/novell.c src/protocols/oscar/oscar.c src/protocols/rendezvous/rendezvous.c src/protocols/silc/silc.c src/protocols/toc/toc.c src/protocols/trepia/trepia.c src/protocols/yahoo/yahoo.c src/protocols/zephyr/zephyr.c src/prpl.h |
diffstat | 15 files changed, 123 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkaccount.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/gtkaccount.c Sat Jun 19 04:57:43 2004 +0000 @@ -22,6 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #include "gtkinternal.h" #include "account.h" @@ -31,6 +32,7 @@ #include "notify.h" #include "plugin.h" #include "prefs.h" +#include "prpl.h" #include "request.h" #include "signals.h" #include "util.h" @@ -117,6 +119,7 @@ GtkWidget *new_mail_check; GtkWidget *buddy_icon_hbox; GtkWidget *buddy_icon_entry; + char *buddy_icon_path; GtkWidget *buddy_icon_filesel; GtkWidget *buddy_icon_preview; GtkWidget *buddy_icon_text; @@ -269,7 +272,10 @@ return; } - gtk_entry_set_text(GTK_ENTRY(dialog->buddy_icon_entry), filename); + if (dialog->buddy_icon_path) + g_free(dialog->buddy_icon_path); + dialog->buddy_icon_path = g_strdup(filename); + gtk_image_set_from_file(GTK_IMAGE(dialog->buddy_icon_entry), filename); gtk_widget_destroy(dialog->buddy_icon_filesel); } @@ -377,7 +383,66 @@ static void buddy_icon_reset_cb(GtkWidget *button, AccountPrefsDialog *dialog) { - gtk_entry_set_text(GTK_ENTRY(dialog->buddy_icon_entry), ""); + if (dialog->buddy_icon_path) + g_free(dialog->buddy_icon_path); + dialog->buddy_icon_path = NULL; + gtk_image_set_from_file(GTK_IMAGE(dialog->buddy_icon_entry), ""); +} + +gboolean str_array_match(char **a, char **b) +{ + int i, j; + for (i = 0; a[i] != NULL; i++) + for (j = 0; b[j] != NULL; j++) + if (!g_ascii_strcasecmp(a[i], b[j])) + return TRUE; + return FALSE; +} + +static void +convert_and_set_buddy_icon(GaimAccount *account, const char *path) +{ + int width, height; + GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(account->protocol_id)); + char **prpl_formats = g_strsplit (prpl_info->icon_spec.format,",",0); + GdkPixbufFormat *format = gdk_pixbuf_get_file_info (path, &width, &height); + char **pixbuf_formats = gdk_pixbuf_format_get_extensions(format); + + if (str_array_match(pixbuf_formats, prpl_formats)) { + gaim_account_set_buddy_icon(account, path); + } else { + int i; + GError *error = NULL; + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &error); + GdkPixbuf *scale; + char *random = g_strdup_printf("%x", g_random_int()); + const char *dirname = gaim_buddy_icons_get_cache_dir(); + char *filename = g_build_filename(dirname, random, NULL); + if (prpl_info->icon_spec.width > 0 && prpl_info->icon_spec.height > 0) { + scale = gdk_pixbuf_scale_simple (pixbuf, prpl_info->icon_spec.width, prpl_info->icon_spec.height, GDK_INTERP_HYPER); + gdk_pixbuf_unref(pixbuf); + pixbuf = scale; + } + if (error) { + g_free(filename); + g_free(random); + gaim_debug_error("buddyicon", "Could not open icon for conversion: %s\n", error->message); + return; + } + for (i = 0; prpl_formats[i]; i++) { + gaim_debug_info("buddyicon", "Converting buddy icon to %s as %s\n", prpl_formats[i], filename); + if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == FALSE) + break; + } + if (!error) { + gaim_account_set_buddy_icon(account, filename); + } else { + gaim_debug_error("buddyicon", "Could not convert icon to usable format: %s\n", error->message); + } + g_free(filename); + g_free(random); + g_object_unref(pixbuf); + } } static void @@ -578,8 +643,7 @@ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_widget_show(label); - dialog->buddy_icon_entry = gtk_entry_new(); - gtk_editable_set_editable(GTK_EDITABLE(dialog->buddy_icon_entry), FALSE); + dialog->buddy_icon_entry = gtk_image_new(); gtk_box_pack_start(GTK_BOX(hbox), dialog->buddy_icon_entry, TRUE, TRUE, 0); gtk_widget_show(dialog->buddy_icon_entry); gaim_set_accessible_label (dialog->buddy_icon_entry, label); @@ -600,7 +664,7 @@ if (!(dialog->prpl_info->options & OPT_PROTO_MAIL_CHECK)) gtk_widget_hide(dialog->new_mail_check); - if (!(dialog->prpl_info->options & OPT_PROTO_BUDDY_ICON)) + if (!(dialog->prpl_info->icon_spec.format != NULL)) gtk_widget_hide(dialog->buddy_icon_hbox); } @@ -608,14 +672,15 @@ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->new_mail_check), gaim_account_get_check_mail(dialog->account)); - if (gaim_account_get_buddy_icon(dialog->account) != NULL) - gtk_entry_set_text(GTK_ENTRY(dialog->buddy_icon_entry), - gaim_account_get_buddy_icon(dialog->account)); + if (gaim_account_get_buddy_icon(dialog->account) != NULL) { + dialog->buddy_icon_path = g_strdup(gaim_account_get_buddy_icon(dialog->account)); + gtk_image_set_from_file(GTK_IMAGE(dialog->buddy_icon_entry),dialog->buddy_icon_path); + } } if (!dialog->prpl_info || (!(dialog->prpl_info->options & OPT_PROTO_MAIL_CHECK) && - !(dialog->prpl_info->options & OPT_PROTO_BUDDY_ICON))) { + (dialog->prpl_info->icon_spec.format == NULL))) { /* Nothing to see :( aww. */ gtk_widget_hide(dialog->user_frame); @@ -1099,15 +1164,15 @@ gaim_account_set_alias(dialog->account, NULL); /* Buddy Icon */ - value = gtk_entry_get_text(GTK_ENTRY(dialog->buddy_icon_entry)); - + value = dialog->buddy_icon_path; + if (dialog->prpl_info && - (dialog->prpl_info->options & OPT_PROTO_BUDDY_ICON) && - *value != '\0') - gaim_account_set_buddy_icon(dialog->account, value); - else + (dialog->prpl_info->icon_spec.format) && + *value != '\0') { + convert_and_set_buddy_icon(dialog->account, value); + } else { gaim_account_set_buddy_icon(dialog->account, NULL); - + } /* Remember Password */ gaim_account_set_remember_password(dialog->account, gtk_toggle_button_get_active(
--- a/src/protocols/gg/gg.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/gg/gg.c Sat Jun 19 04:57:43 2004 +0000 @@ -1,6 +1,6 @@ /* * gaim - Gadu-Gadu Protocol Plugin - * $Id: gg.c 10098 2004-06-15 21:59:04Z thekingant $ + * $Id: gg.c 10116 2004-06-19 04:57:43Z seanegan $ * * Copyright (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL> * @@ -1533,6 +1533,7 @@ 0, NULL, NULL, + NO_BUDDY_ICONS, agg_list_icon, agg_list_emblems, NULL,
--- a/src/protocols/irc/irc.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/irc/irc.c Sat Jun 19 04:57:43 2004 +0000 @@ -574,6 +574,7 @@ OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL, NULL, NULL, + NO_BUDDY_ICONS, irc_blist_icon, irc_blist_emblems, NULL,
--- a/src/protocols/jabber/jabber.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/jabber/jabber.c Sat Jun 19 04:57:43 2004 +0000 @@ -1465,6 +1465,7 @@ OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME, NULL, NULL, + NO_BUDDY_ICONS, jabber_list_icon, jabber_list_emblems, jabber_status_text,
--- a/src/protocols/msn/msn.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/msn/msn.c Sat Jun 19 04:57:43 2004 +0000 @@ -1631,9 +1631,10 @@ static GaimPluginProtocolInfo prpl_info = { GAIM_PRPL_API_VERSION, - OPT_PROTO_MAIL_CHECK | OPT_PROTO_BUDDY_ICON, + OPT_PROTO_MAIL_CHECK, NULL, NULL, + {"png", 96, 96}, msn_list_icon, msn_list_emblems, msn_status_text,
--- a/src/protocols/napster/napster.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/napster/napster.c Sat Jun 19 04:57:43 2004 +0000 @@ -553,6 +553,7 @@ OPT_PROTO_CHAT_TOPIC, NULL, NULL, + NO_BUDDY_ICONS, nap_list_icon, nap_list_emblems, NULL,
--- a/src/protocols/novell/novell.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/novell/novell.c Sat Jun 19 04:57:43 2004 +0000 @@ -3314,6 +3314,7 @@ 0, NULL, NULL, + NO_BUDDY_ICONS, novell_list_icon, novell_list_emblems, novell_status_text,
--- a/src/protocols/oscar/oscar.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/oscar/oscar.c Sat Jun 19 04:57:43 2004 +0000 @@ -7147,9 +7147,10 @@ static GaimPluginProtocolInfo prpl_info = { GAIM_PRPL_API_VERSION, - OPT_PROTO_MAIL_CHECK | OPT_PROTO_BUDDY_ICON | OPT_PROTO_IM_IMAGE, + OPT_PROTO_MAIL_CHECK | OPT_PROTO_IM_IMAGE, NULL, NULL, + {"jpeg,gif,bmp,ico", 50, 50}, oscar_list_icon, oscar_list_emblems, oscar_status_text,
--- a/src/protocols/rendezvous/rendezvous.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/rendezvous/rendezvous.c Sat Jun 19 04:57:43 2004 +0000 @@ -639,7 +639,8 @@ char hostname[255]; prpl_info.api_version = GAIM_PRPL_API_VERSION; - prpl_info.options = OPT_PROTO_NO_PASSWORD | OPT_PROTO_BUDDY_ICON; + prpl_info.options = OPT_PROTO_NO_PASSWORD; + prpl_info.icon_spec = {"FIXME, Mark!", 0,0}; prpl_info.list_icon = rendezvous_prpl_list_icon; prpl_info.list_emblems = rendezvous_prpl_list_emblems; prpl_info.status_text = rendezvous_prpl_status_text;
--- a/src/protocols/silc/silc.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/silc/silc.c Sat Jun 19 04:57:43 2004 +0000 @@ -1265,6 +1265,7 @@ OPT_PROTO_PASSWORD_OPTIONAL, NULL, NULL, + NO_BUDDY_ICONS, silcgaim_list_icon, silcgaim_list_emblems, silcgaim_status_text,
--- a/src/protocols/toc/toc.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/toc/toc.c Sat Jun 19 04:57:43 2004 +0000 @@ -2098,6 +2098,7 @@ 0, NULL, NULL, + NO_BUDDY_ICONS, toc_list_icon, toc_list_emblems, NULL,
--- a/src/protocols/trepia/trepia.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/trepia/trepia.c Sat Jun 19 04:57:43 2004 +0000 @@ -1197,9 +1197,10 @@ static GaimPluginProtocolInfo prpl_info = { GAIM_PRPL_API_VERSION, - OPT_PROTO_BUDDY_ICON, + 0, NULL, /* user_splits */ NULL, /* protocol_options */ + {"Christian, fix me!", 0, 0}, trepia_list_icon, trepia_list_emblems, trepia_status_text,
--- a/src/protocols/yahoo/yahoo.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/yahoo/yahoo.c Sat Jun 19 04:57:43 2004 +0000 @@ -3187,9 +3187,10 @@ static GaimPluginProtocolInfo prpl_info = { GAIM_PRPL_API_VERSION, - OPT_PROTO_MAIL_CHECK | OPT_PROTO_CHAT_TOPIC | OPT_PROTO_BUDDY_ICON, + OPT_PROTO_MAIL_CHECK | OPT_PROTO_CHAT_TOPIC, NULL, /* user_splits */ NULL, /* protocol_options */ + {"png", 96, 96}, yahoo_list_icon, yahoo_list_emblems, yahoo_status_text,
--- a/src/protocols/zephyr/zephyr.c Fri Jun 18 07:39:02 2004 +0000 +++ b/src/protocols/zephyr/zephyr.c Sat Jun 19 04:57:43 2004 +0000 @@ -1286,7 +1286,8 @@ OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD, NULL, NULL, - zephyr_list_icon, + NO_BUDDY_ICONS, + zephyr_list_icon, NULL, NULL, NULL,
--- a/src/prpl.h Fri Jun 18 07:39:02 2004 +0000 +++ b/src/prpl.h Sat Jun 19 04:57:43 2004 +0000 @@ -100,6 +100,21 @@ } GaimConvImFlags; +/** + * A description of a Buddy Icon specification. This tells Gaim what kind of image file + * it should give this prpl, and what kind of image file it should expect back. + */ +typedef struct { + char *format; /**< This is a comma-delimited list of image formats or NULL if icons are not supported. + * The core nor the prpl will actually check to see if the data it's given matches this, it's entirely + * up to the UI to do what it wants */ + int width; /**< The width of this icon */ + int height; /**< The height of this icon */ +} GaimBuddyIconSpec; + +/* This #define exists just to make it easier to fill out the buddy icon field in he prpl info struct for protocols that couldn't care less. */ +#define NO_BUDDY_ICONS {NULL, 0, 0} + #include "blist.h" #include "proxy.h" #include "plugin.h" @@ -146,8 +161,11 @@ * Buddy icon support. * * Oscar and Jabber have buddy icons. + * + * *We'll do this a bit more sophisticated like, now. + * + * OPT_PROTO_BUDDY_ICON = 0x00000040, */ - OPT_PROTO_BUDDY_ICON = 0x00000040, /** * Images in IMs. @@ -194,7 +212,9 @@ GList *user_splits; /* A GList of GaimAccountUserSplit */ GList *protocol_options; /* A GList of GaimAccountOption */ - + + GaimBuddyIconSpec icon_spec; /* The icon spec. */ + /** * Returns the base icon name for the given buddy and account. * If buddy is NULL, it will return the name to use for the account's icon