[gnome-shell/wip/gtk-notification: 21/22] shell-global: Add new APIs for saving/loading persistent state
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/gtk-notification: 21/22] shell-global: Add new APIs for saving/loading persistent state
- Date: Mon, 14 Oct 2013 13:55:24 +0000 (UTC)
commit 55cd927ebbc22c7730df7ce7b8bd13f8a325350c
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sun Oct 13 18:46:50 2013 -0400
shell-global: Add new APIs for saving/loading persistent state
src/shell-global.c | 126 +++++++++++++++++++++++++++++++++++-----------------
src/shell-global.h | 12 ++++-
2 files changed, 94 insertions(+), 44 deletions(-)
---
diff --git a/src/shell-global.c b/src/shell-global.c
index 68773b8..f0a04a1 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -80,10 +80,11 @@ struct _ShellGlobal {
const char *datadir;
const char *imagedir;
const char *userdatadir;
- StFocusManager *focus_manager;
-
+ GFile *userdatadir_path;
GFile *runtime_state_path;
+ StFocusManager *focus_manager;
+
guint work_count;
GSList *leisure_closures;
guint leisure_function_id;
@@ -252,6 +253,7 @@ shell_global_init (ShellGlobal *global)
/* Ensure config dir exists for later use */
global->userdatadir = g_build_filename (g_get_user_data_dir (), "gnome-shell", NULL);
g_mkdir_with_parents (global->userdatadir, 0700);
+ global->userdatadir_path = g_file_new_for_path (global->userdatadir);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
byteorder_string = "LE";
@@ -306,6 +308,7 @@ shell_global_finalize (GObject *object)
the_object = NULL;
+ g_clear_object (&global->userdatadir_path);
g_clear_object (&global->runtime_state_path);
G_OBJECT_CLASS(shell_global_parent_class)->finalize (object);
@@ -1746,29 +1749,12 @@ shell_global_get_session_mode (ShellGlobal *global)
return global->session_mode;
}
-static GFile *
-get_runtime_state_path (ShellGlobal *global,
- const char *property_name)
-{
- return g_file_get_child (global->runtime_state_path, property_name);
-}
-
-/**
- * shell_global_set_runtime_state:
- * @global: a #ShellGlobal
- * @property_name: Name of the property
- * @variant: (allow-none): A #GVariant, or %NULL to unset
- *
- * Change the value of serialized runtime state.
- */
-void
-shell_global_set_runtime_state (ShellGlobal *global,
- const char *property_name,
- GVariant *variant)
+static void
+save_variant (GFile *dir,
+ const char *property_name,
+ GVariant *variant)
{
- GFile *path;
-
- path = get_runtime_state_path (global, property_name);
+ GFile *path = g_file_get_child (dir, property_name);
if (variant == NULL || g_variant_get_data (variant) == NULL)
(void) g_file_delete (path, NULL, NULL);
@@ -1783,29 +1769,17 @@ shell_global_set_runtime_state (ShellGlobal *global,
g_object_unref (path);
}
-/**
- * shell_global_get_runtime_state:
- * @global: a #ShellGlobal
- * @property_type: Expected data type
- * @property_name: Name of the property
- *
- * The shell maintains "runtime" state which does not persist across
- * logout or reboot.
- *
- * Returns: (transfer floating): The value of a serialized property, or %NULL if none stored
- */
-GVariant *
-shell_global_get_runtime_state (ShellGlobal *global,
- const char *property_type,
- const char *property_name)
+static GVariant *
+load_variant (GFile *dir,
+ const char *property_type,
+ const char *property_name)
{
GVariant *res = NULL;
GMappedFile *mfile;
- GFile *path;
+ GFile *path = g_file_get_child (dir, property_name);
char *pathstr;
GError *local_error = NULL;
- path = get_runtime_state_path (global, property_name);
pathstr = g_file_get_path (path);
mfile = g_mapped_file_new (pathstr, FALSE, &local_error);
if (!mfile)
@@ -1829,3 +1803,73 @@ shell_global_get_runtime_state (ShellGlobal *global,
return res;
}
+
+/**
+ * shell_global_set_runtime_state:
+ * @global: a #ShellGlobal
+ * @property_name: Name of the property
+ * @variant: (allow-none): A #GVariant, or %NULL to unset
+ *
+ * Change the value of serialized runtime state.
+ */
+void
+shell_global_set_runtime_state (ShellGlobal *global,
+ const char *property_name,
+ GVariant *variant)
+{
+ save_variant (global->runtime_state_path, property_name, variant);
+}
+
+/**
+ * shell_global_get_runtime_state:
+ * @global: a #ShellGlobal
+ * @property_type: Expected data type
+ * @property_name: Name of the property
+ *
+ * The shell maintains "runtime" state which does not persist across
+ * logout or reboot.
+ *
+ * Returns: (transfer floating): The value of a serialized property, or %NULL if none stored
+ */
+GVariant *
+shell_global_get_runtime_state (ShellGlobal *global,
+ const char *property_type,
+ const char *property_name)
+{
+ return load_variant (global->runtime_state_path, property_type, property_name);
+}
+
+/**
+ * shell_global_set_persistent_state:
+ * @global: a #ShellGlobal
+ * @property_name: Name of the property
+ * @variant: (allow-none): A #GVariant, or %NULL to unset
+ *
+ * Change the value of serialized persistent state.
+ */
+void
+shell_global_set_persistent_state (ShellGlobal *global,
+ const char *property_name,
+ GVariant *variant)
+{
+ save_variant (global->userdatadir_path, property_name, variant);
+}
+
+/**
+ * shell_global_get_persistent_state:
+ * @global: a #ShellGlobal
+ * @property_type: Expected data type
+ * @property_name: Name of the property
+ *
+ * The shell maintains "persistent" state which will persist after
+ * logout or reboot.
+ *
+ * Returns: (transfer none): The value of a serialized property, or %NULL if none stored
+ */
+GVariant *
+shell_global_get_persistent_state (ShellGlobal *global,
+ const char *property_type,
+ const char *property_name)
+{
+ return load_variant (global->userdatadir_path, property_type, property_name);
+}
diff --git a/src/shell-global.h b/src/shell-global.h
index 037b55f..b445c42 100644
--- a/src/shell-global.h
+++ b/src/shell-global.h
@@ -129,13 +129,19 @@ void shell_global_reexec_self (ShellGlobal *global);
const char * shell_global_get_session_mode (ShellGlobal *global);
-void shell_global_set_runtime_state (ShellGlobal *global,
- const char *property_name,
- GVariant *variant);
+void shell_global_set_runtime_state (ShellGlobal *global,
+ const char *property_name,
+ GVariant *variant);
GVariant * shell_global_get_runtime_state (ShellGlobal *global,
const char *property_type,
const char *property_name);
+void shell_global_set_persistent_state (ShellGlobal *global,
+ const char *property_name,
+ GVariant *variant);
+GVariant * shell_global_get_persistent_state (ShellGlobal *global,
+ const char *property_type,
+ const char *property_name);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]