From 0fe9e223f49814fd1d68f054c496fab5ad7ec183 Mon Sep 17 00:00:00 2001 From: Javier Fernandez Garcia-Boente Date: Thu, 3 May 2007 12:14:29 +0000 Subject: [PATCH] * public method in modest_progress_object to get the number of pending operations to be observed. * Fix bug in replay/forward when mulitple headers are selected. * Reply/Forward functions are observed now by MainWindow progress objects, to get all messages to reply/forward. * Replay/Forward status_callback implemented. pmo-trunk-r1744 --- src/maemo/modest-main-window.c | 29 ++++++++++++++++++-- src/maemo/modest-progress-bar-widget.c | 16 ++++++++++++ src/modest-mail-operation.c | 45 +++++++++++++++++++++++++++++++- src/modest-mail-operation.h | 5 +++- src/modest-progress-object.c | 7 +++++ src/modest-progress-object.h | 3 +++ src/modest-ui-actions.c | 36 ++++++++++++++----------- 7 files changed, 122 insertions(+), 19 deletions(-) diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index d0e1628..5c4f490 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -1125,6 +1125,29 @@ cancel_progressbar (GtkToolButton *toolbutton, } } +static gboolean +observers_empty (ModestMainWindow *self) +{ + GSList *tmp = NULL; + ModestMainWindowPrivate *priv; + gboolean is_empty = FALSE; + guint pending_ops = 0; + + priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); + tmp = priv->progress_widgets; + if (tmp == NULL) return TRUE; + + /* Check all observers */ + while (tmp && !is_empty) { + pending_ops = modest_progress_object_num_pending_operations (MODEST_PROGRESS_OBJECT(tmp->data)); + is_empty = pending_ops == 0; + + tmp = g_slist_next(tmp); + } + + return is_empty; +} + static void on_queue_changed (ModestMailOperationQueue *queue, ModestMailOperation *mail_op, @@ -1170,14 +1193,16 @@ on_queue_changed (ModestMailOperationQueue *queue, } break; case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED: - if (modest_mail_operation_queue_num_elements (queue) == 0) - set_toolbar_mode (MODEST_MAIN_WINDOW(self), TOOLBAR_MODE_NORMAL); if (mode == TOOLBAR_MODE_TRANSFER) { while (tmp) { modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data), mail_op); tmp = g_slist_next (tmp); } + + /* If no more operations are being observed, NORMAL mode is enabled again */ + if (observers_empty (MODEST_MAIN_WINDOW(self))) + set_toolbar_mode (MODEST_MAIN_WINDOW(self), TOOLBAR_MODE_NORMAL); } break; } diff --git a/src/maemo/modest-progress-bar-widget.c b/src/maemo/modest-progress-bar-widget.c index 29a55b8..202ba66 100644 --- a/src/maemo/modest-progress-bar-widget.c +++ b/src/maemo/modest-progress-bar-widget.c @@ -47,6 +47,9 @@ static void modest_progress_bar_remove_operation (ModestProgressObject *self, static void modest_progress_bar_cancel_current_operation (ModestProgressObject *self); +static guint +modest_progress_bar_num_pending_operations (ModestProgressObject *self); + static void on_progress_changed (ModestMailOperation *mail_op, ModestProgressBarWidget *self); @@ -96,6 +99,7 @@ modest_progress_object_init (gpointer g, gpointer iface_data) klass->add_operation_func = modest_progress_bar_add_operation; klass->remove_operation_func = modest_progress_bar_remove_operation; klass->cancel_current_operation_func = modest_progress_bar_cancel_current_operation; + klass->num_pending_operations_func = modest_progress_bar_num_pending_operations; } @@ -289,6 +293,18 @@ modest_progress_bar_remove_operation (ModestProgressObject *self, g_free(tmp_data); } +static guint +modest_progress_bar_num_pending_operations (ModestProgressObject *self) +{ + ModestProgressBarWidget *me; + ModestProgressBarWidgetPrivate *priv; + + me = MODEST_PROGRESS_BAR_WIDGET (self); + priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (me); + + return g_slist_length(priv->observables); +} + static void modest_progress_bar_cancel_current_operation (ModestProgressObject *self) { diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index e58c7bf..5454f4e 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -64,6 +64,9 @@ static void update_folders_status_cb (GObject *obj, TnyStatus *status, gpointer user_data); +static void update_process_msg_status_cb (GObject *obj, + TnyStatus *status, + gpointer user_data); enum _ModestMailOperationSignals { @@ -382,6 +385,22 @@ update_folders_status_cb (GObject *obj, TnyStatus *status, gpointer user_data) { + ModestMailOperation *self; + ModestMailOperationPrivate *priv; + + g_return_if_fail (status != NULL); + g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_REFRESH); + + self = MODEST_MAIL_OPERATION (user_data); + priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self); + + priv->done = status->position; + priv->total = status->of_total; + + if (priv->done == 1 && priv->total == 100) + return; + + g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL); } static void @@ -751,6 +770,7 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self, void modest_mail_operation_process_msg (ModestMailOperation *self, TnyHeader *header, + guint num_ops, TnyGetMsgCallback user_callback, gpointer user_data) { @@ -764,11 +784,12 @@ void modest_mail_operation_process_msg (ModestMailOperation *self, folder = tny_header_get_folder (header); priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS; + priv->total = num_ops; /* Get message from folder */ if (folder) { /* The callback will call it per each header */ - tny_folder_get_msg_async (folder, header, user_callback, NULL, user_data); + tny_folder_get_msg_async (folder, header, user_callback, update_process_msg_status_cb, user_data); g_object_unref (G_OBJECT (folder)); } else { /* Set status failed and set an error */ @@ -779,6 +800,28 @@ void modest_mail_operation_process_msg (ModestMailOperation *self, } } +static void +update_process_msg_status_cb (GObject *obj, + TnyStatus *status, + gpointer user_data) +{ + ModestMailOperation *self; + ModestMailOperationPrivate *priv; + + g_return_if_fail (status != NULL); + g_return_if_fail (status->code == TNY_FOLDER_STATUS_CODE_REFRESH); + + self = MODEST_MAIL_OPERATION (user_data); + priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self); + + priv->done += status->position; + + if (priv->done == 1 && priv->total == 100) + return; + + g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL); +} + void diff --git a/src/modest-mail-operation.h b/src/modest-mail-operation.h index af53120..d2f1760 100644 --- a/src/modest-mail-operation.h +++ b/src/modest-mail-operation.h @@ -338,7 +338,9 @@ void modest_mail_operation_remove_msg (ModestMailOperation *self, * modest_mail_operation_process_msg: * @self: a #ModestMailOperation * @header: the #TnyHeader of the message to get - * permanently + * @num_ops: number of times to repeat operation with next header. + * @user_callback: a #TnyGetMsgCallback function to call after tinymail operation execution. + * @user_data: user data passed to both, user_callback and update_status_callback. * * Gets a message and process it using @callback function * pased as argument. This operation is assynchronous, so the @@ -347,6 +349,7 @@ void modest_mail_operation_remove_msg (ModestMailOperation *self, **/ void modest_mail_operation_process_msg (ModestMailOperation *self, TnyHeader *header, + guint num_ops, TnyGetMsgCallback user_callback, gpointer user_data); diff --git a/src/modest-progress-object.c b/src/modest-progress-object.c index d63659d..44cd6d1 100644 --- a/src/modest-progress-object.c +++ b/src/modest-progress-object.c @@ -51,6 +51,13 @@ modest_progress_object_cancel_current_operation (ModestProgressObject *self) return MODEST_PROGRESS_OBJECT_GET_IFACE (self)->cancel_current_operation_func (self); } +guint +modest_progress_object_num_pending_operations (ModestProgressObject *self) +{ + return MODEST_PROGRESS_OBJECT_GET_IFACE (self)->num_pending_operations_func (self); +} + + static void modest_progress_object_base_init (gpointer g_class) { diff --git a/src/modest-progress-object.h b/src/modest-progress-object.h index d96ed18..b8a59c2 100644 --- a/src/modest-progress-object.h +++ b/src/modest-progress-object.h @@ -51,6 +51,7 @@ struct _ModestProgressObjectIface { void (*add_operation_func) (ModestProgressObject *self, ModestMailOperation *mail_op); void (*remove_operation_func) (ModestProgressObject *self, ModestMailOperation *mail_op); void (*cancel_current_operation_func) (ModestProgressObject *self); + guint (*num_pending_operations_func) (ModestProgressObject *self); }; GType modest_progress_object_get_type (void) G_GNUC_CONST; @@ -62,6 +63,8 @@ void modest_progress_object_remove_operation (ModestProgressObject *self ModestMailOperation *mail_op); void modest_progress_object_cancel_current_operation (ModestProgressObject *self); +guint modest_progress_object_num_pending_operations (ModestProgressObject *self); + G_END_DECLS #endif /* __MODEST_PROGRESS_OBJECT_H__ */ diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index c0df163..3946ef1 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -67,6 +67,7 @@ typedef struct _GetMsgAsyncHelper { ModestWindow *window; ModestMailOperation *mail_op; TnyIterator *iter; + guint num_ops; GFunc func; gpointer user_data; } GetMsgAsyncHelper; @@ -478,8 +479,8 @@ cleanup: if (account) g_object_unref (G_OBJECT (account)); - g_free (rf_helper->account_name); - g_slice_free (ReplyForwardHelper, rf_helper); +/* g_free (rf_helper->account_name); */ +/* g_slice_free (ReplyForwardHelper, rf_helper); */ } /* * Common code for the reply and forward actions @@ -523,6 +524,7 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) helper->func = reply_forward_func; helper->iter = tny_list_create_iterator (header_list); helper->user_data = rf_helper; + helper->num_ops = tny_list_get_length (header_list); if (MODEST_IS_MSG_VIEW_WINDOW(win)) { TnyMsg *msg; @@ -545,7 +547,7 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), helper->mail_op); - modest_mail_operation_process_msg (helper->mail_op, header, get_msg_cb, helper); + modest_mail_operation_process_msg (helper->mail_op, header, helper->num_ops, get_msg_cb, helper); /* Clean */ g_object_unref (G_OBJECT (header)); @@ -909,10 +911,6 @@ get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data) return; } - /* Notify the queue (if neccesary) */ - if (helper->mail_op != NULL) - modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), helper->mail_op); - /* Call user function */ if (helper->func) helper->func (msg, user_data); @@ -920,20 +918,27 @@ get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data) /* Process next element (if exists) */ tny_iterator_next (helper->iter); if (tny_iterator_is_done (helper->iter)) { + /* Notify the queue */ + if (helper->mail_op != NULL) + modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), helper->mail_op); + + /* Free resources */ TnyList *headers; + ReplyForwardHelper *rf_helper = (ReplyForwardHelper *) helper->user_data; headers = tny_iterator_get_list (helper->iter); - /* Free resources */ g_object_unref (G_OBJECT (headers)); g_object_unref (G_OBJECT (helper->iter)); + if (rf_helper != NULL) { + g_free (rf_helper->account_name); + g_slice_free (ReplyForwardHelper, rf_helper); + } g_slice_free (GetMsgAsyncHelper, helper); } else { TnyHeader *header; header = TNY_HEADER (tny_iterator_get_current (helper->iter)); /* tny_folder_get_msg_async (folder, header, */ /* get_msg_cb, NULL, helper); */ - helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); - modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), helper->mail_op); - modest_mail_operation_process_msg (helper->mail_op, header, get_msg_cb, helper); + modest_mail_operation_process_msg (helper->mail_op, header, helper->num_ops, get_msg_cb, helper); g_object_unref (G_OBJECT(header)); } @@ -981,6 +986,7 @@ modest_ui_actions_on_header_selected (ModestHeaderView *header_view, helper->window = MODEST_WINDOW (main_window); helper->iter = tny_list_create_iterator (list); helper->func = read_msg_func; + helper->num_ops = tny_list_get_length (list); /* folder = tny_header_get_folder (TNY_HEADER(header)); */ @@ -990,7 +996,7 @@ modest_ui_actions_on_header_selected (ModestHeaderView *header_view, helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), helper->mail_op); - modest_mail_operation_process_msg (helper->mail_op, header, get_msg_cb, helper); + modest_mail_operation_process_msg (helper->mail_op, header, helper->num_ops, get_msg_cb, helper); /* Frees */ /* g_object_unref (G_OBJECT (folder)); */ @@ -1226,7 +1232,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 (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation); modest_mail_operation_save_to_drafts (mail_operation, @@ -1513,7 +1519,7 @@ modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_windo if (result == GTK_RESPONSE_REJECT) { finished = TRUE; } else { - ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO); TnyFolder *new_folder = NULL; modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), @@ -1567,7 +1573,7 @@ modest_ui_actions_on_rename_folder (GtkAction *action, if (folder_name != NULL && strlen (folder_name) > 0) { ModestMailOperation *mail_op; - mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE); + mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); -- 1.7.9.5