[evolution] EMailPartHeaders: Add a "default-headers" property.



commit c5313b3614bbcb912b4a81a1ffe75911b60ad580
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat May 25 15:36:42 2013 -0400

    EMailPartHeaders: Add a "default-headers" property.
    
    This will replace the headers API in EMailFormatter.  Need a more
    permanent place for headers since EMailFormatter is too disposable.
    
    Also add an ESettingsMailPartHeaders class, which binds the new property
    to the "show-headers" setting with a suitable mapping function to filter
    out disabled header names.

 .../evolution-mail-formatter-sections.txt          |    2 +
 em-format/e-mail-part-headers.c                    |  135 ++++++++++++++++++++
 em-format/e-mail-part-headers.h                    |    9 +-
 modules/settings/Makefile.am                       |    2 +
 modules/settings/e-settings-mail-part-headers.c    |  126 ++++++++++++++++++
 modules/settings/e-settings-mail-part-headers.h    |   66 ++++++++++
 modules/settings/evolution-module-settings.c       |    2 +
 po/POTFILES.in                                     |    1 +
 8 files changed, 341 insertions(+), 2 deletions(-)
---
diff --git a/doc/reference/evolution-mail-formatter/evolution-mail-formatter-sections.txt 
b/doc/reference/evolution-mail-formatter/evolution-mail-formatter-sections.txt
index 67cf18e..2d2957e 100644
--- a/doc/reference/evolution-mail-formatter/evolution-mail-formatter-sections.txt
+++ b/doc/reference/evolution-mail-formatter/evolution-mail-formatter-sections.txt
@@ -327,6 +327,8 @@ EMailPartAttachmentBarPrivate
 E_MAIL_PART_HEADERS_MIME_TYPE
 EMailPartHeaders
 e_mail_part_headers_new
+e_mail_part_headers_dup_default_headers
+e_mail_part_headers_set_default_headers
 <SUBSECTION Standard>
 E_MAIL_PART_HEADERS
 E_IS_MAIL_PART_HEADERS
diff --git a/em-format/e-mail-part-headers.c b/em-format/e-mail-part-headers.c
index d1398f9..5a74376 100644
--- a/em-format/e-mail-part-headers.c
+++ b/em-format/e-mail-part-headers.c
@@ -18,11 +18,91 @@
 
 #include "e-mail-part-headers.h"
 
+#include <config.h>
+#include <glib/gi18n-lib.h>
+
+#define E_MAIL_PART_HEADERS_GET_PRIVATE(obj) \
+       (G_TYPE_INSTANCE_GET_PRIVATE \
+       ((obj), E_TYPE_MAIL_PART_HEADERS, EMailPartHeadersPrivate))
+
+struct _EMailPartHeadersPrivate {
+       GMutex property_lock;
+       gchar **default_headers;
+};
+
+enum {
+       PROP_0,
+       PROP_DEFAULT_HEADERS
+};
+
 G_DEFINE_TYPE (
        EMailPartHeaders,
        e_mail_part_headers,
        E_TYPE_MAIL_PART)
 
+static const gchar *basic_headers[] = {
+       N_("From"),
+       N_("Reply-To"),
+       N_("To"),
+       N_("Cc"),
+       N_("Bcc"),
+       N_("Subject"),
+       N_("Date"),
+       N_("Newsgroups"),
+       N_("Face"),
+       NULL
+};
+
+static void
+mail_part_headers_set_property (GObject *object,
+                                guint property_id,
+                                const GValue *value,
+                                GParamSpec *pspec)
+{
+       switch (property_id) {
+               case PROP_DEFAULT_HEADERS:
+                       e_mail_part_headers_set_default_headers (
+                               E_MAIL_PART_HEADERS (object),
+                               g_value_get_boxed (value));
+                       return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+mail_part_headers_get_property (GObject *object,
+                                guint property_id,
+                                GValue *value,
+                                GParamSpec *pspec)
+{
+       switch (property_id) {
+               case PROP_DEFAULT_HEADERS:
+                       g_value_take_boxed (
+                               value,
+                               e_mail_part_headers_dup_default_headers (
+                               E_MAIL_PART_HEADERS (object)));
+                       return;
+       }
+
+       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+mail_part_headers_finalize (GObject *object)
+{
+       EMailPartHeadersPrivate *priv;
+
+       priv = E_MAIL_PART_HEADERS_GET_PRIVATE (object);
+
+       g_mutex_clear (&priv->property_lock);
+
+       g_strfreev (priv->default_headers);
+
+       /* Chain up to parent's finalize() method. */
+       G_OBJECT_CLASS (e_mail_part_headers_parent_class)->finalize (object);
+}
+
 static void
 mail_part_headers_constructed (GObject *object)
 {
@@ -70,16 +150,36 @@ e_mail_part_headers_class_init (EMailPartHeadersClass *class)
        GObjectClass *object_class;
        EMailPartClass *mail_part_class;
 
+       g_type_class_add_private (class, sizeof (EMailPartHeadersPrivate));
+
        object_class = G_OBJECT_CLASS (class);
+       object_class->set_property = mail_part_headers_set_property;
+       object_class->get_property = mail_part_headers_get_property;
+       object_class->finalize = mail_part_headers_finalize;
        object_class->constructed = mail_part_headers_constructed;
 
        mail_part_class = E_MAIL_PART_CLASS (class);
        mail_part_class->bind_dom_element = mail_part_headers_bind_dom_element;
+
+       g_object_class_install_property (
+               object_class,
+               PROP_DEFAULT_HEADERS,
+               g_param_spec_boxed (
+                       "default-headers",
+                       "Default Headers",
+                       "Headers to display by default",
+                       G_TYPE_STRV,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_STATIC_STRINGS));
 }
 
 static void
 e_mail_part_headers_init (EMailPartHeaders *part)
 {
+       part->priv = E_MAIL_PART_HEADERS_GET_PRIVATE (part);
+
+       g_mutex_init (&part->priv->property_lock);
 }
 
 EMailPart *
@@ -93,3 +193,38 @@ e_mail_part_headers_new (CamelMimePart *mime_part,
                "id", id, "mime-part", mime_part, NULL);
 }
 
+gchar **
+e_mail_part_headers_dup_default_headers (EMailPartHeaders *part)
+{
+       gchar **default_headers;
+
+       g_return_val_if_fail (E_IS_MAIL_PART_HEADERS (part), NULL);
+
+       g_mutex_lock (&part->priv->property_lock);
+
+       default_headers = g_strdupv (part->priv->default_headers);
+
+       g_mutex_unlock (&part->priv->property_lock);
+
+       return default_headers;
+}
+
+void
+e_mail_part_headers_set_default_headers (EMailPartHeaders *part,
+                                         const gchar * const *default_headers)
+{
+       g_return_if_fail (E_IS_MAIL_PART_HEADERS (part));
+
+       if (default_headers == NULL)
+               default_headers = basic_headers;
+
+       g_mutex_lock (&part->priv->property_lock);
+
+       g_strfreev (part->priv->default_headers);
+       part->priv->default_headers = g_strdupv ((gchar **) default_headers);
+
+       g_mutex_unlock (&part->priv->property_lock);
+
+       g_object_notify (G_OBJECT (part), "default-headers");
+}
+
diff --git a/em-format/e-mail-part-headers.h b/em-format/e-mail-part-headers.h
index fb0e0eb..c302637 100644
--- a/em-format/e-mail-part-headers.h
+++ b/em-format/e-mail-part-headers.h
@@ -32,10 +32,10 @@
        ((cls), E_TYPE_MAIL_PART_HEADERS, EMailPartHeadersClass))
 #define E_IS_MAIL_PART_HEADERS(obj) \
        (G_TYPE_CHECK_INSTANCE_TYPE \
-       ((cls), E_TYPE_MAIL_PART_HEADERS))
+       ((obj), E_TYPE_MAIL_PART_HEADERS))
 #define E_IS_MAIL_PART_HEADERS_CLASS(cls) \
        (G_TYPE_CHECK_CLASS_TYPE \
-       ((obj), E_TYPE_MAIL_PART_HEADERS))
+       ((cls), E_TYPE_MAIL_PART_HEADERS))
 #define E_MAIL_PART_HEADERS_GET_CLASS(obj) \
        (G_TYPE_INSTANCE_GET_CLASS \
        ((obj), E_TYPE_MAIL_PART_HEADERS, EMailPartHeadersClass))
@@ -61,6 +61,11 @@ struct _EMailPartHeadersClass {
 GType          e_mail_part_headers_get_type    (void) G_GNUC_CONST;
 EMailPart *    e_mail_part_headers_new         (CamelMimePart *mime_part,
                                                 const gchar *id);
+gchar **       e_mail_part_headers_dup_default_headers
+                                               (EMailPartHeaders *part);
+void           e_mail_part_headers_set_default_headers
+                                               (EMailPartHeaders *part,
+                                                const gchar * const *default_headers);
 
 G_END_DECLS
 
diff --git a/modules/settings/Makefile.am b/modules/settings/Makefile.am
index 7e3658f..27dc8c7 100644
--- a/modules/settings/Makefile.am
+++ b/modules/settings/Makefile.am
@@ -31,6 +31,8 @@ module_settings_la_SOURCES = \
        e-settings-mail-browser.h \
        e-settings-mail-formatter.c \
        e-settings-mail-formatter.h \
+       e-settings-mail-part-headers.c \
+       e-settings-mail-part-headers.h \
        e-settings-mail-reader.c \
        e-settings-mail-reader.h \
        e-settings-meeting-store.c \
diff --git a/modules/settings/e-settings-mail-part-headers.c b/modules/settings/e-settings-mail-part-headers.c
new file mode 100644
index 0000000..3a846b1
--- /dev/null
+++ b/modules/settings/e-settings-mail-part-headers.c
@@ -0,0 +1,126 @@
+/*
+ * e-settings-mail-part-headers.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-settings-mail-part-headers.h"
+
+#include <em-format/e-mail-part-headers.h>
+
+G_DEFINE_DYNAMIC_TYPE (
+       ESettingsMailPartHeaders,
+       e_settings_mail_part_headers,
+       E_TYPE_EXTENSION)
+
+static EMailPartHeaders *
+settings_mail_part_headers_get_extensible (ESettingsMailPartHeaders *extension)
+{
+       EExtensible *extensible;
+
+       extensible = e_extension_get_extensible (E_EXTENSION (extension));
+
+       return E_MAIL_PART_HEADERS (extensible);
+}
+
+static gboolean
+settings_mail_part_headers_get_mapping (GValue *value,
+                                        GVariant *variant,
+                                        gpointer user_data)
+{
+       gchar **strv;
+       gsize ii, n_children;
+       guint index = 0;
+
+       /* Form a string array of enabled header names. */
+
+       n_children = g_variant_n_children (variant);
+
+       strv = g_new0 (gchar *, n_children + 1);
+
+       for (ii = 0; ii < n_children; ii++) {
+               const gchar *name = NULL;
+               gboolean enabled = FALSE;
+
+               g_variant_get_child (variant, ii, "(&sb)", &name, &enabled);
+
+               if (enabled && name != NULL)
+                       strv[index++] = g_strdup (name);
+       }
+
+       g_value_take_boxed (value, strv);
+
+       return TRUE;
+}
+
+static void
+settings_mail_part_headers_constructed (GObject *object)
+{
+       ESettingsMailPartHeaders *extension;
+       EMailPartHeaders *part;
+       GSettings *settings;
+
+       extension = E_SETTINGS_MAIL_PART_HEADERS (object);
+       part = settings_mail_part_headers_get_extensible (extension);
+
+       settings = g_settings_new ("org.gnome.evolution.mail");
+
+       g_settings_bind_with_mapping (
+               settings, "show-headers",
+               part, "default-headers",
+               G_SETTINGS_BIND_GET,
+               settings_mail_part_headers_get_mapping,
+               (GSettingsBindSetMapping) NULL,
+               NULL, (GDestroyNotify) NULL);
+
+       g_object_unref (settings);
+
+       /* Chain up to parent's constructed() method. */
+       G_OBJECT_CLASS (e_settings_mail_part_headers_parent_class)->
+               constructed (object);
+}
+
+static void
+e_settings_mail_part_headers_class_init (ESettingsMailPartHeadersClass *class)
+{
+       GObjectClass *object_class;
+       EExtensionClass *extension_class;
+
+       object_class = G_OBJECT_CLASS (class);
+       object_class->constructed = settings_mail_part_headers_constructed;
+
+       extension_class = E_EXTENSION_CLASS (class);
+       extension_class->extensible_type = E_TYPE_MAIL_PART_HEADERS;
+}
+
+static void
+e_settings_mail_part_headers_class_finalize (ESettingsMailPartHeadersClass *class)
+{
+}
+
+static void
+e_settings_mail_part_headers_init (ESettingsMailPartHeaders *extension)
+{
+}
+
+void
+e_settings_mail_part_headers_type_register (GTypeModule *type_module)
+{
+       /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
+        *     function, so we have to wrap it with a public function in
+        *     order to register types from a separate compilation unit. */
+       e_settings_mail_part_headers_register_type (type_module);
+}
+
diff --git a/modules/settings/e-settings-mail-part-headers.h b/modules/settings/e-settings-mail-part-headers.h
new file mode 100644
index 0000000..e1917a4
--- /dev/null
+++ b/modules/settings/e-settings-mail-part-headers.h
@@ -0,0 +1,66 @@
+/*
+ * e-settings-mail-part-headers.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_SETTINGS_MAIL_PART_HEADERS_H
+#define E_SETTINGS_MAIL_PART_HEADERS_H
+
+#include <libebackend/libebackend.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SETTINGS_MAIL_PART_HEADERS \
+       (e_settings_mail_part_headers_get_type ())
+#define E_SETTINGS_MAIL_PART_HEADERS(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), E_TYPE_SETTINGS_MAIL_PART_HEADERS, ESettingsMailPartHeaders))
+#define E_SETTINGS_MAIL_PART_HEADERS_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), E_TYPE_SETTINGS_MAIL_PART_HEADERS, ESettingsMailPartHeadersClass))
+#define E_IS_SETTINGS_MAIL_PART_HEADERS(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), E_TYPE_SETTINGS_MAIL_PART_HEADERS))
+#define E_IS_SETTINGS_MAIL_PART_HEADERS_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), E_TYPE_SETTINGS_MAIL_PART_HEADERS))
+#define E_SETTINGS_MAIL_PART_HEADERS_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), E_TYPE_SETTINGS_MAIL_PART_HEADERS, ESettingsMailPartHeadersClass))
+
+G_BEGIN_DECLS
+
+typedef struct _ESettingsMailPartHeaders ESettingsMailPartHeaders;
+typedef struct _ESettingsMailPartHeadersClass ESettingsMailPartHeadersClass;
+typedef struct _ESettingsMailPartHeadersPrivate ESettingsMailPartHeadersPrivate;
+
+struct _ESettingsMailPartHeaders {
+       EExtension parent;
+       ESettingsMailPartHeadersPrivate *priv;
+};
+
+struct _ESettingsMailPartHeadersClass {
+       EExtensionClass parent_class;
+};
+
+GType          e_settings_mail_part_headers_get_type
+                                               (void) G_GNUC_CONST;
+void           e_settings_mail_part_headers_type_register
+                                               (GTypeModule *type_module);
+
+G_END_DECLS
+
+#endif /* E_SETTINGS_MAIL_PART_HEADERS_H */
+
diff --git a/modules/settings/evolution-module-settings.c b/modules/settings/evolution-module-settings.c
index 4de9022..7cde55a 100644
--- a/modules/settings/evolution-module-settings.c
+++ b/modules/settings/evolution-module-settings.c
@@ -25,6 +25,7 @@
 #include "e-settings-deprecated.h"
 #include "e-settings-mail-browser.h"
 #include "e-settings-mail-formatter.h"
+#include "e-settings-mail-part-headers.h"
 #include "e-settings-mail-reader.h"
 #include "e-settings-meeting-store.h"
 #include "e-settings-meeting-time-selector.h"
@@ -50,6 +51,7 @@ e_module_load (GTypeModule *type_module)
        e_settings_deprecated_type_register (type_module);
        e_settings_mail_browser_type_register (type_module);
        e_settings_mail_formatter_type_register (type_module);
+       e_settings_mail_part_headers_type_register (type_module);
        e_settings_mail_reader_type_register (type_module);
        e_settings_meeting_store_type_register (type_module);
        e_settings_meeting_time_selector_type_register (type_module);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6b7b1da..cd2e191 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -170,6 +170,7 @@ em-format/e-mail-parser-inlinepgp-signed.c
 em-format/e-mail-parser-message-external.c
 em-format/e-mail-parser-multipart-encrypted.c
 em-format/e-mail-parser-multipart-signed.c
+em-format/e-mail-part-headers.c
 em-format/e-mail-part-utils.c
 [type: gettext/glade]e-util/e-send-options.ui
 [type: gettext/glade]e-util/e-table-config.ui


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