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@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); }
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>"
From a translation perspective, pasting the TOOLTIP_BASE_FORMAT_STR string together like this worries me. It's a little better because you are using complete sentences, but I'm not convinced it'll work for everyone. I don't suppose anyone else has experience with this?
The code looks fine, though.
- Chris
On Tue, 2013-09-24 at 16:49 -0400, Chris Lumens wrote:
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>"
From a translation perspective, pasting the TOOLTIP_BASE_FORMAT_STR string together like this worries me. It's a little better because you are using complete sentences, but I'm not convinced it'll work for everyone. I don't suppose anyone else has experience with this?
I was thinking about having two macros with full tooltip format strings, both starting with what the TOOLTIP_BASE_FORMAT_STR is. I guess that would be better?
This version should be easier for translators and it keeps the string we already have translated.
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@redhat.com --- widgets/src/LayoutIndicator.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/widgets/src/LayoutIndicator.c b/widgets/src/LayoutIndicator.c index c76768d..cafcef8 100644 --- a/widgets/src/LayoutIndicator.c +++ b/widgets/src/LayoutIndicator.c @@ -28,7 +28,8 @@ #include "LayoutIndicator.h" #include "intl.h"
-#define TOOLTIP_FORMAT_STR _("Current layout: '%s'. Click to switch to the next layout") +#define MULTIPLE_LAYOUTS_TIP _("Current layout: '%s'. Click to switch to the next layout.") +#define SINGLE_LAYOUT_TIP _("Current layout: '%s'. 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 +73,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 +313,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 +330,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(MULTIPLE_LAYOUTS_TIP, self->priv->layout); + else + tooltip = g_strdup_printf(SINGLE_LAYOUT_TIP, self->priv->layout); + + gtk_widget_set_tooltip_text(GTK_WIDGET(self), tooltip); + g_free(tooltip); +} + /** * get_current_layout: * @@ -457,6 +470,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); }
This version should be easier for translators and it keeps the string we already have translated.
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@redhat.com
I like this one better. Thanks.
- Chris
anaconda-patches@lists.fedorahosted.org