#include "modest-progress-bar-widget.h"
#include <string.h>
#include "modest-platform.h"
+#include "modest-runtime.h"
/* 'private'/'protected' functions */
static void modest_progress_bar_widget_class_init (ModestProgressBarWidgetClass *klass);
static void modest_progress_bar_remove_operation (ModestProgressObject *self,
ModestMailOperation *mail_op);
-static void
-modest_progress_bar_cancel_current_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 modest_progress_bar_cancel_all_operations (ModestProgressObject *self);
+
+static guint modest_progress_bar_num_pending_operations (ModestProgressObject *self);
static void on_progress_changed (ModestMailOperation *mail_op,
ModestMailOperationState *state,
GSList *observables;
ModestMailOperation *current;
+ guint count;
GtkWidget *progress_bar;
};
#define MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
/* 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}; */
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->cancel_all_operations_func = modest_progress_bar_cancel_all_operations;
klass->num_pending_operations_func = modest_progress_bar_num_pending_operations;
}
GtkAdjustment *adj;
priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE(self);
-
+
/* Alignment */
align = gtk_alignment_new(XALIGN, YALIGN, XSPACE, YSPACE);
req.height = 64;
gtk_progress_set_text_alignment (GTK_PROGRESS (priv->progress_bar), 0, 0.5);
gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (priv->progress_bar), PANGO_ELLIPSIZE_END);
+ gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (priv->progress_bar), 0.05);
gtk_widget_size_request (priv->progress_bar, &req);
gtk_container_add (GTK_CONTAINER (align), priv->progress_bar);
gtk_widget_size_request (align, &req);
G_CALLBACK (on_progress_changed),
me);
/* Set curent operation */
- priv->current = mail_op;
-
- /* Call progress_change handler to initialize progress message */
- 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);
+ if (priv->current == NULL) {
+ priv->current = mail_op;
+
+ priv->count = 0;
+
+ /* Call progress_change handler to initialize progress message */
+ 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 void
modest_progress_bar_remove_operation (ModestProgressObject *self,
- ModestMailOperation *mail_op)
+ ModestMailOperation *mail_op)
{
ModestProgressBarWidget *me;
ModestProgressBarWidgetPrivate *priv;
GSList *link;
ObservableData *tmp_data = NULL;
+ gboolean is_current;
me = MODEST_PROGRESS_BAR_WIDGET (self);
priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (me);
+ is_current = (priv->current == mail_op);
+
/* Find item */
tmp_data = g_malloc0 (sizeof (ObservableData));
- tmp_data->mail_op = mail_op;
+ tmp_data->mail_op = mail_op;
link = g_slist_find_custom (priv->observables,
tmp_data,
(GCompareFunc) compare_observable_data);
}
/* Update the current mail operation */
- if (priv->current == mail_op) {
+ if (is_current) {
if (priv->observables)
priv->current = ((ObservableData *) priv->observables->data)->mail_op;
else
if (priv->current == NULL) return;
- /* 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"));
- }
+ /* If received canceled we shall show banner */
+ if (modest_mail_operation_get_type_operation (priv->current) ==
+ MODEST_MAIL_OPERATION_TYPE_RECEIVE)
+ modest_platform_information_banner (NULL, NULL,
+ _("emev_ib_ui_pop3_msg_recv_cancel"));
modest_mail_operation_cancel (priv->current);
}
static void
+modest_progress_bar_cancel_all_operations (ModestProgressObject *self)
+{
+ ModestProgressBarWidget *me;
+ ModestProgressBarWidgetPrivate *priv;
+
+ me = MODEST_PROGRESS_BAR_WIDGET (self);
+ priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (me);
+
+ /* If received canceled we shall show banner */
+ if (priv->current && modest_mail_operation_get_type_operation (priv->current) ==
+ MODEST_MAIL_OPERATION_TYPE_RECEIVE)
+ modest_platform_information_banner (NULL, NULL,
+ _("emev_ib_ui_pop3_msg_recv_cancel"));
+
+ /* Cancel all the mail operations */
+ modest_mail_operation_queue_cancel_all (modest_runtime_get_mail_operation_queue ());
+}
+
+static void
on_progress_changed (ModestMailOperation *mail_op,
ModestMailOperationState *state,
ModestProgressBarWidget *self)
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 > 1) &&
!(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);
gint total)
{
ModestProgressBarWidgetPrivate *priv;
-
+ gboolean determined = FALSE;
+
g_return_if_fail (MODEST_IS_PROGRESS_BAR_WIDGET(self));
g_return_if_fail (done <= total);
priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (self);
+ priv->count++;
+
/* 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)) {
+ determined = (done > 0 && total > 1) &&
+ !(done == 1 && total == 100);
+/* if ((done == 0 && total == 0) || */
+/* (done == 1 && total == 100)) { */
+ if (!determined) {
+ gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (priv->progress_bar), /* Deprecated */
+ GTK_PROGRESS_CONTINUOUS);
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->progress_bar));
+ printf ("debug: %s:\n undetermined progress (%i) changed (%i/%i) : %i\n", __FUNCTION__,
+ (int) priv->progress_bar,
+ done,
+ total,
+ priv->count);
} 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);
- }
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress_bar),
+ percent);
+ printf ("debug: %s:\n determined progress (%i) changed (%i/%i) : %i\n", __FUNCTION__,
+ (int) priv->progress_bar,
+ done,
+ total,
+ priv->count);
+ }
+
/* Set text */
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress_bar), message);
}