evolution r35285 - in branches/mbarnes-composer: composer widgets/misc



Author: mbarnes
Date: Mon Mar 31 03:13:04 2008
New Revision: 35285
URL: http://svn.gnome.org/viewvc/evolution?rev=35285&view=rev

Log:
Implement the "Character Encoding" menu.


Modified:
   branches/mbarnes-composer/composer/e-composer-actions.c
   branches/mbarnes-composer/composer/e-composer-private.h
   branches/mbarnes-composer/composer/e-msg-composer.c
   branches/mbarnes-composer/composer/evolution-composer.ui
   branches/mbarnes-composer/widgets/misc/e-charset-picker.c
   branches/mbarnes-composer/widgets/misc/e-charset-picker.h

Modified: branches/mbarnes-composer/composer/e-composer-actions.c
==============================================================================
--- branches/mbarnes-composer/composer/e-composer-actions.c	(original)
+++ branches/mbarnes-composer/composer/e-composer-actions.c	Mon Mar 31 03:13:04 2008
@@ -7,6 +7,8 @@
 #include <mail/em-event.h>
 #include <mail/em-format-html-print.h>
 
+#include "misc/e-charset-picker.h"
+
 static void
 action_attach_cb (GtkAction *action,
                   EMsgComposer *composer)
@@ -77,6 +79,22 @@
 }
 
 static void
+action_charset_cb (GtkRadioAction *action,
+                   GtkRadioAction *current,
+                   EMsgComposer *composer)
+{
+	const gchar *charset;
+
+	if (action != current)
+		return;
+
+	charset = gtk_action_get_name (GTK_ACTION (current));
+
+	g_free (composer->priv->charset);
+	composer->priv->charset = g_strdup (charset);
+}
+
+static void
 action_close_cb (GtkAction *action,
                  EMsgComposer *composer)
 {
@@ -484,6 +502,13 @@
 
 	/* Menus */
 
+	{ "charset-menu",
+	  NULL,
+	  N_("Ch_aracter Encoding"),
+	  NULL,
+	  NULL,
+	  NULL },
+
 	{ "security-menu",
 	  NULL,
 	  N_("_Security"),
@@ -611,7 +636,7 @@
 	manager = gtkhtml_editor_get_ui_manager (GTKHTML_EDITOR (composer));
 
 	/* Composer Actions */
-	action_group = composer->priv->action_group;
+	action_group = composer->priv->composer_actions;
 	gtk_action_group_set_translation_domain (
 		action_group, GETTEXT_PACKAGE);
 	gtk_action_group_add_actions (
@@ -622,6 +647,15 @@
 		G_N_ELEMENTS (toggle_entries), composer);
 	gtk_ui_manager_insert_action_group (manager, action_group, 0);
 
+	/* Character Set Actions */
+	action_group = composer->priv->charset_actions;
+	gtk_action_group_set_translation_domain (
+		action_group, GETTEXT_PACKAGE);
+	e_charset_add_radio_actions (
+		action_group, composer->priv->charset,
+		G_CALLBACK (action_charset_cb), composer);
+	gtk_ui_manager_insert_action_group (manager, action_group, 0);
+
 	/* Fine Tuning */
 
 	g_object_set (

Modified: branches/mbarnes-composer/composer/e-composer-private.h
==============================================================================
--- branches/mbarnes-composer/composer/e-composer-private.h	(original)
+++ branches/mbarnes-composer/composer/e-composer-private.h	Mon Mar 31 03:13:04 2008
@@ -7,6 +7,8 @@
 #include <glib/gstdio.h>
 #include "gconf-bridge.h"
 
+#include <libedataserver/e-iconv.h>
+
 #include "e-attachment-bar.h"
 #include "e-composer-actions.h"
 #include "e-composer-autosave.h"
@@ -16,6 +18,44 @@
 	(G_TYPE_INSTANCE_GET_PRIVATE \
 	((obj), E_TYPE_MSG_COMPOSER, EMsgComposerPrivate))
 
+/* Mail configuration keys */
+#define MAIL_GCONF_PREFIX \
+	"/apps/evolution/mail"
+#define MAIL_GCONF_CHARSET_KEY \
+	MAIL_GCONF_PREFIX "/format/charset"
+
+/* Composer configuration keys */
+#define COMPOSER_GCONF_PREFIX \
+	MAIL_GCONF_PREFIX "/composer"
+#define COMPOSER_GCONF_CHARSET_KEY \
+	COMPOSER_GCONF_PREFIX "/charset"
+#define COMPOSER_GCONF_CURRENT_FOLDER_KEY \
+	COMPOSER_GCONF_PREFIX "/current_folder"
+#define COMPOSER_GCONF_INLINE_SPELLING_KEY \
+	COMPOSER_GCONF_PREFIX "/inline_spelling"
+#define COMPOSER_GCONF_MAGIC_LINKS_KEY \
+	COMPOSER_GCONF_PREFIX "/magic_links"
+#define COMPOSER_GCONF_MAGIC_SMILEYS_KEY \
+	COMPOSER_GCONF_PREFIX "/magic_smileys"
+#define COMPOSER_GCONF_REQUEST_RECEIPT_KEY \
+	COMPOSER_GCONF_PREFIX "/request_receipt"
+#define COMPOSER_GCONF_TOP_SIGNATURE_KEY \
+	COMPOSER_GCONF_PREFIX "/top_signature"
+#define COMPOSER_GCONF_SEND_HTML_KEY \
+	COMPOSER_GCONF_PREFIX "/send_html"
+#define COMPOSER_GCONF_VIEW_BCC_KEY \
+	COMPOSER_GCONF_PREFIX "/view/Bcc"
+#define COMPOSER_GCONF_VIEW_CC_KEY \
+	COMPOSER_GCONF_PREFIX "/view/Cc"
+#define COMPOSER_GCONF_VIEW_FROM_KEY \
+	COMPOSER_GCONF_PREFIX "/view/From"
+#define COMPOSER_GCONF_VIEW_POST_TO_KEY \
+	COMPOSER_GCONF_PREFIX "/view/PostTo"
+#define COMPOSER_GCONF_VIEW_REPLY_TO_KEY \
+	COMPOSER_GCONF_PREFIX "/view/ReplyTo"
+#define COMPOSER_GCONF_WINDOW_PREFIX \
+	COMPOSER_GCONF_PREFIX "/window"
+
 /* Shorthand, requires a variable named "composer". */
 #define ACTION(name)	(E_COMPOSER_ACTION_##name (composer))
 
@@ -33,7 +73,8 @@
 
 	GtkWidget *html_editor;
 	GtkWidget *header_table;
-	GtkActionGroup *action_group;
+	GtkActionGroup *charset_actions;
+	GtkActionGroup *composer_actions;
 
 	GPtrArray *extra_hdr_names, *extra_hdr_values;
 	GArray *gconf_bridge_binding_ids;
@@ -78,6 +119,7 @@
 
 void		e_composer_actions_init		(EMsgComposer *composer);
 gchar *		e_composer_find_data_file	(const gchar *basename);
+gchar *		e_composer_get_default_charset	(void);
 
 G_END_DECLS
 

Modified: branches/mbarnes-composer/composer/e-msg-composer.c
==============================================================================
--- branches/mbarnes-composer/composer/e-msg-composer.c	(original)
+++ branches/mbarnes-composer/composer/e-msg-composer.c	Mon Mar 31 03:13:04 2008
@@ -66,8 +66,6 @@
 
 #include <glade/glade.h>
 
-#include <libedataserver/e-iconv.h>
-
 #include "e-util/e-dialog-utils.h"
 #include "misc/e-charset-picker.h"
 #include "misc/e-expander.h"
@@ -117,44 +115,6 @@
 #include <X11/XF86keysym.h>
 #endif
 
-/* Mail configuration keys */
-#define MAIL_GCONF_PREFIX \
-	"/apps/evolution/mail"
-#define MAIL_GCONF_CHARSET_KEY \
-	MAIL_GCONF_PREFIX "/format/charset"
-
-/* Composer configuration keys */
-#define COMPOSER_GCONF_PREFIX \
-	MAIL_GCONF_PREFIX "/composer"
-#define COMPOSER_GCONF_CHARSET_KEY \
-	COMPOSER_GCONF_PREFIX "/charset"
-#define COMPOSER_GCONF_CURRENT_FOLDER_KEY \
-	COMPOSER_GCONF_PREFIX "/current_folder"
-#define COMPOSER_GCONF_INLINE_SPELLING_KEY \
-	COMPOSER_GCONF_PREFIX "/inline_spelling"
-#define COMPOSER_GCONF_MAGIC_LINKS_KEY \
-	COMPOSER_GCONF_PREFIX "/magic_links"
-#define COMPOSER_GCONF_MAGIC_SMILEYS_KEY \
-	COMPOSER_GCONF_PREFIX "/magic_smileys"
-#define COMPOSER_GCONF_REQUEST_RECEIPT_KEY \
-	COMPOSER_GCONF_PREFIX "/request_receipt"
-#define COMPOSER_GCONF_TOP_SIGNATURE_KEY \
-	COMPOSER_GCONF_PREFIX "/top_signature"
-#define COMPOSER_GCONF_SEND_HTML_KEY \
-	COMPOSER_GCONF_PREFIX "/send_html"
-#define COMPOSER_GCONF_VIEW_BCC_KEY \
-	COMPOSER_GCONF_PREFIX "/view/Bcc"
-#define COMPOSER_GCONF_VIEW_CC_KEY \
-	COMPOSER_GCONF_PREFIX "/view/Cc"
-#define COMPOSER_GCONF_VIEW_FROM_KEY \
-	COMPOSER_GCONF_PREFIX "/view/From"
-#define COMPOSER_GCONF_VIEW_POST_TO_KEY \
-	COMPOSER_GCONF_PREFIX "/view/PostTo"
-#define COMPOSER_GCONF_VIEW_REPLY_TO_KEY \
-	COMPOSER_GCONF_PREFIX "/view/ReplyTo"
-#define COMPOSER_GCONF_WINDOW_PREFIX \
-	COMPOSER_GCONF_PREFIX "/window"
-
 #define d(x)
 
 #define E_MSG_COMPOSER_GET_PRIVATE(obj) \
@@ -325,39 +285,6 @@
 }
 
 static gchar *
-composer_get_default_charset_setting (void)
-{
-	GConfClient *client;
-	const gchar *locale;
-	gchar *charset;
-
-	client = gconf_client_get_default ();
-
-	charset = gconf_client_get_string (
-		client, COMPOSER_GCONF_CHARSET_KEY, NULL);
-
-	/* See what charset the mailer is using.
-	 * XXX We should not have to know where this lives in GConf.
-	 *     Need a mail_config_get_default_charset() that does this. */
-	if (!charset || charset[0] == '\0') {
-		g_free (charset);
-		charset = gconf_client_get_string (
-			client, MAIL_GCONF_CHARSET_KEY, NULL);
-		if (charset && charset[0] == '\0') {
-			g_free (charset);
-			charset = NULL;
-		}
-	}
-
-	g_object_unref (client);
-
-	if (!charset && (locale = e_iconv_locale_charset ()))
-		charset = g_strdup (locale);
-
-	return charset ? charset : g_strdup ("us-ascii");
-}
-
-static gchar *
 best_charset (GByteArray *buf, const gchar *default_charset, CamelTransferEncoding *encoding)
 {
 	gchar *charset;
@@ -373,7 +300,7 @@
 		return g_strdup (default_charset);
 
 	/* Now try the user's default charset from the mail config */
-	charset = composer_get_default_charset_setting ();
+	charset = e_composer_get_default_charset ();
 	*encoding = best_encoding (buf, charset);
 	if (*encoding != -1)
 		return charset;
@@ -1113,7 +1040,7 @@
 		camel_object_unref (stream);
 
 		charset = composer && composer->priv->charset ? composer->priv->charset : NULL;
-		charset = charset ? g_strdup (charset) : composer_get_default_charset_setting ();
+		charset = charset ? g_strdup (charset) : e_composer_get_default_charset ();
 		if ((charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "UTF-8"))) {
 			camel_stream_filter_add (filtered_stream, charenc);
 			camel_object_unref (charenc);
@@ -1425,25 +1352,6 @@
 }
 
 static void
-menu_changed_charset_cb (BonoboUIComponent           *component,
-			 const char                  *path,
-			 Bonobo_UIComponent_EventType type,
-			 const char                  *state,
-			 gpointer                     user_data)
-{
-	if (type != Bonobo_UIComponent_STATE_CHANGED)
-		return;
-
-	if (atoi (state)) {
-		EMsgComposer *composer = E_MSG_COMPOSER (user_data);
-		EMsgComposerPrivate *p = composer->priv;
-		/* Charset menu names are "Charset-%s" where %s is the charset name */
-		g_free (p->charset);
-		p->charset = g_strdup (path + strlen ("Charset-"));
-	}
-}
-
-static void
 setup_ui (EMsgComposer *composer)
 {
 #if 0 /* GTKHTML-EDITOR */

Modified: branches/mbarnes-composer/composer/evolution-composer.ui
==============================================================================
--- branches/mbarnes-composer/composer/evolution-composer.ui	(original)
+++ branches/mbarnes-composer/composer/evolution-composer.ui	Mon Mar 31 03:13:04 2008
@@ -14,6 +14,12 @@
         <menuitem action='close'/>
       </menu>
     </placeholder>
+    <menu action='edit-menu'>
+      <placeholder name='pre-spell-check'>
+        <menu action='charset-menu'/>
+        <separator/>
+      </placeholder>
+    </menu>
     <placeholder name='pre-insert-menu'>
       <menu action='view-menu'>
         <menuitem action='view-from'/>

Modified: branches/mbarnes-composer/widgets/misc/e-charset-picker.c
==============================================================================
--- branches/mbarnes-composer/widgets/misc/e-charset-picker.c	(original)
+++ branches/mbarnes-composer/widgets/misc/e-charset-picker.c	Mon Mar 31 03:13:04 2008
@@ -28,15 +28,6 @@
 #include <string.h>
 #include <iconv.h>
 
-#include <gtk/gtkhbox.h>
-#include <gtk/gtkvbox.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtkstock.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkmenuitem.h>
-#include <gtk/gtkoptionmenu.h>
-#include <gtk/gtksignal.h>
-
 #include <glib/gi18n.h>
 
 #include <bonobo/bonobo-ui-node.h>
@@ -446,6 +437,127 @@
 }
 
 /**
+ * e_charset_add_radio_actions:
+ * @action_group: a #GtkActionGroup
+ * @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
+ * @user_data: user data to be passed to @callback, or %NULL
+ * 
+ * Adds a set of #GtkRadioActions for available character sets to
+ * @action_group.  The @default_charset (or locale character set if
+ * @default_charset is %NULL) will be added 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 added next, followed by the remaining character
+ * sets.
+ **/
+void
+e_charset_add_radio_actions (GtkActionGroup *action_group,
+                             const gchar *default_charset,
+                             GCallback callback,
+                             gpointer user_data)
+{
+	GtkRadioAction *action = NULL;
+	GSList *group = NULL;
+	const gchar *locale_charset;
+	gint def, ii;
+
+	g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
+
+	/* 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. */
+
+	g_get_charset (&locale_charset);
+	if (!g_ascii_strcasecmp (locale_charset, "US-ASCII"))
+		locale_charset = "iso-8859-1";
+
+	if (default_charset == NULL)
+		default_charset = locale_charset;
+	for (def = 0; def < G_N_ELEMENTS (charsets); def++)
+		if (!g_ascii_strcasecmp (charsets[def].name, default_charset))
+			break;
+
+	for (ii = 0; ii < G_N_ELEMENTS (charsets); ii++) {
+		gchar *escaped_name;
+		gchar *charset_label;
+		gchar **str_array;
+
+		/* Escape underlines in the character set name so
+		 * they're not treated as GtkLabel mnemonics. */
+		str_array = g_strsplit (charsets[ii].name, "_", -1);
+		escaped_name = g_strjoinv ("__", str_array);
+		g_strfreev (str_array);
+
+		if (charsets[ii].subclass != NULL)
+			charset_label = g_strdup_printf (
+				"%s, %s (%s)",
+				gettext (classnames[charsets[ii].class]),
+				gettext (charsets[ii].subclass),
+				escaped_name);
+		else if (charsets[ii].class != E_CHARSET_UNKNOWN)
+			charset_label = g_strdup_printf (
+				"%s (%s)",
+				gettext (classnames[charsets[ii].class]),
+				escaped_name);
+		else
+			charset_label = g_strdup (escaped_name);
+
+		action = gtk_radio_action_new (
+			charsets[ii].name, charset_label, NULL, NULL, ii);
+
+		gtk_radio_action_set_group (action, group);
+		group = gtk_radio_action_get_group (action);
+
+		if (callback != NULL)
+			g_signal_connect (
+				action, "changed", callback, user_data);
+
+		gtk_action_group_add_action (
+			action_group, GTK_ACTION (action));
+
+		g_object_unref (action);
+
+		g_free (escaped_name);
+		g_free (charset_label);
+	}
+
+	if (def == G_N_ELEMENTS (charsets)) {
+		gchar *charset_label;
+		gchar **str_array;
+
+		/* Escape underlines in the character set name so
+		 * they're not treated as GtkLabel mnemonics. */
+		str_array = g_strsplit (default_charset, "_", -1);
+		charset_label = g_strjoinv ("__", str_array);
+		g_strfreev (str_array);
+
+		action = gtk_radio_action_new (
+			default_charset, charset_label, NULL, NULL, def);
+
+		gtk_radio_action_set_group (action, group);
+		group = gtk_radio_action_get_group (action);
+
+		if (callback != NULL)
+			g_signal_connect (
+				action, "changed", callback, user_data);
+
+		gtk_action_group_add_action (
+			action_group, GTK_ACTION (action));
+
+		g_object_unref (action);
+
+		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

Modified: branches/mbarnes-composer/widgets/misc/e-charset-picker.h
==============================================================================
--- branches/mbarnes-composer/widgets/misc/e-charset-picker.h	(original)
+++ branches/mbarnes-composer/widgets/misc/e-charset-picker.h	Mon Mar 31 03:13:04 2008
@@ -18,31 +18,33 @@
  *
  */
 
-#ifndef _E_CHARSETPICKER_H_
-#define _E_CHARSETPICKER_H_
+#ifndef E_CHARSETPICKER_H
+#define E_CHARSETPICKER_H
 
-#include <gtk/gtkwindow.h>
+#include <gtk/gtk.h>
 #include <bonobo/bonobo-ui-component.h>
 
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus */
-
-GtkWidget *e_charset_picker_new (const char *default_charset);
-char      *e_charset_picker_get_charset (GtkWidget *picker);
-
-char      *e_charset_picker_dialog (const char *title, const char *prompt,
-				    const char *default_charset,
-				    GtkWindow *parent);
-
-/* bonobo equivalents */
-void       e_charset_picker_bonobo_ui_populate (BonoboUIComponent *uic, const char *path,
-						const char *default_charset,
-						BonoboUIListenerFn cb, gpointer user_data);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+G_BEGIN_DECLS
 
-#endif /* _E_CHARSETPICKER_H_ */
+GtkWidget *	e_charset_picker_new		(const char *default_charset);
+char *		e_charset_picker_get_charset	(GtkWidget *picker);
+char *		e_charset_picker_dialog		(const char *title,
+						 const char *prompt,
+						 const char *default_charset,
+						 GtkWindow *parent);
+
+void		e_charset_add_radio_actions	(GtkActionGroup *action_group,
+						 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 */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]