aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2019-07-11 20:51:37 -0500
committerLeandro Pereira <leandro@hardinfo.org>2019-07-11 20:31:37 -0700
commit3a333a773e524b8f167168e0b50025e0ba3bf9c9 (patch)
tree0123e52d7193da993b63bf9d89647ae81e52c7f3 /modules
parent89d149a497123e2841c50aaf7315e1ffa7e3f1f9 (diff)
info struct bug Fixes, add tagged update fields
* tag was always included even when it didn't need to be. Now only include it when tag specified, flagged, or includes an icon. This messed up the existing update fields system. * The update fields system has been changed to allow updating by tag instead of the translated label. By label still works, however. I think it would be best to switch to using tags in the future. * info_flatten() calls flatten_shell_param() after flatten_group() which could cause a field name or tag to be used after it was freed. Created special free functions to handle this after all is used. Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/computer.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/modules/computer.c b/modules/computer.c
index cc3e9be3..99257e9f 100644
--- a/modules/computer.c
+++ b/modules/computer.c
@@ -110,31 +110,42 @@ gchar *hi_more_info(gchar * entry)
return g_strdup_printf("[%s]", entry);
}
+/* a g_str_equal() where either may be null */
+#define g_str_equal0(a,b) (g_strcmp0(a,b) == 0)
+
gchar *hi_get_field(gchar * field)
{
+ gchar *tag, *label;
+ key_get_components(field, NULL, &tag, NULL, &label, NULL, TRUE);
+
gchar *tmp;
- if (g_str_equal(field, _("Memory"))) {
+ if (g_str_equal0(label, _("Memory"))) {
MemoryInfo *mi = computer_get_memory();
tmp = g_strdup_printf(_("%dMB (%dMB used)"), mi->total, mi->used);
g_free(mi);
- } else if (g_str_equal(field, _("Uptime"))) {
+ } else if (g_str_equal0(label, _("Uptime"))) {
tmp = computer_get_formatted_uptime();
- } else if (g_str_equal(field, _("Date/Time"))) {
+ } else if (g_str_equal0(label, _("Date/Time"))) {
time_t t = time(NULL);
tmp = g_new0(gchar, 64);
strftime(tmp, 64, "%c", localtime(&t));
- } else if (g_str_equal(field, _("Load Average"))) {
+ } else if (g_str_equal0(label, _("Load Average"))) {
tmp = computer_get_formatted_loadavg();
- } else if (g_str_equal(field, _("Available entropy in /dev/random"))) {
+ } else if (g_str_equal0(tag, "entropy")) {
tmp = computer_get_entropy_avail();
} else {
- gchar *info = moreinfo_lookup_with_prefix("DEV", field);
+ gchar *info = NULL;
+ if (tag)
+ info = moreinfo_lookup_with_prefix("DEV", tag);
+ else if (label)
+ info = moreinfo_lookup_with_prefix("DEV", label);
+
if (info)
tmp = g_strdup(info);
else
- tmp = g_strdup_printf("Unknown field: %s", field);
+ tmp = g_strdup_printf("Unknown field: [tag: %s] label: %s", tag ? tag : "(none)", label ? label : "(empty)");
}
return tmp;
}
@@ -600,7 +611,7 @@ gchar *callback_security(void)
info_add_group(
info, _("Health"),
- info_field_update(_("Available entropy in /dev/random"), 1000),
+ info_field_update(_("Available entropy in /dev/random"), 1000, .tag = g_strdup("entropy") ),
info_field_last());
info_add_group(