diff options
-rw-r--r-- | addressbook/ChangeLog | 23 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-contact-display.c | 41 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-gui-util.c | 431 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-gui-util.h | 1 |
4 files changed, 325 insertions, 171 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 27a0bf9826..05fd23bcb6 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,25 @@ +2004-05-18 Chris Toshok <toshok@ximian.com> + + * gui/widgets/eab-gui-util.c + (eab_send_to_contact_and_email_num_list): split out the + DISPOSITION_AS_TO stuff here, and make it take a GList of + ContactAndEmailNum, so we can set it for the single contact case. + (eab_send_contact_list_as_attachment): split out the + DISPOSITION_AS_ATTACHMENT stuff here. + (eab_send_contact_list): call one or the other of the above, + munging the list if disposition is set to TO. + (eab_send_contact): call eab_send_to_contact_and_email_num_list + directly with the supplied email_num, instead of calling + eab_send_contact_list. + + * gui/widgets/eab-gui-util.h (eab_send_contact) add "email_num" + arg, so we can specify the email address we want to be selected. + + * gui/widgets/eab-contact-display.c (on_link_clicked): add + (ifdefed out at the moment) code to handle mailto: urls + internally, instead of farming them out to gnome_url_show. + (render_contact): same. + 2004-05-18 Jerome Lacoste <jerome@coffeebreaks.org> Fixes #57940 @@ -185,7 +207,6 @@ * gui/component/ldap-config.glade: remove unused colorpicker. ->>>>>>> 1.1697 2004-05-03 JP Rosevear <jpr@ximian.com> * gui/component/GNOME_Evolution_Addressbook.server.in.in: set the diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c index 623b798089..a74fc3a7cb 100644 --- a/addressbook/gui/widgets/eab-contact-display.c +++ b/addressbook/gui/widgets/eab-contact-display.c @@ -22,6 +22,7 @@ #include "eab-contact-display.h" +#include "eab-gui-util.h" #include "e-util/e-html-utils.h" #include "e-util/e-icon-factory.h" @@ -92,7 +93,20 @@ static void on_link_clicked (GtkHTML *html, const char *url, EABContactDisplay *display) { GError *err = NULL; - + +#ifdef HANDLE_MAILTO_INTERNALLY + if (!strncmp (url, "internal-mailto:", strlen ("internal-mailto:"))) { + int mail_num = atoi (url + strlen ("internal-mailto:")); + + if (mail_num == -1) + return; + + eab_send_contact (display->priv->contact, mail_num, EAB_DISPOSITION_AS_TO); + + return; + } +#endif + gnome_url_show (url, &err); if (err) { @@ -276,23 +290,48 @@ render_contact (GtkHTMLStream *html_stream, EContact *contact) nl = ""; e = e_contact_get_const (contact, E_CONTACT_EMAIL_1); if (e) { +#ifdef HANDLE_MAILTO_INTERNALLY + g_string_append_printf (accum, "<a href=\"internal-mailto:0\">%s</a>", e); + nl = "<br>"; +#else g_string_append_printf (accum, "%s", e); nl = "\n"; +#endif } e = e_contact_get_const (contact, E_CONTACT_EMAIL_2); if (e) { +#ifdef HANDLE_MAILTO_INTERNALLY + g_string_append_printf (accum, "<a href=\"internal-mailto:1\">%s</a>", e); + nl = "<br>"; +#else g_string_append_printf (accum, "%s%s", nl, e); nl = "\n"; +#endif } e = e_contact_get_const (contact, E_CONTACT_EMAIL_3); if (e) { +#ifdef HANDLE_MAILTO_INTERNALLY + g_string_append_printf (accum, "<a href=\"internal-mailto:2\">%s</a>", e); + nl = "<br>"; +#else g_string_append_printf (accum, "%s%s", nl, e); + nl = "\n"; +#endif } if (accum->len) { start_block (html_stream, ""); + +#ifdef HANDLE_MAILTO_INTERNALLY + gtk_html_stream_printf (html_stream, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); + gtk_html_stream_printf (html_stream, + "</td><td valign=\"top\" width=\"100\" nowrap><font color=" HEADER_COLOR ">%s:</font></td> <td valign=\"top\">%s</td></tr>", + _("E-mail"), accum->str); +#else render_name_value (html_stream, _("E-mail"), accum->str, NULL, E_TEXT_TO_HTML_CONVERT_ADDRESSES | E_TEXT_TO_HTML_CONVERT_NL); +#endif + end_block (html_stream); } diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c index 1b90cc0551..c8fcb1cde5 100644 --- a/addressbook/gui/widgets/eab-gui-util.c +++ b/addressbook/gui/widgets/eab-gui-util.c @@ -744,78 +744,85 @@ eab_transfer_contacts (EBook *source, GList *contacts /* adopted */, gboolean de #define COMPOSER_OAFID "OAFIID:GNOME_Evolution_Mail_Composer:" BASE_VERSION -void -eab_send_contact_list (GList *contacts, EABDisposition disposition) +typedef struct { + EContact *contact; + int email_num; /* if the contact is a person (not a list), the email address to use */ +} ContactAndEmailNum; + +static void +eab_send_to_contact_and_email_num_list (GList *c) { GNOME_Evolution_Composer composer_server; CORBA_Environment ev; + GNOME_Evolution_Composer_RecipientList *to_list, *cc_list, *bcc_list; + CORBA_char *subject; + int to_i, bcc_i; + GList *iter; + gint to_length = 0, bcc_length = 0; - if (contacts == NULL) + if (c == NULL) return; CORBA_exception_init (&ev); composer_server = bonobo_activation_activate_from_id (COMPOSER_OAFID, 0, NULL, &ev); - if (disposition == EAB_DISPOSITION_AS_TO) { - GNOME_Evolution_Composer_RecipientList *to_list, *cc_list, *bcc_list; - CORBA_char *subject; - int to_i, bcc_i; - GList *iter; - gint to_length = 0, bcc_length = 0; - - /* Figure out how many addresses of each kind we have. */ - for (iter = contacts; iter != NULL; iter = g_list_next (iter)) { - EContact *contact = E_CONTACT (iter->data); - GList *emails = e_contact_get (contact, E_CONTACT_EMAIL); - if (e_contact_get (contact, E_CONTACT_IS_LIST)) { - gint len = g_list_length (emails); - if (e_contact_get (contact, E_CONTACT_LIST_SHOW_ADDRESSES)) - to_length += len; - else - bcc_length += len; - } else { - if (emails != NULL) - ++to_length; - } - g_list_foreach (emails, (GFunc)g_free, NULL); - g_list_free (emails); + /* Figure out how many addresses of each kind we have. */ + for (iter = c; iter != NULL; iter = g_list_next (iter)) { + ContactAndEmailNum *ce = iter->data; + EContact *contact = ce->contact; + GList *emails = e_contact_get (contact, E_CONTACT_EMAIL); + if (e_contact_get (contact, E_CONTACT_IS_LIST)) { + gint len = g_list_length (emails); + if (e_contact_get (contact, E_CONTACT_LIST_SHOW_ADDRESSES)) + to_length += len; + else + bcc_length += len; + } else { + if (emails != NULL) + ++to_length; } + g_list_foreach (emails, (GFunc)g_free, NULL); + g_list_free (emails); + } - /* Now I have to make a CORBA sequences that represents a recipient list with - the right number of entries, for the contacts. */ - to_list = GNOME_Evolution_Composer_RecipientList__alloc (); - to_list->_maximum = to_length; - to_list->_length = to_length; - if (to_length > 0) { - to_list->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (to_length); - } + /* Now I have to make a CORBA sequences that represents a recipient list with + the right number of entries, for the contacts. */ + to_list = GNOME_Evolution_Composer_RecipientList__alloc (); + to_list->_maximum = to_length; + to_list->_length = to_length; + if (to_length > 0) { + to_list->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (to_length); + } - cc_list = GNOME_Evolution_Composer_RecipientList__alloc (); - cc_list->_maximum = cc_list->_length = 0; + cc_list = GNOME_Evolution_Composer_RecipientList__alloc (); + cc_list->_maximum = cc_list->_length = 0; - bcc_list = GNOME_Evolution_Composer_RecipientList__alloc (); - bcc_list->_maximum = bcc_length; - bcc_list->_length = bcc_length; - if (bcc_length > 0) { - bcc_list->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (bcc_length); - } + bcc_list = GNOME_Evolution_Composer_RecipientList__alloc (); + bcc_list->_maximum = bcc_length; + bcc_list->_length = bcc_length; + if (bcc_length > 0) { + bcc_list->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (bcc_length); + } + + to_i = 0; + bcc_i = 0; + while (c != NULL) { + ContactAndEmailNum *ce = c->data; + EContact *contact = ce->contact; + int nth = ce->email_num; + char *name, *addr; + gboolean is_list, is_hidden; + GNOME_Evolution_Composer_Recipient *recipient; + GList *emails = e_contact_get (contact, E_CONTACT_EMAIL); + GList *iterator; + + if (emails != NULL) { + + is_list = (gboolean)e_contact_get (contact, E_CONTACT_IS_LIST); + is_hidden = is_list && !e_contact_get (contact, E_CONTACT_LIST_SHOW_ADDRESSES); - to_i = 0; - bcc_i = 0; - while (contacts != NULL) { - EContact *contact = contacts->data; - gchar *name, *addr; - gboolean is_list, is_hidden; - GNOME_Evolution_Composer_Recipient *recipient; - GList *emails = e_contact_get (contact, E_CONTACT_EMAIL); - GList *iterator; - - if (emails != NULL) { - - is_list = (gboolean)e_contact_get (contact, E_CONTACT_IS_LIST); - is_hidden = is_list && !e_contact_get (contact, E_CONTACT_LIST_SHOW_ADDRESSES); - + if (is_list) { for (iterator = emails; iterator; iterator = iterator->next) { if (is_hidden) { @@ -829,139 +836,181 @@ eab_send_contact_list (GList *contacts, EABDisposition disposition) name = NULL; addr = NULL; if (iterator && iterator->data) { - if (is_list) { - /* XXX we should probably try to get the name from the attribute parameter here.. */ - addr = g_strdup ((char*)iterator->data); - } else { /* is just a plain old card */ - EContactName *contact_name = e_contact_get (contact, E_CONTACT_NAME); - if (contact_name) { - name = e_contact_name_to_string (contact_name); - e_contact_name_free (contact_name); - } - addr = g_strdup ((char *) iterator->data); - } + /* XXX we should probably try to get the name from the attribute parameter here.. */ + addr = g_strdup ((char*)iterator->data); } - + recipient->name = CORBA_string_dup (name ? name : ""); recipient->address = CORBA_string_dup (addr ? 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. */ - if (!is_list) - break; + g_free (name); + g_free (addr); + } + } + else { + EContactName *contact_name = e_contact_get (contact, E_CONTACT_NAME); + int length = g_list_length (emails); + + if (is_hidden) { + recipient = &(bcc_list->_buffer[bcc_i]); + ++bcc_i; + } else { + recipient = &(to_list->_buffer[to_i]); + ++to_i; + } + + if (nth >= length) + nth = 0; + if (contact_name) { + name = e_contact_name_to_string (contact_name); + e_contact_name_free (contact_name); } - g_list_foreach (emails, (GFunc)g_free, NULL); - g_list_free (emails); + else + name = NULL; + + addr = g_strdup (g_list_nth_data (emails, nth)); + + + recipient->name = CORBA_string_dup (name ? name : ""); + recipient->address = CORBA_string_dup (addr ? addr : ""); + + g_free (name); + g_free (addr); } - contacts = g_list_next (contacts); + g_list_foreach (emails, (GFunc)g_free, NULL); + g_list_free (emails); } - subject = CORBA_string_dup (""); + c = c->next; + } - GNOME_Evolution_Composer_setHeaders (composer_server, "", to_list, cc_list, bcc_list, subject, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_printerr ("gui/e-meeting-edit.c: I couldn't set the composer headers via CORBA! Aagh.\n"); - CORBA_exception_free (&ev); - return; - } + subject = CORBA_string_dup (""); - CORBA_free (to_list); - CORBA_free (cc_list); - CORBA_free (bcc_list); - CORBA_free (subject); - } else if (disposition == EAB_DISPOSITION_AS_ATTACHMENT) { - CORBA_char *content_type, *filename, *description; - GNOME_Evolution_Composer_AttachmentData *attach_data; - CORBA_boolean show_inline; - char *tempstr; - - GNOME_Evolution_Composer_RecipientList *to_list, *cc_list, *bcc_list; - CORBA_char *subject; - - content_type = CORBA_string_dup ("text/x-vcard"); - filename = CORBA_string_dup (""); + GNOME_Evolution_Composer_setHeaders (composer_server, "", to_list, cc_list, bcc_list, subject, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_printerr ("gui/e-meeting-edit.c: I couldn't set the composer headers via CORBA! Aagh.\n"); + CORBA_exception_free (&ev); + return; + } + + CORBA_free (to_list); + CORBA_free (cc_list); + CORBA_free (bcc_list); + CORBA_free (subject); + + GNOME_Evolution_Composer_show (composer_server, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_printerr ("gui/e-meeting-edit.c: I couldn't show the composer via CORBA! Aagh.\n"); + CORBA_exception_free (&ev); + return; + } + + CORBA_exception_free (&ev); +} + +static void +eab_send_contact_list_as_attachment (GList *contacts) +{ + GNOME_Evolution_Composer composer_server; + CORBA_Environment ev; + CORBA_char *content_type, *filename, *description; + GNOME_Evolution_Composer_AttachmentData *attach_data; + CORBA_boolean show_inline; + char *tempstr; + GNOME_Evolution_Composer_RecipientList *to_list, *cc_list, *bcc_list; + CORBA_char *subject; + + if (contacts == NULL) + return; + + CORBA_exception_init (&ev); + + composer_server = bonobo_activation_activate_from_id (COMPOSER_OAFID, 0, NULL, &ev); - if (contacts->next) { - description = CORBA_string_dup (_("Multiple VCards")); - } else { - char *file_as = e_contact_get (E_CONTACT (contacts->data), E_CONTACT_FILE_AS); - tempstr = g_strdup_printf (_("VCard for %s"), file_as); - description = CORBA_string_dup (tempstr); - g_free (tempstr); - g_free (file_as); - } - show_inline = FALSE; + + content_type = CORBA_string_dup ("text/x-vcard"); + filename = CORBA_string_dup (""); - tempstr = eab_contact_list_to_string (contacts); - attach_data = GNOME_Evolution_Composer_AttachmentData__alloc(); - attach_data->_maximum = attach_data->_length = strlen (tempstr); - attach_data->_buffer = CORBA_sequence_CORBA_char_allocbuf (attach_data->_length); - strcpy (attach_data->_buffer, tempstr); + if (contacts->next) { + description = CORBA_string_dup (_("Multiple VCards")); + } else { + char *file_as = e_contact_get (E_CONTACT (contacts->data), E_CONTACT_FILE_AS); + tempstr = g_strdup_printf (_("VCard for %s"), file_as); + description = CORBA_string_dup (tempstr); g_free (tempstr); + g_free (file_as); + } + + show_inline = FALSE; - GNOME_Evolution_Composer_attachData (composer_server, - content_type, filename, description, - show_inline, attach_data, - &ev); + tempstr = eab_contact_list_to_string (contacts); + attach_data = GNOME_Evolution_Composer_AttachmentData__alloc(); + attach_data->_maximum = attach_data->_length = strlen (tempstr); + attach_data->_buffer = CORBA_sequence_CORBA_char_allocbuf (attach_data->_length); + strcpy (attach_data->_buffer, tempstr); + g_free (tempstr); + + GNOME_Evolution_Composer_attachData (composer_server, + content_type, filename, description, + show_inline, attach_data, + &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_printerr ("gui/e-meeting-edit.c: I couldn't attach data to the composer via CORBA! Aagh.\n"); - CORBA_exception_free (&ev); - return; - } + if (ev._major != CORBA_NO_EXCEPTION) { + g_printerr ("gui/e-meeting-edit.c: I couldn't attach data to the composer via CORBA! Aagh.\n"); + CORBA_exception_free (&ev); + return; + } - CORBA_free (content_type); - CORBA_free (filename); - CORBA_free (description); - CORBA_free (attach_data); + CORBA_free (content_type); + CORBA_free (filename); + CORBA_free (description); + CORBA_free (attach_data); - to_list = GNOME_Evolution_Composer_RecipientList__alloc (); - to_list->_maximum = to_list->_length = 0; + to_list = GNOME_Evolution_Composer_RecipientList__alloc (); + to_list->_maximum = to_list->_length = 0; - cc_list = GNOME_Evolution_Composer_RecipientList__alloc (); - cc_list->_maximum = cc_list->_length = 0; + cc_list = GNOME_Evolution_Composer_RecipientList__alloc (); + cc_list->_maximum = cc_list->_length = 0; - bcc_list = GNOME_Evolution_Composer_RecipientList__alloc (); - bcc_list->_maximum = bcc_list->_length = 0; + bcc_list = GNOME_Evolution_Composer_RecipientList__alloc (); + bcc_list->_maximum = bcc_list->_length = 0; - if (!contacts || contacts->next) { - subject = CORBA_string_dup ("Contact information"); - } else { - EContact *contact = contacts->data; - const gchar *tempstr2; - - tempstr2 = e_contact_get_const (contact, E_CONTACT_FILE_AS); - if (!tempstr2 || !*tempstr2) - tempstr2 = e_contact_get_const (contact, E_CONTACT_FULL_NAME); - if (!tempstr2 || !*tempstr2) - tempstr2 = e_contact_get_const (contact, E_CONTACT_ORG); - if (!tempstr2 || !*tempstr2) - tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_1); - if (!tempstr2 || !*tempstr2) - tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_2); - if (!tempstr2 || !*tempstr2) - tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_3); - - if (!tempstr2 || !*tempstr2) - tempstr = g_strdup_printf ("Contact information"); - else - tempstr = g_strdup_printf ("Contact information for %s", tempstr2); - subject = CORBA_string_dup (tempstr); - g_free (tempstr); - } + if (!contacts || contacts->next) { + subject = CORBA_string_dup ("Contact information"); + } else { + EContact *contact = contacts->data; + const gchar *tempstr2; + + tempstr2 = e_contact_get_const (contact, E_CONTACT_FILE_AS); + if (!tempstr2 || !*tempstr2) + tempstr2 = e_contact_get_const (contact, E_CONTACT_FULL_NAME); + if (!tempstr2 || !*tempstr2) + tempstr2 = e_contact_get_const (contact, E_CONTACT_ORG); + if (!tempstr2 || !*tempstr2) + tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_1); + if (!tempstr2 || !*tempstr2) + tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_2); + if (!tempstr2 || !*tempstr2) + tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_3); + + if (!tempstr2 || !*tempstr2) + tempstr = g_strdup_printf ("Contact information"); + else + tempstr = g_strdup_printf ("Contact information for %s", tempstr2); + subject = CORBA_string_dup (tempstr); + g_free (tempstr); + } - GNOME_Evolution_Composer_setHeaders (composer_server, "", to_list, cc_list, bcc_list, subject, &ev); + GNOME_Evolution_Composer_setHeaders (composer_server, "", to_list, cc_list, bcc_list, subject, &ev); - CORBA_free (to_list); - CORBA_free (cc_list); - CORBA_free (bcc_list); - CORBA_free (subject); - } + CORBA_free (to_list); + CORBA_free (cc_list); + CORBA_free (bcc_list); + CORBA_free (subject); GNOME_Evolution_Composer_show (composer_server, &ev); @@ -975,11 +1024,55 @@ eab_send_contact_list (GList *contacts, EABDisposition disposition) } void -eab_send_contact (EContact *contact, EABDisposition disposition) +eab_send_contact_list (GList *contacts, EABDisposition disposition) { - GList *list; - list = g_list_prepend (NULL, contact); - eab_send_contact_list (list, disposition); + switch (disposition) { + case EAB_DISPOSITION_AS_TO: { + GList *list = NULL, *l; + + for (l = contacts; l; l = l->next) { + ContactAndEmailNum *ce = g_new (ContactAndEmailNum, 1); + ce->contact = l->data; + ce->email_num = 0; /* hardcode this */ + + list = g_list_append (list, ce); + } + + eab_send_to_contact_and_email_num_list (list); + + g_list_foreach (list, (GFunc)g_free, NULL); + g_list_free (list); + break; + } + case EAB_DISPOSITION_AS_ATTACHMENT: + eab_send_contact_list_as_attachment (contacts); + break; + } +} + +void +eab_send_contact (EContact *contact, int email_num, EABDisposition disposition) +{ + GList *list = NULL; + + switch (disposition) { + case EAB_DISPOSITION_AS_TO: { + ContactAndEmailNum ce; + + ce.contact = contact; + ce.email_num = email_num; + + list = g_list_prepend (NULL, &ce); + eab_send_to_contact_and_email_num_list (list); + break; + } + case EAB_DISPOSITION_AS_ATTACHMENT: { + list = g_list_prepend (NULL, contact); + eab_send_contact_list_as_attachment (list); + break; + } + } + g_list_free (list); } diff --git a/addressbook/gui/widgets/eab-gui-util.h b/addressbook/gui/widgets/eab-gui-util.h index e986fd925a..4a3dffba0b 100644 --- a/addressbook/gui/widgets/eab-gui-util.h +++ b/addressbook/gui/widgets/eab-gui-util.h @@ -66,6 +66,7 @@ typedef enum { } EABDisposition; void eab_send_contact (EContact *contact, + int email_num, EABDisposition disposition); void eab_send_contact_list (GList *contacts, EABDisposition disposition); |