changeset 30725:b6c3000eec60

Use GtkUIManager for gtk media stuff, since it's internal. applied changes from 7f3cdd61a34080056b8024a0297d01ed559bef25 through c9211cd8bf87478800560441c7eb893f1e3995e0 applied partial changes from 231d9237a777f9d01fa2ff9c26a575a0ac8db31c through d0c6c98ad725a3a64114bd1d5c1da1220d738c93
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Mon, 26 Jul 2010 04:21:47 +0000
parents bb7e8e98bdb1
children a551fb648e09 d3e13deb64a5
files pidgin/gtkmedia.c
diffstat 1 files changed, 39 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkmedia.c	Sun Jul 25 23:33:46 2010 +0000
+++ b/pidgin/gtkmedia.c	Mon Jul 26 04:21:47 2010 +0000
@@ -84,7 +84,7 @@
 	gchar *screenname;
 	gulong level_handler_id;
 
-	GtkItemFactory *item_factory;
+	GtkUIManager *ui;
 	GtkWidget *menubar;
 	GtkWidget *statusbar;
 
@@ -260,50 +260,60 @@
 #endif
 
 static void
-menu_hangup(gpointer data, guint action, GtkWidget *item)
+menu_hangup(GtkAction *action, gpointer data)
 {
 	PidginMedia *gtkmedia = PIDGIN_MEDIA(data);
 	purple_media_stream_info(gtkmedia->priv->media,
 			PURPLE_MEDIA_INFO_HANGUP, NULL, NULL, TRUE);
 }
 
-static GtkItemFactoryEntry menu_items[] = {
-	{ N_("/_Media"), NULL, NULL, 0, "<Branch>", NULL },
-	{ N_("/Media/_Hangup"), NULL, menu_hangup, 0, "<Item>", NULL },
+static const GtkActionEntry menu_entries[] = {
+	{ "MediaMenu", NULL, N_("_Media"), NULL, NULL, NULL },
+	{ "Hangup", NULL, N_("_Hangup"), NULL, NULL, G_CALLBACK(menu_hangup) },
 };
 
-static gint menu_item_count = sizeof(menu_items) / sizeof(menu_items[0]);
-
-static const char *
-item_factory_translate_func (const char *path, gpointer func_data)
-{
-	return _(path);
-}
+static const char *media_menu =
+"<ui>"
+	"<menubar name='Media'>"
+		"<menu action='MediaMenu'>"
+			"<menuitem action='Hangup'/>"
+		"</menu>"
+	"</menubar>"
+"</ui>";
 
 static GtkWidget *
 setup_menubar(PidginMedia *window)
 {
+	GtkActionGroup *action_group;
+	GError *error;
 	GtkAccelGroup *accel_group;
 	GtkWidget *menu;
 
-	accel_group = gtk_accel_group_new ();
-	gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
-	g_object_unref(accel_group);
+	action_group = gtk_action_group_new("MediaActions");
+	gtk_action_group_add_actions(action_group,
+	                             menu_entries,
+	                             G_N_ELEMENTS(menu_entries),
+	                             GTK_WINDOW(window));
+#ifdef ENABLE_NLS
+	gtk_action_group_set_translation_domain(action_group,
+	                                        PACKAGE);
+#endif
 
-	window->priv->item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR,
-			"<main>", accel_group);
+	window->priv->ui = gtk_ui_manager_new();
+	gtk_ui_manager_insert_action_group(window->priv->ui, action_group, 0);
 
-	gtk_item_factory_set_translate_func(window->priv->item_factory,
-			(GtkTranslateFunc)item_factory_translate_func,
-			NULL, NULL);
+	accel_group = gtk_ui_manager_get_accel_group(window->priv->ui);
+	gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
 
-	gtk_item_factory_create_items(window->priv->item_factory,
-			menu_item_count, menu_items, window);
-	g_signal_connect(G_OBJECT(accel_group), "accel-changed",
-			G_CALLBACK(pidgin_save_accels_cb), NULL);
+	error = NULL;
+	if (!gtk_ui_manager_add_ui_from_string(window->priv->ui, media_menu, -1, &error))
+	{
+		g_message("building menus failed: %s", error->message);
+		g_error_free(error);
+		exit(EXIT_FAILURE);
+	}
 
-	menu = gtk_item_factory_get_widget(
-			window->priv->item_factory, "<main>");
+	menu = gtk_ui_manager_get_widget(window->priv->ui, "/Media");
 
 	gtk_widget_show(menu);
 	return menu;
@@ -384,9 +394,9 @@
 		gtkmedia->priv->media = NULL;
 	}
 
-	if (gtkmedia->priv->item_factory) {
-		g_object_unref(gtkmedia->priv->item_factory);
-		gtkmedia->priv->item_factory = NULL;
+	if (gtkmedia->priv->ui) {
+		g_object_unref(gtkmedia->priv->ui);
+		gtkmedia->priv->ui = NULL;
 	}
 
 	G_OBJECT_CLASS(parent_class)->dispose(media);