aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2004-04-01 05:13:00 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-04-01 05:13:00 +0800
commit16a061d1bf45a585189e91b82e95eabe2e0d33d6 (patch)
tree0540834aaee277686765c19bd36b9c3c50edb7da /e-util
parent736f887487a3e3a546744cbb6658a3774287da9f (diff)
downloadgsoc2013-evolution-16a061d1bf45a585189e91b82e95eabe2e0d33d6.tar
gsoc2013-evolution-16a061d1bf45a585189e91b82e95eabe2e0d33d6.tar.gz
gsoc2013-evolution-16a061d1bf45a585189e91b82e95eabe2e0d33d6.tar.bz2
gsoc2013-evolution-16a061d1bf45a585189e91b82e95eabe2e0d33d6.tar.lz
gsoc2013-evolution-16a061d1bf45a585189e91b82e95eabe2e0d33d6.tar.xz
gsoc2013-evolution-16a061d1bf45a585189e91b82e95eabe2e0d33d6.tar.zst
gsoc2013-evolution-16a061d1bf45a585189e91b82e95eabe2e0d33d6.zip
New class similar to EAccount but for signatures.
2004-03-31 Jeffrey Stedfast <fejj@ximian.com> * e-signature.[c,h]: New class similar to EAccount but for signatures. * e-signature-list.[c,h]: New class similar to EAccountList only for signatures. svn path=/trunk/; revision=25271
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog8
-rw-r--r--e-util/Makefile.am4
-rw-r--r--e-util/e-signature-list.c428
-rw-r--r--e-util/e-signature-list.h76
-rw-r--r--e-util/e-signature.c363
-rw-r--r--e-util/e-signature.h76
6 files changed, 955 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index ba5e6c1399..7313f5a540 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,11 @@
+2004-03-31 Jeffrey Stedfast <fejj@ximian.com>
+
+ * e-signature.[c,h]: New class similar to EAccount but for
+ signatures.
+
+ * e-signature-list.[c,h]: New class similar to EAccountList only
+ for signatures.
+
2004-03-31 Not Zed <NotZed@Ximian.com>
* e-account-list.h: similar to below.
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index b88b20db2e..70cb9ab836 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -39,6 +39,8 @@ eutilinclude_HEADERS = \
e-path.h \
e-request.h \
e-sexp.h \
+ e-signature.h \
+ e-signature-list.h \
e-time-utils.h \
e-trie.h \
e-uid.h \
@@ -75,6 +77,8 @@ libeutil_la_SOURCES = \
e-path.c \
e-request.c \
e-sexp.c \
+ e-signature.c \
+ e-signature-list.c \
e-time-utils.c \
e-trie.c \
e-uid.c \
diff --git a/e-util/e-signature-list.c b/e-util/e-signature-list.c
new file mode 100644
index 0000000000..315ea8f042
--- /dev/null
+++ b/e-util/e-signature-list.c
@@ -0,0 +1,428 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Jeffrey Stedfast <fejj@ximian.com>
+ *
+ * Copyright 2004 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include "e-util-marshal.h"
+
+#include "e-signature-list.h"
+
+struct _ESignatureListPrivate {
+ GConfClient *gconf;
+ guint notify_id;
+};
+
+enum {
+ SIGNATURE_ADDED,
+ SIGNATURE_CHANGED,
+ SIGNATURE_REMOVED,
+ LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0 };
+
+static void e_signature_list_class_init (ESignatureListClass *klass);
+static void e_signature_list_init (ESignatureList *list, ESignatureListClass *klass);
+static void e_signature_list_finalize (GObject *object);
+static void e_signature_list_dispose (GObject *object);
+
+
+static EListClass *parent_class = NULL;
+
+
+GType
+e_signature_list_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ GTypeInfo type_info = {
+ sizeof (ESignatureListClass),
+ NULL, NULL,
+ (GClassInitFunc) e_signature_list_class_init,
+ NULL, NULL,
+ sizeof (ESignatureList),
+ 0,
+ (GInstanceInitFunc) e_signature_list_init,
+ };
+
+ type = g_type_register_static (E_TYPE_LIST, "ESignatureList", &type_info, 0);
+ }
+
+ return type;
+}
+
+
+static void
+e_signature_list_class_init (ESignatureListClass *klass)
+{
+ GObjectClass *object_class = (GObjectClass *) klass;
+
+ parent_class = g_type_class_ref (E_TYPE_LIST);
+
+ /* virtual method override */
+ object_class->dispose = e_signature_list_dispose;
+ object_class->finalize = e_signature_list_finalize;
+
+ /* signals */
+ signals[SIGNATURE_ADDED] =
+ g_signal_new ("signature-added",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ESignatureListClass, signature_added),
+ NULL, NULL,
+ e_util_marshal_NONE__OBJECT,
+ G_TYPE_NONE, 1,
+ E_TYPE_SIGNATURE);
+ signals[SIGNATURE_CHANGED] =
+ g_signal_new ("signature-changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ESignatureListClass, signature_changed),
+ NULL, NULL,
+ e_util_marshal_NONE__OBJECT,
+ G_TYPE_NONE, 1,
+ E_TYPE_SIGNATURE);
+ signals[SIGNATURE_REMOVED] =
+ g_signal_new ("signature-removed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ESignatureListClass, signature_removed),
+ NULL, NULL,
+ e_util_marshal_NONE__OBJECT,
+ G_TYPE_NONE, 1,
+ E_TYPE_SIGNATURE);
+}
+
+static void
+e_signature_list_init (ESignatureList *list, ESignatureListClass *klass)
+{
+ list->priv = g_new0 (struct _ESignatureListPrivate, 1);
+}
+
+static void
+e_signature_list_dispose (GObject *object)
+{
+ ESignatureList *list = (ESignatureList *) object;
+
+ if (list->priv->gconf) {
+ if (list->priv->notify_id != 0)
+ gconf_client_notify_remove (list->priv->gconf, list->priv->notify_id);
+ g_object_unref (list->priv->gconf);
+ list->priv->gconf = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+e_signature_list_finalize (GObject *object)
+{
+ ESignatureList *list = (ESignatureList *) object;
+
+ g_free (list->priv);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+static void
+gconf_signatures_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data)
+{
+ ESignatureList *signature_list = user_data;
+ GSList *list, *l, *n, *new_sigs = NULL;
+ ESignature *signature;
+ EList *old_sigs;
+ EIterator *iter;
+ char *uid;
+
+ old_sigs = e_list_duplicate (E_LIST (signature_list));
+
+ list = gconf_client_get_list (client, "/apps/evolution/mail/signatures", GCONF_VALUE_STRING, NULL);
+ for (l = list; l; l = l->next) {
+ uid = e_signature_uid_from_xml (l->data);
+ if (!uid)
+ continue;
+
+ /* See if this is an existing signature */
+ for (iter = e_list_get_iterator (old_sigs); e_iterator_is_valid (iter); e_iterator_next (iter)) {
+ signature = (ESignature *) e_iterator_get (iter);
+ if (!strcmp (signature->uid, uid)) {
+ /* The signature still exists, so remove
+ * it from "old_sigs" and update it.
+ */
+ e_iterator_delete (iter);
+ if (e_signature_set_from_xml (signature, l->data))
+ g_signal_emit (signature_list, signals[SIGNATURE_CHANGED], 0, signature);
+ goto next;
+ }
+ }
+
+ /* Must be a new signature */
+ signature = e_signature_new_from_xml (l->data);
+ e_list_append (E_LIST (signature_list), signature);
+ new_sigs = g_slist_prepend (new_sigs, signature);
+
+ next:
+ g_free (uid);
+ g_object_unref (iter);
+ }
+
+ /* Now emit signals for each added signature. */
+ l = new_sigs;
+ while (l != NULL) {
+ n = l->next;
+ signature = l->data;
+ g_signal_emit (signature_list, signals[SIGNATURE_ADDED], 0, signature);
+ g_object_unref (signature);
+ g_slist_free_1 (l);
+ l = n;
+ }
+
+ /* Anything left in old_sigs must have been deleted */
+ for (iter = e_list_get_iterator (old_sigs); e_iterator_is_valid (iter); e_iterator_next (iter)) {
+ signature = (ESignature *) e_iterator_get (iter);
+ e_list_remove (E_LIST (signature_list), signature);
+ g_signal_emit (signature_list, signals[SIGNATURE_REMOVED], 0, signature);
+ }
+
+ g_object_unref (iter);
+ g_object_unref (old_sigs);
+}
+
+static void *
+copy_func (const void *data, void *closure)
+{
+ GObject *object = (GObject *)data;
+
+ g_object_ref (object);
+
+ return object;
+}
+
+static void
+free_func (void *data, void *closure)
+{
+ g_object_unref (data);
+}
+
+/**
+ * e_signature_list_new:
+ * @gconf: a #GConfClient
+ *
+ * Reads the list of signaturess from @gconf and listens for changes.
+ * Will emit #signature_added, #signature_changed, and #signature_removed
+ * signals according to notifications from GConf.
+ *
+ * You can modify the list using e_list_append(), e_list_remove(), and
+ * e_iterator_delete(). After adding, removing, or changing accounts,
+ * you must call e_signature_list_save() to push the changes back to
+ * GConf.
+ *
+ * Return value: the list of signatures
+ **/
+ESignatureList *
+e_signature_list_new (GConfClient *gconf)
+{
+ ESignatureList *signature_list;
+
+ g_return_val_if_fail (GCONF_IS_CLIENT (gconf), NULL);
+
+ signature_list = g_object_new (E_TYPE_SIGNATURE_LIST, NULL);
+ e_signature_list_construct (signature_list, gconf);
+
+ return signature_list;
+}
+
+void
+e_signature_list_construct (ESignatureList *signature_list, GConfClient *gconf)
+{
+ g_return_if_fail (GCONF_IS_CLIENT (gconf));
+
+ e_list_construct (E_LIST (signature_list), copy_func, free_func, NULL);
+ signature_list->priv->gconf = gconf;
+ g_object_ref (gconf);
+
+ gconf_client_add_dir (signature_list->priv->gconf,
+ "/apps/evolution/mail/signatures",
+ GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+
+ signature_list->priv->notify_id =
+ gconf_client_notify_add (signature_list->priv->gconf,
+ "/apps/evolution/mail/signatures",
+ gconf_signatures_changed, signature_list,
+ NULL, NULL);
+
+ gconf_signatures_changed (signature_list->priv->gconf,
+ signature_list->priv->notify_id,
+ NULL, signature_list);
+}
+
+
+/**
+ * e_signature_list_save:
+ * @signature_list: an #ESignatureList
+ *
+ * Saves @signature_list to GConf. Signals will be emitted for changes.
+ **/
+void
+e_signature_list_save (ESignatureList *signature_list)
+{
+ GSList *list = NULL;
+ ESignature *signature;
+ EIterator *iter;
+ char *xmlbuf;
+
+ for (iter = e_list_get_iterator (E_LIST (signature_list));
+ e_iterator_is_valid (iter);
+ e_iterator_next (iter)) {
+ signature = (ESignature *) e_iterator_get (iter);
+
+ if ((xmlbuf = e_signature_to_xml (signature)))
+ list = g_slist_append (list, xmlbuf);
+ }
+
+ g_object_unref (iter);
+
+ gconf_client_set_list (signature_list->priv->gconf,
+ "/apps/evolution/mail/signatures",
+ GCONF_VALUE_STRING, list, NULL);
+
+ while (list) {
+ g_free (list->data);
+ list = g_slist_remove (list, list->data);
+ }
+
+ gconf_client_suggest_sync (signature_list->priv->gconf, NULL);
+}
+
+
+/**
+ * e_signature_list_add:
+ * @signatures: signature list
+ * @signature: signature to add
+ *
+ * Add an signature to the signature list. Will emit the signature-changed
+ * event.
+ **/
+void
+e_signature_list_add (ESignatureList *signatures, ESignature *signature)
+{
+ e_list_append ((EList *) signatures, signature);
+ g_signal_emit (signatures, signals[SIGNATURE_ADDED], 0, signature);
+}
+
+
+/**
+ * e_signature_list_change:
+ * @signatures: signature list
+ * @signature: signature to change
+ *
+ * Signal that the details of an signature have changed.
+ **/
+void
+e_signature_list_change (ESignatureList *signatures, ESignature *signature)
+{
+ /* maybe the signature should do this itself ... */
+ g_signal_emit (signatures, signals[SIGNATURE_CHANGED], 0, signature);
+}
+
+
+/**
+ * e_signature_list_remove:
+ * @signatures: signature list
+ * @signature: signature
+ *
+ * Remove an signature from the signature list, and emit the
+ * signature-removed signal. If the signature was the default signature,
+ * then reset the default to the first signature.
+ **/
+void
+e_signature_list_remove (ESignatureList *signatures, ESignature *signature)
+{
+ /* not sure if need to ref but no harm */
+ g_object_ref (signature);
+ e_list_remove ((EList *) signatures, signature);
+ g_signal_emit (signatures, signals[SIGNATURE_REMOVED], 0, signature);
+ g_object_unref (signature);
+}
+
+
+/**
+ * e_signature_list_find:
+ * @signatures: signature list
+ * @type: Type of search.
+ * @key: Search key.
+ *
+ * Perform a search of the signature list on a single key.
+ *
+ * @type must be set from one of the following search types:
+ * E_SIGNATURE_FIND_NAME - Find a signature by signature name.
+ * E_SIGNATURE_FIND_UID - Find a signature based on UID
+ *
+ * Return value: The signature or NULL if it doesn't exist.
+ **/
+const ESignature *
+e_signature_list_find (ESignatureList *signatures, e_signature_find_t type, const char *key)
+{
+ const ESignature *signature = NULL;
+ EIterator *it;
+ char *val;
+
+ /* this could use a callback for more flexibility ...
+ ... but this makes the common cases easier */
+
+ if (!key)
+ return NULL;
+
+ for (it = e_list_get_iterator ((EList *)signatures);
+ e_iterator_is_valid (it);
+ e_iterator_next (it)) {
+ int found = 0;
+
+ signature = (const ESignature *) e_iterator_get (it);
+
+ val = NULL;
+ switch (type) {
+ case E_SIGNATURE_FIND_NAME:
+ found = strcmp (signature->name, key) == 0;
+ break;
+ case E_SIGNATURE_FIND_UID:
+ found = strcmp (signature->uid, key) == 0;
+ break;
+ }
+
+ if (found)
+ break;
+
+ signature = NULL;
+ }
+
+ g_object_unref (it);
+
+ return signature;
+}
diff --git a/e-util/e-signature-list.h b/e-util/e-signature-list.h
new file mode 100644
index 0000000000..0e7f437041
--- /dev/null
+++ b/e-util/e-signature-list.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Jeffrey Stedfast <fejj@ximian.com>
+ *
+ * Copyright 2004 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+#ifndef __E_SIGNATURE_LIST__
+#define __E_SIGNATURE_LIST__
+
+#include <e-util/e-list.h>
+#include <e-util/e-signature.h>
+
+#include <gconf/gconf-client.h>
+
+#define E_TYPE_SIGNATURE_LIST (e_signature_list_get_type ())
+#define E_SIGNATURE_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SIGNATURE_LIST, ESignatureList))
+#define E_SIGNATURE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_SIGNATURE_LIST, ESignatureListClass))
+#define E_IS_SIGNATURE_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SIGNATURE_LIST))
+#define E_IS_SIGNATURE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_SIGNATURE_LIST))
+
+typedef struct _ESignatureList ESignatureList;
+typedef struct _ESignatureListClass ESignatureListClass;
+
+/* search options for the find command */
+typedef enum {
+ E_SIGNATURE_FIND_NAME,
+ E_SIGNATURE_FIND_UID,
+} e_signature_find_t;
+
+struct _ESignatureList {
+ EList parent_object;
+
+ struct _ESignatureListPrivate *priv;
+};
+
+struct _ESignatureListClass {
+ EListClass parent_class;
+
+ /* signals */
+ void (* signature_added) (ESignatureList *, ESignature *);
+ void (* signature_changed) (ESignatureList *, ESignature *);
+ void (* signature_removed) (ESignatureList *, ESignature *);
+};
+
+
+GType e_signature_list_get_type (void);
+
+ESignatureList *e_signature_list_new (GConfClient *gconf);
+void e_signature_list_construct (ESignatureList *signature_list, GConfClient *gconf);
+
+void e_signature_list_save (ESignatureList *signature_list);
+
+void e_signature_list_add (ESignatureList *, ESignature *);
+void e_signature_list_change (ESignatureList *, ESignature *);
+void e_signature_list_remove (ESignatureList *, ESignature *);
+
+const ESignature *e_signature_list_find (ESignatureList *, e_signature_find_t type, const char *key);
+
+#endif /* __E_SIGNATURE_LIST__ */
diff --git a/e-util/e-signature.c b/e-util/e-signature.c
new file mode 100644
index 0000000000..6f34472c65
--- /dev/null
+++ b/e-util/e-signature.c
@@ -0,0 +1,363 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Jeffrey Stedfast <fejj@ximian.com>
+ *
+ * Copyright 2004 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <libxml/xmlmemory.h>
+
+#include <gconf/gconf-client.h>
+
+#include "e-uid.h"
+
+#include "e-signature.h"
+
+
+static void e_signature_class_init (ESignatureClass *klass);
+static void e_signature_init (ESignature *sig, ESignatureClass *klass);
+static void e_signature_finalize (GObject *object);
+
+
+static GObjectClass *parent_class = NULL;
+
+
+GType
+e_signature_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ GTypeInfo type_info = {
+ sizeof (ESignatureClass),
+ NULL, NULL,
+ (GClassInitFunc) e_signature_class_init,
+ NULL, NULL,
+ sizeof (ESignature),
+ 0,
+ (GInstanceInitFunc) e_signature_init,
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT, "ESignature", &type_info, 0);
+ }
+
+ return type;
+}
+
+static void
+e_signature_class_init (ESignatureClass *klass)
+{
+ GObjectClass *object_class = (GObjectClass *) klass;
+
+ parent_class = g_type_class_ref (G_TYPE_OBJECT);
+
+ /* virtual method override */
+ object_class->finalize = e_signature_finalize;
+}
+
+static void
+e_signature_init (ESignature *sig, ESignatureClass *klass)
+{
+ ;
+}
+
+static void
+e_signature_finalize (GObject *object)
+{
+ ESignature *sig = (ESignature *) object;
+
+ g_free (sig->uid);
+ g_free (sig->name);
+ g_free (sig->filename);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+/**
+ * e_signature_new:
+ *
+ * Returns a new signature which can be filled in and
+ * added to an #ESignatureList.
+ **/
+ESignature *
+e_signature_new (void)
+{
+ ESignature *signature;
+
+ signature = g_object_new (E_TYPE_SIGNATURE, NULL);
+ signature->uid = e_uid_new ();
+
+ return signature;
+}
+
+
+/**
+ * e_signature_new_from_xml:
+ * @xml: an XML signature description
+ *
+ * Return value: a new #ESignature based on the data in @xml, or %NULL
+ * if @xml could not be parsed as valid signature data.
+ **/
+ESignature *
+e_signature_new_from_xml (const char *xml)
+{
+ ESignature *signature;
+
+ signature = g_object_new (E_TYPE_SIGNATURE, NULL);
+ if (!e_signature_set_from_xml (signature, xml)) {
+ g_object_unref (signature);
+ return NULL;
+ }
+
+ return signature;
+}
+
+
+static gboolean
+xml_set_bool (xmlNodePtr node, const char *name, gboolean *val)
+{
+ gboolean bool;
+ char *buf;
+
+ if ((buf = xmlGetProp (node, name))) {
+ bool = (!strcmp (buf, "true") || !strcmp (buf, "yes"));
+ xmlFree (buf);
+
+ if (bool != *val) {
+ *val = bool;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
+xml_set_prop (xmlNodePtr node, const char *name, char **val)
+{
+ char *buf, *new_val;
+
+ buf = xmlGetProp (node, name);
+ new_val = g_strdup (buf);
+ xmlFree (buf);
+
+ /* We can use strcmp here whether the value is UTF8 or
+ * not, since we only care if the bytes changed.
+ */
+ if (!*val || strcmp (*val, new_val)) {
+ g_free (*val);
+ *val = new_val;
+ return TRUE;
+ } else {
+ g_free (new_val);
+ return FALSE;
+ }
+}
+
+static gboolean
+xml_set_content (xmlNodePtr node, char **val)
+{
+ char *buf, *new_val;
+
+ buf = xmlNodeGetContent (node);
+ new_val = g_strdup (buf);
+ xmlFree (buf);
+
+ /* We can use strcmp here whether the value is UTF8 or
+ * not, since we only care if the bytes changed.
+ */
+ if (!*val || strcmp (*val, new_val)) {
+ g_free (*val);
+ *val = new_val;
+ return TRUE;
+ } else {
+ g_free (new_val);
+ return FALSE;
+ }
+}
+
+
+/**
+ * e_signature_uid_from_xml:
+ * @xml: an XML signature description
+ *
+ * Return value: the permanent UID of the signature described by @xml
+ * (or %NULL if @xml could not be parsed or did not contain a uid).
+ * The caller must free this string.
+ **/
+char *
+e_signature_uid_from_xml (const char *xml)
+{
+ xmlNodePtr node;
+ xmlDocPtr doc;
+ char *uid = NULL;
+
+ if (!(doc = xmlParseDoc ((char *) xml)))
+ return NULL;
+
+ node = doc->children;
+ if (strcmp (node->name, "signature") != 0) {
+ xmlFreeDoc (doc);
+ return NULL;
+ }
+
+ xml_set_prop (node, "uid", &uid);
+ xmlFreeDoc (doc);
+
+ return uid;
+}
+
+
+/**
+ * e_signature_set_from_xml:
+ * @signature: an #ESignature
+ * @xml: an XML signature description.
+ *
+ * Changes @signature to match @xml.
+ *
+ * Returns %TRUE if the signature was loaded or %FALSE otherwise.
+ **/
+gboolean
+e_signature_set_from_xml (ESignature *signature, const char *xml)
+{
+ gboolean changed = FALSE;
+ xmlNodePtr node, cur;
+ xmlDocPtr doc;
+ gboolean bool;
+ char *buf;
+
+ if (!(doc = xmlParseDoc ((char *) xml)))
+ return FALSE;
+
+ node = doc->children;
+ if (strcmp (node->name, "signature") != 0) {
+ xmlFreeDoc (doc);
+ return FALSE;
+ }
+
+ if (!signature->uid)
+ xml_set_prop (node, "uid", &signature->uid);
+
+ changed |= xml_set_prop (node, "name", &signature->name);
+ changed |= xml_set_bool (node, "auto", &signature->autogen);
+
+ if (signature->autogen) {
+ /* we're done */
+ g_free (signature->filename);
+ signature->filename = NULL;
+ signature->script = FALSE;
+ signature->html = FALSE;
+ xmlFreeDoc (doc);
+
+ return changed;
+ }
+
+ buf = NULL;
+ xml_set_prop (node, "format", &buf);
+ if (buf && !strcmp (buf, "text/html"))
+ bool = TRUE;
+ else
+ bool = FALSE;
+ g_free (buf);
+
+ if (signature->html != bool) {
+ signature->html = bool;
+ changed = TRUE;
+ }
+
+ cur = node->children;
+ while (cur) {
+ if (!strcmp (cur->name, "filename")) {
+ changed |= xml_set_content (cur, &signature->filename);
+ changed |= xml_set_bool (cur, "script", &signature->script);
+ break;
+ } else if (!strcmp (cur->name, "script")) {
+ /* this is for handling 1.4 signature script definitions */
+ changed |= xml_set_content (cur, &signature->filename);
+ if (!signature->script) {
+ signature->script = TRUE;
+ changed = TRUE;
+ }
+ break;
+ }
+
+ cur = cur->next;
+ }
+
+ xmlFreeDoc (doc);
+
+ return changed;
+}
+
+
+/**
+ * e_signature_to_xml:
+ * @signature: an #ESignature
+ *
+ * Return value: an XML representation of @signature, which the caller
+ * must free.
+ **/
+char *
+e_signature_to_xml (ESignature *signature)
+{
+ char *xmlbuf, *tmp;
+ xmlNodePtr root, node;
+ xmlDocPtr doc;
+ int n;
+
+ doc = xmlNewDoc ("1.0");
+
+ root = xmlNewDocNode (doc, NULL, "signature", NULL);
+ xmlDocSetRootElement (doc, root);
+
+ xmlSetProp (root, "name", signature->name);
+ xmlSetProp (root, "uid", signature->uid);
+ xmlSetProp (root, "auto", signature->autogen ? "true" : "false");
+
+ if (!signature->autogen) {
+ xmlSetProp (root, "format", signature->html ? "text/html" : "text/plain");
+
+ if (signature->filename) {
+ node = xmlNewTextChild (root, NULL, "filename", signature->filename);
+ if (signature->script)
+ xmlSetProp (node, "script", "true");
+ }
+ }
+
+ xmlDocDumpMemory (doc, (xmlChar **) &xmlbuf, &n);
+ xmlFreeDoc (doc);
+
+ /* remap to glib memory */
+ tmp = g_malloc (n + 1);
+ memcpy (tmp, xmlbuf, n);
+ tmp[n] = '\0';
+ xmlFree (xmlbuf);
+
+ return tmp;
+}
+
diff --git a/e-util/e-signature.h b/e-util/e-signature.h
new file mode 100644
index 0000000000..b30b475c1a
--- /dev/null
+++ b/e-util/e-signature.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Jeffrey Stedfast <fejj@ximian.com>
+ *
+ * Copyright 2004 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+#ifndef __E_SIGNATURE_H__
+#define __E_SIGNATURE_H__
+
+#include <glib-object.h>
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+#define E_TYPE_SIGNATURE (e_signature_get_type ())
+#define E_SIGNATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SIGNATURE, ESignature))
+#define E_SIGNATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_SIGNATURE, ESignatureClass))
+#define E_IS_SIGNATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SIGNATURE))
+#define E_IS_SIGNATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_SIGNATURE))
+
+typedef struct _ESignature ESignature;
+typedef struct _ESignatureClass ESignatureClass;
+
+struct _ESignature {
+ GObject parent_object;
+
+ gboolean autogen;
+ gboolean script;
+ gboolean html;
+
+ char *filename;
+ char *name;
+ char *uid;
+};
+
+struct _ESignatureClass {
+ GObjectClass parent_class;
+
+};
+
+
+GType e_signature_get_type (void);
+
+ESignature *e_signature_new (void);
+ESignature *e_signature_new_from_xml (const char *xml);
+
+char *e_signature_uid_from_xml (const char *xml);
+
+gboolean e_signature_set_from_xml (ESignature *sig, const char *xml);
+
+char *e_signature_to_xml (ESignature *sig);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __E_SIGNATURE_H__ */