From ee263045b6b80debde38c24ee14c5c9ffd352d0b Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Tue, 11 Dec 2007 16:01:33 +0000 Subject: [PATCH] * Fixed an error in the documentation * Replaced the call to tny_folder_store_create_folder by tny_folder_store_create_folder_async * Fixes NB#78382, Modest UI is not blocked while creating a folder pmo-trunk-r3899 --- src/modest-mail-operation.c | 82 ++++++++++++++++++++----- src/modest-mail-operation.h | 24 +++++++- src/modest-ui-actions.c | 125 +++++++++++++++++++------------------- src/widgets/modest-folder-view.h | 2 +- 4 files changed, 151 insertions(+), 82 deletions(-) diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index d7b24ce..ede8f8e 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -1639,17 +1639,62 @@ compare_headers_by_date (gconstpointer a, /* ************************** STORE ACTIONS ************************* */ /* ******************************************************************* */ +typedef struct { + ModestMailOperation *mail_op; + CreateFolderUserCallback callback; + gpointer user_data; +} CreateFolderInfo; + + +static void +create_folder_cb (TnyFolderStore *parent_folder, + gboolean canceled, + TnyFolder *new_folder, + GError *err, + gpointer user_data) +{ + ModestMailOperationPrivate *priv; + CreateFolderInfo *info; + + info = (CreateFolderInfo *) user_data; + priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op); -TnyFolder * + if (canceled || err) { + priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED; + if (err) + priv->error = g_error_copy (err); + else + g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR, + MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED, + "canceled"); + } else { + priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS; + } + + /* The user will unref the new_folder */ + if (info->callback) + info->callback (info->mail_op, parent_folder, + new_folder, info->user_data); + + /* Notify about operation end */ + modest_mail_operation_notify_end (info->mail_op); + + /* Frees */ + g_object_unref (info->mail_op); + g_slice_free (CreateFolderInfo, info); +} + +void modest_mail_operation_create_folder (ModestMailOperation *self, TnyFolderStore *parent, - const gchar *name) + const gchar *name, + CreateFolderUserCallback callback, + gpointer user_data) { ModestMailOperationPrivate *priv; - TnyFolder *new_folder = NULL; - g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL); - g_return_val_if_fail (name, NULL); + g_return_if_fail (TNY_IS_FOLDER_STORE (parent)); + g_return_if_fail (name); priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self); priv->op_type = MODEST_MAIL_OPERATION_TYPE_INFO; @@ -1686,18 +1731,25 @@ modest_mail_operation_create_folder (ModestMailOperation *self, } if (!priv->error) { - /* Create the folder */ - modest_mail_operation_notify_start (self); - new_folder = tny_folder_store_create_folder (parent, name, &(priv->error)); - CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED); - if (!priv->error) - priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS; - } + CreateFolderInfo *info; - /* Notify about operation end */ - modest_mail_operation_notify_end (self); + info = g_slice_new0 (CreateFolderInfo); + info->mail_op = g_object_ref (self); + info->callback = callback; + info->user_data = user_data; + + modest_mail_operation_notify_start (self); - return new_folder; + /* Create the folder */ + tny_folder_store_create_folder_async (parent, name, create_folder_cb, + NULL, info); + } else { + /* Call the user callback anyway */ + if (callback) + callback (self, parent, NULL, user_data); + /* Notify about operation end */ + modest_mail_operation_notify_end (self); + } } void diff --git a/src/modest-mail-operation.h b/src/modest-mail-operation.h index 9052003..f6c5fca 100644 --- a/src/modest-mail-operation.h +++ b/src/modest-mail-operation.h @@ -190,6 +190,22 @@ typedef gboolean (*RetrieveAllCallback) (GObject *source, guint num_msgs, guint limit); +/** + * CreateFolderUserCallback: + * + * @mail_op: the current #ModestMailOperation. + * @folder: a #TnyFolder summary item. + * @user_data: generic data passed to user defined function. + * + * This function will be called after get_msg_cb private function, which is + * used as tinymail operation callback. The private function fills private + * fields of mail operation and calls user defined callback if it exists. + */ +typedef void (*CreateFolderUserCallback) (ModestMailOperation *mail_op, + TnyFolderStore *parent_folder, + TnyFolder *new_folder, + gpointer user_data); + /* This struct represents the internal state of a mail operation in a given time */ typedef struct { @@ -430,9 +446,11 @@ void modest_mail_operation_update_account (ModestMailOperation *self, * * Returns: a newly created #TnyFolder or NULL in case of error. **/ -TnyFolder* modest_mail_operation_create_folder (ModestMailOperation *self, - TnyFolderStore *parent, - const gchar *name); +void modest_mail_operation_create_folder (ModestMailOperation *self, + TnyFolderStore *parent, + const gchar *name, + CreateFolderUserCallback callback, + gpointer user_data); /** * modest_mail_operation_remove_folder: diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 362522b..9f54530 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -159,6 +159,9 @@ static gboolean remote_folder_is_pop (const TnyFolderStore *folder); static gboolean msgs_already_deleted_from_server ( TnyList *headers, const TnyFolderStore *src_folder); +static void do_create_folder (GtkWindow *window, + TnyFolderStore *parent_folder, + const gchar *suggested_name); /* * This function checks whether a TnyFolderStore is a pop account @@ -2588,18 +2591,68 @@ modest_ui_actions_on_remove_attachments (GtkAction *action, } static void -modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op, - gpointer user_data) +do_create_folder_cb (ModestMailOperation *mail_op, + TnyFolderStore *parent_folder, + TnyFolder *new_folder, + gpointer user_data) { - ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data); - const GError *error = modest_mail_operation_get_error (mail_op); + gchar *suggested_name = (gchar *) user_data; + GtkWindow *main_window = (GtkWindow *) modest_mail_operation_get_source (mail_op); - if(error) { - modest_platform_information_banner (GTK_WIDGET (window), NULL, + if (modest_mail_operation_get_error (mail_op)) { + /* Show an error */ + modest_platform_information_banner (GTK_WIDGET (main_window), NULL, _("mail_in_ui_folder_create_error")); + + /* Try again */ + do_create_folder (main_window, parent_folder, (const gchar *) suggested_name); + } else { + GtkWidget *folder_view; + + folder_view = + modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window), + MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); + + /* Select the newly created folder */ + modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), + new_folder, FALSE); + g_object_unref (new_folder); + } + /* Free. Note that the first time it'll be NULL so noop */ + g_free (suggested_name); + g_object_unref (main_window); +} + +static void +do_create_folder (GtkWindow *parent_window, + TnyFolderStore *parent_folder, + const gchar *suggested_name) +{ + gint result; + gchar *folder_name = NULL; + + result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window), + parent_folder, + (gchar *) suggested_name, + &folder_name); + + if (result == GTK_RESPONSE_ACCEPT) { + ModestMailOperation *mail_op; + + mail_op = modest_mail_operation_new (G_OBJECT(parent_window)); + + modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), + mail_op); + modest_mail_operation_create_folder (mail_op, + parent_folder, + (const gchar *) folder_name, + do_create_folder_cb, + folder_name); + g_object_unref (mail_op); } } + static void modest_ui_actions_create_folder(GtkWidget *parent_window, GtkWidget *folder_view) @@ -2609,64 +2662,10 @@ modest_ui_actions_create_folder(GtkWidget *parent_window, parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view)); if (parent_folder) { - gboolean finished = FALSE; - gint result; - gchar *folder_name = NULL, *suggested_name = NULL; - const gchar *proto_str = NULL; - TnyAccount *account; - - if (TNY_IS_ACCOUNT (parent_folder)) - account = g_object_ref (parent_folder); - else - account = tny_folder_get_account (TNY_FOLDER (parent_folder)); - proto_str = tny_account_get_proto (TNY_ACCOUNT (account)); - - if (proto_str && modest_protocol_info_get_transport_store_protocol (proto_str) == - MODEST_PROTOCOL_STORE_POP) { - finished = TRUE; - modest_platform_information_banner (NULL, NULL, _("mail_in_ui_folder_create_error")); - } - g_object_unref (account); - + /* Run the new folder dialog */ - while (!finished) { - result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window), - parent_folder, - suggested_name, - &folder_name); - - g_free (suggested_name); - suggested_name = NULL; - - if (result == GTK_RESPONSE_ACCEPT) { - ModestMailOperation *mail_op; - TnyFolder *new_folder = NULL; - - mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window), - modest_ui_actions_new_folder_error_handler, - parent_window, NULL); - - modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), - mail_op); - new_folder = modest_mail_operation_create_folder (mail_op, - parent_folder, - (const gchar *) folder_name); - if (new_folder) { - modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), - new_folder, TRUE); - - g_object_unref (new_folder); - finished = TRUE; - } - g_object_unref (mail_op); - } else { - finished = TRUE; - } - - suggested_name = folder_name; - folder_name = NULL; - } - + do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL); + g_object_unref (parent_folder); } } diff --git a/src/widgets/modest-folder-view.h b/src/widgets/modest-folder-view.h index c6efd8b..ed7e973 100644 --- a/src/widgets/modest-folder-view.h +++ b/src/widgets/modest-folder-view.h @@ -193,7 +193,7 @@ void modest_folder_view_cut_selection (ModestFolderView *folder_view); * modest_folder_view_select_folder * @self: a #ModestFolderView * @folder: a #TnyFolder - * @after_change: should we select directly (TRUE), or after the first change to the view (FALSE) + * @after_change: should we select first change to the view (TRUE), or just now (FALSE) * * select the given TnyFolder in the folder; * return TRUE if it succeeded, FALSE otherwise. -- 1.7.9.5