diff options
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | hardinfo/info.c | 14 | ||||
| -rw-r--r-- | includes/computer.h | 6 | ||||
| -rw-r--r-- | includes/info.h | 1 | ||||
| -rw-r--r-- | includes/ubuntu_flavors.h | 33 | ||||
| -rw-r--r-- | modules/computer.c | 19 | ||||
| -rw-r--r-- | modules/computer/os.c | 10 | ||||
| -rw-r--r-- | modules/computer/ubuntu_flavors.c | 88 | 
8 files changed, 166 insertions, 6 deletions
| diff --git a/CMakeLists.txt b/CMakeLists.txt index f4a970e3..2fd2542e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,7 @@ set(MODULE_computer_SOURCES  	modules/computer/memory_usage.c  	modules/computer/modules.c  	modules/computer/os.c +	modules/computer/ubuntu_flavors.c  	modules/computer/uptime.c  	modules/computer/users.c  	modules/computer/groups.c diff --git a/hardinfo/info.c b/hardinfo/info.c index 57e67ce6..c082791b 100644 --- a/hardinfo/info.c +++ b/hardinfo/info.c @@ -35,13 +35,27 @@ struct Info *info_new(void)      return info;  } +void info_group_add_field(struct InfoGroup *group, struct InfoField field) +{ +    if (!group) +        return; + +    /* info_field_last() */ +    if (!field.name) +        return; + +    g_array_append_val(group->fields, field); +} +  void info_group_add_fieldsv(struct InfoGroup *group, va_list ap)  {      while (1) {          struct InfoField field = va_arg(ap, struct InfoField); +        /* info_field_last() */          if (!field.name)              break; +          g_array_append_val(group->fields, field);      }  } diff --git a/includes/computer.h b/includes/computer.h index fe427ef8..d01e1f2f 100644 --- a/includes/computer.h +++ b/includes/computer.h @@ -90,6 +90,8 @@ struct _Computer {      gchar *date_time;  }; +#include "ubuntu_flavors.h" +  struct _OperatingSystem {      gchar *kernel;      gchar *kcmdline; @@ -109,6 +111,10 @@ struct _OperatingSystem {      gchar *boots;      gchar *entropy_avail; + +    /* perhaps this could union with a flavors/spins +     * pointer for other distro families */ +    const UbuntuFlavor* ubuntu_flavor;  };  struct _MemoryInfo { diff --git a/includes/info.h b/includes/info.h index 1ac16dd5..5ccec9d5 100644 --- a/includes/info.h +++ b/includes/info.h @@ -75,6 +75,7 @@ struct Info *info_new(void);  struct InfoGroup *info_add_group(struct Info *info, const gchar *group_name, ...);  void info_add_computed_group(struct Info *info, const gchar *name, const gchar *value); +void info_group_add_field(struct InfoGroup *group, struct InfoField field);  void info_group_add_fields(struct InfoGroup *group, ...);  void info_group_add_fieldsv(struct InfoGroup *group, va_list ap); diff --git a/includes/ubuntu_flavors.h b/includes/ubuntu_flavors.h new file mode 100644 index 00000000..ea21ddb9 --- /dev/null +++ b/includes/ubuntu_flavors.h @@ -0,0 +1,33 @@ +/* + *    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 + */ + +#ifndef __UBUNTU_FLAVORS_H__ +#define __UBUNTU_FLAVORS_H__ + +typedef struct UbuntuFlavor { +    const char *package; +    const char *name; +    const char *icon; +    const char *url; +} UbuntuFlavor; + +/* items are const; free with g_slist_free() */ +GSList *ubuntu_flavors_scan(void); + +#endif 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; +} | 
