diff options
Diffstat (limited to 'widgets/misc/e-charset-picker.c')
-rw-r--r-- | widgets/misc/e-charset-picker.c | 203 |
1 files changed, 35 insertions, 168 deletions
diff --git a/widgets/misc/e-charset-picker.c b/widgets/misc/e-charset-picker.c index 53beaa9c11..593df6b651 100644 --- a/widgets/misc/e-charset-picker.c +++ b/widgets/misc/e-charset-picker.c @@ -31,9 +31,6 @@ #include <glib/gi18n-lib.h> -#include <bonobo/bonobo-ui-node.h> -#include <bonobo/bonobo-ui-util.h> - typedef enum { E_CHARSET_UNKNOWN, E_CHARSET_ARABIC, @@ -440,6 +437,7 @@ e_charset_picker_dialog (const gchar *title, const gchar *prompt, /** * e_charset_add_radio_actions: * @action_group: a #GtkActionGroup + * @action_prefix: a prefix for action names, or %NULL * @default_charset: the default character set, or %NULL to use the * locale character set * @callback: a callback function for actions in the group, or %NULL @@ -453,8 +451,9 @@ e_charset_picker_dialog (const gchar *title, const gchar *prompt, * the default will be added next, followed by the remaining character * sets. **/ -void +GSList * e_charset_add_radio_actions (GtkActionGroup *action_group, + const gchar *action_prefix, const gchar *default_charset, GCallback callback, gpointer user_data) @@ -464,12 +463,10 @@ e_charset_add_radio_actions (GtkActionGroup *action_group, const gchar *locale_charset; gint def, ii; - g_return_if_fail (GTK_IS_ACTION_GROUP (action_group)); + g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL); - /* XXX I could try to factor out code common to this - * function and e_charset_picker_bonobo_ui_populate() - * instead of duplicating it, but I expect the latter - * function to be obsolete in the foreseeable future. */ + if (action_prefix == NULL) + action_prefix = ""; g_get_charset (&locale_charset); if (!g_ascii_strcasecmp (locale_charset, "US-ASCII")) @@ -482,13 +479,18 @@ e_charset_add_radio_actions (GtkActionGroup *action_group, break; for (ii = 0; ii < G_N_ELEMENTS (charsets); ii++) { + const gchar *charset_name; + gchar *action_name; gchar *escaped_name; gchar *charset_label; gchar **str_array; + charset_name = charsets[ii].name; + action_name = g_strconcat (action_prefix, charset_name, NULL); + /* Escape underlines in the character set name so * they're not treated as GtkLabel mnemonics. */ - str_array = g_strsplit (charsets[ii].name, "_", -1); + str_array = g_strsplit (charset_name, "_", -1); escaped_name = g_strjoinv ("__", str_array); g_strfreev (str_array); @@ -506,8 +508,14 @@ e_charset_add_radio_actions (GtkActionGroup *action_group, else charset_label = g_strdup (escaped_name); + /* XXX Add a tooltip! */ action = gtk_radio_action_new ( - charsets[ii].name, charset_label, NULL, NULL, ii); + action_name, charset_label, NULL, NULL, ii); + + /* Character set name is static so no need to free it. */ + g_object_set_data ( + G_OBJECT (action), "charset", + (gpointer) charset_name); gtk_radio_action_set_group (action, group); group = gtk_radio_action_get_group (action); @@ -521,22 +529,34 @@ e_charset_add_radio_actions (GtkActionGroup *action_group, g_object_unref (action); + g_free (action_name); g_free (escaped_name); g_free (charset_label); } if (def == G_N_ELEMENTS (charsets)) { + const gchar *charset_name; + gchar *action_name; gchar *charset_label; gchar **str_array; + charset_name = default_charset; + action_name = g_strconcat (action_prefix, charset_name, NULL); + /* Escape underlines in the character set name so * they're not treated as GtkLabel mnemonics. */ - str_array = g_strsplit (default_charset, "_", -1); + str_array = g_strsplit (charset_name, "_", -1); charset_label = g_strjoinv ("__", str_array); g_strfreev (str_array); + /* XXX Add a tooltip! */ action = gtk_radio_action_new ( - default_charset, charset_label, NULL, NULL, def); + action_name, charset_label, NULL, NULL, def); + + /* Character set name is static so no need to free it. */ + g_object_set_data ( + G_OBJECT (action), "charset", + (gpointer) charset_name); gtk_radio_action_set_group (action, group); group = gtk_radio_action_get_group (action); @@ -550,166 +570,13 @@ e_charset_add_radio_actions (GtkActionGroup *action_group, g_object_unref (action); + g_free (action_name); g_free (charset_label); } /* Any of the actions in the action group will do. */ if (action != NULL) gtk_radio_action_set_current_value (action, def); -} - -/** - * e_charset_picker_bonobo_ui_populate: - * @uic: Bonobo UI Component - * @path: menu path - * @default_charset: the default character set, or %NULL to use the - * locale character set. - * @cb: Callback function - * @user_data: data to be passed to the callback. - * - * This creates a Bonobo UI menu and fills it in with a selection - * of available character sets. The @default_charset (or locale character - * set if @default_charset is %NULL) will be listed first, and selected - * by default (except that iso-8859-1 will always be used instead of - * US-ASCII). Any other character sets of the same language class as - * the default will be listed next, followed by the remaining character - * sets. - **/ -void -e_charset_picker_bonobo_ui_populate (BonoboUIComponent *uic, const gchar *path, - const gchar *default_charset, - BonoboUIListenerFn cb, gpointer user_data) -{ - gchar *encoded_label, *label; - const gchar *locale_charset; - GString *menuitems; - gint def, i; - - g_get_charset (&locale_charset); - if (!g_ascii_strcasecmp (locale_charset, "US-ASCII")) - locale_charset = "iso-8859-1"; - - if (!default_charset) - default_charset = locale_charset; - for (def = 0; def < num_charsets; def++) { - if (!g_ascii_strcasecmp (charsets[def].name, default_charset)) - break; - } - - label = g_strdup (_("Ch_aracter Encoding")); - encoded_label = bonobo_ui_util_encode_str (label); - menuitems = g_string_new (""); - g_string_append_printf (menuitems, "<submenu name=\"ECharsetPicker\" label=\"%s\">\n", - encoded_label); - g_free (encoded_label); - g_free (label); - - for (i = 0; i < num_charsets; i++) { - gchar *charset_name; - gchar *command, *u; - - /* escape _'s in the charset name so that it doesn't become an underline in a GtkLabel */ - if ((u = strchr (charsets[i].name, '_'))) { - gint extra = 1; - const gchar *s; - gchar *d; - - while ((u = strchr (u + 1, '_'))) - extra++; - - d = charset_name = g_alloca (strlen (charsets[i].name) + extra + 1); - s = charsets[i].name; - while (*s != '\0') { - if (*s == '_') - *d++ = '_'; - *d++ = *s++; - } - *d = '\0'; - } else { - charset_name = (gchar *) charsets[i].name; - } - - if (charsets[i].subclass) { - label = g_strdup_printf ("%s, %s (%s)", - _(classnames[charsets[i].class]), - _(charsets[i].subclass), - charset_name); - } else if (charsets[i].class) { - label = g_strdup_printf ("%s (%s)", - _(classnames[charsets[i].class]), - charset_name); - } else { - label = g_strdup (charset_name); - } - - encoded_label = bonobo_ui_util_encode_str (label); - g_free (label); - - command = g_strdup_printf ("<cmd name=\"Charset-%s\" label=\"%s\" type=\"radio\"" - " group=\"charset_picker\" state=\"%d\"/>\n", - charsets[i].name, encoded_label, i == def); - - bonobo_ui_component_set (uic, "/commands", command, NULL); - g_free (command); - - g_string_append_printf (menuitems, " <menuitem name=\"Charset-%s\" verb=\"\"/>\n", - charsets[i].name); - - g_free (encoded_label); - - label = g_strdup_printf ("Charset-%s", charsets[i].name); - bonobo_ui_component_add_listener (uic, label, cb, user_data); - g_free (label); - } - - if (def == num_charsets) { - gchar *command; - gchar *charset_name, *u; - - /* escape _'s in the charset name so that it doesn't become an underline in a GtkLabel */ - if ((u = strchr (default_charset, '_'))) { - gint extra = 1; - gchar *s, *d; - - while ((u = strchr (u + 1, '_'))) - extra++; - - d = charset_name = g_alloca (strlen (default_charset) + extra + 1); - s = (gchar *) default_charset; - while (*s != '\0') { - if (*s == '_') - *d++ = '_'; - *d++ = *s++; - } - *d = '\0'; - } else { - charset_name = (gchar *) default_charset; - } - - label = g_strdup (charset_name); - encoded_label = bonobo_ui_util_encode_str (label); - g_free (label); - - command = g_strdup_printf ("<cmd name=\"Charset-%s\" label=\"%s\" type=\"radio\"" - " group=\"charset_picker\" state=\"1\"/>\n", - default_charset, encoded_label); - - bonobo_ui_component_set (uic, "/commands", command, NULL); - g_free (command); - - g_string_append (menuitems, " <separator/>\n"); - g_string_append_printf (menuitems, " <menuitem name=\"Charset-%s\" verb=\"\"/>\n", - default_charset); - - g_free (encoded_label); - - label = g_strdup_printf ("Charset-%s", default_charset); - bonobo_ui_component_add_listener (uic, label, cb, user_data); - g_free (label); - } - - g_string_append (menuitems, "</submenu>\n"); - bonobo_ui_component_set (uic, path, menuitems->str, NULL); - g_string_free (menuitems, TRUE); + return group; } |