Partially fixes NB#78521
authorFelipe Erias Morandeira <femorandeira@igalia.com>
Thu, 13 Dec 2007 15:30:38 +0000 (15:30 +0000)
committerFelipe Erias Morandeira <femorandeira@igalia.com>
Thu, 13 Dec 2007 15:30:38 +0000 (15:30 +0000)
  * src/maemo/modest-progress-bar-widget.c:
    When the progress bar receives a "progress-changed" signal from its mail operation
    where state->done = 0 and state->total = 0, it begins to pulse periodically until
    the mail operation finishes or it receives a "progress-changed" signal with
    positive values.
    * (modest_progress_bar_widget_is_pulsating) :
    * (modest_progress_bar_widget_set_pulsating_mode) : manage this pulsating mode

* src/modest-mail-operation.c
    * (modest_mail_operation_update_account) :
    * (modest_mail_operation_get_msg) :
    * (modest_mail_operation_get_msgs_full) :
    * (modest_mail_operation_refresh_folder) : these functions send an initial "progress-changed"
        signal because it could happen that the first signal with "real" data takes a long time
        to happen, or in some cases doesn't happen at all, leaving the user with an empty
        progress bar for a while.

pmo-trunk-r3912

src/maemo/modest-progress-bar-widget.c
src/modest-mail-operation.c

index 5dd1b7d..ac0ca5d 100644 (file)
@@ -59,6 +59,12 @@ static void on_progress_changed                    (ModestMailOperation  *mail_o
 
 static gboolean     progressbar_clean        (GtkProgressBar *bar);
 
+static gboolean modest_progress_bar_widget_is_pulsating (ModestProgressBarWidget *self);
+
+static void modest_progress_bar_widget_set_pulsating_mode (ModestProgressBarWidget *self,
+                                                           const gchar* msg,
+                                                           gboolean is_pulsating);
+
 #define XALIGN 0.5
 #define YALIGN 0.5
 #define XSPACE 1
@@ -67,6 +73,8 @@ static gboolean     progressbar_clean        (GtkProgressBar *bar);
 #define LOWER 0
 #define UPPER 150
 
+#define MODEST_PROGRESS_BAR_PULSE_INTERVAL 250
+
 /* list my signals  */
 /* enum { */
 /*     LAST_SIGNAL */
@@ -80,11 +88,11 @@ struct _ObservableData {
 
 typedef struct _ModestProgressBarWidgetPrivate ModestProgressBarWidgetPrivate;
 struct _ModestProgressBarWidgetPrivate {
-        GSList              *observables;
-        ModestMailOperation *current;
-
+       GSList              *observables;
+       ModestMailOperation *current;
        guint count;
        GtkWidget *progress_bar;
+       guint pulsating_timeout;
 };
 #define MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                  MODEST_TYPE_PROGRESS_BAR_WIDGET, \
@@ -186,6 +194,8 @@ modest_progress_bar_widget_init (ModestProgressBarWidget *self)
        /* Add progress bar widget */   
        gtk_box_pack_start (GTK_BOX(self), align, TRUE, TRUE, 0);
        gtk_widget_show_all (GTK_WIDGET(self));       
+       
+       priv->pulsating_timeout = 0;
 }
 
 static void
@@ -206,6 +216,10 @@ modest_progress_bar_widget_finalize (GObject *obj)
                g_slist_free (priv->observables);
                priv->observables = NULL;
        }
+       
+       /* remove timeout */
+       if (priv->pulsating_timeout != 0)
+               g_source_remove (priv->pulsating_timeout);
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
@@ -292,6 +306,7 @@ modest_progress_bar_remove_operation (ModestProgressObject *self,
                        priv->current = NULL;
 
                /* Refresh the view */
+               modest_progress_bar_widget_set_pulsating_mode (me, NULL, FALSE);
                progressbar_clean (GTK_PROGRESS_BAR (priv->progress_bar));
        }
        
@@ -383,6 +398,8 @@ on_progress_changed (ModestMailOperation  *mail_op,
                        modest_progress_bar_widget_set_progress (self, msg,
                                                                 state->bytes_done,
                                                                 state->bytes_total);
+               else if ((state->done == 0) && (state->total == 0))
+                       modest_progress_bar_widget_set_pulsating_mode (self, msg, TRUE);
                else
                        modest_progress_bar_widget_set_progress (self, msg,
                                                                 state->done,
@@ -421,7 +438,10 @@ modest_progress_bar_widget_set_progress (ModestProgressBarWidget *self,
        
        priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (self);
 
-       priv->count++;
+       priv->count++;
+
+       if (modest_progress_bar_widget_is_pulsating (self))
+               modest_progress_bar_widget_set_pulsating_mode (self, NULL, FALSE);
 
        /* Set progress. Tinymail sometimes returns us 1/100 when it
           does not have any clue, NOTE that 1/100 could be also a
@@ -459,3 +479,55 @@ modest_progress_bar_widget_set_undetermined_progress (ModestProgressBarWidget *s
        on_progress_changed (mail_op, state, self);
        g_free(state);
 }
+
+/* this has to be explicitly removed */
+static gboolean
+do_pulse (gpointer data)
+{
+       ModestProgressBarWidgetPrivate *priv;
+       
+       g_return_val_if_fail (MODEST_IS_PROGRESS_BAR_WIDGET(data), FALSE);
+       
+       priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (data);
+       gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->progress_bar));
+       return TRUE;
+}
+
+gboolean
+modest_progress_bar_widget_is_pulsating (ModestProgressBarWidget *self)
+{
+       ModestProgressBarWidgetPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_PROGRESS_BAR_WIDGET(self), FALSE);
+
+       priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (self);
+       
+       return priv->pulsating_timeout != 0;
+}
+
+void
+modest_progress_bar_widget_set_pulsating_mode (ModestProgressBarWidget *self,
+                                               const gchar* msg,
+                                               gboolean is_pulsating)
+{
+       ModestProgressBarWidgetPrivate *priv;
+
+       g_return_if_fail (MODEST_IS_PROGRESS_BAR_WIDGET(self));
+
+       priv = MODEST_PROGRESS_BAR_WIDGET_GET_PRIVATE (self);
+       
+       if (msg != NULL)
+               gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress_bar), msg);
+       
+       if (is_pulsating == (priv->pulsating_timeout != 0))
+               return;
+       else if (is_pulsating && (priv->pulsating_timeout == 0)) {
+               /* enable */
+               priv->pulsating_timeout = g_timeout_add (MODEST_PROGRESS_BAR_PULSE_INTERVAL,
+                               do_pulse, self);
+       } else if (!is_pulsating && (priv->pulsating_timeout != 0)) {
+               /* disable */
+               g_source_remove (priv->pulsating_timeout);
+               priv->pulsating_timeout = 0;
+       }
+}
index 82f2bcf..1d8bcc9 100644 (file)
@@ -1590,6 +1590,14 @@ modest_mail_operation_update_account (ModestMailOperation *self,
        modest_account_mgr_set_account_busy (modest_runtime_get_account_mgr (), account_name, TRUE);
        modest_mail_operation_notify_start (self);
 
+       /* notify about the start of the operation */ 
+       ModestMailOperationState *state;
+       state = modest_mail_operation_clone_state (self);
+       state->done = 0;
+       state->total = 0;
+       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 
+                       0, state, NULL);
+       
        /* Get all folders and continue in the callback */    
        folders = tny_simple_list_new ();
        tny_folder_store_get_folders_async (TNY_FOLDER_STORE (store_account),
@@ -2154,6 +2162,15 @@ modest_mail_operation_get_msg (ModestMailOperation *self,
        helper->total_bytes = tny_header_get_message_size (header);
 
        modest_mail_operation_notify_start (self);
+       
+       /* notify about the start of the operation */ 
+       ModestMailOperationState *state;
+       state = modest_mail_operation_clone_state (self);
+       state->done = 0;
+       state->total = 0;
+       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 
+                               0, state, NULL);
+       
        tny_folder_get_msg_async (folder, header, get_msg_async_cb, get_msg_status_cb, helper);
 
        g_object_unref (G_OBJECT (folder));
@@ -2302,6 +2319,14 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
                modest_mail_operation_notify_start (self);
                iter = tny_list_create_iterator (header_list);
                while (!tny_iterator_is_done (iter)) { 
+                       /* notify about the start of the operation */ 
+                       ModestMailOperationState *state;
+                       state = modest_mail_operation_clone_state (self);
+                       state->done = 0;
+                       state->total = 0;
+                       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 
+                                       0, state, NULL);
+                       
                        GetMsgInfo *msg_info = NULL;
                        TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
                        TnyFolder *folder = tny_header_get_folder (header);
@@ -2906,6 +2931,15 @@ modest_mail_operation_refresh_folder  (ModestMailOperation *self,
           updates before the callback call then this could happen. We
           must review the design */
        modest_mail_operation_notify_start (self);
+       
+       /* notify that the operation was started */
+       ModestMailOperationState *state;
+       state = modest_mail_operation_clone_state (self);
+       state->done = 0;
+       state->total = 0;
+       g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 
+                       0, state, NULL);
+       
        tny_folder_refresh_async (folder,
                                  on_refresh_folder,
                                  on_refresh_folder_status_update,