From 623cac7a837b571d342d6e7cdeb9c832393d0b61 Mon Sep 17 00:00:00 2001 From: Gary Kramlich Date: Tue, 23 Aug 2022 02:25:05 -0500 Subject: Remove pidgin_create_icon_from_protocol and pidgin_create_protocol_icon Testing Done: Compiled. Reviewed at https://reviews.imfreedom.org/r/1628/ --- ChangeLog.API | 2 ++ pidgin/gtkblist.c | 56 ++++++++++++++----------------- pidgin/gtknotify.c | 23 +++++++------ pidgin/gtkrequest.c | 54 ++++-------------------------- pidgin/gtkutils.c | 65 ------------------------------------ pidgin/gtkutils.h | 38 --------------------- pidgin/pidginaccountstore.c | 11 +++--- pidgin/pidginaccountstore.h | 2 +- pidgin/resources/Accounts/chooser.ui | 2 +- 9 files changed, 54 insertions(+), 199 deletions(-) diff --git a/ChangeLog.API b/ChangeLog.API index a633e1b773..69a5b04bf8 100644 --- a/ChangeLog.API +++ b/ChangeLog.API @@ -927,6 +927,8 @@ version 3.0.0 (??/??/????): * pidgin_conversations_fill_menu * pidgin_conversations_get_unseen_all * pidgin_create_dialog, use pidgin_dialog_new instead. + * pidgin_create_icon_from_protocol + * pidgin_create_protocol_icon * pidgin_create_small_button, use pidgin_close_button_new instead. * pidgin_create_status_icon * pidgin_create_window, use pidgin_window_new instead. diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c index 30ffbd7d2b..4049cd95cc 100644 --- a/pidgin/gtkblist.c +++ b/pidgin/gtkblist.c @@ -89,7 +89,7 @@ enum { NODE_COLUMN, EMBLEM_COLUMN, EMBLEM_VISIBLE_COLUMN, - PROTOCOL_ICON_COLUMN, + PROTOCOL_ICON_NAME_COLUMN, BLIST_COLUMNS }; @@ -1897,18 +1897,17 @@ static gboolean buddy_is_displayable(PurpleBuddy *buddy) static void add_tip_for_account(GtkWidget *grid, gint row, PurpleAccount *account) { - GdkPixbuf *protocol_icon = NULL; + PurpleProtocol *protocol = NULL; GtkWidget *image = NULL; GtkWidget *name = NULL; + const gchar *icon_name = NULL; - protocol_icon = pidgin_create_protocol_icon(account, PIDGIN_PROTOCOL_ICON_SMALL); - if (purple_account_is_disconnected(account)) { - gdk_pixbuf_saturate_and_pixelate(protocol_icon, protocol_icon, 0.0, FALSE); - } - image = gtk_image_new_from_pixbuf(protocol_icon); + protocol = purple_account_get_protocol(account); + icon_name = purple_protocol_get_icon_name(protocol); + + image = gtk_image_new_from_icon_name(icon_name); gtk_image_set_pixel_size(GTK_IMAGE(image), STATUS_SIZE); gtk_grid_attach(GTK_GRID(grid), image, 0, row, 1, 1); - g_clear_object(&protocol_icon); name = gtk_label_new(purple_account_get_username(account)); gtk_label_set_xalign(GTK_LABEL(name), 0); @@ -1965,13 +1964,13 @@ add_tip_for_node(GtkWidget *grid, gint row, PurpleBlistNode *node, gboolean full gtk_grid_attach(GTK_GRID(grid), name, 1, row, 1, 1); if (account != NULL) { - GdkPixbuf *protocol_icon = pidgin_create_protocol_icon( - account, PIDGIN_PROTOCOL_ICON_SMALL); - image = gtk_image_new_from_pixbuf(protocol_icon); + PurpleProtocol *protocol = purple_account_get_protocol(account); + const gchar *icon_name = purple_protocol_get_icon_name(protocol); + + image = gtk_image_new_from_icon_name(icon_name); gtk_image_set_pixel_size(GTK_IMAGE(image), STATUS_SIZE); gtk_widget_set_halign(image, GTK_ALIGN_END); gtk_grid_attach(GTK_GRID(grid), image, 2, row, 1, 1); - g_clear_object(&protocol_icon); } tooltip_text = pidgin_get_tooltip_text(node, full); @@ -1986,12 +1985,6 @@ add_tip_for_node(GtkWidget *grid, gint row, PurpleBlistNode *node, gboolean full } avatar = pidgin_blist_get_buddy_icon(node, !full, FALSE); -#if 0 /* Protocol Icon as avatar */ - if(!avatar && full) { - avatar = pidgin_create_protocol_icon(account, PIDGIN_PROTOCOL_ICON_LARGE); - } -#endif - if (avatar != NULL) { avatar_image = gtk_image_new_from_pixbuf(avatar); gtk_widget_set_halign(avatar_image, GTK_ALIGN_END); @@ -2980,7 +2973,7 @@ pidgin_blist_build_layout(PurpleBuddyList *list) rend = gtk_cell_renderer_pixbuf_new(); gtk_tree_view_column_pack_start(column, rend, FALSE); gtk_tree_view_column_set_attributes(column, rend, - "pixbuf", PROTOCOL_ICON_COLUMN, + "icon-name", PROTOCOL_ICON_NAME_COLUMN, NULL); g_object_set(rend, "xalign", 0.0, "xpad", 3, "ypad", 0, NULL); @@ -3097,7 +3090,7 @@ static void pidgin_blist_show(PurpleBuddyList *list) G_TYPE_POINTER, /* Node */ GDK_TYPE_PIXBUF, /* Emblem */ G_TYPE_BOOLEAN, /* Emblem visible */ - GDK_TYPE_PIXBUF /* Protocol icon */ + G_TYPE_STRING /* Protocol icon */ ); gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); @@ -3469,10 +3462,12 @@ static char *pidgin_get_group_title(PurpleBlistNode *gnode, gboolean expanded) static void buddy_node(PurpleBuddy *buddy, GtkTreeIter *iter, PurpleBlistNode *node) { PurplePresence *presence = purple_buddy_get_presence(buddy); - GdkPixbuf *status, *avatar, *emblem, *protocol_icon; + PurpleProtocol *protocol = NULL; + GdkPixbuf *status, *avatar, *emblem; char *mark; char *idle = NULL; gboolean selected = (gtkblist->selected_node == node); + const gchar *protocol_icon_name = NULL; if(editing_blist) { return; @@ -3491,7 +3486,8 @@ static void buddy_node(PurpleBuddy *buddy, GtkTreeIter *iter, PurpleBlistNode *n emblem = pidgin_blist_get_emblem(PURPLE_BLIST_NODE(buddy)); mark = pidgin_blist_get_name_markup(buddy, selected, TRUE); - protocol_icon = pidgin_create_protocol_icon(purple_buddy_get_account(buddy), PIDGIN_PROTOCOL_ICON_SMALL); + protocol = purple_account_get_protocol(purple_buddy_get_account(buddy)); + protocol_icon_name = purple_protocol_get_icon_name(protocol); gtk_tree_store_set(gtkblist->treemodel, iter, STATUS_ICON_COLUMN, status, @@ -3500,7 +3496,7 @@ static void buddy_node(PurpleBuddy *buddy, GtkTreeIter *iter, PurpleBlistNode *n BUDDY_ICON_COLUMN, avatar, EMBLEM_COLUMN, emblem, EMBLEM_VISIBLE_COLUMN, (emblem != NULL), - PROTOCOL_ICON_COLUMN, protocol_icon, + PROTOCOL_ICON_NAME_COLUMN, protocol_icon_name, -1); g_free(mark); @@ -3511,8 +3507,6 @@ static void buddy_node(PurpleBuddy *buddy, GtkTreeIter *iter, PurpleBlistNode *n g_object_unref(status); if(avatar) g_object_unref(avatar); - if(protocol_icon) - g_object_unref(protocol_icon); } /* This is a variation on the original gtk_blist_update_contact. Here we @@ -3627,12 +3621,14 @@ static void pidgin_blist_update_chat(PurpleBuddyList *list, PurpleBlistNode *nod chat = (PurpleChat*)node; if(purple_account_is_connected(purple_chat_get_account(chat))) { + PurpleProtocol *protocol = NULL; GtkTreeIter iter; - GdkPixbuf *status, *avatar, *emblem, *protocol_icon; + GdkPixbuf *status, *avatar, *emblem; const gchar *color = NULL; gchar *mark, *tmp; gboolean selected = (gtkblist->selected_node == node); gboolean nick_said = FALSE; + const gchar *protocol_icon_name = NULL; if (!insert_node(list, node, &iter)) return; @@ -3654,7 +3650,8 @@ static void pidgin_blist_update_chat(PurpleBuddyList *list, PurpleBlistNode *nod mark = tmp; } - protocol_icon = pidgin_create_protocol_icon(purple_chat_get_account(chat), PIDGIN_PROTOCOL_ICON_SMALL); + protocol = purple_account_get_protocol(purple_chat_get_account(chat)); + protocol_icon_name = purple_protocol_get_icon_name(protocol); gtk_tree_store_set(gtkblist->treemodel, &iter, STATUS_ICON_COLUMN, status, @@ -3662,7 +3659,7 @@ static void pidgin_blist_update_chat(PurpleBuddyList *list, PurpleBlistNode *nod BUDDY_ICON_COLUMN, avatar, EMBLEM_COLUMN, emblem, EMBLEM_VISIBLE_COLUMN, emblem != NULL, - PROTOCOL_ICON_COLUMN, protocol_icon, + PROTOCOL_ICON_NAME_COLUMN, protocol_icon_name, NAME_COLUMN, mark, -1); @@ -3673,9 +3670,6 @@ static void pidgin_blist_update_chat(PurpleBuddyList *list, PurpleBlistNode *nod g_object_unref(status); if(avatar) g_object_unref(avatar); - if(protocol_icon) - g_object_unref(protocol_icon); - } else { pidgin_blist_hide_node(list, node, TRUE); } diff --git a/pidgin/gtknotify.c b/pidgin/gtknotify.c index 9219c1715b..69a2e9a515 100644 --- a/pidgin/gtknotify.c +++ b/pidgin/gtknotify.c @@ -111,15 +111,17 @@ searchresults_callback_wrapper_cb(GtkWidget *widget, PidginNotifySearchResultsBu static void pidgin_widget_decorate_account(GtkWidget *cont, PurpleAccount *account) { + PurpleProtocol *protocol = NULL; GtkWidget *image; - GdkPixbuf *pixbuf; + const gchar *icon_name = NULL; if (!account) return; - pixbuf = pidgin_create_protocol_icon(account, PIDGIN_PROTOCOL_ICON_SMALL); - image = gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(G_OBJECT(pixbuf)); + protocol = purple_account_get_protocol(account); + icon_name = purple_protocol_get_icon_name(protocol); + + image = gtk_image_new_from_icon_name(icon_name); gtk_widget_set_tooltip_text(image, purple_account_get_username(account)); @@ -322,20 +324,22 @@ pidgin_notify_searchresults_new_rows(PurpleConnection *gc, PurpleNotifySearchRes void *data_) { PidginNotifySearchResultsData *data = data_; + PurpleProtocol *protocol = NULL; GtkListStore *model = data->model; GtkTreeIter iter; - GdkPixbuf *pixbuf; GList *row, *column; guint n; + const gchar *icon_name = NULL; gtk_list_store_clear(data->model); - pixbuf = pidgin_create_protocol_icon(purple_connection_get_account(gc), PIDGIN_PROTOCOL_ICON_SMALL); + protocol = purple_account_get_protocol(purple_connection_get_account(gc)); + icon_name = purple_protocol_get_icon_name(protocol); for (row = results->rows; row != NULL; row = row->next) { gtk_list_store_append(model, &iter); - gtk_list_store_set(model, &iter, 0, pixbuf, -1); + gtk_list_store_set(model, &iter, 0, icon_name, -1); n = 1; for (column = row->data; column != NULL; column = column->next) { @@ -348,9 +352,6 @@ pidgin_notify_searchresults_new_rows(PurpleConnection *gc, PurpleNotifySearchRes n++; } } - - if (pixbuf != NULL) - g_object_unref(pixbuf); } static void * @@ -443,7 +444,7 @@ pidgin_notify_searchresults(PurpleConnection *gc, const char *title, renderer = gtk_cell_renderer_pixbuf_new(); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), - -1, "", renderer, "pixbuf", 0, NULL); + -1, "", renderer, "icon-name", 0, NULL); i = 1; for (columniter = results->columns; columniter != NULL; columniter = columniter->next) { diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c index baf69c3d2b..9c5f782d4a 100644 --- a/pidgin/gtkrequest.c +++ b/pidgin/gtkrequest.c @@ -89,20 +89,18 @@ static GtkWidget * create_account_field(PurpleRequestField *field); static void pidgin_widget_decorate_account(GtkWidget *cont, PurpleAccount *account) { + PurpleProtocol *protocol = NULL; GtkWidget *image; - GdkPixbuf *pixbuf; + const gchar *icon_name = NULL; if(!PURPLE_IS_ACCOUNT(account)) { return; } - pixbuf = pidgin_create_protocol_icon(account, PIDGIN_PROTOCOL_ICON_SMALL); - if(!GDK_IS_PIXBUF(pixbuf)) { - return; - } + protocol = purple_account_get_protocol(account); + icon_name = purple_protocol_get_icon_name(protocol); - image = gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(G_OBJECT(pixbuf)); + image = gtk_image_new_from_icon_name(icon_name); gtk_widget_set_tooltip_text(image, purple_account_get_username(account)); @@ -1557,7 +1555,6 @@ static GdkPixbuf* _pidgin_datasheet_stock_icon_get(const gchar *stock_name) { GdkPixbuf *image = NULL; - gchar *domain, *id; if (stock_name == NULL) return NULL; @@ -1572,46 +1569,9 @@ _pidgin_datasheet_stock_icon_get(const gchar *stock_name) return image; } - domain = g_strdup(stock_name); - id = strchr(domain, '/'); - if (!id) { - g_free(domain); - return NULL; - } - id[0] = '\0'; - id++; - - if (purple_strequal(domain, "protocol")) { - PurpleAccount *account; - PurpleAccountManager *manager = NULL; - gchar *protocol_id, *accountname; - - protocol_id = id; - accountname = strchr(id, ':'); - - if (!accountname) { - g_free(domain); - return NULL; - } + purple_debug_error("gtkrequest", "Unknown icon: %s", stock_name); - accountname[0] = '\0'; - accountname++; - - manager = purple_account_manager_get_default(); - account = purple_account_manager_find(manager, accountname, - protocol_id); - if(account) { - image = pidgin_create_protocol_icon(account, - PIDGIN_PROTOCOL_ICON_SMALL); - } - } else { - purple_debug_error("gtkrequest", "Unknown domain: %s", domain); - g_free(domain); - return NULL; - } - - g_hash_table_insert(datasheet_stock, g_strdup(stock_name), image); - return image; + return NULL; } static PurpleRequestDatasheetRecord* diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c index f2be9736b4..f46209b71c 100644 --- a/pidgin/gtkutils.c +++ b/pidgin/gtkutils.c @@ -121,58 +121,6 @@ pidgin_make_frame(GtkWidget *parent, const char *title) return vbox2; } -GdkPixbuf * -pidgin_create_icon_from_protocol(PurpleProtocol *protocol, - PidginProtocolIconSize size, - PurpleAccount *account) -{ - GdkPixbuf *pixbuf; - const char *protoname = NULL; - const gchar *icon_name = NULL; - char *tmp; - GtkIconTheme *theme = NULL; - gint dimensions = 0; - - theme = gtk_icon_theme_get_default(); - if(size == PIDGIN_PROTOCOL_ICON_SMALL) { - dimensions = 16; - } else if(size == PIDGIN_PROTOCOL_ICON_MEDIUM) { - dimensions = 22; - } else { - dimensions = 48; - } - - /* If the protocol specified an icon-name try to load it from the icon - * theme. - */ - icon_name = purple_protocol_get_icon_name(protocol); - if(icon_name != NULL) { - pixbuf = gtk_icon_theme_load_icon(theme, icon_name, dimensions, - GTK_ICON_LOOKUP_FORCE_SIZE, NULL); - - if(GDK_IS_PIXBUF(pixbuf)) { - return pixbuf; - } - - } - - protoname = purple_protocol_get_list_icon(protocol, account, NULL); - if (protoname == NULL) { - return NULL; - } - - /* - * Status icons will be themeable too, and then it will look up - * protoname from the theme - */ - tmp = g_strconcat("im-", protoname, NULL); - pixbuf = gtk_icon_theme_load_icon(theme, tmp, dimensions, - GTK_ICON_LOOKUP_FORCE_SIZE, NULL); - g_free(tmp); - - return pixbuf; -} - static void aop_option_menu_select_by_data(GtkWidget *optmenu, gpointer data) { @@ -263,19 +211,6 @@ void pidgin_buddy_icon_get_scale_size(GdkPixbuf *buf, PurpleBuddyIconSpec *spec, *height = 100; } -GdkPixbuf * -pidgin_create_protocol_icon(PurpleAccount *account, PidginProtocolIconSize size) -{ - PurpleProtocol *protocol; - - g_return_val_if_fail(account != NULL, NULL); - - protocol = purple_account_get_protocol(account); - if (protocol == NULL) - return NULL; - return pidgin_create_icon_from_protocol(protocol, size, account); -} - static gboolean buddyname_completion_match_func(GtkEntryCompletion *completion, const gchar *key, GtkTreeIter *iter, gpointer user_data) { diff --git a/pidgin/gtkutils.h b/pidgin/gtkutils.h index f8af08d1ba..50be2440ce 100644 --- a/pidgin/gtkutils.h +++ b/pidgin/gtkutils.h @@ -139,44 +139,6 @@ void pidgin_set_accessible_relations(GtkWidget *w, GtkLabel *l); */ void pidgin_buddy_icon_get_scale_size(GdkPixbuf *buf, PurpleBuddyIconSpec *spec, PurpleBuddyIconScaleFlags rules, int *width, int *height); -/** - * pidgin_create_protocol_icon: - * @account: The account. - * @size: The size of the icon to return. - * - * Returns the base image to represent the account, based on - * the currently selected theme. - * - * Returns: (transfer full): 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 *pidgin_create_protocol_icon(PurpleAccount *account, PidginProtocolIconSize size); - -/** - * pidgin_create_icon_from_protocol: - * @protocol: The #PurpleProtocol instance. - * @size: The size of the icon to return. - * @account: (nullable): An optional #PurpleAccount to use. - * - * Returns the base image to represent @protocol based on the currently - * selected theme. If @account is not %NULL then the returned icon will - * represent the account. - * - * Returns: (transfer full): 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. - * - * Since: 3.0.0 - */ -GdkPixbuf *pidgin_create_icon_from_protocol(PurpleProtocol *protocol, PidginProtocolIconSize size, PurpleAccount *account); - /** * pidgin_convert_buddy_icon: * @protocol: The protocol to convert the icon diff --git a/pidgin/pidginaccountstore.c b/pidgin/pidginaccountstore.c index 21a921b92b..0e2c2546c1 100644 --- a/pidgin/pidginaccountstore.c +++ b/pidgin/pidginaccountstore.c @@ -37,12 +37,14 @@ static void pidgin_account_store_add_account(PidginAccountStore *store, PurpleAccount *account) { + PurpleProtocol *protocol = NULL; GtkTreeIter iter; GdkPixbuf *pixbuf = NULL; gchar *markup = NULL; - const gchar *alias = NULL; + const gchar *alias = NULL, *icon_name = NULL; - pixbuf = pidgin_create_protocol_icon(account, PIDGIN_PROTOCOL_ICON_SMALL); + protocol = purple_account_get_protocol(account); + icon_name = purple_protocol_get_icon_name(protocol); alias = purple_account_get_private_alias(account); if(alias != NULL) { @@ -62,11 +64,10 @@ pidgin_account_store_add_account(PidginAccountStore *store, &iter, PIDGIN_ACCOUNT_STORE_COLUMN_ACCOUNT, account, PIDGIN_ACCOUNT_STORE_COLUMN_MARKUP, markup, - PIDGIN_ACCOUNT_STORE_COLUMN_ICON, pixbuf, + PIDGIN_ACCOUNT_STORE_COLUMN_ICON_NAME, icon_name, -1 ); - g_clear_object(&pixbuf); g_free(markup); } @@ -150,7 +151,7 @@ pidgin_account_store_init(PidginAccountStore *store) { GType types[PIDGIN_ACCOUNT_STORE_N_COLUMNS] = { PURPLE_TYPE_ACCOUNT, G_TYPE_STRING, - GDK_TYPE_PIXBUF, + G_TYPE_STRING, }; gtk_list_store_set_column_types( diff --git a/pidgin/pidginaccountstore.h b/pidgin/pidginaccountstore.h index d2636cfcb6..47a763c128 100644 --- a/pidgin/pidginaccountstore.h +++ b/pidgin/pidginaccountstore.h @@ -57,7 +57,7 @@ typedef enum { PIDGIN_ACCOUNT_STORE_COLUMN_ACCOUNT, PIDGIN_ACCOUNT_STORE_COLUMN_MARKUP, - PIDGIN_ACCOUNT_STORE_COLUMN_ICON, + PIDGIN_ACCOUNT_STORE_COLUMN_ICON_NAME, /*< private >*/ PIDGIN_ACCOUNT_STORE_N_COLUMNS, } PidginAccountStoreColumn; diff --git a/pidgin/resources/Accounts/chooser.ui b/pidgin/resources/Accounts/chooser.ui index 42afe65274..a19ddde291 100644 --- a/pidgin/resources/Accounts/chooser.ui +++ b/pidgin/resources/Accounts/chooser.ui @@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - 2 + 2 -- cgit v1.2.1