[recipes/gsettings: 4/11] Store the cooking count in gsettings
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/gsettings: 4/11] Store the cooking count in gsettings
- Date: Wed, 8 Mar 2017 03:13:51 +0000 (UTC)
commit cd78fe911b235146a2152a9c177e4264cb8da559
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Mar 7 17:44:35 2017 -0500
Store the cooking count in gsettings
No need to write a file for this tiny amount of data.
data/org.gnome.recipes.gschema.xml | 6 +++++
src/gr-cooking-page.c | 42 +++++------------------------------
src/gr-recipe-store.c | 5 ++-
3 files changed, 15 insertions(+), 38 deletions(-)
---
diff --git a/data/org.gnome.recipes.gschema.xml b/data/org.gnome.recipes.gschema.xml
index bf6bc6a..9609cf5 100644
--- a/data/org.gnome.recipes.gschema.xml
+++ b/data/org.gnome.recipes.gschema.xml
@@ -2,11 +2,17 @@
<schemalist>
<schema path="/org/gnome/recipes/" id="org.gnome.recipes" gettext-domain="gnome-recipes">
+
<key type="s" name="user">
<default>''</default>
<summary>The user ID of the current user</summary>
<description>The user ID of the current user</description>
</key>
+ <key type="u" name="cooking">
+ <default>0</default>
+ <summary>The number of times cooking mode has been presented</summary>
+ <description>The number of times cooking mode has been presented</description>
+ </key>
</schema>
diff --git a/src/gr-cooking-page.c b/src/gr-cooking-page.c
index 1d7a29a..71182f0 100644
--- a/src/gr-cooking-page.c
+++ b/src/gr-cooking-page.c
@@ -91,48 +91,18 @@ gr_cooking_page_init (GrCookingPage *self)
gr_cooking_view_set_timer_box (GR_COOKING_VIEW (self->cooking_view), self->mini_timer_box);
}
-static int
+static guint
get_cooking_overlay_count (void)
{
- g_autofree char *path = NULL;
- g_autoptr(GKeyFile) keyfile = NULL;
- g_autoptr(GError) error = NULL;
- int count;
-
- keyfile = g_key_file_new ();
-
- path = g_build_filename (get_user_data_dir (), "cooking", NULL);
- if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error)) {
- if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
- g_error ("Failed to load cooking overlay count: %s", error->message);
- return 0;
- }
-
- count = g_key_file_get_integer (keyfile, "Cooking", "OverlayShown", &error);
- if (error) {
- g_error ("Failed to load cooking overlay count: %s", error->message);
- return 0;
- }
-
- return count;
+ g_autoptr(GSettings) settings = g_settings_new ("org.gnome.recipes");
+ return g_settings_get_uint (settings, "cooking");
}
static void
-set_cooking_overlay_count (int count)
+set_cooking_overlay_count (uint count)
{
- g_autofree char *path = NULL;
- g_autoptr(GKeyFile) keyfile = NULL;
- g_autoptr(GError) error = NULL;
-
- keyfile = g_key_file_new ();
-
- path = g_build_filename (get_user_data_dir (), "cooking", NULL);
-
- g_key_file_set_integer (keyfile, "Cooking", "OverlayShown", count);
-
- if (!g_key_file_save_to_file (keyfile, path, &error)) {
- g_error ("Failed to save cooking overlay count: %s", error->message);
- }
+ g_autoptr(GSettings) settings = g_settings_new ("org.gnome.recipes");
+ g_settings_set_uint (settings, "cooking", count);
}
static void
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index 91a63fe..ddf435a 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -46,7 +46,6 @@
* - picks, with lists of things to put on the landing page
* - favorites.db, with a list of the user's favorites
* - shopping.db, with the current shppping list
- * - cooking, with a counter for how often cooking mode was launched
*
* Some of these files are preinstalled (picks.db), some are only per-user
* (favorites.db, shopping.db, user, cooking), and some are both, with the
@@ -66,7 +65,9 @@
* Ancillary data
* --------------
*
- * The user id of the user is kept in gsettings
+ * Ancillary data is kept in gsettings:
+ * - the user id of the user
+ * - the counter for how often cooking mode was launched
*/
struct _GrRecipeStore
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]