pidgin: 00a9efda: Show the stock status icons in the statu...

sadrul at pidgin.im sadrul at pidgin.im
Sat Jun 7 16:40:44 EDT 2008


-----------------------------------------------------------------
Revision: 00a9efda899566f921e7c8bbe98a0eb684855f62
Ancestor: 876a824bb4677ca7738acdf553d255fd1a4c857b
Author: ml at update.uu.se
Date: 2008-06-07T20:37:18
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/00a9efda899566f921e7c8bbe98a0eb684855f62

Modified files:
        pidgin/gtksavedstatuses.c

ChangeLog: 

Show the stock status icons in the status list and status menus. Closes
#6038.

-------------- next part --------------
============================================================
--- pidgin/gtksavedstatuses.c	5c938b426a9e3b5935ee66c71aba844d2529b519
+++ pidgin/gtksavedstatuses.c	26d7f2493b4efd47f78544b5aa8b2a6c2b5dedc8
@@ -59,6 +59,7 @@ enum
 	STATUS_WINDOW_COLUMN_MESSAGE,
 	/** A hidden column containing a pointer to the editor for this saved status. */
 	STATUS_WINDOW_COLUMN_WINDOW,
+	STATUS_WINDOW_COLUMN_ICON,
 	STATUS_WINDOW_NUM_COLUMNS
 };
 
@@ -80,6 +81,7 @@ enum
 	STATUS_EDITOR_COLUMN_STATUS_ID,
 	STATUS_EDITOR_COLUMN_STATUS_NAME,
 	STATUS_EDITOR_COLUMN_STATUS_MESSAGE,
+	STATUS_EDITOR_COLUMN_STATUS_ICON,
 	STATUS_EDITOR_NUM_COLUMNS
 };
 
@@ -392,12 +394,35 @@ status_selected_cb(GtkTreeSelection *sel
     g_list_free(sel_paths);
 }
 
+static const gchar *
+get_stock_icon_from_primitive(PurpleStatusPrimitive type)
+{
+	switch (type) {
+		case PURPLE_STATUS_AVAILABLE:
+			return PIDGIN_STOCK_STATUS_AVAILABLE;
+		case PURPLE_STATUS_AWAY:
+			return PIDGIN_STOCK_STATUS_AWAY;
+		case PURPLE_STATUS_EXTENDED_AWAY:
+			return PIDGIN_STOCK_STATUS_XA;
+		case PURPLE_STATUS_INVISIBLE:
+			return PIDGIN_STOCK_STATUS_INVISIBLE;
+		case PURPLE_STATUS_OFFLINE:
+			return PIDGIN_STOCK_STATUS_OFFLINE;
+		case PURPLE_STATUS_UNAVAILABLE:
+			return PIDGIN_STOCK_STATUS_BUSY;
+		default:
+			/* this shouldn't happen */
+			return NULL;
+	}
+}
+
 static void
 add_status_to_saved_status_list(GtkListStore *model, PurpleSavedStatus *saved_status)
 {
 	GtkTreeIter iter;
 	const char *title;
 	const char *type;
+	const gchar *icon;
 	char *message;
 
 	if (purple_savedstatus_is_transient(saved_status))
@@ -406,14 +431,16 @@ add_status_to_saved_status_list(GtkListS
 	title = purple_savedstatus_get_title(saved_status);
 	type = purple_primitive_get_name_from_type(purple_savedstatus_get_type(saved_status));
 	message = purple_markup_strip_html(purple_savedstatus_get_message(saved_status));
+	icon = get_stock_icon_from_primitive(purple_savedstatus_get_type(saved_status));
 
 	gtk_list_store_append(model, &iter);
 	gtk_list_store_set(model, &iter,
+					   STATUS_WINDOW_COLUMN_ICON, icon,
 					   STATUS_WINDOW_COLUMN_TITLE, title,
 					   STATUS_WINDOW_COLUMN_TYPE, type,
 					   STATUS_WINDOW_COLUMN_MESSAGE, message,
 					   -1);
-	free(message);
+	g_free(message);
 }
 
 static void
@@ -479,7 +506,8 @@ create_saved_status_list(StatusWindow *d
 									   G_TYPE_STRING,
 									   G_TYPE_STRING,
 									   G_TYPE_STRING,
-									   G_TYPE_POINTER);
+									   G_TYPE_POINTER,
+									   G_TYPE_STRING);
 
 	/* Create the treeview */
 	treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model));
@@ -517,6 +545,10 @@ create_saved_status_list(StatusWindow *d
 	gtk_tree_view_column_set_sort_column_id(column,
 											STATUS_WINDOW_COLUMN_TYPE);
 	gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+	renderer = gtk_cell_renderer_pixbuf_new();
+	gtk_tree_view_column_pack_start(column, renderer, TRUE);
+	gtk_tree_view_column_add_attribute(column, renderer, "stock-id",
+									   STATUS_WINDOW_COLUMN_ICON);
 	renderer = gtk_cell_renderer_text_new();
 	gtk_tree_view_column_pack_start(column, renderer, TRUE);
 	gtk_tree_view_column_add_attribute(column, renderer, "text",
@@ -856,6 +888,26 @@ static GtkWidget *
 }
 
 static GtkWidget *
+create_stock_item(const gchar *str, const gchar *icon)
+{
+	GtkWidget *menuitem = gtk_menu_item_new();
+	GtkWidget *label = gtk_label_new_with_mnemonic(str);
+	GtkWidget *hbox = gtk_hbox_new(FALSE, 4);
+	GtkIconSize icon_size = gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
+	GtkWidget *image = gtk_image_new_from_stock(icon, icon_size);;
+
+	gtk_widget_show(label);
+	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
+	gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+	gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+
+	gtk_container_add(GTK_CONTAINER(menuitem), hbox);
+
+	return menuitem;
+}
+
+static GtkWidget *
 create_status_type_menu(PurpleStatusPrimitive type)
 {
 	int i;
@@ -874,7 +926,9 @@ create_status_type_menu(PurpleStatusPrim
 			 * status types, so don't show them in the list.
 			 */
 			continue;
-		item = gtk_menu_item_new_with_label(purple_primitive_get_name_from_type(i));
+
+		item = create_stock_item(purple_primitive_get_name_from_type(i),
+					get_stock_icon_from_primitive(i));
 		gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 	}
 
@@ -930,6 +984,7 @@ status_editor_substatus_cb(GtkCellRender
 						   STATUS_EDITOR_COLUMN_STATUS_ID, NULL,
 						   STATUS_EDITOR_COLUMN_STATUS_NAME, NULL,
 						   STATUS_EDITOR_COLUMN_STATUS_MESSAGE, NULL,
+						   STATUS_EDITOR_COLUMN_STATUS_ICON, NULL,
 						   -1);
 	}
 }
@@ -975,6 +1030,10 @@ status_editor_add_columns(StatusEditor *
 	gtk_tree_view_column_set_title(column, _("Status"));
 	gtk_tree_view_insert_column(GTK_TREE_VIEW(dialog->treeview), column, -1);
 	gtk_tree_view_column_set_resizable(column, TRUE);
+	renderer = gtk_cell_renderer_pixbuf_new();
+	gtk_tree_view_column_pack_start(column, renderer, FALSE);
+	gtk_tree_view_column_add_attribute(column, renderer, "stock-id",
+			STATUS_EDITOR_COLUMN_STATUS_ICON);
 	renderer = gtk_cell_renderer_text_new();
 	gtk_tree_view_column_pack_start(column, renderer, TRUE);
 	gtk_tree_view_column_add_attribute(column, renderer, "text",
@@ -1001,6 +1060,7 @@ status_editor_set_account(GtkListStore *
 {
 	GdkPixbuf *pixbuf;
 	const char *id = NULL, *name = NULL, *message = NULL;
+	PurpleStatusPrimitive prim = PURPLE_STATUS_UNSET;
 
 	pixbuf = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_MEDIUM);
 	if ((pixbuf != NULL) && !purple_account_is_connected(account))
@@ -1015,6 +1075,7 @@ status_editor_set_account(GtkListStore *
 		type = purple_savedstatus_substatus_get_type(substatus);
 		id = purple_status_type_get_id(type);
 		name = purple_status_type_get_name(type);
+		prim = purple_status_type_get_primitive(type);
 		if (purple_status_type_get_attr(type, "message"))
 			message = purple_savedstatus_substatus_get_message(substatus);
 	}
@@ -1027,6 +1088,7 @@ status_editor_set_account(GtkListStore *
 			STATUS_EDITOR_COLUMN_STATUS_ID, id,
 			STATUS_EDITOR_COLUMN_STATUS_NAME, name,
 			STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message,
+			STATUS_EDITOR_COLUMN_STATUS_ICON, get_stock_icon_from_primitive(prim),
 			-1);
 
 	if (pixbuf != NULL)
@@ -1183,6 +1245,7 @@ pidgin_status_editor_show(gboolean edit,
 									   G_TYPE_STRING,
 									   G_TYPE_STRING,
 									   G_TYPE_STRING,
+									   G_TYPE_STRING,
 									   G_TYPE_STRING);
 
 	/* Create the treeview */
@@ -1336,7 +1399,7 @@ substatus_editor_ok_cb(GtkButton *button
 	PurpleStatusType *type;
 	char *id = NULL;
 	char *message = NULL;
-	const char *name = NULL;
+	const char *name = NULL, *stock = NULL;
 
 	if (!gtk_combo_box_get_active_iter(dialog->box, &iter))
 	{
@@ -1351,6 +1414,7 @@ substatus_editor_ok_cb(GtkButton *button
 	if (purple_status_type_get_attr(type, "message") != NULL)
 		message = gtk_imhtml_get_markup(GTK_IMHTML(dialog->message));
 	name = purple_status_type_get_name(type);
+	stock = get_stock_icon_from_primitive(purple_status_type_get_primitive(type));
 
 	status_editor = dialog->status_editor;
 
@@ -1362,6 +1426,7 @@ substatus_editor_ok_cb(GtkButton *button
 						   STATUS_EDITOR_COLUMN_STATUS_NAME, name,
 						   STATUS_EDITOR_COLUMN_STATUS_MESSAGE, message,
 						   STATUS_EDITOR_COLUMN_WINDOW, NULL,
+						   STATUS_EDITOR_COLUMN_STATUS_ICON, stock,
 						   -1);
 	}
 


More information about the Commits mailing list