Install a new 'hildon-keyboard-shortcuts' boolean GtkSetting to control whether
mnemonics and shortcuts should be enabled (default=TRUE) and update GtkLabel
and GtkAccelLabel accordingly to display the mnemonics and shortcuts when
enabled.

This patch does not disable the mnemonic and shortcut activation.

The 'hildon' prefix should be replaced with 'gtk' but as I'm developing this
for maemo I'd like to keep it clear it is not (yet?) an official gtk+ feature.

Signal connection setup similar to GtkButton and GtkImageMenuItem.

Calling gtk_accel_label_refetch() from GtkLabel saves duplicating the signal
connection setup and widget hierarchy traversal also in GtkAccelLabel.


	* gtk/gtklabel.c (gtk_label_class_init): install
	'hildon-keyboard-shortcuts' to GtkSettings
	(keyboard_shortcuts_change_notify) (traverse_container)
	(hildon_label_setting_changed) (gtk_label_screen_changed): Monitor
	changes in GtkSettings and update all labels and accel labels in all
	toplevel windows.
	(gtk_label_set_pattern_internal): Underline mnemonics only if
	'hildon-keyboard-shortcuts' GtkSetting is enabled
	* gtk/gtkaccellabel.c (gtk_accel_label_refetch): Display shortcuts only
	if 'hildon-keyboard-shortcuts' GtkSetting is enabled
	(#72375)
---
 gtk/gtkaccellabel.c |    7 ++++
 gtk/gtklabel.c      |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 77 insertions(+), 3 deletions(-)

Index: gtk/gtkaccellabel.c
===================================================================
--- gtk/gtkaccellabel.c.orig
+++ gtk/gtkaccellabel.c
@@ -620,9 +620,14 @@ gboolean
 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
 {
   GtkAccelLabelClass *class;
+  gboolean keyboard_shortcuts;
 
   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
 
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
+		"hildon-keyboard-shortcuts", &keyboard_shortcuts,
+		NULL);
+
   class = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
 
   if (accel_label->accel_string)
@@ -631,7 +636,7 @@ gtk_accel_label_refetch (GtkAccelLabel *
       accel_label->accel_string = NULL;
     }
 
-  if (accel_label->accel_closure)
+  if (keyboard_shortcuts && accel_label->accel_closure)
     {
       GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);
 
Index: gtk/gtklabel.c
===================================================================
--- gtk/gtklabel.c.orig
+++ gtk/gtklabel.c
@@ -27,6 +27,7 @@
 #include <math.h>
 #include <string.h>
 #include "gtklabel.h"
+#include "gtkaccellabel.h"
 #include "gtkdnd.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
@@ -596,6 +597,12 @@ gtk_label_class_init (GtkLabelClass *cla
 				"copy_clipboard", 0);
 				
   g_type_class_add_private (class, sizeof (GtkLabelPrivate));
+
+  gtk_settings_install_property (g_param_spec_boolean ("hildon-keyboard-shortcuts",
+						       P_("Visual keyboard shortcut cues"),
+						       P_("Whether menus should have visible accelerators and mnemonics"),
+						       TRUE,
+						       GTK_PARAM_READWRITE));
 }
 
 static void 
@@ -932,12 +939,68 @@ gtk_label_hierarchy_changed (GtkWidget *
 }
 
 static void
+keyboard_shortcuts_change_notify (GtkLabel *label)
+{
+  gtk_label_recalculate (label);
+  if (GTK_IS_ACCEL_LABEL (label))
+    gtk_accel_label_refetch (GTK_ACCEL_LABEL (label));
+}
+
+static void
+traverse_container (GtkWidget *widget,
+		    gpointer   data)
+{
+  if (GTK_IS_LABEL (widget))
+    keyboard_shortcuts_change_notify (GTK_LABEL (widget));
+  else if (GTK_IS_CONTAINER (widget))
+    gtk_container_forall (GTK_CONTAINER (widget), traverse_container, data);
+}
+
+static void
+hildon_label_setting_changed (GtkSettings *settings)
+{
+  GList *list, *l;
+
+  list = gtk_window_list_toplevels ();
+
+  for (l = list; l ; l = l->next)
+    gtk_container_forall (GTK_CONTAINER (l->data),
+			  traverse_container, NULL);
+
+  g_list_free (list);
+}
+
+static void
 gtk_label_screen_changed (GtkWidget *widget,
 			  GdkScreen *old_screen)
 {
-  gtk_label_clear_layout (GTK_LABEL (widget));
+  GtkSettings *settings;
+  guint keyboard_shortcuts_connection;
+
+  if (!gtk_widget_has_screen (widget))
+    return;
+
+  settings = gtk_widget_get_settings (widget);
+
+  keyboard_shortcuts_connection = 
+    GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
+					 "hildon-label-connection"));
+
+  if (keyboard_shortcuts_connection)
+    return;
+
+  keyboard_shortcuts_connection =
+    g_signal_connect (settings, "notify::hildon-keyboard-shortcuts",
+		      G_CALLBACK (hildon_label_setting_changed), NULL);
+
+  g_object_set_data (G_OBJECT (settings),
+		     "hildon-label-connection",
+		     GUINT_TO_POINTER (keyboard_shortcuts_connection));
+
+  keyboard_shortcuts_change_notify (GTK_LABEL (widget));
 }
 
+
 static void
 label_mnemonic_widget_weak_notify (gpointer      data,
 				   GObject      *where_the_object_was)
@@ -1424,9 +1487,15 @@ gtk_label_set_pattern_internal (GtkLabel
 				const gchar *pattern)
 {
   PangoAttrList *attrs;
+  gboolean keyboard_shortcuts;
+
   g_return_if_fail (GTK_IS_LABEL (label));
+
+  g_object_get (gtk_widget_get_settings (GTK_WIDGET (label)),
+		"hildon-keyboard-shortcuts", &keyboard_shortcuts,
+		NULL);
   
-  if (pattern)
+  if (keyboard_shortcuts && pattern)
     attrs = gtk_label_pattern_to_attrs (label, pattern);
   else
     attrs = NULL;
