From 19ec5dbb3b419740b0a9e84ba4c6667cb48c5631 Mon Sep 17 00:00:00 2001 From: Jon Trowbridge Date: Thu, 30 Aug 2001 04:57:18 +0000 Subject: Use e_select_names_model_merge to combine the selected names with any 2001-08-29 Jon Trowbridge * gui/component/select-names/e-select-names-manager.c (e_select_names_clicked): Use e_select_names_model_merge to combine the selected names with any existing ones. This causes you to not lose addresses typed directly into the entry while the SelectNames dialog is up. (Bug #8058) * gui/component/select-names/e-select-names-model.c (e_select_names_model_merge): Merge the contents of one ESelectNamesModel into another, avoiding duplicates. * backend/ebook/e-destination.c (e_destination_equal): Added. Determines if two destinations appear to refer to the same recipient. * backend/ebook/e-card.c (e_card_list_send): Added cast to g_free args to silence compiler warnings. svn path=/trunk/; revision=12526 --- addressbook/ChangeLog | 17 ++++++++++ addressbook/backend/ebook/e-card.c | 4 +-- addressbook/backend/ebook/e-destination.c | 38 ++++++++++++++++++++++ addressbook/backend/ebook/e-destination.h | 1 + .../select-names/e-select-names-manager.c | 2 +- .../component/select-names/e-select-names-model.c | 35 ++++++++++++++++++++ .../component/select-names/e-select-names-model.h | 3 ++ 7 files changed, 97 insertions(+), 3 deletions(-) (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index f86356d6f9..5302057895 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,5 +1,22 @@ 2001-08-29 Jon Trowbridge + * gui/component/select-names/e-select-names-manager.c + (e_select_names_clicked): Use e_select_names_model_merge to + combine the selected names with any existing ones. This causes + you to not lose addresses typed directly into the entry while the + SelectNames dialog is up. (Bug #8058) + + * gui/component/select-names/e-select-names-model.c + (e_select_names_model_merge): Merge the contents of one + ESelectNamesModel into another, avoiding duplicates. + + * backend/ebook/e-destination.c (e_destination_equal): Added. + Determines if two destinations appear to refer to the same + recipient. + + * backend/ebook/e-card.c (e_card_list_send): Added cast to + g_free args to silence compiler warnings. + * gui/contact-editor/e-contact-quick-add.c (quick_add_set_name): Paranoia. Check that name != qa->name. (quick_add_set_email): Check that email != qa->email. diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c index 725fedaa11..57619b0080 100644 --- a/addressbook/backend/ebook/e-card.c +++ b/addressbook/backend/ebook/e-card.c @@ -4055,8 +4055,8 @@ e_card_list_send (GList *cards, ECardDisposition disposition) recipient->address = CORBA_string_dup (addr ? addr : ""); if (free_name_addr) { - g_free (name); - g_free (addr); + g_free ((gchar *) name); + g_free ((gchar *) addr); } /* If this isn't a list, we quit after the first (i.e. the default) address. */ diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c index 5776f2c253..9e0e4b6067 100644 --- a/addressbook/backend/ebook/e-destination.c +++ b/addressbook/backend/ebook/e-destination.c @@ -303,6 +303,44 @@ e_destination_is_empty (const EDestination *dest) || (p->list_dests != NULL)); } +gboolean +e_destination_equal (const EDestination *a, const EDestination *b) +{ + const struct _EDestinationPrivate *pa, *pb; + const gchar *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; + } + + /* Just in case name returns NULL */ + na = e_destination_get_name (a); + nb = e_destination_get_name (b); + if ((na || nb) && !(na && nb && !strcmp (na, nb))) + return FALSE; + + if (!strcmp (e_destination_get_email (a), e_destination_get_email (b))) + return TRUE; + + return FALSE; +} + void e_destination_set_card (EDestination *dest, ECard *card, gint email_num) { diff --git a/addressbook/backend/ebook/e-destination.h b/addressbook/backend/ebook/e-destination.h index c0ab60d33f..b9b06c47ff 100644 --- a/addressbook/backend/ebook/e-destination.h +++ b/addressbook/backend/ebook/e-destination.h @@ -68,6 +68,7 @@ EDestination *e_destination_copy (const EDestination *); void e_destination_clear (EDestination *); gboolean e_destination_is_empty (const EDestination *); +gboolean e_destination_equal (const EDestination *a, const EDestination *b); void e_destination_set_card (EDestination *, ECard *card, gint email_num); void e_destination_set_book_uri (EDestination *, const gchar *uri); diff --git a/addressbook/gui/component/select-names/e-select-names-manager.c b/addressbook/gui/component/select-names/e-select-names-manager.c index 0bec7da416..3212242fbd 100644 --- a/addressbook/gui/component/select-names/e-select-names-manager.c +++ b/addressbook/gui/component/select-names/e-select-names-manager.c @@ -472,7 +472,7 @@ e_select_names_clicked(ESelectNames *dialog, gint button, ESelectNamesManager *m for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { ESelectNamesManagerSection *section = (void *) e_iterator_get(iterator); ESelectNamesModel *source = e_select_names_get_source(dialog, section->id); - e_select_names_model_overwrite_copy (section->model, source); + e_select_names_model_merge (section->model, source); gtk_object_unref (GTK_OBJECT (source)); } diff --git a/addressbook/gui/component/select-names/e-select-names-model.c b/addressbook/gui/component/select-names/e-select-names-model.c index 6e0482ade3..66d7e96bb4 100644 --- a/addressbook/gui/component/select-names/e-select-names-model.c +++ b/addressbook/gui/component/select-names/e-select-names-model.c @@ -465,6 +465,22 @@ disconnect_destination (ESelectNamesModel *model, EDestination *dest) gtk_signal_disconnect_by_func (GTK_OBJECT (dest), destination_changed_proxy, model); } +gboolean +e_select_names_model_contains (ESelectNamesModel *model, EDestination *dest) +{ + GList *iter; + + g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), FALSE); + g_return_val_if_fail (E_IS_DESTINATION (dest), FALSE); + + for (iter = model->priv->data; iter != NULL; iter = g_list_next (iter)) { + if (iter->data != NULL && e_destination_equal (dest, E_DESTINATION (iter->data))) + return TRUE; + } + + return FALSE; +} + void e_select_names_model_insert (ESelectNamesModel *model, gint index, EDestination *dest) { @@ -651,6 +667,25 @@ e_select_names_model_overwrite_copy (ESelectNamesModel *dest, ESelectNamesModel } } +void +e_select_names_model_merge (ESelectNamesModel *dest, ESelectNamesModel *src) +{ + gint i, len; + + g_return_if_fail (E_IS_SELECT_NAMES_MODEL (dest)); + g_return_if_fail (E_IS_SELECT_NAMES_MODEL (src)); + + if (src == dest) + return; + + len = e_select_names_model_count (src); + for (i = 0; i < len; ++i) { + const EDestination *d = e_select_names_model_get_destination (src, i); + if (d && !e_select_names_model_contains (dest, d)) + e_select_names_model_append (dest, e_destination_copy (d)); + } +} + void e_select_names_model_name_pos (ESelectNamesModel *model, gint index, gint *pos, gint *length) { diff --git a/addressbook/gui/component/select-names/e-select-names-model.h b/addressbook/gui/component/select-names/e-select-names-model.h index 9f89e91093..9fca3897db 100644 --- a/addressbook/gui/component/select-names/e-select-names-model.h +++ b/addressbook/gui/component/select-names/e-select-names-model.h @@ -61,12 +61,15 @@ void e_select_names_model_import_destinationv (ESelectNamesModel ECard *e_select_names_model_get_card (ESelectNamesModel *model, gint index); const gchar *e_select_names_model_get_string (ESelectNamesModel *model, gint index); +gboolean e_select_names_model_contains (ESelectNamesModel *model, EDestination *dest); + void e_select_names_model_insert (ESelectNamesModel *model, gint index, EDestination *dest); void e_select_names_model_append (ESelectNamesModel *model, EDestination *dest); void e_select_names_model_replace (ESelectNamesModel *model, gint index, EDestination *dest); void e_select_names_model_delete (ESelectNamesModel *model, gint index); void e_select_names_model_delete_all (ESelectNamesModel *model); void e_select_names_model_overwrite_copy (ESelectNamesModel *dest, ESelectNamesModel *src); +void e_select_names_model_merge (ESelectNamesModel *dest, ESelectNamesModel *src); void e_select_names_model_clean (ESelectNamesModel *model); -- cgit v1.2.3