aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2019-07-06 15:22:26 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2019-07-10 12:24:36 -0700
commit754a87070910c336c7f62074aeac587374f85403 (patch)
tree513b0b5c0dc3778c9f4ea66abcc32bf8dffb8aa3 /modules
parent70dfa900d53588dfda6fd1e12a47d9313e89c413 (diff)
computer/os: Ubuntu flavors
See: https://github.com/lpereira/hardinfo/issues/404 Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/computer.c19
-rw-r--r--modules/computer/os.c10
-rw-r--r--modules/computer/ubuntu_flavors.c88
3 files changed, 111 insertions, 6 deletions
diff --git a/modules/computer.c b/modules/computer.c
index 8e867275..95614ca7 100644
--- a/modules/computer.c
+++ b/modules/computer.c
@@ -556,6 +556,7 @@ gchar *callback_os(void)
computer->os->distrocode))
: NULL;
+ struct InfoGroup *version_group =
info_add_group(
info, _("Version"), info_field(_("Kernel"), computer->os->kernel),
info_field(_("Command Line"), computer->os->kcmdline ?: _("Unknown")),
@@ -565,13 +566,19 @@ gchar *callback_os(void)
.icon = distro_icon),
info_field_last());
+ if (computer->os->ubuntu_flavor) {
+ info_group_add_field(version_group,
+ info_field(_("Spin/Flavor"), computer->os->ubuntu_flavor->name,
+ .icon = computer->os->ubuntu_flavor->icon) );
+ }
+
info_add_group(info, _("Current Session"),
- info_field(_("Computer Name"), computer->os->hostname),
- info_field(_("User Name"), computer->os->username),
- info_field(_("Language"), computer->os->language),
- info_field(_("Home Directory"), computer->os->homedir),
- info_field(_("Desktop Environment"), computer->os->desktop),
- info_field_last());
+ info_field(_("Computer Name"), computer->os->hostname),
+ info_field(_("User Name"), computer->os->username),
+ info_field(_("Language"), computer->os->language),
+ info_field(_("Home Directory"), computer->os->homedir),
+ info_field(_("Desktop Environment"), computer->os->desktop),
+ info_field_last());
info_add_group(info, _("Misc"), info_field_update(_("Uptime"), 1000),
info_field_update(_("Load Average"), 10000),
diff --git a/modules/computer/os.c b/modules/computer/os.c
index 536d328f..dae93761 100644
--- a/modules/computer/os.c
+++ b/modules/computer/os.c
@@ -21,6 +21,7 @@
#include <sys/utsname.h>
#include "hardinfo.h"
#include "computer.h"
+#include "ubuntu_flavors.h"
static gchar *
get_libc_version(void)
@@ -531,6 +532,15 @@ computer_get_os(void)
os->entropy_avail = computer_get_entropy_avail();
+ if (g_strcmp0(os->distrocode, "ubuntu") == 0) {
+ GSList *flavs = ubuntu_flavors_scan();
+ if (flavs) {
+ /* just use the first one */
+ os->ubuntu_flavor = (UbuntuFlavor*)flavs->data;
+ }
+ g_slist_free(flavs);
+ }
+
return os;
}
diff --git a/modules/computer/ubuntu_flavors.c b/modules/computer/ubuntu_flavors.c
new file mode 100644
index 00000000..d6933604
--- /dev/null
+++ b/modules/computer/ubuntu_flavors.c
@@ -0,0 +1,88 @@
+/*
+ * HardInfo - Displays System Information
+ * Copyright (C) 2003-2019 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * This file Burt P. <pburt0@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <hardinfo.h>
+#include "ubuntu_flavors.h"
+
+#include "dt_util.h" /* for appf() */
+#define SEQ(s,m) (g_strcmp0(s, m) == 0)
+
+static const UbuntuFlavor ubuntu_flavors[] = {
+ { "ubuntu-server", "Vanilla Server", "distros/ubuntu.png", "https://ubuntu.org/" },
+ { "ubuntu-desktop", "Ubuntu GNOME", "distros/ubuntu.png", "https://ubuntu.org/" },
+ { "xubuntu-desktop", "Xubuntu", "distros/xubuntu.png", "https://xubuntu.org/" },
+ { "kubuntu-desktop", "Kubuntu", "distros/kubuntu.png", "https://kubuntu.org/" },
+ { "lubuntu-desktop", "Lubuntu", "distros/lubuntu.png", "https://lubuntu.me/" }, /* formerly or also lubuntu.net? */
+ { "ubuntu-mate-desktop", "Ubuntu MATE", "distros/ubuntu-mate.png", "https://ubuntu-mate.org/" },
+ { "ubuntu-budgie-desktop", "Ubuntu Budgie", "distros/ubuntu-budgie.png", "https://ubuntubudgie.org/" },
+ { "ubuntukylin-desktop", "UbuntuKylin (做最有中国味的操作系统)", "distros/ubuntu-kylin.png", "https://www.ubuntukylin.com" },
+ { "ubuntustudio-desktop", "UbuntuStudio", "distros/ubuntu-studio.png", "https://ubuntustudio.org/"},
+ { NULL }
+};
+
+static const UbuntuFlavor *_find_flavor(const gchar *pkg) {
+ int i = 0;
+ for(; ubuntu_flavors[i].name; i++) {
+ if (SEQ(ubuntu_flavors[i].package, pkg))
+ return &ubuntu_flavors[i];
+ }
+ return NULL;
+}
+
+/* items are const; free with g_slist_free() */
+GSList *ubuntu_flavors_scan(void) {
+ GSList *ret = NULL;
+ gboolean spawned;
+ gchar *out, *err, *p, *next_nl;
+ gint exit_status;
+ const UbuntuFlavor *f = NULL;
+ gchar *cmd_line = g_strdup("apt-cache policy");
+ int i;
+ for(i = 0; ubuntu_flavors[i].name; i++) {
+ cmd_line = appf(cmd_line, "%s", ubuntu_flavors[i].package);
+ }
+ if (!i)
+ return NULL;
+
+ spawned = g_spawn_command_line_sync(cmd_line,
+ &out, &err, &exit_status, NULL);
+ if (spawned) {
+ p = out;
+ while(next_nl = strchr(p, '\n')) {
+ strend(p, '\n');
+ int mc = 0;
+ char pkg[32] = "";
+ if (*p != ' ' && *p != '\t')
+ mc = sscanf(p, "%31s", pkg);
+ if (mc == 1) {
+ strend(pkg, ':');
+ f = _find_flavor(pkg);
+ } else if
+ (g_strstr_len(p, -1, "Installed:")
+ && !g_strstr_len(p, -1, "(none)") ) {
+ ret = g_slist_append(ret, (void*)f);
+ }
+ p = next_nl + 1;
+ }
+ g_free(out);
+ g_free(err);
+ }
+ g_free(cmd_line);
+ return ret;
+}