* modest-tny-account-store:
authorAlberto Garcia <agarcia@igalia.com>
Thu, 25 Oct 2007 17:22:47 +0000 (17:22 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Thu, 25 Oct 2007 17:22:47 +0000 (17:22 +0000)
  (modest_tny_account_store_get_transport_account_from_outbox_header)
  New function to obtain the transport account from a message in the
  outbox

* modest-ui-actions:
  (open_msg_cb)
  Open Failed messages in the outbox with the editor and not with the
  viewer.

Fixes NB#74147

pmo-trunk-r3579

src/modest-tny-account-store.c
src/modest-tny-account-store.h
src/modest-ui-actions.c

index 94b1f46..b009bdf 100644 (file)
@@ -1762,3 +1762,34 @@ modest_tny_account_store_find_msg_in_outboxes (ModestTnyAccountStore *self,
 
        return msg;
 }
+
+TnyTransportAccount *
+modest_tny_account_store_get_transport_account_from_outbox_header(ModestTnyAccountStore *self, TnyHeader *header)
+{
+       TnyIterator *acc_iter;
+       ModestTnyAccountStorePrivate *priv;
+       TnyTransportAccount *header_acc = NULL;
+       const gchar *msg_id;
+
+       g_return_val_if_fail (MODEST_IS_TNY_ACCOUNT_STORE (self), NULL);
+       g_return_val_if_fail (TNY_IS_HEADER (header), NULL);
+       priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
+
+       msg_id = modest_tny_send_queue_get_msg_id (header);
+       acc_iter = tny_list_create_iterator (priv->transport_accounts);
+       while (!header_acc && !tny_iterator_is_done (acc_iter)) {
+               TnyTransportAccount *account = TNY_TRANSPORT_ACCOUNT (tny_iterator_get_current (acc_iter));
+               ModestTnySendQueue *send_queue;
+               ModestTnySendQueueStatus status;
+               send_queue = modest_runtime_get_send_queue(TNY_TRANSPORT_ACCOUNT(account));
+               status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
+               if (status != MODEST_TNY_SEND_QUEUE_UNKNONW) {
+                       header_acc = g_object_ref(account);
+               }
+               g_object_unref (account);
+               tny_iterator_next (acc_iter);
+       }
+
+       g_object_unref(acc_iter);
+       return header_acc;
+}
index 4c326be..df87c3c 100644 (file)
@@ -202,6 +202,19 @@ TnyMsg *modest_tny_account_store_find_msg_in_outboxes (ModestTnyAccountStore *se
                                                       TnyAccount **ac_out);
 
 
+/**
+ * modest_tny_account_store_get_transport_account_from_outbox_header:
+ * @self: a #ModestTnyAccountStore
+ * @header: a #TnyHeader
+ *
+ * Gets the transport account from a header that is in the outbox
+ *
+ * Returns: %NULL or a %TnyTransportAccount
+ */
+TnyTransportAccount *
+modest_tny_account_store_get_transport_account_from_outbox_header(ModestTnyAccountStore *self,
+                                                                 TnyHeader *header);
+
 G_END_DECLS
 
 #endif /* __MODEST_TNY_ACCOUNT_STORE_H__ */
index 83f499c..ab84241 100644 (file)
@@ -871,6 +871,7 @@ open_msg_cb (ModestMailOperation *mail_op, TnyHeader *header,  TnyMsg *msg, gpoi
        TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
        gchar *account = NULL;
        TnyFolder *folder;
+       gboolean open_in_editor = FALSE;
        
        /* Do nothing if there was any problem with the mail
           operation. The error will be shown by the error_handler of
@@ -889,15 +890,39 @@ open_msg_cb (ModestMailOperation *mail_op, TnyHeader *header,  TnyMsg *msg, gpoi
                folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
        }
 
+       if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
+               TnyTransportAccount *traccount = NULL;
+               ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
+               traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
+               if (traccount) {
+                       ModestTnySendQueue *send_queue = NULL;
+                       ModestTnySendQueueStatus status;
+                       char *msg_id;
+                       account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
+                                                  TNY_ACCOUNT(traccount)));
+                       send_queue = modest_runtime_get_send_queue(traccount);
+                       msg_id = modest_tny_send_queue_get_msg_id (header);
+                       status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
+                       /* Only open messages in outbox with the editor if they are in Failed state */
+                       if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
+                               open_in_editor = TRUE;
+                       }
+                       g_free(msg_id);
+                       g_object_unref(traccount);
+               } else {
+                       g_warning("Cannot get transport account for message in outbox!!");
+               }
+       } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
+               open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
+       }
+
        /* Get account */
        if (!account)
                account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
        if (!account)
                account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
        
-       /* If the header is in the drafts folder then open the editor,
-          else the message view window */
-       if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
+       if (open_in_editor) {
                ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
                const gchar *from_header = NULL;