[recipes] Add a shopping list notification
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add a shopping list notification
- Date: Sat, 28 Jan 2017 18:05:32 +0000 (UTC)
commit 91cd6b5ad96feb1bf52149bcb564717bb333f993
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jan 28 19:04:06 2017 +0100
Add a shopping list notification
Show an in-app notification when a recipe is added to the
shopping list. This is following the latest mockups for
this feature.
src/gr-details-page.c | 4 +++
src/gr-window.c | 44 ++++++++++++++++++++++++++++++++++++++
src/gr-window.h | 2 +
src/gr-window.ui | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 106 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 0cda500..6012bd6 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -517,9 +517,13 @@ static void
shop_it (GrDetailsPage *page)
{
GrRecipeStore *store;
+ GtkWidget *window;
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
gr_recipe_store_add_to_shopping (store, page->recipe);
+
+ window = gtk_widget_get_ancestor (GTK_WIDGET (page), GTK_TYPE_APPLICATION_WINDOW);
+ gr_window_offer_shopping (GR_WINDOW (window));
}
static gboolean save_notes (gpointer data);
diff --git a/src/gr-window.c b/src/gr-window.c
index 9309c6a..dbdaf85 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -64,6 +64,8 @@ struct _GrWindow
GtkWidget *undo_label;
GrRecipe *undo_recipe;
guint undo_timeout_id;
+ GtkWidget *shopping_added_revealer;
+ guint shopping_timeout_id;
GrRecipeImporter *importer;
@@ -383,6 +385,10 @@ gr_window_finalize (GObject *object)
g_source_remove (self->undo_timeout_id);
self->undo_timeout_id = 0;
}
+ if (self->shopping_timeout_id) {
+ g_source_remove (self->shopping_timeout_id);
+ self->shopping_timeout_id = 0;
+ }
G_OBJECT_CLASS (gr_window_parent_class)->finalize (object);
}
@@ -441,6 +447,41 @@ gr_window_offer_undelete (GrWindow *window,
}
static void
+close_shopping_added (GrWindow *window)
+{
+ if (window->shopping_timeout_id) {
+ g_source_remove (window->shopping_timeout_id);
+ window->shopping_timeout_id = 0;
+ }
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->shopping_added_revealer), FALSE);
+}
+
+static gboolean
+shopping_timeout (gpointer data)
+{
+ GrWindow *window = data;
+
+ close_shopping_added (window);
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+do_shopping_list (GrWindow *window)
+{
+ close_shopping_added (window);
+ gr_window_show_shopping (window);
+}
+
+void
+gr_window_offer_shopping (GrWindow *window)
+{
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->shopping_added_revealer), TRUE);
+ window->shopping_timeout_id = g_timeout_add_seconds (10, shopping_timeout, window);
+}
+
+static void
shopping_title_changed (GrWindow *window)
{
const char *page;
@@ -485,6 +526,7 @@ gr_window_class_init (GrWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrWindow, image_page);
gtk_widget_class_bind_template_child (widget_class, GrWindow, undo_revealer);
gtk_widget_class_bind_template_child (widget_class, GrWindow, undo_label);
+ gtk_widget_class_bind_template_child (widget_class, GrWindow, shopping_added_revealer);
gtk_widget_class_bind_template_callback (widget_class, new_recipe);
gtk_widget_class_bind_template_callback (widget_class, go_back);
@@ -499,6 +541,8 @@ gr_window_class_init (GrWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, window_mapped_handler);
gtk_widget_class_bind_template_callback (widget_class, do_undo);
gtk_widget_class_bind_template_callback (widget_class, close_undo);
+ gtk_widget_class_bind_template_callback (widget_class, do_shopping_list);
+ gtk_widget_class_bind_template_callback (widget_class, close_shopping_added);
gtk_widget_class_bind_template_callback (widget_class, shopping_title_changed);
}
diff --git a/src/gr-window.h b/src/gr-window.h
index 2ea5a1b..9e65768 100644
--- a/src/gr-window.h
+++ b/src/gr-window.h
@@ -69,4 +69,6 @@ void gr_window_show_image (GrWindow *window,
GArray *images,
int index);
+void gr_window_offer_shopping (GrWindow *window);
+
G_END_DECLS
diff --git a/src/gr-window.ui b/src/gr-window.ui
index 5f80c8c..bda8de1 100644
--- a/src/gr-window.ui
+++ b/src/gr-window.ui
@@ -166,6 +166,62 @@
<object class="GtkOverlay">
<property name="visible">1</property>
<child type="overlay">
+ <object class="GtkRevealer" id="shopping_added_revealer">
+ <property name="visible">1</property>
+ <property name="halign">center</property>
+ <property name="valign">start</property>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">1</property>
+ <style>
+ <class name="app-notification"/>
+ </style>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <property name="spacing">20</property>
+ <property name="margin">10</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ <property name="hexpand">1</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Ingredients to buy added.</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">1</property>
+ <property name="focus-on-click">0</property>
+ <property name="label" translatable="yes">View Shopping List</property>
+ <signal name="clicked" handler="do_shopping_list" swapped="yes"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">1</property>
+ <property name="focus-on-click">0</property>
+ <property name="relief">none</property>
+ <signal name="clicked" handler="close_shopping_added" swapped="yes"/>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">1</property>
+ <property name="icon-name">window-close-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="overlay">
<object class="GtkRevealer" id="undo_revealer">
<property name="visible">1</property>
<property name="halign">center</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]