]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-presentation-timer.c
[timer] fix Issue #5
[evince.git] / shell / ev-presentation-timer.c
index 3b2a000dda055f636942eccb1e335bf77fb9875e..d1b3474d46ada8002edb65a1f874725239cec39a 100644 (file)
@@ -37,7 +37,8 @@ struct _EvPresentationTimerPrivate
        gint       remaining;
        guint      page;
        guint      pages;
-       guint      running;
+       guint      timeout;
+       gboolean   running;
 };
 
 #define EV_PRESENTATION_TIMER_GET_PRIVATE(object) \
@@ -65,8 +66,12 @@ ev_presentation_timer_draw(GtkWidget *timer, cairo_t *cr)
        cairo_stroke (cr);
        if(ev_timer->priv->running && ev_timer->priv->time > 0 && ev_timer->priv->remaining > 0)
        {
-               gdouble progress = ev_presentation_timer_progress (ev_timer->priv->time, ev_timer->priv->remaining)*(allocation.width);
-               cairo_rectangle (cr, allocation.width-progress, 10, (allocation.width-(allocation.width-progress))-10, allocation.height-5);
+               gdouble progress = ev_presentation_timer_progress (ev_timer->priv->time,
+                                                                  ev_timer->priv->remaining)*(allocation.width);
+               cairo_rectangle (cr, allocation.width-progress,
+                                10,
+                                (allocation.width-(allocation.width-progress))-10,
+                                allocation.height-5);
                cairo_stroke_preserve (cr);
                cairo_fill(cr);
        }
@@ -113,6 +118,7 @@ ev_presentation_timer_init (EvPresentationTimer *ev_timer)
        ev_timer->priv->pages = 0;
        ev_timer->priv->remaining = 0;
        ev_timer->priv->time = 0;
+       ev_timer->priv->timeout = 0;
        ev_timer->priv->running = FALSE;
 }
 
@@ -123,7 +129,7 @@ ev_presentation_timer_start (EvPresentationTimer *ev_timer)
        {
                ev_timer->priv->remaining = (ev_timer->priv->time)*60;
                ev_timer->priv->running = TRUE;
-               g_timeout_add_seconds (1, timeout_cb, ev_timer);
+               ev_timer->priv->timeout = g_timeout_add_seconds (1, timeout_cb, ev_timer);
        }
 }
 
@@ -143,6 +149,16 @@ ev_presentation_timer_set_time (EvPresentationTimer *ev_timer,
        ev_timer->priv->time = (time < -1)? -1:time;
 }
 
+static void
+ev_presentation_timer_dispose (GObject *gobject)
+{
+       EvPresentationTimer *ev_timer = EV_PRESENTATION_TIMER (gobject);
+       EvPresentationTimerPrivate *priv = EV_PRESENTATION_TIMER (ev_timer)->priv;
+       if (priv->timeout > 0)
+               g_source_remove (priv->timeout);
+       G_OBJECT_CLASS (ev_presentation_timer_parent_class)->dispose (gobject);
+}
+
 static void
 ev_presentation_timer_class_init (EvPresentationTimerClass *klass)
 {
@@ -150,7 +166,7 @@ ev_presentation_timer_class_init (EvPresentationTimerClass *klass)
        GtkWidgetClass  *widget_class = GTK_WIDGET_CLASS (klass);
        g_type_class_add_private (object_class, sizeof (EvPresentationTimerPrivate));
        widget_class->draw = ev_presentation_timer_draw;
-       /*object_class->finalize = ev_presentation_timer_finalize;*/
+       object_class->dispose =  ev_presentation_timer_dispose;
 }
 
 GtkWidget *