Skip to content

Commit

Permalink
summary: remove extra columns from storage/input dev. values
Browse files Browse the repository at this point in the history
  • Loading branch information
ocerman authored and lpereira committed Dec 30, 2019
1 parent dac822a commit 7eabf4b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
33 changes: 33 additions & 0 deletions hardinfo/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ struct InfoField info_field_printf(const gchar *name, const gchar *format, ...)
};
}

static void info_group_strip_extra(struct InfoGroup *group)
{
guint fi;
char *val, *oldval;
struct InfoField *field;

for (fi = 0; fi < group->fields->len; fi++) {
field = &g_array_index(group->fields, struct InfoField, fi);
if (field->value){
val = strrchr(field->value, '|');
if (val) {
oldval = field->value;
field->value = strdup(val + 1);
g_free(oldval);
}
}
}
}

void info_add_computed_group(struct Info *info, const gchar *name, const gchar *value)
{
/* This is a scaffolding method: HardInfo should move away from pre-computing
Expand Down Expand Up @@ -137,6 +156,20 @@ void info_add_computed_group(struct Info *info, const gchar *name, const gchar *
g_free(tmp_str);
}

void info_add_computed_group_wo_extra(struct Info *info, const gchar *name, const gchar *value)
{
/* This is a scaffolding method: HardInfo should move away from pre-computing
* the strings in favor of storing InfoGroups instead; while modules are not
* fully converted, use this instead. */
struct InfoGroup *agroup;

info_add_computed_group(info, name, value);
if (info->groups->len > 0) {
agroup = &g_array_index(info->groups, struct InfoGroup, info->groups->len - 1);
info_group_strip_extra(agroup);
}
}

void info_set_column_title(struct Info *info, const gchar *column, const gchar *title)
{
int i;
Expand Down
2 changes: 2 additions & 0 deletions includes/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ struct InfoField {
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_add_computed_group_wo_extra(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, ...);
Expand Down
4 changes: 2 additions & 2 deletions modules/computer.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ gchar *callback_summary(void)

info_add_computed_group(info, _("Audio Devices"),
idle_free(computer_get_alsacards(computer)));
info_add_computed_group(info, _("Input Devices"),
info_add_computed_group_wo_extra(info, _("Input Devices"),
idle_free(module_call_method("devices::getInputDevices")));
info_add_computed_group(info, NULL, /* getPrinters provides group headers */
idle_free(module_call_method("devices::getPrinters")));
info_add_computed_group(info, NULL, /* getStorageDevices provides group headers */
info_add_computed_group_wo_extra(info, NULL, /* getStorageDevices provides group headers */
idle_free(module_call_method("devices::getStorageDevices")));

return info_flatten(info);
Expand Down

0 comments on commit 7eabf4b

Please sign in to comment.