* Added two new signal handlers to detect when messages are bieng processed to be...
[modest] / src / modest-ui-dimming-rules.c
index 8f9fbc7..36f3413 100644 (file)
@@ -54,7 +54,8 @@ static gboolean _selected_folder_is_root (ModestMainWindow *win);
 static gboolean _selected_folder_is_empty (ModestMainWindow *win);
 static gboolean _msg_download_in_progress (ModestMsgViewWindow *win);
 static gboolean _msg_download_completed (ModestMainWindow *win);
 static gboolean _selected_folder_is_empty (ModestMainWindow *win);
 static gboolean _msg_download_in_progress (ModestMsgViewWindow *win);
 static gboolean _msg_download_completed (ModestMainWindow *win);
-static gboolean _msg_sent_in_progress (ModestWindow *win);
+static gboolean _selected_msg_sent_in_progress (ModestWindow *win);
+static gboolean _sending_in_progress (ModestWindow *win);
 static gboolean _marked_as_deleted (ModestWindow *win);
 
 
 static gboolean _marked_as_deleted (ModestWindow *win);
 
 
@@ -200,7 +201,7 @@ modest_ui_dimming_rules_on_open_msg (ModestWindow *win, gpointer user_data)
        if (!dimmed)
                dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);
        if (!dimmed) {
        if (!dimmed)
                dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);
        if (!dimmed) {
-               dimmed = _msg_sent_in_progress (win);
+               dimmed = _selected_msg_sent_in_progress (win);
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, _("TEST"));
        }
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, _("TEST"));
        }
@@ -314,7 +315,7 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                                modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_delete"));
                }
                if (!dimmed) {
                                modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_delete"));
                }
                if (!dimmed) {
-                       dimmed = _msg_sent_in_progress (win);
+                       dimmed = _selected_msg_sent_in_progress (win);
                        if (dimmed)
                                modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_delete"));
                }
                        if (dimmed)
                                modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_delete"));
                }
@@ -613,7 +614,8 @@ modest_ui_dimming_rules_on_view_next (ModestWindow *win, gpointer user_data)
 }
 
 
 }
 
 
-gboolean modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpointer user_data)
+gboolean 
+modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpointer user_data)
 {
        const gboolean dimmed = 
                !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
 {
        const gboolean dimmed = 
                !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
@@ -622,6 +624,36 @@ gboolean modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpoin
        return dimmed;
 }
 
        return dimmed;
 }
 
+gboolean 
+modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data)
+{
+       gboolean dimmed = FALSE;
+
+       /* Check dimmed rule */ 
+       if (!dimmed) 
+               dimmed = !_sending_in_progress (win);
+               
+       return dimmed;
+}
+
+gboolean 
+modest_ui_dimming_rules_on_send_receive (ModestWindow *win, gpointer user_data)
+{
+       ModestDimmingRule *rule = NULL;
+       gboolean dimmed = FALSE;
+       
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+       rule = MODEST_DIMMING_RULE (user_data);
+       /* Check dimmed rule */ 
+       if (!dimmed) {
+               dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
+                                                         TRUE);        
+               modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
+       }
+
+       return dimmed;
+}
 
 /* *********************** static utility functions ******************** */
 
 
 /* *********************** static utility functions ******************** */
 
@@ -1130,66 +1162,97 @@ _msg_download_completed (ModestMainWindow *win)
 }
 
 static gboolean
 }
 
 static gboolean
-_msg_sent_in_progress (ModestWindow *win)
+_selected_msg_sent_in_progress (ModestWindow *win)
 {
 {
-/*     ModestTnySendQueue *send_queue = NULL; */
-/*     GtkWidget *header_view = NULL;  */
-/*     ModestTnyAccountStore *acc_store = NULL; */
-/*     TnyAccount *account = NULL;      */
-/*     TnyList *header_list = NULL; */
-/*     TnyIterator *iter = NULL; */
-/*     TnyHeader *header = NULL; */
-/*     const gchar *account_name = NULL; */
+       ModestTnySendQueue *send_queue = NULL;
+       GtkWidget *header_view = NULL;
+       ModestTnyAccountStore *acc_store = NULL;
+       TnyAccount *account = NULL;
+       TnyList *header_list = NULL;
+       TnyIterator *iter = NULL;
+       TnyHeader *header = NULL;
+       const gchar *account_name = NULL;
        gboolean result = FALSE;
        gboolean result = FALSE;
-/*     gchar *id = NULL; */
+       gchar *id = NULL;
        
        
-/*     g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), FALSE); */
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), FALSE);
+       
+       /* Get transport account */
+       acc_store = modest_runtime_get_account_store();
+       account_name = modest_window_get_active_account (win);
        
        
-/*     /\* Get transport account *\/   */
-/*     acc_store = modest_runtime_get_account_store(); */
-/*     account_name = modest_window_get_active_account (win);   */
-/*     account = modest_tny_account_store_get_transport_account_for_open_connection (acc_store, account_name); */
+       /* If no account defined, this action must be always dimmed  */
+       if (account_name == NULL) return FALSE;
+       account = modest_tny_account_store_get_transport_account_for_open_connection (acc_store, account_name);
+       if (!TNY_IS_TRANSPORT_ACCOUNT (account)) return FALSE;
 
 
-/*     /\* Get send queue for current ransport account *\/  */
-/*     send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT(account)); */
-/*     g_return_val_if_fail (MODEST_IS_TNY_SEND_QUEUE (send_queue), FALSE); */
+       /* Get send queue for current ransport account */
+       send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT(account));
+       g_return_val_if_fail (MODEST_IS_TNY_SEND_QUEUE (send_queue), FALSE);
 
 
-/*     if (MODEST_IS_MAIN_WINDOW(win)) { */
+       if (MODEST_IS_MAIN_WINDOW(win)) {
                
                
-/*             /\* Get header view to check selected messages *\/ */
-/*             header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win), */
-/*                                                                MODEST_WIDGET_TYPE_HEADER_VIEW); */
+               /* Get header view to check selected messages */
+               header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                                  MODEST_WIDGET_TYPE_HEADER_VIEW);
                
                
-/*             /\* Get selected headers *\/ */
-/*             header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view)); */
+               /* Get selected headers */
+               header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
 
 
-/*             /\* Get message header *\/ */
-/*             if (!header_list) return FALSE; */
-/*             iter = tny_list_create_iterator (header_list); */
-/*             header = TNY_HEADER (tny_iterator_get_current (iter)); */
+               /* Get message header */
+               if (!header_list) return FALSE;
+               iter = tny_list_create_iterator (header_list);
+               header = TNY_HEADER (tny_iterator_get_current (iter));
 
 
-/*             /\* Get message id *\/ */
-/*             id = g_strdup(tny_header_get_message_id (header));               */
+               /* Get message id */
+               id = g_strdup(tny_header_get_message_id (header));
                
                
-/*         } else if (MODEST_IS_MSG_VIEW_WINDOW(win)) { */
+        } else if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
                
                
-/*             /\* Get message header *\/ */
-/*             header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));                */
+               /* Get message header */
+               header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
 
 
-/*             /\* Get message id *\/ */
-/*             id = g_strdup(tny_header_get_message_id (header));               */
-/*     } */
+               /* Get message id */
+               id = g_strdup(tny_header_get_message_id (header));
+       }
 
 
-/*     /\* Check if msg id is being processed inside send queue *\/ */
-/*     result = modest_tny_send_queue_msg_is_being_sent (send_queue, id); */
+       /* Check if msg id is being processed inside send queue */
+       result = modest_tny_send_queue_msg_is_being_sent (send_queue, id);
 
 
-/*     /\* Free *\/ */
-/*     g_free(id); */
-/*     g_object_unref (header); */
-/*     g_free(header_list); */
-/*     g_free(iter); */
+       /* Free */
+       g_free(id);
+       g_object_unref (header);
+       g_free(header_list);
+       g_free(iter);
 
        return result;
 }
 
 
 
        return result;
 }
 
 
+static gboolean
+_sending_in_progress (ModestWindow *win)
+{
+       ModestTnySendQueue *send_queue = NULL;
+       ModestTnyAccountStore *acc_store = NULL;
+       TnyAccount *account = NULL;
+       const gchar *account_name = NULL;
+       gboolean result = FALSE;
+       
+       /* Get transport account */
+       acc_store = modest_runtime_get_account_store();
+       account_name = modest_window_get_active_account (win);
+
+       /* If no account defined, this action must be always dimmed  */
+       if (account_name == NULL) return FALSE;
+       account = modest_tny_account_store_get_transport_account_for_open_connection (acc_store, account_name);
+       if (!TNY_IS_TRANSPORT_ACCOUNT (account)) return FALSE;
+
+       /* Get send queue for current ransport account */
+       send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT(account));
+       g_return_val_if_fail (MODEST_IS_TNY_SEND_QUEUE (send_queue), FALSE);
+
+       /* Check if send queue is perfimring any send operation */
+       result = modest_tny_send_queue_sending_in_progress (send_queue);
+
+       return result;
+}