[recipes/temperature-settings: 3/3] Add a temperature button on the details page
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/temperature-settings: 3/3] Add a temperature button on the details page
- Date: Sun, 7 May 2017 19:26:06 +0000 (UTC)
commit d44afd13b2ad47b82c05ef12cbe6d10a6f2b7fa3
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 12 19:08:45 2017 -0400
Add a temperature button on the details page
Just an idea, and probably not a good one.
src/gr-details-page.c | 35 +++++++++++++++++++++++++++++++++++
src/gr-details-page.ui | 11 +++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index fadd4da..72d522a 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -87,6 +87,7 @@ struct _GrDetailsPage
GtkWidget *export_button;
GtkWidget *error_label;
GtkWidget *error_revealer;
+ GtkWidget *temperature_button;
guint save_timeout;
@@ -362,10 +363,42 @@ dismiss_error (GrDetailsPage *page)
}
static void
+update_temperature_label (GrDetailsPage *page)
+{
+ g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+
+ if (g_settings_get_enum (settings, "temperature-unit") == 1)
+ gtk_button_set_label (GTK_BUTTON (page->temperature_button), "๐กโ");
+ else
+ gtk_button_set_label (GTK_BUTTON (page->temperature_button), "๐กโ");
+}
+
+static char * process_instructions (const char *instructions);
+
+static void
+toggle_temperature (GtkButton *button,
+ GrDetailsPage *page)
+{
+ g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ int value;
+ const char *instructions;
+ g_autofree char *processed;
+
+ value = g_settings_get_enum (settings, "temperature-unit");
+ g_settings_set_enum (settings, "temperature-unit", value == 0 ? 1 : 0);
+ update_temperature_label (page);
+
+ instructions = gr_recipe_get_translated_instructions (page->recipe);
+ processed = process_instructions (instructions);
+ gtk_label_set_label (GTK_LABEL (page->instructions_label), processed);
+}
+
+static void
gr_details_page_init (GrDetailsPage *page)
{
gtk_widget_set_has_window (GTK_WIDGET (page), FALSE);
gtk_widget_init_template (GTK_WIDGET (page));
+ update_temperature_label (page);
connect_store_signals (page);
g_signal_connect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (page->notes_field)), "changed",
G_CALLBACK (schedule_save), page);
@@ -424,6 +457,7 @@ gr_details_page_class_init (GrDetailsPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, export_button);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, error_label);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, error_revealer);
+ gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, temperature_button);
gtk_widget_class_bind_template_callback (widget_class, edit_recipe);
gtk_widget_class_bind_template_callback (widget_class, delete_recipe);
@@ -436,6 +470,7 @@ gr_details_page_class_init (GrDetailsPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, activate_link);
gtk_widget_class_bind_template_callback (widget_class, dismiss_error);
gtk_widget_class_bind_template_callback (widget_class, activate_image);
+ gtk_widget_class_bind_template_callback (widget_class, toggle_temperature);
}
GtkWidget *
diff --git a/src/gr-details-page.ui b/src/gr-details-page.ui
index 882d01f..e108945 100644
--- a/src/gr-details-page.ui
+++ b/src/gr-details-page.ui
@@ -495,6 +495,17 @@
</object>
</child>
<child>
+ <object class="GtkButton" id="temperature_button">
+ <property name="visible">1</property>
+ <property name="use-underline">1</property>
+ <property name="relief">none</property>
+ <property name="focus-on-click">0</property>
+ <property name="label" translatable="yes">๐ก</property>
+ <property name="tooltip-text" translatable="yes">Temperature Display Unit</property>
+ <signal name="clicked" handler="toggle_temperature"/>
+ </object>
+ </child>
+ <child>
<object class="GtkButton" id="export_button">
<property name="focus-on-click">0</property>
<property name="use-underline">1</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]