[recipes] Use a singleton settings object
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Use a singleton settings object
- Date: Sat, 25 Mar 2017 23:16:55 +0000 (UTC)
commit f95bd36b9949dfd7ed83a9ada34f2f67136c5444
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 26 00:14:43 2017 +0100
Use a singleton settings object
No need to instantiate these all the time.
src/gr-cooking-page.c | 5 +++--
src/gr-recipe-store.c | 17 +++++++++--------
src/gr-settings.c | 34 ++++++++++++++++++++++++++++++++++
src/gr-settings.h | 29 +++++++++++++++++++++++++++++
src/meson.build | 1 +
5 files changed, 76 insertions(+), 10 deletions(-)
---
diff --git a/src/gr-cooking-page.c b/src/gr-cooking-page.c
index 98ab9f3..6d34056 100644
--- a/src/gr-cooking-page.c
+++ b/src/gr-cooking-page.c
@@ -26,6 +26,7 @@
#include "gr-cooking-page.h"
#include "gr-cooking-view.h"
+#include "gr-settings.h"
#include "gr-utils.h"
#include "gr-window.h"
#include "gr-recipe.h"
@@ -95,14 +96,14 @@ gr_cooking_page_init (GrCookingPage *self)
static guint
get_cooking_overlay_count (void)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
return g_settings_get_uint (settings, "cooking");
}
static void
set_cooking_overlay_count (uint count)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
g_settings_set_uint (settings, "cooking", count);
}
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index 1d3742c..58932c4 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -27,6 +27,7 @@
#include "gr-recipe-store.h"
#include "gr-recipe.h"
+#include "gr-settings.h"
#include "gr-utils.h"
#include "gr-ingredients-list.h"
#include "gr-images.h"
@@ -644,7 +645,7 @@ load_picks (GrRecipeStore *self,
static void
load_favorites (GrRecipeStore *self)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
gint64 timestamp;
self->favorites = g_settings_get_strv (settings, "favorites");
@@ -655,7 +656,7 @@ load_favorites (GrRecipeStore *self)
static void
save_favorites (GrRecipeStore *self)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
gint64 timestamp;
g_settings_set_strv (settings, "favorites", (const char * const *)self->favorites);
@@ -666,7 +667,7 @@ save_favorites (GrRecipeStore *self)
static void
load_export_list (GrRecipeStore *self)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
self->export_list = g_settings_get_strv (settings, "export-list");
}
@@ -674,7 +675,7 @@ load_export_list (GrRecipeStore *self)
static void
save_export_list (GrRecipeStore *self)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
g_settings_set_strv (settings, "export-list", (const char * const *)self->export_list);
}
@@ -682,7 +683,7 @@ save_export_list (GrRecipeStore *self)
static void
load_shopping (GrRecipeStore *self)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
g_autoptr(GVariant) value = NULL;
gint64 timestamp;
@@ -696,7 +697,7 @@ load_shopping (GrRecipeStore *self)
static void
save_shopping (GrRecipeStore *self)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
g_autoptr(GVariant) value = NULL;
gint64 timestamp;
@@ -872,7 +873,7 @@ save_chefs (GrRecipeStore *store)
static void
save_user (GrRecipeStore *self)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
g_settings_set_string (settings, "user", self->user ? self->user : "");
}
@@ -880,7 +881,7 @@ static void
load_user (GrRecipeStore *self,
const char *dir)
{
- g_autoptr(GSettings) settings = g_settings_new ("org.gnome.Recipes");
+ GSettings *settings = gr_settings_get ();
g_autofree char *user = g_settings_get_string (settings, "user");
if (user[0] == '\0') {
diff --git a/src/gr-settings.c b/src/gr-settings.c
new file mode 100644
index 0000000..7320061
--- /dev/null
+++ b/src/gr-settings.c
@@ -0,0 +1,34 @@
+/* gr-settings.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 <gr-settings.h>
+
+GSettings *
+gr_settings_get (void)
+{
+ static GSettings *settings;
+
+ if (settings == NULL)
+ settings = g_settings_new ("org.gnome.Recipes");
+
+ return settings;
+}
diff --git a/src/gr-settings.h b/src/gr-settings.h
new file mode 100644
index 0000000..711a9a4
--- /dev/null
+++ b/src/gr-settings.h
@@ -0,0 +1,29 @@
+/* gr-settings.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
+
+GSettings *gr_settings_get (void);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index e815a34..af706f0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -81,6 +81,7 @@ src += ['main.c',
'gr-recipes-page.c',
'gr-search-page.c',
'gr-season.c',
+ 'gr-settings.c',
'gr-shell-search-provider.c',
'gr-shopping-list-formatter.c',
'gr-shopping-list-printer.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]