aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro Pereira <leandro@hardinfo.org>2020-05-03 10:11:13 -0700
committerLeandro Pereira <leandro@hardinfo.org>2020-05-03 10:11:13 -0700
commit0867b5c6b8ee0e8b1fb9a969f13975eab6ab0fc9 (patch)
treef91a78da7c4b44a3451c3ad484dfcd80aedb1022
parent142244445116202f3ae99e64a271e7e53bfc7a54 (diff)
Show distro code name, if present
-rw-r--r--includes/computer.h2
-rw-r--r--modules/computer.c11
-rw-r--r--modules/computer/os.c11
3 files changed, 19 insertions, 5 deletions
diff --git a/includes/computer.h b/includes/computer.h
index 25da8e27..b537f7b1 100644
--- a/includes/computer.h
+++ b/includes/computer.h
@@ -97,6 +97,7 @@ struct _OperatingSystem {
gchar *kcmdline;
gchar *libc;
gchar *distrocode;
+ gchar *distroid;
gchar *distro;
gchar *hostname;
gchar *language;
@@ -123,6 +124,7 @@ struct _MemoryInfo {
struct _Distro {
gchar *distro;
gchar *codename;
+ gchar *id;
};
#define get_str(field_name,ptr) \
diff --git a/modules/computer.c b/modules/computer.c
index 6cd778e8..49a1511f 100644
--- a/modules/computer.c
+++ b/modules/computer.c
@@ -579,13 +579,18 @@ gchar *callback_os(void)
{
struct Info *info = info_new();
gchar *distro_icon;
+ gchar *distro;
info_set_view_type(info, SHELL_VIEW_DETAIL);
- distro_icon = computer->os->distrocode
+ distro_icon = computer->os->distroid
? idle_free(g_strdup_printf("distros/%s.svg",
- computer->os->distrocode))
+ computer->os->distroid))
: NULL;
+ distro = computer->os->distrocode
+ ? idle_free(g_strdup_printf("%s (%s)",
+ computer->os->distro, computer->os->distrocode))
+ : computer->os->distro;
struct InfoGroup *version_group =
info_add_group(
@@ -593,7 +598,7 @@ gchar *callback_os(void)
info_field(_("Command Line"), computer->os->kcmdline ?: _("Unknown")),
info_field(_("Version"), computer->os->kernel_version),
info_field(_("C Library"), computer->os->libc),
- info_field(_("Distribution"), computer->os->distro,
+ info_field(_("Distribution"), distro,
.value_has_vendor = TRUE,
.icon = distro_icon),
info_field_last());
diff --git a/modules/computer/os.c b/modules/computer/os.c
index 32e4e8cd..14f61e06 100644
--- a/modules/computer/os.c
+++ b/modules/computer/os.c
@@ -353,6 +353,7 @@ parse_os_release(void)
{
gchar *pretty_name = NULL;
gchar *id = NULL;
+ gchar *codename = NULL;
gchar **split, *contents, **line;
if (!g_file_get_contents("/usr/lib/os-release", &contents, NULL, NULL))
@@ -365,6 +366,8 @@ parse_os_release(void)
for (line = split; *line; line++) {
if (!strncmp(*line, "ID=", sizeof("ID=") - 1)) {
id = g_strdup(*line + strlen("ID="));
+ } else if (!strncmp(*line, "CODENAME=", sizeof("CODENAME=") - 1)) {
+ codename = g_strdup(*line + strlen("CODENAME="));
} else if (!strncmp(*line, "PRETTY_NAME=", sizeof("PRETTY_NAME=") - 1)) {
pretty_name = g_strdup(*line +
strlen("PRETTY_NAME=\""));
@@ -375,7 +378,7 @@ parse_os_release(void)
g_strfreev(split);
if (pretty_name)
- return (Distro) { .distro = pretty_name, .codename = id };
+ return (Distro) { .distro = pretty_name, .codename = codename, .id = id };
g_free(id);
return (Distro) {};
@@ -386,6 +389,7 @@ parse_lsb_release(void)
{
gchar *pretty_name = NULL;
gchar *id = NULL;
+ gchar *codename = NULL;
gchar **split, *contents, **line;
if (!hardinfo_spawn_command_line_sync("/usr/bin/lsb_release -di", &contents, NULL, NULL, NULL))
@@ -398,6 +402,8 @@ parse_lsb_release(void)
for (line = split; *line; line++) {
if (!strncmp(*line, "Distributor ID:\t", sizeof("Distributor ID:\t") - 1)) {
id = g_utf8_strdown(*line + strlen("Distributor ID:\t"), -1);
+ } else if (!strncmp(*line, "Codename:\t", sizeof("Codename:\t") - 1)) {
+ codename = g_utf8_strdown(*line + strlen("Codename:\t"), -1);
} else if (!strncmp(*line, "Description:\t", sizeof("Description:\t") - 1)) {
pretty_name = g_strdup(*line + strlen("Description:\t"));
}
@@ -406,7 +412,7 @@ parse_lsb_release(void)
g_strfreev(split);
if (pretty_name)
- return (Distro) { .distro = pretty_name, .codename = id };
+ return (Distro) { .distro = pretty_name, .codename = codename, .id = id };
g_free(id);
return (Distro) {};
@@ -510,6 +516,7 @@ computer_get_os(void)
Distro distro = detect_distro();
os->distro = g_strstrip(distro.distro);
+ os->distroid = distro.id;
os->distrocode = distro.codename;
/* Kernel and hostname info */