From 23c042a0b5053abc7c406f1e37e162f7a7771abe Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Wed, 4 Nov 2009 18:53:19 +0100 Subject: [PATCH] Added "Add to Contacts" to the message editor window Fixes NB#144914 (5/8) --- src/hildon2/modest-address-book.c | 11 ++++++---- src/hildon2/modest-msg-edit-window.c | 39 ++++++++++++++++++++++++++++++++++ src/modest-ui-actions.c | 7 +++--- src/modest-ui-dimming-rules.c | 9 +++++--- src/widgets/modest-msg-edit-window.h | 9 ++++++++ 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/hildon2/modest-address-book.c b/src/hildon2/modest-address-book.c index 0f1e92d..b7ee2aa 100644 --- a/src/hildon2/modest-address-book.c +++ b/src/hildon2/modest-address-book.c @@ -1214,10 +1214,13 @@ modest_address_book_add_address_list_with_selector (GSList *address_list, GtkWin g_object_ref (selector); for (node = address_list; node != NULL; node = g_slist_next (node)) { - if (!modest_address_book_has_address ((const gchar *) node->data)) { - hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), - (const gchar *) node->data); - contacts_to_add = TRUE; + const gchar *recipient = (const gchar *) node->data; + if (modest_text_utils_validate_recipient (recipient, NULL)) { + if (!modest_address_book_has_address (recipient)) { + hildon_touch_selector_append_text ((HildonTouchSelector *) selector, + recipient); + contacts_to_add = TRUE; + } } } diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index 7a5d0f5..005efe1 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -3435,6 +3435,42 @@ modest_msg_edit_window_check_names (ModestMsgEditWindow *window, gboolean add_to } +void +modest_msg_edit_window_add_to_contacts (ModestMsgEditWindow *self) +{ + GSList *recipients = NULL; + ModestMsgEditWindowPrivate *priv; + gchar *joined, *after_remove, *to, *cc, *bcc; + + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); + + /* First of all check names */ + if (!modest_msg_edit_window_check_names (self, FALSE)) + return; + + /* Don't add the from obviously */ + to = g_strdup (modest_recpt_editor_get_recipients ((ModestRecptEditor *) priv->to_field)); + cc = g_strdup (modest_recpt_editor_get_recipients ((ModestRecptEditor *) priv->cc_field)); + bcc = g_strdup (modest_recpt_editor_get_recipients ((ModestRecptEditor *) priv->bcc_field)); + + joined = modest_text_utils_join_addresses (NULL, to, cc, bcc); + g_free (to); + g_free (cc); + g_free (bcc); + + after_remove = modest_text_utils_remove_duplicate_addresses (joined); + g_free (joined); + + recipients = modest_text_utils_split_addresses_list (after_remove); + g_free (after_remove); + + if (recipients) { + /* Offer the user to add recipients to the address book */ + modest_address_book_add_address_list_with_selector (recipients, (GtkWindow *) self); + g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients); + } +} + static void modest_msg_edit_window_add_attachment_clicked (GtkButton *button, ModestMsgEditWindow *window) @@ -4334,6 +4370,9 @@ setup_menu (ModestMsgEditWindow *self) modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_editor_checknames"), NULL, APP_MENU_CALLBACK (modest_ui_actions_on_check_names), NULL); + modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_viewer_addtocontacts"), NULL, + APP_MENU_CALLBACK (modest_ui_actions_add_to_contacts), + MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_add_to_contacts)); modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_undo"), "z", APP_MENU_CALLBACK (modest_ui_actions_on_undo), MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_undo)); diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 6c8fdde..7ed4609 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -686,9 +686,10 @@ modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win) void modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win) { - g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win)); - - modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win)); + if (MODEST_IS_MSG_VIEW_WINDOW (win)) + modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win)); + else if (MODEST_IS_MSG_EDIT_WINDOW (win)) + modest_msg_edit_window_add_to_contacts (MODEST_MSG_EDIT_WINDOW (win)); } void diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index 8faeed5..b15b59e 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -2118,9 +2118,12 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat if (recipients) { GSList *node; for (node = recipients; node != NULL; node = g_slist_next (node)) { - if (!modest_address_book_has_address ((const gchar *) node->data)) { - has_recipients_to_add = TRUE; - break; + const gchar *recipient = (const gchar *) node->data; + if (modest_text_utils_validate_recipient (recipient, NULL)) { + if (!modest_address_book_has_address (recipient)) { + has_recipients_to_add = TRUE; + break; + } } } g_slist_foreach (recipients, (GFunc) g_free, NULL); diff --git a/src/widgets/modest-msg-edit-window.h b/src/widgets/modest-msg-edit-window.h index a364da0..b60dec9 100644 --- a/src/widgets/modest-msg-edit-window.h +++ b/src/widgets/modest-msg-edit-window.h @@ -374,6 +374,15 @@ gboolean modest_msg_edit_window_can_redo (ModestMsgEdit void modest_msg_edit_window_select_contacts (ModestMsgEditWindow *window); /** + * modest_msg_edit_window_add_to_contacts: + * @self: a #ModestMsgEditWindow + * + * activates the add to contacts use. It shows the add to contacts + * dialog to select the recipient to add. + */ +void modest_msg_edit_window_add_to_contacts (ModestMsgEditWindow *self); + +/** * modest_msg_edit_window_check_names: * @window: a #ModestMsgEditWindow * @add_to_addressbook: if TRUE, add valid addresses to the addressbook -- 1.7.9.5