[evolution] [EActivityBar] Reset priv->timeout_id when the timeout is reached



commit 4ed443d42014474bcd7c91aa1561c48ee51c205d
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 23 18:34:25 2014 +0200

    [EActivityBar] Reset priv->timeout_id when the timeout is reached
    
    Since GLib begun to claim about incorrect ids being passed to
    g_source_remove(), a problem with EActivityBar had been discovered,
    it doesn't unset its priv->timeout_id when the timeout is reached,
    which leads to the new runtime warnings from GLib.

 e-util/e-activity-bar.c |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/e-util/e-activity-bar.c b/e-util/e-activity-bar.c
index 3638435..0edf019 100644
--- a/e-util/e-activity-bar.c
+++ b/e-util/e-activity-bar.c
@@ -54,11 +54,43 @@ G_DEFINE_TYPE (
        e_activity_bar,
        GTK_TYPE_INFO_BAR)
 
+typedef struct _EActivityBarTimeoutData {
+       EActivityBar *bar;
+       EActivity *activity;
+} EActivityBarTimeoutData;
+
+static void
+activity_bar_timeout_data_free (gpointer ptr)
+{
+       EActivityBarTimeoutData *data = ptr;
+
+       if (data) {
+               g_object_unref (data->activity);
+               g_free (data);
+       }
+}
+
+static gboolean
+activity_bar_timeout_reached (gpointer user_data)
+{
+       EActivityBarTimeoutData *data = user_data;
+
+       g_return_val_if_fail (data != NULL, FALSE);
+       g_return_val_if_fail (E_IS_ACTIVITY_BAR (data->bar), FALSE);
+
+       if (!g_source_is_destroyed (g_main_current_source ()) &&
+           g_source_get_id (g_main_current_source ()) == data->bar->priv->timeout_id)
+               data->bar->priv->timeout_id = 0;
+
+       return FALSE;
+}
+
 static void
 activity_bar_feedback (EActivityBar *bar)
 {
        EActivity *activity;
        EActivityState state;
+       EActivityBarTimeoutData *data;
 
        activity = e_activity_bar_get_activity (bar);
        g_return_if_fail (E_IS_ACTIVITY (activity));
@@ -70,11 +102,16 @@ activity_bar_feedback (EActivityBar *bar)
        if (bar->priv->timeout_id > 0)
                g_source_remove (bar->priv->timeout_id);
 
+       data = g_new0 (EActivityBarTimeoutData, 1);
+
+       data->bar = bar;
+       data->activity = g_object_ref (activity);
+
        /* Hold a reference on the EActivity for a short
         * period so the activity bar stays visible. */
        bar->priv->timeout_id = e_named_timeout_add_seconds_full (
-               G_PRIORITY_LOW, FEEDBACK_PERIOD, (GSourceFunc) gtk_false,
-               g_object_ref (activity), (GDestroyNotify) g_object_unref);
+               G_PRIORITY_LOW, FEEDBACK_PERIOD, activity_bar_timeout_reached,
+               data, activity_bar_timeout_data_free);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]