aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-08-07 05:48:45 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-08-07 06:42:42 +0800
commit740af34bdf59229f5c63b30b5cca6264672f6707 (patch)
tree153c02805da8ade80f8e0934fcdd529f20d8d4be
parentba5c9e6f8046f76ffda4a1871d1287f9834d1211 (diff)
downloadgsoc2013-evolution-740af34bdf59229f5c63b30b5cca6264672f6707.tar.gz
gsoc2013-evolution-740af34bdf59229f5c63b30b5cca6264672f6707.tar.zst
gsoc2013-evolution-740af34bdf59229f5c63b30b5cca6264672f6707.zip
Seal up ESignature and add GObject properties.
-rw-r--r--composer/e-msg-composer.c29
-rw-r--r--e-util/e-signature-list.c42
-rw-r--r--e-util/e-signature.c631
-rw-r--r--e-util/e-signature.h84
-rw-r--r--mail/em-account-editor.c26
-rw-r--r--mail/em-composer-prefs.c54
-rw-r--r--mail/em-migrate.c2
-rw-r--r--mail/mail-config.c28
-rw-r--r--mail/mail-signature-editor.c20
-rw-r--r--widgets/misc/e-signature-combo-box.c6
10 files changed, 679 insertions, 243 deletions
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index d7d9c034c0..926553fdff 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1017,13 +1017,16 @@ e_msg_composer_get_sig_file_content (const gchar *sigfile, gboolean in_html)
}
static gchar *
-encode_signature_name (const gchar *name)
+encode_signature_uid (ESignature *signature)
{
+ const gchar *uid;
const gchar *s;
gchar *ename, *e;
gint len = 0;
- s = name;
+ uid = e_signature_get_uid (signature);
+
+ s = uid;
while (*s) {
len ++;
if (*s == '"' || *s == '.' || *s == '=')
@@ -1033,7 +1036,7 @@ encode_signature_name (const gchar *name)
ename = g_new (gchar, len + 1);
- s = name;
+ s = uid;
e = ename;
while (*s) {
if (*s == '"') {
@@ -1155,17 +1158,19 @@ get_signature_html (EMsgComposer *composer)
add_delim = add_signature_delim ();
- if (!signature->autogen) {
- if (!signature->filename)
+ if (!e_signature_get_autogenerated (signature)) {
+ const gchar *filename;
+
+ filename = e_signature_get_filename (signature);
+ if (filename == NULL)
return NULL;
- format_html = signature->html;
+ format_html = e_signature_get_is_html (signature);
- if (signature->script) {
- text = mail_config_signature_run_script (signature->filename);
- } else {
- text = e_msg_composer_get_sig_file_content (signature->filename, format_html);
- }
+ if (e_signature_get_is_script (signature))
+ text = mail_config_signature_run_script (filename);
+ else
+ text = e_msg_composer_get_sig_file_content (filename, format_html);
} else {
EAccount *account;
EAccountIdentity *id;
@@ -1203,7 +1208,7 @@ get_signature_html (EMsgComposer *composer)
gchar *encoded_uid = NULL;
if (signature)
- encoded_uid = encode_signature_name (signature->uid);
+ encoded_uid = encode_signature_uid (signature);
/* The signature dash convention ("-- \n") is specified in the
* "Son of RFC 1036": http://www.chemie.fu-berlin.de/outerspace/netnews/son-of-1036.html,
diff --git a/e-util/e-signature-list.c b/e-util/e-signature-list.c
index 094d4785da..3fd4f8ab15 100644
--- a/e-util/e-signature-list.c
+++ b/e-util/e-signature-list.c
@@ -153,8 +153,7 @@ add_autogen (ESignatureList *list, GSList *new_sigs)
ESignature *autogen;
autogen = e_signature_new ();
- autogen->name = g_strdup ("Autogenerated");
- autogen->autogen = TRUE;
+ e_signature_set_autogenerated (autogen, TRUE);
e_list_append (E_LIST (list), autogen);
@@ -182,8 +181,11 @@ gconf_signatures_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry,
if ((uid = e_signature_uid_from_xml (l->data))) {
/* See if this is an existing signature */
for (iter = e_list_get_iterator (old_sigs); e_iterator_is_valid (iter); e_iterator_next (iter)) {
+ const gchar *signature_uid;
+
signature = (ESignature *) e_iterator_get (iter);
- if (!strcmp (signature->uid, uid)) {
+ signature_uid = e_signature_get_uid (signature);
+ if (!strcmp (signature_uid, uid)) {
/* The signature still exists, so remove
* it from "old_sigs" and update it.
*/
@@ -192,7 +194,7 @@ gconf_signatures_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry,
if (e_signature_set_from_xml (signature, l->data))
g_signal_emit (signature_list, signals[SIGNATURE_CHANGED], 0, signature);
- have_autogen |= signature->autogen;
+ have_autogen |= e_signature_get_autogenerated (signature);
break;
}
@@ -204,11 +206,8 @@ gconf_signatures_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry,
if (!found) {
/* Must be a new signature */
signature = e_signature_new_from_xml (l->data);
- have_autogen |= signature->autogen;
- if (!signature->uid) {
- signature->uid = e_uid_new ();
- resave = TRUE;
- }
+ have_autogen |= e_signature_get_autogenerated (signature);
+ resave = TRUE;
e_list_append (E_LIST (signature_list), signature);
new_sigs = g_slist_prepend (new_sigs, signature);
@@ -422,9 +421,11 @@ e_signature_list_remove (ESignatureList *signatures, ESignature *signature)
* 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 gchar *key)
+e_signature_list_find (ESignatureList *signatures,
+ e_signature_find_t type,
+ const gchar *key)
{
- const ESignature *signature = NULL;
+ ESignature *signature = NULL;
EIterator *it;
/* this could use a callback for more flexibility ...
@@ -436,20 +437,21 @@ e_signature_list_find (ESignatureList *signatures, e_signature_find_t type, cons
for (it = e_list_get_iterator ((EList *) signatures);
e_iterator_is_valid (it);
e_iterator_next (it)) {
- gint found = 0;
+ const gchar *value;
- signature = (const ESignature *) e_iterator_get (it);
+ /* XXX EIterator misuses const. */
+ signature = (ESignature *) e_iterator_get (it);
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;
+ case E_SIGNATURE_FIND_NAME:
+ value = e_signature_get_name (signature);
+ break;
+ case E_SIGNATURE_FIND_UID:
+ value = e_signature_get_uid (signature);
+ break;
}
- if (found)
+ if (g_strcmp0 (value, key) == 0)
break;
signature = NULL;
diff --git a/e-util/e-signature.c b/e-util/e-signature.c
index 86e29fe34a..1b22dbafa0 100644
--- a/e-util/e-signature.c
+++ b/e-util/e-signature.c
@@ -14,9 +14,6 @@
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*
- * Authors:
- * Jeffrey Stedfast <fejj@ximian.com>
- *
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
@@ -31,69 +28,327 @@
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
+#include <glib/gi18n-lib.h>
#include <gconf/gconf-client.h>
#include <libedataserver/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);
+#define E_SIGNATURE_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_SIGNATURE, ESignaturePrivate))
-static GObjectClass *parent_class = NULL;
+struct _ESignaturePrivate {
+ gchar *filename;
+ gchar *name;
+ gchar *uid;
-GType
-e_signature_get_type (void)
+ gboolean autogenerated;
+ gboolean is_html;
+ gboolean is_script;
+};
+
+enum {
+ PROP_0,
+ PROP_AUTOGENERATED,
+ PROP_FILENAME,
+ PROP_IS_HTML,
+ PROP_IS_SCRIPT,
+ PROP_NAME,
+ PROP_UID
+};
+
+static gpointer parent_class;
+
+static gboolean
+xml_set_bool (xmlNodePtr node,
+ const gchar *name,
+ gboolean *val)
{
- static GType type = 0;
+ gboolean v_boolean;
+ gchar *buf;
- if (!type) {
- GTypeInfo type_info = {
- sizeof (ESignatureClass),
- NULL, NULL,
- (GClassInitFunc) e_signature_class_init,
- NULL, NULL,
- sizeof (ESignature),
- 0,
- (GInstanceInitFunc) e_signature_init,
- };
+ if ((buf = (gchar *)xmlGetProp (node, (xmlChar *) name))) {
+ v_boolean = (!strcmp (buf, "true") || !strcmp (buf, "yes"));
+ xmlFree (buf);
- type = g_type_register_static (G_TYPE_OBJECT, "ESignature", &type_info, 0);
+ if (v_boolean != *val) {
+ *val = v_boolean;
+ return TRUE;
+ }
}
- return type;
+ return FALSE;
}
-static void
-e_signature_class_init (ESignatureClass *klass)
+static gboolean
+xml_set_prop (xmlNodePtr node,
+ const gchar *name,
+ gchar **val)
+{
+ gchar *buf, *new_val;
+
+ buf = (gchar *)xmlGetProp (node, (xmlChar *) 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,
+ gchar **val)
{
- GObjectClass *object_class = (GObjectClass *) klass;
+ gchar *buf, *new_val;
- parent_class = g_type_class_ref (G_TYPE_OBJECT);
+ buf = (gchar *)xmlNodeGetContent (node);
+ new_val = g_strdup (buf);
+ xmlFree (buf);
- /* virtual method override */
- object_class->finalize = e_signature_finalize;
+ /* 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 void
-e_signature_init (ESignature *sig, ESignatureClass *klass)
+signature_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- ;
+ switch (property_id) {
+ case PROP_AUTOGENERATED:
+ e_signature_set_autogenerated (
+ E_SIGNATURE (object),
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_FILENAME:
+ e_signature_set_filename (
+ E_SIGNATURE (object),
+ g_value_get_string (value));
+ return;
+
+ case PROP_IS_HTML:
+ e_signature_set_is_html (
+ E_SIGNATURE (object),
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_IS_SCRIPT:
+ e_signature_set_is_script (
+ E_SIGNATURE (object),
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_NAME:
+ e_signature_set_name (
+ E_SIGNATURE (object),
+ g_value_get_string (value));
+ return;
+
+ case PROP_UID:
+ e_signature_set_uid (
+ E_SIGNATURE (object),
+ g_value_get_string (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+signature_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_AUTOGENERATED:
+ g_value_set_boolean (
+ value, e_signature_get_autogenerated (
+ E_SIGNATURE (object)));
+ return;
+
+ case PROP_FILENAME:
+ g_value_set_string (
+ value, e_signature_get_filename (
+ E_SIGNATURE (object)));
+ return;
+
+ case PROP_IS_HTML:
+ g_value_set_boolean (
+ value, e_signature_get_is_html (
+ E_SIGNATURE (object)));
+ return;
+
+ case PROP_IS_SCRIPT:
+ g_value_set_boolean (
+ value, e_signature_get_is_script (
+ E_SIGNATURE (object)));
+ return;
+
+ case PROP_NAME:
+ g_value_set_string (
+ value, e_signature_get_name (
+ E_SIGNATURE (object)));
+ return;
+
+ case PROP_UID:
+ g_value_set_string (
+ value, e_signature_get_uid (
+ E_SIGNATURE (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
-e_signature_finalize (GObject *object)
+signature_finalize (GObject *object)
{
- ESignature *sig = (ESignature *) object;
+ ESignaturePrivate *priv;
- g_free (sig->uid);
- g_free (sig->name);
- g_free (sig->filename);
+ priv = E_SIGNATURE_GET_PRIVATE (object);
+ g_free (priv->filename);
+ g_free (priv->name);
+ g_free (priv->uid);
+
+ /* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (parent_class)->finalize (object);
}
+static void
+e_signature_class_init (ESignatureClass *class)
+{
+ GObjectClass *object_class;
+
+ parent_class = g_type_class_peek_parent (class);
+ g_type_class_add_private (class, sizeof (ESignaturePrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = signature_set_property;
+ object_class->get_property = signature_get_property;
+ object_class->finalize = signature_finalize;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_AUTOGENERATED,
+ g_param_spec_boolean (
+ "autogenerated",
+ "Autogenerated",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_FILENAME,
+ g_param_spec_string (
+ "filename",
+ "Filename",
+ NULL,
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_IS_HTML,
+ g_param_spec_boolean (
+ "is-html",
+ "Is HTML",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_IS_SCRIPT,
+ g_param_spec_boolean (
+ "is-script",
+ "Is Script",
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_NAME,
+ g_param_spec_string (
+ "name",
+ "Name",
+ NULL,
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_UID,
+ g_param_spec_string (
+ "uid",
+ "UID",
+ NULL,
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
+}
+
+static void
+e_signature_init (ESignature *signature)
+{
+ signature->priv = E_SIGNATURE_GET_PRIVATE (signature);
+}
+
+GType
+e_signature_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ GTypeInfo type_info = {
+ sizeof (ESignatureClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) e_signature_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (ESignature),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) e_signature_init,
+ NULL /* value_table */
+ };
+
+ type = g_type_register_static (
+ G_TYPE_OBJECT, "ESignature", &type_info, 0);
+ }
+
+ return type;
+}
+
/**
* e_signature_new:
*
@@ -106,7 +361,7 @@ e_signature_new (void)
ESignature *signature;
signature = g_object_new (E_TYPE_SIGNATURE, NULL);
- signature->uid = e_uid_new ();
+ signature->priv->uid = e_uid_new ();
return signature;
}
@@ -124,6 +379,7 @@ e_signature_new_from_xml (const gchar *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;
@@ -132,69 +388,6 @@ e_signature_new_from_xml (const gchar *xml)
return signature;
}
-static gboolean
-xml_set_bool (xmlNodePtr node, const gchar *name, gboolean *val)
-{
- gboolean bool;
- gchar *buf;
-
- if ((buf = (gchar *)xmlGetProp (node, (const guchar *)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 gchar *name, gchar **val)
-{
- gchar *buf, *new_val;
-
- buf = (gchar *)xmlGetProp (node, (const guchar *)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, gchar **val)
-{
- gchar *buf, *new_val;
-
- buf = (gchar *)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
@@ -210,7 +403,7 @@ e_signature_uid_from_xml (const gchar *xml)
xmlDocPtr doc;
gchar *uid = NULL;
- if (!(doc = xmlParseDoc ((guchar *) xml)))
+ if (!(doc = xmlParseDoc ((xmlChar *) xml)))
return NULL;
node = doc->children;
@@ -243,7 +436,7 @@ e_signature_set_from_xml (ESignature *signature, const gchar *xml)
gboolean bool;
gchar *buf;
- if (!(doc = xmlParseDoc ((guchar *) xml)))
+ if (!(doc = xmlParseDoc ((xmlChar *) xml)))
return FALSE;
node = doc->children;
@@ -252,18 +445,13 @@ e_signature_set_from_xml (ESignature *signature, const gchar *xml)
return FALSE;
}
- if (!signature->uid)
- xml_set_prop (node, "uid", &signature->uid);
+ if (!signature->priv->uid)
+ xml_set_prop (node, "uid", &signature->priv->uid);
- changed |= xml_set_prop (node, "name", &signature->name);
- changed |= xml_set_bool (node, "auto", &signature->autogen);
+ changed |= xml_set_prop (node, "name", &signature->priv->name);
+ changed |= xml_set_bool (node, "auto", &signature->priv->autogenerated);
- if (signature->autogen) {
- /* we're done */
- g_free (signature->filename);
- signature->filename = NULL;
- signature->script = FALSE;
- signature->html = FALSE;
+ if (e_signature_get_autogenerated (signature)) {
xmlFreeDoc (doc);
return changed;
@@ -277,22 +465,22 @@ e_signature_set_from_xml (ESignature *signature, const gchar *xml)
bool = FALSE;
g_free (buf);
- if (signature->html != bool) {
- signature->html = bool;
+ if (e_signature_get_is_html (signature) != bool) {
+ e_signature_set_is_html (signature, bool);
changed = TRUE;
}
cur = node->children;
while (cur) {
if (!strcmp ((gchar *)cur->name, "filename")) {
- changed |= xml_set_content (cur, &signature->filename);
- changed |= xml_set_bool (cur, "script", &signature->script);
+ changed |= xml_set_content (cur, &signature->priv->filename);
+ changed |= xml_set_bool (cur, "script", &signature->priv->is_script);
break;
} else if (!strcmp ((gchar *)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 |= xml_set_content (cur, &signature->priv->filename);
+ if (!e_signature_get_is_script (signature)) {
+ e_signature_set_is_script (signature, TRUE);
changed = TRUE;
}
break;
@@ -320,28 +508,42 @@ e_signature_to_xml (ESignature *signature)
gchar *tmp;
xmlNodePtr root, node;
xmlDocPtr doc;
+ const gchar *string;
gint n;
- doc = xmlNewDoc ((const guchar *)"1.0");
+ doc = xmlNewDoc ((xmlChar *) "1.0");
- root = xmlNewDocNode (doc, NULL, (const guchar *)"signature", NULL);
+ root = xmlNewDocNode (doc, NULL, (xmlChar *) "signature", NULL);
xmlDocSetRootElement (doc, root);
- xmlSetProp (root, (const guchar *)"name", (guchar *)signature->name);
- xmlSetProp (root, (const guchar *)"uid", (guchar *)signature->uid);
- xmlSetProp (root, (const guchar *)"auto", (const guchar *)(signature->autogen ? "true" : "false"));
+ string = e_signature_get_name (signature);
+ xmlSetProp (root, (xmlChar *) "name", (xmlChar *) string);
- if (!signature->autogen) {
- xmlSetProp (root, (const guchar *)"format", (const guchar *)(signature->html ? "text/html" : "text/plain"));
+ string = e_signature_get_uid (signature);
+ xmlSetProp (root, (xmlChar *) "uid", (xmlChar *) string);
- if (signature->filename) {
- node = xmlNewTextChild (root, NULL, (const guchar *)"filename", (guchar *)signature->filename);
- if (signature->script)
- xmlSetProp (node, (const guchar *)"script", (const guchar *)"true");
+ if (e_signature_get_autogenerated (signature))
+ string = "true";
+ else
+ string = "false";
+ xmlSetProp (root, (xmlChar *) "auto", (xmlChar *) string);
+
+ if (!e_signature_get_autogenerated (signature)) {
+ if (e_signature_get_is_html (signature))
+ string = "text/html";
+ else
+ string = "text/plain";
+ xmlSetProp (root, (xmlChar *) "format", (xmlChar *) string);
+
+ string = e_signature_get_filename (signature);
+ if (string != NULL) {
+ node = xmlNewTextChild (root, NULL, (xmlChar *) "filename", (xmlChar *) string);
+ if (e_signature_get_is_script (signature))
+ xmlSetProp (node, (xmlChar *) "script", (xmlChar *) "true");
}
} else {
/* this is to make Evolution-1.4 and older 1.5 versions happy */
- xmlSetProp (root, (const guchar *)"format", (const guchar *)"text/html");
+ xmlSetProp (root, (xmlChar *) "format", (xmlChar *) "text/html");
}
xmlDocDumpMemory (doc, &xmlbuf, &n);
@@ -356,3 +558,172 @@ e_signature_to_xml (ESignature *signature)
return tmp;
}
+gboolean
+e_signature_is_equal (ESignature *signature1,
+ ESignature *signature2)
+{
+ const gchar *uid1;
+ const gchar *uid2;
+
+ g_return_val_if_fail (E_IS_SIGNATURE (signature1), FALSE);
+ g_return_val_if_fail (E_IS_SIGNATURE (signature2), FALSE);
+
+ /* XXX Simply compares the UIDs. Not fool-proof. */
+ uid1 = e_signature_get_uid (signature1);
+ uid2 = e_signature_get_uid (signature2);
+
+ return (g_strcmp0 (uid1, uid2) == 0);
+}
+
+gboolean
+e_signature_get_autogenerated (ESignature *signature)
+{
+ g_return_val_if_fail (E_IS_SIGNATURE (signature), FALSE);
+
+ return signature->priv->autogenerated;
+}
+
+void
+e_signature_set_autogenerated (ESignature *signature,
+ gboolean autogenerated)
+{
+ g_return_if_fail (E_IS_SIGNATURE (signature));
+
+ if (signature->priv->autogenerated == autogenerated)
+ return;
+
+ signature->priv->autogenerated = autogenerated;
+
+ /* Autogenerated flags overrides several properties. */
+ g_object_freeze_notify (G_OBJECT (signature));
+ g_object_notify (G_OBJECT (signature), "autogenerated");
+ g_object_notify (G_OBJECT (signature), "filename");
+ g_object_notify (G_OBJECT (signature), "is-html");
+ g_object_notify (G_OBJECT (signature), "is-script");
+ g_object_notify (G_OBJECT (signature), "name");
+ g_object_thaw_notify (G_OBJECT (signature));
+}
+
+const gchar *
+e_signature_get_filename (ESignature *signature)
+{
+ g_return_val_if_fail (E_IS_SIGNATURE (signature), NULL);
+
+ /* Autogenerated flags overrides the filename property. */
+ if (e_signature_get_autogenerated (signature))
+ return NULL;
+
+ return signature->priv->filename;
+}
+
+void
+e_signature_set_filename (ESignature *signature,
+ const gchar *filename)
+{
+ g_return_if_fail (E_IS_SIGNATURE (signature));
+
+ g_free (signature->priv->filename);
+ signature->priv->filename = g_strdup (filename);
+
+ g_object_notify (G_OBJECT (signature), "filename");
+}
+
+gboolean
+e_signature_get_is_html (ESignature *signature)
+{
+ g_return_val_if_fail (E_IS_SIGNATURE (signature), FALSE);
+
+ /* Autogenerated flag overrides the is-html property. */
+ if (e_signature_get_autogenerated (signature))
+ return FALSE;
+
+ return signature->priv->is_html;
+}
+
+void
+e_signature_set_is_html (ESignature *signature,
+ gboolean is_html)
+{
+ g_return_if_fail (E_IS_SIGNATURE (signature));
+
+ if (signature->priv->is_html == is_html)
+ return;
+
+ signature->priv->is_html = is_html;
+
+ g_object_notify (G_OBJECT (signature), "is-html");
+}
+
+gboolean
+e_signature_get_is_script (ESignature *signature)
+{
+ g_return_val_if_fail (E_IS_SIGNATURE (signature), FALSE);
+
+ /* Autogenerated flags overrides the is-script property. */
+ if (e_signature_get_autogenerated (signature))
+ return FALSE;
+
+ return signature->priv->is_script;
+}
+
+void
+e_signature_set_is_script (ESignature *signature,
+ gboolean is_script)
+{
+ g_return_if_fail (E_IS_SIGNATURE (signature));
+
+ if (signature->priv->is_script == is_script)
+ return;
+
+ signature->priv->is_script = is_script;
+
+ g_object_notify (G_OBJECT (signature), "is-script");
+}
+
+const gchar *
+e_signature_get_name (ESignature *signature)
+{
+ g_return_val_if_fail (E_IS_SIGNATURE (signature), NULL);
+
+ /* Autogenerated flag overrides the name property. */
+ if (e_signature_get_autogenerated (signature))
+ return _("Autogenerated");
+
+ return signature->priv->name;
+}
+
+void
+e_signature_set_name (ESignature *signature,
+ const gchar *name)
+{
+ g_return_if_fail (E_IS_SIGNATURE (signature));
+
+ g_free (signature->priv->name);
+ signature->priv->name = g_strdup (name);
+
+ g_object_notify (G_OBJECT (signature), "name");
+}
+
+const gchar *
+e_signature_get_uid (ESignature *signature)
+{
+ g_return_val_if_fail (E_IS_SIGNATURE (signature), NULL);
+
+ return signature->priv->uid;
+}
+
+void
+e_signature_set_uid (ESignature *signature,
+ const gchar *uid)
+{
+ g_return_if_fail (E_IS_SIGNATURE (signature));
+
+ g_free (signature->priv->uid);
+
+ if (uid == NULL)
+ signature->priv->uid = e_uid_new ();
+ else
+ signature->priv->uid = g_strdup (uid);
+
+ g_object_notify (G_OBJECT (signature), "uid");
+}
diff --git a/e-util/e-signature.h b/e-util/e-signature.h
index 3dced1903d..fad1faffa3 100644
--- a/e-util/e-signature.h
+++ b/e-util/e-signature.h
@@ -14,57 +14,77 @@
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*
- * Authors:
- * Jeffrey Stedfast <fejj@ximian.com>
- *
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
-#ifndef __E_SIGNATURE_H__
-#define __E_SIGNATURE_H__
+#ifndef E_SIGNATURE_H
+#define E_SIGNATURE_H
#include <glib-object.h>
-G_BEGIN_DECLS
+/* Standard GObject macros */
+#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(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_SIGNATURE, ESignatureClass))
+#define E_IS_SIGNATURE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_SIGNATURE))
+#define E_IS_SIGNATURE_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_SIGNATURE))
+#define E_SIGNATURE_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_SIGNATURE, ESignatureClass))
-#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))
+G_BEGIN_DECLS
typedef struct _ESignature ESignature;
typedef struct _ESignatureClass ESignatureClass;
+typedef struct _ESignaturePrivate ESignaturePrivate;
struct _ESignature {
- GObject parent_object;
-
- gboolean autogen;
- gboolean script;
- gboolean html;
-
- gchar *filename;
- gchar *name;
- gchar *uid;
+ GObject parent;
+ ESignaturePrivate *priv;
};
struct _ESignatureClass {
GObjectClass parent_class;
-
};
-GType e_signature_get_type (void);
-
-ESignature *e_signature_new (void);
-ESignature *e_signature_new_from_xml (const gchar *xml);
-
-gchar *e_signature_uid_from_xml (const gchar *xml);
-
-gboolean e_signature_set_from_xml (ESignature *sig, const gchar *xml);
-
-gchar *e_signature_to_xml (ESignature *sig);
+GType e_signature_get_type (void);
+ESignature * e_signature_new (void);
+ESignature * e_signature_new_from_xml (const gchar *xml);
+gchar * e_signature_uid_from_xml (const gchar *xml);
+gboolean e_signature_set_from_xml (ESignature *signature,
+ const gchar *xml);
+gchar * e_signature_to_xml (ESignature *signature);
+gboolean e_signature_is_equal (ESignature *signature1,
+ ESignature *signature2);
+gboolean e_signature_get_autogenerated (ESignature *signature);
+void e_signature_set_autogenerated (ESignature *signature,
+ gboolean autogenerated);
+const gchar * e_signature_get_filename (ESignature *signature);
+void e_signature_set_filename (ESignature *signature,
+ const gchar *filename);
+gboolean e_signature_get_is_html (ESignature *signature);
+void e_signature_set_is_html (ESignature *signature,
+ gboolean is_html);
+gboolean e_signature_get_is_script (ESignature *signature);
+void e_signature_set_is_script (ESignature *signature,
+ gboolean is_script);
+const gchar * e_signature_get_name (ESignature *signature);
+void e_signature_set_name (ESignature *signature,
+ const gchar *name);
+const gchar * e_signature_get_uid (ESignature *signature);
+void e_signature_set_uid (ESignature *signature,
+ const gchar *uid);
G_END_DECLS
-#endif /* __E_SIGNATURE_H__ */
+#endif /* E_SIGNATURE_H */
diff --git a/mail/em-account-editor.c b/mail/em-account-editor.c
index 21650d0624..dceaec5bb3 100644
--- a/mail/em-account-editor.c
+++ b/mail/em-account-editor.c
@@ -604,11 +604,16 @@ emae_signature_added (ESignatureList *signatures, ESignature *sig, EMAccountEdit
{
GtkTreeModel *model;
GtkTreeIter iter;
+ const gchar *name;
+ const gchar *uid;
+
+ name = e_signature_get_name (sig);
+ uid = e_signature_get_uid (sig);
model = gtk_combo_box_get_model (emae->priv->signatures_dropdown);
gtk_list_store_append ((GtkListStore *)model, &iter);
- gtk_list_store_set ((GtkListStore *)model, &iter, 0, sig->autogen?_("Autogenerated"):sig->name, 1, sig->uid, -1);
+ gtk_list_store_set ((GtkListStore *)model, &iter, 0, name, 1, uid, -1);
gtk_combo_box_set_active (emae->priv->signatures_dropdown, gtk_tree_model_iter_n_children (model, NULL)-1);
}
@@ -625,10 +630,13 @@ emae_signature_get_iter (EMAccountEditor *emae, ESignature *sig, GtkTreeModel **
return FALSE;
do {
+ const gchar *signature_uid;
gchar *uid;
+ signature_uid = e_signature_get_uid (sig);
+
gtk_tree_model_get (model, iter, 1, &uid, -1);
- if (uid && !strcmp (uid, sig->uid))
+ if (uid && !strcmp (uid, signature_uid))
found = TRUE;
g_free (uid);
} while (!found && gtk_tree_model_iter_next (model, iter));
@@ -651,9 +659,12 @@ emae_signature_changed (ESignatureList *signatures, ESignature *sig, EMAccountEd
{
GtkTreeIter iter;
GtkTreeModel *model;
+ const gchar *name;
+
+ name = e_signature_get_name (sig);
if (emae_signature_get_iter (emae, sig, &model, &iter))
- gtk_list_store_set ((GtkListStore *)model, &iter, 0, sig->autogen?_("Autogenerated"):sig->name, -1);
+ gtk_list_store_set ((GtkListStore *)model, &iter, 0, name, -1);
}
static void
@@ -718,11 +729,16 @@ emae_setup_signatures (EMAccountEditor *emae, GladeXML *xml)
it = e_list_get_iterator ((EList *) signatures);
while (e_iterator_is_valid (it)) {
ESignature *sig = (ESignature *)e_iterator_get (it);
+ const gchar *name;
+ const gchar *uid;
+
+ name = e_signature_get_name (sig);
+ uid = e_signature_get_uid (sig);
gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, sig->autogen?_("Autogenerated"):sig->name, 1, sig->uid, -1);
+ gtk_list_store_set (store, &iter, 0, name, 1, uid, -1);
- if (current && !strcmp (current, sig->uid))
+ if (current && !strcmp (current, uid))
active = i;
e_iterator_next (it);
diff --git a/mail/em-composer-prefs.c b/mail/em-composer-prefs.c
index ab2bb2d8a4..0a7312e837 100644
--- a/mail/em-composer-prefs.c
+++ b/mail/em-composer-prefs.c
@@ -155,6 +155,8 @@ sig_load_preview (EMComposerPrefs *prefs,
{
GtkHTML *html;
gchar *str;
+ const gchar *filename;
+ gboolean is_html;
html = prefs->sig_preview;
@@ -163,20 +165,22 @@ sig_load_preview (EMComposerPrefs *prefs,
return;
}
- if (signature->script)
- str = mail_config_signature_run_script (signature->filename);
+ filename = e_signature_get_filename (signature);
+ is_html = e_signature_get_is_html (signature);
+
+ if (e_signature_get_is_script (signature))
+ str = mail_config_signature_run_script (filename);
else
- str = e_msg_composer_get_sig_file_content (
- signature->filename, signature->html);
+ str = e_msg_composer_get_sig_file_content (filename, is_html);
if (!str || !*str) {
/* make html stream happy and write at least one character */
g_free (str);
str = g_strdup (" ");
}
- if (signature->html) {
+ if (is_html)
gtk_html_load_from_string (html, str, strlen (str));
- } else {
+ else {
GtkHTMLStream *stream;
gint len;
@@ -201,16 +205,19 @@ signature_added (ESignatureList *signature_list,
GtkTreeModel *model;
GtkTreePath *path;
GtkTreeIter iter;
+ const gchar *name;
/* autogen signature is special */
- if (signature->autogen)
+ if (e_signature_get_autogenerated (signature))
return;
+ name = e_signature_get_name (signature);
+
model = gtk_tree_view_get_model (prefs->sig_list);
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (
GTK_LIST_STORE (model), &iter,
- 0, signature->name, 1, signature, -1);
+ 0, name, 1, signature, -1);
path = gtk_tree_model_get_path (model, &iter);
row = gtk_tree_row_reference_new (model, path);
@@ -255,6 +262,7 @@ signature_changed (ESignatureList *signature_list,
GtkTreePath *path;
GtkTreeIter iter;
ESignature *cur;
+ const gchar *name;
if (!(row = g_hash_table_lookup (prefs->sig_hash, signature)))
return;
@@ -269,7 +277,8 @@ signature_changed (ESignatureList *signature_list,
gtk_tree_path_free (path);
- gtk_list_store_set ((GtkListStore *) model, &iter, 0, signature->name, -1);
+ name = e_signature_get_name (signature);
+ gtk_list_store_set ((GtkListStore *) model, &iter, 0, name, -1);
selection = gtk_tree_view_get_selection (prefs->sig_list);
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
@@ -287,6 +296,8 @@ sig_edit_cb (GtkWidget *widget, EMComposerPrefs *prefs)
GtkWidget *parent;
GtkTreeIter iter;
ESignature *signature;
+ const gchar *filename;
+ const gchar *name;
selection = gtk_tree_view_get_selection (prefs->sig_list);
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
@@ -294,13 +305,18 @@ sig_edit_cb (GtkWidget *widget, EMComposerPrefs *prefs)
gtk_tree_model_get (model, &iter, 1, &signature, -1);
- if (!signature->script) {
+ filename = e_signature_get_filename (signature);
+ name = e_signature_get_name (signature);
+
+ if (!e_signature_get_is_script (signature)) {
GtkWidget *editor;
+ filename = e_signature_get_filename (signature);
+
/* normal signature */
- if (!signature->filename || *signature->filename == '\0') {
- g_free (signature->filename);
- signature->filename = g_strdup (_("Unnamed"));
+ if (filename == NULL || *filename == '\0') {
+ e_signature_set_filename (signature, _("Unnamed"));
+ filename = e_signature_get_filename (signature);
}
editor = e_signature_editor_new ();
@@ -318,10 +334,10 @@ sig_edit_cb (GtkWidget *widget, EMComposerPrefs *prefs)
GtkWidget *entry;
entry = glade_xml_get_widget (prefs->sig_script_gui, "filechooserbutton_add_script");
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (entry), signature->filename);
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (entry), filename);
entry = glade_xml_get_widget (prefs->sig_script_gui, "entry_add_script_name");
- gtk_entry_set_text (GTK_ENTRY (entry), signature->name);
+ gtk_entry_set_text (GTK_ENTRY (entry), name);
g_object_set_data ((GObject *) entry, "sig", signature);
@@ -397,14 +413,12 @@ sig_add_script_response (GtkWidget *widget, gint button, EMComposerPrefs *prefs)
if ((signature = g_object_get_data ((GObject *) entry, "sig"))) {
/* we're just editing an existing signature script */
- g_free (signature->name);
- signature->name = g_strdup (name);
- g_free(signature->filename);
- signature->filename = g_strdup(script);
+ e_signature_set_name (signature, name);
+ e_signature_set_filename (signature, script);
e_signature_list_change (mail_config_get_signatures (), signature);
} else {
signature = mail_config_signature_new (script, TRUE, TRUE);
- signature->name = g_strdup (name);
+ e_signature_set_name (signature, name);
e_signature_list_add (mail_config_get_signatures (), signature);
g_object_unref (signature);
diff --git a/mail/em-migrate.c b/mail/em-migrate.c
index fd59bafea9..b3888dc7c0 100644
--- a/mail/em-migrate.c
+++ b/mail/em-migrate.c
@@ -1916,7 +1916,7 @@ get_nth_sig (gint id)
if (i == id && e_iterator_is_valid (iter)) {
sig = (ESignature *) e_iterator_get (iter);
- uid = g_strdup (sig->uid);
+ uid = g_strdup (e_signature_get_uid (sig));
}
g_object_unref (iter);
diff --git a/mail/mail-config.c b/mail/mail-config.c
index 316957bf38..0c22f0036e 100644
--- a/mail/mail-config.c
+++ b/mail/mail-config.c
@@ -1157,14 +1157,18 @@ mail_config_signature_new (const gchar *filename, gboolean script, gboolean html
ESignature *sig;
sig = e_signature_new ();
- sig->name = g_strdup (_("Unnamed"));
- sig->script = script;
- sig->html = html;
+ e_signature_set_name (sig, _("Unnamed"));
+ e_signature_set_is_script (sig, script);
+ e_signature_set_is_html (sig, html);
- if (filename == NULL)
- sig->filename = get_new_signature_filename ();
- else
- sig->filename = g_strdup (filename);
+ if (filename == NULL) {
+ gchar *new_filename;
+
+ new_filename = get_new_signature_filename ();
+ e_signature_set_filename (sig, new_filename);
+ g_free (new_filename);
+ } else
+ e_signature_set_filaname (sig, filename);
return sig;
}
@@ -1191,8 +1195,14 @@ mail_config_add_signature (ESignature *signature)
void
mail_config_remove_signature (ESignature *signature)
{
- if (signature->filename && !signature->script)
- g_unlink (signature->filename);
+ const gchar *filename;
+ gboolean is_script;
+
+ filename = e_signature_get_filename (signature);
+ is_script = e_signature_get_is_script (signature);
+
+ if (filename == NULL && !is_script)
+ g_unlink (filename);
e_signature_list_remove (config->signatures, signature);
mail_config_save_signatures ();
diff --git a/mail/mail-signature-editor.c b/mail/mail-signature-editor.c
index 401f26feed..e00818e8a1 100644
--- a/mail/mail-signature-editor.c
+++ b/mail/mail-signature-editor.c
@@ -132,10 +132,10 @@ action_save_and_close_cb (GtkAction *action,
signature = mail_config_signature_new (NULL, FALSE, html);
else {
signature = g_object_ref (editor->priv->signature);
- signature->html = html;
+ e_signature_set_is_html (signature, html);
}
- filename = signature->filename;
+ filename = e_signature_get_filename (signature);
gtkhtml_editor_save (GTKHTML_EDITOR (editor), filename, html, &error);
if (error != NULL) {
@@ -166,7 +166,7 @@ action_save_and_close_cb (GtkAction *action,
* XXX ESignatureList misuses const. */
same_name = (ESignature *) e_signature_list_find (
signature_list, E_SIGNATURE_FIND_NAME, signature_name);
- if (same_name != NULL && strcmp (signature->uid, same_name->uid) != 0) {
+ if (same_name != NULL && !e_signature_is_equal (signature, same_name)) {
e_error_run (
GTK_WINDOW (editor),
"mail:signature-already-exists",
@@ -176,8 +176,8 @@ action_save_and_close_cb (GtkAction *action,
return;
}
- g_free (signature->name);
- signature->name = signature_name;
+ e_signature_set_name (signature, signature_name);
+ g_free (signature_name);
if (editor->priv->signature != NULL)
e_signature_list_change (signature_list, signature);
@@ -426,6 +426,7 @@ e_signature_editor_set_signature (ESignatureEditor *editor,
{
const gchar *filename;
const gchar *signature_name;
+ gboolean is_html;
gchar *contents;
gsize length;
GError *error = NULL;
@@ -447,9 +448,10 @@ e_signature_editor_set_signature (ESignatureEditor *editor,
/* Load signature content. */
- filename = signature->filename;
+ filename = e_signature_get_filename (signature);
+ is_html = e_signature_get_is_html (signature);
- if (signature->html)
+ if (is_html)
g_file_get_contents (filename, &contents, &length, &error);
else {
gchar *data;
@@ -462,7 +464,7 @@ e_signature_editor_set_signature (ESignatureEditor *editor,
if (error == NULL) {
gtkhtml_editor_set_html_mode (
- GTKHTML_EDITOR (editor), signature->html);
+ GTKHTML_EDITOR (editor), is_html);
gtkhtml_editor_set_text_html (
GTKHTML_EDITOR (editor), contents, length);
g_free (contents);
@@ -473,7 +475,7 @@ e_signature_editor_set_signature (ESignatureEditor *editor,
exit:
if (signature != NULL)
- signature_name = signature->name;
+ signature_name = e_signature_get_name (signature);
else
signature_name = _("Unnamed");
diff --git a/widgets/misc/e-signature-combo-box.c b/widgets/misc/e-signature-combo-box.c
index cb11ba632f..abaa8eafe3 100644
--- a/widgets/misc/e-signature-combo-box.c
+++ b/widgets/misc/e-signature-combo-box.c
@@ -97,11 +97,7 @@ signature_combo_box_refresh_cb (ESignatureList *signature_list,
const gchar *string;
signature = iter->data;
-
- if (signature->autogen)
- string = _("Autogenerated");
- else
- string = signature->name;
+ string = e_signature_get_name (signature);
gtk_list_store_append (store, &tree_iter);
gtk_list_store_set (