X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-ui-actions.c;h=858716e4e5dced9ae4a6673e51e4642172c1baae;hp=9f54530699465c43acafcc7dbdc4fa54189c54b4;hb=c3da84683c35ffe81b2e07b8acae82bcbd739f54;hpb=ee263045b6b80debde38c24ee14c5c9ffd352d0b diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 9f54530..858716e 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -163,6 +163,9 @@ static void do_create_folder (GtkWindow *window, TnyFolderStore *parent_folder, const gchar *suggested_name); +static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog); + + /* * This function checks whether a TnyFolderStore is a pop account */ @@ -557,9 +560,9 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) gtk_tree_path_free (prev_path); } - /* Update toolbar dimming state */ + /* Update window dimming state */ if (main_window) - modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window)); + modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window)); /* Free */ g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL); @@ -743,8 +746,7 @@ modest_ui_actions_compose_msg(ModestWindow *win, ModestAccountMgr *mgr = modest_runtime_get_account_mgr(); ModestTnyAccountStore *store = modest_runtime_get_account_store(); - if (win) account_name = g_strdup (modest_window_get_active_account (win)); - if (!account_name) account_name = modest_account_mgr_get_default_account(mgr); + account_name = modest_account_mgr_get_default_account(mgr); if (!account_name) { g_printerr ("modest: no account found\n"); goto cleanup; @@ -787,11 +789,6 @@ modest_ui_actions_compose_msg(ModestWindow *win, attachments = g_slist_next(attachments); } modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win); - - if (win) { - gtk_window_set_transient_for (GTK_WINDOW (msg_win), - GTK_WINDOW (win)); - } gtk_widget_show_all (GTK_WIDGET (msg_win)); cleanup: @@ -985,9 +982,9 @@ open_msg_cb (ModestMailOperation *mail_op, gtk_widget_show_all (GTK_WIDGET(win)); } - /* Update toolbar dimming state */ + /* Update window dimming state */ if (MODEST_IS_MAIN_WINDOW (parent_win)) { - modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win)); + modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (parent_win)); } cleanup: @@ -1060,7 +1057,6 @@ open_msgs_performer(gboolean canceled, status = tny_account_get_connection_status (account); if (err || canceled) { - /* TODO: Show an error ? */ goto clean; } @@ -1640,17 +1636,21 @@ new_messages_arrived (ModestMailOperation *self, gpointer user_data) { GObject *source; + gboolean show_visual_notifications; source = modest_mail_operation_get_source (self); - - /* Notify new messages have been downloaded. Do not notify if - the send&receive was invoked by the user, i.e, if the mail - operation has a source (the main window) */ - if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0) && !source) - modest_platform_on_new_headers_received (new_headers); - + show_visual_notifications = (source) ? FALSE : TRUE; if (source) g_object_unref (source); + + /* Notify new messages have been downloaded. If the + send&receive was invoked by the user then do not show any + visual notification, only play a sound and activate the LED + (for the Maemo version) */ + if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0)) + modest_platform_on_new_headers_received (new_headers, + show_visual_notifications); + } gboolean @@ -1695,7 +1695,6 @@ do_send_receive_performer (gboolean canceled, info = (SendReceiveInfo *) user_data; if (err || canceled) { - goto clean; } @@ -1967,8 +1966,8 @@ modest_ui_actions_on_header_selected (ModestHeaderView *header_view, if (!gtk_widget_is_focus (GTK_WIDGET(header_view))) gtk_widget_grab_focus (GTK_WIDGET(header_view)); - /* Update toolbar dimming state */ - modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window)); + /* Update window dimming state */ + modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window)); } void @@ -1979,7 +1978,7 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view, TnyList *headers; g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window)); - + if (!header) return; @@ -2036,8 +2035,6 @@ folder_refreshed_cb (ModestMailOperation *mail_op, { ModestMainWindow *win = NULL; GtkWidget *header_view; - gboolean folder_empty = FALSE; - gboolean all_marked_as_deleted = FALSE; g_return_if_fail (TNY_IS_FOLDER (folder)); @@ -2057,9 +2054,7 @@ folder_refreshed_cb (ModestMailOperation *mail_op, } /* Check if folder is empty and set headers view contents style */ - folder_empty = (tny_folder_get_all_count (folder) == 0); - all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW(header_view)); - if (folder_empty || all_marked_as_deleted) + if (tny_folder_get_all_count (folder) == 0) modest_main_window_set_contents_style (win, MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY); } @@ -2135,8 +2130,8 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view, } } - /* Update toolbar dimming state */ - modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window)); + /* Update window dimming state */ + modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window)); } void @@ -2244,9 +2239,14 @@ on_save_to_drafts_cb (ModestMailOperation *mail_op, edit_window = MODEST_MSG_EDIT_WINDOW (user_data); - /* If there was any error do nothing */ - if (modest_mail_operation_get_error (mail_op) != NULL) + /* It might not be a good idea to do nothing if there was an error, + * so let's at least show a generic error banner. */ + /* TODO error while saving attachment, show "Saving draft failed" banner */ + if (modest_mail_operation_get_error (mail_op) != NULL) { + g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_op))->message); + modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed")); return; + } modest_msg_edit_window_set_draft (edit_window, saved_draft); } @@ -2597,22 +2597,28 @@ do_create_folder_cb (ModestMailOperation *mail_op, gpointer user_data) { gchar *suggested_name = (gchar *) user_data; - GtkWindow *main_window = (GtkWindow *) modest_mail_operation_get_source (mail_op); - + GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op); + if (modest_mail_operation_get_error (mail_op)) { /* Show an error */ - modest_platform_information_banner (GTK_WIDGET (main_window), NULL, + modest_platform_information_banner (GTK_WIDGET (source_win), NULL, _("mail_in_ui_folder_create_error")); /* Try again */ - do_create_folder (main_window, parent_folder, (const gchar *) suggested_name); + do_create_folder (source_win, parent_folder, (const gchar *) suggested_name); } else { + /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog + * FIXME: any other? */ GtkWidget *folder_view; - folder_view = - modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window), - MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); - + if (MODEST_IS_MAIN_WINDOW(source_win)) + folder_view = + modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win), + MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); + else + folder_view = + get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win)); + /* Select the newly created folder */ modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE); @@ -2620,7 +2626,7 @@ do_create_folder_cb (ModestMailOperation *mail_op, } /* Free. Note that the first time it'll be NULL so noop */ g_free (suggested_name); - g_object_unref (main_window); + g_object_unref (source_win); } static void @@ -2652,6 +2658,25 @@ do_create_folder (GtkWindow *parent_window, } } +static void +create_folder_performer (gboolean canceled, + GError *err, + GtkWindow *parent_window, + TnyAccount *account, + gpointer user_data) +{ + TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data); + + if (canceled || err) { + goto frees; + } + + /* Run the new folder dialog */ + do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL); + + frees: + g_object_unref (parent_folder); +} static void modest_ui_actions_create_folder(GtkWidget *parent_window, @@ -2662,11 +2687,11 @@ modest_ui_actions_create_folder(GtkWidget *parent_window, parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view)); if (parent_folder) { - - /* Run the new folder dialog */ - do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL); - - g_object_unref (parent_folder); + /* The parent folder will be freed in the callback */ + modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window), + parent_folder, + create_folder_performer, + parent_folder); } } @@ -3490,7 +3515,7 @@ modest_ui_actions_on_select_all (GtkAction *action, /* Enable window dimming management */ modest_window_enable_dimming (MODEST_WINDOW(window)); - modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window)); + modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (window)); } } @@ -3772,11 +3797,19 @@ modest_ui_actions_msg_edit_on_select_font (GtkAction *action, modest_msg_edit_window_select_font (window); } + void modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view, const gchar *display_name, GtkWindow *window) { + /* don't update the display name if it was already set; + * updating the display name apparently is expensive */ + const gchar* old_name = gtk_window_get_title (window); + + if (old_name && display_name && strcmp (old_name, display_name) == 0) + return; /* don't do anything */ + /* This is usually used to change the title of the main window, which * is the one that holds the folder view. Note that this change can * happen even when the widget doesn't have the focus. */ @@ -3784,6 +3817,7 @@ modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view, gtk_window_set_title (window, display_name); else gtk_window_set_title (window, " "); + } void @@ -3937,6 +3971,16 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self, gtk_widget_set_sensitive (new_button, new_sensitive); } + +#define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view" + +static GtkWidget* +get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog) +{ + return GTK_WIDGET(g_object_get_data (G_OBJECT(move_to_dialog), + MODEST_MOVE_TO_DIALOG_FOLDER_VIEW)); +} + static GtkWidget* create_move_to_dialog (GtkWindow *win, GtkWidget *folder_view, @@ -4025,9 +4069,16 @@ create_move_to_dialog (GtkWindow *win, } } + /* we keep a pointer to the embedded folder view, so we can retrieve it with + * get_folder_view_from_move_to_dialog + * (see above) later (needed for focus handling) + */ + g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, *tree_view); + + /* Hide special folders */ modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE); - + gtk_container_add (GTK_CONTAINER (scroll), *tree_view); /* Add scroll to dialog */ @@ -4837,7 +4888,6 @@ retrieve_msg_contents_performer (gboolean canceled, TnyList *headers = TNY_LIST (user_data); if (err || canceled) { - /* Show an error ? */ goto out; } @@ -4891,102 +4941,12 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action, } void -modest_ui_actions_on_email_menu_activated (GtkAction *action, - ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_on_edit_menu_activated (GtkAction *action, - ModestWindow *window) +modest_ui_actions_check_window_dimming_rules (ModestWindow *window) { g_return_if_fail (MODEST_IS_WINDOW (window)); /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_on_view_menu_activated (GtkAction *action, - ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_on_format_menu_activated (GtkAction *action, - ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_on_tools_menu_activated (GtkAction *action, - ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_on_attachment_menu_activated (GtkAction *action, - ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action, - ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action, - ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action, - ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); -} - -void -modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window) -{ - g_return_if_fail (MODEST_IS_WINDOW (window)); - - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules"); + modest_window_check_dimming_rules_group (window, "ModestWindowDimmingRules"); } void @@ -5110,7 +5070,10 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self, message = g_strdup (_("emev_ib_ui_smtp_send_error")); break; default: - g_return_if_reached (); + g_warning ("%s: unexpected TNY_TRANSPORT_ACCOUNT_ERROR %d", + __FUNCTION__, err->code); + message = g_strdup (_("emev_ib_ui_smtp_send_error")); + break; } /* TODO if the username or the password where not defined we