Properly show and store from's from mailboxes in editor
authorJose Dapena Paz <jdapena@igalia.com>
Thu, 2 Apr 2009 20:57:27 +0000 (20:57 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Thu, 2 Apr 2009 20:57:27 +0000 (20:57 +0000)
pmo-trunk-r8570

src/hildon2/modest-msg-edit-window.c
src/modest-account-mgr-helpers.c
src/modest-account-mgr.h
src/modest-ui-actions.c
src/modest-utils.c

index 7fad0c1..01ea821 100644 (file)
@@ -36,6 +36,7 @@
 #include <tny-fs-stream.h>
 #include <tny-vfs-stream.h>
 #include <tny-camel-mem-stream.h>
+#include <modest-account-protocol.h>
 
 #include <config.h>
 
@@ -460,17 +461,48 @@ get_transports (void)
        GSList *cursor = accounts;
        while (cursor) {
                gchar *account_name = cursor->data;
-               gchar *from_string  = NULL;
                if (account_name) {
-                       from_string = modest_account_mgr_get_from_string (account_mgr,
-                                                                         account_name);
-               }
-               
-               if (from_string && account_name) {
-                       gchar *name = account_name;
-                       ModestPair *pair = modest_pair_new ((gpointer) name,
-                                               (gpointer) from_string , TRUE);
-                       transports = g_slist_prepend (transports, pair);
+
+                       gchar *transport_account;
+                       gboolean multi_mailbox = FALSE;
+                       gchar *proto;
+
+                       transport_account = modest_account_mgr_get_server_account_name (modest_runtime_get_account_mgr (),
+                                                                                       account_name,
+                                                                                       TNY_ACCOUNT_TYPE_TRANSPORT);
+                       if (transport_account) {
+                               proto = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), transport_account, 
+                                                                      MODEST_ACCOUNT_PROTO, TRUE);
+                               if (proto != NULL) {
+                                       ModestProtocol *protocol = 
+                                               modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
+                                                                                              MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS,
+                                                                                              proto);
+                                       if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
+                                               ModestPairList *pair_list;
+                                               pair_list = modest_account_protocol_get_from_list (MODEST_ACCOUNT_PROTOCOL (protocol),
+                                                                                                  account_name);
+                                               if (pair_list) {
+                                                       transports = g_slist_concat (transports, pair_list);
+                                                       multi_mailbox = TRUE;
+                                               }
+                                       }
+                               }
+                               g_free (proto);
+                       }
+
+                       if (!multi_mailbox) {
+                               gchar *from_string  = NULL;
+
+                               from_string = modest_account_mgr_get_from_string (account_mgr,
+                                                                                 account_name, NULL);
+                               if (from_string && account_name) {
+                                       gchar *name = account_name;
+                                       ModestPair *pair = modest_pair_new ((gpointer) name,
+                                                                           (gpointer) from_string , TRUE);
+                                       transports = g_slist_prepend (transports, pair);
+                               }
+                       }
                }
                
                cursor = cursor->next;
@@ -1512,7 +1544,11 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, const gchar
        /* Menubar. Update the state of some toggles */
        priv->from_field_protos = get_transports ();
        modest_selector_picker_set_pair_list (MODEST_SELECTOR_PICKER (priv->from_field), priv->from_field_protos);
-       modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name);
+       if (mailbox && modest_pair_list_find_by_first_as_string (priv->from_field_protos, mailbox)) {
+               modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) mailbox);
+       } else {
+               modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name);
+       }
        priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field));
        hildon_button_set_title (HILDON_BUTTON (priv->from_field),
                                 _("mail_va_from"));
@@ -1635,8 +1671,7 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        
        /* don't free these (except from) */
        data = g_slice_new0 (MsgData);
-       data->from    =  modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
-                                                            account_name);
+       data->from    =  g_strdup ((gchar *) modest_selector_picker_get_active_display_name (MODEST_SELECTOR_PICKER (priv->from_field)));
        data->account_name = g_strdup (account_name);
        data->to      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->to_field)));
        data->cc      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field)));
@@ -3251,8 +3286,10 @@ modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor)
        if (gtk_text_buffer_get_modified (priv->text_buffer))
                return TRUE;
 
-       /* TODO: check the mailbox too here */
        account_name = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field));
+       if ((priv->original_mailbox) && 
+           (!account_name || strcmp (account_name, priv->original_mailbox)))
+               return TRUE;
        if (!priv->original_account_name || strcmp(account_name, priv->original_account_name)) {
                return TRUE;
        }
index 0cb3db2..e680756 100644 (file)
@@ -34,6 +34,7 @@
 #include <modest-defs.h>
 #include <string.h>
 #include <strings.h>
+#include <modest-account-protocol.h>
 
 static const gchar * null_means_empty (const gchar * str);
 
@@ -854,7 +855,7 @@ modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self)
 gchar*
 modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name, const gchar *mailbox)
 {
-       gchar **from;
+       gchar *from;
        
        g_return_val_if_fail (self, NULL);
        g_return_val_if_fail (name, NULL);
@@ -874,7 +875,7 @@ modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name, c
                                ModestProtocol *protocol = 
                                        modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
                                                                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS,
-                                                                                      TRUE);
+                                                                                      proto);
                                if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
                                        from = modest_account_protocol_get_from (MODEST_ACCOUNT_PROTOCOL (protocol),
                                                                                 name,
index 81698a9..679c97d 100644 (file)
@@ -373,6 +373,8 @@ void  modest_account_mgr_set_display_name (ModestAccountMgr *self,
 gboolean modest_account_mgr_singleton_protocol_exists (ModestAccountMgr *mgr,
                                                       ModestProtocolType protocol_type);
 
+gchar * modest_account_mgr_get_string (ModestAccountMgr *self, const gchar *name,
+                                      const gchar *key, gboolean server_account);
 G_END_DECLS
 
 #endif /* __MODEST_ACCOUNT_MGR_H__ */
index 3d12d02..9bb5a1f 100644 (file)
@@ -824,7 +824,7 @@ modest_ui_actions_compose_msg(ModestWindow *win,
                g_printerr ("modest: failed to find Drafts folder\n");
                goto cleanup;
        }
-       from_str = modest_account_mgr_get_from_string (mgr, account_name);
+       from_str = modest_account_mgr_get_from_string (mgr, account_name, mailbox);
        if (!from_str) {
                g_printerr ("modest: failed get from string for '%s'\n", account_name);
                goto cleanup;
@@ -1715,9 +1715,9 @@ reply_forward_cb (ModestMailOperation *mail_op,
                goto cleanup;
 
        from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
-                                                  rf_helper->account_name);
-       signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
-                                                     rf_helper->account_name,
+                                                  rf_helper->account_name, NULL);
+       signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(), 
+                                                     rf_helper->account_name, 
                                                      &use_signature);
 
        /* Create reply mail */
@@ -2871,7 +2871,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        TnyTransportAccount *transport_account;
        ModestMailOperation *mail_operation;
        MsgData *data;
-       gchar *account_name, *from;
+       gchar *account_name;
        ModestAccountMgr *account_mgr;
        gboolean had_error = FALSE;
        ModestMainWindow *win = NULL;
@@ -2913,7 +2913,6 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                modest_msg_edit_window_free_msg_data (edit_window, data);
                return FALSE;
        }
-       from = modest_account_mgr_get_from_string (account_mgr, account_name);
 
        /* Create the mail operation */
        mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
@@ -2923,9 +2922,9 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        modest_mail_operation_save_to_drafts (mail_operation,
                                              transport_account,
                                              data->draft_msg,
-                                             from,
-                                             data->to,
-                                             data->cc,
+                                             data->from,
+                                             data->to, 
+                                             data->cc, 
                                              data->bcc,
                                              data->subject,
                                              data->plain_body,
@@ -2962,7 +2961,6 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        modest_msg_edit_window_set_modified (edit_window, FALSE);
 
        /* Frees */
-       g_free (from);
        g_free (account_name);
        g_object_unref (G_OBJECT (transport_account));
        g_object_unref (G_OBJECT (mail_operation));
@@ -3016,7 +3014,6 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        MsgData *data;
        ModestAccountMgr *account_mgr;
        gchar *account_name;
-       gchar *from;
        ModestMailOperation *mail_operation;
 
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
@@ -3065,14 +3062,13 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
 
 
        /* Create the mail operation */
-       from = modest_account_mgr_get_from_string (account_mgr, account_name);
        mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
 
        modest_mail_operation_send_new_mail (mail_operation,
                                             transport_account,
                                             data->draft_msg,
-                                            from,
+                                            data->from,
                                             data->to,
                                             data->cc,
                                             data->bcc,
@@ -3099,7 +3095,6 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        }
 
        /* Free data: */
-       g_free (from);
        g_free (account_name);
        g_object_unref (G_OBJECT (transport_account));
        g_object_unref (G_OBJECT (mail_operation));
index 7f6f17b..fdb9c9f 100644 (file)
@@ -739,7 +739,7 @@ modest_utils_get_account_name_from_recipient (const gchar *from_header, gchar **
                gchar *proto;
 
                from = 
-                       modest_account_mgr_get_from_string (mgr, node->data);
+                       modest_account_mgr_get_from_string (mgr, node->data, NULL);
                        
                if (from) {
                        gchar *from_email = 
@@ -759,7 +759,7 @@ modest_utils_get_account_name_from_recipient (const gchar *from_header, gchar **
                        g_free (from_header_email);
                        g_free (from);
                }
-               proto = modest_account_mgr_get_string (self, node->data, MODEST_ACCOUNT_PROTO, TRUE);
+               proto = modest_account_mgr_get_string (mgr, node->data, MODEST_ACCOUNT_PROTO, TRUE);
                if (proto != NULL) {
                        ModestProtocol *protocol = 
                                modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),