sadrul.gtkblist-theme: c13af148: Use stock id where possible.

sadrul at pidgin.im sadrul at pidgin.im
Wed Apr 22 23:55:41 EDT 2009


-----------------------------------------------------------------
Revision: c13af148b1fd91aad82d8b6caa8b663e677aef1a
Ancestor: a57412002fdb5aebb7db072fdd4af6edafb78d84
Author: sadrul at pidgin.im
Date: 2009-04-23T03:38:44
Branch: im.pidgin.sadrul.gtkblist-theme
URL: http://d.pidgin.im/viewmtn/revision/info/c13af148b1fd91aad82d8b6caa8b663e677aef1a

Modified files:
        pidgin/gtkstatusbox.c

ChangeLog: 

Use stock id where possible.

-------------- next part --------------
============================================================
--- pidgin/gtkstatusbox.c	5305c1aaf941b5dcb4b30f6ad8e4f667419b2fae
+++ pidgin/gtkstatusbox.c	789d4bfb65780efa9ef08ec4a431d36aa99a19b5
@@ -98,6 +98,9 @@ enum {
 	/** A PidginStatusBoxItemType */
 	TYPE_COLUMN,
 
+	/** This is the stock-id for the icon. */
+	ICON_STOCK_COLUMN,
+
 	/**
 	 * This is a GdkPixbuf (the other columns are strings).
 	 * This column is visible.
@@ -638,7 +641,8 @@ pidgin_status_box_refresh(PidginStatusBo
 	char aa_color[8];
 	PurpleSavedStatus *saved_status;
 	char *primary, *secondary, *text;
-	GdkPixbuf *pixbuf, *emblem = NULL;
+	const char *stock = NULL;
+	GdkPixbuf *pixbuf = NULL, *emblem = NULL;
 	GtkTreePath *path;
 	gboolean account_status = FALSE;
 	PurpleAccount *acct = (status_box->account) ? status_box->account : status_box->token_status_account;
@@ -722,13 +726,32 @@ pidgin_status_box_refresh(PidginStatusBo
 	    PurpleStatusType *status_type;
 	    PurpleStatusPrimitive prim;
 	    if (account_status) {
-	    	status_type = purple_status_get_type(purple_account_get_active_status(acct));
+			status_type = purple_status_get_type(purple_account_get_active_status(acct));
 	        prim = purple_status_type_get_primitive(status_type);
 	    } else {
-	    	prim = purple_savedstatus_get_type(saved_status);
+			prim = purple_savedstatus_get_type(saved_status);
 	    }
 
-		pixbuf = pidgin_status_box_get_pixbuf(status_box, prim);
+		switch (prim) {
+			case PURPLE_STATUS_UNAVAILABLE:
+				stock = PIDGIN_STOCK_STATUS_BUSY;
+				break;
+			case PURPLE_STATUS_AWAY:
+				stock = PIDGIN_STOCK_STATUS_AWAY;
+				break;
+			case PURPLE_STATUS_EXTENDED_AWAY:
+				stock = PIDGIN_STOCK_STATUS_XA;
+				break;
+			case PURPLE_STATUS_INVISIBLE:
+				stock = PIDGIN_STOCK_STATUS_INVISIBLE;
+				break;
+			case PURPLE_STATUS_OFFLINE:
+				stock = PIDGIN_STOCK_STATUS_OFFLINE;
+				break;
+			default:
+				stock = PIDGIN_STOCK_STATUS_AVAILABLE;
+				break;
+		}
 	}
 
 	if (status_box->account != NULL) {
@@ -750,12 +773,13 @@ pidgin_status_box_refresh(PidginStatusBo
 	 * really need to be a list store?)
 	 */
 	gtk_list_store_set(status_box->store, &(status_box->iter),
+			   ICON_STOCK_COLUMN, (gpointer)stock,
 			   ICON_COLUMN, pixbuf,
 			   TEXT_COLUMN, text,
 			   EMBLEM_COLUMN, emblem,
 			   EMBLEM_VISIBLE_COLUMN, (emblem != NULL),
 			   -1);
-	if ((status_box->typing == 0) && (!status_box->connecting))
+	if (pixbuf && (status_box->typing == 0) && (!status_box->connecting))
 		g_object_unref(pixbuf);
 	g_free(text);
 	if (emblem)
@@ -1032,7 +1056,6 @@ add_account_statuses(PidginStatusBox *st
 {
 	/* Per-account */
 	GList *l;
-	GdkPixbuf *pixbuf;
 
 	for (l = purple_account_get_status_types(account); l != NULL; l = l->next)
 	{
@@ -1045,22 +1068,17 @@ add_account_statuses(PidginStatusBox *st
 
 		prim = purple_status_type_get_primitive(status_type);
 
-		pixbuf = pidgin_status_box_get_pixbuf(status_box, prim);
-
 		pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box),
-					PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, pixbuf,
+					PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, NULL,
 					purple_status_type_get_name(status_type),
 					NULL,
 					GINT_TO_POINTER(purple_status_type_get_primitive(status_type)));
-		if (pixbuf != NULL)
-			g_object_unref(pixbuf);
 	}
 }
 
 static void
 pidgin_status_box_regenerate(PidginStatusBox *status_box)
 {
-	GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4, *pixbuf5;
 	GtkIconSize icon_size;
 
 	icon_size = gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
@@ -1075,8 +1093,6 @@ pidgin_status_box_regenerate(PidginStatu
 
 	if (status_box->account == NULL)
 	{
-		pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), PIDGIN_STOCK_STATUS_AVAILABLE,
-		                                 icon_size, "PidginStatusBox");
 		/* Do all the currently enabled accounts have the same statuses?
 		 * If so, display them instead of our global list.
 		 */
@@ -1084,25 +1100,11 @@ pidgin_status_box_regenerate(PidginStatu
 			add_account_statuses(status_box, status_box->token_status_account);
 		} else {
 			/* Global */
-			pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), PIDGIN_STOCK_STATUS_AWAY,
-			                                  icon_size, "PidginStatusBox");
-			pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), PIDGIN_STOCK_STATUS_OFFLINE,
-			                                  icon_size, "PidginStatusBox");
-			pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), PIDGIN_STOCK_STATUS_INVISIBLE,
-			                                  icon_size, "PidginStatusBox");
-			pixbuf5 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), PIDGIN_STOCK_STATUS_BUSY,
-							  icon_size, "PidginStatusBox");
-
-			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, pixbuf, _("Available"), NULL, GINT_TO_POINTER(PURPLE_STATUS_AVAILABLE));
-			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, pixbuf2, _("Away"), NULL, GINT_TO_POINTER(PURPLE_STATUS_AWAY));
-			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, pixbuf5, _("Do not disturb"), NULL, GINT_TO_POINTER(PURPLE_STATUS_UNAVAILABLE));
-			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, pixbuf4, _("Invisible"), NULL, GINT_TO_POINTER(PURPLE_STATUS_INVISIBLE));
-			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, pixbuf3, _("Offline"), NULL, GINT_TO_POINTER(PURPLE_STATUS_OFFLINE));
-
-			if (pixbuf2)	g_object_unref(G_OBJECT(pixbuf2));
-			if (pixbuf3)	g_object_unref(G_OBJECT(pixbuf3));
-			if (pixbuf4)	g_object_unref(G_OBJECT(pixbuf4));
-			if (pixbuf5)	g_object_unref(G_OBJECT(pixbuf5));
+			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, NULL, _("Available"), NULL, GINT_TO_POINTER(PURPLE_STATUS_AVAILABLE));
+			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, NULL, _("Away"), NULL, GINT_TO_POINTER(PURPLE_STATUS_AWAY));
+			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, NULL, _("Do not disturb"), NULL, GINT_TO_POINTER(PURPLE_STATUS_UNAVAILABLE));
+			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, NULL, _("Invisible"), NULL, GINT_TO_POINTER(PURPLE_STATUS_INVISIBLE));
+			pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_PRIMITIVE, NULL, _("Offline"), NULL, GINT_TO_POINTER(PURPLE_STATUS_OFFLINE));
 		}
 
 		add_popular_statuses(status_box);
@@ -1110,7 +1112,6 @@ pidgin_status_box_regenerate(PidginStatu
 		pidgin_status_box_add_separator(PIDGIN_STATUS_BOX(status_box));
 		pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_CUSTOM, NULL, _("New status..."), NULL, NULL);
 		pidgin_status_box_add(PIDGIN_STATUS_BOX(status_box), PIDGIN_STATUS_BOX_TYPE_SAVED, NULL, _("Saved statuses..."), NULL, NULL);
-		if (pixbuf)	g_object_unref(G_OBJECT(pixbuf));
 
 		status_menu_refresh_iter(status_box);
 		pidgin_status_box_refresh(status_box);
@@ -1778,9 +1779,9 @@ pidgin_status_box_init (PidginStatusBox 
 	status_box->vsep = gtk_vseparator_new();
 	status_box->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
 
-	status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING,
+	status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING,
 					       G_TYPE_STRING, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN);
-	status_box->dropdown_store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING,
+	status_box->dropdown_store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING,
 							G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_BOOLEAN);
 
 	gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store));
@@ -1855,7 +1856,7 @@ pidgin_status_box_init (PidginStatusBox 
 	gtk_tree_view_column_pack_start(status_box->column, icon_rend, FALSE);
 	gtk_tree_view_column_pack_start(status_box->column, text_rend, TRUE);
 	gtk_tree_view_column_pack_start(status_box->column, emblem_rend, FALSE);
-	gtk_tree_view_column_set_attributes(status_box->column, icon_rend, "pixbuf", ICON_COLUMN, NULL);
+	gtk_tree_view_column_set_attributes(status_box->column, icon_rend, "pixbuf", ICON_COLUMN, "stock-id", ICON_STOCK_COLUMN, NULL);
 	gtk_tree_view_column_set_attributes(status_box->column, text_rend, "markup", TEXT_COLUMN, NULL);
 	gtk_tree_view_column_set_attributes(status_box->column, emblem_rend, "stock-id", EMBLEM_COLUMN, "visible", EMBLEM_VISIBLE_COLUMN, NULL);
 	gtk_container_add(GTK_CONTAINER(status_box->scrolled_window), status_box->tree_view);
@@ -1874,7 +1875,7 @@ pidgin_status_box_init (PidginStatusBox 
 	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE);
 	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE);
 	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), emblem_rend, FALSE);
-	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL);
+	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, "stock-id", ICON_STOCK_COLUMN, NULL);
 	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL);
 	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), emblem_rend, "pixbuf", EMBLEM_COLUMN, "visible", EMBLEM_VISIBLE_COLUMN, NULL);
 #if GTK_CHECK_VERSION(2, 6, 0)
@@ -2133,7 +2134,8 @@ pidgin_status_box_new_with_account(Purpl
  *
  * @param status_box The status box itself.
  * @param type       A PidginStatusBoxItemType.
- * @param pixbuf     The icon to associate with this row in the menu.
+ * @param pixbuf     The icon to associate with this row in the menu. The
+ *                   function will try to decide a pixbuf if none is given.
  * @param title      The title of this item.  For the primitive entries,
  *                   this is something like "Available" or "Away."  For
  *                   the saved statuses, this is something like
@@ -2149,10 +2151,12 @@ void
  *                   creation timestamp.
  */
 void
-pidgin_status_box_add(PidginStatusBox *status_box, PidginStatusBoxItemType type, GdkPixbuf *pixbuf, const char *title, const char *desc, gpointer data)
+pidgin_status_box_add(PidginStatusBox *status_box, PidginStatusBoxItemType type, GdkPixbuf *pixbuf,
+		const char *title, const char *desc, gpointer data)
 {
 	GtkTreeIter iter;
 	char *text;
+	const char *stock = NULL;
 
 	if (desc == NULL)
 	{
@@ -2179,9 +2183,36 @@ pidgin_status_box_add(PidginStatusBox *s
 		g_free(escaped_desc);
 	}
 
+	if (!pixbuf) {
+		if (type == PIDGIN_STATUS_BOX_TYPE_PRIMITIVE) {
+			PurpleStatusPrimitive prim = GPOINTER_TO_INT(data);
+			switch (prim) {
+				case PURPLE_STATUS_UNAVAILABLE:
+					stock = PIDGIN_STOCK_STATUS_BUSY;
+					break;
+				case PURPLE_STATUS_AWAY:
+					stock = PIDGIN_STOCK_STATUS_AWAY;
+					break;
+				case PURPLE_STATUS_EXTENDED_AWAY:
+					stock = PIDGIN_STOCK_STATUS_XA;
+					break;
+				case PURPLE_STATUS_INVISIBLE:
+					stock = PIDGIN_STOCK_STATUS_INVISIBLE;
+					break;
+				case PURPLE_STATUS_OFFLINE:
+					stock = PIDGIN_STOCK_STATUS_OFFLINE;
+					break;
+				default:
+					stock = PIDGIN_STOCK_STATUS_AVAILABLE;
+					break;
+			}
+		}
+	}
+
 	gtk_list_store_append(status_box->dropdown_store, &iter);
 	gtk_list_store_set(status_box->dropdown_store, &iter,
 			TYPE_COLUMN, type,
+			ICON_STOCK_COLUMN, stock,
 			ICON_COLUMN, pixbuf,
 			TEXT_COLUMN, text,
 			TITLE_COLUMN, title,


More information about the Commits mailing list