From 0278dabc7e2e767712e75de5045ed664f1f5fb30 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Tue, 25 Nov 2008 13:38:10 +0000 Subject: [PATCH] * Added code to show dialog for choosing recipients * Refactored code to integrate properly with old add to contacts functionality. pmo-trunk-r6398 --- src/gnome/modest-main-window-ui.h | 2 +- src/gnome/modest-msg-view-window.c | 7 +++ src/hildon2/modest-main-window-ui.h | 2 +- src/hildon2/modest-msg-view-window.c | 83 +++++++++++++++++++++++++++++++++- src/maemo/modest-main-window-ui.h | 2 +- src/maemo/modest-msg-view-window.c | 7 +++ src/modest-ui-actions.c | 8 ++++ src/modest-ui-actions.h | 1 + src/modest-ui-dimming-rules.c | 8 ++++ src/widgets/modest-msg-view-window.h | 12 +++++ 10 files changed, 128 insertions(+), 4 deletions(-) diff --git a/src/gnome/modest-main-window-ui.h b/src/gnome/modest-main-window-ui.h index a6074f8..b5397b5 100644 --- a/src/gnome/modest-main-window-ui.h +++ b/src/gnome/modest-main-window-ui.h @@ -96,7 +96,7 @@ static const GtkActionEntry modest_action_entries [] = { { "ToolsSendReceiveAll", NULL, N_("mcen_me_inbox_sendandreceive_all"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_send_receive) }, { "ToolsSendReceiveCancelSending", NULL, N_("mcen_me_outbox_cancelsend"), NULL, NULL, G_CALLBACK (modest_ui_actions_cancel_send) }, { "ToolsContacts", NULL, N_("mcen_me_inbox_open_addressbook"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_open_addressbook) }, - { "ToolsAddToContacts", NULL, N_("mcen_me_viewer_addtocontacts"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_add_to_contacts) }, + { "ToolsAddToContacts", NULL, N_("mcen_me_viewer_addtocontacts"), NULL, NULL, G_CALLBACK (modest_ui_actions_add_to_contacts) }, { "ToolsSearchMessages", NULL, N_("mcen_me_inbox_search"), "E", NULL, G_CALLBACK (modest_ui_actions_on_search_messages) }, { "ToolsHelp", NULL, N_("mcen_me_inbox_help"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_help) }, diff --git a/src/gnome/modest-msg-view-window.c b/src/gnome/modest-msg-view-window.c index 172bb0f..35fe46e 100644 --- a/src/gnome/modest-msg-view-window.c +++ b/src/gnome/modest-msg-view-window.c @@ -516,3 +516,10 @@ modest_msg_view_window_toggle_find_toolbar (GtkToggleAction *toggle, g_message ("NOT IMPLEMENTED %s", __FUNCTION__); return FALSE; } + +void +modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self) +{ + modest_ui_actions_on_add_to_contacts (NULL, MODEST_WINDOW (self)); +} + diff --git a/src/hildon2/modest-main-window-ui.h b/src/hildon2/modest-main-window-ui.h index 8ddaa22..b4b8913 100644 --- a/src/hildon2/modest-main-window-ui.h +++ b/src/hildon2/modest-main-window-ui.h @@ -97,7 +97,7 @@ static const GtkActionEntry modest_action_entries [] = { { "ToolsSendReceiveAll", NULL, N_("mcen_me_inbox_sendandreceive_all"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_send_receive) }, { "ToolsSendReceiveCancelSending", NULL, N_("mcen_me_outbox_cancelsend"), NULL, NULL, G_CALLBACK (modest_ui_actions_cancel_send) }, { "ToolsContacts", NULL, N_("mcen_me_inbox_open_addressbook"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_open_addressbook) }, - { "ToolsAddToContacts", NULL, N_("mcen_me_viewer_addtocontacts"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_add_to_contacts) }, + { "ToolsAddToContacts", NULL, N_("mcen_me_viewer_addtocontacts"), NULL, NULL, G_CALLBACK (modest_ui_actions_add_to_contacts) }, /* Close */ { "CloseWindow", NULL, N_("mcen_me_inbox_close_window"), "W", NULL, G_CALLBACK (modest_ui_actions_on_close_window) }, diff --git a/src/hildon2/modest-msg-view-window.c b/src/hildon2/modest-msg-view-window.c index 28412cd..3fc077b 100644 --- a/src/hildon2/modest-msg-view-window.c +++ b/src/hildon2/modest-msg-view-window.c @@ -48,7 +48,8 @@ #include #include #include "modest-progress-bar.h" -#include "hildon/hildon-pannable-area.h" +#include +#include #include "modest-defs.h" #include "modest-hildon-includes.h" #include "modest-ui-dimming-manager.h" @@ -57,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -3011,3 +3013,82 @@ on_fetch_image (ModestMsgView *msgview, return TRUE;; } + +static GSList * +all_recipients_list (TnyMsg *msg) +{ + TnyHeader *header = NULL; + GSList *recipients = NULL; + gchar *from = NULL, *to = NULL, *cc = NULL, *bcc = NULL; + + if (msg == NULL) + return NULL; + + header = tny_msg_get_header (msg); + if (header == NULL) + return NULL; + + from = tny_header_dup_from (header); + to = tny_header_dup_to (header); + cc = tny_header_dup_cc (header); + bcc = tny_header_dup_bcc (header); + + recipients = NULL; + if (from) + recipients = g_slist_concat (recipients, modest_text_utils_split_addresses_list (from)); + if (to) + recipients = g_slist_concat (recipients, modest_text_utils_split_addresses_list (to)); + if (cc) + recipients = g_slist_concat (recipients, modest_text_utils_split_addresses_list (cc)); + if (bcc) + recipients = g_slist_concat (recipients, modest_text_utils_split_addresses_list (bcc)); + + g_free (from); + g_free (to); + g_free (cc); + g_free (bcc); + + return recipients; +} + +void +modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self) +{ + ModestMsgViewWindowPrivate *priv; + priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self); + GSList *recipients = NULL; + TnyMsg *msg = NULL; + + msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view)); + if (msg == NULL) return; + recipients = all_recipients_list (msg); + + if (recipients != NULL) { + GtkWidget *picker_dialog; + GtkWidget *selector; + GSList *node; + gchar *selected; + + picker_dialog = hildon_picker_dialog_new (GTK_WINDOW (self)); + gtk_window_set_title (GTK_WINDOW (picker_dialog), _("mcen_me_viewer_addtocontacts")); + + selector = hildon_touch_selector_new_text (); + for (node = recipients; node != NULL; node = g_slist_next (node)) { + hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), (const gchar *) node->data); + } + + hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (picker_dialog), + HILDON_TOUCH_SELECTOR (selector)); + + gtk_dialog_run (GTK_DIALOG (picker_dialog)); + selected = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)); + gtk_widget_destroy (picker_dialog); + + if (selected) + modest_address_book_add_address (selected); + g_free (selected); + } + + if (recipients) {g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients);} + g_object_unref (msg); +} diff --git a/src/maemo/modest-main-window-ui.h b/src/maemo/modest-main-window-ui.h index 9bbe466..f41327e 100644 --- a/src/maemo/modest-main-window-ui.h +++ b/src/maemo/modest-main-window-ui.h @@ -99,7 +99,7 @@ static const GtkActionEntry modest_action_entries [] = { { "ToolsSendReceiveAll", NULL, N_("mcen_me_inbox_sendandreceive_all"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_send_receive) }, { "ToolsSendReceiveCancelSending", NULL, N_("mcen_me_outbox_cancelsend"), NULL, NULL, G_CALLBACK (modest_ui_actions_cancel_send) }, { "ToolsContacts", NULL, N_("mcen_me_inbox_open_addressbook"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_open_addressbook) }, - { "ToolsAddToContacts", NULL, N_("mcen_me_viewer_addtocontacts"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_add_to_contacts) }, + { "ToolsAddToContacts", NULL, N_("mcen_me_viewer_addtocontacts"), NULL, NULL, G_CALLBACK (modest_ui_actions_add_to_contacts) }, { "ToolsSearchMessages", NULL, N_("mcen_me_inbox_search"), "E", NULL, G_CALLBACK (modest_ui_actions_on_search_messages) }, { "ToolsHelp", NULL, N_("mcen_me_inbox_help"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_help) }, diff --git a/src/maemo/modest-msg-view-window.c b/src/maemo/modest-msg-view-window.c index 4f47097..eade580 100644 --- a/src/maemo/modest-msg-view-window.c +++ b/src/maemo/modest-msg-view-window.c @@ -3208,3 +3208,10 @@ on_fetch_image (ModestMsgView *msgview, return TRUE;; } + +void +modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self) +{ + modest_ui_actions_on_add_to_contacts (NULL, MODEST_WINDOW (self)); +} + diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 27c367f..86dbe0f 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -633,6 +633,14 @@ 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)); +} + +void modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win) { GtkClipboard *clipboard = NULL; diff --git a/src/modest-ui-actions.h b/src/modest-ui-actions.h index 1408a30..02ef1ba 100644 --- a/src/modest-ui-actions.h +++ b/src/modest-ui-actions.h @@ -58,6 +58,7 @@ void modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *wi void modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win); +void modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win); void modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win); void modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *win); diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index af08d11..e84e456 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -1749,6 +1749,13 @@ modest_ui_dimming_rules_on_send_receive_all (ModestWindow *win, gpointer user_da return dimmed; } +#ifdef MODEST_TOOLKIT_HILDON2 +gboolean +modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_data) +{ + return FALSE; +} +#else gboolean modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_data) { @@ -1796,6 +1803,7 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat return dimmed; } +#endif /* *********************** static utility functions ******************** */ diff --git a/src/widgets/modest-msg-view-window.h b/src/widgets/modest-msg-view-window.h index 1121687..46d1678 100644 --- a/src/widgets/modest-msg-view-window.h +++ b/src/widgets/modest-msg-view-window.h @@ -292,6 +292,18 @@ modest_msg_view_window_get_folder_type (ModestMsgViewWindow *window); gboolean modest_msg_view_window_transfer_mode_enabled (ModestMsgViewWindow *self); +/** + * modest_msg_view_window_add_to_contacts: + * @self: a #ModestMsgViewWindow + * + * activates the add to contacts use case. In Diablo and gnome it gets the + * clipboard selection current value and tries to add it to the addressbook. + * In fremantle, it shows the add to contacts dialog to select the recipient + * to add. + */ +void +modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self); + G_END_DECLS #endif /* __MODEST_MSG_VIEW_WINDOW_H__ */ -- 1.7.9.5