From a4e8821c4dd117ede537ab7d5a5fb9992dd62df5 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Wed, 5 Dec 2007 11:07:47 +0000 Subject: [PATCH] * Fixes NB#77589, modest asks the user if they want to retrieve more mails than the retrieve limit * Fixes a very stupid bug by myself that was preventing opening messages in offline mode pmo-trunk-r3873 --- src/gnome/modest-platform.c | 25 ++++++++++++++++++++++++- src/maemo/modest-platform.c | 26 ++++++++++++++++++++++++++ src/modest-mail-operation.c | 25 +++++++++++++++++++------ src/modest-mail-operation.h | 6 +++++- src/modest-platform.h | 18 ++++++++++++++++++ src/modest-ui-actions.c | 30 ++++++++++++++++++++++++++---- 6 files changed, 118 insertions(+), 12 deletions(-) diff --git a/src/gnome/modest-platform.c b/src/gnome/modest-platform.c index 8cac0d5..368e076 100644 --- a/src/gnome/modest-platform.c +++ b/src/gnome/modest-platform.c @@ -193,7 +193,30 @@ modest_platform_run_confirmation_dialog (GtkWindow *parent_window, response = gtk_dialog_run (GTK_DIALOG(dialog)); gtk_widget_destroy (dialog); - /* TODO implement confirmation dialog */ + return response; +} + +gint +modest_platform_run_confirmation_dialog_with_buttons (GtkWindow *parent_window, + const gchar *message, + const gchar *button_accept, + const gchar *button_cancel) +{ + gint response; + GtkWidget *dialog; + + dialog = gtk_dialog_new_with_buttons (message, + parent_window, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + button_accept, + GTK_RESPONSE_ACCEPT, + button_cancel, + GTK_RESPONSE_CANCEL, + NULL); + + response = gtk_dialog_run (GTK_DIALOG(dialog)); + gtk_widget_destroy (dialog); + return response; } diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 4a9c238..9127de6 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -984,6 +984,32 @@ modest_platform_run_confirmation_dialog (GtkWindow *parent_window, return response; } + +gint +modest_platform_run_confirmation_dialog_with_buttons (GtkWindow *parent_window, + const gchar *message, + const gchar *button_accept, + const gchar *button_cancel) +{ + GtkWidget *dialog; + gint response; + + dialog = hildon_note_new_confirmation_add_buttons (parent_window, message, + button_accept, GTK_RESPONSE_ACCEPT, + button_cancel, GTK_RESPONSE_CANCEL, + NULL); + modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), + GTK_WINDOW (dialog)); + + response = gtk_dialog_run (GTK_DIALOG (dialog)); + + on_destroy_dialog (GTK_DIALOG(dialog)); + + while (gtk_events_pending ()) + gtk_main_iteration (); + + return response; +} gint modest_platform_run_yes_no_dialog (GtkWindow *parent_window, diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 0996030..d7b24ce 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -1231,6 +1231,7 @@ typedef struct gboolean poke_all; TnyFolderObserver *inbox_observer; guint update_timeout; + RetrieveAllCallback retrieve_all_cb; } UpdateAccountInfo; @@ -1279,7 +1280,7 @@ inbox_refreshed_cb (TnyFolder *inbox, ModestAccountMgr *mgr; ModestAccountRetrieveType retrieve_type; TnyList *new_headers = NULL; - gboolean headers_only; + gboolean headers_only, ignore_limit; TnyTransportAccount *transport_account; ModestTnySendQueue *send_queue; @@ -1338,11 +1339,18 @@ inbox_refreshed_cb (TnyFolder *inbox, /* Order by date */ g_ptr_array_sort (new_headers_array, (GCompareFunc) compare_headers_by_date); - /* TODO: Ask the user, instead of just failing, - * showing mail_nc_msg_count_limit_exceeded, with 'Get - * all' and 'Newest only' buttons. */ + /* Ask the users if they want to retrieve all the messages + even though the limit was exceeded */ + ignore_limit = FALSE; if (new_headers_array->len > retrieve_limit) { - /* TODO */ + /* Ask the user if a callback has been specified and + if the mail operation has a source (this means that + was invoked by the user and not automatically by a + D-Bus method) */ + if (info->retrieve_all_cb && priv->source) + ignore_limit = info->retrieve_all_cb (priv->source, + new_headers_array->len, + retrieve_limit); } if (!headers_only) { @@ -1350,7 +1358,10 @@ inbox_refreshed_cb (TnyFolder *inbox, const gint msg_list_size = compute_message_array_size (new_headers_array); priv->done = 0; - priv->total = MIN (new_headers_array->len, retrieve_limit); + if (ignore_limit) + priv->total = new_headers_array->len; + else + priv->total = MIN (new_headers_array->len, retrieve_limit); while (msg_num < priv->total) { TnyHeader *header = TNY_HEADER (g_ptr_array_index (new_headers_array, msg_num)); TnyFolder *folder = tny_header_get_folder (header); @@ -1537,6 +1548,7 @@ void modest_mail_operation_update_account (ModestMailOperation *self, const gchar *account_name, gboolean poke_all, + RetrieveAllCallback retrieve_all_cb, UpdateAccountCallback callback, gpointer user_data) { @@ -1571,6 +1583,7 @@ modest_mail_operation_update_account (ModestMailOperation *self, info->callback = callback; info->user_data = user_data; info->update_timeout = g_timeout_add (250, timeout_notify_progress, self); + info->retrieve_all_cb = retrieve_all_cb; /* Set account busy */ modest_account_mgr_set_account_busy (modest_runtime_get_account_mgr (), account_name, TRUE); diff --git a/src/modest-mail-operation.h b/src/modest-mail-operation.h index c46a31f..9052003 100644 --- a/src/modest-mail-operation.h +++ b/src/modest-mail-operation.h @@ -171,7 +171,6 @@ typedef void (*UpdateAccountCallback) (ModestMailOperation *self, TnyList *new_headers, gpointer user_data); - /** * SaveToDraftsCallback: * @@ -187,6 +186,10 @@ typedef void (*SaveToDraftstCallback) (ModestMailOperation *self, gpointer user_data); +typedef gboolean (*RetrieveAllCallback) (GObject *source, + guint num_msgs, + guint limit); + /* This struct represents the internal state of a mail operation in a given time */ typedef struct { @@ -407,6 +410,7 @@ void modest_mail_operation_save_to_drafts (ModestMailOperation *self, void modest_mail_operation_update_account (ModestMailOperation *self, const gchar *account_name, gboolean poke_all, + RetrieveAllCallback retrieve_all_cb, UpdateAccountCallback callback, gpointer user_data); diff --git a/src/modest-platform.h b/src/modest-platform.h index fca70aa..00f4010 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -189,6 +189,24 @@ gint modest_platform_run_rename_folder_dialog (GtkWindow *parent_win gint modest_platform_run_confirmation_dialog (GtkWindow *parent_window, const gchar *message); + +/** + * modest_platform_run_confirmation_dialog_with_buttons: + * @parent_window: the parent #GtkWindow of the dialog + * @message: the message to show to the user + * @button_accept: the text to show in the label of the accept button + * @button_cancel: the text to show in the label of the cancel button + * + * runs a confirmation dialog with the given values for the buttons + * + * Returns: GTK_RESPONSE_OK or GTK_RESPONSE_CANCEL + **/ +gint +modest_platform_run_confirmation_dialog_with_buttons (GtkWindow *parent_window, + const gchar *message, + const gchar *button_accept, + const gchar *button_cancel); + /** * modest_platform_run_yes_no_dialog: * @parent_window: the parent #GtkWindow of the dialog diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 34a0d7b..908b0e4 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -1055,9 +1055,7 @@ open_msgs_performer(gboolean canceled, not_opened_headers = TNY_LIST (user_data); status = tny_account_get_connection_status (account); - if (err || canceled || - (modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (account)) && - status != TNY_CONNECTION_STATUS_CONNECTED)) { + if (err || canceled) { /* TODO: Show an error ? */ goto clean; } @@ -1651,6 +1649,29 @@ new_messages_arrived (ModestMailOperation *self, g_object_unref (source); } +gboolean +retrieve_all_messages_cb (GObject *source, + guint num_msgs, + guint retrieve_limit) +{ + GtkWindow *window; + gchar *msg; + gint response; + + window = GTK_WINDOW (source); + msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"), + num_msgs, retrieve_limit); + + /* Ask the user if they want to retrieve all the messages */ + response = + modest_platform_run_confirmation_dialog_with_buttons (window, msg, + _("mcen_bd_get_all"), + _("mcen_bd_newest_only")); + /* Free and return */ + g_free (msg); + return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE; +} + typedef struct { TnyAccount *account; ModestWindow *win; @@ -1679,7 +1700,7 @@ do_send_receive_performer (gboolean canceled, modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win)); } - mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (info->win), + mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL, modest_ui_actions_send_receive_error_handler, NULL, NULL); @@ -1691,6 +1712,7 @@ do_send_receive_performer (gboolean canceled, /* Send & receive. */ modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); modest_mail_operation_update_account (mail_op, info->account_name, (info->win) ? FALSE : TRUE, + (info->win) ? retrieve_all_messages_cb : NULL, new_messages_arrived, info->win); g_object_unref (G_OBJECT (mail_op)); -- 1.7.9.5