shell-global: Add new APIs for saving/loading persistent state
https://bugzilla.gnome.org/show_bug.cgi?id=710137
This commit is contained in:
parent
c9b73ac731
commit
1ac4ab7edc
@ -80,10 +80,11 @@ struct _ShellGlobal {
|
|||||||
const char *datadir;
|
const char *datadir;
|
||||||
const char *imagedir;
|
const char *imagedir;
|
||||||
const char *userdatadir;
|
const char *userdatadir;
|
||||||
StFocusManager *focus_manager;
|
GFile *userdatadir_path;
|
||||||
|
|
||||||
GFile *runtime_state_path;
|
GFile *runtime_state_path;
|
||||||
|
|
||||||
|
StFocusManager *focus_manager;
|
||||||
|
|
||||||
guint work_count;
|
guint work_count;
|
||||||
GSList *leisure_closures;
|
GSList *leisure_closures;
|
||||||
guint leisure_function_id;
|
guint leisure_function_id;
|
||||||
@ -252,6 +253,7 @@ shell_global_init (ShellGlobal *global)
|
|||||||
/* Ensure config dir exists for later use */
|
/* Ensure config dir exists for later use */
|
||||||
global->userdatadir = g_build_filename (g_get_user_data_dir (), "gnome-shell", NULL);
|
global->userdatadir = g_build_filename (g_get_user_data_dir (), "gnome-shell", NULL);
|
||||||
g_mkdir_with_parents (global->userdatadir, 0700);
|
g_mkdir_with_parents (global->userdatadir, 0700);
|
||||||
|
global->userdatadir_path = g_file_new_for_path (global->userdatadir);
|
||||||
|
|
||||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||||
byteorder_string = "LE";
|
byteorder_string = "LE";
|
||||||
@ -306,6 +308,7 @@ shell_global_finalize (GObject *object)
|
|||||||
|
|
||||||
the_object = NULL;
|
the_object = NULL;
|
||||||
|
|
||||||
|
g_clear_object (&global->userdatadir_path);
|
||||||
g_clear_object (&global->runtime_state_path);
|
g_clear_object (&global->runtime_state_path);
|
||||||
|
|
||||||
G_OBJECT_CLASS(shell_global_parent_class)->finalize (object);
|
G_OBJECT_CLASS(shell_global_parent_class)->finalize (object);
|
||||||
@ -1746,29 +1749,12 @@ shell_global_get_session_mode (ShellGlobal *global)
|
|||||||
return global->session_mode;
|
return global->session_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GFile *
|
static void
|
||||||
get_runtime_state_path (ShellGlobal *global,
|
save_variant (GFile *dir,
|
||||||
const char *property_name)
|
const char *property_name,
|
||||||
|
GVariant *variant)
|
||||||
{
|
{
|
||||||
return g_file_get_child (global->runtime_state_path, property_name);
|
GFile *path = g_file_get_child (dir, 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)
|
|
||||||
{
|
|
||||||
GFile *path;
|
|
||||||
|
|
||||||
path = get_runtime_state_path (global, property_name);
|
|
||||||
|
|
||||||
if (variant == NULL || g_variant_get_data (variant) == NULL)
|
if (variant == NULL || g_variant_get_data (variant) == NULL)
|
||||||
(void) g_file_delete (path, NULL, NULL);
|
(void) g_file_delete (path, NULL, NULL);
|
||||||
@ -1783,29 +1769,17 @@ shell_global_set_runtime_state (ShellGlobal *global,
|
|||||||
g_object_unref (path);
|
g_object_unref (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static GVariant *
|
||||||
* shell_global_get_runtime_state:
|
load_variant (GFile *dir,
|
||||||
* @global: a #ShellGlobal
|
const char *property_type,
|
||||||
* @property_type: Expected data type
|
const char *property_name)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
GVariant *res = NULL;
|
GVariant *res = NULL;
|
||||||
GMappedFile *mfile;
|
GMappedFile *mfile;
|
||||||
GFile *path;
|
GFile *path = g_file_get_child (dir, property_name);
|
||||||
char *pathstr;
|
char *pathstr;
|
||||||
GError *local_error = NULL;
|
GError *local_error = NULL;
|
||||||
|
|
||||||
path = get_runtime_state_path (global, property_name);
|
|
||||||
pathstr = g_file_get_path (path);
|
pathstr = g_file_get_path (path);
|
||||||
mfile = g_mapped_file_new (pathstr, FALSE, &local_error);
|
mfile = g_mapped_file_new (pathstr, FALSE, &local_error);
|
||||||
if (!mfile)
|
if (!mfile)
|
||||||
@ -1829,3 +1803,73 @@ shell_global_get_runtime_state (ShellGlobal *global,
|
|||||||
|
|
||||||
return res;
|
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);
|
||||||
|
}
|
||||||
|
@ -129,13 +129,19 @@ void shell_global_reexec_self (ShellGlobal *global);
|
|||||||
|
|
||||||
const char * shell_global_get_session_mode (ShellGlobal *global);
|
const char * shell_global_get_session_mode (ShellGlobal *global);
|
||||||
|
|
||||||
void shell_global_set_runtime_state (ShellGlobal *global,
|
void shell_global_set_runtime_state (ShellGlobal *global,
|
||||||
const char *property_name,
|
const char *property_name,
|
||||||
GVariant *variant);
|
GVariant *variant);
|
||||||
GVariant * shell_global_get_runtime_state (ShellGlobal *global,
|
GVariant * shell_global_get_runtime_state (ShellGlobal *global,
|
||||||
const char *property_type,
|
const char *property_type,
|
||||||
const char *property_name);
|
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
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user