diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-10-22 04:21:19 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-10-23 02:21:22 +0800 |
commit | c881b5bc5e61d04b18d4ab46ad70533e7340d15b (patch) | |
tree | e70a3ed0d2f93dacfe20d856de4d29578beb2e50 /widgets/misc/e-activity-bar.c | |
parent | f0714755e2fa8b06425907c2cf189abd3a1b7119 (diff) | |
download | gsoc2013-evolution-c881b5bc5e61d04b18d4ab46ad70533e7340d15b.tar.gz gsoc2013-evolution-c881b5bc5e61d04b18d4ab46ad70533e7340d15b.tar.zst gsoc2013-evolution-c881b5bc5e61d04b18d4ab46ad70533e7340d15b.zip |
Simplify EActivity.
With unintrusive error dialogs gone, we can cut some unnecessary bits
out of EActivity.
I'm also adding a new enum property called "state", which is one of:
E_ACTIVITY_RUNNING
E_ACTIVITY_WAITING
E_ACTIVITY_CANCELLED
E_ACTIVITY_COMPLETED
The state of an activity must be explicitly changed. In particular,
when the user cancels an activity the state should be set only after
confirming the operation has been cancelled and not when cancellation
is requested (e.g. after receiving a G_IO_ERROR_CANCELLED, not when
the GCancellable emits "cancelled"). EActivityBar and EActivityProxy
widgets have been updated to make this distinction clearer in the UI.
E_ACTIVITY_WAITING will be used when activities have to be queued and
dispatched in sequence, which I haven't written yet.
Diffstat (limited to 'widgets/misc/e-activity-bar.c')
-rw-r--r-- | widgets/misc/e-activity-bar.c | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/widgets/misc/e-activity-bar.c b/widgets/misc/e-activity-bar.c index 0337822adc..a86e37cbdf 100644 --- a/widgets/misc/e-activity-bar.c +++ b/widgets/misc/e-activity-bar.c @@ -23,12 +23,14 @@ ((obj), E_TYPE_ACTIVITY_BAR, EActivityBarPrivate)) #define FEEDBACK_PERIOD 1 /* seconds */ +#define COMPLETED_ICON_NAME "emblem-default" struct _EActivityBarPrivate { EActivity *activity; /* weak reference */ GtkWidget *image; /* not referenced */ GtkWidget *label; /* not referenced */ GtkWidget *cancel; /* not referenced */ + GtkWidget *spinner; /* not referenced */ /* If the user clicks the Cancel button, keep the cancelled * EActivity object alive for a short duration so the user @@ -47,13 +49,35 @@ G_DEFINE_TYPE ( GTK_TYPE_INFO_BAR) static void +activity_bar_feedback (EActivityBar *bar) +{ + EActivity *activity; + EActivityState state; + + activity = e_activity_bar_get_activity (bar); + g_return_if_fail (E_IS_ACTIVITY (activity)); + + state = e_activity_get_state (activity); + if (state != E_ACTIVITY_CANCELLED && state != E_ACTIVITY_COMPLETED) + return; + + if (bar->priv->timeout_id > 0) + g_source_remove (bar->priv->timeout_id); + + /* Hold a reference on the EActivity for a short + * period so the activity bar stays visible. */ + bar->priv->timeout_id = g_timeout_add_seconds_full ( + G_PRIORITY_LOW, FEEDBACK_PERIOD, (GSourceFunc) gtk_false, + g_object_ref (activity), (GDestroyNotify) g_object_unref); +} + +static void activity_bar_update (EActivityBar *bar) { EActivity *activity; + EActivityState state; GCancellable *cancellable; const gchar *icon_name; - gboolean cancelled; - gboolean completed; gboolean sensitive; gboolean visible; gchar *description; @@ -66,14 +90,13 @@ activity_bar_update (EActivityBar *bar) } cancellable = e_activity_get_cancellable (activity); - cancelled = g_cancellable_is_cancelled (cancellable); - completed = e_activity_is_completed (activity); icon_name = e_activity_get_icon_name (activity); + state = e_activity_get_state (activity); description = e_activity_describe (activity); gtk_label_set_text (GTK_LABEL (bar->priv->label), description); - if (cancelled) { + if (state == E_ACTIVITY_CANCELLED) { PangoAttribute *attr; PangoAttrList *attr_list; @@ -90,25 +113,27 @@ activity_bar_update (EActivityBar *bar) gtk_label_set_attributes ( GTK_LABEL (bar->priv->label), NULL); - if (cancelled) + if (state == E_ACTIVITY_COMPLETED) + icon_name = COMPLETED_ICON_NAME; + + if (state == E_ACTIVITY_CANCELLED) { gtk_image_set_from_stock ( GTK_IMAGE (bar->priv->image), GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON); - else { - if (completed) - icon_name = "emblem-default"; + gtk_widget_show (bar->priv->image); + } else if (icon_name != NULL) { gtk_image_set_from_icon_name ( GTK_IMAGE (bar->priv->image), icon_name, GTK_ICON_SIZE_BUTTON); + gtk_widget_show (bar->priv->image); + } else { + gtk_widget_hide (bar->priv->image); } - visible = (icon_name != NULL); - gtk_widget_set_visible (bar->priv->image, visible); - visible = (cancellable != NULL); gtk_widget_set_visible (bar->priv->cancel, visible); - sensitive = !cancelled && !completed; + sensitive = (state == E_ACTIVITY_RUNNING); gtk_widget_set_sensitive (bar->priv->cancel, sensitive); visible = (description != NULL && *description != '\0'); @@ -128,30 +153,16 @@ activity_bar_cancel (EActivityBar *bar) cancellable = e_activity_get_cancellable (activity); g_cancellable_cancel (cancellable); -} - -static void -activity_bar_feedback (EActivityBar *bar) -{ - EActivity *activity; - - activity = e_activity_bar_get_activity (bar); - g_return_if_fail (E_IS_ACTIVITY (activity)); - if (bar->priv->timeout_id > 0) - g_source_remove (bar->priv->timeout_id); - - /* Hold a reference on the EActivity for a short - * period so the activity bar stays visible. */ - bar->priv->timeout_id = g_timeout_add_seconds_full ( - G_PRIORITY_LOW, FEEDBACK_PERIOD, (GSourceFunc) gtk_false, - g_object_ref (activity), (GDestroyNotify) g_object_unref); + activity_bar_update (bar); } static void activity_bar_weak_notify_cb (EActivityBar *bar, GObject *where_the_object_was) { + g_return_if_fail (E_IS_ACTIVITY_BAR (bar)); + bar->priv->activity = NULL; e_activity_bar_set_activity (bar, NULL); } @@ -259,7 +270,19 @@ e_activity_bar_init (EActivityBar *bar) widget = gtk_image_new (); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); bar->priv->image = widget; - gtk_widget_show (widget); + + widget = gtk_spinner_new (); + gtk_spinner_start (GTK_SPINNER (widget)); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + bar->priv->spinner = widget; + + /* The spinner is only visible when the image is not. */ + g_object_bind_property ( + bar->priv->image, "visible", + bar->priv->spinner, "visible", + G_BINDING_BIDIRECTIONAL | + G_BINDING_SYNC_CREATE | + G_BINDING_INVERT_BOOLEAN); widget = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); @@ -300,12 +323,8 @@ e_activity_bar_set_activity (EActivityBar *bar, { g_return_if_fail (E_IS_ACTIVITY_BAR (bar)); - if (activity != NULL) { + if (activity != NULL) g_return_if_fail (E_IS_ACTIVITY (activity)); - g_object_weak_ref ( - G_OBJECT (activity), (GWeakNotify) - activity_bar_weak_notify_cb, bar); - } if (bar->priv->timeout_id > 0) { g_source_remove (bar->priv->timeout_id); @@ -324,23 +343,15 @@ e_activity_bar_set_activity (EActivityBar *bar, bar->priv->activity = activity; if (activity != NULL) { - g_signal_connect_swapped ( - activity, "cancelled", - G_CALLBACK (activity_bar_feedback), bar); + g_object_weak_ref ( + G_OBJECT (activity), (GWeakNotify) + activity_bar_weak_notify_cb, bar); g_signal_connect_swapped ( - activity, "completed", + activity, "notify::state", G_CALLBACK (activity_bar_feedback), bar); g_signal_connect_swapped ( - activity, "cancelled", - G_CALLBACK (activity_bar_update), bar); - - g_signal_connect_swapped ( - activity, "completed", - G_CALLBACK (activity_bar_update), bar); - - g_signal_connect_swapped ( activity, "notify", G_CALLBACK (activity_bar_update), bar); } |