diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-03-02 05:03:02 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-03-02 05:03:02 +0800 |
commit | ce67772c53108003cd8ba2bf2130722ab17d5df8 (patch) | |
tree | 1b732c251e8cbf340ea060f8737fe504dadc7d77 /addressbook/backend/ebook/e-destination.c | |
parent | fae87e8d3d4e69f40b6c3e51ea2c8c8477995857 (diff) | |
download | gsoc2013-evolution-ce67772c53108003cd8ba2bf2130722ab17d5df8.tar.gz gsoc2013-evolution-ce67772c53108003cd8ba2bf2130722ab17d5df8.tar.zst gsoc2013-evolution-ce67772c53108003cd8ba2bf2130722ab17d5df8.zip |
Change for new EDestination/ESelectNamesModel API.
2001-03-01 Jon Trowbridge <trow@ximian.com>
* gui/component/select-names/e-select-names-table-model.c
(fill_in_info): Change for new EDestination/ESelectNamesModel API.
* gui/component/select-names/e-select-names-manager.c
(e_select_names_manager_get_source): Added. A function for
looking up the ESelectNamesModel by id. (I didn't end up using
this function, but it might come in handy later.)
(e_select_names_manager_get_cards): #if 0/#endif out this
function.
(e_select_names_manager_create_entry): Modified to attach an
ESelectNamesCompletion to the entry we create.
(completion_handler): A post-completion handler for our EEntry, to
take the completion's extra data (an EDestination) and properly
stick it into our ESelectNamesModel.
* gui/component/select-names/e-select-names.c
(real_add_address_cb): Changed to operate on EDestinations rather
than ECards and to use the new ESelectNamesModel API. This leads
to a rather nice code simplication.
(remove_address): Changed for new ESelectNamesModel API.
* gui/component/select-names/e-select-names-bonobo.c
(entry_get_property_fn): Rather than just passing the entry's text
through the property bag, get the "address text" from the model.
This returns a nice, verbose string of addresses with names
expanded when the address is tied to an ECard (i.e. "Jon
Trowbridge <trow@ximian.com>").
(impl_SelectNames_get_entry_for_section): Make the text property
read-only.
(entry_set_property_fn): ...and since it is read-only now, chop
out the setter code.
* gui/component/select-names/e-select-names-text-model.h:
* gui/component/select-names/e-select-names-text-model.c: Again,
this code has been (pretty much) totally rewritten to convert all
text operations into changes on the ESelectNamesModel. This lets
us give the associated EEntry some (IMHO) nice semantics regarding
whitespace, etc. Includes object activation, so destinations tied
to ECards are underlined and can be double-clicked to bring up a
contact editor.
* gui/component/select-names/e-select-names-model.h:
* gui/component/select-names/e-select-names-model.c: I've heavily
modified this object to both hide all implementation details
(which the old version exposed a bit too much for my peculiar
tastes) and to act as an EDestination container. The old code put
the text model operations here. I've moved them all to
ESelectNamesTextModel --- so the text model actions (insert,
delete, etc.) are all done through the API rather than operating on
ESelectNamesModel internals.
* gui/component/select-names/e-select-names-completion.c: Added. A
fairly complicated object derived from ECompletion that searches
our local addressbook in various and sundry ways.
* gui/component/select-names/e-select-names-completion.h:
* backend/ebook/e-destination.h:
* backend/ebook/e-destination.c: Added. This object encapsulates
a place to sent an email to, which can either be just a address as
a string ("trow@ximian.com"), a fancier string ("Jon Trowbridge
<trow@ximian.com>"), or an ECard and a specific address within
that ECard.
svn path=/trunk/; revision=8459
Diffstat (limited to 'addressbook/backend/ebook/e-destination.c')
-rw-r--r-- | addressbook/backend/ebook/e-destination.c | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c new file mode 100644 index 0000000000..92aed64715 --- /dev/null +++ b/addressbook/backend/ebook/e-destination.c @@ -0,0 +1,284 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * e-destination.c + * + * Copyright (C) 2001 Ximian, Inc. + * + * Developed by Jon Trowbridge <trow@ximian.com> + */ + +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +#include <config.h> +#include <gtk/gtk.h> +#include <libgnome/gnome-defs.h> +#include <libgnome/gnome-i18n.h> +#include "e-destination.h" + +struct _EDestinationPrivate { + ECard *card; + gint card_email_num; + + gchar *string; + gchar *string_email; + gchar *string_email_verbose; +}; + +static void e_destination_clear_card (EDestination *); +static void e_destination_clear_strings (EDestination *); + +static GtkObjectClass *parent_class; + +static void +e_destination_destroy (GtkObject *obj) +{ + EDestination *dest = E_DESTINATION (obj); + + e_destination_clear_card (dest); + e_destination_clear_strings (dest); + + g_free (dest->priv); + + if (parent_class->destroy) + parent_class->destroy (obj); +} + +static void +e_destination_class_init (EDestinationClass *klass) +{ + GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); + + parent_class = GTK_OBJECT_CLASS (gtk_type_class (GTK_TYPE_OBJECT)); + + object_class->destroy = e_destination_destroy; +} + +static void +e_destination_init (EDestination *dest) +{ + dest->priv = g_new0 (struct _EDestinationPrivate, 1); +} + +GtkType +e_destination_get_type (void) +{ + static GtkType dest_type = 0; + + if (!dest_type) { + GtkTypeInfo dest_info = { + "EDestination", + sizeof (EDestination), + sizeof (EDestinationClass), + (GtkClassInitFunc) e_destination_class_init, + (GtkObjectInitFunc) e_destination_init, + NULL, NULL, /* reserved */ + (GtkClassInitFunc) NULL + }; + + dest_type = gtk_type_unique (gtk_object_get_type (), &dest_info); + } + + return dest_type; +} + +EDestination * +e_destination_new (void) +{ + return E_DESTINATION (gtk_type_new (E_TYPE_DESTINATION)); +} + +EDestination * +e_destination_copy (EDestination *dest) +{ + EDestination *new_dest; + + g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); + + new_dest = e_destination_new (); + + new_dest->priv->card = dest->priv->card; + if (new_dest->priv->card) + gtk_object_ref (GTK_OBJECT (new_dest->priv->card)); + + new_dest->priv->card_email_num = dest->priv->card_email_num; + + new_dest->priv->string = g_strdup (dest->priv->string); + new_dest->priv->string_email = g_strdup (dest->priv->string_email); + new_dest->priv->string_email_verbose = g_strdup (dest->priv->string_email_verbose); + + return new_dest; +} + +static void +e_destination_clear_card (EDestination *dest) +{ + if (dest->priv->card) + gtk_object_unref (GTK_OBJECT (dest->priv->card)); + dest->priv->card = NULL; + + dest->priv->card_email_num = -1; +} + +static void +e_destination_clear_strings (EDestination *dest) +{ + g_free (dest->priv->string); + g_free (dest->priv->string_email); + g_free (dest->priv->string_email_verbose); + + dest->priv->string = NULL; + dest->priv->string_email = NULL; + dest->priv->string_email_verbose = NULL; +} + +void +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) { + if (dest->priv->card) + gtk_object_unref (GTK_OBJECT (dest->priv->card)); + dest->priv->card = card; + gtk_object_ref (GTK_OBJECT (card)); + } + + dest->priv->card_email_num = email_num; + + e_destination_clear_strings (dest); +} + +void +e_destination_set_string (EDestination *dest, const gchar *string) +{ + g_return_if_fail (dest && E_IS_DESTINATION (dest)); + g_return_if_fail (string != NULL); + + g_free (dest->priv->string); + dest->priv->string = g_strdup (string); +} + +ECard * +e_destination_get_card (const EDestination *dest) +{ + g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); + + return dest->priv->card; +} + +const gchar * +e_destination_get_string (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->string == NULL) { + + if (priv->card) { + + priv->string = e_card_name_to_string (priv->card->name); + + } + } + + return priv->string; +} + +gint +e_destination_get_strlen (const EDestination *dest) +{ + const gchar *str; + + g_return_val_if_fail (dest && E_IS_DESTINATION (dest), 0); + + str = e_destination_get_string (dest); + return str ? strlen (str) : 0; +} + +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->string_email == NULL) { + + if (priv->card) { /* Pull the address out of the card. */ + + EIterator *iter = e_list_get_iterator (priv->card->email); + gint n = priv->card_email_num; + + if (n >= 0) { + while (n > 0) { + e_iterator_next (iter); + --n; + } + + if (e_iterator_is_valid (iter)) { + gconstpointer ptr = e_iterator_get (iter); + priv->string_email = g_strdup ((gchar *) ptr); + } + } + + } else if (priv->string) { /* Use the string as an e-mail address */ + return priv->string; + } + + /* else we just return NULL */ + } + + return priv->string_email; +} + +const gchar * +e_destination_get_email_verbose (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->string_email_verbose == NULL) { + + const gchar *email = e_destination_get_email (dest); + + if (priv->card) { + + priv->string_email_verbose = g_strdup_printf ("%s <%s>", + e_card_name_to_string (priv->card->name), + email); + } else { + + return email; + } + + } + + return priv->string_email_verbose; +} + + |