[recipes] Allow setting titles for timers



commit 4f1ee9798cbdbe16aebd0c152168d6ba6a8a8bf7
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 24 00:14:22 2017 -0500

    Allow setting titles for timers
    
    These are used when displaying timers in the cooking view.

 src/gr-cooking-view.c     |    7 ++++---
 src/gr-details-page.c     |    2 ++
 src/gr-edit-page.c        |   15 ++++++++++++---
 src/gr-edit-page.ui       |   30 ++++++++++++++++++++++--------
 src/gr-recipe-formatter.c |   14 ++++++++++++--
 src/gr-recipe-formatter.h |    1 +
 6 files changed, 53 insertions(+), 16 deletions(-)
---
diff --git a/src/gr-cooking-view.c b/src/gr-cooking-view.c
index 1f671e7..c4830dd 100644
--- a/src/gr-cooking-view.c
+++ b/src/gr-cooking-view.c
@@ -142,6 +142,7 @@ step_data_new (int         num,
                int         n_steps,
                const char *text,
                guint64     duration,
+               const char *title,
                int         image,
                GrCookingView *view)
 {
@@ -158,7 +159,7 @@ step_data_new (int         num,
 
                 name = g_strdup_printf (_("Step %d"), num + 1);
                 d->timer = g_object_new (GR_TYPE_TIMER,
-                                         "name", name,
+                                         "name", title ? title : name,
                                          "duration", duration,
                                          "active", FALSE,
                                          NULL);
@@ -194,7 +195,7 @@ step_data_new (int         num,
                                            "size", 32,
                                            "visible", TRUE,
                                            NULL);
-                        label = gtk_label_new (name);
+                        label = gtk_label_new (gr_timer_get_name (d->timer));
                         gtk_label_set_xalign (GTK_LABEL (label), 0.0);
                         gtk_widget_show (label);
                         gtk_style_context_add_class (gtk_widget_get_style_context (label), 
"cooking-heading");
@@ -571,7 +572,7 @@ setup_steps (GrCookingView *view)
                 StepData *data;
 
                 step = g_ptr_array_index (steps, i);
-                data = step_data_new (i, steps->len, step->text, step->timer, step->image, view);
+                data = step_data_new (i, steps->len, step->text, step->timer, step->title, step->image, 
view);
                 g_ptr_array_add (view->steps, data);
 
         }
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 1fcad25..4b11bb5 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -566,6 +566,8 @@ process_instructions (const char *instructions)
                         str = g_strdup_printf ("%02d∶%02d∶%02d", hours, minutes, seconds);
                         g_string_append (s, "<a href=\"timer\" title=\"");
                         g_string_append_printf (s, _("Timer: %s"), str);
+                        if (step->title)
+                                g_string_append_printf (s, "\n%s", step->title);
                         g_string_append (s, "\">⏰</a>");
                 }
                 else if (step->image != -1) {
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 21664bb..0ff8386 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -118,6 +118,7 @@ struct _GrEditPage
         GtkWidget *temperature_spin;
         GtkWidget *celsius_button;
         GtkWidget *timer_spin;
+        GtkWidget *timer_title;
         GtkWidget *preview_stack;
 
         GrRecipeSearch *search;
@@ -1174,15 +1175,22 @@ time_spin_activate (GtkEntry *entry, GrEditPage *self)
         double minutes;
         double seconds;
         g_autofree char *text = NULL;
+        const char *title;
 
-        gtk_spin_button_update (GTK_SPIN_BUTTON (entry));
+        gtk_spin_button_update (GTK_SPIN_BUTTON (self->timer_spin));
 
-        adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (entry));
+        adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (self->timer_spin));
         hours = gtk_adjustment_get_value (adjustment) / 3600.0;
         minutes = (hours - floor (hours)) * 60.0;
         seconds = (minutes - floor (minutes)) * 60.0;
 
-        text = g_strdup_printf ("[timer:%02.0f:%02.0f:%02.0f]", floor (hours), floor (minutes), floor 
(seconds + 0.5));
+        title = gtk_entry_get_text (GTK_ENTRY (self->timer_title));
+
+        if (title && title[0])
+                text = g_strdup_printf ("[timer:%02.0f:%02.0f:%02.0f,%s]", floor (hours), floor (minutes), 
floor (seconds + 0.5), title);
+        else
+                text = g_strdup_printf ("[timer:%02.0f:%02.0f:%02.0f]", floor (hours), floor (minutes), 
floor (seconds + 0.5));
+
         add_tag_to_step (self, text);
 
         gtk_popover_popdown (GTK_POPOVER (self->timer_popover));
@@ -1464,6 +1472,7 @@ gr_edit_page_class_init (GrEditPageClass *klass)
         gtk_widget_class_bind_template_child (widget_class, GrEditPage, temperature_spin);
         gtk_widget_class_bind_template_child (widget_class, GrEditPage, celsius_button);
         gtk_widget_class_bind_template_child (widget_class, GrEditPage, timer_spin);
+        gtk_widget_class_bind_template_child (widget_class, GrEditPage, timer_title);
         gtk_widget_class_bind_template_child (widget_class, GrEditPage, preview_stack);
         gtk_widget_class_bind_template_child (widget_class, GrEditPage, cooking_view);
 
diff --git a/src/gr-edit-page.ui b/src/gr-edit-page.ui
index 90fb7b0..57409ee 100644
--- a/src/gr-edit-page.ui
+++ b/src/gr-edit-page.ui
@@ -1022,14 +1022,28 @@
     <property name="relative-to">timer_button</property>
     <property name="constrain-to">none</property>
     <child>
-      <object class="GtkSpinButton" id="timer_spin">
+      <object class="GtkBox">
         <property name="visible">1</property>
+        <property name="orientation">vertical</property>
         <property name="margin">12</property>
-        <property name="adjustment">time_adjustment</property>
-        <property name="width-chars">8</property>
-        <signal name="input" handler="time_spin_input"/>
-        <signal name="output" handler="time_spin_output"/>
-        <signal name="activate" handler="time_spin_activate"/>
+        <child>
+          <object class="GtkSpinButton" id="timer_spin">
+            <property name="visible">1</property>
+            <property name="adjustment">time_adjustment</property>
+            <property name="width-chars">8</property>
+            <signal name="input" handler="time_spin_input"/>
+            <signal name="output" handler="time_spin_output"/>
+            <signal name="activate" handler="time_spin_activate"/>
+          </object>
+        </child>
+        <child>
+          <object class="GtkEntry" id="timer_title">
+            <property name="visible">1</property>
+            <property name="placeholder-text" translatable="yes">Title…</property>
+            <property name="width-chars">12</property>
+            <signal name="activate" handler="time_spin_activate"/>
+          </object>
+        </child>
       </object>
     </child>
   </object>
@@ -1094,7 +1108,7 @@
         <property name="visible">1</property>
         <property name="margin">12</property>
         <property name="margin-top">0</property>
-        <property name="column-homogeneous">1</property>
+        <property name="column-spacing">20</property>
         <child>
           <object class="GtkLabel">
             <property name="visible">1</property>
@@ -1150,7 +1164,7 @@
           <object class="GtkLabel">
             <property name="visible">1</property>
             <property name="xalign">0</property>
-            <property name="label">[timer:00:30]</property>
+            <property name="label">[timer:00:30]  [timer:01:15,Preheat oven]</property>
           </object>
           <packing>
             <property name="left-attach">1</property>
diff --git a/src/gr-recipe-formatter.c b/src/gr-recipe-formatter.c
index 3df6210..374fa17 100644
--- a/src/gr-recipe-formatter.c
+++ b/src/gr-recipe-formatter.c
@@ -100,7 +100,8 @@ gr_recipe_format (GrRecipe *recipe)
 static GrRecipeStep *
 recipe_step_new (const char *text,
                  int         image,
-                 guint64     timer)
+                 guint64     timer,
+                 const char *title)
 {
         GrRecipeStep *step;
 
@@ -108,6 +109,7 @@ recipe_step_new (const char *text,
         step->text = g_strdup (text);
         step->image = image;
         step->timer = timer;
+        step->title = g_strdup (title);
 
         return step;
 }
@@ -117,6 +119,7 @@ recipe_step_free (gpointer data)
 {
         GrRecipeStep *d = data;
         g_free (d->text);
+        g_free (d->title);
         g_free (d);
 }
 
@@ -136,6 +139,7 @@ gr_recipe_parse_instructions (const char *instructions,
                 const char *p, *q;
                 int image = -1;
                 guint64 timer = 0;
+                g_autofree char *title = NULL;
                 g_autofree char *step = NULL;
 
                 step = g_strdup (steps[i]);
@@ -186,12 +190,18 @@ gr_recipe_parse_instructions (const char *instructions,
                 p = strstr (step, "[timer:");
                 if (p) {
                         g_autofree char *s = NULL;
+                        char *r;
                         g_auto(GStrv) strv = NULL;
                         g_autofree char *prefix = NULL;
                         char *tmp;
 
                         q = strstr (p, "]");
                         s = strndup (p + strlen ("[timer:"), q - (p + strlen ("[timer:")));
+                        r = strchr (s, ',');
+                        if (r) {
+                                title = g_strdup (r + 1);
+                                *r = '\0';
+                        }
                         strv = g_strsplit (s, ":", -1);
                         if (g_strv_length (strv) == 2) {
                                 timer = G_TIME_SPAN_MINUTE * atoi (strv[0]) +
@@ -213,7 +223,7 @@ gr_recipe_parse_instructions (const char *instructions,
                         step = tmp;
                 }
 
-                g_ptr_array_add (step_array, recipe_step_new (step, image, timer));
+                g_ptr_array_add (step_array, recipe_step_new (step, image, timer, title));
         }
 
         return step_array;
diff --git a/src/gr-recipe-formatter.h b/src/gr-recipe-formatter.h
index 9e0e7d8..22425bd 100644
--- a/src/gr-recipe-formatter.h
+++ b/src/gr-recipe-formatter.h
@@ -31,6 +31,7 @@ typedef struct {
         char *text;
         int image;
         guint64 timer;
+        char *title;
 } GrRecipeStep;
 
 GPtrArray *gr_recipe_parse_instructions (const char *instructions,


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