[recipes] details: Remove the original cooking mode
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] details: Remove the original cooking mode
- Date: Sat, 4 Feb 2017 05:10:37 +0000 (UTC)
commit ed26ad61baf894cfe2f2a2ac481d2046a6605919
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 3 09:09:04 2017 +0100
details: Remove the original cooking mode
We have a separate cooking page for this now, so all this code
is not used anymore.
src/gr-details-page.c | 392 ------------------------------------------------
src/gr-details-page.h | 4 -
src/gr-details-page.ui | 168 ---------------------
3 files changed, 0 insertions(+), 564 deletions(-)
---
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 1a80f6d..09af52a 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -42,71 +42,6 @@
#include "gr-recipe-exporter.h"
-typedef struct
-{
- gboolean ingredients;
- gboolean preheat;
- gboolean instructions;
- GrTimer *timer;
-} CookingData;
-
-static void
-timer_complete (GrTimer *timer)
-{
- GApplication *app;
- g_autoptr(GNotification) notification = NULL;
- g_autofree char *body = NULL;
- g_autofree char *action = NULL;
- GrRecipeStore *store;
- g_autoptr(GrRecipe) recipe = NULL;
- const char *id;
- const char *name;
-
- app = g_application_get_default ();
-
- id = gr_timer_get_name (timer);
-
- store = gr_app_get_recipe_store (GR_APP (app));
- recipe = gr_recipe_store_get_recipe (store, id);
- name = gr_recipe_get_translated_name (recipe);
-
- body = g_strdup_printf (_("Your cooking timer for ā%sā has expired."), name);
-
- notification = g_notification_new (_("Time is up!"));
- g_notification_set_body (notification, body);
- action = g_strdup_printf ("app.timer-expired::%s", id);
- g_notification_set_default_action (notification, action);
-
- g_application_send_notification (app, "timer", notification);
-
- gr_recipe_store_add_cooked (store, recipe);
-}
-
-static CookingData *
-cooking_data_new (const char *id)
-{
- CookingData *cd;
-
- cd = g_new (CookingData, 1);
- cd->ingredients = FALSE;
- cd->preheat = FALSE;
- cd->instructions = FALSE;
- cd->timer = gr_timer_new (id);
-
- g_signal_connect (cd->timer, "complete", G_CALLBACK (timer_complete), NULL);
-
- return cd;
-}
-
-static void
-cooking_data_free (gpointer data)
-{
- CookingData *cd = data;
-
- g_object_unref (cd->timer);
- g_free (cd);
-}
-
struct _GrDetailsPage
{
GtkBox parent_instance;
@@ -114,7 +49,6 @@ struct _GrDetailsPage
GrRecipe *recipe;
GrChef *chef;
GrIngredientsList *ingredients;
- GHashTable *cooking;
GrRecipePrinter *printer;
GrRecipeExporter *exporter;
@@ -130,18 +64,7 @@ struct _GrDetailsPage
GtkWidget *dairy_warning;
GtkWidget *ingredients_box;
GtkWidget *instructions_label;
- GtkWidget *cooking_revealer;
- GtkWidget *ingredients_check;
- GtkWidget *preheat_check;
- GtkWidget *instructions_check;
- GtkWidget *timer;
- GtkWidget *timer_stack;
- GtkWidget *timer_popover;
- GtkWidget *time_spin;
- GtkWidget *start_button;
GtkWidget *favorite_button;
- GtkWidget *duration_stack;
- GtkWidget *remaining_time_label;
GtkWidget *chef_label;
GtkWidget *edit_button;
GtkWidget *delete_button;
@@ -154,7 +77,6 @@ struct _GrDetailsPage
GtkWidget *error_revealer;
guint save_timeout;
- guint inhibit_cookie;
char *uri;
};
@@ -164,106 +86,6 @@ G_DEFINE_TYPE (GrDetailsPage, gr_details_page, GTK_TYPE_BOX)
static void connect_store_signals (GrDetailsPage *page);
static void
-timer_active_changed (GrTimer *timer,
- GParamSpec *pspec,
- GrDetailsPage *page)
-{
- if (strcmp (gr_timer_get_name (timer), gr_recipe_get_id (page->recipe)) != 0)
- return;
-
- if (gr_timer_get_active (timer)) {
- gtk_stack_set_visible_child_name (GTK_STACK (page->timer_stack), "timer");
- gtk_stack_set_visible_child_name (GTK_STACK (page->duration_stack), "stop");
- }
- else {
- gtk_stack_set_visible_child_name (GTK_STACK (page->timer_stack), "icon");
- gtk_stack_set_visible_child_name (GTK_STACK (page->duration_stack), "start");
- }
-}
-
-static void
-timer_remaining_changed (GrTimer *timer,
- GParamSpec *pspec,
- GrDetailsPage *page)
-{
- guint64 remaining;
- guint hours, minutes, seconds;
- g_autofree char *buf = NULL;
-
- if (strcmp (gr_timer_get_name (timer), gr_recipe_get_id (page->recipe)) != 0)
- return;
-
- remaining = gr_timer_get_remaining (timer);
-
- seconds = remaining / (1000 * 1000);
-
- hours = seconds / (60 * 60);
- seconds -= hours * 60 * 60;
- minutes = seconds / 60;
- seconds -= minutes * 60;
-
- buf = g_strdup_printf ("%02d:%02d:%02d", hours, minutes, seconds);
- gtk_label_set_label (GTK_LABEL (page->remaining_time_label), buf);
-}
-
-static void
-set_cooking (GrDetailsPage *page,
- gboolean cooking)
-{
- const char *id;
- CookingData *cd;
- GtkWidget *window;
- GtkApplication *app;
-
- window = gtk_widget_get_ancestor (GTK_WIDGET (page), GTK_TYPE_APPLICATION_WINDOW);
- app = gtk_window_get_application (GTK_WINDOW (window));
-
- id = gr_recipe_get_id (page->recipe);
-
- cd = g_hash_table_lookup (page->cooking, id);
-
- if (cooking) {
- if (!cd) {
- cd = cooking_data_new (id);
- g_hash_table_insert (page->cooking, g_strdup (id), cd);
- }
-
- g_object_set (page->ingredients_check, "active", cd->ingredients, NULL);
- g_object_set (page->preheat_check, "active", cd->preheat, NULL);
- g_object_set (page->instructions_check, "active", cd->instructions, NULL);
- g_object_set (page->timer, "timer", cd->timer, NULL);
- g_signal_connect (cd->timer, "notify::active", G_CALLBACK (timer_active_changed), page);
- timer_active_changed (cd->timer, NULL, page);
- g_signal_connect (cd->timer, "notify::remaining", G_CALLBACK (timer_remaining_changed),
page);
- timer_remaining_changed (cd->timer, NULL, page);
- gtk_revealer_set_reveal_child (GTK_REVEALER (page->cooking_revealer), TRUE);
-
- if (page->inhibit_cookie == 0) {
- page->inhibit_cookie = gtk_application_inhibit (app,
- GTK_WINDOW (window),
- GTK_APPLICATION_INHIBIT_SUSPEND |
- GTK_APPLICATION_INHIBIT_IDLE,
- _("Cooking"));
- }
- }
- else {
- if (cd) {
- g_signal_handlers_disconnect_by_func (cd->timer, G_CALLBACK (timer_active_changed),
page);
- g_signal_handlers_disconnect_by_func (cd->timer, G_CALLBACK
(timer_remaining_changed), page);
- g_hash_table_remove (page->cooking, id);
- }
-
- g_object_set (page->timer, "timer", NULL, NULL);
- gtk_revealer_set_reveal_child (GTK_REVEALER (page->cooking_revealer), FALSE);
-
- if (page->inhibit_cookie != 0) {
- gtk_application_uninhibit (app, page->inhibit_cookie);
- page->inhibit_cookie = 0;
- }
- }
-}
-
-static void
delete_recipe (GrDetailsPage *page)
{
GrRecipeStore *store;
@@ -345,163 +167,6 @@ serves_value_changed (GrDetailsPage *page)
}
static void
-start_or_stop_timer (GrDetailsPage *page)
-{
- const char *id;
- CookingData *cd;
-
- id = gr_recipe_get_id (page->recipe);
-
- cd = g_hash_table_lookup (page->cooking, id);
-
- g_assert (cd && cd->timer);
-
- if (gr_timer_get_active (cd->timer)) {
- g_object_set (cd->timer, "active", FALSE, NULL);
- }
- else {
- int seconds;
-
- seconds = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (page->time_spin));
- g_object_set (cd->timer,
- "duration", seconds * 1000 * 1000,
- "active", TRUE,
- NULL);
- }
-
- gtk_popover_popdown (GTK_POPOVER (page->timer_popover));
-}
-
-static int
-time_spin_input (GtkSpinButton *spin_button,
- double *new_val)
-{
- const char *text;
- gboolean found = FALSE;
-
- text = gtk_entry_get_text (GTK_ENTRY (spin_button));
- if (!strchr (text, ':')) {
- g_auto(GStrv) str = NULL;
- int num;
- char *endn;
-
- str = g_strsplit (text, " ", 2);
- num = strtol (str[0], &endn, 10);
- if (!*endn) {
- if (str[1] == NULL) {
- *new_val = num; /* minutes */
- found = TRUE;
- }
- else if (strcmp (str[1], _("hour")) == 0 ||
- strcmp (str[1], _("hours")) == 0 ||
- strcmp (str[1], C_("hour abbreviation", "h")) == 0) {
- *new_val = num * 3600; /* hours */
- found = TRUE;
- }
- else if (strcmp (str[1], _("minute")) == 0 ||
- strcmp (str[1], _("minutes")) == 0 ||
- strcmp (str[1], C_("minute abbreviation", "min")) == 0 ||
- strcmp (str[1], C_("minute abbreviation", "m")) == 0) {
- *new_val = num * 60;
- found = TRUE;
- }
- else if (strcmp (str[1], _("second")) == 0 ||
- strcmp (str[1], _("seconds")) == 0 ||
- strcmp (str[1], C_("second abbreviation", "sec")) == 0 ||
- strcmp (str[1], C_("second abbreviation", "s")) == 0) {
- *new_val = num;
- found = TRUE;
- }
- }
- }
- else {
- g_auto(GStrv) str = NULL;
- int hours;
- int minutes;
- int seconds;
- char *endh;
- char *endm;
- char *ends;
-
- str = g_strsplit (text, ":", 3);
-
- if (g_strv_length (str) == 3) {
- hours = strtol (str[0], &endh,10);
- minutes = strtol (str[1], &endm, 10);
- seconds = strtol (str[2], &ends, 10);
- if (!*endh && !*endm && !*ends &&
- 0 <= hours && hours < 24 &&
- 0 <= minutes && minutes < 60 &&
- 0 <= seconds && seconds < 60) {
- *new_val = (hours * 60 + minutes) * 60 + seconds;
- found = TRUE;
- }
- }
- else if (g_strv_length (str) == 2) {
- hours = strtol (str[0], &endh, 10);
- minutes = strtol (str[1], &endm, 10);
- if (!*endh && !*endm &&
- 0 <= hours && hours < 24 &&
- 0 <= minutes && minutes < 60) {
- *new_val = (hours * 60 + minutes) * 60;
- found = TRUE;
- }
- }
- }
-
- if (!found) {
- *new_val = 0.0;
- return GTK_INPUT_ERROR;
- }
-
- return TRUE;
-}
-
-static int
-time_spin_output (GtkSpinButton *spin_button)
-{
- GtkAdjustment *adjustment;
- char *buf;
- double hours;
- double minutes;
- double seconds;
-
- adjustment = gtk_spin_button_get_adjustment (spin_button);
- hours = gtk_adjustment_get_value (adjustment) / 3600.0;
- minutes = (hours - floor (hours)) * 60.0;
- seconds = (minutes - floor (minutes)) * 60.0;
- buf = g_strdup_printf ("%02.0f:%02.0f:%02.0f", floor (hours), floor (minutes), floor (seconds +
0.5));
- if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
- gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
- g_free (buf);
-
- return TRUE;
-}
-
-static void
-check_clicked (GtkWidget *button,
- GrDetailsPage *page)
-{
- CookingData *cd;
- const char *id;
- gboolean active;
-
- id = gr_recipe_get_id (page->recipe);
- cd = g_hash_table_lookup (page->cooking, id);
-
- g_assert (cd);
-
- g_object_get (button, "active", &active, NULL);
-
- if (button == page->ingredients_check)
- cd->ingredients = active;
- else if (button == page->preheat_check)
- cd->preheat = active;
- else if (button == page->instructions_check)
- cd->instructions = active;
-}
-
-static void
cook_it_later (GrDetailsPage *page)
{
GrRecipeStore *store;
@@ -544,27 +209,12 @@ details_page_finalize (GObject *object)
g_clear_object (&self->ingredients);
g_clear_object (&self->printer);
g_clear_object (&self->exporter);
- g_clear_pointer (&self->cooking, g_hash_table_unref);
g_clear_pointer (&self->uri, g_free);
G_OBJECT_CLASS (gr_details_page_parent_class)->finalize (object);
}
static gboolean
-gdouble_to_boolean (GBinding *binding,
- const GValue *from_value,
- GValue *to_value,
- gpointer user_data)
-{
- if (g_value_get_double (from_value))
- g_value_set_boolean (to_value, TRUE);
- else
- g_value_set_boolean (to_value, FALSE);
-
- return TRUE;
-}
-
-static gboolean
save_notes (gpointer data)
{
GrDetailsPage *page = data;
@@ -690,15 +340,6 @@ gr_details_page_init (GrDetailsPage *page)
gtk_widget_set_has_window (GTK_WIDGET (page), FALSE);
gtk_widget_init_template (GTK_WIDGET (page));
connect_store_signals (page);
- page->cooking = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, cooking_data_free);
-
- g_object_bind_property_full (page->time_spin, "value",
- page->start_button, "sensitive",
- 0,
- gdouble_to_boolean,
- NULL,
- NULL,
- NULL);
g_signal_connect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (page->notes_field)), "changed",
G_CALLBACK (schedule_save), page);
@@ -736,18 +377,7 @@ gr_details_page_class_init (GrDetailsPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, gluten_warning);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, ingredients_box);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, instructions_label);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, cooking_revealer);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, ingredients_check);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, instructions_check);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, preheat_check);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, timer);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, timer_stack);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, timer_popover);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, time_spin);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, start_button);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, favorite_button);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, duration_stack);
- gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, remaining_time_label);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, chef_label);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, edit_button);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, delete_button);
@@ -765,10 +395,6 @@ gr_details_page_class_init (GrDetailsPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, print_recipe);
gtk_widget_class_bind_template_callback (widget_class, export_recipe);
gtk_widget_class_bind_template_callback (widget_class, serves_value_changed);
- gtk_widget_class_bind_template_callback (widget_class, start_or_stop_timer);
- gtk_widget_class_bind_template_callback (widget_class, time_spin_input);
- gtk_widget_class_bind_template_callback (widget_class, time_spin_output);
- gtk_widget_class_bind_template_callback (widget_class, check_clicked);
gtk_widget_class_bind_template_callback (widget_class, cook_it_later);
gtk_widget_class_bind_template_callback (widget_class, shop_it);
gtk_widget_class_bind_template_callback (widget_class, activate_link);
@@ -970,7 +596,6 @@ gr_details_page_set_recipe (GrDetailsPage *page,
g_autoptr(GrChef) chef = NULL;
g_autoptr(GrIngredientsList) ing = NULL;
g_autoptr(GArray) images = NULL;
- gboolean cooking;
gboolean favorite;
gboolean same_recipe;
int index;
@@ -1023,9 +648,6 @@ gr_details_page_set_recipe (GrDetailsPage *page,
gtk_spin_button_set_value (GTK_SPIN_BUTTON (page->serves_spin), want_serves);
gtk_widget_set_sensitive (page->serves_spin, ing != NULL);
- cooking = g_hash_table_lookup (page->cooking, id) != NULL;
- set_cooking (page, cooking);
-
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
favorite = gr_recipe_store_is_favorite (store, recipe);
@@ -1106,17 +728,3 @@ connect_store_signals (GrDetailsPage *page)
g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (details_page_reload), page);
}
-
-gboolean
-gr_details_page_get_cooking (GrDetailsPage *page)
-{
- return gtk_revealer_get_reveal_child (GTK_REVEALER (page->cooking_revealer));
-}
-
-void
-gr_details_page_set_cooking (GrDetailsPage *page,
- gboolean cooking)
-{
- set_cooking (page, cooking);
-}
-
diff --git a/src/gr-details-page.h b/src/gr-details-page.h
index f95f03f..5be870b 100644
--- a/src/gr-details-page.h
+++ b/src/gr-details-page.h
@@ -36,8 +36,4 @@ void gr_details_page_set_recipe (GrDetailsPage *page,
GrRecipe *recipe);
GrRecipe *gr_details_page_get_recipe (GrDetailsPage *page);
-gboolean gr_details_page_get_cooking (GrDetailsPage *page);
-void gr_details_page_set_cooking (GrDetailsPage *page,
- gboolean cooking);
-
G_END_DECLS
diff --git a/src/gr-details-page.ui b/src/gr-details-page.ui
index 5dd2379..1185c0e 100644
--- a/src/gr-details-page.ui
+++ b/src/gr-details-page.ui
@@ -65,91 +65,6 @@
<property name="visible">1</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkRevealer" id="cooking_revealer">
- <property name="visible">1</property>
- <child>
- <object class="GtkBox">
- <property name="visible">1</property>
- <property name="spacing">10</property>
- <property name="hexpand">1</property>
- <style>
- <class name="location-bar"/>
- </style>
- <child>
- <object class="GrToggleButton" id="ingredients_check">
- <property name="visible">1</property>
- <property name="halign">center</property>
- <property name="relief">none</property>
- <property name="label" translatable="yes">Ingredients
-gathered</property>
- <signal name="clicked" handler="check_clicked"/>
- </object>
- <packing>
- <property name="expand">1</property>
- </packing>
- </child>
- <child>
- <object class="GrToggleButton" id="preheat_check">
- <property name="visible">1</property>
- <property name="halign">center</property>
- <property name="relief">none</property>
- <property name="label" translatable="yes">Oven
-preheated</property>
- <signal name="clicked" handler="check_clicked"/>
- </object>
- <packing>
- <property name="expand">1</property>
- </packing>
- </child>
- <child>
- <object class="GrToggleButton" id="instructions_check">
- <property name="visible">1</property>
- <property name="halign">center</property>
- <property name="relief">none</property>
- <property name="label" translatable="yes">Instructions
-followed</property>
- <signal name="clicked" handler="check_clicked"/>
- </object>
- <packing>
- <property name="expand">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkMenuButton">
- <property name="visible">1</property>
- <property name="relief">none</property>
- <property name="popover">timer_popover</property>
- <child>
- <object class="GtkStack" id="timer_stack">
- <property name="visible">1</property>
- <child>
- <object class="GtkImage">
- <property name="visible">1</property>
- <property name="icon-name">alarm-symbolic</property>
- <property name="pixel-size">24</property>
- </object>
- <packing>
- <property name="name">icon</property>
- </packing>
- </child>
- <child>
- <object class="GrTimerWidget" id="timer">
- <property name="visible">1</property>
- <property name="valign">center</property>
- </object>
- <packing>
- <property name="name">timer</property>
- </packing>
- </child>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
<object class="GtkScrolledWindow">
<property name="visible">1</property>
<property name="hscrollbar-policy">never</property>
@@ -546,89 +461,6 @@ followed</property>
</packing>
</child>
</template>
- <object class="GtkPopover" id="timer_popover">
- <child>
- <object class="GtkStack" id="duration_stack">
- <property name="visible">1</property>
- <child>
- <object class="GtkBox">
- <property name="visible">1</property>
- <property name="margin">12</property>
- <property name="spacing">12</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkLabel">
- <property name="visible">1</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Duration</property>
- </object>
- </child>
- <child>
- <object class="GtkSpinButton" id="time_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"/>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="start_button">
- <property name="visible">1</property>
- <property name="label" translatable="yes">Start</property>
- <property name="halign">end</property>
- <property name="valign">end</property>
- <property name="sensitive">0</property>
- <signal name="clicked" handler="start_or_stop_timer" swapped="yes"/>
- </object>
- </child>
- </object>
- <packing>
- <property name="name">start</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox">
- <property name="visible">1</property>
- <property name="margin">12</property>
- <property name="spacing">12</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkLabel">
- <property name="visible">1</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Remaining time</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="remaining_time_label">
- <property name="visible">1</property>
- <property name="xalign">0</property>
- <property name="halign">center</property>
- </object>
- </child>
- <child>
- <object class="GtkButton">
- <property name="visible">1</property>
- <property name="label" translatable="yes">Stop</property>
- <property name="halign">end</property>
- <property name="valign">end</property>
- <signal name="clicked" handler="start_or_stop_timer" swapped="yes"/>
- </object>
- </child>
- </object>
- <packing>
- <property name="name">stop</property>
- </packing>
- </child>
- </object>
- </child>
- </object>
- <object class="GtkAdjustment" id="time_adjustment">
- <property name="upper">86400</property>
- <property name="step-increment">60</property>
- <property name="page-increment">900</property>
- </object>
<object class="GtkPopover" id="notes_popover">
<child>
<object class="GtkScrolledWindow">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]