summaryrefslogtreecommitdiff
path: root/panels/info/cc-info-overview-panel.c
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2019-08-21 16:55:51 +1200
committerRobert Ancell <robert.ancell@gmail.com>2019-09-09 21:42:10 +0000
commit1752cf3bb573d300e990ea10006dea70a322d8df (patch)
treef804ca227663c48d3f2932cf775a96a2ce7cd4fa /panels/info/cc-info-overview-panel.c
parentab8aa577e1f7799e527f9200866a8f6e13e5fe85 (diff)
downloadgnome-control-center-1752cf3bb573d300e990ea10006dea70a322d8df.tar.gz
Make /etc/os-release support common
The existing code is used in multiple places with slightly different implementations.
Diffstat (limited to 'panels/info/cc-info-overview-panel.c')
-rw-r--r--panels/info/cc-info-overview-panel.c64
1 files changed, 4 insertions, 60 deletions
diff --git a/panels/info/cc-info-overview-panel.c b/panels/info/cc-info-overview-panel.c
index 7fce8691e..09a589dcd 100644
--- a/panels/info/cc-info-overview-panel.c
+++ b/panels/info/cc-info-overview-panel.c
@@ -22,6 +22,7 @@
#include <config.h>
#include "cc-hostname-entry.h"
+#include "cc-os-release.h"
#include "cc-info-resources.h"
#include "info-cleanup.h"
@@ -371,70 +372,15 @@ get_graphics_data (void)
return result;
}
-static GHashTable*
-get_os_info (void)
-{
- GHashTable *hashtable;
- g_autofree gchar *buffer = NULL;
-
- hashtable = NULL;
-
- if (g_file_get_contents ("/etc/os-release", &buffer, NULL, NULL))
- {
- g_auto(GStrv) lines = NULL;
- gint i;
-
- lines = g_strsplit (buffer, "\n", -1);
-
- for (i = 0; lines[i] != NULL; i++)
- {
- gchar *delimiter;
-
- /* Initialize the hash table if needed */
- if (!hashtable)
- hashtable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-
- delimiter = strstr (lines[i], "=");
-
- if (delimiter != NULL)
- {
- gint size;
- gchar *key, *value;
-
- key = g_strndup (lines[i], delimiter - lines[i]);
-
- /* Jump the '=' */
- delimiter += strlen ("=");
-
- /* Eventually jump the ' " ' character */
- if (g_str_has_prefix (delimiter, "\""))
- delimiter += strlen ("\"");
-
- size = strlen (delimiter);
-
- /* Don't consider the last ' " ' too */
- if (g_str_has_suffix (delimiter, "\""))
- size -= strlen ("\"");
-
- value = g_strndup (delimiter, size);
-
- g_hash_table_insert (hashtable, key, value);
- }
- }
- }
-
- return hashtable;
-}
-
static char *
get_os_name (void)
{
- GHashTable *os_info;
- gchar *name, *version_id, *pretty_name, *build_id;
+ g_autoptr(GHashTable) os_info = NULL;
+ const gchar *name, *version_id, *pretty_name, *build_id;
gchar *result = NULL;
g_autofree gchar *name_version = NULL;
- os_info = get_os_info ();
+ os_info = cc_os_release_get_values ();
if (!os_info)
return g_strdup (_("Unknown"));
@@ -464,8 +410,6 @@ get_os_name (void)
result = g_strdup (name_version);
}
- g_clear_pointer (&os_info, g_hash_table_destroy);
-
return result;
}