aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend/ebook/e-destination.c
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-09-09 11:45:55 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-09-09 11:45:55 +0800
commit2e3a7b37fe4bb3adffd998d005e39fd4758e2c1e (patch)
tree63a92240525e12e6041c707203267e8411e25773 /addressbook/backend/ebook/e-destination.c
parentba8ba2de6e1f656acaaab3e45eaf4b2b9a2c46c2 (diff)
downloadgsoc2013-evolution-2e3a7b37fe4bb3adffd998d005e39fd4758e2c1e.tar
gsoc2013-evolution-2e3a7b37fe4bb3adffd998d005e39fd4758e2c1e.tar.gz
gsoc2013-evolution-2e3a7b37fe4bb3adffd998d005e39fd4758e2c1e.tar.bz2
gsoc2013-evolution-2e3a7b37fe4bb3adffd998d005e39fd4758e2c1e.tar.lz
gsoc2013-evolution-2e3a7b37fe4bb3adffd998d005e39fd4758e2c1e.tar.xz
gsoc2013-evolution-2e3a7b37fe4bb3adffd998d005e39fd4758e2c1e.tar.zst
gsoc2013-evolution-2e3a7b37fe4bb3adffd998d005e39fd4758e2c1e.zip
See e_book_listener_check_queue below.
2001-09-08 Jon Trowbridge <trow@ximian.com> * backend/ebook/e-book-view-listener.c (e_book_view_listener_check_queue): See e_book_listener_check_queue below. (e_book_view_listener_queue_response): See e_book_listener_queue_response below. * backend/ebook/e-book-listener.c (e_book_listener_check_queue): Explicitly prohibit reentrancy. Use gtk-unref rather than bobobo-unref. (e_book_listener_queue_response): Hold a gtk-ref to the listener while the idle function runs, not a bonobo-ref. As far as I can tell, it is impossible to avoid a race condition here when we have to worry about bonobo reentrancy. * gui/component/select-names/e-select-names-text-model.c (e_select_names_text_model_insert_length): Alter a copy of the original EDestination, rather than just using a new one. We need to do this to preserve prior-card information for possible reversion later. (e_select_names_text_model_delete): Ditto. * backend/ebook/e-destination.c (e_destination_clear_card): When clearing a destination where ->card != NULL, store it for possible reversion later. (e_destination_revert): If we have an old card stored, go back to using it for the destination. (e_destination_is_valid): Tries to detect obviously broken addresses. (e_destination_cardify): If our destination is invalid, first try to cardify simply by reverting to an older card. (e_destination_destroy): Unref any cached old card. (e_destination_copy): Copy the old card information. 2001-09-07 Jon Trowbridge <trow@ximian.com> * gui/component/select-names/e-select-names.c (sync_table_and_models): Show all rows in the table, and then remove the rows that correspond to entries in the ESelectNamesModels in the children. (real_add_address): Freeze/thaw our ESelectNamesModel, so that we don't change our table while we are in the middle of iterating over the selection. (remove_address): Just delete the address from the ESelectNamesModel, the signal handler will do the rest. (selected_rows_foreach_cb): Call remove_address to do our dirty work. (e_select_names_add_section): Connect to the 'changed' signal from the ESelectNamesModel, and call sync_table_and_models explicitly to get our initial state correct. * gui/component/select-names/e-select-names-table-model.c (fill_in_info): Deal with EDestinations in our table that don't come from cards. * gui/component/select-names/e-select-names-manager.c: Added another ESelectNamesModel* to the ESelectNamesManagerSection struct. Called 'original_model', this contains a copy of the model as it is when we begin using the SelectNames dialog. (section_copy): Copy the original model. (section_free): Free the original model. (e_select_names_manager_add_section_with_limit): Initialize the original model. (e_select_names_clicked): I've changed the semantics of this dialog quite a bit... no UI freeze can stop me! If OK is clicked, we do nothing. If Cancel is clicked, we revert to the 'original_model' copy of our address entry state before we started editting. Finally, we close the dialog before any of thing. Doing it last caused problems, because signals were being triggered which had dangling pointers as their closures. (e_select_names_manager_activate_dialog): Copy our current state to the original model, and share the same ESelectNamesModel between the dialog and the address entry in the composer.. (e_select_names_manager_get_cards): Removed. It had been #if 0/#endif-ed out for a while. * gui/component/select-names/e-select-names-model.c (e_select_names_model_freeze): Added. (e_select_names_model_thaw): Added. (e_select_names_model_uncardify): Added. If possible, "uncardifies" a specific model entry. (e_select_names_model_changed): Changed to pay attention to the freeze count. * gui/component/select-names/e-select-names-completion.c (clean_query_text): Strip leading/trailing whitespace from queries. * backend/ebook/e-destination.c (e_destination_uncardify): Added. Converts a card-associated destination into a text-associated destination w/ the e-mail address. (e_destination_list_to_vector): Added. A convenience routine. (e_destination_freev): Added. A convenience routine. (e_destination_touchv): Added. I'm lazy. svn path=/trunk/; revision=12709
Diffstat (limited to 'addressbook/backend/ebook/e-destination.c')
-rw-r--r--addressbook/backend/ebook/e-destination.c230
1 files changed, 193 insertions, 37 deletions
diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c
index 9e0e4b6067..842fa8652e 100644
--- a/addressbook/backend/ebook/e-destination.c
+++ b/addressbook/backend/ebook/e-destination.c
@@ -59,9 +59,13 @@ struct _EDestinationPrivate {
ECard *card;
gint card_email_num;
+ ECard *old_card;
+ gint old_card_email_num;
+
gchar *name;
gchar *email;
gchar *addr;
+ gchar *textrep;
gboolean html_mail_override;
gboolean wants_html_mail;
@@ -90,6 +94,9 @@ e_destination_destroy (GtkObject *obj)
EDestination *dest = E_DESTINATION (obj);
e_destination_clear (dest);
+
+ if (dest->priv->old_card)
+ gtk_object_unref (GTK_OBJECT (dest->priv->old_card));
if (dest->priv->cardify_book)
gtk_object_unref (GTK_OBJECT (dest->priv->cardify_book));
@@ -207,17 +214,22 @@ e_destination_copy (const EDestination *dest)
new_dest = e_destination_new ();
- new_dest->priv->book_uri = g_strdup (dest->priv->book_uri);
- new_dest->priv->card_uid = g_strdup (dest->priv->card_uid);
- new_dest->priv->name = g_strdup (dest->priv->name);
- new_dest->priv->email = g_strdup (dest->priv->email);
- new_dest->priv->addr = g_strdup (dest->priv->addr);
- new_dest->priv->card_email_num = dest->priv->card_email_num;
+ new_dest->priv->book_uri = g_strdup (dest->priv->book_uri);
+ new_dest->priv->card_uid = g_strdup (dest->priv->card_uid);
+ new_dest->priv->name = g_strdup (dest->priv->name);
+ new_dest->priv->email = g_strdup (dest->priv->email);
+ new_dest->priv->addr = g_strdup (dest->priv->addr);
+ new_dest->priv->card_email_num = dest->priv->card_email_num;
+ new_dest->priv->old_card_email_num = dest->priv->old_card_email_num;
new_dest->priv->card = dest->priv->card;
if (new_dest->priv->card)
gtk_object_ref (GTK_OBJECT (new_dest->priv->card));
+ new_dest->priv->old_card = dest->priv->old_card;
+ if (new_dest->priv->old_card)
+ gtk_object_ref (GTK_OBJECT (new_dest->priv->old_card));
+
new_dest->priv->html_mail_override = dest->priv->html_mail_override;
new_dest->priv->wants_html_mail = dest->priv->wants_html_mail;
@@ -237,10 +249,16 @@ e_destination_clear_card (EDestination *dest)
g_free (dest->priv->card_uid);
dest->priv->card_uid = NULL;
- if (dest->priv->card)
- gtk_object_unref (GTK_OBJECT (dest->priv->card));
- dest->priv->card = NULL;
+ 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;
+ }
+
+ dest->priv->card = NULL;
dest->priv->card_email_num = -1;
g_list_foreach (dest->priv->list_dests, (GFunc) gtk_object_unref, NULL);
@@ -270,6 +288,9 @@ e_destination_clear_strings (EDestination *dest)
g_free (dest->priv->addr);
dest->priv->addr = NULL;
+ g_free (dest->priv->textrep);
+ dest->priv->textrep = NULL;
+
e_destination_changed (dest);
}
@@ -290,7 +311,7 @@ gboolean
e_destination_is_empty (const EDestination *dest)
{
struct _EDestinationPrivate *p;
- g_return_val_if_fail (dest && E_IS_DESTINATION (dest), TRUE);
+ g_return_val_if_fail (E_IS_DESTINATION (dest), TRUE);
p = dest->priv;
return !(p->card != NULL
@@ -304,6 +325,20 @@ e_destination_is_empty (const EDestination *dest)
}
gboolean
+e_destination_is_valid (const EDestination *dest)
+{
+ const gchar *email;
+
+ g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE);
+
+ if (dest->priv->card != NULL)
+ return TRUE;
+
+ email = e_destination_get_email (dest);
+ return email && *email && strchr (email, '@');
+}
+
+gboolean
e_destination_equal (const EDestination *a, const EDestination *b)
{
const struct _EDestinationPrivate *pa, *pb;
@@ -419,19 +454,25 @@ e_destination_set_card_uid (EDestination *dest, const gchar *uid, gint email_num
void
e_destination_set_name (EDestination *dest, const gchar *name)
{
- g_return_if_fail (dest && E_IS_DESTINATION (dest));
- g_return_if_fail (name != NULL);
+ gboolean changed = FALSE;
- if (dest->priv->name == NULL || strcmp (dest->priv->name, name)) {
+ g_return_if_fail (E_IS_DESTINATION (dest));
+ if (name == NULL) {
+ if (dest->priv->name != NULL) {
+ g_free (dest->priv->name);
+ dest->priv->name = NULL;
+ changed = TRUE;
+ }
+ } else if (dest->priv->name == NULL || strcmp (dest->priv->name, name)) {
g_free (dest->priv->name);
dest->priv->name = g_strdup (name);
+ changed = TRUE;
+ }
- if (dest->priv->addr != NULL) {
- g_free (dest->priv->addr);
- dest->priv->addr = NULL;
- }
-
+ if (changed) {
+ g_free (dest->priv->addr);
+ dest->priv->addr = NULL;
e_destination_changed (dest);
}
}
@@ -439,19 +480,27 @@ e_destination_set_name (EDestination *dest, const gchar *name)
void
e_destination_set_email (EDestination *dest, const gchar *email)
{
- g_return_if_fail (dest && E_IS_DESTINATION (dest));
- g_return_if_fail (email != NULL);
+ gboolean changed = FALSE;
- if (dest->priv->email == NULL || strcmp (dest->priv->email, email)) {
-
- g_free (dest->priv->email);
- dest->priv->email = g_strdup (email);
+ g_return_if_fail (E_IS_DESTINATION (dest));
- if (dest->priv->addr != NULL) {
+ 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)) {
+ g_free (dest->priv->email);
+ dest->priv->email = g_strdup (email);
+ changed = TRUE;
+ }
+
+
+ if (changed) {
+ g_free (dest->priv->addr);
+ dest->priv->addr = NULL;
e_destination_changed (dest);
}
}
@@ -750,20 +799,32 @@ e_destination_set_raw (EDestination *dest, const gchar *raw)
const gchar *
e_destination_get_textrep (const EDestination *dest)
{
- const gchar *txt;
+ const gchar *name, *email;
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
if (dest->priv->raw)
return dest->priv->raw;
- txt = e_destination_get_name (dest);
- if (txt != NULL)
- return txt;
+ name = e_destination_get_name (dest);
+ email = e_destination_get_email (dest);
+
+ if (e_destination_from_card (dest) && name != NULL)
+ return name;
- txt = e_destination_get_email (dest);
- if (txt != NULL)
- return txt;
+ if (name && email) {
+ gchar *rep = g_strdup_printf ("%s <%s>", name, email);
+ if (dest->priv->textrep && !strcmp (rep, dest->priv->textrep)) {
+ g_free (rep);
+ } else {
+ g_free (dest->priv->textrep);
+ dest->priv->textrep = rep;
+ }
+ return dest->priv->textrep;
+ }
+
+ if (email)
+ return email;
return "";
}
@@ -943,6 +1004,11 @@ e_destination_cardify (EDestination *dest, EBook *book)
e_destination_cancel_cardify (dest);
+ /* In some cases, we can revert to the previous card. */
+ if (!e_destination_is_valid (dest) && e_destination_revert (dest)) {
+ return;
+ }
+
set_cardify_book (dest, book);
/* Handle the case of an EDestination containing a card URL */
@@ -996,15 +1062,54 @@ e_destination_cancel_cardify (EDestination *dest)
}
}
-#if 0
-void
+gboolean
e_destination_uncardify (EDestination *dest)
{
- g_return_if_fail (E_IS_DESTINATION (dest));
+ gchar *email;
- g_assert_not_reached ();
+ g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE);
+
+ 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;
+}
+
+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;
+
+ card = dest->priv->old_card;
+ card_email_num = dest->priv->old_card_email_num;
+
+ dest->priv->old_card = 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;
}
-#endif
/*
* Destination import/export
@@ -1216,6 +1321,9 @@ 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;
e_destination_thaw (dest);
@@ -1390,6 +1498,42 @@ e_destination_importv (const gchar *str)
return destv;
}
+EDestination **
+e_destination_list_to_vector (GList *list)
+{
+ gint N = g_list_length (list);
+ EDestination **destv;
+ gint i = 0;
+
+ if (N == 0)
+ return NULL;
+
+ destv = g_new (EDestination *, N+1);
+ while (list != NULL) {
+ destv[i] = E_DESTINATION (list->data);
+ list->data = NULL;
+ ++i;
+ list = g_list_next (list);
+ }
+ destv[N] = NULL;
+
+ return destv;
+}
+
+void
+e_destination_freev (EDestination **destv)
+{
+ gint i;
+
+ if (destv) {
+ for (i = 0; destv[i] != NULL; ++i) {
+ gtk_object_unref (GTK_OBJECT (destv[i]));
+ }
+ g_free (destv);
+ }
+
+}
+
static void
touch_cb (EBook *book, const gchar *addr, ECard *card, gpointer closure)
{
@@ -1413,3 +1557,15 @@ e_destination_touch (EDestination *dest)
e_book_query_address_locally (email, touch_cb, NULL);
}
}
+
+void
+e_destination_touchv (EDestination **destv)
+{
+ gint i;
+
+ g_return_if_fail (destv != NULL);
+
+ for (i = 0; destv[i] != NULL; ++i) {
+ e_destination_touch (destv[i]);
+ }
+}