[Xfce4-commits] <xfce4-xkb-plugin:master> Use prettier layout names in tooltips and popup menu.
Igor Slepchin
noreply at xfce.org
Wed Aug 22 23:24:15 CEST 2012
Updating branch refs/heads/master
to 74a4232d6b4553d6517ac714223516763c8f6c4f (commit)
from 498501367c4cfe96278585e106843f15c072fa6c (commit)
commit 74a4232d6b4553d6517ac714223516763c8f6c4f
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date: Tue Jul 24 23:21:09 2012 -0400
Use prettier layout names in tooltips and popup menu.
E.g., "Kurdish (Iran, Latin Alt-Q)" instead of "ir (ku_alt)"
panel-plugin/xfce4-xkb-plugin.c | 5 +--
panel-plugin/xkb-config.c | 61 +++++++++++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index 6da99b8..598d68a 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -385,12 +385,9 @@ xkb_populate_popup_menu (t_xkb *xkb)
tmp = rsvg_handle_get_pixbuf (handle);
}
- layout_string =
- xkb_util_get_layout_string (xkb_config_get_group_name (i),
- xkb_config_get_variant (i));
+ layout_string = xkb_config_get_pretty_layout_name (i);
menu_item = gtk_image_menu_item_new_with_label (layout_string);
- g_free (layout_string);
g_signal_connect (G_OBJECT (menu_item), "activate",
G_CALLBACK (xkb_plugin_set_group), GINT_TO_POINTER (i));
diff --git a/panel-plugin/xkb-config.c b/panel-plugin/xkb-config.c
index 6acd315..3967131 100644
--- a/panel-plugin/xkb-config.c
+++ b/panel-plugin/xkb-config.c
@@ -130,6 +130,54 @@ xkb_config_initialize (t_group_policy group_policy,
return TRUE;
}
+static gchar *
+xkb_config_xkb_description (XklConfigItem *config_item)
+{
+ gchar *ci_description;
+ gchar *description;
+
+ ci_description = g_strstrip (config_item->description);
+
+ if (ci_description[0] == 0)
+ description = g_strdup (config_item->name);
+ else
+ description = g_locale_to_utf8 (ci_description, -1, NULL, NULL, NULL);
+
+ return description;
+}
+
+static gchar*
+xkb_config_create_pretty_layout_name (XklConfigRegistry *registry,
+ XklConfigItem *config_item,
+ gchar *layout_name,
+ gchar *layout_variant)
+{
+ gchar *pretty_layout_name;
+
+ g_snprintf (config_item->name, sizeof (config_item->name),
+ "%s", layout_variant);
+ if (xkl_config_registry_find_variant (registry, layout_name, config_item))
+ {
+ pretty_layout_name = xkb_config_xkb_description (config_item);
+ }
+ else
+ {
+ g_snprintf (config_item->name, sizeof (config_item->name),
+ "%s", layout_name);
+ if (xkl_config_registry_find_layout (registry, config_item))
+ {
+ pretty_layout_name = xkb_config_xkb_description (config_item);
+ }
+ else
+ {
+ pretty_layout_name = xkb_util_get_layout_string (layout_name,
+ layout_variant);
+ }
+ }
+
+ return pretty_layout_name;
+}
+
static void
xkb_config_initialize_xkb_options (const XklConfigRec *config_rec)
{
@@ -138,6 +186,8 @@ xkb_config_initialize_xkb_options (const XklConfigRec *config_rec)
gint val, i;
gpointer pval;
gchar *imgfilename;
+ XklConfigRegistry *registry;
+ XklConfigItem *config_item;
xkb_config_free ();
@@ -156,6 +206,10 @@ xkb_config_initialize_xkb_options (const XklConfigRec *config_rec)
config->variant_index_by_group = g_hash_table_new (NULL, NULL);
index_variants = g_hash_table_new (g_str_hash, g_str_equal);
+ registry = xkl_config_registry_get_instance (config->engine);
+ xkl_config_registry_load (registry, FALSE);
+ config_item = xkl_config_item_new ();
+
for (i = 0; i < config->group_count; i++)
{
t_group_data *group_data = &config->group_data[i];
@@ -197,9 +251,12 @@ xkb_config_initialize_xkb_options (const XklConfigRec *config_rec)
g_free (imgfilename);
group_data->pretty_layout_name =
- xkb_util_get_layout_string (group_data->group_name,
- group_data->variant);
+ xkb_config_create_pretty_layout_name (registry, config_item,
+ group_data->group_name,
+ group_data->variant);
}
+ g_object_unref (config_item);
+ g_object_unref (registry);
g_hash_table_destroy (index_variants);
}
More information about the Xfce4-commits
mailing list