Add to contacts now also works with only a TnyHeader in viewer
authorJose Dapena Paz <jdapena@igalia.com>
Tue, 20 Jan 2009 15:44:31 +0000 (15:44 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Tue, 20 Jan 2009 15:44:31 +0000 (15:44 +0000)
pmo-trunk-r7202

src/hildon2/modest-msg-view-window.c
src/modest-tny-msg.c
src/modest-tny-msg.h
src/modest-ui-dimming-rules.c

index 5519206..790e3cd 100644 (file)
@@ -3137,8 +3137,18 @@ modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self)
        gboolean contacts_to_add = FALSE;
 
        msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view));
-       if (msg == NULL) return;
-       recipients = modest_tny_msg_get_all_recipients_list (msg);
+       if (msg == NULL) {
+               TnyHeader *header;
+
+               header = modest_msg_view_window_get_header (self);
+               if (header == NULL)
+                       return;
+               recipients = modest_tny_msg_header_get_all_recipients_list (header);
+               g_object_unref (header);
+       } else {
+               recipients = modest_tny_msg_get_all_recipients_list (msg);
+               g_object_unref (msg);
+       }
 
        if (recipients != NULL) {
                GtkWidget *picker_dialog;
@@ -3185,5 +3195,4 @@ modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self)
        }
        
        if (recipients) {g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients);}
-       g_object_unref (msg);
 }
index 40ecc2f..e481d9f 100644 (file)
@@ -959,16 +959,11 @@ modest_tny_msg_estimate_size (const gchar *plain_body, const gchar *html_body,
 }
 
 GSList *
-modest_tny_msg_get_all_recipients_list (TnyMsg *msg)
+modest_tny_msg_header_get_all_recipients_list (TnyHeader *header)
 {
-       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;
 
@@ -995,3 +990,22 @@ modest_tny_msg_get_all_recipients_list (TnyMsg *msg)
        return recipients;
 }
 
+GSList *
+modest_tny_msg_get_all_recipients_list (TnyMsg *msg)
+{
+       TnyHeader *header = NULL;
+       GSList *recipients = NULL;
+
+       if (msg == NULL)
+               return NULL;
+
+       header = tny_msg_get_header (msg);
+       if (header == NULL)
+               return NULL;
+
+       recipients = modest_tny_msg_header_get_all_recipients_list (header);
+       g_object_unref (header);
+
+       return recipients;
+}
+
index 88d4532..91ae148 100644 (file)
@@ -199,6 +199,17 @@ modest_tny_msg_estimate_size (const gchar *plain_body, const gchar *html_body,
 
 /**
  * modest_tny_msg_get_all_recipients_list:
+ * @header: a #TnyHeader
+ *
+ * Obtains a list of all the addresses available in @header.
+ *
+ * Returns: a newly allocated #GSList of strings. Caller should free strings and list.
+ */
+GSList *
+modest_tny_msg_header_get_all_recipients_list (TnyHeader *header);
+
+/**
+ * modest_tny_msg_get_all_recipients_list:
  * @msg: a #TnyMsg
  *
  * Obtains a list of all the addresses available in a message header.
index 79f9447..9dc3076 100644 (file)
@@ -1915,10 +1915,23 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat
        msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
 
        /* Message is loaded asynchronously, so this could happen */
-       if (!msg)
-               return TRUE;
+       if (!msg) {
+#ifdef MODEST_TOOLKIT_HILDON2
+               TnyHeader *header;
+
+               header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
+               if (!header)
+                       return TRUE;
 
-       recipients = modest_tny_msg_get_all_recipients_list (msg);
+               recipients = modest_tny_msg_header_get_all_recipients_list (header);
+               g_object_unref (header);
+#else
+               return TRUE;
+#endif
+       } else {
+               recipients = modest_tny_msg_get_all_recipients_list (msg);
+               g_object_unref (msg);
+       }
 
        has_recipients_to_add = FALSE;
        for (node = recipients; node != NULL; node = g_slist_next (node)) {
@@ -1930,7 +1943,6 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat
 
        g_slist_foreach (recipients, (GFunc) g_free, NULL);
        g_slist_free (recipients);
-       g_object_unref (msg);
   
        return !has_recipients_to_add;
 }