[totem] Bug 484142 – Show menu item descriptions in status bar



commit 6fdfd1ca71ee5d0c82ba1915df981fd26b0a7b7f
Author: Robin Stocker <robin nibor org>
Date:   Sun Jul 26 20:08:47 2009 +0100

    Bug 484142 â?? Show menu item descriptions in status bar

 src/totem-menu.c      |   55 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/totem-statusbar.c |   23 ++++++++++++++++++++
 src/totem-statusbar.h |    3 ++
 3 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/src/totem-menu.c b/src/totem-menu.c
index bf7bbc1..0330c17 100644
--- a/src/totem-menu.c
+++ b/src/totem-menu.c
@@ -31,6 +31,7 @@
 #include "totem-interface.h"
 #include "totem-private.h"
 #include "totem-sidebar.h"
+#include "totem-statusbar.h"
 #include "totem-plugin-manager.h"
 #include "bacon-video-widget.h"
 #include "totem-uri.h"
@@ -1314,6 +1315,58 @@ clear_playlist_action_callback (GtkAction *action, Totem *totem)
 	totem_action_set_mrl (totem, NULL, NULL);
 }
 
+/* Show help in status bar when selecting (hovering over) a menu item. */
+static void
+menu_item_select_cb (GtkMenuItem *proxy, Totem *totem)
+{
+	GtkAction *action;
+	char *message;
+
+	action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (proxy));
+	g_return_if_fail (action != NULL);
+
+	g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
+	if (message) {
+		totem_statusbar_push_help (TOTEM_STATUSBAR (totem->statusbar), message);
+		g_free (message);
+	}
+}
+
+static void
+menu_item_deselect_cb (GtkMenuItem *proxy, Totem *totem)
+{
+	totem_statusbar_pop_help (TOTEM_STATUSBAR (totem->statusbar));
+}
+
+static void
+setup_action (Totem *totem, GtkAction *action)
+{
+	GSList *proxies;
+	for (proxies = gtk_action_get_proxies (action); proxies != NULL; proxies = proxies->next) {
+		if (GTK_IS_MENU_ITEM (proxies->data)) {
+			g_signal_connect (proxies->data, "select", G_CALLBACK (menu_item_select_cb), totem);
+			g_signal_connect (proxies->data, "deselect", G_CALLBACK (menu_item_deselect_cb), totem);
+		}
+
+	}
+}
+
+static void
+setup_menu_items (Totem *totem)
+{
+	GList *action_groups;
+
+	/* FIXME: We can remove this once GTK+ bug #574001 is fixed */
+	for (action_groups = gtk_ui_manager_get_action_groups (totem->ui_manager);
+	     action_groups != NULL; action_groups = action_groups->next) {
+		GtkActionGroup *action_group = GTK_ACTION_GROUP (action_groups->data);
+		GList *actions;
+		for (actions = gtk_action_group_list_actions (action_group); actions != NULL; actions = actions->next) {
+			setup_action (totem, GTK_ACTION (actions->data));
+		}
+	}
+}
+
 static const GtkActionEntry seek_entries_ltr[] = {
 	{ "skip-forward", GTK_STOCK_MEDIA_FORWARD, N_("Skip _Forward"), "Right", N_("Skip forward"), G_CALLBACK (skip_forward_action_callback) },
 	{ "skip-backwards", GTK_STOCK_MEDIA_REWIND, N_("Skip _Backwards"), "Left", N_("Skip backwards"), G_CALLBACK (skip_backwards_action_callback) }
@@ -1361,6 +1414,8 @@ totem_ui_manager_setup (Totem *totem)
 
 	totem->ui_manager = GTK_UI_MANAGER (gtk_builder_get_object (totem->xml, "totem-ui-manager"));
 
+	setup_menu_items (totem);
+
 	totem->devices_action_group = NULL;
 	totem->devices_ui_id = gtk_ui_manager_new_merge_id (totem->ui_manager);
 	totem->languages_action_group = NULL;
diff --git a/src/totem-statusbar.c b/src/totem-statusbar.c
index 724833f..f9f31c0 100644
--- a/src/totem-statusbar.c
+++ b/src/totem-statusbar.c
@@ -37,6 +37,7 @@
 #define SPACING 4
 #define NORMAL_CONTEXT "text"
 #define BUFFERING_CONTEXT "buffering"
+#define HELP_CONTEXT "help"
 
 static void totem_statusbar_dispose          (GObject             *object);
 static void totem_statusbar_sync_description (TotemStatusbar      *statusbar);
@@ -160,6 +161,28 @@ totem_statusbar_set_time (TotemStatusbar *statusbar, gint _time)
   totem_statusbar_update_time (statusbar);
 }
 
+/* Set a help message to be displayed in the status bar. */
+void
+totem_statusbar_push_help (TotemStatusbar *statusbar, const char *message)
+{
+  GtkStatusbar *gstatusbar = GTK_STATUSBAR (statusbar);
+  guint id;
+
+  id = gtk_statusbar_get_context_id (gstatusbar, HELP_CONTEXT);
+  gtk_statusbar_push (gstatusbar, id, message);
+}
+
+/* Remove the last help message of the status bar. */
+void
+totem_statusbar_pop_help (TotemStatusbar *statusbar)
+{
+  GtkStatusbar *gstatusbar = GTK_STATUSBAR (statusbar);
+  guint id;
+
+  id = gtk_statusbar_get_context_id (gstatusbar, HELP_CONTEXT);
+  gtk_statusbar_pop (gstatusbar, id);
+}
+
 static gboolean
 totem_statusbar_timeout_pop (TotemStatusbar *statusbar)
 {
diff --git a/src/totem-statusbar.h b/src/totem-statusbar.h
index 9df0b50..62d99b1 100644
--- a/src/totem-statusbar.h
+++ b/src/totem-statusbar.h
@@ -73,6 +73,9 @@ void       totem_statusbar_set_seeking          (TotemStatusbar *statusbar,
 
 void       totem_statusbar_set_text             (TotemStatusbar *statusbar,
 						 const char *label);
+void       totem_statusbar_push_help            (TotemStatusbar *statusbar,
+						 const char *message);
+void       totem_statusbar_pop_help             (TotemStatusbar *statusbar);
 void	   totem_statusbar_push			(TotemStatusbar *statusbar,
 						 guint percentage);
 void       totem_statusbar_pop			(TotemStatusbar *statusbar);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]