Remove spacing in headers view calendar, as it was causing a very bad
[modest] / src / modest-ui-dimming-rules.c
index e8d2c5c..0bbde7f 100644 (file)
@@ -52,7 +52,7 @@
 #include <gtkhtml/gtkhtml.h>
 #include <modest-runtime.h>
 #include <widgets/modest-header-window.h>
-#include <modest-folder-window.h>
+#include <widgets/modest-folder-window.h>
 
 
 static gboolean _invalid_attach_selected (ModestWindow *win, 
@@ -407,7 +407,7 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                        if (state)
                                dimmed = state->sent_in_progress;
                        if (dimmed)
-                               modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
+                               modest_dimming_rule_set_notification (rule, _CS_UNABLE_TO_DELETE);
                }
 
                /* This could happen if we're viewing a message of the
@@ -420,11 +420,14 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                 * or when viewing a search result.
                 */
                if (!dimmed) {
-                       if (!modest_msg_view_window_is_search_result (MODEST_MSG_VIEW_WINDOW(win))) {
-                               dimmed = !modest_msg_view_window_has_headers_model (MODEST_MSG_VIEW_WINDOW(win));
-                               if (dimmed) {
-                                       modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
-                               }
+                       TnyMsg *top_msg = NULL;
+                       top_msg = modest_msg_view_window_get_top_message ((ModestMsgViewWindow *) win);
+                       if (top_msg != NULL) {
+                               g_object_unref (top_msg);
+                               dimmed = TRUE;
+                       }
+                       if (dimmed) {
+                               modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
                        }
                }
        }
@@ -456,11 +459,24 @@ gboolean
 modest_ui_dimming_rules_on_fetch_images (ModestWindow *win, gpointer user_data)
 {
        gboolean dimmed = FALSE;
+       ModestDimmingRule *rule = NULL;
 
        g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), FALSE);
+       rule = MODEST_DIMMING_RULE (user_data);
 
        dimmed = !modest_msg_view_window_has_blocked_external_images (MODEST_MSG_VIEW_WINDOW (win));
 
+       if (!dimmed) {
+               dimmed = _transfer_mode_enabled (win);
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+       }
+       if (!dimmed) {
+               dimmed = _msg_download_in_progress (win);
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply"));
+       }
+
        return dimmed;
 }
 
@@ -555,14 +571,34 @@ modest_ui_dimming_rules_on_move_to (ModestWindow *win, gpointer user_data)
 static gboolean
 _forbid_outgoing_xfers (ModestWindow *window)
 {
-       const gchar *account_name;
-       TnyAccount *account;
+       const gchar *account_name = NULL;
+       TnyAccount *account = NULL;
        gboolean dimmed = FALSE;
 
-       account_name = modest_window_get_active_account (window);
-       account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store (),
-                                                              account_name,
-                                                              TNY_ACCOUNT_TYPE_STORE);
+#ifdef MODEST_TOOLKIT_HILDON2
+       /* We cannot just get the active account because the active
+          account of a header window that shows the headers of a
+          local account is the ID of the remote account */
+       if (MODEST_IS_HEADER_WINDOW (window)) {
+               ModestHeaderView *header_view;
+               TnyFolder *folder;
+
+               header_view = modest_header_window_get_header_view ((ModestHeaderWindow *) window);
+               folder = modest_header_view_get_folder (header_view);
+
+               if (folder) {
+                       account = modest_tny_folder_get_account (folder);
+                       g_object_unref (folder);
+               }
+       }
+#endif
+
+       if (!account) {
+               account_name = modest_window_get_active_account (window);
+               account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store (),
+                                                                      account_name,
+                                                                      TNY_ACCOUNT_TYPE_STORE);
+       }
 
        if (account) {
                ModestProtocolType protocol_type;
@@ -686,8 +722,7 @@ modest_ui_dimming_rules_on_select_all (ModestWindow *win, gpointer user_data)
        g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
        rule = MODEST_DIMMING_RULE (user_data);
 
-       focused = gtk_window_get_focus (GTK_WINDOW (win));
-
+       focused = gtk_container_get_focus_child ((GtkContainer *) win);
 
        if (!dimmed && GTK_IS_ENTRY (focused)) {
                const gchar *current_text;
@@ -728,7 +763,6 @@ modest_ui_dimming_rules_on_view_attachments (ModestWindow *win, gpointer user_da
        return dimmed;
 }
 
-#ifdef MODEST_TOOLKIT_HILDON2
 static gboolean
 _not_valid_attachments (ModestWindow *win, gboolean save_not_remove)
 {
@@ -788,7 +822,6 @@ _not_valid_attachments (ModestWindow *win, gboolean save_not_remove)
        return result;
 
 }
-#endif
 
 gboolean 
 modest_ui_dimming_rules_on_save_attachments (ModestWindow *win, gpointer user_data)
@@ -950,6 +983,27 @@ modest_ui_dimming_rules_on_set_style (ModestWindow *win, gpointer user_data)
 }
 
 gboolean 
+modest_ui_dimming_rules_on_editor_show_toolbar (ModestWindow *win, gpointer user_data)
+{
+       ModestDimmingRule *rule = NULL;
+       gboolean dimmed = FALSE;
+       
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+       g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
+       rule = MODEST_DIMMING_RULE (user_data);
+
+       /* Check common dimming rules */
+       ModestMsgEditFormat format;
+       format = modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (win));
+
+       dimmed = (format != MODEST_MSG_EDIT_FORMAT_HTML);
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_item_unavailable_plaintext"));
+       
+       return dimmed;
+}
+
+gboolean 
 modest_ui_dimming_rules_on_zoom (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
@@ -981,7 +1035,7 @@ modest_ui_dimming_rules_on_editor_paste (ModestWindow *win, gpointer user_data)
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
        rule = MODEST_DIMMING_RULE (user_data);
 
-       focused = gtk_window_get_focus (GTK_WINDOW (win));
+       focused = gtk_container_get_focus_child ((GtkContainer *) win);
 
        dimmed = MODEST_IS_ATTACHMENTS_VIEW (focused);
        
@@ -1027,7 +1081,7 @@ modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer
        return dimmed;
 }
 
-gboolean 
+gboolean
 modest_ui_dimming_rules_on_send (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
@@ -1057,6 +1111,14 @@ modest_ui_dimming_rules_on_send (ModestWindow *win, gpointer user_data)
                dimmed = ((gtk_text_buffer_get_char_count (to_buffer) +
                           gtk_text_buffer_get_char_count (cc_buffer) +
                           gtk_text_buffer_get_char_count (bcc_buffer)) == 0);
+
+               if (!dimmed) {
+                       if (modest_text_utils_no_recipient (to_buffer) &&
+                           modest_text_utils_no_recipient (cc_buffer) &&
+                           modest_text_utils_no_recipient (bcc_buffer))
+                               dimmed = TRUE;
+               }
+
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, _("mcen_ib_add_recipients_first"));
        }
@@ -1214,7 +1276,7 @@ modest_ui_dimming_rules_on_send_receive_all (ModestWindow *win, gpointer user_da
 gboolean
 modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_data)
 {
-       GSList *recipients;
+       GSList *recipients = NULL;
        gboolean has_recipients_to_add;
 
        g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
@@ -1300,7 +1362,7 @@ _invalid_clipboard_selected (ModestWindow *win,
        g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
 
        /* Get focuesed widget */
-       focused = gtk_window_get_focus (GTK_WINDOW (win));
+       focused = gtk_container_get_focus_child ((GtkContainer *) win);
 
        if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
                gboolean has_selection = FALSE;
@@ -1641,10 +1703,7 @@ modest_ui_dimming_rules_on_insert_image (ModestWindow *win,
 {
        g_return_val_if_fail (MODEST_MSG_EDIT_WINDOW (win), FALSE);
 
-       ModestMsgEditFormat format =
-         modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (win));
-
-       return (format != MODEST_MSG_EDIT_FORMAT_HTML);
+       return modest_ui_dimming_rules_on_set_style (win, user_data);
 }
 
 static gboolean 
@@ -1706,10 +1765,6 @@ _msgs_send_in_progress (void)
        return found;
 }
 
-/*****************************************************************************/
-/********************** HILDON2 only dimming rules ***************************/
-/*****************************************************************************/
-
 gboolean 
 modest_ui_dimming_rules_on_header_window_move_to (ModestWindow *win, gpointer user_data)
 {
@@ -1783,7 +1838,7 @@ modest_ui_dimming_rules_on_folder_window_move_to (ModestWindow *win, gpointer us
        return dimmed;
 }
 
-gboolean 
+gboolean
 modest_ui_dimming_rules_on_folder_window_delete (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
@@ -1793,7 +1848,7 @@ modest_ui_dimming_rules_on_folder_window_delete (ModestWindow *win, gpointer use
        g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
        rule = MODEST_DIMMING_RULE (user_data);
 
-       /* Check dimmed rule */ 
+       /* Check dimmed rule */
        dimmed = _transfer_mode_enabled (win);
        if (dimmed)
                modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));