diff options
author | P. F. Chimento <philip.chimento@gmail.com> | 2013-10-07 15:48:36 -0700 |
---|---|---|
committer | P. F. Chimento <philip.chimento@gmail.com> | 2013-10-07 15:48:36 -0700 |
commit | 4c49aaa08d76ae834e7dfca8a6708ae3e4d067e6 (patch) | |
tree | ff302a98e79490d8dfd5b20a0f0184e38bd16ddd /endless/eosinit.c | |
parent | 94f36c68267417104128884823fbd90768d9e979 (diff) | |
parent | 4752753fafe02bb96d42ddac11f928a3e2400a7c (diff) |
Merge pull request #342 from endlessm/issues/326
#326 Add function to retrieve the system personality
Diffstat (limited to 'endless/eosinit.c')
-rw-r--r-- | endless/eosinit.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/endless/eosinit.c b/endless/eosinit.c index fadc9b4..f285da7 100644 --- a/endless/eosinit.c +++ b/endless/eosinit.c @@ -51,3 +51,58 @@ eos_is_inited (void) { return _eos_initialized; } + +/** + * eos_get_system_personality: + * + * Retrieves the "personality" of the system. + * + * The personality is a unique string that identifies the installation + * of EndlessOS for a specific country or audience. The availability of + * certain applications, or their content, is determined by this value. + * + * Return value: (transfer none): a string, owned by the Endless SDK, + * with the name of the personality. You should never free or modify + * the returned string. + */ +const gchar * +eos_get_system_personality (void) +{ + static gchar *personality; + + if (g_once_init_enter (&personality)) + { + gchar *tmp; + + tmp = g_strdup (g_getenv ("ENDLESS_OS_PERSONALITY")); + if (tmp == '\0') + { + g_free (tmp); + tmp = NULL; + } + + if (tmp == NULL) + { + char *path = g_build_filename (DATADIR, + "EndlessOS", + "personality.txt", + NULL); + + GError *error = NULL; + g_file_get_contents (path, &tmp, NULL, &error); + if (error != NULL) + { + g_critical ("No personality defined: %s", error->message); + g_error_free (error); + tmp = NULL; + } + } + + if (tmp == NULL) + tmp = g_strdup ("Default"); + + g_once_init_leave (&personality, tmp); + } + + return personality; +} |