#include <widgets/modest-combo-box.h>
#include "modest-progress-bar-widget.h"
#include <string.h>
+#include "modest-platform.h"
/* 'private'/'protected' functions */
static void modest_progress_bar_widget_class_init (ModestProgressBarWidgetClass *klass);
/* globals */
static GtkContainerClass *parent_class = NULL;
+/* Flag to show or not show Recv cancellation banner */
+static gboolean f_receivingOngoing = FALSE;
+
/* uncomment the following if you have defined any signals */
/* static guint signals[LAST_SIGNAL] = {0}; */
modest_progress_bar_add_operation (ModestProgressObject *self,
ModestMailOperation *mail_op)
{
- ModestProgressBarWidget *me;
- ObservableData *data;
- ModestProgressBarWidgetPrivate *priv;
+ ModestProgressBarWidget *me = NULL;
+ ObservableData *data = NULL;
+ ModestProgressBarWidgetPrivate *priv = NULL;
+ ModestMailOperationState *state = NULL;
me = MODEST_PROGRESS_BAR_WIDGET (self);
priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (me);
"progress-changed",
G_CALLBACK (on_progress_changed),
me);
- if (priv->observables == NULL) {
- priv->current = mail_op;
- }
- priv->observables = g_slist_append (priv->observables, data);
+ /* Set curent operation */
+ priv->current = mail_op;
/* Call progress_change handler to initialize progress message */
-/* on_progress_changed (mail_op, me); */
+ state = g_malloc0(sizeof(ModestMailOperationState));
+ state->done = 0;
+ state->total = 0;
+ state->op_type = modest_mail_operation_get_type_operation (mail_op);;
+/* on_progress_changed (mail_op, state, me); */
+ g_free(state);
+
+ /* Add operation to obserbable objects list */
+ priv->observables = g_slist_prepend (priv->observables, data);
}
static gint
priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (me);
if (priv->current == NULL) return;
- modest_mail_operation_cancel (priv->current);
+ /* bug 59107: if received canceled we shall show banner */
+ if ( f_receivingOngoing )
+ {
+ f_receivingOngoing = FALSE;
+ modest_platform_information_banner (NULL, NULL, _("emev_ib_ui_pop3_msg_recv_cancel"));
+ }
+
+ modest_mail_operation_cancel (priv->current);
}
+
static void
on_progress_changed (ModestMailOperation *mail_op,
ModestMailOperationState *state,
ModestProgressBarWidgetPrivate *priv;
gboolean determined = FALSE;
+ f_receivingOngoing = FALSE;
priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (self);
/* If the mail operation is the currently shown one */
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) {
case MODEST_MAIL_OPERATION_TYPE_RECEIVE:
+ f_receivingOngoing = TRUE;
if (determined)
msg = g_strdup_printf(_("mcen_me_receiving"),
state->done, state->total);
if (determined)
msg = g_strdup_printf(_("mcen_me_sending"), state->done,
state->total);
- else
+ else
msg = g_strdup(_("mail_me_sending"));
break;
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);
}
}
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;
g_return_if_fail (done <= total);
priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (self);
-
- /* Set progress */
- if (total != 100) /* FIXME: tinymail send 1/100 when it doesn't know better.. */
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress_bar),
- (gdouble)done/(gdouble)total);
- else
+
+ /* Set progress. Tinymail sometimes returns us 1/100 when it
+ does not have any clue, NOTE that 1/100 could be also a
+ valid progress (we will loose it), but it will be recovered
+ once the done is greater than 1 */
+ if ((done == 0 && total == 0) ||
+ (done == 1 && total == 100)) {
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->progress_bar));
+ } else {
+ gdouble percent = 0;
+ if (total != 0) /* Avoid division by zero. */
+ percent = (gdouble)done/(gdouble)total;
+
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress_bar),
+ percent);
+ }
/* Set text */
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress_bar), message);