aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-07-17 08:33:36 +0000
committerCI bot <ps-jenkins@lists.canonical.com>2014-07-17 08:33:36 +0000
commit5a43af8c8abcd51b8c6d136dc9c3ecf1a94f3575 (patch)
tree783ef181bba6a42cea297fc33569cfb83544467c
parent63f2cd2eb4cb1ef1ec95732b4a5ed052d523d71f (diff)
parentbf07982baca283c98624d4e64efbf0e641d019d0 (diff)
downloadayatana-indicator-session-5a43af8c8abcd51b8c6d136dc9c3ecf1a94f3575.tar.gz
ayatana-indicator-session-5a43af8c8abcd51b8c6d136dc9c3ecf1a94f3575.tar.bz2
ayatana-indicator-session-5a43af8c8abcd51b8c6d136dc9c3ecf1a94f3575.zip
Add support for getting the distro name from /etc/os-release. Fixes: 1331873
Approved by: Ted Gould, PS Jenkins bot
-rw-r--r--src/service.c80
1 files changed, 78 insertions, 2 deletions
diff --git a/src/service.c b/src/service.c
index 7484134..034e67c 100644
--- a/src/service.c
+++ b/src/service.c
@@ -329,14 +329,90 @@ get_current_real_name (IndicatorSessionService * self)
****
***/
+static GHashTable*
+get_os_release (void)
+{
+ static const char * const os_release = "/etc/os-release";
+ GHashTable * hash;
+ GIOChannel * io;
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+ if ((io = g_io_channel_new_file (os_release, "r", NULL)))
+ {
+ GString * key = g_string_new (NULL);
+
+ for (;;)
+ {
+ GIOStatus status;
+ char * in;
+ GError * error;
+ gchar * val;
+
+ /* read a line */
+ status = g_io_channel_read_line_string (io, key, NULL, NULL);
+ if (status == G_IO_STATUS_EOF)
+ break;
+
+ /* ignore blank lines & comments */
+ if (!key->len || key->str[0]=='#')
+ continue;
+
+ /* split into key=value */
+ in = strchr(key->str, '=');
+ if (!in)
+ continue;
+ *in++ = '\0';
+
+ /* unmunge the value component */
+ g_strstrip(in); /* eat linefeed */
+ error = NULL;
+ val = g_shell_unquote (in, &error);
+ if (error != NULL)
+ {
+ g_warning("Unable to unquote \"%s\": %s", in, error->message);
+ val = g_strdup(in);
+ g_clear_error(&error);
+ }
+
+ g_debug("from \"%s\": key [%s] val [%s]", os_release, key->str, val);
+ g_hash_table_insert (hash, g_strdup(key->str), val); /* hash owns val now */
+ }
+
+ g_string_free(key, TRUE);
+ g_io_channel_unref(io);
+ }
+
+ return hash;
+}
+
+static const char*
+get_distro_name (void)
+{
+ static char * distro_name = NULL;
+
+ if (distro_name == NULL)
+ {
+ GHashTable * os_release = get_os_release();
+ gpointer value = g_hash_table_lookup(os_release, "NAME");
+ if (value == NULL)
+ value = "Ubuntu"; /* fallback value */
+ distro_name = g_strdup(value);
+ g_hash_table_destroy(os_release);
+ }
+
+ return distro_name;
+}
+
static GMenuModel *
create_admin_section (void)
{
GMenu * menu;
-
+ gchar * help_label = g_strdup_printf(_("%s Help"), get_distro_name());
menu = g_menu_new ();
g_menu_append (menu, _("About This Computer"), "indicator.about");
- g_menu_append (menu, _("Ubuntu Help"), "indicator.help");
+ g_menu_append (menu, help_label, "indicator.help");
+ g_free (help_label);
return G_MENU_MODEL (menu);
}