* Added code to show dialog for choosing recipients
authorJose Dapena Paz <jdapena@igalia.com>
Tue, 25 Nov 2008 13:38:10 +0000 (13:38 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Tue, 25 Nov 2008 13:38:10 +0000 (13:38 +0000)
* Refactored code to integrate properly with old add to contacts
  functionality.

pmo-trunk-r6398

src/gnome/modest-main-window-ui.h
src/gnome/modest-msg-view-window.c
src/hildon2/modest-main-window-ui.h
src/hildon2/modest-msg-view-window.c
src/maemo/modest-main-window-ui.h
src/maemo/modest-msg-view-window.c
src/modest-ui-actions.c
src/modest-ui-actions.h
src/modest-ui-dimming-rules.c
src/widgets/modest-msg-view-window.h

index a6074f8..b5397b5 100644 (file)
@@ -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"),  "<CTRL>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) },
 
index 172bb0f..35fe46e 100644 (file)
@@ -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));
+}
+
index 8ddaa22..b4b8913 100644 (file)
@@ -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"), "<CTRL>W", NULL,  G_CALLBACK (modest_ui_actions_on_close_window) },
index 28412cd..3fc077b 100644 (file)
@@ -48,7 +48,8 @@
 #include <modest-text-utils.h>
 #include <modest-account-mgr-helpers.h>
 #include "modest-progress-bar.h"
-#include "hildon/hildon-pannable-area.h"
+#include <hildon/hildon-pannable-area.h>
+#include <hildon/hildon-picker-dialog.h>
 #include "modest-defs.h"
 #include "modest-hildon-includes.h"
 #include "modest-ui-dimming-manager.h"
@@ -57,6 +58,7 @@
 #include <modest-mime-part-view.h>
 #include <modest-isearch-view.h>
 #include <modest-tny-mime-part.h>
+#include <modest-address-book.h>
 #include <math.h>
 #include <errno.h>
 #include <glib/gstdio.h>
@@ -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);
+}
index 9bbe466..f41327e 100644 (file)
@@ -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"),  "<CTRL>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) },
 
index 4f47097..eade580 100644 (file)
@@ -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));
+}
+
index 27c367f..86dbe0f 100644 (file)
@@ -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;
index 1408a30..02ef1ba 100644 (file)
@@ -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);
index af08d11..e84e456 100644 (file)
@@ -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 ******************** */
 
index 1121687..46d1678 100644 (file)
@@ -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__ */