[recipes/temperature-settings: 2/3] Add a preference dialog
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/temperature-settings: 2/3] Add a preference dialog
- Date: Sun, 7 May 2017 19:26:01 +0000 (UTC)
commit 913619455627e276fd21e3051fa31ca720930bb0
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 12 08:20:10 2017 -0400
Add a preference dialog
For now, this dialog just allows to choose between
Fahrenheit and Celsius.
src/Makefile.am | 2 +
src/gr-app.c | 15 +++++++-
src/gr-preferences.c | 81 ++++++++++++++++++++++++++++++++++++++++++
src/gr-preferences.h | 33 +++++++++++++++++
src/gr-preferences.ui | 50 ++++++++++++++++++++++++++
src/gr-window.c | 10 +++++
src/gr-window.h | 1 +
src/menus.ui | 6 +++
src/meson.build | 1 +
src/recipes-ui.gresource.xml | 1 +
10 files changed, 199 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 44d90e2..6797b55 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -84,6 +84,8 @@ gnome_recipes_SOURCES = \
gr-number.c \
gr-chef-dialog.h \
gr-chef-dialog.c \
+ gr-preferences.c \
+ gr-preferences.h \
gr-query-editor.h \
gr-query-editor.c \
gr-recipe.h \
diff --git a/src/gr-app.c b/src/gr-app.c
index 1759637..e41c9fc 100644
--- a/src/gr-app.c
+++ b/src/gr-app.c
@@ -271,6 +271,18 @@ verbose_logging_activated (GSimpleAction *action,
g_variant_get (parameter, "b", &verbose_logging);
}
+static void
+preferences_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer app)
+{
+ GtkWindow *win;
+
+ gr_app_activate (G_APPLICATION (app));
+ win = gtk_application_get_active_window (GTK_APPLICATION (app));
+ gr_window_show_preferences (GR_WINDOW (win));
+}
+
static GActionEntry app_entries[] =
{
{ "timer-expired", timer_expired, "(si)", NULL, NULL },
@@ -283,7 +295,8 @@ static GActionEntry app_entries[] =
{ "search", search_activated, "s", NULL, NULL },
{ "quit", quit_activated, NULL, NULL, NULL },
{ "report-issue", report_issue_activated, NULL, NULL, NULL },
- { "verbose-logging", verbose_logging_activated, "b", NULL, NULL }
+ { "verbose-logging", verbose_logging_activated, "b", NULL, NULL },
+ { "preferences", preferences_activated, NULL, NULL, NULL }
};
static void
diff --git a/src/gr-preferences.c b/src/gr-preferences.c
new file mode 100644
index 0000000..232b04d
--- /dev/null
+++ b/src/gr-preferences.c
@@ -0,0 +1,81 @@
+/* gr-preferences.c:
+ *
+ * Copyright (C) 2017 Matthias Clasen <mclasen redhat com>
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "gr-preferences.h"
+
+
+struct _GrPreferences
+{
+ GtkDialog parent_instance;
+ GtkWidget *temperature_unit;
+ GSettings *settings;
+};
+
+G_DEFINE_TYPE (GrPreferences, gr_preferences, GTK_TYPE_DIALOG)
+
+static void
+preferences_finalize (GObject *object)
+{
+ GrPreferences *prefs = GR_PREFERENCES (object);
+
+ g_object_unref (prefs->settings);
+
+ G_OBJECT_CLASS (gr_preferences_parent_class)->finalize (object);
+}
+
+static void
+gr_preferences_init (GrPreferences *prefs)
+{
+ gtk_widget_init_template (GTK_WIDGET (prefs));
+ prefs->settings = g_settings_new ("org.gnome.Recipes");
+
+ g_settings_bind (prefs->settings, "temperature-unit",
+ prefs->temperature_unit, "active-id",
+ G_SETTINGS_BIND_DEFAULT);
+}
+
+static void
+gr_preferences_class_init (GrPreferencesClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->finalize = preferences_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Recipes/gr-preferences.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, GrPreferences, temperature_unit);
+}
+
+GtkWidget *
+gr_preferences_new (void)
+{
+ gboolean use_header;
+
+ g_object_get (gtk_settings_get_default (), "gtk-dialogs-use-header", &use_header, NULL);
+ return GTK_WIDGET (g_object_new (GR_TYPE_PREFERENCES,
+ "use-header-bar", use_header,
+ NULL));
+}
diff --git a/src/gr-preferences.h b/src/gr-preferences.h
new file mode 100644
index 0000000..dac156a
--- /dev/null
+++ b/src/gr-preferences.h
@@ -0,0 +1,33 @@
+/* gr-preferences.h:
+ *
+ * Copyright (C) 2017 Matthias Clasen <mclasen redhat com>
+ *
+ * Licensed under the GNU General Public License Version 3
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GR_TYPE_PREFERENCES (gr_preferences_get_type ())
+
+G_DECLARE_FINAL_TYPE (GrPreferences, gr_preferences, GR, PREFERENCES, GtkDialog)
+
+GtkWidget *gr_preferences_new (void);
+
+G_END_DECLS
diff --git a/src/gr-preferences.ui b/src/gr-preferences.ui
new file mode 100644
index 0000000..d30cb37
--- /dev/null
+++ b/src/gr-preferences.ui
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gnome-recipes">
+ <template class="GrPreferences" parent="GtkDialog">
+ <property name="title" translatable="yes">Preferences</property>
+ <property name="resizable">0</property>
+ <property name="modal">1</property>
+ <property name="destroy-with-parent">1</property>
+ <child internal-child="vbox">
+ <object class="GtkBox">
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">1</property>
+ <property name="margin">10</property>
+ <property name="row-spacing">10</property>
+ <property name="column-spacing">10</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ <property name="label" translatable="yes">Temperature Unit</property>
+ <property name="xalign">1</property>
+ <property name="valign">baseline</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="temperature_unit">
+ <property name="visible">1</property>
+ <property name="valign">baseline</property>
+ <items>
+ <item translatable="yes" id="celsius">Celsius</item>
+ <item translatable="yes" id="fahrenheit">Fahrenheit</item>
+ </items>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/gr-window.c b/src/gr-window.c
index ca08a73..606dbd3 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -46,6 +46,7 @@
#include "gr-account.h"
#include "gr-utils.h"
#include "gr-appdata.h"
+#include "gr-preferences.h"
struct _GrWindow
@@ -1482,3 +1483,12 @@ gr_window_show_report_issue (GrWindow *window)
if (error)
g_warning ("Unable to show '%s': %s", uri, error->message);
}
+
+void
+gr_window_show_preferences (GrWindow *window)
+{
+ GtkWidget *preferences;
+
+ preferences = (GtkWidget *)gr_preferences_new ();
+ gr_window_present_dialog (window, GTK_WINDOW (preferences));
+}
diff --git a/src/gr-window.h b/src/gr-window.h
index 4431dcc..d0609f9 100644
--- a/src/gr-window.h
+++ b/src/gr-window.h
@@ -84,5 +84,6 @@ void gr_window_show_my_chef_information (GrWindow *window);
void gr_window_show_about_dialog (GrWindow *window);
void gr_window_show_report_issue (GrWindow *window);
void gr_window_show_news (GrWindow *window);
+void gr_window_show_preferences (GrWindow *window);
G_END_DECLS
diff --git a/src/menus.ui b/src/menus.ui
index db79068..f13b5a4 100644
--- a/src/menus.ui
+++ b/src/menus.ui
@@ -20,6 +20,12 @@
</section>
<section>
<item>
+ <attribute name="label" translatable="yes">_Preferences</attribute>
+ <attribute name="action">app.preferences</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
<attribute name="label" translatable="yes">_About</attribute>
<attribute name="action">app.about</attribute>
</item>
diff --git a/src/meson.build b/src/meson.build
index 3fe3e2c..5bcb3ab 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -75,6 +75,7 @@ src += ['main.c',
'gr-meal.c',
'gr-meal-row.c',
'gr-number.c',
+ 'gr-preferences.c',
'gr-query-editor.c',
'gr-recipe.c',
'gr-recipe-exporter.c',
diff --git a/src/recipes-ui.gresource.xml b/src/recipes-ui.gresource.xml
index 1578e81..e86e3bd 100644
--- a/src/recipes-ui.gresource.xml
+++ b/src/recipes-ui.gresource.xml
@@ -17,6 +17,7 @@
<file preprocess="xml-stripblanks">gr-ingredient-row.ui</file>
<file preprocess="xml-stripblanks">gr-list-page.ui</file>
<file preprocess="xml-stripblanks">gr-meal-row.ui</file>
+ <file preprocess="xml-stripblanks">gr-preferences.ui</file>
<file preprocess="xml-stripblanks">gr-recipes-page.ui</file>
<file preprocess="xml-stripblanks">gr-recipe-small-tile.ui</file>
<file preprocess="xml-stripblanks">gr-recipe-tile.ui</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]