aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2002-02-02 05:00:15 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2002-02-02 05:00:15 +0800
commit6235db69b8ebab4877b00c7b683e48d3efd2aabb (patch)
tree2f29f4e1a60c2954509ac04b2a82eb758cef9050 /addressbook
parent7078e689561c5af29e0007965143368fd6dba7a7 (diff)
downloadgsoc2013-evolution-6235db69b8ebab4877b00c7b683e48d3efd2aabb.tar
gsoc2013-evolution-6235db69b8ebab4877b00c7b683e48d3efd2aabb.tar.gz
gsoc2013-evolution-6235db69b8ebab4877b00c7b683e48d3efd2aabb.tar.bz2
gsoc2013-evolution-6235db69b8ebab4877b00c7b683e48d3efd2aabb.tar.lz
gsoc2013-evolution-6235db69b8ebab4877b00c7b683e48d3efd2aabb.tar.xz
gsoc2013-evolution-6235db69b8ebab4877b00c7b683e48d3efd2aabb.tar.zst
gsoc2013-evolution-6235db69b8ebab4877b00c7b683e48d3efd2aabb.zip
New function to find out if a destination was one which was auto-matically
2002-02-01 Jeffrey Stedfast <fejj@ximian.com> * backend/ebook/e-destination.c (e_destination_is_auto_recipient): New function to find out if a destination was one which was auto-matically set by Evolution. (e_destination_set_auto_recipient): Set whether or not the dest is an auto-recipient. (e_destination_touch): Don't touch the address if it is an auto_recipient. (e_destination_list_to_vector_sized): New function to avoid having to calculate the length of the list ourselves. Allows for a bit of optimization if our caller knows the length of the list. (e_destination_xml_encode): Encode the auto_recipient bit. (e_destination_xml_decode): Decode the auto_recipient bit. svn path=/trunk/; revision=15550
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/ChangeLog15
-rw-r--r--addressbook/backend/ebook/e-destination.c570
-rw-r--r--addressbook/backend/ebook/e-destination.h7
3 files changed, 319 insertions, 273 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 9b66ebfc42..b7cfe0ce46 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,18 @@
+2002-02-01 Jeffrey Stedfast <fejj@ximian.com>
+
+ * backend/ebook/e-destination.c (e_destination_is_auto_recipient):
+ New function to find out if a destination was one which was
+ auto-matically set by Evolution.
+ (e_destination_set_auto_recipient): Set whether or not the dest is
+ an auto-recipient.
+ (e_destination_touch): Don't touch the address if it is an
+ auto_recipient.
+ (e_destination_list_to_vector_sized): New function to avoid having
+ to calculate the length of the list ourselves. Allows for a bit of
+ optimization if our caller knows the length of the list.
+ (e_destination_xml_encode): Encode the auto_recipient bit.
+ (e_destination_xml_decode): Decode the auto_recipient bit.
+
2002-02-01 Christopher James Lahey <clahey@ximian.com>
* backend/ebook/e-card-simple.c (e_card_simple_sync_card): Made
diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c
index 5e4ebfa488..5cb5fa859f 100644
--- a/addressbook/backend/ebook/e-destination.c
+++ b/addressbook/backend/ebook/e-destination.c
@@ -41,6 +41,8 @@
#include <gnome-xml/xmlmemory.h>
#include <camel/camel-internet-address.h>
+#define d(x) x
+
enum {
CHANGED,
CARDIFIED,
@@ -50,7 +52,6 @@ enum {
guint e_destination_signals[LAST_SIGNAL] = { 0 };
struct _EDestinationPrivate {
-
gchar *raw;
gchar *book_uri;
@@ -77,6 +78,7 @@ struct _EDestinationPrivate {
guint has_been_cardified : 1;
guint allow_cardify : 1;
guint cannot_cardify : 1;
+ guint auto_recipient : 1;
guint pending_cardification;
guint pending_change : 1;
@@ -147,6 +149,7 @@ e_destination_init (EDestination *dest)
dest->priv->allow_cardify = TRUE;
dest->priv->cannot_cardify = FALSE;
+ dest->priv->auto_recipient = FALSE;
dest->priv->pending_cardification = 0;
}
@@ -183,7 +186,8 @@ e_destination_freeze (EDestination *dest)
{
g_return_if_fail (E_IS_DESTINATION (dest));
g_return_if_fail (dest->priv->freeze_count >= 0);
- ++dest->priv->freeze_count;
+
+ dest->priv->freeze_count++;
}
static void
@@ -191,7 +195,8 @@ e_destination_thaw (EDestination *dest)
{
g_return_if_fail (E_IS_DESTINATION (dest));
g_return_if_fail (dest->priv->freeze_count > 0);
- --dest->priv->freeze_count;
+
+ dest->priv->freeze_count--;
if (dest->priv->freeze_count == 0 && dest->priv->pending_change)
e_destination_changed (dest);
}
@@ -251,34 +256,33 @@ static void
e_destination_clear_card (EDestination *dest)
{
if (dest->priv->card) {
-
if (dest->priv->old_card)
gtk_object_unref (GTK_OBJECT (dest->priv->old_card));
-
+
dest->priv->old_card = dest->priv->card;
dest->priv->old_card_email_num = dest->priv->card_email_num;
-
+
g_free (dest->priv->old_textrep);
dest->priv->old_textrep = g_strdup (e_destination_get_textrep (dest));
}
-
+
g_free (dest->priv->book_uri);
dest->priv->book_uri = NULL;
g_free (dest->priv->card_uid);
dest->priv->card_uid = NULL;
-
+
dest->priv->card = NULL;
dest->priv->card_email_num = -1;
-
+
g_list_foreach (dest->priv->list_dests, (GFunc) gtk_object_unref, NULL);
g_list_free (dest->priv->list_dests);
dest->priv->list_dests = NULL;
-
+
dest->priv->allow_cardify = TRUE;
dest->priv->cannot_cardify = FALSE;
-
+
e_destination_cancel_cardify (dest);
-
+
e_destination_changed (dest);
}
@@ -287,19 +291,19 @@ e_destination_clear_strings (EDestination *dest)
{
g_free (dest->priv->raw);
dest->priv->raw = NULL;
-
+
g_free (dest->priv->name);
dest->priv->name = NULL;
-
+
g_free (dest->priv->email);
dest->priv->email = NULL;
-
+
g_free (dest->priv->addr);
dest->priv->addr = NULL;
-
+
g_free (dest->priv->textrep);
dest->priv->textrep = NULL;
-
+
e_destination_changed (dest);
}
@@ -307,12 +311,12 @@ void
e_destination_clear (EDestination *dest)
{
g_return_if_fail (dest && E_IS_DESTINATION (dest));
-
+
e_destination_freeze (dest);
-
+
e_destination_clear_card (dest);
e_destination_clear_strings (dest);
-
+
e_destination_thaw (dest);
}
@@ -322,7 +326,7 @@ nonempty (const gchar *s)
gunichar c;
while (*s) {
c = g_utf8_get_char (s);
- if (! g_unichar_isspace (c))
+ if (!g_unichar_isspace (c))
return TRUE;
s = g_utf8_next_char (s);
}
@@ -334,7 +338,9 @@ e_destination_is_empty (const EDestination *dest)
{
struct _EDestinationPrivate *p;
+
g_return_val_if_fail (E_IS_DESTINATION (dest), TRUE);
+
p = dest->priv;
return !(p->card != NULL
@@ -350,13 +356,13 @@ e_destination_is_empty (const EDestination *dest)
gboolean
e_destination_is_valid (const EDestination *dest)
{
- const gchar *email;
-
+ const char *email;
+
g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE);
-
+
if (e_destination_from_card (dest))
return TRUE;
-
+
email = e_destination_get_email (dest);
/* FIXME: if we really wanted to get fancy here, we could
@@ -370,25 +376,25 @@ gboolean
e_destination_equal (const EDestination *a, const EDestination *b)
{
const struct _EDestinationPrivate *pa, *pb;
- const gchar *na, *nb;
-
+ const char *na, *nb;
+
g_return_val_if_fail (E_IS_DESTINATION (a), FALSE);
g_return_val_if_fail (E_IS_DESTINATION (b), FALSE);
-
+
if (a == b)
return TRUE;
-
+
pa = a->priv;
pb = b->priv;
-
+
/* Check equality of cards. */
if (pa->card || pb->card) {
if (! (pa->card && pb->card))
return FALSE;
-
+
if (pa->card == pb->card || !strcmp (e_card_get_id (pa->card), e_card_get_id (pb->card)))
return TRUE;
-
+
return FALSE;
}
@@ -409,20 +415,19 @@ e_destination_set_card (EDestination *dest, ECard *card, gint email_num)
{
g_return_if_fail (dest && E_IS_DESTINATION (dest));
g_return_if_fail (card && E_IS_CARD (card));
-
+
if (dest->priv->card != card || dest->priv->card_email_num != email_num) {
-
/* We have to freeze/thaw around these operations so that the 'changed'
signals don't cause the EDestination's internal state to be altered
before we can finish setting ->card && ->card_email_num. */
e_destination_freeze (dest);
e_destination_clear (dest);
-
+
dest->priv->card = card;
gtk_object_ref (GTK_OBJECT (dest->priv->card));
-
+
dest->priv->card_email_num = email_num;
-
+
e_destination_changed (dest);
e_destination_thaw (dest);
}
@@ -433,13 +438,11 @@ e_destination_set_book_uri (EDestination *dest, const gchar *uri)
{
g_return_if_fail (dest && E_IS_DESTINATION (dest));
g_return_if_fail (uri != NULL);
-
- if (dest->priv->book_uri == NULL
- || strcmp (dest->priv->book_uri, uri)) {
+ if (dest->priv->book_uri == NULL || strcmp (dest->priv->book_uri, uri)) {
g_free (dest->priv->book_uri);
dest->priv->book_uri = g_strdup (uri);
-
+
/* If we already have a card, remove it unless it's uri matches the one
we just set. */
if (dest->priv->card) {
@@ -449,7 +452,7 @@ e_destination_set_book_uri (EDestination *dest, const gchar *uri)
dest->priv->card = NULL;
}
}
-
+
e_destination_changed (dest);
}
}
@@ -459,22 +462,22 @@ e_destination_set_card_uid (EDestination *dest, const gchar *uid, gint email_num
{
g_return_if_fail (dest && E_IS_DESTINATION (dest));
g_return_if_fail (uid != NULL);
-
+
if (dest->priv->card_uid == NULL
|| strcmp (dest->priv->card_uid, uid)
|| dest->priv->card_email_num != email_num) {
-
+
g_free (dest->priv->card_uid);
dest->priv->card_uid = g_strdup (uid);
dest->priv->card_email_num = email_num;
-
+
/* If we already have a card, remove it unless it's uri matches the one
we just set. */
if (dest->priv->card && strcmp (uid, e_card_get_id (dest->priv->card))) {
gtk_object_unref (GTK_OBJECT (dest->priv->card));
dest->priv->card = NULL;
}
-
+
e_destination_changed (dest);
}
}
@@ -483,9 +486,9 @@ void
e_destination_set_name (EDestination *dest, const gchar *name)
{
gboolean changed = FALSE;
-
+
g_return_if_fail (E_IS_DESTINATION (dest));
-
+
if (name == NULL) {
if (dest->priv->name != NULL) {
g_free (dest->priv->name);
@@ -497,7 +500,7 @@ e_destination_set_name (EDestination *dest, const gchar *name)
dest->priv->name = g_strdup (name);
changed = TRUE;
}
-
+
if (changed) {
g_free (dest->priv->addr);
dest->priv->addr = NULL;
@@ -511,22 +514,20 @@ void
e_destination_set_email (EDestination *dest, const gchar *email)
{
gboolean changed = FALSE;
-
+
g_return_if_fail (E_IS_DESTINATION (dest));
-
+
if (email == NULL) {
if (dest->priv->email != NULL) {
g_free (dest->priv->addr);
dest->priv->addr = NULL;
changed = TRUE;
}
- } else if (dest->priv->email == NULL || strcmp (dest->priv->email, email)) {
-
+ } else if (dest->priv->email == NULL || strcmp (dest->priv->email, email)) {
g_free (dest->priv->email);
dest->priv->email = g_strdup (email);
changed = TRUE;
}
-
if (changed) {
g_free (dest->priv->addr);
@@ -563,6 +564,21 @@ e_destination_from_card (const EDestination *dest)
return dest->priv->card != NULL || dest->priv->book_uri != NULL || dest->priv->card_uid != NULL;
}
+gboolean
+e_destination_is_auto_recipient (const EDestination *dest)
+{
+ g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE);
+
+ return dest->priv->auto_recipient;
+}
+
+void
+e_destination_set_auto_recipient (EDestination *dest, gboolean value)
+{
+ g_return_if_fail (dest && E_IS_DESTINATION (dest));
+
+ dest->priv->auto_recipient = value;
+}
typedef struct _UseCard UseCard;
struct _UseCard {
@@ -575,19 +591,17 @@ static void
use_card_cb (ECard *card, gpointer closure)
{
UseCard *uc = (UseCard *) closure;
-
+
if (card != NULL && uc->dest->priv->card == NULL) {
-
uc->dest->priv->card = card;
gtk_object_ref (GTK_OBJECT (uc->dest->priv->card));
e_destination_changed (uc->dest);
-
}
-
+
if (uc->cb) {
uc->cb (uc->dest, uc->dest->priv->card, uc->closure);
}
-
+
/* We held a copy of the destination during the callback. */
gtk_object_unref (GTK_OBJECT (uc->dest));
g_free (uc);
@@ -597,13 +611,13 @@ void
e_destination_use_card (EDestination *dest, EDestinationCardCallback cb, gpointer closure)
{
g_return_if_fail (dest && E_IS_DESTINATION (dest));
-
+
if (dest->priv->card != NULL) {
if (cb)
cb (dest, dest->priv->card, closure);
} else if (dest->priv->book_uri != NULL && dest->priv->card_uid != NULL) {
-
UseCard *uc = g_new (UseCard, 1);
+
uc->dest = dest;
/* Hold a reference to the destination during the callback. */
gtk_object_ref (GTK_OBJECT (uc->dest));
@@ -620,7 +634,7 @@ ECard *
e_destination_get_card (const EDestination *dest)
{
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
-
+
return dest->priv->card;
}
@@ -634,7 +648,7 @@ e_destination_get_card_uid (const EDestination *dest)
if (dest->priv->card)
return e_card_get_id (dest->priv->card);
-
+
return NULL;
}
@@ -648,11 +662,12 @@ e_destination_get_book_uri (const EDestination *dest)
if (dest->priv->card) {
EBook *book = e_card_get_book (dest->priv->card);
+
if (book) {
return e_book_get_uri (book);
}
}
-
+
return NULL;
}
@@ -660,10 +675,10 @@ gint
e_destination_get_email_num (const EDestination *dest)
{
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), -1);
-
+
if (dest->priv->card == NULL && (dest->priv->book_uri == NULL || dest->priv->card_uid == NULL))
return -1;
-
+
return dest->priv->card_email_num;
}
@@ -671,36 +686,34 @@ const gchar *
e_destination_get_name (const EDestination *dest)
{
struct _EDestinationPrivate *priv;
+
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
-
+
priv = (struct _EDestinationPrivate *)dest->priv; /* cast out const */
if (priv->name == NULL) {
-
if (priv->card != NULL) {
-
priv->name = e_card_name_to_string (priv->card->name);
-
+
if (priv->name == NULL || *priv->name == '\0') {
g_free (priv->name);
priv->name = g_strdup (priv->card->file_as);
}
-
+
if (priv->name == NULL || *priv->name == '\0') {
g_free (priv->name);
priv->name = g_strdup (e_destination_get_email (dest));
}
-
} else if (priv->raw != NULL) {
-
CamelInternetAddress *addr = camel_internet_address_new ();
-
+
if (camel_address_unformat (CAMEL_ADDRESS (addr), priv->raw)) {
- const gchar *camel_name = NULL;
+ const char *camel_name = NULL;
+
camel_internet_address_get (addr, 0, &camel_name, NULL);
priv->name = g_strdup (camel_name);
}
-
+
camel_object_unref (CAMEL_OBJECT (addr));
}
}
@@ -713,37 +726,33 @@ const gchar *
e_destination_get_email (const EDestination *dest)
{
struct _EDestinationPrivate *priv;
-
+
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
-
+
priv = (struct _EDestinationPrivate *)dest->priv; /* cast out const */
if (priv->email == NULL) {
-
- if (priv->card != NULL) { /* Pull the address out of the card. */
-
+ if (priv->card != NULL) {
+ /* Pull the address out of the card. */
if (priv->card->email) {
EIterator *iter = e_list_get_iterator (priv->card->email);
- gint n = priv->card_email_num;
-
+ int n = priv->card_email_num;
+
if (n >= 0) {
while (n > 0) {
e_iterator_next (iter);
- --n;
+ n--;
}
-
+
if (e_iterator_is_valid (iter)) {
gconstpointer ptr = e_iterator_get (iter);
- priv->email = g_strdup ((gchar *) ptr);
+ priv->email = g_strdup ((char *) ptr);
}
}
-
}
-
} else if (priv->raw != NULL) {
-
CamelInternetAddress *addr = camel_internet_address_new ();
-
+
if (camel_address_unformat (CAMEL_ADDRESS (addr), priv->raw)) {
const gchar *camel_email = NULL;
camel_internet_address_get (addr, 0, NULL, &camel_email);
@@ -758,7 +767,7 @@ e_destination_get_email (const EDestination *dest)
priv->email = g_strdup ("");
}
}
-
+
return priv->email;
}
@@ -770,15 +779,16 @@ e_destination_get_address (const EDestination *dest)
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
priv = (struct _EDestinationPrivate *)dest->priv; /* cast out const */
-
+
if (priv->addr == NULL) {
CamelInternetAddress *addr = camel_internet_address_new ();
-
+
if (e_destination_is_evolution_list (dest)) {
GList *iter = dest->priv->list_dests;
while (iter) {
EDestination *list_dest = E_DESTINATION (iter->data);
+
if (!e_destination_is_empty (list_dest)) {
camel_internet_address_add (addr,
e_destination_get_name (list_dest),
@@ -788,25 +798,22 @@ e_destination_get_address (const EDestination *dest)
}
priv->addr = camel_address_encode (CAMEL_ADDRESS (addr));
-
} else if (priv->raw) {
if (camel_address_unformat (CAMEL_ADDRESS (addr), priv->raw)) {
priv->addr = camel_address_encode (CAMEL_ADDRESS (addr));
}
-
} else {
-
camel_internet_address_add (addr,
e_destination_get_name (dest),
e_destination_get_email (dest));
-
+
priv->addr = camel_address_encode (CAMEL_ADDRESS (addr));
}
-
+
camel_object_unref (CAMEL_OBJECT (addr));
}
-
+
return priv->addr;
}
@@ -815,15 +822,14 @@ e_destination_set_raw (EDestination *dest, const gchar *raw)
{
g_return_if_fail (E_IS_DESTINATION (dest));
g_return_if_fail (raw != NULL);
-
+
if (dest->priv->raw == NULL || strcmp (dest->priv->raw, raw)) {
-
e_destination_freeze (dest);
-
+
e_destination_clear (dest);
dest->priv->raw = g_strdup (raw);
e_destination_changed (dest);
-
+
e_destination_thaw (dest);
}
}
@@ -831,34 +837,35 @@ e_destination_set_raw (EDestination *dest, const gchar *raw)
const gchar *
e_destination_get_textrep (const EDestination *dest)
{
- const gchar *name, *email;
-
+ const char *name, *email;
+
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
-
+
if (dest->priv->raw)
return dest->priv->raw;
-
+
name = e_destination_get_name (dest);
email = e_destination_get_email (dest);
-
+
if (e_destination_from_card (dest) && name != NULL)
return name;
-
+
/* Make sure that our address gets quoted properly */
if (name && email && dest->priv->textrep == NULL) {
CamelInternetAddress *addr = camel_internet_address_new ();
+
camel_internet_address_add (addr, name, email);
g_free (dest->priv->textrep);
dest->priv->textrep = camel_address_format (CAMEL_ADDRESS (addr));
camel_object_unref (CAMEL_OBJECT (addr));
}
-
+
if (dest->priv->textrep != NULL)
return dest->priv->textrep;
if (email)
return email;
-
+
return "";
}
@@ -866,23 +873,25 @@ gboolean
e_destination_is_evolution_list (const EDestination *dest)
{
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE);
-
+
if (dest->priv->list_dests == NULL
&& dest->priv->card != NULL
&& dest->priv->card->email != NULL
&& e_card_evolution_list (dest->priv->card)) {
-
+
EIterator *iter = e_list_get_iterator (dest->priv->card->email);
+
e_iterator_reset (iter);
while (e_iterator_is_valid (iter)) {
- const gchar *dest_xml = (const gchar *) e_iterator_get (iter);
+ const char *dest_xml = (const char *) e_iterator_get (iter);
EDestination *list_dest = e_destination_import (dest_xml);
+
if (list_dest)
dest->priv->list_dests = g_list_append (dest->priv->list_dests, list_dest);
e_iterator_next (iter);
}
}
-
+
return dest->priv->list_dests != NULL;
}
@@ -890,10 +899,10 @@ gboolean
e_destination_list_show_addresses (const EDestination *dest)
{
g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE);
-
+
if (dest->priv->card != NULL)
return e_card_evolution_list_show_addresses (dest->priv->card);
-
+
return dest->priv->show_addresses;
}
@@ -901,10 +910,10 @@ 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;
}
@@ -912,7 +921,7 @@ gboolean
e_destination_allow_cardification (const EDestination *dest)
{
g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE);
-
+
return dest->priv->allow_cardify;
}
@@ -932,7 +941,7 @@ set_cardify_book (EDestination *dest, EBook *book)
}
dest->priv->cardify_book = book;
-
+
if (book)
gtk_object_ref (GTK_OBJECT (book));
}
@@ -941,32 +950,32 @@ static void
name_and_email_simple_query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure)
{
EDestination *dest = E_DESTINATION (closure);
-
+
if (status == E_BOOK_SIMPLE_QUERY_STATUS_SUCCESS && g_list_length ((GList *) cards) == 1) {
ECard *card = E_CARD (cards->data);
- const gchar *email = e_destination_get_email (dest);
- gint email_num = 0;
-
+ const char *email = e_destination_get_email (dest);
+ int email_num = 0;
+
if (e_destination_is_valid (dest) && email && *email) {
email_num = e_card_email_find_number (card, e_destination_get_email (dest));
}
-
+
if (email_num >= 0) {
const char *book_uri;
-
+
book_uri = e_book_get_uri (book);
-
+
dest->priv->has_been_cardified = TRUE;
e_destination_set_card (dest, card, email_num);
e_destination_set_book_uri (dest, book_uri);
gtk_signal_emit (GTK_OBJECT (dest), e_destination_signals[CARDIFIED]);
}
}
-
+
if (!dest->priv->has_been_cardified) {
dest->priv->cannot_cardify = TRUE;
}
-
+
gtk_object_unref (GTK_OBJECT (dest)); /* drop the reference held by the query */
}
@@ -975,14 +984,13 @@ static void
nickname_simple_query_cb (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure)
{
EDestination *dest = E_DESTINATION (closure);
-
+
if (status == E_BOOK_SIMPLE_QUERY_STATUS_SUCCESS) {
-
if (g_list_length ((GList *) cards) == 1) {
const char *book_uri;
-
+
book_uri = e_book_get_uri (book);
-
+
dest->priv->has_been_cardified = TRUE;
e_destination_set_card (dest, E_CARD (cards->data), 0); /* Uses primary e-mail by default. */
e_destination_set_book_uri (dest, book_uri);
@@ -991,10 +999,9 @@ nickname_simple_query_cb (EBook *book, EBookSimpleQueryStatus status, const GLis
gtk_object_unref (GTK_OBJECT (dest)); /* drop the reference held by the query */
} else {
-
/* We can only end up here if we don't look at all like an e-mail address, so
we do a name-only query on the textrep */
-
+
e_book_name_and_email_query (book,
e_destination_get_textrep (dest),
NULL,
@@ -1011,7 +1018,6 @@ static void
launch_cardify_query (EDestination *dest)
{
if (! e_destination_is_valid (dest)) {
-
/* If it doesn't look like an e-mail address, see if it is a nickname. */
e_book_nickname_query (dest->priv->cardify_book,
e_destination_get_textrep (dest),
@@ -1019,7 +1025,6 @@ launch_cardify_query (EDestination *dest)
dest);
} else {
-
e_book_name_and_email_query (dest->priv->cardify_book,
e_destination_get_name (dest),
e_destination_get_email (dest),
@@ -1036,7 +1041,7 @@ use_local_book_cb (EBook *book, gpointer closure)
dest->priv->cardify_book = book;
gtk_object_ref (GTK_OBJECT (book));
}
-
+
launch_cardify_query (dest);
}
@@ -1044,21 +1049,21 @@ use_local_book_cb (EBook *book, gpointer closure)
static gboolean
e_destination_reverting_is_a_good_idea (EDestination *dest)
{
- const gchar *textrep;
- gint len, old_len;
-
+ const char *textrep;
+ int len, old_len;
+
g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE);
if (dest->priv->old_textrep == NULL)
return FALSE;
-
+
textrep = e_destination_get_textrep (dest);
-
+
len = g_utf8_strlen (textrep, -1);
old_len = g_utf8_strlen (dest->priv->old_textrep, -1);
-
+
if (len <= old_len/2)
return FALSE;
-
+
return TRUE;
}
@@ -1067,30 +1072,30 @@ e_destination_cardify (EDestination *dest, EBook *book)
{
g_return_if_fail (E_IS_DESTINATION (dest));
g_return_if_fail (book == NULL || E_IS_BOOK (book));
-
+
if (e_destination_is_evolution_list (dest))
return;
-
+
if (e_destination_contains_card (dest))
return;
-
+
if (!dest->priv->allow_cardify)
return;
-
+
if (dest->priv->cannot_cardify)
return;
-
+
e_destination_cancel_cardify (dest);
-
+
/* In some cases, we can revert to the previous card. */
if (!e_destination_is_valid (dest)
&& e_destination_reverting_is_a_good_idea (dest)
&& e_destination_revert (dest)) {
return;
}
-
+
set_cardify_book (dest, book);
-
+
/* Handle the case of an EDestination containing a card URL */
if (e_destination_contains_card (dest)) {
e_destination_use_card (dest, NULL, NULL);
@@ -1107,10 +1112,11 @@ e_destination_cardify (EDestination *dest, EBook *book)
}
}
-static gint
+static int
do_cardify_delayed (gpointer ptr)
{
EDestination *dest = E_DESTINATION (ptr);
+
e_destination_cardify (dest, dest->priv->cardify_book);
return FALSE;
}
@@ -1120,14 +1126,14 @@ e_destination_cardify_delayed (EDestination *dest, EBook *book, gint delay)
{
g_return_if_fail (E_IS_DESTINATION (dest));
g_return_if_fail (book == NULL || E_IS_BOOK (book));
-
+
if (delay < 0)
delay = 500;
-
+
e_destination_cancel_cardify (dest);
-
+
set_cardify_book (dest, book);
-
+
dest->priv->pending_cardification = gtk_timeout_add (delay, do_cardify_delayed, dest);
}
@@ -1135,7 +1141,7 @@ void
e_destination_cancel_cardify (EDestination *dest)
{
g_return_if_fail (E_IS_DESTINATION (dest));
-
+
if (dest->priv->pending_cardification) {
gtk_timeout_remove (dest->priv->pending_cardification);
dest->priv->pending_cardification = 0;
@@ -1145,24 +1151,24 @@ e_destination_cancel_cardify (EDestination *dest)
gboolean
e_destination_uncardify (EDestination *dest)
{
- gchar *email;
-
+ char *email;
+
g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE);
-
- if (! e_destination_contains_card (dest))
+
+ if (!e_destination_contains_card (dest))
return FALSE;
-
+
email = g_strdup (e_destination_get_email (dest));
-
+
if (email == NULL)
return FALSE;
-
+
e_destination_freeze (dest);
e_destination_clear (dest);
e_destination_set_raw (dest, email);
g_free (email);
e_destination_thaw (dest);
-
+
return TRUE;
}
@@ -1170,26 +1176,26 @@ gboolean
e_destination_revert (EDestination *dest)
{
g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE);
-
+
if (dest->priv->old_card) {
ECard *card;
- gint card_email_num;
-
+ int card_email_num;
+
card = dest->priv->old_card;
card_email_num = dest->priv->old_card_email_num;
-
+
dest->priv->old_card = NULL;
g_free (dest->priv->old_textrep);
dest->priv->old_textrep = NULL;
-
+
e_destination_freeze (dest);
e_destination_clear (dest);
e_destination_set_card (dest, card, card_email_num);
e_destination_thaw (dest);
-
+
return TRUE;
}
-
+
return FALSE;
}
@@ -1200,29 +1206,29 @@ e_destination_revert (EDestination *dest)
gchar *
e_destination_get_address_textv (EDestination **destv)
{
- gint i, j, len = 0;
- gchar **strv;
- gchar *str;
+ int i, j, len = 0;
+ char **strv;
+ char *str;
g_return_val_if_fail (destv, NULL);
-
+
/* Q: Please tell me this is only for assertion
reasons. If this is considered to be ok behavior then you
shouldn't use g_return's. Just a reminder ;-)
-
+
A: Yes, this is just an assertion. (Though it does find the
length of the vector in the process...)
*/
while (destv[len]) {
g_return_val_if_fail (E_IS_DESTINATION (destv[len]), NULL);
- ++len;
+ len++;
}
- strv = g_new0 (gchar *, len+1);
+ strv = g_new0 (char *, len + 1);
for (i = 0, j = 0; destv[i]; i++) {
if (!e_destination_is_empty (destv[i])) {
- const gchar *addr = e_destination_get_address (destv[i]);
- strv[j++] = addr ? (gchar *) addr : "";
+ const char *addr = e_destination_get_address (destv[i]);
+ strv[j++] = addr ? (char *) addr : "";
}
}
@@ -1237,17 +1243,17 @@ xmlNodePtr
e_destination_xml_encode (const EDestination *dest)
{
xmlNodePtr dest_node;
- const gchar *str;
-
+ const char *str;
+
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
-
+
dest_node = xmlNewNode (NULL, "destination");
-
+
str = e_destination_get_name (dest);
if (str)
xmlNewTextChild (dest_node, NULL, "name", str);
-
- if (! e_destination_is_evolution_list (dest)) {
+
+ if (!e_destination_is_evolution_list (dest)) {
str = e_destination_get_email (dest);
if (str)
xmlNewTextChild (dest_node, NULL, "email", str);
@@ -1265,44 +1271,48 @@ e_destination_xml_encode (const EDestination *dest)
str = e_destination_get_email (list_dest);
if (str)
xmlNewTextChild (list_node, NULL, "email", str);
-
+
xmlAddChild (dest_node, list_node);
iter = g_list_next (iter);
}
-
+
xmlNewProp (dest_node, "is_list", "yes");
xmlNewProp (dest_node, "show_addresses",
e_destination_list_show_addresses (dest) ? "yes" : "no");
}
-
+
str = e_destination_get_book_uri (dest);
if (str) {
xmlNewTextChild (dest_node, NULL, "book_uri", str);
}
-
+
str = e_destination_get_card_uid (dest);
if (str) {
- gchar buf[16];
+ char buf[16];
+
xmlNodePtr uri_node = xmlNewTextChild (dest_node, NULL, "card_uid", str);
g_snprintf (buf, 16, "%d", e_destination_get_email_num (dest));
xmlNewProp (uri_node, "email_num", buf);
}
-
+
xmlNewProp (dest_node, "html_mail", e_destination_get_html_mail_pref (dest) ? "yes" : "no");
-
+
+ xmlNewProp (dest_node, "auto_recipient",
+ e_destination_is_auto_recipient (dest) ? "yes" : "no");
+
return dest_node;
}
gboolean
e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
{
- gchar *name = NULL, *email = NULL, *book_uri = NULL, *card_uid = NULL;
- gint email_num = -1;
+ char *name = NULL, *email = NULL, *book_uri = NULL, *card_uid = NULL;
+ gboolean is_list = FALSE, show_addr = FALSE, auto_recip = FALSE;
gboolean html_mail = FALSE;
- gboolean is_list = FALSE, show_addr = FALSE;
- gchar *tmp;
GList *list_dests = NULL;
+ int email_num = -1;
+ char *tmp;
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE);
g_return_val_if_fail (node != NULL, FALSE);
@@ -1328,6 +1338,12 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
xmlFree (tmp);
}
+ tmp = xmlGetProp (node, "auto_recipient");
+ if (tmp) {
+ auto_recip = !strcmp (tmp, "yes");
+ xmlFree (tmp);
+ }
+
node = node->xmlChildrenNode;
while (node) {
if (!strcmp (node->name, "name")) {
@@ -1342,7 +1358,7 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
xmlFree (tmp);
} else if (is_list && !strcmp (node->name, "list_entry")) {
xmlNodePtr subnode = node->xmlChildrenNode;
- gchar *list_name = NULL, *list_email = NULL;
+ char *list_name = NULL, *list_email = NULL;
while (subnode) {
if (!strcmp (subnode->name, "name")) {
@@ -1362,6 +1378,7 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
if (list_name || list_email) {
EDestination *list_dest = e_destination_new ();
+
if (list_name)
e_destination_set_name (list_dest, list_name);
if (list_email)
@@ -1369,7 +1386,7 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
g_free (list_name);
g_free (list_email);
-
+
list_dests = g_list_append (list_dests, list_dest);
}
} else if (!strcmp (node->name, "book_uri")) {
@@ -1390,7 +1407,7 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
node = node->next;
}
-
+
e_destination_freeze (dest);
e_destination_clear (dest);
@@ -1413,12 +1430,14 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
}
if (list_dests)
dest->priv->list_dests = list_dests;
-
+
dest->priv->html_mail_override = TRUE;
dest->priv->wants_html_mail = html_mail;
-
+
dest->priv->show_addresses = show_addr;
-
+
+ dest->priv->auto_recipient = auto_recip;
+
e_destination_thaw (dest);
return TRUE;
@@ -1428,34 +1447,33 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
static gchar *
null_terminate_and_remove_extra_whitespace (xmlChar *xml_in, gint size)
{
- gchar *xml;
- gchar *r, *w;
gboolean skip_white = FALSE;
-
+ char *xml, *r, *w;
+
if (xml_in == NULL || size <= 0)
return NULL;
-
+
xml = g_strndup (xml_in, size);
r = w = xml;
-
+
while (*r) {
if (*r == '\n' || *r == '\r') {
skip_white = TRUE;
} else {
gboolean is_space = isspace (*r);
-
+
*w = *r;
-
- if (! (skip_white && is_space))
- ++w;
- if (! is_space)
+
+ if (!(skip_white && is_space))
+ w++;
+ if (!is_space)
skip_white = FALSE;
}
- ++r;
+ r++;
}
-
+
*w = '\0';
-
+
return xml;
}
@@ -1463,26 +1481,26 @@ gchar *
e_destination_export (const EDestination *dest)
{
xmlNodePtr dest_node;
- xmlDocPtr dest_doc;
- xmlChar *buffer = NULL;
- gint size = -1;
- gchar *str;
+ xmlDocPtr dest_doc;
+ xmlChar *buffer = NULL;
+ int size = -1;
+ char *str;
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
-
+
dest_node = e_destination_xml_encode (dest);
if (dest_node == NULL)
return NULL;
-
+
dest_doc = xmlNewDoc (XML_DEFAULT_VERSION);
xmlDocSetRootElement (dest_doc, dest_node);
-
+
xmlDocDumpMemory (dest_doc, &buffer, &size);
xmlFreeDoc (dest_doc);
-
+
str = null_terminate_and_remove_extra_whitespace (buffer, size);
xmlFree (buffer);
-
+
return str;
}
@@ -1491,11 +1509,11 @@ e_destination_import (const gchar *str)
{
EDestination *dest = NULL;
xmlDocPtr dest_doc;
-
- if (! (str && *str))
+
+ if (!(str && *str))
return NULL;
-
- dest_doc = xmlParseMemory ((gchar *) str, strlen (str));
+
+ dest_doc = xmlParseMemory ((char *) str, strlen (str));
if (dest_doc && dest_doc->xmlRootNode) {
dest = e_destination_new ();
if (! e_destination_xml_decode (dest, dest_doc->xmlRootNode)) {
@@ -1504,41 +1522,40 @@ e_destination_import (const gchar *str)
}
}
xmlFreeDoc (dest_doc);
-
+
return dest;
}
gchar *
e_destination_exportv (EDestination **destv)
{
- xmlDocPtr destv_doc;
- xmlNodePtr destv_node;
- xmlChar *buffer = NULL;
- gint size = -1;
- gchar *str;
- gint i;
-
+ xmlDocPtr destv_doc;
+ xmlNodePtr destv_node;
+ xmlChar *buffer = NULL;
+ int i, size = -1;
+ char *str;
+
if (destv == NULL || *destv == NULL)
return NULL;
-
+
destv_doc = xmlNewDoc (XML_DEFAULT_VERSION);
destv_node = xmlNewNode (NULL, "destinations");
xmlDocSetRootElement (destv_doc, destv_node);
-
- for (i=0; destv[i]; ++i) {
+
+ for (i = 0; destv[i]; i++) {
if (! e_destination_is_empty (destv[i])) {
xmlNodePtr dest_node = e_destination_xml_encode (destv[i]);
if (dest_node)
xmlAddChild (destv_node, dest_node);
}
}
-
+
xmlDocDumpMemory (destv_doc, &buffer, &size);
xmlFreeDoc (destv_doc);
-
+
str = null_terminate_and_remove_extra_whitespace (buffer, size);
xmlFree (buffer);
-
+
return str;
}
@@ -1553,10 +1570,10 @@ e_destination_importv (const gchar *str)
if (!(str && *str))
return NULL;
- destv_doc = xmlParseMemory ((gchar *)str, strlen (str));
+ destv_doc = xmlParseMemory ((char *)str, strlen (str));
if (destv_doc == NULL)
return NULL;
-
+
node = destv_doc->xmlRootNode;
if (strcmp (node->name, "destinations"))
@@ -1592,32 +1609,40 @@ e_destination_importv (const gchar *str)
}
EDestination **
-e_destination_list_to_vector (GList *list)
+e_destination_list_to_vector_sized (GList *list, int n)
{
- gint N = g_list_length (list);
EDestination **destv;
- gint i = 0;
-
- if (N == 0)
+ int i = 0;
+
+ if (n == -1)
+ n = g_list_length (list);
+
+ if (n == 0)
return NULL;
- destv = g_new (EDestination *, N+1);
- while (list != NULL) {
+ destv = g_new (EDestination *, n + 1);
+ while (list != NULL && i < n) {
destv[i] = E_DESTINATION (list->data);
list->data = NULL;
- ++i;
+ i++;
list = g_list_next (list);
}
- destv[N] = NULL;
-
+ destv[i] = NULL;
+
return destv;
}
+EDestination **
+e_destination_list_to_vector (GList *list)
+{
+ return e_destination_list_to_vector_sized (list, -1);
+}
+
void
e_destination_freev (EDestination **destv)
{
- gint i;
-
+ int i;
+
if (destv) {
for (i = 0; destv[i] != NULL; ++i) {
gtk_object_unref (GTK_OBJECT (destv[i]));
@@ -1632,7 +1657,7 @@ touch_cb (EBook *book, const gchar *addr, ECard *card, gpointer closure)
{
if (book != NULL && card != NULL) {
e_card_touch (card);
- g_message ("Use score for \"%s\" is now %f", addr, e_card_get_use_score (card));
+ d(g_message ("Use score for \"%s\" is now %f", addr, e_card_get_use_score (card)));
e_book_commit_card (book, card, NULL, NULL);
}
}
@@ -1640,24 +1665,25 @@ touch_cb (EBook *book, const gchar *addr, ECard *card, gpointer closure)
void
e_destination_touch (EDestination *dest)
{
- const gchar *email;
-
+ const char *email;
+
g_return_if_fail (dest && E_IS_DESTINATION (dest));
-
- email = e_destination_get_email (dest);
-
- if (email) {
- e_book_query_address_locally (email, touch_cb, NULL);
+
+ if (!e_destination_is_auto_recipient (dest)) {
+ email = e_destination_get_email (dest);
+
+ if (email)
+ e_book_query_address_locally (email, touch_cb, NULL);
}
}
void
e_destination_touchv (EDestination **destv)
{
- gint i;
-
+ int i;
+
g_return_if_fail (destv != NULL);
-
+
for (i = 0; destv[i] != NULL; ++i) {
e_destination_touch (destv[i]);
}
diff --git a/addressbook/backend/ebook/e-destination.h b/addressbook/backend/ebook/e-destination.h
index 4beb199503..f545794ab0 100644
--- a/addressbook/backend/ebook/e-destination.h
+++ b/addressbook/backend/ebook/e-destination.h
@@ -82,6 +82,9 @@ void e_destination_set_html_mail_pref (EDestination *, gboolean);
gboolean e_destination_contains_card (const EDestination *);
gboolean e_destination_from_card (const EDestination *);
+gboolean e_destination_is_auto_recipient (const EDestination *);
+void e_destination_set_auto_recipient (EDestination *, gboolean value);
+
void e_destination_use_card (EDestination *, EDestinationCardCallback cb, gpointer closure);
ECard *e_destination_get_card (const EDestination *);
@@ -122,7 +125,9 @@ EDestination *e_destination_import (const gchar *str);
gchar *e_destination_exportv (EDestination **);
EDestination **e_destination_importv (const gchar *str);
-EDestination **e_destination_list_to_vector (GList *);
+EDestination **e_destination_list_to_vector_sized (GList *, int n);
+EDestination **e_destination_list_to_vector (GList *);
+
void e_destination_freev (EDestination **);
void e_destination_touch (EDestination *);