From 05b4851da8aa1701795bb9665116313a5a0c49a7 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 7 Oct 2013 14:23:37 +0100 Subject: Add function to retrieve the system personality We will use it in the app store, and other applications, to determine the content to be displayed. [endlessm/eos-sdk#326] [endlessm/eos-sdk#326] --- endless/eosinit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'endless/eosinit.c') diff --git a/endless/eosinit.c b/endless/eosinit.c index fadc9b4..057e391 100644 --- a/endless/eosinit.c +++ b/endless/eosinit.c @@ -21,6 +21,8 @@ should also work on Clang. */ static gboolean _eos_initialized = FALSE; +static char *eos_system_personality; + /* * _eos_init: * @@ -51,3 +53,52 @@ 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 char * +eos_get_system_personality (void) +{ + static char *personality; + + if (g_once_init_enter (&personality)) + { + char *tmp; + + tmp = g_strdup (g_getenv ("ENDLESS_OS_PERSONALITY")); + if (tmp == NULL || *tmp == '\0') + { + 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; +} -- cgit v1.2.3 From 4752753fafe02bb96d42ddac11f928a3e2400a7c Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 7 Oct 2013 23:40:25 +0100 Subject: Fixes after code review [endlessm/eos-sdk#326] --- endless/eosinit.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'endless/eosinit.c') diff --git a/endless/eosinit.c b/endless/eosinit.c index 057e391..f285da7 100644 --- a/endless/eosinit.c +++ b/endless/eosinit.c @@ -21,8 +21,6 @@ should also work on Clang. */ static gboolean _eos_initialized = FALSE; -static char *eos_system_personality; - /* * _eos_init: * @@ -67,17 +65,23 @@ eos_is_inited (void) * with the name of the personality. You should never free or modify * the returned string. */ -const char * +const gchar * eos_get_system_personality (void) { - static char *personality; + static gchar *personality; if (g_once_init_enter (&personality)) { - char *tmp; + gchar *tmp; tmp = g_strdup (g_getenv ("ENDLESS_OS_PERSONALITY")); - if (tmp == NULL || *tmp == '\0') + if (tmp == '\0') + { + g_free (tmp); + tmp = NULL; + } + + if (tmp == NULL) { char *path = g_build_filename (DATADIR, "EndlessOS", -- cgit v1.2.3