* Merged from plugin system the actual fix for NB#87094
[modest] / src / modest-ui-dimming-rules.c
index 0b3d233..08aed61 100644 (file)
@@ -707,6 +707,33 @@ modest_ui_dimming_rules_always_dimmed (ModestWindow *win, gpointer user_data)
        return dimmed;
 }
 
+static gboolean
+_message_already_sent (ModestMsgViewWindow *view_window)
+{
+       TnyHeader *header;
+       TnyFolder *folder;
+       gboolean already_sent = FALSE;
+
+       header = modest_msg_view_window_get_header (view_window);
+       if (header) {
+               folder = tny_header_get_folder (header);
+               if (folder) {
+                       if (modest_tny_folder_guess_folder_type (folder) ==
+                           TNY_FOLDER_TYPE_OUTBOX) {                           
+                               ModestTnySendQueueStatus status = 
+                                       modest_tny_all_send_queues_get_msg_status (header);
+                               if (status == MODEST_TNY_SEND_QUEUE_UNKNOWN ||
+                                   status == MODEST_TNY_SEND_QUEUE_SENDING)
+                                       already_sent = TRUE;
+                       }
+                       g_object_unref (folder);
+               }
+               g_object_unref (header);
+       }
+       return already_sent;
+}
+
+
 gboolean 
 modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
 {
@@ -776,12 +803,8 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
 
                /* This could happen if we're viewing a message of the
                   outbox that has been already sent */
-               if (!dimmed) {
-                       ModestMsgViewWindow *view_window = MODEST_MSG_VIEW_WINDOW (win);
-                       if (modest_msg_view_window_last_message_selected (view_window) &&
-                           modest_msg_view_window_first_message_selected (view_window))
-                               dimmed = TRUE; 
-               }
+               if (!dimmed)
+                       dimmed = _message_already_sent (MODEST_MSG_VIEW_WINDOW(win));
                
                /* The delete button should be dimmed when viewing an attachment,
                 * but should be enabled when viewing a message from the list, 
@@ -1050,12 +1073,8 @@ modest_ui_dimming_rules_on_view_window_move_to (ModestWindow *win, gpointer user
 
        /* This could happen if we're viewing a message of the outbox
           that has been already sent */
-       if (!dimmed) {
-               ModestMsgViewWindow *view_window = MODEST_MSG_VIEW_WINDOW (win);
-               if (modest_msg_view_window_last_message_selected (view_window) &&
-                   modest_msg_view_window_first_message_selected (view_window))
-                       dimmed = TRUE; 
-       }
+       if (!dimmed)
+               dimmed = _message_already_sent (MODEST_MSG_VIEW_WINDOW(win));
 
        if (!dimmed) {
                if (MODEST_IS_MSG_VIEW_WINDOW (win)) {