[recipes] Add explicit start/stop API for the cooking view



commit 578ca94d5892bafdc1ea56fa29120ac0aa5fe83d
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Feb 23 19:09:20 2017 -0500

    Add explicit start/stop API for the cooking view
    
    This will help with cleaning up the life-cycle handling
    of timer objects. We don't want to leak those, since
    they may cause unexpected notifications when they
    expire much later.

 src/gr-cooking-view.c |   21 ++++++++++++++++++++-
 src/gr-cooking-view.h |    2 ++
 2 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/src/gr-cooking-view.c b/src/gr-cooking-view.c
index bf795a5..d81288e 100644
--- a/src/gr-cooking-view.c
+++ b/src/gr-cooking-view.c
@@ -202,6 +202,7 @@ setup_step (GrCookingView *view)
                 gtk_widget_hide (view->cooking_label);
         }
 
+        g_object_set (view->cooking_timer, "timer", s->timer, NULL);
         if (s->timer) {
                 gboolean active;
                 guint64 remaining;
@@ -211,7 +212,6 @@ setup_step (GrCookingView *view)
 
                 active = gr_timer_get_active (s->timer);
                 remaining = gr_timer_get_remaining (s->timer);
-                g_object_set (view->cooking_timer, "timer", s->timer, NULL);
 
                 if (active || remaining > 0)
                         gtk_stack_set_visible_child_name (GTK_STACK (view->cooking_stack), "timer");
@@ -493,6 +493,7 @@ void
 gr_cooking_view_set_images (GrCookingView *view,
                             GArray        *images)
 {
+        g_clear_pointer (&view->images, g_array_unref);
         view->images = g_array_ref (images);
 
         setup_steps (view);
@@ -530,6 +531,24 @@ gr_cooking_view_set_step (GrCookingView *view,
 }
 
 void
+gr_cooking_view_start (GrCookingView *view)
+{
+        set_step (view, 0);
+}
+
+void
+gr_cooking_view_stop (GrCookingView *view)
+{
+        g_object_set (view->cooking_timer, "timer", NULL, NULL);
+        if (view->timer_box)
+                container_remove_all (GTK_CONTAINER (view->timer_box));
+
+        g_clear_pointer (&view->instructions, g_free);
+        g_clear_pointer (&view->images, g_array_unref);
+        g_ptr_array_set_size (view->steps, 0);
+}
+
+void
 gr_cooking_view_forward (GrCookingView *view)
 {
         StepData *s;
diff --git a/src/gr-cooking-view.h b/src/gr-cooking-view.h
index 34d49d9..85685ab 100644
--- a/src/gr-cooking-view.h
+++ b/src/gr-cooking-view.h
@@ -39,6 +39,8 @@ int            gr_cooking_view_get_n_steps   (GrCookingView *view);
 int            gr_cooking_view_get_step      (GrCookingView *view);
 void           gr_cooking_view_set_step      (GrCookingView *view,
                                               int            step);
+void           gr_cooking_view_start         (GrCookingView *view);
+void           gr_cooking_view_stop          (GrCookingView *view);
 void           gr_cooking_view_forward       (GrCookingView *view);
 void           gr_cooking_view_next_step     (GrCookingView *view);
 void           gr_cooking_view_prev_step     (GrCookingView *view);


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