diff options
Diffstat (limited to 'addressbook/backend')
-rw-r--r-- | addressbook/backend/ebook/e-book-view.c | 5 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-book.c | 1 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.c | 112 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.h | 108 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-destination.c | 117 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-destination.h | 6 |
6 files changed, 177 insertions, 172 deletions
diff --git a/addressbook/backend/ebook/e-book-view.c b/addressbook/backend/ebook/e-book-view.c index 7dbe7d46fb..39aab8623f 100644 --- a/addressbook/backend/ebook/e-book-view.c +++ b/addressbook/backend/ebook/e-book-view.c @@ -47,10 +47,7 @@ add_book_iterator (gpointer data, gpointer closure) ECard *card = E_CARD (data); EBook *book = E_BOOK (closure); - if (card->book == NULL) { - card->book = book; - gtk_object_ref (GTK_OBJECT (book)); - } + e_card_set_book (card, book); } static void diff --git a/addressbook/backend/ebook/e-book.c b/addressbook/backend/ebook/e-book.c index 1d5baf33a3..a9b186b375 100644 --- a/addressbook/backend/ebook/e-book.c +++ b/addressbook/backend/ebook/e-book.c @@ -221,6 +221,7 @@ e_book_do_response_get_vcard (EBook *book, card = e_card_new(resp->vcard); if (card != NULL) { + e_card_set_book (card, book); if (op->cb) { if (op->active) ((EBookCardCallback) op->cb) (book, resp->status, card, op->closure); diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c index 5c1efb42f5..02b869a9bf 100644 --- a/addressbook/backend/ebook/e-card.c +++ b/addressbook/backend/ebook/e-card.c @@ -130,9 +130,6 @@ 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 { @@ -347,17 +344,16 @@ e_card_get_book (ECard *card) return card->book; } -const gchar * -e_card_get_uri (ECard *card) +void +e_card_set_book (ECard *card, EBook *book) { - 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; + g_return_if_fail (card && E_IS_CARD (card)); + + if (card->book) + gtk_object_unref (GTK_OBJECT (card->book)); + card->book = book; + if (card->book) + gtk_object_ref (GTK_OBJECT (card->book)); } static gchar * @@ -376,7 +372,6 @@ static VObject * e_card_get_vobject (ECard *card) { VObject *vobj; - const char *tmp; vobj = newVObject (VCCardProp); @@ -607,16 +602,9 @@ e_card_get_vobject (ECard *card) } } - tmp = e_card_get_uri (card); - if (tmp == NULL) - tmp = card->id; - if (tmp) { - addPropValue (vobj, VCUniqueStringProp, tmp); - } + addPropValue (vobj, VCUniqueStringProp, card->id); -#if 0 - - +#if 0 if (crd->photo.prop.used) { vprop = addPropSizedValue (vobj, VCPhotoProp, crd->photo.data, crd->photo.size); @@ -1124,24 +1112,8 @@ parse_arbitrary(ECard *card, VObject *vobj) static void parse_id(ECard *card, VObject *vobj) { - 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); - } + g_free(card->id); + assign_string(vobj, &(card->id)); } static void @@ -1847,7 +1819,6 @@ e_card_destroy (GtkObject *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 ) @@ -4136,33 +4107,6 @@ e_card_evolution_list_show_addresses (ECard *card) 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; @@ -4171,12 +4115,16 @@ struct _CardLoadData { }; static void -card_get_cb (EBook *book, EBookStatus status, ECard *card, gpointer closure) +get_card_cb (EBook *book, EBookStatus status, ECard *card, gpointer closure) { CardLoadData *data = (CardLoadData *) closure; - if (data->cb != NULL) - data->cb (card, data->closure); + if (data->cb != NULL) { + if (status == E_BOOK_STATUS_SUCCESS) + data->cb (card, data->closure); + else + data->cb (NULL, data->closure); + } g_free (data->card_id); g_free (data); @@ -4188,29 +4136,25 @@ card_load_cb (EBook *book, EBookStatus status, gpointer closure) CardLoadData *data = (CardLoadData *) closure; if (status == E_BOOK_STATUS_SUCCESS) - e_book_get_card (book, data->card_id, card_get_cb, closure); + e_book_get_card (book, data->card_id, get_card_cb, closure); + else { + data->cb (NULL, data->closure); + g_free (data->card_id); + g_free (data); + } } void -e_card_load_uri (const gchar *uri, ECardCallback cb, gpointer closure) +e_card_load_uri (const gchar *book_uri, const gchar *uid, 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->card_id = g_strdup (uid); 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); } diff --git a/addressbook/backend/ebook/e-card.h b/addressbook/backend/ebook/e-card.h index 83e074ff23..c870ae2978 100644 --- a/addressbook/backend/ebook/e-card.h +++ b/addressbook/backend/ebook/e-card.h @@ -34,7 +34,6 @@ struct _ECard { char *id; struct _EBook *book; /* The EBook this card is from. */ - gchar *uri; /* The card's uri (book uri + id) */ char *file_as; /* The File As field. */ char *fname; /* The full name. */ @@ -117,87 +116,88 @@ struct _ECardClass { /* Simple functions */ -ECard *e_card_new (char *vcard); -const char *e_card_get_id (ECard *card); -void e_card_set_id (ECard *card, - const char *character); - -struct _EBook *e_card_get_book (ECard *card); -const char *e_card_get_uri (ECard *card); - - -char *e_card_get_vcard (ECard *card); -char *e_card_list_get_vcard (GList *list); -ECard *e_card_duplicate (ECard *card); - -float e_card_get_use_score (ECard *card); -void e_card_touch (ECard *card); +ECard *e_card_new (char *vcard); +const char *e_card_get_id (ECard *card); +void e_card_set_id (ECard *card, + const char *character); + +struct _EBook *e_card_get_book (ECard *card); +void e_card_set_book (ECard *card, + struct _EBook *book); +char *e_card_get_vcard (ECard *card); +char *e_card_list_get_vcard (GList *list); +ECard *e_card_duplicate (ECard *card); +float e_card_get_use_score (ECard *card); +void e_card_touch (ECard *card); /* Evolution List convenience functions */ /* used for encoding uids in email addresses */ -gboolean e_card_evolution_list (ECard *card); -gboolean e_card_evolution_list_show_addresses(ECard *card); +gboolean e_card_evolution_list (ECard *card); +gboolean e_card_evolution_list_show_addresses (ECard *card); /* ECardPhone manipulation */ -ECardPhone *e_card_phone_new (void); -ECardPhone *e_card_phone_copy (const ECardPhone *phone); -void e_card_phone_free (ECardPhone *phone); +ECardPhone *e_card_phone_new (void); +ECardPhone *e_card_phone_copy (const ECardPhone *phone); +void e_card_phone_free (ECardPhone *phone); /* ECardDeliveryAddress manipulation */ -ECardDeliveryAddress *e_card_delivery_address_new (void); -ECardDeliveryAddress *e_card_delivery_address_copy (const ECardDeliveryAddress *addr); -void e_card_delivery_address_free (ECardDeliveryAddress *addr); -gboolean e_card_delivery_address_is_empty (const ECardDeliveryAddress *addr); -char *e_card_delivery_address_to_string (const ECardDeliveryAddress *addr); -ECardDeliveryAddress *e_card_delivery_address_from_label (const ECardAddrLabel *label); -ECardAddrLabel *e_card_delivery_address_to_label (const ECardDeliveryAddress *addr); +ECardDeliveryAddress *e_card_delivery_address_new (void); +ECardDeliveryAddress *e_card_delivery_address_copy (const ECardDeliveryAddress *addr); +void e_card_delivery_address_free (ECardDeliveryAddress *addr); +gboolean e_card_delivery_address_is_empty (const ECardDeliveryAddress *addr); +char *e_card_delivery_address_to_string (const ECardDeliveryAddress *addr); +ECardDeliveryAddress *e_card_delivery_address_from_label (const ECardAddrLabel *label); +ECardAddrLabel *e_card_delivery_address_to_label (const ECardDeliveryAddress *addr); /* ECardAddrLabel manipulation */ -ECardAddrLabel *e_card_address_label_new (void); -ECardAddrLabel *e_card_address_label_copy (const ECardAddrLabel *addr); -void e_card_address_label_free (ECardAddrLabel *addr); +ECardAddrLabel *e_card_address_label_new (void); +ECardAddrLabel *e_card_address_label_copy (const ECardAddrLabel *addr); +void e_card_address_label_free (ECardAddrLabel *addr); /* ECardName manipulation */ -ECardName *e_card_name_new (void); -ECardName *e_card_name_copy (const ECardName *name); -void e_card_name_free (ECardName *name); -char *e_card_name_to_string (const ECardName *name); -ECardName *e_card_name_from_string (const char *full_name); -gboolean e_card_name_match_string (const ECardName *name, - const gchar *str); +ECardName *e_card_name_new (void); +ECardName *e_card_name_copy (const ECardName *name); +void e_card_name_free (ECardName *name); +char *e_card_name_to_string (const ECardName *name); +ECardName *e_card_name_from_string (const char *full_name); +gboolean e_card_name_match_string (const ECardName *name, + const gchar *str); /* ECardArbitrary manipulation */ -ECardArbitrary *e_card_arbitrary_new (void); -ECardArbitrary *e_card_arbitrary_copy (const ECardArbitrary *arbitrary); -void e_card_arbitrary_free (ECardArbitrary *arbitrary); +ECardArbitrary *e_card_arbitrary_new (void); +ECardArbitrary *e_card_arbitrary_copy (const ECardArbitrary *arbitrary); +void e_card_arbitrary_free (ECardArbitrary *arbitrary); /* ECard email manipulation */ -gboolean e_card_email_match_string (const ECard *card, - const gchar *str); -gint e_card_email_find_number (const ECard *card, - const gchar *email); +gboolean e_card_email_match_string (const ECard *card, + const gchar *str); +gint e_card_email_find_number (const ECard *card, + const gchar *email); /* Specialized functionality */ -GList *e_card_load_cards_from_file (const char *filename); -GList *e_card_load_cards_from_string (const char *str); -void e_card_free_empty_lists (ECard *card); +GList *e_card_load_cards_from_file (const char *filename); +GList *e_card_load_cards_from_string (const char *str); +void e_card_free_empty_lists (ECard *card); enum _ECardDisposition { E_CARD_DISPOSITION_AS_ATTACHMENT, E_CARD_DISPOSITION_AS_TO, }; typedef enum _ECardDisposition ECardDisposition; -void e_card_send (ECard *card, - ECardDisposition disposition); -void e_card_list_send (GList *cards, - ECardDisposition disposition); +void e_card_send (ECard *card, + ECardDisposition disposition); +void e_card_list_send (GList *cards, + ECardDisposition disposition); /* Getting ECards via their URIs */ typedef void (*ECardCallback) (ECard *card, gpointer closure); -void e_card_load_uri (const gchar *uri, ECardCallback cb, gpointer closure); +void e_card_load_uri (const gchar *book_uri, + const gchar *uid, + ECardCallback cb, + gpointer closure); /* Standard Gtk function */ -GtkType e_card_get_type (void); +GtkType e_card_get_type (void); #endif /* ! __E_CARD_H__ */ diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c index 4e1e27519d..44032d9cf6 100644 --- a/addressbook/backend/ebook/e-destination.c +++ b/addressbook/backend/ebook/e-destination.c @@ -54,7 +54,8 @@ struct _EDestinationPrivate { gchar *raw; - gchar *card_uri; + gchar *book_uri; + gchar *card_uid; ECard *card; gint card_email_num; @@ -206,7 +207,8 @@ e_destination_copy (const EDestination *dest) new_dest = e_destination_new (); - new_dest->priv->card_uri = g_strdup (dest->priv->card_uri); + 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); @@ -230,8 +232,10 @@ e_destination_copy (const EDestination *dest) static void e_destination_clear_card (EDestination *dest) { - g_free (dest->priv->card_uri); - dest->priv->card_uri = NULL; + g_free (dest->priv->book_uri); + dest->priv->book_uri = NULL; + g_free (dest->priv->card_uid); + dest->priv->card_uid = NULL; if (dest->priv->card) gtk_object_unref (GTK_OBJECT (dest->priv->card)); @@ -290,7 +294,8 @@ e_destination_is_empty (const EDestination *dest) p = dest->priv; return !(p->card != NULL - || (p->card_uri && *p->card_uri) + || (p->book_uri && *p->book_uri) + || (p->card_uid && *p->card_uid) || (p->raw && *p->raw) || (p->name && *p->name) || (p->email && *p->email) @@ -318,22 +323,48 @@ e_destination_set_card (EDestination *dest, ECard *card, gint email_num) } void -e_destination_set_card_uri (EDestination *dest, const gchar *uri, gint email_num) +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->card_uri == NULL - || strcmp (dest->priv->card_uri, uri) - || dest->priv->card_email_num != email_num) { + if (dest->priv->book_uri == NULL + || strcmp (dest->priv->book_uri, uri)) { - g_free (dest->priv->card_uri); - dest->priv->card_uri = g_strdup (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) { + EBook *book = e_card_get_book (dest->priv->card); + if ((!book) || strcmp (uri, e_book_get_uri (book))) { + gtk_object_unref (GTK_OBJECT (dest->priv->card)); + dest->priv->card = NULL; + } + } + + e_destination_changed (dest); + } +} + +void +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 (uri, e_card_get_uri (dest->priv->card))) { + 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; } @@ -405,7 +436,7 @@ gboolean e_destination_from_card (const EDestination *dest) { g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE); - return dest->priv->card != NULL || dest->priv->card_uri != NULL; + return dest->priv->card != NULL || dest->priv->book_uri != NULL || dest->priv->card_uid != NULL; } @@ -449,7 +480,7 @@ e_destination_use_card (EDestination *dest, EDestinationCardCallback cb, gpointe cb (dest, dest->priv->card, closure); } - } else if (dest->priv->card_uri != NULL) { + } else if (dest->priv->book_uri != NULL && dest->priv->card_uid != NULL) { UseCard *uc = g_new (UseCard, 1); uc->dest = dest; @@ -457,7 +488,7 @@ e_destination_use_card (EDestination *dest, EDestinationCardCallback cb, gpointe gtk_object_ref (GTK_OBJECT (uc->dest)); uc->cb = cb; uc->closure = closure; - e_card_load_uri (dest->priv->card_uri, use_card_cb, uc); + e_card_load_uri (dest->priv->book_uri, dest->priv->card_uid, use_card_cb, uc); } } @@ -470,15 +501,33 @@ e_destination_get_card (const EDestination *dest) } const gchar * -e_destination_get_card_uri (const EDestination *dest) +e_destination_get_card_uid (const EDestination *dest) { g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); - if (dest->priv->card_uri) - return dest->priv->card_uri; + if (dest->priv->card_uid) + return dest->priv->card_uid; if (dest->priv->card) - return e_card_get_uri (dest->priv->card); + return e_card_get_id (dest->priv->card); + + return NULL; +} + +const gchar * +e_destination_get_book_uri (const EDestination *dest) +{ + g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); + + if (dest->priv->book_uri) + return dest->priv->book_uri; + + if (dest->priv->card) { + EBook *book = e_card_get_book (dest->priv->card); + if (book) { + return e_book_get_uri (book); + } + } return NULL; } @@ -488,7 +537,7 @@ 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->card_uri == NULL) + if (dest->priv->card == NULL && (dest->priv->book_uri == NULL || dest->priv->card_uid == NULL)) return -1; return dest->priv->card_email_num; @@ -976,10 +1025,15 @@ e_destination_xml_encode (const EDestination *dest) xmlNewProp (dest_node, "is_list", "yes"); } - str = e_destination_get_card_uri (dest); + 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]; - xmlNodePtr uri_node = xmlNewTextChild (dest_node, NULL, "card_uri", str); + 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); } @@ -992,7 +1046,7 @@ e_destination_xml_encode (const EDestination *dest) gboolean e_destination_xml_decode (EDestination *dest, xmlNodePtr node) { - gchar *name = NULL, *email = NULL, *card_uri = NULL; + gchar *name = NULL, *email = NULL, *book_uri = NULL, *card_uid = NULL; gint email_num = -1; gboolean html_mail = FALSE; gboolean is_list = FALSE; @@ -1058,10 +1112,15 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node) list_dests = g_list_append (list_dests, list_dest); } - } else if (!strcmp (node->name, "card_uri")) { + } else if (!strcmp (node->name, "book_uri")) { + tmp = xmlNodeGetContent (node); + g_free (book_uri); + book_uri = g_strdup (tmp); + xmlFree (tmp); + } else if (!strcmp (node->name, "card_uid")) { tmp = xmlNodeGetContent (node); - g_free (card_uri); - card_uri = g_strdup (tmp); + g_free (card_uid); + card_uid = g_strdup (tmp); xmlFree (tmp); tmp = xmlGetProp (node, "email_num"); @@ -1080,8 +1139,10 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node) e_destination_set_name (dest, name); if (email) e_destination_set_email (dest, email); - if (card_uri) - e_destination_set_card_uri (dest, card_uri, email_num); + if (book_uri) + e_destination_set_book_uri (dest, book_uri); + if (card_uid) + e_destination_set_card_uid (dest, card_uid, email_num); if (list_dests) dest->priv->list_dests = list_dests; diff --git a/addressbook/backend/ebook/e-destination.h b/addressbook/backend/ebook/e-destination.h index 92d4d803f2..dc43d9703c 100644 --- a/addressbook/backend/ebook/e-destination.h +++ b/addressbook/backend/ebook/e-destination.h @@ -70,7 +70,8 @@ void e_destination_clear (EDestination *); gboolean e_destination_is_empty (const EDestination *); void e_destination_set_card (EDestination *, ECard *card, gint email_num); -void e_destination_set_card_uri (EDestination *, const gchar *uri, gint email_num); +void e_destination_set_book_uri (EDestination *, const gchar *uri); +void e_destination_set_card_uid (EDestination *, const gchar *uid, gint email_num); void e_destination_set_name (EDestination *, const gchar *name); void e_destination_set_email (EDestination *, const gchar *email); @@ -83,7 +84,8 @@ gboolean e_destination_from_card (const EDestination *); void e_destination_use_card (EDestination *, EDestinationCardCallback cb, gpointer closure); ECard *e_destination_get_card (const EDestination *); -const gchar *e_destination_get_card_uri (const EDestination *); +const gchar *e_destination_get_book_uri (const EDestination *); +const gchar *e_destination_get_card_uid (const EDestination *); gint e_destination_get_email_num (const EDestination *); const gchar *e_destination_get_name (const EDestination *); /* "Jane Smith" */ |