diff options
author | Ryan Lortie <desrt@desrt.ca> | 2010-10-27 09:08:32 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2010-11-12 09:06:19 -0500 |
commit | 3aff43d07ae62961e995237770c820aefa78e5dd (patch) | |
tree | 903ca35f58659908437ddad23e885ef972a23ffd | |
parent | 54b8e6596e8c3e772fe4744f2a591c5070dade1e (diff) |
Bug 632169 - manual use of gsettings-data-convert
Add some words and example code to the documentation about why you might
want to manually invoke gsettings-data-convert and how you should go
about doing that.
(cherry picked from commit dfb0577ef4947afb32d91a72769bd22d6c1edfaa)
-rw-r--r-- | docs/reference/gio/migrating-gconf.xml | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/docs/reference/gio/migrating-gconf.xml b/docs/reference/gio/migrating-gconf.xml index 1992fe657..44d455ba6 100644 --- a/docs/reference/gio/migrating-gconf.xml +++ b/docs/reference/gio/migrating-gconf.xml @@ -449,5 +449,69 @@ some-odd-key1 = /apps/myapp/some_ODD-key1 script if you are making use of the GConf backend or the conversion utility. </para> + + <para> + If, as an application developer, you are interested in manually + ensuring that <command>gsettings-data-convert</command> has been + invoked (for example, to deal with the case where the user is + logged in during a distribution upgrade or for non-XDG desktop + environments which do not run the command as an autostart) you + may invoke it manually during your program initialisation. This + is not recommended for all application authors -- it is your + choice if this use case concerns you enough. + </para> + <para> + Internally, <command>gsettings-data-convert</command> uses a + keyfile to track which settings have been migrated. The + following code fragment will check that keyfile to see if your + data conversion script has been run yet and, if not, will + attempt to invoke the tool to run it. You should adapt it to + your application as you see fit. + </para> + <para> + <programlisting> +<![CDATA[ +static void +ensure_migrated (const gchar *name) +{ + gboolean needed = TRUE; + GKeyFile *kf; + gchar **list; + gsize i, n; + + kf = g_key_file_new (); + + g_key_file_load_from_data_dirs (kf, "gsettings-data-convert", + NULL, G_KEY_FILE_NONE, NULL); + list = g_key_file_get_string_list (kf, "State", "converted", &n, NULL); + + if (list) + { + for (i = 0; i < n; i++) + if (strcmp (list[i], name) == 0) + { + needed = FALSE; + break; + } + + g_strfreev (list); + } + + g_key_file_free (kf); + + if (needed) + g_spawn_command_line_sync ("gsettings-data-convert", + NULL, NULL, NULL, NULL); +} + +]]> + </programlisting> + </para> + <para> + Although there is the possibility that the + <command>gsettings-data-convert</command> script will end up + running multiple times concurrently with this approach, it is + believed that this is safe. + </para> </section> </chapter> |