aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@src.gnome.org>2009-01-01 04:24:59 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2009-01-01 04:24:59 +0800
commit9d915124c28eb0772b4e1086d6988e7d56d9a04c (patch)
tree11224ba217bd8a17ca1a0f54230a096db842a6b4 /widgets/misc
parent11e1bc38c325665c24b1c831d009f89b7112ebe5 (diff)
downloadgsoc2013-evolution-9d915124c28eb0772b4e1086d6988e7d56d9a04c.tar
gsoc2013-evolution-9d915124c28eb0772b4e1086d6988e7d56d9a04c.tar.gz
gsoc2013-evolution-9d915124c28eb0772b4e1086d6988e7d56d9a04c.tar.bz2
gsoc2013-evolution-9d915124c28eb0772b4e1086d6988e7d56d9a04c.tar.lz
gsoc2013-evolution-9d915124c28eb0772b4e1086d6988e7d56d9a04c.tar.xz
gsoc2013-evolution-9d915124c28eb0772b4e1086d6988e7d56d9a04c.tar.zst
gsoc2013-evolution-9d915124c28eb0772b4e1086d6988e7d56d9a04c.zip
Get the Character Encoding menu working.
Kill e_charset_picker_bonobo_ui_populate(). svn path=/branches/kill-bonobo/; revision=36950
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/e-charset-picker.c199
-rw-r--r--widgets/misc/e-charset-picker.h10
2 files changed, 37 insertions, 172 deletions
diff --git a/widgets/misc/e-charset-picker.c b/widgets/misc/e-charset-picker.c
index 03014609ae..1f24397fae 100644
--- a/widgets/misc/e-charset-picker.c
+++ b/widgets/misc/e-charset-picker.c
@@ -440,6 +440,7 @@ e_charset_picker_dialog (const char *title, const char *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 +454,9 @@ e_charset_picker_dialog (const char *title, const char *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 +466,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 +482,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 +511,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 +532,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,165 +573,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 char *path,
- const char *default_charset,
- BonoboUIListenerFn cb, gpointer user_data)
-{
- char *encoded_label, *label;
- const char *locale_charset;
- GString *menuitems;
- int 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++) {
- char *command;
- char *charset_name, *u;
-
- /* escape _'s in the charset name so that it doesn't become an underline in a GtkLabel */
- if ((u = strchr (charsets[i].name, '_'))) {
- int extra = 1;
- char *s, *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 = 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) {
- char *command;
- char *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, '_'))) {
- int extra = 1;
- char *s, *d;
-
- while ((u = strchr (u + 1, '_')))
- extra++;
-
- d = charset_name = g_alloca (strlen (default_charset) + extra + 1);
- s = (char *) default_charset;
- while (*s != '\0') {
- if (*s == '_')
- *d++ = '_';
- *d++ = *s++;
- }
- *d = '\0';
- } else {
- charset_name = (char *) 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;
}
diff --git a/widgets/misc/e-charset-picker.h b/widgets/misc/e-charset-picker.h
index 7250b10dfb..21643ccf99 100644
--- a/widgets/misc/e-charset-picker.h
+++ b/widgets/misc/e-charset-picker.h
@@ -33,18 +33,12 @@ char * e_charset_picker_dialog (const char *title,
const char *default_charset,
GtkWindow *parent);
-void e_charset_add_radio_actions (GtkActionGroup *action_group,
+GSList * e_charset_add_radio_actions (GtkActionGroup *action_group,
+ const gchar *action_prefix,
const gchar *default_charset,
GCallback callback,
gpointer user_data);
-void e_charset_picker_bonobo_ui_populate
- (BonoboUIComponent *uic,
- const char *path,
- const char *default_charset,
- BonoboUIListenerFn cb,
- gpointer user_data);
-
G_END_DECLS
#endif /* E_CHARSETPICKER_H */