aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2010-04-26 22:42:02 +0800
committerMilan Crha <mcrha@redhat.com>2010-04-26 22:42:02 +0800
commitcd7c20d152dcaa2b92c3e78822b5243a71a94514 (patch)
tree3e0ae9951834a407611d3032d0ff4606e1c54755
parentbfd1a13f60b3b0bf914ce6d6e92f097c1ee05197 (diff)
downloadgsoc2013-evolution-cd7c20d152dcaa2b92c3e78822b5243a71a94514.tar.gz
gsoc2013-evolution-cd7c20d152dcaa2b92c3e78822b5243a71a94514.tar.zst
gsoc2013-evolution-cd7c20d152dcaa2b92c3e78822b5243a71a94514.zip
Bug #603418 - Custom headers not displayed in message preview
-rw-r--r--mail/e-mail-browser.c2
-rw-r--r--mail/e-mail-reader-utils.c186
-rw-r--r--mail/e-mail-reader-utils.h15
-rw-r--r--modules/mail/e-mail-shell-content.c3
-rw-r--r--modules/mail/em-mailer-prefs.c128
-rw-r--r--modules/mail/em-mailer-prefs.h12
6 files changed, 216 insertions, 130 deletions
diff --git a/mail/e-mail-browser.c b/mail/e-mail-browser.c
index a1d6d114bb..5018a6818d 100644
--- a/mail/e-mail-browser.c
+++ b/mail/e-mail-browser.c
@@ -615,6 +615,8 @@ mail_browser_constructed (GObject *object)
id = "org.gnome.evolution.mail.browser";
e_plugin_ui_register_manager (ui_manager, id, object);
e_plugin_ui_enable_manager (ui_manager, id);
+
+ e_mail_reader_connect_headers (E_MAIL_READER (reader));
}
static gboolean
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index f41c4e2d68..51912bb1b1 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -24,6 +24,7 @@
#include "e-mail-reader-utils.h"
#include <glib/gi18n.h>
+#include <libxml/tree.h>
#include <gtkhtml/gtkhtml.h>
#include <camel/camel.h>
@@ -35,6 +36,7 @@
#include "mail/em-format-html-print.h"
#include "mail/em-utils.h"
#include "mail/mail-autofilter.h"
+#include "mail/mail-config.h"
#include "mail/mail-ops.h"
#include "mail/mail-tools.h"
#include "mail/mail-vfolder.h"
@@ -554,3 +556,187 @@ e_mail_reader_create_vfolder_from_selected (EMailReader *reader,
em_utils_uids_free (uids);
}
+
+static EMailReaderHeader *
+emr_header_from_xmldoc (xmlDocPtr doc)
+{
+ EMailReaderHeader *h;
+ xmlNodePtr root;
+ xmlChar *name;
+
+ if (doc == NULL)
+ return NULL;
+
+ root = doc->children;
+ if (strcmp ((gchar *)root->name, "header") != 0)
+ return NULL;
+
+ name = xmlGetProp (root, (const guchar *)"name");
+ if (name == NULL)
+ return NULL;
+
+ h = g_malloc0 (sizeof (EMailReaderHeader));
+ h->name = g_strdup ((gchar *)name);
+ xmlFree (name);
+
+ if (xmlHasProp (root, (const guchar *)"enabled"))
+ h->enabled = 1;
+ else
+ h->enabled = 0;
+
+ return h;
+}
+
+/**
+ * e_mail_reader_header_from_xml
+ * @xml: XML configuration data
+ *
+ * Parses passed XML data, which should be of
+ * the format <header name="foo" enabled />, and
+ * returns a EMailReaderHeader structure, or NULL if there
+ * is an error.
+ **/
+EMailReaderHeader *
+e_mail_reader_header_from_xml (const gchar *xml)
+{
+ EMailReaderHeader *header;
+ xmlDocPtr doc;
+
+ if (!(doc = xmlParseDoc ((guchar *) xml)))
+ return NULL;
+
+ header = emr_header_from_xmldoc (doc);
+ xmlFreeDoc (doc);
+
+ return header;
+}
+
+/**
+ * e_mail_reader_header_to_xml
+ * @header: header from which to generate XML
+ *
+ * Returns the passed header as a XML structure,
+ * or NULL on error
+ */
+gchar *
+e_mail_reader_header_to_xml (EMailReaderHeader *header)
+{
+ xmlDocPtr doc;
+ xmlNodePtr root;
+ xmlChar *xml;
+ gchar *out;
+ gint size;
+
+ g_return_val_if_fail (header != NULL, NULL);
+ g_return_val_if_fail (header->name != NULL, NULL);
+
+ doc = xmlNewDoc ((const guchar *)"1.0");
+
+ root = xmlNewDocNode (doc, NULL, (const guchar *)"header", NULL);
+ xmlSetProp (root, (const guchar *)"name", (guchar *)header->name);
+ if (header->enabled)
+ xmlSetProp (root, (const guchar *)"enabled", NULL);
+
+ xmlDocSetRootElement (doc, root);
+ xmlDocDumpMemory (doc, &xml, &size);
+ xmlFreeDoc (doc);
+
+ out = g_malloc (size + 1);
+ memcpy (out, xml, size);
+ out[size] = '\0';
+ xmlFree (xml);
+
+ return out;
+}
+
+/**
+ * e_mail_reader_header_free
+ * @header: header to free
+ *
+ * Frees the memory associated with the passed header
+ * structure.
+ */
+void
+e_mail_reader_header_free (EMailReaderHeader *header)
+{
+ if (header == NULL)
+ return;
+
+ g_free (header->name);
+ g_free (header);
+}
+
+static void
+headers_changed_cb (GConfClient *gconf, guint cnxn_id, GConfEntry *entry, EMailReader *reader)
+{
+ EMFormat *emf;
+ EMFormatHTMLDisplay *emfhd;
+ GSList *header_config_list, *p;
+
+ g_return_if_fail (gconf != NULL);
+ g_return_if_fail (reader != NULL);
+
+ emfhd = e_mail_reader_get_html_display (reader);
+ if (!emfhd)
+ return;
+
+ emf = EM_FORMAT (emfhd);
+ g_return_if_fail (emf != NULL);
+
+ header_config_list = gconf_client_get_list (gconf, "/apps/evolution/mail/display/headers", GCONF_VALUE_STRING, NULL);
+ em_format_clear_headers (emf);
+ for (p = header_config_list; p; p = g_slist_next(p)) {
+ EMailReaderHeader *h;
+ gchar *xml = (gchar *)p->data;
+
+ h = e_mail_reader_header_from_xml (xml);
+ if (h && h->enabled) {
+ em_format_add_header (emf, h->name, EM_FORMAT_HEADER_BOLD);
+ }
+
+ e_mail_reader_header_free (h);
+ }
+
+ g_slist_foreach(header_config_list, (GFunc) g_free, NULL);
+ g_slist_free(header_config_list);
+
+ /* force a redraw */
+ if (emf->message)
+ em_format_redraw (emf);
+}
+
+static void
+remove_header_notify_cb (gpointer data)
+{
+ GConfClient *gconf = mail_config_get_gconf_client ();
+ guint notify_id;
+
+ g_return_if_fail (gconf != NULL);
+
+ notify_id = GPOINTER_TO_INT (data);
+ g_return_if_fail (notify_id != 0);
+
+ gconf_client_notify_remove (gconf, notify_id);
+ gconf_client_remove_dir (gconf, "/apps/evolution/mail/display", NULL);
+}
+
+/**
+ * e_mail_reader_connect_headers
+ * @reader: an #EMailReader
+ *
+ * Connects @reader to listening for changes in headers and
+ * updates the EMFormat whenever it changes and on this call too.
+ **/
+void
+e_mail_reader_connect_headers (EMailReader *reader)
+{
+ GConfClient *gconf = mail_config_get_gconf_client ();
+ guint notify_id;
+
+ gconf_client_add_dir (gconf, "/apps/evolution/mail/display", GCONF_CLIENT_PRELOAD_NONE, NULL);
+ notify_id = gconf_client_notify_add (gconf, "/apps/evolution/mail/display/headers", (GConfClientNotifyFunc) headers_changed_cb, reader, NULL, NULL);
+
+ g_object_set_data_full (G_OBJECT (reader), "reader-header-notify-id", GINT_TO_POINTER (notify_id), remove_header_notify_cb);
+
+ headers_changed_cb (gconf, 0, NULL, reader);
+}
diff --git a/mail/e-mail-reader-utils.h b/mail/e-mail-reader-utils.h
index 46c3ea7345..72ad761cc3 100644
--- a/mail/e-mail-reader-utils.h
+++ b/mail/e-mail-reader-utils.h
@@ -28,6 +28,14 @@
G_BEGIN_DECLS
+typedef struct _EMailReaderHeader EMailReaderHeader;
+
+struct _EMailReaderHeader {
+ gchar *name;
+ guint enabled:1;
+ guint is_default:1;
+};
+
void e_mail_reader_activate (EMailReader *reader,
const gchar *action_name);
gboolean e_mail_reader_confirm_delete (EMailReader *reader);
@@ -51,6 +59,13 @@ void e_mail_reader_create_vfolder_from_selected
(EMailReader *reader,
gint filter_type);
+EMailReaderHeader *
+ e_mail_reader_header_from_xml (const gchar *xml);
+gchar * e_mail_reader_header_to_xml (EMailReaderHeader *header);
+void e_mail_reader_header_free (EMailReaderHeader *header);
+
+void e_mail_reader_connect_headers (EMailReader *reader);
+
G_END_DECLS
#endif /* E_MAIL_READER_UTILS_H */
diff --git a/modules/mail/e-mail-shell-content.c b/modules/mail/e-mail-shell-content.c
index 7bfced18e8..adda27da49 100644
--- a/modules/mail/e-mail-shell-content.c
+++ b/modules/mail/e-mail-shell-content.c
@@ -39,6 +39,7 @@
#include "message-list.h"
#include "e-mail-reader.h"
+#include "e-mail-reader-utils.h"
#include "e-mail-shell-backend.h"
#include "e-mail-shell-view-actions.h"
@@ -456,6 +457,8 @@ mail_shell_content_constructed (GObject *object)
message_list, "message-selected",
G_CALLBACK (mail_shell_content_message_selected_cb),
shell_content);
+
+ e_mail_reader_connect_headers (reader);
}
static guint32
diff --git a/modules/mail/em-mailer-prefs.c b/modules/mail/em-mailer-prefs.c
index 838144695d..4fb910a396 100644
--- a/modules/mail/em-mailer-prefs.c
+++ b/modules/mail/em-mailer-prefs.c
@@ -44,6 +44,7 @@
#include "widgets/misc/e-charset-combo-box.h"
#include "e-mail-label-manager.h"
+#include "e-mail-reader-utils.h"
#include "mail-config.h"
#include "em-folder-selection-button.h"
#include "em-junk.h"
@@ -423,7 +424,7 @@ emmp_save_headers (EMMailerPrefs *prefs)
header_list = NULL;
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (prefs->header_list_store), &iter);
while (valid) {
- struct _EMMailerPrefsHeader h;
+ struct _EMailReaderHeader h;
gboolean enabled;
gchar *xml;
@@ -433,7 +434,7 @@ emmp_save_headers (EMMailerPrefs *prefs)
-1);
h.enabled = enabled;
- if ((xml = em_mailer_prefs_header_to_xml (&h)))
+ if ((xml = e_mail_reader_header_to_xml (&h)))
header_list = g_slist_append (header_list, xml);
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (prefs->header_list_store), &iter);
@@ -1092,9 +1093,9 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs,
header_add_list = NULL;
default_header_hash = g_hash_table_new (g_str_hash, g_str_equal);
for (i = 0; i < G_N_ELEMENTS (default_headers); i++) {
- struct _EMMailerPrefsHeader *h;
+ EMailReaderHeader *h;
- h = g_malloc (sizeof (struct _EMMailerPrefsHeader));
+ h = g_malloc (sizeof (EMailReaderHeader));
h->is_default = TRUE;
h->name = g_strdup (default_headers[i]);
h->enabled = strcmp ((gchar *)default_headers[i], "x-evolution-mailer") != 0;
@@ -1106,15 +1107,15 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs,
header_config_list = gconf_client_get_list (prefs->gconf, "/apps/evolution/mail/display/headers", GCONF_VALUE_STRING, NULL);
p = header_config_list;
while (p) {
- struct _EMMailerPrefsHeader *h, *def;
+ EMailReaderHeader *h, *def;
gchar *xml = (gchar *) p->data;
- h = em_mailer_prefs_header_from_xml (xml);
+ h = e_mail_reader_header_from_xml (xml);
if (h) {
def = g_hash_table_lookup (default_header_hash, h->name);
if (def) {
def->enabled = h->enabled;
- em_mailer_prefs_header_free (h);
+ e_mail_reader_header_free (h);
} else {
h->is_default = FALSE;
header_add_list = g_slist_append (header_add_list, h);
@@ -1130,7 +1131,7 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs,
p = header_add_list;
while (p) {
- struct _EMMailerPrefsHeader *h = (struct _EMMailerPrefsHeader *) p->data;
+ struct _EMailReaderHeader *h = (struct _EMailReaderHeader *) p->data;
const gchar *name;
if (g_ascii_strcasecmp (h->name, EM_FORMAT_HEADER_XMAILER) == 0)
@@ -1146,7 +1147,7 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs,
HEADER_LIST_HEADER_COLUMN, h->name,
-1);
- em_mailer_prefs_header_free (h);
+ e_mail_reader_header_free (h);
p = p->next;
}
@@ -1234,112 +1235,3 @@ em_mailer_prefs_new (EShell *shell)
return GTK_WIDGET (new);
}
-
-static struct _EMMailerPrefsHeader *
-emmp_header_from_xmldoc (xmlDocPtr doc)
-{
- struct _EMMailerPrefsHeader *h;
- xmlNodePtr root;
- xmlChar *name;
-
- if (doc == NULL)
- return NULL;
-
- root = doc->children;
- if (strcmp ((gchar *)root->name, "header") != 0)
- return NULL;
-
- name = xmlGetProp (root, (const guchar *)"name");
- if (name == NULL)
- return NULL;
-
- h = g_malloc0 (sizeof (struct _EMMailerPrefsHeader));
- h->name = g_strdup ((gchar *)name);
- xmlFree (name);
-
- if (xmlHasProp (root, (const guchar *)"enabled"))
- h->enabled = 1;
- else
- h->enabled = 0;
-
- return h;
-}
-
-/**
- * em_mailer_prefs_header_from_xml
- * @xml: XML configuration data
- *
- * Parses passed XML data, which should be of
- * the format <header name="foo" enabled />, and
- * returns a EMMailerPrefs structure, or NULL if there
- * is an error.
- **/
-struct _EMMailerPrefsHeader *
-em_mailer_prefs_header_from_xml (const gchar *xml)
-{
- struct _EMMailerPrefsHeader *header;
- xmlDocPtr doc;
-
- if (!(doc = xmlParseDoc ((guchar *) xml)))
- return NULL;
-
- header = emmp_header_from_xmldoc (doc);
- xmlFreeDoc (doc);
-
- return header;
-}
-
-/**
- * em_mailer_prefs_header_free
- * @header: header to free
- *
- * Frees the memory associated with the passed header
- * structure.
- */
-void
-em_mailer_prefs_header_free (struct _EMMailerPrefsHeader *header)
-{
- if (header == NULL)
- return;
-
- g_free (header->name);
- g_free (header);
-}
-
-/**
- * em_mailer_prefs_header_to_xml
- * @header: header from which to generate XML
- *
- * Returns the passed header as a XML structure,
- * or NULL on error
- */
-gchar *
-em_mailer_prefs_header_to_xml (struct _EMMailerPrefsHeader *header)
-{
- xmlDocPtr doc;
- xmlNodePtr root;
- xmlChar *xml;
- gchar *out;
- gint size;
-
- g_return_val_if_fail (header != NULL, NULL);
- g_return_val_if_fail (header->name != NULL, NULL);
-
- doc = xmlNewDoc ((const guchar *)"1.0");
-
- root = xmlNewDocNode (doc, NULL, (const guchar *)"header", NULL);
- xmlSetProp (root, (const guchar *)"name", (guchar *)header->name);
- if (header->enabled)
- xmlSetProp (root, (const guchar *)"enabled", NULL);
-
- xmlDocSetRootElement (doc, root);
- xmlDocDumpMemory (doc, &xml, &size);
- xmlFreeDoc (doc);
-
- out = g_malloc (size + 1);
- memcpy (out, xml, size);
- out[size] = '\0';
- xmlFree (xml);
-
- return out;
-}
diff --git a/modules/mail/em-mailer-prefs.h b/modules/mail/em-mailer-prefs.h
index 8ad6ad2f64..db77493416 100644
--- a/modules/mail/em-mailer-prefs.h
+++ b/modules/mail/em-mailer-prefs.h
@@ -50,13 +50,6 @@ G_BEGIN_DECLS
typedef struct _EMMailerPrefs EMMailerPrefs;
typedef struct _EMMailerPrefsClass EMMailerPrefsClass;
-typedef struct _EMMailerPrefsHeader EMMailerPrefsHeader;
-
-struct _EMMailerPrefsHeader {
- gchar *name;
- guint enabled:1;
- guint is_default:1;
-};
struct _EMMailerPrefs {
GtkVBox parent_object;
@@ -120,11 +113,6 @@ GtkWidget * create_combo_text_widget (void);
GtkWidget * em_mailer_prefs_new (EShell *shell);
-EMMailerPrefsHeader *
- em_mailer_prefs_header_from_xml (const gchar *xml);
-gchar * em_mailer_prefs_header_to_xml (EMMailerPrefsHeader *header);
-void em_mailer_prefs_header_free (EMMailerPrefsHeader *header);
-
G_END_DECLS
#endif /* EM_MAILER_PREFS_H */