From 68945e42768533308e3b94f0dc046ef722e56115 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Wed, 20 Jun 2007 11:57:49 +0000 Subject: [PATCH] * Added progress information to open single message operation * Added byte information to the ModestMailOperationStatus struct pmo-trunk-r2331 --- src/maemo/modest-progress-bar-widget.c | 20 ++++++++++++++------ src/maemo/modest-progress-bar-widget.h | 4 +++- src/modest-mail-operation.c | 9 ++++++++- src/modest-mail-operation.h | 2 ++ src/modest-ui-actions.c | 19 ++++++++++++++----- 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/maemo/modest-progress-bar-widget.c b/src/maemo/modest-progress-bar-widget.c index 63d971a..9459be1 100644 --- a/src/maemo/modest-progress-bar-widget.c +++ b/src/maemo/modest-progress-bar-widget.c @@ -333,7 +333,7 @@ on_progress_changed (ModestMailOperation *mail_op, if (priv->current == mail_op) { gchar *msg = NULL; - determined = (state->done > 0 && state->total > 0) & + determined = (state->done > 0 && state->total > 0) && !(state->done == 1 && state->total == 100); switch (state->op_type) { @@ -359,7 +359,15 @@ on_progress_changed (ModestMailOperation *mail_op, msg = g_strdup(""); } - modest_progress_bar_widget_set_progress (self, msg, state->done, state->total); + /* If we have byte information use it */ + if ((state->bytes_done == 0) && (state->bytes_total == 0)) + modest_progress_bar_widget_set_progress (self, msg, + state->bytes_done, + state->bytes_total); + else + modest_progress_bar_widget_set_progress (self, msg, + state->done, + state->total); g_free (msg); } } @@ -381,10 +389,10 @@ modest_progress_bar_widget_new () void -modest_progress_bar_widget_set_progress (ModestProgressBarWidget *self, - const gchar *message, - guint done, - guint total) +modest_progress_bar_widget_set_progress (ModestProgressBarWidget *self, + const gchar *message, + gint done, + gint total) { ModestProgressBarWidgetPrivate *priv; diff --git a/src/maemo/modest-progress-bar-widget.h b/src/maemo/modest-progress-bar-widget.h index 0db622a..a55dd5b 100644 --- a/src/maemo/modest-progress-bar-widget.h +++ b/src/maemo/modest-progress-bar-widget.h @@ -70,7 +70,9 @@ GType modest_progress_bar_widget_get_type (void) G_GNUC_CONST; GtkWidget* modest_progress_bar_widget_new (void); void modest_progress_bar_widget_set_progress (ModestProgressBarWidget *self, - const gchar *msg, guint done, guint total); + const gchar *msg, + gint done, + gint total); diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 0199d9e..f41bfda 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -105,6 +105,7 @@ struct _ModestMailOperationPrivate { typedef struct _GetMsgAsyncHelper { ModestMailOperation *mail_op; + TnyHeader *header; GetMsgAsyncUserCallback user_callback; gpointer user_data; } GetMsgAsyncHelper; @@ -477,6 +478,8 @@ modest_mail_operation_clone_state (ModestMailOperation *self) state->done = priv->done; state->total = priv->total; state->finished = modest_mail_operation_is_finished (self); + state->bytes_done = 0; + state->bytes_total = 0; return state; } @@ -1488,6 +1491,7 @@ void modest_mail_operation_get_msg (ModestMailOperation *self, helper->mail_op = self; helper->user_callback = user_callback; helper->user_data = user_data; + helper->header = g_object_ref (header); tny_folder_get_msg_async (folder, header, get_msg_cb, get_msg_status_cb, helper); @@ -1540,11 +1544,12 @@ get_msg_cb (TnyFolder *folder, /* If user defined callback function was defined, call it */ if (helper->user_callback) { - helper->user_callback (self, NULL, msg, helper->user_data); + helper->user_callback (self, helper->header, msg, helper->user_data); } out: /* Free */ + g_object_unref (helper->header); g_slice_free (GetMsgAsyncHelper, helper); /* Notify about operation end */ @@ -1577,6 +1582,8 @@ get_msg_status_cb (GObject *obj, priv->total = 1; state = modest_mail_operation_clone_state (self); + state->bytes_done = status->position; + state->bytes_total = status->of_total; g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, state, NULL); g_slice_free (ModestMailOperationState, state); } diff --git a/src/modest-mail-operation.h b/src/modest-mail-operation.h index 7806925..8ff9dfe 100644 --- a/src/modest-mail-operation.h +++ b/src/modest-mail-operation.h @@ -134,6 +134,8 @@ typedef void (*RefreshAsyncUserCallback) (const GObject *obj, typedef struct { guint done; guint total; + gdouble bytes_done; + gdouble bytes_total; gboolean finished; ModestMailOperationStatus status; ModestMailOperationTypeOperation op_type; diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 626b997..663915b 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -726,11 +726,20 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win) modest_ui_actions_get_msgs_full_error_handler, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); - modest_mail_operation_get_msgs_full (mail_op, - not_opened_headers, - open_msg_cb, - NULL, - NULL); + if (tny_list_get_length (not_opened_headers) > 1) { + modest_mail_operation_get_msgs_full (mail_op, + not_opened_headers, + open_msg_cb, + NULL, + NULL); + } else { + TnyIterator *iter = tny_list_create_iterator (not_opened_headers); + TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter)); + modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL); + g_object_unref (header); + g_object_unref (iter); + } + /* Clean */ g_object_unref (not_opened_headers); g_object_unref (iter); -- 1.7.9.5