[PATCH] Don't confuse users by misleading tooltip (#1011112)

Vratislav Podzimek vpodzime at redhat.com
Tue Sep 24 20:04:53 UTC 2013


If there is only one keyboard layout configured, the layout indicator shouldn't
tell users that clicking it will switch layouts.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 widgets/src/LayoutIndicator.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/widgets/src/LayoutIndicator.c b/widgets/src/LayoutIndicator.c
index c76768d..d77812b 100644
--- a/widgets/src/LayoutIndicator.c
+++ b/widgets/src/LayoutIndicator.c
@@ -28,7 +28,9 @@
 #include "LayoutIndicator.h"
 #include "intl.h"
 
-#define TOOLTIP_FORMAT_STR _("Current layout: '%s'. Click to switch to the next layout")
+#define TOOLTIP_BASE_FORMAT_STR _("Current layout: '%s'. %s")
+#define MULTIPLE_LAYOUTS_TIP  _("Click to switch to the next layout.")
+#define SINGLE_LAYOUT_TIP _("Add more layouts to enable switching.")
 #define DEFAULT_LAYOUT "us"
 #define DEFAULT_LABEL_MAX_CHAR_WIDTH 8
 #define MARKUP_FORMAT_STR "<span fgcolor='black' weight='bold'>%s</span>"
@@ -72,6 +74,7 @@ static void anaconda_layout_indicator_realize(GtkWidget *widget, gpointer user_d
 static void anaconda_layout_indicator_clicked(GtkWidget *widget, GdkEvent *event, gpointer user_data);
 static void anaconda_layout_indicator_refresh_ui_elements(AnacondaLayoutIndicator *indicator);
 static void anaconda_layout_indicator_refresh_layout(AnacondaLayoutIndicator *indicator);
+static void anaconda_layout_indicator_refresh_tooltip(AnacondaLayoutIndicator *indicator);
 
 /* helper functions */
 static gchar* get_current_layout(XklEngine *engine, XklConfigRec *conf_rec);
@@ -311,15 +314,12 @@ static void anaconda_layout_indicator_clicked(GtkWidget *widget, GdkEvent *event
 
 static void anaconda_layout_indicator_refresh_ui_elements(AnacondaLayoutIndicator *self) {
     gchar *markup;
-    gchar *tooltip;
 
     markup = g_markup_printf_escaped(MARKUP_FORMAT_STR, self->priv->layout);
     gtk_label_set_markup(self->priv->layout_label, markup);
     g_free(markup);
 
-    tooltip = g_strdup_printf(TOOLTIP_FORMAT_STR, self->priv->layout);
-    gtk_widget_set_tooltip_text(GTK_WIDGET(self), tooltip);
-    g_free(tooltip);
+    anaconda_layout_indicator_refresh_tooltip(self);
 }
 
 static void anaconda_layout_indicator_refresh_layout(AnacondaLayoutIndicator *self) {
@@ -331,6 +331,20 @@ static void anaconda_layout_indicator_refresh_layout(AnacondaLayoutIndicator *se
     anaconda_layout_indicator_refresh_ui_elements(self);
 }
 
+static void anaconda_layout_indicator_refresh_tooltip(AnacondaLayoutIndicator *self) {
+    AnacondaLayoutIndicatorClass *klass = ANACONDA_LAYOUT_INDICATOR_GET_CLASS(self);
+    guint n_groups = xkl_engine_get_num_groups(klass->engine);
+    gchar *tooltip;
+
+    if (n_groups > 1)
+        tooltip = g_strdup_printf(TOOLTIP_BASE_FORMAT_STR, self->priv->layout, MULTIPLE_LAYOUTS_TIP);
+    else
+        tooltip = g_strdup_printf(TOOLTIP_BASE_FORMAT_STR, self->priv->layout, SINGLE_LAYOUT_TIP);
+
+    gtk_widget_set_tooltip_text(GTK_WIDGET(self), tooltip);
+    g_free(tooltip);
+}
+
 /**
  * get_current_layout:
  *
@@ -457,6 +471,5 @@ void anaconda_layout_indicator_set_label_width(AnacondaLayoutIndicator *indicato
  * Since: 1.0
  */
 void anaconda_layout_indicator_retranslate(AnacondaLayoutIndicator *indicator) {
-    gtk_widget_set_tooltip_text(GTK_WIDGET(indicator),
-                                g_strdup_printf(TOOLTIP_FORMAT_STR, indicator->priv->layout));
+    anaconda_layout_indicator_refresh_tooltip(indicator);
 }
-- 
1.7.11.7



More information about the anaconda-patches mailing list