Skip to content
Permalink
Browse files

computer/os: Ubuntu flavors

See: #404

Signed-off-by: Burt P <pburt0@gmail.com>
  • Loading branch information...
bp0 authored and lpereira committed Jul 6, 2019
1 parent 70dfa90 commit 754a87070910c336c7f62074aeac587374f85403
Showing with 166 additions and 6 deletions.
  1. +1 −0 CMakeLists.txt
  2. +14 −0 hardinfo/info.c
  3. +6 −0 includes/computer.h
  4. +1 −0 includes/info.h
  5. +33 −0 includes/ubuntu_flavors.h
  6. +13 −6 modules/computer.c
  7. +10 −0 modules/computer/os.c
  8. +88 −0 modules/computer/ubuntu_flavors.c
@@ -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
@@ -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);
}
}
@@ -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 {
@@ -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);

@@ -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
@@ -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),
@@ -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;
}

@@ -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;
}

0 comments on commit 754a870

Please sign in to comment.
You can’t perform that action at this time.