X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-ui-dimming-rules.c;h=ef93ecbc575e1c58db0f9e4192ab4bd3fc13c82b;hp=f3ba9d90331b54e20ddccd17735727dce3ad6ead;hb=e45958deaf9701399c552ea0d84c2447efacd4ca;hpb=8f16f11e5d4980b31fcdadab6609157714dc3e5a diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index f3ba9d9..ef93ecb 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -61,7 +61,6 @@ static gboolean _selected_folder_not_renameable (ModestMainWindow *win); static gboolean _selected_folder_not_deletable (ModestMainWindow *win); static gboolean _selected_folder_is_any_of_type (ModestWindow *win, TnyFolderType types[], guint ntypes); static gboolean _selected_folder_is_root_or_inbox (ModestMainWindow *win); -static gboolean _selected_folder_is_MMC_or_POP_root (ModestMainWindow *win); static gboolean _selected_folder_is_root (ModestMainWindow *win); static gboolean _header_view_is_all_selected (ModestMainWindow *win); static gboolean _selected_folder_is_empty (ModestMainWindow *win); @@ -70,7 +69,6 @@ static gboolean _selected_folder_is_same_as_source (ModestWindow *win); 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_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); @@ -391,11 +389,14 @@ modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data) if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) { dimmed = FALSE; } else { - const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (parent_folder)); - if (proto_str != NULL) { - /* If it's POP then dim */ - dimmed = (modest_protocol_info_get_transport_store_protocol (proto_str) == - MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE; + ModestProtocolType protocol_type = modest_tny_account_get_protocol_type (TNY_ACCOUNT (parent_folder)); + if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) { + ModestProtocolRegistry *protocol_registry; + + protocol_registry = modest_runtime_get_protocol_registry (); + /* If account does not support folders (pop) then dim */ + dimmed = (!modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, + MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS)); if (dimmed) modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error")); } @@ -510,11 +511,6 @@ modest_ui_dimming_rules_on_delete_folder (ModestWindow *win, gpointer user_data) modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error")); } if (!dimmed) { - dimmed = _selected_folder_is_MMC_or_POP_root (MODEST_MAIN_WINDOW(win)); - if (dimmed) - modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error")); - } - if (!dimmed) { dimmed = _transfer_mode_enabled (win); if (dimmed) modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete")); @@ -707,6 +703,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 +799,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, @@ -851,8 +870,9 @@ modest_ui_dimming_rules_on_details (ModestWindow *win, gpointer user_data) modest_dimming_rule_set_notification (rule, ""); } + } else { + return TRUE; } - } /* msg view window dimming rules */ @@ -1049,12 +1069,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)) { @@ -1754,37 +1770,7 @@ modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data modest_dimming_rule_set_notification (rule, ""); } if (!dimmed) { - dimmed = !_sending_in_progress (win); - if (dimmed) - modest_dimming_rule_set_notification (rule, ""); - } - - return dimmed; -} - -gboolean -modest_ui_dimming_rules_on_csm_cancel_sending (ModestWindow *win, gpointer user_data) -{ - ModestDimmingRule *rule = NULL; - TnyFolderType types[1]; - const DimmedState *state = NULL; - gboolean dimmed = FALSE; - - g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE); - g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE); - rule = MODEST_DIMMING_RULE (user_data); - state = modest_window_get_dimming_state (win); - - types[0] = TNY_FOLDER_TYPE_OUTBOX; - - /* Check dimmed rules */ - if (!dimmed) { - dimmed = !_selected_folder_is_any_of_type (win, types, 1); - if (dimmed) - modest_dimming_rule_set_notification (rule, ""); - } - if (!dimmed) { - dimmed = !_sending_in_progress (win); + dimmed = !state->sent_in_progress; if (dimmed) modest_dimming_rule_set_notification (rule, ""); } @@ -1867,6 +1853,8 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat int len = -1; sel = gtk_html_get_selection_html (GTK_HTML (focused), &len); do_check = !((sel == NULL) || (sel[0] == '\0')); + } else if (MODEST_IS_ATTACHMENTS_VIEW (focused)) { + do_check = FALSE; } if (do_check) { clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); @@ -2060,7 +2048,7 @@ _selected_folder_is_root_or_inbox (ModestMainWindow *win) /* Check pop and MMC accounts */ if (!result) { - result = _selected_folder_is_MMC_or_POP_root (win); + result = _selected_folder_is_root (win); } return result; @@ -2084,6 +2072,7 @@ _selected_folder_is_root (ModestMainWindow *win) modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view)); if (folder_store) { is_account = TNY_IS_ACCOUNT (folder_store); + g_object_unref (folder_store); folder_store = NULL; } @@ -2098,49 +2087,6 @@ _selected_folder_is_root (ModestMainWindow *win) /* Check folder type */ result = _selected_folder_is_any_of_type (MODEST_WINDOW(win), types, 1); - /* Check pop and MMC accounts */ - if (!result) { - result = _selected_folder_is_MMC_or_POP_root (win); - } - - return result; -} - -static gboolean -_selected_folder_is_MMC_or_POP_root (ModestMainWindow *win) -{ - GtkWidget *folder_view = NULL; - TnyFolderStore *parent_folder = NULL; - gboolean result = FALSE; - - folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win), - MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); - if (!folder_view) - return FALSE; - - /* Get selected folder as parent of new folder to create */ - parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view)); - if (!parent_folder) - return TRUE; - - if (TNY_IS_ACCOUNT (parent_folder)) { - /* If it's the local account then do not dim */ - if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) { - result = FALSE; - } else { - /* If it's the MMC root folder then dim it */ - if (!strcmp (tny_account_get_id (TNY_ACCOUNT (parent_folder)), MODEST_MMC_ACCOUNT_ID)) { - result = TRUE; - } else { - const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (parent_folder)); - /* If it's POP then dim */ - result = (modest_protocol_info_get_transport_store_protocol (proto_str) == - MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE; - } - } - } - g_object_unref (parent_folder); - return result; } @@ -2623,34 +2569,6 @@ _selected_msg_sent_in_progress (ModestWindow *win) static gboolean -_sending_in_progress (ModestWindow *win) -{ - GHashTable *send_queue_cache = NULL; - ModestCacheMgr *cache_mgr = NULL; - ModestTnySendQueue *send_queue = NULL; - GSList *send_queues = NULL, *node = NULL; - gboolean result = FALSE; - - g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (win), FALSE); - - /* Get send queue */ - 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); - - for (node = send_queues; node != NULL && !result; node = g_slist_next (node)) { - send_queue = MODEST_TNY_SEND_QUEUE (node->data); - - /* Check if send operation is in progress */ - result = modest_tny_send_queue_sending_in_progress (send_queue); - } - - return result; -} - -static gboolean _invalid_folder_for_purge (ModestWindow *win, ModestDimmingRule *rule) { @@ -2694,11 +2612,11 @@ _invalid_folder_for_purge (ModestWindow *win, result = TRUE; } } else { - const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account)); - ModestTransportStoreProtocol proto; - proto = modest_protocol_info_get_transport_store_protocol (proto_str); + ModestProtocolType protocol_type = modest_tny_account_get_protocol_type (TNY_ACCOUNT (account)); /* If it's a remote folder then dim */ - if (proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP) { + if (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (), + protocol_type, + MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS)) { result = TRUE; } }