diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-05-18 15:10:04 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-05-18 15:10:04 +0800 |
commit | 3ca3f79dbe4641478582cd0b78a6e377c3430b19 (patch) | |
tree | 2693ebef04b05fff098f38f00233e676caf6229e /addressbook/backend/ebook/e-destination.c | |
parent | c8476fc1ff4887bde985382de708f248067ac7ba (diff) | |
download | gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.tar gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.tar.gz gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.tar.bz2 gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.tar.lz gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.tar.xz gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.tar.zst gsoc2013-evolution-3ca3f79dbe4641478582cd0b78a6e377c3430b19.zip |
Return the serialized EDestinations (rather than just a string w/ e-mail
2001-05-18 Jon Trowbridge <trow@ximian.com>
* gui/component/select-names/e-select-names-bonobo.c
(entry_get_property_fn): Return the serialized EDestinations
(rather than just a string w/ e-mail addresses) through the bonobo
component's property bag.
* gui/component/select-names/e-select-names-model.c
(e_select_names_model_export_destinationv): Added. A convenience routine
for serializing the model's EDestinations into a string.
* gui/component/select-names/e-select-names-popup.c
(add_html_mail): Added. Puts in a check menu item for whether or
not the recipient wants HTML mail.
(popup_menu_card): Add menu item for HTML mail. Enable edit
contact info item.
(popup_menu_nocard): Add menu item for HTML mail. Enable edit
contact info item.
* backend/ebook/e-book-util.c (e_book_use_local_address_book):
Added. Fetches the local addressbook and caches it on the first
call. This is meant to be an easy and efficient way to get at the
local addressbook with the minimum of code.
(e_book_query_address_locally): Added. Convenience code that
does an e-mail only e_book_name_and_email_query against the
local address book.
* backend/ebook/e-destination.c
(e_destination_set_html_mail_pref): Added. Allows the intended
recipient's HTML mail preference to be manipulated.
(e_destination_get_email_verbose): Added. Cleaned up to use
e_destination_get_name.
(e_destination_get_html_mail_pref): Added. Read the recipient's HTML mail
preference. If the destination is linked to a card, the
preference is taken from the card (unless it has been explicitly
overridden by a called to e_destination_set_html_mail_pref).
(e_destination_get_address_textv): Added. Form a unified address string
from a NULL-terminated vector of EDestinations.
(e_destination_export): Added. Serialize an EDestination to a string.
(e_destination_import): Added. Unserialize a string to build an
EDestination.
(e_destination_exportv): Added. Serialize a NULL-terminated vector of
EDestinations to a string.
(e_destination_importv): Added. Unserialize a string to build a
NULL-terminated vector of EDestinations.
* gui/component/select-names/e-select-names-completion.c:
Implemented local versions of g_strcasecmp and g_strncasecmp
(which should really be in glib, I think...) for utf8, and used
them to make this code utf8-safe.
2001-05-18 Jon Trowbridge <trow@ximian.com>
* Makefile.am (evolution_mail_LDADD): Added libebook.la (which is
now required by the composer.)
2001-05-18 Jon Trowbridge <trow@ximian.com>
* e-msg-composer-hdrs.c (set_recipients): Properly unserialize the
string returned by the "text" property of the bonobo control,
convert it into EDestinations, and use them to get the e-mail
addresses of our recipients.
22001-05-18 Jon Trowbridge <trow@ximian.com>
* Makefile.am (SUBDIRS): Changed build order. Now addressbook
gets built before mail.
svn path=/trunk/; revision=9878
Diffstat (limited to 'addressbook/backend/ebook/e-destination.c')
-rw-r--r-- | addressbook/backend/ebook/e-destination.c | 246 |
1 files changed, 242 insertions, 4 deletions
diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c index e6fdb3ee43..83bd96a7d1 100644 --- a/addressbook/backend/ebook/e-destination.c +++ b/addressbook/backend/ebook/e-destination.c @@ -40,6 +40,9 @@ struct _EDestinationPrivate { gchar *string; gchar *string_email; gchar *string_email_verbose; + + gboolean html_mail_override; + gboolean wants_html_mail; }; static void e_destination_clear_card (EDestination *); @@ -187,6 +190,15 @@ e_destination_set_string (EDestination *dest, const gchar *string) dest->priv->string = g_strdup (string); } +void +e_destination_set_html_mail_pref (EDestination *dest, gboolean x) +{ + g_return_if_fail (dest && E_IS_DESTINATION (dest)); + + dest->priv->html_mail_override = TRUE; + dest->priv->wants_html_mail = x; +} + ECard * e_destination_get_card (const EDestination *dest) { @@ -319,11 +331,11 @@ e_destination_get_email_verbose (const EDestination *dest) if (priv->string_email_verbose == NULL) { const gchar *email = e_destination_get_email (dest); + const gchar *name = e_destination_get_name (dest); - if (priv->card) { - gchar *n = e_card_name_to_string (priv->card->name); - priv->string_email_verbose = g_strdup_printf ("%s <%s>", n, email); - g_free (n); + if (name) { + + priv->string_email_verbose = g_strdup_printf ("%s <%s>", name, email); } else { @@ -335,4 +347,230 @@ e_destination_get_email_verbose (const EDestination *dest) return priv->string_email_verbose; } +gboolean +e_destination_get_html_mail_pref (const EDestination *dest) +{ + g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE); + + if (dest->priv->html_mail_override || dest->priv->card == NULL) + return dest->priv->wants_html_mail; + + return dest->priv->card->wants_html; +} + +gchar * +e_destination_get_address_textv (EDestination **destv) +{ + gint i, j, len = 0; + gchar **strv; + gchar *str; + g_return_val_if_fail (destv, NULL); + + while (destv[len]) { + g_return_val_if_fail (E_IS_DESTINATION (destv[len]), NULL); + ++len; + } + + strv = g_new0 (gchar *, len+1); + for (i = 0, j = 0; destv[i]; ++i) { + const gchar *addr = e_destination_get_email_verbose (destv[i]); + + strv[j++] = addr ? (gchar *) addr : ""; + } + + str = g_strjoinv (", ", strv); + + g_free (strv); + + return str; +} + +/* + * + * Serialization code + * + */ + +#define DESTINATION_TAG "DEST" +#define DESTINATION_SEPARATOR "|" + +static gchar * +join_strings (gchar **strv) +{ + /* FIXME: Should also quote any |'s that occur in any of the strings. */ + return g_strjoinv (DESTINATION_SEPARATOR, strv); +} + +static gchar ** +unjoin_string (const gchar *str) +{ + /* FIXME: Should properly handle quoteded |'s in the string. */ + return g_strsplit (str, DESTINATION_SEPARATOR, 0); +} + +static gchar * +build_field (const gchar *key, const gchar *value) +{ + return g_strdup_printf ("%s=%s", key, value); +} + +/* Modifies string in place, \0-terminates after the key, returns pointer to "value", + or NULL if the field is malformed. */ +static gchar * +extract_field (gchar *field) +{ + gchar *s = strchr (field, '='); + if (s == NULL) + return NULL; + *s = '\0'; + return s+1; +} + + +gchar * +e_destination_export (const EDestination *dest) +{ + gchar **fields; + gchar *str; + gint i; + + g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); + + fields = g_new (gchar *, 5); + fields[0] = g_strdup (DESTINATION_TAG); + fields[1] = build_field ("addr", e_destination_get_email (dest)); + + i = 2; + + if (e_destination_get_name (dest)) + fields[i++] = build_field ("name", e_destination_get_name (dest)); + + fields[i++] = build_field ("html", + e_destination_get_html_mail_pref (dest) ? "Y" : "N"); + + fields[i] = NULL; + + + str = join_strings (fields); + g_strfreev (fields); + + return str; +} + +EDestination * +e_destination_import (const gchar *str) +{ + EDestination *dest; + gchar **fields; + gint i; + + gchar *addr = NULL, *name = NULL; + gboolean want_html = FALSE; + + g_return_val_if_fail (str, NULL); + + fields = unjoin_string (str); + g_return_val_if_fail (fields && fields[0], NULL); + g_return_val_if_fail (!strcmp (fields[0], DESTINATION_TAG), NULL); + + for (i = 1; fields[i]; ++i) { + gchar *key = fields[i]; + gchar *value = extract_field (fields[i]); + + if (value) { + + if (!strcmp ("addr", key)) { + + if (addr) { + g_warning ("addr redefined: \"%s\" => \"%s\"", addr, value); + } + + addr = g_strdup (value); + + } else if (!strcmp ("name", key)) { + + if (name) { + g_warning ("name redefined: \"%s\" => \"%s\"", name, value); + } + + name = g_strdup (name); + + } else if (!strcmp ("html", key)) { + + want_html = (*value == 'Y'); + + } + + } + + } + dest = e_destination_new (); + + /* We construct this part of the object in a rather abusive way. */ + dest->priv->string_email = addr; + dest->priv->name = name; + + e_destination_set_html_mail_pref (dest, want_html); + + g_strfreev (fields); + + return dest; +} + +#define VEC_SEPARATOR "\1" + +gchar * +e_destination_exportv (EDestination **destv) +{ + gint i, len = 0; + gchar **strv; + gchar *str; + + g_return_val_if_fail (destv, NULL); + + while (destv[len]) { + g_return_val_if_fail (E_IS_DESTINATION (destv[len]), NULL); + ++len; + } + + strv = g_new0 (gchar *, len+1); + for (i = 0; i < len; ++i) + strv[i] = e_destination_export (destv[i]); + + str = g_strjoinv (VEC_SEPARATOR, strv); + + for (i = 0; i < len; ++i) + g_free (strv[i]); + g_free (strv); + + return str; +} + +EDestination ** +e_destination_importv (const gchar *str) +{ + gchar** strv; + EDestination **destv; + gint i = 0, j = 0, len = 0; + + if (!(str && *str)) + return NULL; + + strv = g_strsplit (str, VEC_SEPARATOR, 0); + while (strv[len]) + ++len; + + destv = g_new0 (EDestination *, len+1); + + while (strv[i]) { + EDestination *dest = e_destination_import (strv[i]); + if (dest) { + destv[j++] = dest; + } + ++i; + } + + g_strfreev (strv); + return destv; +} |