Mercurial > pidgin.yaz
changeset 13090:0aa231ebbfd5
[gaim-migrate @ 15452]
Changes to some pixbuf stuff.
I added a 'gaim_gtk_create_gaim_icon_with_status()' function to util.c,
and changed 'gaim_gtk_create_prpl_icon_with_status()' to accept a scale
factor because almost everywhere this function was used we would scale
the pixbuf to a smaller size as soon as we got it. So there's a bit less
code duplication.
Also, I think I added some g_object_unref()'s in one or two places where
it was missing.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 01 Feb 2006 22:38:34 +0000 |
parents | b553326bc468 |
children | 7aea8de78463 |
files | plugins/gevolution/add_buddy_dialog.c plugins/gevolution/gevolution.c src/gtkaccount.c src/gtkblist.c src/gtkconv.c src/gtklog.c src/gtknotify.c src/gtkpounce.c src/gtksavedstatuses.c src/gtkstatusbox.c src/gtkutils.c src/gtkutils.h |
diffstat | 12 files changed, 261 insertions(+), 248 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/gevolution/add_buddy_dialog.c Wed Feb 01 06:07:53 2006 +0000 +++ b/plugins/gevolution/add_buddy_dialog.c Wed Feb 01 22:38:34 2006 +0000 @@ -163,7 +163,7 @@ GaimAccount *account = NULL; GList *l; GtkTreeIter iter; - GdkPixbuf *pixbuf, *icon = NULL; + GdkPixbuf *pixbuf; if (list == NULL) return; @@ -183,11 +183,7 @@ if (account == NULL) return; - pixbuf = gaim_gtk_create_prpl_icon(account); - - if (pixbuf != NULL) - icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); for (l = list; l != NULL; l = l->next) { @@ -203,7 +199,7 @@ gtk_list_store_set(dialog->model, &iter, COLUMN_NAME, name, - COLUMN_PRPL_ICON, icon, + COLUMN_PRPL_ICON, pixbuf, COLUMN_USERNAME, account_name, COLUMN_DATA, contact, -1); @@ -223,8 +219,8 @@ } } - if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); - if (icon != NULL) g_object_unref(G_OBJECT(icon)); + if (pixbuf != NULL) + g_object_unref(G_OBJECT(pixbuf)); g_list_foreach(list, (GFunc)g_free, NULL); g_list_free(list); @@ -611,19 +607,16 @@ EContact *contact, const char *name, GaimAccount *account, const char *screenname) { - GdkPixbuf *pixbuf, *icon = NULL; + GdkPixbuf *pixbuf; GtkTreeIter iter; - pixbuf = gaim_gtk_create_prpl_icon(account); - - if (pixbuf != NULL) - icon = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); gtk_list_store_append(dialog->model, &iter); gtk_list_store_set(dialog->model, &iter, COLUMN_NAME, name, - COLUMN_PRPL_ICON, icon, + COLUMN_PRPL_ICON, pixbuf, COLUMN_DATA, contact, COLUMN_USERNAME, screenname, -1); @@ -631,6 +624,6 @@ if (contact != NULL) dialog->contacts = g_list_append(dialog->contacts, contact); - if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); - if (icon != NULL) g_object_unref(G_OBJECT(icon)); + if (pixbuf != NULL) + g_object_unref(G_OBJECT(pixbuf)); }
--- a/plugins/gevolution/gevolution.c Wed Feb 01 06:07:53 2006 +0000 +++ b/plugins/gevolution/gevolution.c Wed Feb 01 22:38:34 2006 +0000 @@ -405,7 +405,7 @@ GtkWidget *treeview; GtkTreeViewColumn *column; GtkCellRenderer *renderer; - GdkPixbuf *pixbuf, *scale = NULL; + GdkPixbuf *pixbuf; GtkListStore *model; GList *l; @@ -483,29 +483,22 @@ gtk_list_store_append(model, &iter); - pixbuf = gaim_gtk_create_prpl_icon(account); - - if (pixbuf != NULL) - { - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); - - if (!gaim_account_is_connected(account)) - gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); - } + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); + if ((pixbuf != NULL) && (!gaim_account_is_connected(account))) + gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); gtk_list_store_set(model, &iter, COLUMN_AUTOADD, gaim_account_get_bool(account, "gevo-autoadd", FALSE), - COLUMN_ICON, scale, + COLUMN_ICON, pixbuf, COLUMN_SCREENNAME, gaim_account_get_username(account), COLUMN_DATA, account, -1); - if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); - if (scale != NULL) g_object_unref(G_OBJECT(scale)); + if (pixbuf != NULL) + g_object_unref(G_OBJECT(pixbuf)); } gtk_widget_show_all(ret);
--- a/src/gtkaccount.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtkaccount.c Wed Feb 01 22:38:34 2006 +0000 @@ -1828,7 +1828,7 @@ GaimGtkPulseData *pulse_data; GtkTreeModel *model; GtkTreeIter iter; - GdkPixbuf *pixbuf, *scale = NULL; + GdkPixbuf *pixbuf; size_t index; /* Don't need to do anything if the accounts window is not visible */ @@ -1854,24 +1854,18 @@ g_free(pulse_data); } - pixbuf = gaim_gtk_create_prpl_icon(account); + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); + if ((pixbuf != NULL) && gaim_account_is_disconnected(account)) + gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); + + gtk_list_store_set(accounts_window->model, &iter, + COLUMN_ICON, pixbuf, + COLUMN_PULSE_DATA, NULL, + -1); + if (pixbuf != NULL) - { - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); - - if (gaim_account_is_disconnected(account)) - gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); - } - gtk_list_store_set(accounts_window->model, &iter, - COLUMN_ICON, scale, - COLUMN_PULSE_DATA, NULL, - -1); - - - if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); - if (scale != NULL) g_object_unref(G_OBJECT(scale)); + g_object_unref(G_OBJECT(pixbuf)); } } @@ -2259,30 +2253,21 @@ set_account(GtkListStore *store, GtkTreeIter *iter, GaimAccount *account) { GdkPixbuf *pixbuf; - GdkPixbuf *scale; - - scale = NULL; - - pixbuf = gaim_gtk_create_prpl_icon(account); - - if (pixbuf != NULL) - { - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); - - if (gaim_account_is_disconnected(account)) - gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); - } + + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); + if ((pixbuf != NULL) && gaim_account_is_disconnected(account)) + gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); gtk_list_store_set(store, iter, - COLUMN_ICON, scale, + COLUMN_ICON, pixbuf, COLUMN_SCREENNAME, gaim_account_get_username(account), COLUMN_ENABLED, gaim_account_get_enabled(account, GAIM_GTK_UI), COLUMN_PROTOCOL, gaim_account_get_protocol_name(account), COLUMN_DATA, account, -1); - if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); - if (scale != NULL) g_object_unref(G_OBJECT(scale)); + if (pixbuf != NULL) + g_object_unref(G_OBJECT(pixbuf)); } static void
--- a/src/gtkblist.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtkblist.c Wed Feb 01 22:38:34 2006 +0000 @@ -3492,9 +3492,10 @@ gpointer user_data) { GaimAccount *account; - gchar *escaped, *text, *filename; + GaimStatusType *status_type; + gchar *escaped, *text; GtkWidget *button, *label, *image, *hbox; - GdkPixbuf *pixbuf, *emblem, *scale; + GdkPixbuf *pixbuf; account = key; escaped = g_markup_escape_text((const gchar *)value, -1); @@ -3506,32 +3507,12 @@ hbox = gtk_hbox_new(FALSE, 0); /* Create the icon */ - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "offline.png", NULL); - pixbuf = gdk_pixbuf_new_from_file(filename, NULL); - g_free(filename); + status_type = gaim_account_get_status_type_with_primitive(account, + GAIM_STATUS_OFFLINE); + pixbuf = gaim_gtk_create_prpl_icon_with_status(account, status_type, 0.5); if (pixbuf != NULL) { - scale = gdk_pixbuf_scale_simple(pixbuf, 10, 10, - GDK_INTERP_BILINEAR); + image = gtk_image_new_from_pixbuf(pixbuf); g_object_unref(pixbuf); - emblem = scale; - scale = NULL; - - pixbuf = gaim_gtk_create_prpl_icon(account); - if (pixbuf != NULL) { - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); - gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); - g_object_unref(G_OBJECT(pixbuf)); - - gdk_pixbuf_composite(emblem, scale, 6, 6, 10, 10, 6, 6, 1, 1, - GDK_INTERP_BILINEAR, 255); - g_object_unref(emblem); - - emblem = scale; - } - - image = gtk_image_new_from_pixbuf(emblem); - g_object_unref(emblem); gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, GAIM_HIG_BOX_SPACE); @@ -5545,7 +5526,7 @@ GaimConnection *gc = NULL; GaimAccount *account = NULL; GaimStatus *status = NULL; - GdkPixbuf *pixbuf = NULL, *scale = NULL; + GdkPixbuf *pixbuf = NULL; account = accounts->data; @@ -5555,16 +5536,14 @@ menuitem = gtk_image_menu_item_new_with_label(buf); g_free(buf); status = gaim_account_get_active_status(account); - pixbuf = gaim_gtk_create_prpl_icon_with_status(account, gaim_status_get_type(status)); - if (pixbuf) { - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); + pixbuf = gaim_gtk_create_prpl_icon_with_status(account, gaim_status_get_type(status), 0.5); + if (pixbuf != NULL) + { if (!gaim_account_is_connected(account)) - gdk_pixbuf_saturate_and_pixelate(scale, scale, + gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); - image = gtk_image_new_from_pixbuf(scale); + image = gtk_image_new_from_pixbuf(pixbuf); g_object_unref(G_OBJECT(pixbuf)); - g_object_unref(G_OBJECT(scale)); gtk_widget_show(image); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); } @@ -5647,7 +5626,7 @@ char *buf = NULL; GtkWidget *image = NULL; GaimAccount *account = NULL; - GdkPixbuf *pixbuf = NULL, *scale = NULL; + GdkPixbuf *pixbuf = NULL; account = accounts->data; @@ -5659,15 +5638,13 @@ gaim_account_get_protocol_name(account), ")", NULL); menuitem = gtk_image_menu_item_new_with_label(buf); g_free(buf); - pixbuf = gaim_gtk_create_prpl_icon(account); - if (pixbuf) { - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); - if (gaim_account_is_disconnected(account)) - gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.00, FALSE); - image = gtk_image_new_from_pixbuf(scale); + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); + if (pixbuf != NULL) + { + if (!gaim_account_is_connected(account)) + gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); + image = gtk_image_new_from_pixbuf(pixbuf); g_object_unref(G_OBJECT(pixbuf)); - g_object_unref(G_OBJECT(scale)); gtk_widget_show(image); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); }
--- a/src/gtkconv.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtkconv.c Wed Feb 01 22:38:34 2006 +0000 @@ -2220,6 +2220,7 @@ g_return_val_if_fail(account != NULL, NULL); g_return_val_if_fail(name != NULL, NULL); + /* Use the buddy icon, if possible */ if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) { GaimBuddy *b = gaim_find_buddy(account, name); if (b != NULL) { @@ -2228,19 +2229,10 @@ } } - if (!status) { - GdkPixbuf *pixbuf; - pixbuf = gaim_gtk_create_prpl_icon(account); - - if (small_icon && pixbuf != NULL) - { - status = gdk_pixbuf_scale_simple(pixbuf, 15, 15, - GDK_INTERP_BILINEAR); - g_object_unref(pixbuf); - } - else - status = pixbuf; - } + /* If they don't have a buddy icon, then use the PRPL icon */ + if (status == NULL) + status = gaim_gtk_create_prpl_icon(account, small_icon ? 0.5 : 1.0); + return status; } @@ -3036,25 +3028,19 @@ if (buddy != NULL) pixbuf = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy, GAIM_STATUS_ICON_SMALL); else - { - GdkPixbuf *unscaled = gaim_gtk_create_prpl_icon(account); - - /* XXX: 15 is the size for GAIM_STATUS_ICON_SMALL in gtkblist.c */ - pixbuf = gdk_pixbuf_scale_simple(unscaled, 15, 15, - GDK_INTERP_BILINEAR); - g_object_unref(G_OBJECT(unscaled)); - } + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); /* Now convert it to GtkImage */ if (pixbuf == NULL) image = gtk_image_new(); else + { image = gtk_image_new_from_pixbuf(pixbuf); + g_object_unref(G_OBJECT(pixbuf)); + } gtk_size_group_add_widget(sg, image); - g_object_unref(G_OBJECT(pixbuf)); - /* Make our menu item */ text = g_strdup_printf("%s (%s)", name, gaim_account_get_username(account)); menuitem = gtk_radio_menu_item_new_with_label(*group, text); @@ -5542,7 +5528,7 @@ win = gaim_gtkconv_get_window(gtkconv); if (!win) return; - + if (fields & GAIM_GTKCONV_SET_TITLE) { gaim_conversation_autoset_title(conv);
--- a/src/gtklog.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtklog.c Wed Feb 01 22:38:34 2006 +0000 @@ -501,7 +501,7 @@ } display_log_viewer(ht, gaim_log_get_logs(type, screenname, account), - title, gaim_gtk_create_prpl_icon(account), gaim_log_get_total_size(type, screenname, account)); + title, gaim_gtk_create_prpl_icon(account, 0.5), gaim_log_get_total_size(type, screenname, account)); g_free(title); }
--- a/src/gtknotify.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtknotify.c Wed Feb 01 22:38:34 2006 +0000 @@ -392,7 +392,7 @@ gtk_tree_view_column_pack_start(column, rend, TRUE); gtk_tree_view_column_set_attributes(column, rend, "markup", GAIM_MAIL_SUBJECT, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(mail_dialog->treeview), column); - + gtk_container_add(GTK_CONTAINER(sw), mail_dialog->treeview); label = gtk_label_new(NULL); @@ -410,7 +410,7 @@ while (count--) { char *from_text = NULL, *subject_text = NULL; - GdkPixbuf *pixbuf, *scale = NULL; + GdkPixbuf *pixbuf; if (froms != NULL) from_text = g_markup_escape_text(*froms, -1); @@ -421,22 +421,18 @@ data = g_new0(GaimNotifyMailData, 1); data->url = g_strdup(*urls); - pixbuf = gaim_gtk_create_prpl_icon(account); - if (pixbuf != NULL) - { - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); - g_object_unref(pixbuf); - } + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); gtk_tree_store_append(mail_dialog->treemodel, &iter, NULL); gtk_tree_store_set(mail_dialog->treemodel, &iter, - GAIM_MAIL_ICON, scale, + GAIM_MAIL_ICON, pixbuf, GAIM_MAIL_TO, *tos, GAIM_MAIL_FROM, from_text, GAIM_MAIL_SUBJECT, subject_text, GAIM_MAIL_DATA, data, -1); + if (pixbuf != NULL) + g_object_unref(pixbuf); data->iter = iter; urls++; froms++; @@ -581,15 +577,14 @@ GaimNotifySearchResultsData *data = data_; GtkListStore *model = data->model; GtkTreeIter iter; - GdkPixbuf *icon, *scaled; + GdkPixbuf *pixbuf; guint col_num; guint i; guint j; - + gtk_list_store_clear(data->model); - icon = gaim_gtk_create_prpl_icon(gaim_connection_get_account(gc)); - scaled = gdk_pixbuf_scale_simple(icon, 16, 16, GDK_INTERP_BILINEAR); + pixbuf = gaim_gtk_create_prpl_icon(gaim_connection_get_account(gc), 0.5); /* +1 is for the automagically created Status column. */ col_num = gaim_notify_searchresults_get_columns_count(results) + 1; @@ -598,7 +593,7 @@ GList *row = gaim_notify_searchresults_row_get(results, i); gtk_list_store_append(model, &iter); - gtk_list_store_set(model, &iter, 0, scaled, -1); + gtk_list_store_set(model, &iter, 0, pixbuf, -1); for (j = 1; j < col_num; j++) { GValue v; @@ -611,6 +606,9 @@ g_free(escaped); } } + + if (pixbuf != NULL) + g_object_unref(pixbuf); } static void *
--- a/src/gtkpounce.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtkpounce.c Wed Feb 01 22:38:34 2006 +0000 @@ -185,7 +185,7 @@ gboolean recurring; const char *pouncer; const char *pouncee; - GdkPixbuf *pixbuf, *scale = NULL; + GdkPixbuf *pixbuf; account = gaim_pounce_get_pouncer(pounce); @@ -194,11 +194,7 @@ events = gaim_pounce_get_events(pounce); - pixbuf = gaim_gtk_create_prpl_icon(account); - - if (pixbuf != NULL) - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, - GDK_INTERP_BILINEAR); + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); pouncer = gaim_account_get_username(account); pouncee = gaim_pounce_get_pouncee(pounce); @@ -207,11 +203,14 @@ gtk_list_store_append(model, &iter); gtk_list_store_set(model, &iter, POUNCES_MANAGER_COLUMN_POUNCE, pounce, - POUNCES_MANAGER_COLUMN_ICON, scale, + POUNCES_MANAGER_COLUMN_ICON, pixbuf, POUNCES_MANAGER_COLUMN_TARGET, pouncee, POUNCES_MANAGER_COLUMN_ACCOUNT, pouncer, POUNCES_MANAGER_COLUMN_RECURRING, recurring, -1); + + if (pixbuf != NULL) + g_object_unref(pixbuf); } static void
--- a/src/gtksavedstatuses.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtksavedstatuses.c Wed Feb 01 22:38:34 2006 +0000 @@ -921,19 +921,12 @@ GtkTreeIter *iter, GaimSavedStatusSub *substatus) { GdkPixbuf *pixbuf; - GdkPixbuf *scale; const char *id = NULL, *name = NULL, *message = NULL; - scale = NULL; - - pixbuf = gaim_gtk_create_prpl_icon(account); - - if (pixbuf != NULL) + pixbuf = gaim_gtk_create_prpl_icon(account, 0.5); + if ((pixbuf != NULL) && !gaim_account_is_connected(account)) { - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); - - if (gaim_account_is_disconnected(account)) - gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); + gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); } if (substatus != NULL) @@ -950,15 +943,15 @@ gtk_list_store_set(store, iter, STATUS_EDITOR_COLUMN_ACCOUNT, account, STATUS_EDITOR_COLUMN_ENABLE_SUBSTATUS, (substatus != NULL), - STATUS_EDITOR_COLUMN_ICON, scale, + STATUS_EDITOR_COLUMN_ICON, pixbuf, STATUS_EDITOR_COLUMN_SCREENNAME, gaim_account_get_username(account), STATUS_EDITOR_COLUMN_STATUS_ID, id, STATUS_EDITOR_COLUMN_STATUS_NAME, name, STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message, -1); - if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); - if (scale != NULL) g_object_unref(G_OBJECT(scale)); + if (pixbuf != NULL) + g_object_unref(G_OBJECT(pixbuf)); } static void @@ -1459,7 +1452,7 @@ for (list = gaim_account_get_status_types(account); list; list = list->next) { GaimStatusType *status_type; - GdkPixbuf *pixbuf, *scale = NULL; + GdkPixbuf *pixbuf; const char *id, *name; status_type = list->data; @@ -1469,18 +1462,18 @@ continue; id = gaim_status_type_get_id(status_type); - pixbuf = gaim_gtk_create_prpl_icon_with_status(account, status_type); - if (pixbuf != NULL) - scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); + pixbuf = gaim_gtk_create_prpl_icon_with_status(account, status_type, 0.5); name = gaim_status_type_get_name(status_type); gtk_list_store_append(dialog->model, &iter); gtk_list_store_set(dialog->model, &iter, SUBSTATUS_COLUMN_ACCOUNT, account, - SUBSTATUS_COLUMN_ICON, scale, + SUBSTATUS_COLUMN_ICON, pixbuf, SUBSTATUS_COLUMN_STATUS_ID, id, SUBSTATUS_COLUMN_STATUS_NAME, name, -1); + if (pixbuf != NULL) + g_object_unref(pixbuf); if (id && !strcmp(id, gaim_status_type_get_id(status_type))) { gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
--- a/src/gtkstatusbox.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtkstatusbox.c Wed Feb 01 22:38:34 2006 +0000 @@ -488,9 +488,9 @@ static void add_popular_statuses(GtkGaimStatusBox *statusbox) { + gboolean show_buddy_icons; GList *list, *cur; GtkIconSize icon_size; - const GdkPixbuf *orig; GdkPixbuf *pixbuf, *emblem; int width, height; @@ -499,27 +499,12 @@ /* Odd... oh well, nothing we can do about it. */ return; - if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) + show_buddy_icons = gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"); + if (show_buddy_icons) icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); else icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL); - /* Create the icon to use for non-transient saved-statuses */ - orig = gtk_widget_render_icon(GTK_WIDGET(statusbox->vbox), - GAIM_STOCK_STATUS_ONLINE, icon_size, "GtkGaimStatusBox"); - pixbuf = gdk_pixbuf_copy(orig); - g_object_unref(G_OBJECT(orig)); - - emblem = gtk_widget_render_icon(GTK_WIDGET(statusbox->vbox), - GTK_STOCK_SAVE, icon_size, "GtkGaimStatusBox"); - width = gdk_pixbuf_get_width(pixbuf) / 2; - height = gdk_pixbuf_get_height(pixbuf) / 2; - - gdk_pixbuf_composite(emblem, pixbuf, width, height, - width, height, width, height, - 0.5, 0.5, GDK_INTERP_BILINEAR, 255); - g_object_unref(G_OBJECT(emblem)); - gtk_gaim_status_box_add_separator(statusbox); for (cur = list; cur != NULL; cur = cur->next) @@ -528,7 +513,9 @@ const gchar *message; gchar *stripped; - /* TODO: For transient saved-statuses, make a new icon showing the primitive */ + /* Get an appropriate status icon */ + pixbuf = gaim_gtk_create_gaim_icon_with_status(gaim_savedstatus_get_type(saved), + show_buddy_icons ? 1.0 : 0.5); if (gaim_savedstatus_is_transient(saved)) { @@ -544,11 +531,27 @@ message = gaim_savedstatus_get_message(saved); stripped = gaim_markup_strip_html(message); gaim_util_chrreplace(stripped, '\n', ' '); + + /* Overlay a disk in the bottom left corner */ + emblem = gtk_widget_render_icon(GTK_WIDGET(statusbox->vbox), + GTK_STOCK_SAVE, icon_size, "GtkGaimStatusBox"); + if (emblem != NULL) + { + width = gdk_pixbuf_get_width(pixbuf) / 2; + height = gdk_pixbuf_get_height(pixbuf) / 2; + gdk_pixbuf_composite(emblem, pixbuf, 0, height, + width, height, 0, height, + 0.5, 0.5, GDK_INTERP_BILINEAR, 255); + g_object_unref(G_OBJECT(emblem)); + } } + gtk_gaim_status_box_add(statusbox, GTK_GAIM_STATUS_BOX_TYPE_POPULAR, pixbuf, gaim_savedstatus_get_title(saved), stripped, GINT_TO_POINTER(gaim_savedstatus_get_creation_time(saved))); g_free(stripped); + if (pixbuf != NULL) + g_object_unref(G_OBJECT(pixbuf)); } g_list_free(list); @@ -557,11 +560,13 @@ static void gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) { + gboolean show_buddy_icons; GaimAccount *account; - GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; + GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4, *tmp; GtkIconSize icon_size; - if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) + show_buddy_icons = gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"); + if (show_buddy_icons) icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); else icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL); @@ -608,11 +613,15 @@ if (!gaim_status_type_is_user_settable(status_type)) continue; + tmp = gaim_gtk_create_prpl_icon_with_status(account, status_type, + show_buddy_icons ? 1.0 : 0.5); gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), gaim_status_type_get_primitive(status_type), - gaim_gtk_create_prpl_icon_with_status(account, status_type), + tmp, gaim_status_type_get_name(status_type), NULL, NULL); + if (tmp != NULL) + g_object_unref(tmp); } update_to_reflect_account_status(status_box, account, gaim_account_get_active_status(account));
--- a/src/gtkutils.c Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtkutils.c Wed Feb 01 22:38:34 2006 +0000 @@ -57,6 +57,7 @@ #include "gtkdialogs.h" #include "gtkimhtml.h" #include "gtkimhtmltoolbar.h" +#include "gtkstock.h" #include "gtkthemes.h" #include "gtkutils.h" @@ -1543,26 +1544,26 @@ } GdkPixbuf * -gaim_gtk_create_prpl_icon(GaimAccount *account) +gaim_gtk_create_prpl_icon(GaimAccount *account, double scale_factor) { GaimPlugin *prpl; - GaimPluginProtocolInfo *prpl_info = NULL; - GdkPixbuf *status = NULL; - char *filename = NULL; + GaimPluginProtocolInfo *prpl_info; const char *protoname = NULL; char buf[256]; /* TODO: We should use a define for max file length */ + char *filename = NULL; + GdkPixbuf *pixbuf, *scaled; g_return_val_if_fail(account != NULL, NULL); prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); - - if (prpl != NULL) { - prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); + if (prpl == NULL) + return NULL; - if (prpl_info->list_icon != NULL) - protoname = prpl_info->list_icon(account, NULL); - } + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); + if (prpl_info->list_icon == NULL) + return NULL; + protoname = prpl_info->list_icon(account, NULL); if (protoname == NULL) return NULL; @@ -1574,53 +1575,90 @@ filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", buf, NULL); - status = gdk_pixbuf_new_from_file(filename, NULL); + pixbuf = gdk_pixbuf_new_from_file(filename, NULL); g_free(filename); - return status; + scaled = gdk_pixbuf_scale_simple(pixbuf, 30*scale_factor, + 30*scale_factor, GDK_INTERP_BILINEAR); + g_object_unref(pixbuf); + + return scaled; +} + +static GdkPixbuf * +overlay_status_onto_icon(GdkPixbuf *pixbuf, GaimStatusPrimitive primitive) +{ + const char *type_name; + char basename[256]; + char *filename; + GdkPixbuf *emblem; + + type_name = gaim_primitive_get_id_from_type(primitive); + + g_snprintf(basename, sizeof(basename), "%s.png", type_name); + filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", + "default", basename, NULL); + emblem = gdk_pixbuf_new_from_file(filename, NULL); + g_free(filename); + + if (emblem != NULL) { + int width, height, emblem_width, emblem_height, new_emblem_width, new_emblem_height; + width = gdk_pixbuf_get_width(pixbuf); + height = gdk_pixbuf_get_height(pixbuf); + emblem_width = gdk_pixbuf_get_width(emblem); + emblem_height = gdk_pixbuf_get_height(emblem); + new_emblem_width = width / 2; + new_emblem_height = height / 2; + /* Overlay emblem onto the bottom right corner of pixbuf */ + gdk_pixbuf_composite(emblem, pixbuf, + width - new_emblem_width, height - new_emblem_height, + new_emblem_width, new_emblem_height, + width - new_emblem_width, height - new_emblem_height, + (double)new_emblem_width / (double)emblem_width, + (double)new_emblem_height / (double)emblem_height, + GDK_INTERP_BILINEAR, + 255); + g_object_unref(emblem); + } + + return pixbuf; } GdkPixbuf * -gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type) +gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type, double scale_factor) { - char basename2[256]; - char *filename; - const char *type_name; - GdkPixbuf *pixbuf, *scale = NULL, *emblem; + GdkPixbuf *pixbuf; + + pixbuf = gaim_gtk_create_prpl_icon(account, scale_factor); + if (pixbuf == NULL) + return NULL; - pixbuf = gaim_gtk_create_prpl_icon(account); + /* + * TODO: Let the prpl pick the emblem on a per status basis, + * and only use the primitive as a fallback? + */ - if (pixbuf != NULL) { - scale = gdk_pixbuf_scale_simple(pixbuf, 32, 32, - GDK_INTERP_BILINEAR); - g_object_unref(G_OBJECT(pixbuf)); - } else { - return NULL; - } + return overlay_status_onto_icon(pixbuf, + gaim_status_type_get_primitive(status_type)); +} - /* TODO: let the prpl pick the emblem on a per status basis, and only - * use the primitive as a fallback */ - type_name = gaim_primitive_get_id_from_type(gaim_status_type_get_primitive(status_type)); - - g_snprintf(basename2, sizeof(basename2), "%s.png", - type_name); - filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", - basename2, NULL); - emblem = gdk_pixbuf_new_from_file(filename, NULL); - g_free(filename); +GdkPixbuf * +gaim_gtk_create_gaim_icon_with_status(GaimStatusPrimitive primitive, double scale_factor) +{ + gchar *filename; + GdkPixbuf *orig, *pixbuf; - if (emblem) { - gdk_pixbuf_composite(emblem, - scale, 32-15, 32-15, - 15, 15, - 32-15, 32-15, - 1, 1, - GDK_INTERP_BILINEAR, - 255); + filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL); + orig = gdk_pixbuf_new_from_file(filename, NULL); + g_free(filename); + if (orig == NULL) + return NULL; - g_object_unref(emblem); - } - return scale; + pixbuf = gdk_pixbuf_scale_simple(orig, 30*scale_factor, + 30*scale_factor, GDK_INTERP_BILINEAR); + g_object_unref(G_OBJECT(orig)); + + return overlay_status_onto_icon(pixbuf, primitive); } static void
--- a/src/gtkutils.h Wed Feb 01 06:07:53 2006 +0000 +++ b/src/gtkutils.h Wed Feb 01 22:38:34 2006 +0000 @@ -355,21 +355,63 @@ * Returns the base image to represent the account, based on * the currently selected theme. * - * @param account The account. + * @param account The account. + * @param scale_factor The amount to scale to the original image. + * The default size is 30x30 pixels. A scale + * factor of 1 means no scaling will be done. + * A scale factor of 0.5 means the length + * and width will be 15 pixels each. * - * @return The icon. + * @return A newly-created pixbuf with a reference count of 1, + * or NULL if any of several error conditions occurred: + * the file could not be opened, there was no loader + * for the file's format, there was not enough memory + * to allocate the image buffer, or the image file + * contained invalid data. */ -GdkPixbuf *gaim_gtk_create_prpl_icon(GaimAccount *account); +GdkPixbuf *gaim_gtk_create_prpl_icon(GaimAccount *account, double scale_factor); /** - * Create a protocol-icon with the status emblem. + * Create a protocol icon with the status emblem overlayed in + * the lower right corner. + * + * @param account The account. + * @param status_type The status type of the emblem to overlay. + * @param scale_factor The amount to scale to the original image. + * The default size is 30x30 pixels. A scale + * factor of 1 means no scaling will be done. + * A scale factor of 0.5 means the length + * and width will be 15 pixels each. * - * @param account The account. - * @param status_type The status type to set the emblem for. + * @return A newly-created pixbuf with a reference count of 1, + * or NULL if any of several error conditions occurred: + * the file could not be opened, there was no loader + * for the file's format, there was not enough memory + * to allocate the image buffer, or the image file + * contained invalid data. + */ +GdkPixbuf *gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type, double scale_factor); + +/** + * Create a Gaim running-man icon with the status emblem overlayed + * in the lower right corner. * - * @return The icon. + * @param status_type The status type to set the emblem for. + * @param scale_factor The amount to scale to the original image. + * The default size is 30x30 pixels. A scale + * factor of 1 means no scaling will be done. + * A scale factor of 0.5 means the length + * and width will be 15 pixels each. + * + * @return A newly-created pixbuf with a reference count of 1, + * or NULL if any of several error conditions occurred: + * the file could not be opened, there was no loader for + * the file's format, there was not enough memory to + * allocate the image buffer, or the image file contained + * invalid data. */ -GdkPixbuf * gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type); +GdkPixbuf *gaim_gtk_create_gaim_icon_with_status(GaimStatusPrimitive primitve, double scale_factor); + /** * Append a GaimMenuAction to a menu.