X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-ui-actions.c;h=432e45b27b1c6397635cde14b9183b7c1a3ea89e;hp=3cc1f10f43a9597e1f059bb2222e2c1a805cc784;hb=a3966167004d901791014719da71326403dbdf3e;hpb=3b214150a992267f0722e89c94759f8e3c637c0a diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 3cc1f10..432e45b 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 */ @@ -786,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: @@ -815,6 +813,26 @@ modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win) modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL); } +void +modest_ui_actions_on_new_msg_or_folder (GtkAction *action, ModestWindow *win) +{ + g_return_if_fail (MODEST_IS_WINDOW (win)); + + /* Check first if the header view has the focus */ + if (MODEST_IS_MAIN_WINDOW (win)) { + GtkWidget *w; + w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win), + MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); + if (gtk_widget_is_focus (w)) { + modest_ui_actions_on_new_folder (action, MODEST_MAIN_WINDOW(win)); + return; + } + } + + modest_ui_actions_on_new_msg (action, win); +} + + gboolean modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op, TnyHeader *header, @@ -1222,7 +1240,7 @@ open_msgs_from_headers (TnyList *headers, ModestWindow *win) /* Connect to the account and perform */ if (uncached_msgs > 0) { - modest_platform_connect_and_perform ((GtkWindow *) win, g_object_ref (account), + modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account), open_msgs_performer, g_object_ref (not_opened_headers)); } else { /* Call directly the performer, do not need to connect */ @@ -1771,7 +1789,8 @@ modest_ui_actions_do_send_receive (const gchar *account_name, TNY_ACCOUNT_TYPE_STORE); /* Invoke the connect and perform */ - modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, info->account, + modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, + (win) ? TRUE : FALSE, info->account, do_send_receive_performer, info); } @@ -2037,8 +2056,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)); @@ -2053,14 +2070,12 @@ folder_refreshed_cb (ModestMailOperation *mail_op, if (current_folder != NULL && folder != current_folder) { g_object_unref (current_folder); return; - } - g_object_unref (current_folder); + } else if (current_folder) + g_object_unref (current_folder); } /* 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); } @@ -2301,7 +2316,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi from = modest_account_mgr_get_from_string (account_mgr, account_name); /* Create the mail operation */ - mail_operation = modest_mail_operation_new (G_OBJECT(edit_window)); + mail_operation = modest_mail_operation_new (NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation); modest_mail_operation_save_to_drafts (mail_operation, @@ -2389,7 +2404,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window) ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr(); gchar *account_name = g_strdup (data->account_name); if (!account_name) - g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window))); + account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window))); if (!account_name) account_name = modest_account_mgr_get_default_account (account_mgr); @@ -2397,8 +2412,9 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window) if (!account_name) { modest_msg_edit_window_free_msg_data (edit_window, data); /* Run account setup wizard */ - if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) + if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) { return; + } } /* Get the currently-active transport account for this modest account: */ @@ -2409,6 +2425,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window) } if (!transport_account) { + modest_msg_edit_window_free_msg_data (edit_window, data); /* Run account setup wizard */ if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window))) return; @@ -2417,7 +2434,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window) gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name); /* Create the mail operation */ - ModestMailOperation *mail_operation = modest_mail_operation_new (G_OBJECT(edit_window)); + ModestMailOperation *mail_operation = modest_mail_operation_new (NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation); modest_mail_operation_send_new_mail (mail_operation, @@ -2603,22 +2620,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); @@ -2626,7 +2649,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 @@ -2689,6 +2712,7 @@ modest_ui_actions_create_folder(GtkWidget *parent_window, if (parent_folder) { /* The parent folder will be freed in the callback */ modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window), + TRUE, parent_folder, create_folder_performer, parent_folder); @@ -2742,8 +2766,21 @@ typedef struct { } RenameFolderInfo; static void -on_rename_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window, - TnyAccount *account, gpointer user_data) +on_rename_folder_cb (ModestMailOperation *mail_op, + TnyFolder *new_folder, + gpointer user_data) +{ + /* Select now */ + modest_folder_view_select_folder (MODEST_FOLDER_VIEW (user_data), + new_folder, FALSE); +} + +static void +on_rename_folder_performer (gboolean canceled, + GError *err, + GtkWindow *parent_window, + TnyAccount *account, + gpointer user_data) { ModestMailOperation *mail_op = NULL; GtkTreeSelection *sel = NULL; @@ -2768,20 +2805,12 @@ on_rename_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window, sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view)); gtk_tree_selection_unselect_all (sel); - /* Select *after* the changes */ - modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), - TNY_FOLDER(data->folder), TRUE); - /* Actually rename the folder */ modest_mail_operation_rename_folder (mail_op, - TNY_FOLDER (data->folder), - (const gchar *) (data->new_name)); - - /* TODO folder view filter refilter */ - /* - GtkTreeModel *tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)); - if (GTK_IS_TREE_MODEL_FILTER (tree_model)) - gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (tree_model)); */ + TNY_FOLDER (data->folder), + (const gchar *) (data->new_name), + on_rename_folder_cb, + folder_view); } g_object_unref (mail_op); @@ -2835,8 +2864,8 @@ modest_ui_actions_on_rename_folder (GtkAction *action, RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1); rename_folder_data->folder = folder; rename_folder_data->new_name = folder_name; - modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), - folder, on_rename_folder_cb, rename_folder_data); + modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE, + folder, on_rename_folder_performer, rename_folder_data); } } g_object_unref (folder); @@ -2938,9 +2967,11 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash) info->folder = folder; info->move_to_trash = move_to_trash; g_object_ref (G_OBJECT (info->folder)); - TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder)); - modest_platform_connect_and_perform (GTK_WINDOW (main_window), - account, on_delete_folder_cb, info); + TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder)); + modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window), + TRUE, + TNY_FOLDER_STORE (account), + on_delete_folder_cb, info); g_object_unref (account); } g_object_unref (G_OBJECT (folder)); @@ -3310,7 +3341,17 @@ modest_ui_actions_on_redo (GtkAction *action, static void -destroy_information_note (ModestMailOperation *mail_op, gpointer user_data) +destroy_information_note (ModestMailOperation *mail_op, + gpointer user_data) +{ + /* destroy information note */ + gtk_widget_destroy (GTK_WIDGET(user_data)); +} + +static void +destroy_folder_information_note (ModestMailOperation *mail_op, + TnyFolder *new_folder, + gpointer user_data) { /* destroy information note */ gtk_widget_destroy (GTK_WIDGET(user_data)); @@ -3455,7 +3496,7 @@ modest_ui_actions_on_paste (GtkAction *action, src_folder, folder_store, delete, - destroy_information_note, + destroy_folder_information_note, inf_note); } @@ -3807,16 +3848,16 @@ modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view, * updating the display name apparently is expensive */ const gchar* old_name = gtk_window_get_title (window); + if (display_name == NULL) + display_name = " "; + 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. */ - if (display_name) - gtk_window_set_title (window, display_name); - else - gtk_window_set_title (window, " "); + gtk_window_set_title (window, display_name); } @@ -3971,6 +4012,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, @@ -4059,9 +4110,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 */ @@ -4171,10 +4229,9 @@ modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win, return response; } - - static void -move_to_cb (ModestMailOperation *mail_op, gpointer user_data) +move_to_cb (ModestMailOperation *mail_op, + gpointer user_data) { MoveToHelper *helper = (MoveToHelper *) user_data; @@ -4213,6 +4270,21 @@ move_to_cb (ModestMailOperation *mail_op, gpointer user_data) g_free (helper); } +static void +folder_move_to_cb (ModestMailOperation *mail_op, + TnyFolder *new_folder, + gpointer user_data) +{ + move_to_cb (mail_op, user_data); +} + +static void +msgs_move_to_cb (ModestMailOperation *mail_op, + gpointer user_data) +{ + move_to_cb (mail_op, user_data); +} + void modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op, gpointer user_data) @@ -4491,7 +4563,7 @@ xfer_messages_from_move_to_cb (gboolean canceled, GError *err, headers, TNY_FOLDER (dst_folder), TRUE, - move_to_cb, + msgs_move_to_cb, helper); g_object_unref (G_OBJECT (mail_op)); @@ -4557,11 +4629,13 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window, TNY_FOLDER (info->src_folder), info->dst_folder, info->delete_original, - move_to_cb, + folder_move_to_cb, helper); - - modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view), - TNY_FOLDER (info->dst_folder), TRUE); + + if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { + modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view), + TNY_FOLDER (info->dst_folder), TRUE); + } /* Unref mail operation */ g_object_unref (G_OBJECT (mail_op)); @@ -4619,7 +4693,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action, info->folder_view = folder_view; g_object_ref (G_OBJECT (info->src_folder)); g_object_ref (G_OBJECT (info->dst_folder)); - modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), + modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE, TNY_FOLDER_STORE (dst_folder), on_move_folder_cb, info); } } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) { @@ -4638,7 +4712,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action, } if (do_xfer) /* Transfer messages */ { g_object_ref (dst_folder); - modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), + modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE, TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder); } } @@ -4682,7 +4756,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action, if (do_xfer) { g_object_ref (dst_folder); - modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), + modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE, TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder); } g_object_unref (account); @@ -4913,7 +4987,7 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action, g_object_unref (iter); /* Connect and perform the message retrieval */ - modest_platform_connect_and_perform ((GtkWindow *) window, + modest_platform_connect_and_perform ((GtkWindow *) window, TRUE, g_object_ref (account), retrieve_msg_contents_performer, g_object_ref (headers)); @@ -4924,13 +4998,31 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action, } 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, MODEST_DIMMING_RULES_TOOLBAR); +} + +void +modest_ui_actions_check_menu_dimming_rules (ModestWindow *window) +{ + g_return_if_fail (MODEST_IS_WINDOW (window)); + + /* Update dimmed */ + modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU); +} + +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"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -4939,8 +5031,8 @@ modest_ui_actions_on_edit_menu_activated (GtkAction *action, { g_return_if_fail (MODEST_IS_WINDOW (window)); - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -4949,8 +5041,8 @@ modest_ui_actions_on_view_menu_activated (GtkAction *action, { g_return_if_fail (MODEST_IS_WINDOW (window)); - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -4959,8 +5051,8 @@ modest_ui_actions_on_format_menu_activated (GtkAction *action, { g_return_if_fail (MODEST_IS_WINDOW (window)); - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -4969,8 +5061,8 @@ modest_ui_actions_on_tools_menu_activated (GtkAction *action, { g_return_if_fail (MODEST_IS_WINDOW (window)); - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -4979,8 +5071,8 @@ modest_ui_actions_on_attachment_menu_activated (GtkAction *action, { g_return_if_fail (MODEST_IS_WINDOW (window)); - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -4989,8 +5081,8 @@ modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action, { g_return_if_fail (MODEST_IS_WINDOW (window)); - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -4999,8 +5091,8 @@ modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action, { g_return_if_fail (MODEST_IS_WINDOW (window)); - /* Update dimmed */ - modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -5009,17 +5101,8 @@ modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action, { 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"); + /* Update dimmed */ + modest_ui_actions_check_menu_dimming_rules (window); } void @@ -5143,7 +5226,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