diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-07-07 14:38:52 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-07-07 14:38:52 +0800 |
commit | da9c4d10641eed27263f12c7415100348991ef32 (patch) | |
tree | 50428b4e028ce83e81502b142920753bb61a2a31 /addressbook/backend/ebook/e-card.c | |
parent | 5304dda169dd9778def88176572bb76eeaf0883b (diff) | |
download | gsoc2013-evolution-da9c4d10641eed27263f12c7415100348991ef32.tar gsoc2013-evolution-da9c4d10641eed27263f12c7415100348991ef32.tar.gz gsoc2013-evolution-da9c4d10641eed27263f12c7415100348991ef32.tar.bz2 gsoc2013-evolution-da9c4d10641eed27263f12c7415100348991ef32.tar.lz gsoc2013-evolution-da9c4d10641eed27263f12c7415100348991ef32.tar.xz gsoc2013-evolution-da9c4d10641eed27263f12c7415100348991ef32.tar.zst gsoc2013-evolution-da9c4d10641eed27263f12c7415100348991ef32.zip |
Detect the embedded EDestination XML, and convert it to a nice-looking
2001-07-07 Jon Trowbridge <trow@ximian.com>
* gui/widgets/e-minicard.c (add_field): Detect the embedded
EDestination XML, and convert it to a nice-looking e-mail address.
* gui/contact-list-editor/e-contact-list-editor.c: Adjusted to
reflect changes to EContactListModel. (Yeah, this is vague,
but the changes are _really_ obvious and boring.)
* gui/contact-list-editor/e-contact-list-model.c: Revamped
to make everything an EDestination, rather than storing either
cards or strings.
* gui/component/select-names/e-select-names-text-model.c
(e_select_names_text_model_insert_length): Use
e_destination_get_textrep.
* gui/component/select-names/e-select-names-table-model.c
(fill_in_info): Use e_destination_get_name and
e_destination_get_email.
* gui/component/select-names/e-select-names-popup.c
(popup_menu_card): Use e_destination_get_name instead of
e_card_name_to_string.
(quick_add_cb): Use e_destination_get_address.
(popup_menu_nocard): Use e_destination_get_name.
* gui/component/select-names/e-select-names-model.c
(e_select_names_model_changed): Removed obsolete debugging code.
(e_select_names_model_get_textification): Use e_destination_get_textrep\.
(e_select_names_model_get_address_text): Use e_destination_get_address.
(e_select_names_model_get_string): Use e_destination_get_textrep.
(e_select_names_model_replace): Use e_destination_get_textrep.
(e_select_names_model_name_pos): Use e_destination_get_textrep.
* gui/component/select-names/e-select-names-completion.c
(emailify_match): Match only if this isn't a contact list.
(match_email): Match only if this isn't a contact list.
(match_name): Do the right thing in the case of a contact list.
(book_query_process_card_list): Don't construct a match for
each possible e-mail address if this is a contact list.
* backend/ebook/e-destination.c: Major-league de-crufting and
rationalization, combined with lots of hacks to make things work
properly with contact lists.
(e_destination_copy): Copy contact list info.
(e_destination_clear_card): Clear contact list info.
(e_destination_is_empty): If we contain a contact list, we aren't
empty.
(e_destination_set_card_uri): Added. Allows us to set a
destination by card URI.
(e_destination_set_name): Allows the contact's name only ("Jane
Smith") to be set.
(e_destination_set_email): Allows the contact's e-mail only
("jane@assbarn.com") to be set.
(e_destination_set_string): Takes a free-form string containing a
contact's name and/or e-mail, and tries to do the right thing with
it.
(e_destination_contains_card): Renamed. Used to be
e_destination_has_card.
(e_destination_from_card): Added. Returns TRUE if the
EDestination comes from either a ECard (which we presently hold)
or is specified by an ECard URI.
(e_destination_use_card): Allows an EDestination's ECard to be
accessed, via a callback. If we only are holding the URI, the
card will be loaded and stored in the EDestination.
(e_destination_get_name): Returns the name only ("Jane Smith"), or
NULL.
(e_destination_get_email): Returns the email only
("jane@assbarn.com"), or NULL.
(e_destination_get_address): Added. Returns a "full address" if
both the name & e-mail are available ("Jane Smith
<jane@assbarn.com>"), or just the e-mail if the name is unknown
("jane@assbarn.com>"). If the destination is a contact list,
returns a comma-separated list of addresses.
(e_destination_get_textrep): Added. Returns a "text
representation" of the EDestination. This is what is now
displayed for completed, "cardified" destinations in addressbook
entries.
(e_destination_is_evolution_list): Check to see if this
destination is for a contact list.
(e_destination_xml_encode): Added. Build an XML data structure
representing an EDestination.
(e_destination_xml_decode): Added. Parse an XML data structure,
constructing an EDestination.
(e_destination_export): Added. Returns a null-terminated string
containing an XML representation of the EDestination, with
newlines and excess whitespace removed.
(e_destination_import): Added. Parses a string containing an XML
representation of an EDestination.
(e_destination_exportv): Added. Returns a null-terminated string
containing an XML representation of a collection of EDestinations,
with newlines and excess whitespace removed.
(e_destination_importv): Added. Takes an XML representation of a
collection of destinations, parses it, and returns a vector of
EDestinations.
* backend/ebook/e-card.c (e_card_duplicate): Copy the ->book
pointer.
(e_card_get_id): Check that the argument is valid.
(e_card_set_id): Check that the argument is valid.
(e_card_get_book): Added. Return the EBook the ECard came from.
(e_card_get_uri): Added. Tries to returns a URI for the ECard,
which is of the form (EBook URI)/(ECard unique ID). Returns NULL
if the EBook URI or the ID are unknown/not set.
(e_card_get_vobject): If we have the URI, use it as the
VCUniqueStringProp, rather than just the ID. This is a hack to
make DnD work properly.
(parse_id): Detect if the unique ID we've been passed is a URI or
just a plain card ID, and do the right thing in either case.
(e_card_uri_extract_book_uri): Added. Convenience function for
parsing card URIs.
(e_card_uri_extract_card_id): Added. Convenience function for
parsing card URIs.
(e_card_load_uri): Added. Allows an ECard to be loaded by its
URI.
* backend/ebook/e-book-view.c: Added a EBook * to the
_EBookViewPrivate struct. This is meant to contain the EBook the
EBookView is associated with.
(add_book_iterator): Added. A convenience function for attaching
the EBook to a GList of cards (if no EBook is already stored).
(e_book_view_do_added_event): Record the EBook in the added
ECards.
(e_book_view_do_modified_event): Record the EBook in the modified
ECards.
(e_book_view_set_book): Added. Stores a pointer to the
EBookView's "parent" EBook.
(e_book_view_init): Init book_view->priv->book to NULL.
(e_book_view_destroy): Unref book_view->priv->book.
* backend/ebook/e-book.c: Added a uri field to _EBookPrivate.
(e_book_unqueue_op): Removed debugging spew.
(e_book_do_response_get_view): Attach the current EBook to the
created EBookView.
(e_book_do_response_get_changes): Attach the current EBook to the
created EBookView.
(e_book_load_uri): Save a copy of the uri in the EBook.
(e_book_get_uri): Added. Just returns book->priv->uri.
(e_book_get_card): Attach a pointer to the Ebook to the
newly-loaded ECard.
(e_book_add_card): Attach a pointer to the EBook to the
newly-added ECard.
(e_book_commit_card): Attach a pointer to the EBook to the
committed ECard.
(e_book_init): Initialize the uri to NULL.
(e_book_destroy): Free the uri string on destruction.
svn path=/trunk/; revision=10882
Diffstat (limited to 'addressbook/backend/ebook/e-card.c')
-rw-r--r-- | addressbook/backend/ebook/e-card.c | 144 |
1 files changed, 139 insertions, 5 deletions
diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c index 044f27be3b..53ba425a48 100644 --- a/addressbook/backend/ebook/e-card.c +++ b/addressbook/backend/ebook/e-card.c @@ -28,6 +28,7 @@ #include <libversit/vcc.h> #include "e-util/ename/e-name-western.h" #include "e-util/ename/e-address-western.h" +#include "e-book.h" #define is_a_prop_of(obj,prop) (isAPropertyOf ((obj),(prop))) #define str_val(obj) (the_str = (vObjectValueType (obj))? fakeCString (vObjectUStringZValue (obj)) : calloc (1, 1)) @@ -129,6 +130,9 @@ static void set_phone_flags (VObject *vobj, ECardPhoneFlags flags); static ECardAddressFlags get_address_flags (VObject *vobj); static void set_address_flags (VObject *vobj, ECardAddressFlags flags); +static gchar *e_card_uri_extract_book_uri (const gchar *uri); +static gchar *e_card_uri_extract_card_id (const gchar *uri); + typedef void (* ParsePropertyFunc) (ECard *card, VObject *object); struct { @@ -234,6 +238,12 @@ e_card_duplicate(ECard *card) char *vcard = e_card_get_vcard(card); ECard *new_card = e_card_new(vcard); g_free (vcard); + + if (card->book) { + new_card->book = card->book; + gtk_object_ref (GTK_OBJECT (new_card->book)); + } + return new_card; } @@ -306,6 +316,8 @@ e_card_touch(ECard *card) const char * e_card_get_id (ECard *card) { + g_return_val_if_fail (card && E_IS_CARD (card), NULL); + return card->id; } @@ -320,11 +332,34 @@ e_card_get_id (ECard *card) void e_card_set_id (ECard *card, const char *id) { + g_return_if_fail (card && E_IS_CARD (card)); + if ( card->id ) g_free(card->id); card->id = g_strdup(id); } +EBook * +e_card_get_book (ECard *card) +{ + g_return_val_if_fail (card && E_IS_CARD (card), NULL); + + return card->book; +} + +const gchar * +e_card_get_uri (ECard *card) +{ + g_return_val_if_fail (card && E_IS_CARD (card), NULL); + + if (card->uri == NULL && card->id && *card->id && card->book) { + const char *book_uri = e_book_get_uri (card->book); + if (book_uri) + card->uri = g_strdup_printf ("%s/%s", book_uri, card->id); + } + return card->uri; +} + static gchar * e_card_date_to_string (ECardDate *dt) { @@ -341,6 +376,7 @@ static VObject * e_card_get_vobject (ECard *card) { VObject *vobj; + const char *tmp; vobj = newVObject (VCCardProp); @@ -571,8 +607,14 @@ e_card_get_vobject (ECard *card) } } - if (card->id) - addPropValue (vobj, VCUniqueStringProp, card->id); + tmp = e_card_get_uri (card); + if (tmp == NULL) + tmp = card->id; + if (tmp) { + g_message ("unique string = [%s]", tmp); + addPropValue (vobj, VCUniqueStringProp, tmp); + } + #if 0 @@ -1083,9 +1125,24 @@ parse_arbitrary(ECard *card, VObject *vobj) static void parse_id(ECard *card, VObject *vobj) { - if ( card->id ) - g_free(card->id); - assign_string(vobj, &(card->id)); + if ( vObjectValueType (vobj) ) { + gchar *str = fakeCString (vObjectUStringZValue (vobj)); + gchar *id; + if ( card->id ) + g_free(card->id); + if ( card->uri ) + g_free(card->uri); + + id = e_card_uri_extract_card_id (str); + if (id) { + card->id = id; + card->uri = g_strdup (str); + } else { + card->id = g_strdup (str); + card->uri = NULL; + } + free (str); + } } static void @@ -1770,6 +1827,9 @@ e_card_destroy (GtkObject *object) { ECard *card = E_CARD(object); g_free(card->id); + if (card->book) + gtk_object_unref (GTK_OBJECT (card->book)); + g_free(card->uri); g_free(card->file_as); g_free(card->fname); if ( card->name ) @@ -4047,3 +4107,77 @@ e_card_evolution_list_show_addresses (ECard *card) g_return_val_if_fail (card && E_IS_CARD (card), FALSE); return card->list_show_addresses; } + +static gchar * +e_card_uri_extract_book_uri (const gchar *uri) +{ + gchar *lastslash; + + if (uri == NULL) + return NULL; + + lastslash = strrchr (uri, '/'); + if (lastslash == NULL) + return NULL; + + return g_strndup (uri, lastslash - uri); +} + +static gchar * +e_card_uri_extract_card_id (const gchar *uri) +{ + gchar *lastslash; + + if (uri == NULL) + return NULL; + + lastslash = strrchr (uri, '/'); + return lastslash ? g_strdup (lastslash+1) : NULL; +} + +typedef struct _CardLoadData CardLoadData; +struct _CardLoadData { + gchar *card_id; + ECardCallback cb; + gpointer closure; +}; + +static void +card_load_cb (EBook *book, EBookStatus status, gpointer closure) +{ + CardLoadData *data = (CardLoadData *) closure; + ECard *card = NULL; + + if (status == E_BOOK_STATUS_SUCCESS) + card = e_book_get_card (book, data->card_id); + + if (data->cb != NULL) + data->cb (card, data->closure); + + g_free (data->card_id); + g_free (data); +} + +void +e_card_load_uri (const gchar *uri, ECardCallback cb, gpointer closure) +{ + CardLoadData *data; + gchar *book_uri; + gchar *card_id; + EBook *book; + + g_return_if_fail (uri != NULL); + + book_uri = e_card_uri_extract_book_uri (uri); + card_id = e_card_uri_extract_card_id (uri); + + data = g_new (CardLoadData, 1); + data->card_id = g_strdup (card_id); + data->cb = cb; + data->closure = closure; + + book = e_book_new (); + e_book_load_uri (book, book_uri, card_load_cb, data); + + g_free (book_uri); +} |