/dev/tomkiewicz/e2ee: 2574bedf42f5: E2EE: make it possible to at...

Tomasz Wasilczyk twasilczyk at pidgin.im
Sat Oct 5 13:57:48 EDT 2013


Changeset: 2574bedf42f5787e6ebb6bc909ba6f9dd5b5ff7f
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-10-05 19:57 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/e2ee/rev/2574bedf42f5

Description:

E2EE: make it possible to attach stock icon to PurpleMenuAction

diffstat:

 libpurple/util.c  |  17 +++++++++++++++++
 libpurple/util.h  |   6 ++++++
 pidgin/gtkconv.c  |   1 +
 pidgin/gtkutils.c |  20 +++++++++++++++++++-
 4 files changed, 43 insertions(+), 1 deletions(-)

diffs (104 lines):

diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -40,6 +40,7 @@ struct _PurpleMenuAction
 	PurpleCallback callback;
 	gpointer data;
 	GList *children;
+	gchar *stock_icon;
 };
 
 static char *custom_user_dir = NULL;
@@ -65,6 +66,7 @@ purple_menu_action_free(PurpleMenuAction
 {
 	g_return_if_fail(act != NULL);
 
+	g_free(act->stock_icon);
 	g_free(act->label);
 	g_free(act);
 }
@@ -125,6 +127,21 @@ void purple_menu_action_set_children(Pur
 	act->children = children;
 }
 
+void purple_menu_action_set_stock_icon(PurpleMenuAction *act,
+	const gchar *stock)
+{
+	g_return_if_fail(act != NULL);
+
+	g_free(act->stock_icon);
+	act->stock_icon = g_strdup(stock);
+}
+
+const gchar *
+purple_menu_action_get_stock_icon(PurpleMenuAction *act)
+{
+	return act->stock_icon;
+}
+
 void
 purple_util_init(void)
 {
diff --git a/libpurple/util.h b/libpurple/util.h
--- a/libpurple/util.h
+++ b/libpurple/util.h
@@ -153,6 +153,12 @@ void purple_menu_action_set_data(PurpleM
  */
 void purple_menu_action_set_children(PurpleMenuAction *act, GList *children);
 
+void purple_menu_action_set_stock_icon(PurpleMenuAction *act,
+	const gchar *stock);
+
+const gchar *
+purple_menu_action_get_stock_icon(PurpleMenuAction *act);
+
 /**
  * Set the appropriate presence values for the currently playing song.
  *
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -4199,6 +4199,7 @@ generate_e2ee_controls(PidginWindow *win
 		gtk_widget_show_all(
 			pidgin_append_menu_action(menu, action, conv));
 	}
+	g_list_free(menu_actions);
 
 	gtk_widget_show(win->menu.e2ee);
 	gtk_widget_show(menu);
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -1724,13 +1724,31 @@ pidgin_append_menu_action(GtkWidget *men
 {
 	GtkWidget *menuitem;
 	GList *list;
+	const gchar *stock_id;
+	GtkWidget *icon_image = NULL;
 
 	if (act == NULL) {
 		return pidgin_separator(menu);
 	}
 
+	stock_id = purple_menu_action_get_stock_icon(act);
+	if (stock_id) {
+		icon_image = gtk_image_new_from_stock(stock_id,
+			gtk_icon_size_from_name(
+				PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL));
+	}
+
+	if (icon_image) {
+		menuitem = gtk_image_menu_item_new_with_mnemonic(
+			purple_menu_action_get_label(act));
+		gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem),
+			icon_image);
+	} else {
+		menuitem = gtk_menu_item_new_with_mnemonic(
+			purple_menu_action_get_label(act));
+	}
+
 	list = purple_menu_action_get_children(act);
-	menuitem = gtk_menu_item_new_with_mnemonic(purple_menu_action_get_label(act));
 
 	if (list == NULL) {
 		PurpleCallback callback;



More information about the Commits mailing list