X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodest-ui-dimming-rules.c;h=c739e557fb322b815812c180cd0cbb86f35d358f;hb=41c33d2e51bef2ae3d750c2848ab13cb4bb8d392;hp=b1e52747d8cfc6c7df14364272af92bf77fe8ca7;hpb=197bb9ad06a0fc246af700ce95271c6d8c316aaf;p=modest diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index b1e5274..c739e55 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -38,6 +38,7 @@ #include "modest-debug.h" #include "modest-tny-folder.h" #include "modest-tny-account.h" +#include "modest-tny-mime-part.h" #include "modest-text-utils.h" #include #include @@ -70,7 +71,6 @@ static gboolean _msg_download_in_progress (ModestWindow *win); static gboolean _msg_download_completed (ModestMainWindow *win); static gboolean _selected_msg_sent_in_progress (ModestWindow *win); static gboolean _sending_in_progress (ModestWindow *win); -static gboolean _invalid_account_for_purge (ModestWindow *win, ModestDimmingRule *rule); static gboolean _invalid_folder_for_purge (ModestWindow *win, ModestDimmingRule *rule); static gboolean _transfer_mode_enabled (ModestWindow *win); static gboolean _selected_folder_has_subfolder_with_same_name (ModestWindow *win); @@ -99,6 +99,7 @@ _define_main_window_dimming_state (ModestMainWindow *window) gboolean all_seen = TRUE; gboolean all_cached = TRUE; gboolean all_has_attach = TRUE; + TnyFolder *folder = NULL; g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(window), NULL); @@ -173,23 +174,28 @@ _define_main_window_dimming_state (ModestMainWindow *window) state->any_has_attachments = flags & TNY_HEADER_FLAG_ATTACHMENTS; /* sent in progress */ - msg_uid = modest_tny_send_queue_get_msg_id (header); - if (!state->sent_in_progress) { - cache_mgr = modest_runtime_get_cache_mgr (); - send_queue_cache = modest_cache_mgr_get_cache (cache_mgr, - MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); - - g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues); + folder = tny_header_get_folder (header); + if (folder) { + if (modest_tny_folder_guess_folder_type (folder) == TNY_FOLDER_TYPE_OUTBOX) { + msg_uid = modest_tny_send_queue_get_msg_id (header); + if (!state->sent_in_progress) { + cache_mgr = modest_runtime_get_cache_mgr (); + send_queue_cache = modest_cache_mgr_get_cache (cache_mgr, + MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); - for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) { - send_queue = MODEST_TNY_SEND_QUEUE (node->data); - - /* Check if msg uid is being processed inside send queue */ - found = modest_tny_send_queue_msg_is_being_sent (send_queue, msg_uid); + g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues); + + for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) { + send_queue = MODEST_TNY_SEND_QUEUE (node->data); + + /* Check if msg uid is being processed inside send queue */ + found = modest_tny_send_queue_msg_is_being_sent (send_queue, msg_uid); + } + state->sent_in_progress = found; + } } - state->sent_in_progress = found; + g_object_unref (folder); } - tny_iterator_next (iter); g_object_unref (header); } @@ -1021,6 +1027,14 @@ modest_ui_dimming_rules_on_view_window_move_to (ModestWindow *win, gpointer user if (dimmed) modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading")); } + if (!dimmed) { + dimmed = modest_window_get_dimming_state (win)->any_marked_as_deleted; + if (dimmed) { + gchar *msg = modest_ui_actions_get_msg_already_deleted_error_msg (win); + modest_dimming_rule_set_notification (rule, msg); + g_free (msg); + } + } if (!dimmed) { dimmed = _selected_msg_sent_in_progress (win); @@ -1240,14 +1254,11 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_ } } - /* cannot purge in pop accounts */ - if (!dimmed) { - dimmed = _invalid_account_for_purge (win, rule); - } - /* cannot purge in editable drafts nor pop folders */ if (!dimmed) { dimmed = _invalid_folder_for_purge (win, rule); + if (dimmed) + modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments")); } /* Check if the selected message in main window has attachments */ @@ -1594,10 +1605,9 @@ modest_ui_dimming_rules_on_send (ModestWindow *win, gpointer user_data) body_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (body_field)); subject = gtk_entry_get_text (GTK_ENTRY (subject_field)); - dimmed = ((subject == NULL || subject[0] == '\0') - || (gtk_text_buffer_get_char_count(body_buffer) == 0)); + dimmed = (subject == NULL || subject[0] == '\0'); if (dimmed) - modest_dimming_rule_set_notification (rule, _("mcen_ib_subject_or_body_not_modified")); + modest_dimming_rule_set_notification (rule, _("mcen_ib_subject_not_modified")); } if (!dimmed) { @@ -2115,7 +2125,7 @@ _header_view_is_all_selected (ModestMainWindow *win) static gboolean _selected_folder_is_empty (ModestMainWindow *win) { - GtkWidget *folder_view = NULL; + GtkWidget *folder_view = NULL, *header_view = NULL; TnyFolderStore *folder = NULL; gboolean result = FALSE; @@ -2124,8 +2134,12 @@ _selected_folder_is_empty (ModestMainWindow *win) /* Get folder view */ folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win), MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); + + header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win), + MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW); + /* If no folder view, always dimmed */ - if (!folder_view) + if (!folder_view || !header_view) return TRUE; /* Get selected folder as parent of new folder to create */ @@ -2137,7 +2151,9 @@ _selected_folder_is_empty (ModestMainWindow *win) } /* Check folder type */ - result = tny_folder_get_all_count (TNY_FOLDER (folder)) == 0; + if (modest_header_view_is_empty (MODEST_HEADER_VIEW (header_view)) || + tny_folder_get_all_count (TNY_FOLDER (folder)) == 0) + result = TRUE; /* free */ g_object_unref (folder); @@ -2406,7 +2422,7 @@ _invalid_attach_selected (ModestWindow *win, while (!tny_iterator_is_done (iter) && !result) { TnyMimePart *mime_part = TNY_MIME_PART (tny_iterator_get_current (iter)); TnyList *nested_list = tny_simple_list_new (); - if (!for_remove && TNY_IS_MSG (mime_part)) { + if (!for_remove && modest_tny_mime_part_is_msg (mime_part)) { selected_messages = TRUE; result = TRUE; } @@ -2601,49 +2617,6 @@ _sending_in_progress (ModestWindow *win) } static gboolean -_invalid_account_for_purge (ModestWindow *win, - ModestDimmingRule *rule) -{ - const gchar *account_name; - ModestTnyAccountStore *account_store; - TnyAccount *store_account = NULL; - gboolean result = FALSE; - const gchar *protocol_name; - - account_name = modest_window_get_active_account (win); - if (account_name == NULL) - goto frees; - - account_store = modest_runtime_get_account_store (); - store_account = modest_tny_account_store_get_server_account (account_store, account_name, TNY_ACCOUNT_TYPE_STORE); - if (store_account == NULL) - goto frees; - - protocol_name = tny_account_get_proto (store_account); - if (modest_protocol_info_get_transport_store_protocol (protocol_name) == MODEST_PROTOCOL_STORE_POP) { - gint n_selected = 0; - result = TRUE; - - if (MODEST_IS_MSG_VIEW_WINDOW (win)) { - TnyList *attachments; - attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win)); - n_selected = tny_list_get_length (attachments); - g_object_unref (attachments); - } - - modest_dimming_rule_set_notification (rule, - ngettext ("mail_ib_unable_to_pure_attach_pop_mail_singular", - "mail_ib_unable_to_pure_attach_pop_mail_plural", - n_selected)); - - } -frees: - if (store_account) - g_object_unref (store_account); - return result; -} - -static gboolean _invalid_folder_for_purge (ModestWindow *win, ModestDimmingRule *rule) { @@ -2659,7 +2632,7 @@ _invalid_folder_for_purge (ModestWindow *win, folder = tny_msg_get_folder (msg); g_object_unref (msg); if (folder == NULL) { - modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments")); + result = TRUE; goto frees; } } else if (MODEST_IS_MAIN_WINDOW (win)) { @@ -2667,7 +2640,8 @@ _invalid_folder_for_purge (ModestWindow *win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); if (!folder_view) return FALSE; - folder = TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view))); + folder = (TnyFolder *) modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)); + /* Could be a folder store */ if (folder == NULL || ! TNY_IS_FOLDER (folder)) goto frees; } else { @@ -2684,31 +2658,14 @@ _invalid_folder_for_purge (ModestWindow *win, if (_selected_folder_is_any_of_type (win, types, 2)) { result = TRUE; - modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_editable_msg")); - } else { - result = FALSE; } } else { const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account)); - /* If it's POP then dim */ - if (modest_protocol_info_get_transport_store_protocol (proto_str) == - MODEST_PROTOCOL_STORE_POP) { - TnyList *attachments = NULL; - gint n_selected = 0; + ModestTransportStoreProtocol proto; + proto = modest_protocol_info_get_transport_store_protocol (proto_str); + /* If it's a remote folder then dim */ + if (proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP) { result = TRUE; - - /* TODO: This check is here to prevent a gwarning, but this looks like a logic error. - * murrayc */ - if (MODEST_IS_MSG_VIEW_WINDOW (win)) { - attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win)); - n_selected = tny_list_get_length (attachments); - g_object_unref (attachments); - } - - modest_dimming_rule_set_notification (rule, - ngettext ("mail_ib_unable_to_pure_attach_pop_mail_singular", - "mail_ib_unable_to_pure_attach_pop_mail_plural", - n_selected)); } }