X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-ui-dimming-rules.c;h=94a393c7df581b64faafdc33ca6d4594ce20598c;hp=0d1b12608c644b0e7a4bc51f0cf26973c9ded0f3;hb=fb572256360aee64ab8edc6abb69f13436db8330;hpb=e01e0d7d2200ea1da0a969e7e138e99e812f1ece diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index 0d1b126..94a393c 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -33,14 +33,18 @@ #include #include "modest-ui-dimming-rules.h" +#include "modest-ui-actions.h" #include "modest-dimming-rule.h" +#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 #include #include +#include static gboolean _folder_is_any_of_type (TnyFolder *folder, TnyFolderType types[], guint ntypes); @@ -66,7 +70,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); @@ -95,6 +98,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); @@ -169,23 +173,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); } @@ -317,7 +326,6 @@ modest_ui_dimming_rules_define_dimming_state (ModestWindow *window) return state; } - gboolean modest_ui_dimming_rules_on_new_msg (ModestWindow *win, gpointer user_data) { @@ -370,6 +378,9 @@ modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data) /* Get selected folder as parent of new folder to create */ folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win), MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); + if (!folder_view) /* folder view may not have been created yet */ + return TRUE; + parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view)); if (!parent_folder) return TRUE; @@ -522,15 +533,11 @@ modest_ui_dimming_rules_on_sort (ModestWindow *win, gpointer user_data) rule = MODEST_DIMMING_RULE (user_data); /* Check dimmed rule */ - if (!dimmed) { + if (!dimmed) dimmed = _selected_folder_is_root (MODEST_MAIN_WINDOW(win)); - modest_dimming_rule_set_notification (rule, _CS("ckdg_ib_nothing_to_sort")); - } - if (!dimmed) { + if (!dimmed) dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win)); - modest_dimming_rule_set_notification (rule, _CS("ckdg_ib_nothing_to_sort")); - } return dimmed; @@ -595,8 +602,11 @@ modest_ui_dimming_rules_on_open_msg (ModestWindow *win, gpointer user_data) } if (!dimmed) { dimmed = state->any_marked_as_deleted; - if (dimmed) - modest_dimming_rule_set_notification (rule, _("mcen_ib_message_already_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); @@ -617,19 +627,20 @@ modest_ui_dimming_rules_on_reply_msg (ModestWindow *win, gpointer user_data) g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE); rule = MODEST_DIMMING_RULE (user_data); + types[0] = TNY_FOLDER_TYPE_DRAFTS; + types[1] = TNY_FOLDER_TYPE_OUTBOX; + types[2] = TNY_FOLDER_TYPE_ROOT; + + /* Check dimmed rule */ + if (!dimmed) { + dimmed = _selected_folder_is_any_of_type (win, types, 3); + if (dimmed) + modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply")); + } + /* main window dimming rules */ if (MODEST_IS_MAIN_WINDOW(win)) { - types[0] = TNY_FOLDER_TYPE_DRAFTS; - types[1] = TNY_FOLDER_TYPE_OUTBOX; - types[2] = TNY_FOLDER_TYPE_ROOT; - - /* Check dimmed rule */ - if (!dimmed) { - dimmed = _selected_folder_is_any_of_type (win, types, 3); - if (dimmed) - modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply")); - } if (!dimmed) { dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win)); if (dimmed) @@ -695,6 +706,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) { @@ -717,28 +755,29 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data) dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data); } if (!dimmed) { - dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE; - if (dimmed) { - gchar *num = NULL, *message = NULL; - - num = g_strdup_printf ("%d", state->already_opened_msg); - message = g_strdup_printf(_("mcen_nc_unable_to_delete_n_messages"), num); - modest_dimming_rule_set_notification (rule, message); - g_free(num); - g_free(message); - } - + dimmed = state->sent_in_progress; + if (dimmed) + modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete")); } if (!dimmed) { dimmed = state->any_marked_as_deleted; if (dimmed) { - modest_dimming_rule_set_notification (rule, _("mcen_ib_message_already_deleted")); + 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 = state->sent_in_progress; - if (dimmed) - modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete")); + dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE; + if (dimmed) { + gchar *message = NULL; + + message = g_strdup_printf(_("mcen_nc_unable_to_delete_n_messages"), + state->already_opened_msg); + modest_dimming_rule_set_notification (rule, message); + g_free(message); + } + } } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) { @@ -749,9 +788,22 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data) } if (!dimmed) { dimmed = state->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 = state->sent_in_progress; if (dimmed) - modest_dimming_rule_set_notification (rule, _("mcen_ib_message_already_deleted")); + modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete")); } + + /* This could happen if we're viewing a message of the + outbox that has been already sent */ + 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, @@ -821,8 +873,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 */ @@ -835,6 +888,13 @@ modest_ui_dimming_rules_on_details (ModestWindow *win, gpointer user_data) if (dimmed) modest_dimming_rule_set_notification (rule, ""); } + 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, ""); + } } return dimmed; @@ -933,7 +993,7 @@ modest_ui_dimming_rules_on_main_window_move_to (ModestWindow *win, gpointer user /* Check diming rules for folders transfer */ - if (gtk_widget_is_focus (folder_view)) { + if (folder_view && gtk_widget_is_focus (folder_view)) { TnyFolderType types[5]; types[0] = TNY_FOLDER_TYPE_DRAFTS; @@ -946,12 +1006,12 @@ modest_ui_dimming_rules_on_main_window_move_to (ModestWindow *win, gpointer user if (!dimmed) { dimmed = _selected_folder_not_moveable (MODEST_MAIN_WINDOW(win)); if (dimmed) - modest_dimming_rule_set_notification (rule, _("emev_bd_unabletomove_items")); + modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items")); } if (!dimmed) { dimmed = _selected_folder_is_any_of_type (win, types, 5); if (dimmed) - modest_dimming_rule_set_notification (rule, _("emev_bd_unabletomove_itemsr")); + modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items")); } } @@ -959,14 +1019,14 @@ modest_ui_dimming_rules_on_main_window_move_to (ModestWindow *win, gpointer user if (!dimmed) { dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE; if (dimmed) { - gchar *message = g_strdup_printf(_("emev_bd_unabletomove_items"), + gchar *message = g_strdup_printf(_("emev_nc_unabletomove_items"), state->already_opened_msg); modest_dimming_rule_set_notification (rule, message); g_free(message); } } if (!dimmed) { - if (!gtk_widget_is_focus (folder_view)) + if (!(folder_view && gtk_widget_is_focus (folder_view))) dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data); } @@ -995,8 +1055,27 @@ 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); + if (dimmed) + modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_item")); + } + + /* This could happen if we're viewing a message of the outbox + that has been already sent */ + if (!dimmed) + dimmed = _message_already_sent (MODEST_MSG_VIEW_WINDOW(win)); + + if (!dimmed) { if (MODEST_IS_MSG_VIEW_WINDOW (win)) { /* The move_to button should be dimmed when viewing an attachment, * but should be enabled when viewing a message from the list, @@ -1008,7 +1087,7 @@ modest_ui_dimming_rules_on_view_window_move_to (ModestWindow *win, gpointer user } if (dimmed) - modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_move_mail_attachment")); + modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_item")); } return dimmed; @@ -1081,12 +1160,12 @@ modest_ui_dimming_rules_on_paste (ModestWindow *win, gpointer user_data) if (!dimmed) { dimmed = _selected_folder_is_same_as_source (win); if (dimmed) - modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_copy_samefolder")); + modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_copy_target_error")); } if (!dimmed) { dimmed = _selected_folder_has_subfolder_with_same_name (win); if (dimmed) - modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_copy_samefolder")); + modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_copy_target_error")); } return dimmed; @@ -1201,9 +1280,39 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_ modest_dimming_rule_set_notification (rule, _("FIXME:no attachment selected")); } + /* Messages as attachments could not be removed */ + if (!dimmed && MODEST_IS_MSG_VIEW_WINDOW (win)) { + TnyList *attachments; + TnyIterator *iter; + attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW (win)); + if (attachments) { + iter = tny_list_create_iterator (attachments); + while (!tny_iterator_is_done (iter) && !dimmed) { + TnyMimePart *mime_part = (TnyMimePart *) + tny_iterator_get_current (iter); + if (modest_tny_mime_part_is_msg (mime_part)) + dimmed = TRUE; + g_object_unref (mime_part); + tny_iterator_next (iter); + } + g_object_unref (iter); + g_object_unref (attachments); + } + } + + if (!dimmed) { + + dimmed = _selected_msg_sent_in_progress (win); + if (dimmed) { + modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments")); + } + } + /* 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 */ @@ -1225,7 +1334,6 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_ modest_dimming_rule_set_notification (rule, _("mail_ib_attach_not_local")); } - return dimmed; } @@ -1318,17 +1426,17 @@ modest_ui_dimming_rules_on_cut (ModestWindow *win, gpointer user_data) if (!dimmed) { dimmed = _selected_folder_not_deletable (MODEST_MAIN_WINDOW(win)); if (dimmed) - modest_dimming_rule_set_notification (rule, _("emev_bd_unabletomove_items")); + modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items")); } if (!dimmed) { dimmed = _selected_folder_is_root_or_inbox (MODEST_MAIN_WINDOW(win)); if (dimmed) - modest_dimming_rule_set_notification (rule, _("emev_bd_unabletomove_itemsr")); + modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items")); } if (!dimmed) { dimmed = _selected_folder_is_any_of_type (win, types, 3); if (dimmed) - modest_dimming_rule_set_notification (rule, _("emev_bd_unabletomove_itemsr")); + modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items")); } } } @@ -1342,7 +1450,7 @@ modest_ui_dimming_rules_on_copy (ModestWindow *win, gpointer user_data) ModestDimmingRule *rule = NULL; const DimmedState *state = NULL; gboolean dimmed = 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); @@ -1485,9 +1593,10 @@ modest_ui_dimming_rules_on_editor_paste (ModestWindow *win, gpointer user_data) if (!dimmed) { ModestEmailClipboard *e_clipboard = modest_runtime_get_email_clipboard (); + const gchar *clipboard_text = modest_msg_edit_window_get_clipboard_text (MODEST_MSG_EDIT_WINDOW (win)); + dimmed = modest_email_clipboard_cleared (e_clipboard) && - (modest_msg_edit_window_get_clipboard_text(MODEST_MSG_EDIT_WINDOW (win)) == NULL) && - !gtk_clipboard_wait_is_text_available(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); + ((clipboard_text == NULL) || (clipboard_text[0] == '\0')); } return dimmed; @@ -1506,7 +1615,7 @@ modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer state = modest_window_get_dimming_state (win); if (!dimmed) { - GList *selected_attachments = NULL; + TnyList *selected_attachments = NULL; gint n_att_selected = 0; GtkWidget *attachments_view; attachments_view = modest_msg_edit_window_get_child_widget ( @@ -1515,10 +1624,10 @@ modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer selected_attachments = modest_attachments_view_get_selection ( MODEST_ATTACHMENTS_VIEW (attachments_view)); - n_att_selected = g_list_length (selected_attachments); - g_list_free (selected_attachments); + n_att_selected = tny_list_get_length (selected_attachments); + g_object_unref (selected_attachments); - dimmed = (n_att_selected != 1); + dimmed = (n_att_selected < 1); } return dimmed; @@ -1549,10 +1658,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) { @@ -1665,7 +1773,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); + dimmed = !state->sent_in_progress; if (dimmed) modest_dimming_rule_set_notification (rule, ""); } @@ -1674,37 +1782,27 @@ modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data } gboolean -modest_ui_dimming_rules_on_csm_cancel_sending (ModestWindow *win, gpointer user_data) +modest_ui_dimming_rules_on_send_receive (ModestWindow *win, gpointer user_data) { - ModestDimmingRule *rule = NULL; - TnyFolderType types[1]; - const DimmedState *state = NULL; + ModestDimmingRule *rule = 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, ""); - } + + /* Check dimmed rule */ if (!dimmed) { - dimmed = !_sending_in_progress (win); - if (dimmed) - modest_dimming_rule_set_notification (rule, ""); + dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), + TRUE); + if (dimmed) + modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined")); } return dimmed; } gboolean -modest_ui_dimming_rules_on_send_receive (ModestWindow *win, gpointer user_data) +modest_ui_dimming_rules_on_send_receive_all (ModestWindow *win, gpointer user_data) { ModestDimmingRule *rule = NULL; gboolean dimmed = FALSE; @@ -1714,10 +1812,13 @@ modest_ui_dimming_rules_on_send_receive (ModestWindow *win, gpointer user_data) /* Check dimmed rule */ if (!dimmed) { - dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), - TRUE); + GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr (), TRUE); + if (g_slist_length (account_names) <= 1) + dimmed = TRUE; if (dimmed) modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined")); + + modest_account_mgr_free_account_names (account_names); } return dimmed; @@ -1728,16 +1829,43 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat { ModestDimmingRule *rule = NULL; gboolean dimmed = FALSE; + GtkWidget *focused = NULL; 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)); + + dimmed = !focused; - /* Check dimmed rule */ if (!dimmed) { - GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); gchar *selection = NULL; - selection = gtk_clipboard_wait_for_text (clipboard); - + if (GTK_IS_TEXT_VIEW (focused)) { + GtkTextIter start, end; + GtkTextBuffer *buffer = NULL; + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused)); + if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) { + selection = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); + } + } else if (GTK_IS_LABEL (focused)) { + selection = modest_text_utils_label_get_selection (GTK_LABEL (focused)); + } else { + gboolean do_check = TRUE; + GtkClipboard *clipboard; + if (GTK_IS_HTML (focused)) { + const gchar *sel; + 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); + selection = gtk_clipboard_wait_for_text (clipboard); + } else { + selection = NULL; + } + } dimmed = !((selection != NULL) && (modest_text_utils_validate_recipient (selection, NULL))); } @@ -2022,7 +2150,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; @@ -2031,8 +2159,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 */ @@ -2044,7 +2176,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); @@ -2102,8 +2236,7 @@ _selected_folder_is_same_as_source (ModestWindow *win) } /* Check source folder */ - result = modest_email_clipboard_check_source_folder (clipboard, - (const TnyFolder *) folder); + result = modest_email_clipboard_check_source_folder (clipboard, TNY_FOLDER (folder)); /* Free */ frees: @@ -2154,7 +2287,8 @@ _selected_folder_is_any_of_type (ModestWindow *win, /* free */ - g_object_unref (folder); + if (folder) + g_object_unref (folder); return result; } @@ -2216,28 +2350,46 @@ _invalid_clipboard_selected (ModestWindow *win, if (GTK_IS_TEXT_VIEW (focused)) { GtkTextBuffer *buffer = NULL; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused)); - has_selection = gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer)); + has_selection = modest_text_utils_buffer_selection_is_valid (buffer); } else if (GTK_IS_EDITABLE (focused)) { has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (focused), NULL, NULL); } result = !has_selection; } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) { - GtkClipboard *clipboard = NULL; - gchar *selection = NULL; - - /* Get clipboard selection*/ - clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); - selection = gtk_clipboard_wait_for_text (clipboard); - - /* Check dimming */ - result = ((selection == NULL) || - (MODEST_IS_ATTACHMENTS_VIEW (focused))); + if (focused) { + MODEST_DEBUG_BLOCK (g_message ("FOCUSED %s", g_type_name (G_TYPE_FROM_INSTANCE (focused)));); + if (GTK_IS_LABEL (focused) && + !gtk_label_get_selection_bounds (GTK_LABEL (focused), NULL, NULL)) { + result = TRUE; + } else if (GTK_IS_TEXT_VIEW (focused)) { + GtkTextBuffer *buffer; + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused)); + result = !gtk_text_buffer_get_has_selection (buffer); + } else if (GTK_IS_HTML (focused)) { + const gchar *sel; + int len = -1; + sel = gtk_html_get_selection_html (GTK_HTML (focused), &len); + result = ((sel == NULL) || (sel[0] == '\0')); + } else if (MODEST_IS_ATTACHMENTS_VIEW (focused)) { + result = TRUE; + } else { + GtkClipboard *clipboard; + gchar *selection; + + clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); + /* Get clipboard selection*/ + selection = gtk_clipboard_wait_for_text (clipboard); + /* Check dimming */ + result = (selection == NULL); + g_free (selection); + } + } else { + result = TRUE; + } if (result) modest_dimming_rule_set_notification (rule, ""); - if (selection != NULL) - g_free(selection); } else if (MODEST_IS_MAIN_WINDOW (win)) { /* Check dimming */ @@ -2257,7 +2409,7 @@ _invalid_attach_selected (ModestWindow *win, gboolean for_remove, ModestDimmingRule *rule) { - GList *attachments, *node; + TnyList *attachments; gint n_selected; TnyHeaderFlags flags; gboolean nested_attachments = FALSE; @@ -2277,7 +2429,7 @@ _invalid_attach_selected (ModestWindow *win, /* Get selected atachments */ attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win)); - n_selected = g_list_length (attachments); + n_selected = tny_list_get_length (attachments); /* Check unique */ if (!result) { @@ -2290,10 +2442,12 @@ _invalid_attach_selected (ModestWindow *win, /* Check attached type (view operation not required) */ if (!result && !for_view) { - for (node = attachments; node != NULL && !result; node = g_list_next (node)) { - TnyMimePart *mime_part = TNY_MIME_PART (node->data); + TnyIterator *iter; + iter = tny_list_create_iterator (attachments); + 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; } @@ -2303,7 +2457,10 @@ _invalid_attach_selected (ModestWindow *win, result = TRUE; } g_object_unref (nested_list); + g_object_unref (mime_part); + tny_iterator_next (iter); } + g_object_unref (iter); } /* Set notifications */ @@ -2320,7 +2477,7 @@ _invalid_attach_selected (ModestWindow *win, } /* Free */ - g_list_free (attachments); + g_object_unref (attachments); } return result; @@ -2329,7 +2486,8 @@ _invalid_attach_selected (ModestWindow *win, static gboolean _purged_attach_selected (ModestWindow *win, gboolean all, ModestDimmingRule *rule) { - GList *attachments = NULL, *node; + TnyList *attachments = NULL; + TnyIterator *iter; gint purged = 0; gint n_attachments = 0; gboolean result = FALSE; @@ -2349,24 +2507,35 @@ _purged_attach_selected (ModestWindow *win, gboolean all, ModestDimmingRule *rul if (attachments == NULL) return FALSE; - for (node = attachments; node != NULL; node = g_list_next (node)) { - TnyMimePart *mime_part = TNY_MIME_PART (node->data); + if (tny_list_get_length (attachments)) { + g_object_unref (attachments); + return FALSE; + } + + iter = tny_list_create_iterator (attachments); + while (!tny_iterator_is_done (iter)) { + TnyMimePart *mime_part = TNY_MIME_PART (tny_iterator_get_current (iter)); if (tny_mime_part_is_purged (mime_part)) { purged++; } n_attachments++; + g_object_unref (mime_part); + tny_iterator_next (iter); } + g_object_unref (iter); /* Free */ - g_list_free (attachments); + g_object_unref (attachments); if (all) result = (purged == n_attachments); else result = (purged > 0); + /* This string no longer exists, refer to NB#75415 for more info if (result && (rule != NULL)) modest_dimming_rule_set_notification (rule, _("mail_ib_attachment_already_purged")); + */ return result; } @@ -2445,34 +2614,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) { @@ -2488,7 +2629,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)) { @@ -2496,7 +2637,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 { @@ -2513,31 +2655,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) { - GList *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 = g_list_length (attachments); - g_list_free (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)); } }