[recipes/mini-timer: 5/6] Add a box on the cooking page for timers
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/mini-timer: 5/6] Add a box on the cooking page for timers
- Date: Thu, 23 Feb 2017 04:05:57 +0000 (UTC)
commit c08f40447ec3247f86e5d7b70668e9cf59904ae0
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Feb 22 22:17:14 2017 -0500
Add a box on the cooking page for timers
We populate this box with small widgets indicating
the currently running timers.
src/gr-cooking-page.c | 6 ++++++
src/gr-cooking-page.ui | 10 ++++++++++
src/gr-cooking-view.c | 41 ++++++++++++++++++++++++++++++++++++++---
src/gr-cooking-view.h | 2 ++
4 files changed, 56 insertions(+), 3 deletions(-)
---
diff --git a/src/gr-cooking-page.c b/src/gr-cooking-page.c
index edf6eec..74e7175 100644
--- a/src/gr-cooking-page.c
+++ b/src/gr-cooking-page.c
@@ -47,6 +47,7 @@ struct _GrCookingPage
GtkWidget *done_button;
GtkWidget *notification_revealer;
GtkWidget *notification_label;
+ GtkWidget *mini_timer_box;
GrRecipe *recipe;
@@ -86,6 +87,8 @@ gr_cooking_page_init (GrCookingPage *self)
gtk_widget_add_events (GTK_WIDGET (self->event_box), GDK_POINTER_MOTION_MASK);
gtk_widget_add_events (GTK_WIDGET (self->event_box), GDK_BUTTON_PRESS_MASK);
+
+ gr_cooking_view_set_timer_box (GR_COOKING_VIEW (self->cooking_view), self->mini_timer_box);
}
static int
@@ -453,6 +456,7 @@ gr_cooking_page_class_init (GrCookingPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrCookingPage, done_button);
gtk_widget_class_bind_template_child (widget_class, GrCookingPage, notification_revealer);
gtk_widget_class_bind_template_child (widget_class, GrCookingPage, notification_label);
+ gtk_widget_class_bind_template_child (widget_class, GrCookingPage, mini_timer_box);
gtk_widget_class_bind_template_callback (widget_class, prev_step);
gtk_widget_class_bind_template_callback (widget_class, next_step);
@@ -474,6 +478,8 @@ gr_cooking_page_set_recipe (GrCookingPage *page,
g_object_get (recipe, "images", &images, NULL);
instructions = gr_recipe_get_translated_instructions (recipe);
+ container_remove_all (GTK_CONTAINER (page->mini_timer_box));
+
gr_cooking_view_set_images (GR_COOKING_VIEW (page->cooking_view), images, 0);
gr_cooking_view_set_instructions (GR_COOKING_VIEW (page->cooking_view), instructions);
}
diff --git a/src/gr-cooking-page.ui b/src/gr-cooking-page.ui
index 31bb491..a645770 100644
--- a/src/gr-cooking-page.ui
+++ b/src/gr-cooking-page.ui
@@ -8,6 +8,16 @@
<object class="GtkOverlay">
<property name="visible">1</property>
<child type="overlay">
+ <object class="GtkBox" id="mini_timer_box">
+ <property name="visible">1</property>
+ <property name="orientation">vertical</property>
+ <property name="halign">start</property>
+ <property name="valign">start</property>
+ <property name="margin">10</property>
+ <property name="spacing">10</property>
+ </object>
+ </child>
+ <child type="overlay">
<object class="GtkRevealer" id="prev_revealer">
<property name="visible">1</property>
<property name="halign">start</property>
diff --git a/src/gr-cooking-view.c b/src/gr-cooking-view.c
index 4ae5c42..1eb6c21 100644
--- a/src/gr-cooking-view.c
+++ b/src/gr-cooking-view.c
@@ -36,6 +36,7 @@
#include "gr-timer.h"
#include "gr-window.h"
#include "gr-cooking-page.h"
+#include "gr-mini-timer-widget.h"
typedef struct
{
@@ -43,6 +44,7 @@ typedef struct
char *heading;
char *label;
GrTimer *timer;
+ GtkWidget *mini_timer;
gulong handler;
guint64 duration;
int image;
@@ -108,6 +110,7 @@ struct _GrCookingView
GtkWidget *cooking_stack;
GtkWidget *cooking_timer;
GtkWidget *text_box;
+ GtkWidget *timer_box;
GArray *images;
char *instructions;
@@ -283,6 +286,8 @@ step_timer_complete (GrTimer *timer, StepData *step)
else
send_complete_notification (step);
+ gtk_widget_destroy (step->mini_timer);
+
play_complete_sound (step);
}
@@ -434,11 +439,34 @@ setup_steps (GrCookingView *view)
g_ptr_array_set_size (view->steps, 0);
for (i = 0; i < steps->len; i++) {
GrRecipeStep *step;
+ StepData *data;
step = g_ptr_array_index (steps, i);
-
- g_ptr_array_add (view->steps,
- step_data_new (i + 1, steps->len, step->text, step->timer, step->image,
view));
+ data = step_data_new (i + 1, steps->len, step->text, step->timer, step->image, view);
+ g_ptr_array_add (view->steps, data);
+
+ if (view->timer_box && data->timer) {
+ GtkWidget *box;
+ GtkWidget *tw;
+ GtkWidget *label;
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ tw = g_object_new (GR_TYPE_MINI_TIMER_WIDGET,
+ "timer", data->timer,
+ "visible", TRUE,
+ NULL);
+ gtk_style_context_add_class (gtk_widget_get_style_context (tw), "cooking-heading");
+ label = gtk_label_new (gr_timer_get_name (data->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");
+
+ gtk_container_add (GTK_CONTAINER (box), tw);
+ gtk_container_add (GTK_CONTAINER (box), label);
+ gtk_container_add (GTK_CONTAINER (view->timer_box), box);
+ g_signal_connect_swapped (data->timer, "notify::active", G_CALLBACK
(gtk_widget_show), box);
+ data->mini_timer = box;
+ }
}
}
@@ -505,3 +533,10 @@ gr_cooking_view_prev_step (GrCookingView *view)
{
set_step (view, view->step - 1);
}
+
+void
+gr_cooking_view_set_timer_box (GrCookingView *view,
+ GtkWidget *box)
+{
+ view->timer_box = box;
+}
diff --git a/src/gr-cooking-view.h b/src/gr-cooking-view.h
index ad22202..a974800 100644
--- a/src/gr-cooking-view.h
+++ b/src/gr-cooking-view.h
@@ -43,6 +43,8 @@ void gr_cooking_view_set_step (GrCookingView *view,
int step);
void gr_cooking_view_next_step (GrCookingView *view);
void gr_cooking_view_prev_step (GrCookingView *view);
+void gr_cooking_view_set_timer_box (GrCookingView *view,
+ GtkWidget *box);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]