[recipes] Notify the user when they edit a contributed recipe
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Notify the user when they edit a contributed recipe
- Date: Sun, 19 Feb 2017 16:52:34 +0000 (UTC)
commit 6019408b6754fbac66144f35fd8e687acdd4d7dc
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Feb 19 11:08:10 2017 -0500
Notify the user when they edit a contributed recipe
Remind them to contribute and update.
src/gr-window.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gr-window.h | 2 +
src/gr-window.ui | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-window.c b/src/gr-window.c
index e7dd11a..1358f67 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -70,6 +70,10 @@ struct _GrWindow
GtkWidget *undo_label;
GrRecipe *undo_recipe;
guint undo_timeout_id;
+ GtkWidget *remind_revealer;
+ GtkWidget *remind_label;
+ GrRecipe *remind_recipe;
+ guint remind_timeout_id;
GtkWidget *shopping_added_revealer;
guint shopping_timeout_id;
@@ -190,6 +194,10 @@ add_recipe (GrWindow *window)
recipe = gr_edit_page_get_recipe (GR_EDIT_PAGE (window->edit_page));
gr_window_show_recipe (window, recipe);
+
+ if (gr_recipe_is_contributed (recipe))
+ gr_window_offer_contribute (window, recipe);
+
gr_edit_page_clear (GR_EDIT_PAGE (window->edit_page));
}
}
@@ -430,10 +438,16 @@ gr_window_finalize (GObject *object)
g_clear_object (&self->importer);
+ g_clear_object (&self->undo_recipe);
if (self->undo_timeout_id) {
g_source_remove (self->undo_timeout_id);
self->undo_timeout_id = 0;
}
+ g_clear_object (&self->remind_recipe);
+ if (self->remind_timeout_id) {
+ g_source_remove (self->remind_timeout_id);
+ self->remind_timeout_id = 0;
+ }
if (self->shopping_timeout_id) {
g_source_remove (self->shopping_timeout_id);
self->shopping_timeout_id = 0;
@@ -498,6 +512,54 @@ gr_window_offer_undelete (GrWindow *window,
}
static void
+close_remind (GrWindow *window)
+{
+ if (window->remind_timeout_id) {
+ g_source_remove (window->remind_timeout_id);
+ window->remind_timeout_id = 0;
+ }
+
+ g_clear_object (&window->remind_recipe);
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->remind_revealer), FALSE);
+}
+
+static void
+do_remind (GrWindow *window)
+{
+ g_autoptr(GrRecipe) recipe = NULL;
+
+ recipe = g_object_ref (window->remind_recipe);
+
+ close_remind (window);
+ gr_window_show_recipe (window, recipe);
+}
+
+static gboolean
+remind_timeout (gpointer data)
+{
+ GrWindow *window = data;
+
+ close_remind (window);
+
+ return G_SOURCE_REMOVE;
+}
+
+void
+gr_window_offer_contribute (GrWindow *window,
+ GrRecipe *recipe)
+{
+ g_autofree char *tmp = NULL;
+
+ g_set_object (&window->remind_recipe, recipe);
+ tmp = g_strdup_printf (_("You updated your contributed ā%sā recipe. Send an update?"),
gr_recipe_get_name (recipe));
+ gtk_label_set_label (GTK_LABEL (window->remind_label), tmp);
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->remind_revealer), TRUE);
+ window->remind_timeout_id = g_timeout_add_seconds (10, remind_timeout, window);
+}
+
+static void
close_shopping_added (GrWindow *window)
{
if (window->shopping_timeout_id) {
@@ -579,6 +641,8 @@ gr_window_class_init (GrWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrWindow, cooking_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, remind_revealer);
+ gtk_widget_class_bind_template_child (widget_class, GrWindow, remind_label);
gtk_widget_class_bind_template_child (widget_class, GrWindow, shopping_added_revealer);
gtk_widget_class_bind_template_callback (widget_class, new_recipe);
@@ -596,6 +660,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_remind);
+ gtk_widget_class_bind_template_callback (widget_class, close_remind);
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 ae7c4e4..e0d895c 100644
--- a/src/gr-window.h
+++ b/src/gr-window.h
@@ -65,6 +65,8 @@ void gr_window_show_search_by_ingredients (GrWindow *window,
const char *ingredient);
void gr_window_offer_undelete (GrWindow *window,
GrRecipe *recipe);
+void gr_window_offer_contribute (GrWindow *window,
+ GrRecipe *recipe);
void gr_window_set_fullscreen (GrWindow *window,
gboolean fullscreen);
diff --git a/src/gr-window.ui b/src/gr-window.ui
index 5d5da7c..6415b4d 100644
--- a/src/gr-window.ui
+++ b/src/gr-window.ui
@@ -283,6 +283,66 @@
</child>
</object>
</child>
+ <child type="overlay">
+ <object class="GtkRevealer" id="remind_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">10</property>
+ <child>
+ <object class="GtkLabel" id="remind_label">
+ <property name="visible">1</property>
+ <property name="hexpand">1</property>
+ <property name="wrap">1</property>
+ <property name="width-chars">40</property>
+ <property name="max-width-chars">40</property>
+ <property name="halign">start</property>
+ <style>
+ <class name="notification-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">1</property>
+ <property name="focus-on-click">0</property>
+ <property name="label" translatable="yes">Update</property>
+ <signal name="clicked" handler="do_remind" 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_remind" 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>
<object class="GtkStack" id="main_stack">
<property name="visible">1</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]