aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--hardinfo/info.c16
-rw-r--r--includes/computer.h9
-rw-r--r--includes/info.h7
-rw-r--r--modules/computer.c17
-rw-r--r--modules/computer/os.c98
-rw-r--r--pixmaps/distros/arch.pngbin0 -> 851 bytes
-rw-r--r--pixmaps/distros/deb.pngbin0 -> 842 bytes
-rw-r--r--pixmaps/distros/fedora.pngbin0 -> 309 bytes
-rw-r--r--shell/shell.c131
10 files changed, 185 insertions, 94 deletions
diff --git a/.gitignore b/.gitignore
index 97744313..b19644f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@ config.h
*~
arch/this
build/
+build-*/
test/build-*
po/*.old
diff --git a/hardinfo/info.c b/hardinfo/info.c
index 6209bc69..c54775ed 100644
--- a/hardinfo/info.c
+++ b/hardinfo/info.c
@@ -160,7 +160,7 @@ void info_set_reload_interval(struct Info *info, int setting)
info->reload_interval = setting;
}
-static void flatten_group(GString *output, const struct InfoGroup *group)
+static void flatten_group(GString *output, const struct InfoGroup *group, guint group_count)
{
guint i;
@@ -173,6 +173,9 @@ static void flatten_group(GString *output, const struct InfoGroup *group)
field = g_array_index(group->fields, struct InfoField, i);
+ if (field.icon)
+ g_string_append_printf(output, "$ITEM%d-%d$", group_count, i);
+
g_string_append_printf(output, "%s=%s\n", field.name, field.value);
if (field.free_value_on_flatten)
@@ -183,7 +186,7 @@ static void flatten_group(GString *output, const struct InfoGroup *group)
}
}
-static void flatten_shell_param(GString *output, const struct InfoGroup *group)
+static void flatten_shell_param(GString *output, const struct InfoGroup *group, guint group_count)
{
guint i;
@@ -199,6 +202,11 @@ static void flatten_shell_param(GString *output, const struct InfoGroup *group)
g_string_append_printf(output, "UpdateInterval$%s=%d\n",
field.name, field.update_interval);
}
+
+ if (field.icon) {
+ g_string_append_printf(output, "Icon$ITEM%d-%d$=%s\n",
+ group_count, i, field.icon);
+ }
}
}
@@ -247,8 +255,8 @@ gchar *info_flatten(struct Info *info)
struct InfoGroup group =
g_array_index(info->groups, struct InfoGroup, i);
- flatten_group(values, &group);
- flatten_shell_param(shell_param, &group);
+ flatten_group(values, &group, i);
+ flatten_shell_param(shell_param, &group, i);
if (group.fields)
g_array_free(group.fields, TRUE);
diff --git a/includes/computer.h b/includes/computer.h
index 05db78c3..57da9db3 100644
--- a/includes/computer.h
+++ b/includes/computer.h
@@ -27,6 +27,7 @@ typedef struct _MemoryInfo MemoryInfo;
typedef struct _UptimeInfo UptimeInfo;
typedef struct _LoadInfo LoadInfo;
typedef struct _DisplayInfo DisplayInfo;
+typedef struct _Distro Distro;
typedef struct _AlsaInfo AlsaInfo;
typedef struct _AlsaCard AlsaCard;
@@ -92,7 +93,8 @@ struct _Computer {
struct _OperatingSystem {
gchar *kernel;
gchar *libc;
- gchar *distrocode, *distro;
+ gchar *distrocode;
+ gchar *distro;
gchar *hostname;
gchar *language;
gchar *homedir;
@@ -113,6 +115,11 @@ struct _MemoryInfo {
gfloat ratio;
};
+struct _Distro {
+ gchar *distro;
+ gchar *codename;
+};
+
#define get_str(field_name,ptr) \
if (g_str_has_prefix(tmp[0], field_name)) { \
ptr = g_strdup(tmp[1]); \
diff --git a/includes/info.h b/includes/info.h
index 91eb0eaf..f244ceb4 100644
--- a/includes/info.h
+++ b/includes/info.h
@@ -47,6 +47,7 @@ struct InfoGroup {
struct InfoField {
const gchar *name;
const gchar *value;
+ const gchar *icon;
int update_interval;
@@ -67,6 +68,12 @@ struct InfoField info_field_printf(const gchar *name, const gchar *format, ...)
struct InfoField info_field_update(const gchar *name, int update_interval);
struct InfoField info_field_last(void);
+static inline struct InfoField info_field_with_icon(struct InfoField field, const gchar *icon)
+{
+ field.icon = icon;
+ return field;
+}
+
void info_set_column_title(struct Info *info, const gchar *column, const gchar *title);
void info_set_column_headers_visible(struct Info *info, gboolean setting);
void info_set_zebra_visible(struct Info *info, gboolean setting);
diff --git a/modules/computer.c b/modules/computer.c
index 5e81f386..4a893dac 100644
--- a/modules/computer.c
+++ b/modules/computer.c
@@ -545,12 +545,19 @@ gchar *callback_summary(void)
gchar *callback_os(void)
{
struct Info *info = info_new();
+ struct InfoField distro = info_field(_("Distribution"), computer->os->distro);
+
+ if (computer->os->distrocode) {
+ distro = info_field_with_icon(distro,
+ idle_free(g_strdup_printf("distros/%s.png",
+ computer->os->distrocode)));
+ }
info_add_group(info, _("Version"),
info_field(_("Kernel"), computer->os->kernel),
info_field(_("Version"), computer->os->kernel_version),
info_field(_("C Library"), computer->os->libc),
- info_field(_("Distribution"), computer->os->distro),
+ distro,
info_field_last());
info_add_group(info, _("Current Session"),
@@ -603,9 +610,11 @@ gchar *callback_security(void)
if (!contents)
continue;
- info_group_add_fields(vulns,
- info_field(vuln, idle_free(contents)),
- info_field_last());
+ struct InfoField field = info_field(vuln, idle_free(contents));
+ if (g_strstr_len(contents, -1, "Vulnerable"))
+ field = info_field_with_icon(field, "dialog-warning.png");
+
+ info_group_add_fields(vulns, field, info_field_last());
}
g_dir_close(dir);
diff --git a/modules/computer/os.c b/modules/computer/os.c
index 5872ff82..9d30b15e 100644
--- a/modules/computer/os.c
+++ b/modules/computer/os.c
@@ -347,34 +347,71 @@ computer_get_language(void)
return ret;
}
-static gchar *
+static Distro
parse_os_release(void)
{
gchar *pretty_name = NULL;
+ gchar *id = NULL;
gchar **split, *contents, **line;
if (!g_file_get_contents("/usr/lib/os-release", &contents, NULL, NULL))
- return NULL;
+ return (Distro) {};
split = g_strsplit(idle_free(contents), "\n", 0);
if (!split)
- return NULL;
+ return (Distro) {};
for (line = split; *line; line++) {
- if (!strncmp(*line, "PRETTY_NAME=", sizeof("PRETTY_NAME=") - 1)) {
+ if (!strncmp(*line, "ID=", sizeof("ID=") - 1)) {
+ id = g_strdup(*line + strlen("ID="));
+ } else if (!strncmp(*line, "PRETTY_NAME=", sizeof("PRETTY_NAME=") - 1)) {
pretty_name = g_strdup(*line +
- strlen("PRETTY_NAME=") + 1);
+ strlen("PRETTY_NAME=\""));
strend(pretty_name, '"');
- break;
}
}
g_strfreev(split);
- return pretty_name;
+ if (pretty_name)
+ return (Distro) { .distro = pretty_name, .codename = id };
+
+ g_free(id);
+ return (Distro) {};
}
-static gchar *
+static Distro
+parse_lsb_release(void)
+{
+ gchar *pretty_name = NULL;
+ gchar *id = NULL;
+ gchar **split, *contents, **line;
+
+ if (!g_spawn_command_line_sync("/usr/bin/lsb_release -di", &contents, NULL, NULL, NULL))
+ return (Distro) {};
+
+ split = g_strsplit(idle_free(contents), "\n", 0);
+ if (!split)
+ return (Distro) {};
+
+ 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, "Description:\t", sizeof("Description:\t") - 1)) {
+ pretty_name = g_strdup(*line + strlen("Description:\t"));
+ }
+ }
+
+ g_strfreev(split);
+
+ if (pretty_name)
+ return (Distro) { .distro = pretty_name, .codename = id };
+
+ g_free(id);
+ return (Distro) {};
+}
+
+static Distro
detect_distro(void)
{
static const struct {
@@ -389,7 +426,7 @@ detect_distro(void)
{ DB_PREFIX "slackware-version", "slk" },
{ DB_PREFIX "mandrake-release", "mdk" },
{ DB_PREFIX "mandriva-release", "mdv" },
- { DB_PREFIX "fedora-release", "fdra" },
+ { DB_PREFIX "fedora-release", "fedora" },
{ DB_PREFIX "coas", "coas" },
{ DB_PREFIX "environment.corel", "corel"},
{ DB_PREFIX "gentoo-release", "gnt" },
@@ -398,7 +435,6 @@ detect_distro(void)
{ DB_PREFIX "turbolinux-release", "tl" },
{ DB_PREFIX "yellowdog-release", "yd" },
{ DB_PREFIX "sabayon-release", "sbn" },
- { DB_PREFIX "arch-release", "arch" },
{ DB_PREFIX "enlisy-release", "enlsy" },
{ DB_PREFIX "SuSE-release", "suse" },
{ DB_PREFIX "sun-release", "sun" },
@@ -417,21 +453,17 @@ detect_distro(void)
#undef DB_PREFIX
{ NULL, NULL }
};
+ Distro distro;
gchar *contents;
int i;
- if (g_file_test("/usr/lib/os-release", G_FILE_TEST_EXISTS)) {
- contents = parse_os_release();
- if (contents)
- return contents;
- }
-
- if (g_spawn_command_line_sync("lsb_release -d", &contents, NULL, NULL, NULL)) {
- gchar *tmp = strstr(idle_free(contents), "Description:\t");
+ distro = parse_os_release();
+ if (distro.distro)
+ return distro;
- if (tmp)
- return g_strdup(tmp + strlen("Description:\t"));
- }
+ distro = parse_lsb_release();
+ if (distro.distro)
+ return distro;
for (i = 0; distro_db[i].file; i++) {
if (!g_file_get_contents(distro_db[i].file, &contents, NULL, NULL))
@@ -439,23 +471,31 @@ detect_distro(void)
if (distro_db[i].override) {
g_free(contents);
- return g_strdup(distro_db[i].override);
+ return (Distro) { .distro = g_strdup(distro_db[i].override),
+ .codename = g_strdup(distro_db[i].codename) };
}
if (g_str_equal(distro_db[i].codename, "deb")) {
/* HACK: Some Debian systems doesn't include the distribuition
* name in /etc/debian_release, so add them here. */
if (isdigit(contents[0]) || contents[0] != 'D')
- return g_strdup_printf("Debian GNU/Linux %s", (char*)idle_free(contents));
+ return (Distro) {
+ .distro = g_strdup_printf("Debian GNU/Linux %s", (char*)idle_free(contents)),
+ .codename = g_strdup(distro_db[i].codename)
+ };
}
- if (g_str_equal(distro_db[i].codename, "fatdog"))
- return g_strdup_printf("Fatdog64 [%.10s]", (char*)idle_free(contents));
+ if (g_str_equal(distro_db[i].codename, "fatdog")) {
+ return (Distro) {
+ .distro = g_strdup_printf("Fatdog64 [%.10s]", (char*)idle_free(contents)),
+ .codename = g_strdup(distro_db[i].codename)
+ };
+ }
- return contents;
+ return (Distro) { .distro = contents, .codename = g_strdup(distro_db[i].codename) };
}
- return g_strdup(_("Unknown"));
+ return (Distro) { .distro = g_strdup(_("Unknown")) };
}
OperatingSystem *
@@ -467,7 +507,9 @@ computer_get_os(void)
os = g_new0(OperatingSystem, 1);
- os->distro = g_strstrip(detect_distro());
+ Distro distro = detect_distro();
+ os->distro = g_strstrip(distro.distro);
+ os->distrocode = distro.codename;
/* Kernel and hostname info */
uname(&utsbuf);
diff --git a/pixmaps/distros/arch.png b/pixmaps/distros/arch.png
new file mode 100644
index 00000000..e2800c0e
--- /dev/null
+++ b/pixmaps/distros/arch.png
Binary files differ
diff --git a/pixmaps/distros/deb.png b/pixmaps/distros/deb.png
new file mode 100644
index 00000000..fe63aca6
--- /dev/null
+++ b/pixmaps/distros/deb.png
Binary files differ
diff --git a/pixmaps/distros/fedora.png b/pixmaps/distros/fedora.png
new file mode 100644
index 00000000..c6638f74
--- /dev/null
+++ b/pixmaps/distros/fedora.png
Binary files differ
diff --git a/shell/shell.c b/shell/shell.c
index 5fb125ee..5adb32b0 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -15,6 +15,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#define _GNU_SOURCE
+
#include <stdlib.h>
#include <string.h>
@@ -1149,9 +1151,17 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry,
set_view_type(g_key_file_get_integer(key_file, group,
key, NULL), reload);
} else if (g_str_has_prefix(key, "Icon$")) {
- GtkTreeIter *iter = g_hash_table_lookup(update_tbl,
- g_utf8_strchr(key,
- -1, '$') );
+ GtkTreeIter *iter;
+ const gchar *first_dollar = g_utf8_strchr(key, -1, '$');
+
+ iter = g_hash_table_lookup(update_tbl, first_dollar);
+ if (!iter && first_dollar) {
+ const gchar *second_dollar = g_utf8_strchr(first_dollar + 1, -1, '$');
+ if (second_dollar) {
+ char *copy = strndupa(first_dollar, second_dollar - first_dollar + 1);
+ iter = g_hash_table_lookup(update_tbl, copy);
+ }
+ }
if (iter) {
gchar *file =
@@ -1181,80 +1191,87 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry,
}
}
-static void
-group_handle_normal(GKeyFile * key_file, ShellModuleEntry * entry,
- gchar * group, gchar ** keys, gsize ngroups)
+static void group_handle_normal(GKeyFile* key_file, ShellModuleEntry* entry,
+ gchar* group, gchar** keys, gsize ngroups)
{
GtkTreeIter parent;
- GtkTreeStore *store = GTK_TREE_STORE(shell->info->model);
- gchar *tmp = g_strdup(group);
+ GtkTreeStore* store = GTK_TREE_STORE(shell->info->model);
+ gchar* tmp = g_strdup(group);
gint i;
if (ngroups > 1) {
- gtk_tree_store_append(store, &parent, NULL);
+ gtk_tree_store_append(store, &parent, NULL);
- strend(tmp, '#');
- gtk_tree_store_set(store, &parent, INFO_TREE_COL_NAME, tmp, -1);
- g_free(tmp);
+ strend(tmp, '#');
+ gtk_tree_store_set(store, &parent, INFO_TREE_COL_NAME, tmp, -1);
+ g_free(tmp);
}
for (i = 0; keys[i]; i++) {
- gchar *key = keys[i];
- gchar *value;
- GtkTreeIter child;
+ gchar* key = keys[i];
+ gchar* value;
+ GtkTreeIter child;
+
+ value = g_key_file_get_value(key_file, group, key, NULL);
+ if (entry->fieldfunc && value && g_str_equal(value, "...")) {
+ g_free(value);
+ value = entry->fieldfunc(key);
+ }
- value = g_key_file_get_value(key_file, group, key, NULL);
- if (entry->fieldfunc && value && g_str_equal(value, "...")) {
- g_free(value);
- value = entry->fieldfunc(key);
- }
+ if ((key && value) && g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) {
+ if (ngroups == 1) {
+ gtk_tree_store_append(store, &child, NULL);
+ } else {
+ gtk_tree_store_append(store, &child, &parent);
+ }
- if ((key && value) && g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) {
- if (ngroups == 1) {
- gtk_tree_store_append(store, &child, NULL);
- } else {
- gtk_tree_store_append(store, &child, &parent);
- }
+ /* FIXME: use g_key_file_get_string_list? */
+ if (g_utf8_strchr(value, -1, '|')) {
+ gchar** columns = g_strsplit(value, "|", 0);
+
+ gtk_tree_store_set(store, &child, INFO_TREE_COL_VALUE, columns[0], -1);
+ if (columns[1]) {
+ gtk_tree_store_set(store, &child, INFO_TREE_COL_EXTRA1, columns[1],
+ -1);
+ if (columns[2]) {
+ gtk_tree_store_set(store, &child, INFO_TREE_COL_EXTRA2, columns[2],
+ -1);
+ }
+ }
- /* FIXME: use g_key_file_get_string_list? */
- if (g_utf8_strchr(value, -1, '|')) {
- gchar **columns = g_strsplit(value, "|", 0);
+ g_strfreev(columns);
+ } else {
+ gtk_tree_store_set(store, &child, INFO_TREE_COL_VALUE, value, -1);
+ }
- gtk_tree_store_set(store, &child, INFO_TREE_COL_VALUE, columns[0], -1);
- if (columns[1]) {
- gtk_tree_store_set(store, &child, INFO_TREE_COL_EXTRA1, columns[1], -1);
- if (columns[2]) {
- gtk_tree_store_set(store, &child, INFO_TREE_COL_EXTRA2, columns[2], -1);
- }
- }
+ strend(key, '#');
- g_strfreev(columns);
- } else {
- gtk_tree_store_set(store, &child, INFO_TREE_COL_VALUE, value, -1);
- }
+ if (key_is_flagged(key)) {
+ const gchar* name = key_get_name(key);
+ gchar* flags = g_strdup(key);
+ *(strchr(flags + 1, '$') + 1) = 0;
- strend(key, '#');
+ gtk_tree_store_set(store, &child, INFO_TREE_COL_NAME, name,
+ INFO_TREE_COL_DATA, flags, -1);
- if (key_is_flagged(key)) {
- const gchar *name = key_get_name(key);
- gchar *flags = g_strdup(key);
- *(strchr(flags+1, '$')+1) = 0;
+ g_free(flags);
+ } else {
+ gtk_tree_store_set(store, &child, INFO_TREE_COL_NAME, key,
+ INFO_TREE_COL_DATA, NULL, -1);
+ }
- gtk_tree_store_set(store, &child, INFO_TREE_COL_NAME,
- name, INFO_TREE_COL_DATA, flags, -1);
+ const gchar *first_dollar = g_utf8_strchr(key, -1, '$');
+ if (first_dollar) {
+ const gchar *second_dollar = g_utf8_strchr(first_dollar + 1, -1, '$');
+ gchar *key_copy = g_strndup(first_dollar, second_dollar - first_dollar + 1);
- g_free(flags);
- } else {
- gtk_tree_store_set(store, &child, INFO_TREE_COL_NAME, key,
- INFO_TREE_COL_DATA, NULL, -1);
+ g_hash_table_insert(update_tbl, key_copy, gtk_tree_iter_copy(&child));
+ } else {
+ g_hash_table_insert(update_tbl, g_strdup(key), gtk_tree_iter_copy(&child));
+ }
}
- g_hash_table_insert(update_tbl, g_strdup(key),
- gtk_tree_iter_copy(&child));
-
- }
-
- g_free(value);
+ g_free(value);
}
}