diff options
| -rw-r--r-- | hardinfo/info.c | 15 | ||||
| -rw-r--r-- | includes/info.h | 7 | ||||
| -rw-r--r-- | shell/shell.c | 129 | 
3 files changed, 89 insertions, 62 deletions
| diff --git a/hardinfo/info.c b/hardinfo/info.c index 6209bc69..41f2547f 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,7 +173,7 @@ static void flatten_group(GString *output, const struct InfoGroup *group)              field = g_array_index(group->fields, struct InfoField, i); -            g_string_append_printf(output, "%s=%s\n", field.name, field.value); +            g_string_append_printf(output, "$ITEM%d-%d$%s=%s\n", group_count, i, field.name, field.value);              if (field.free_value_on_flatten)                  g_free((gchar *)field.value); @@ -183,7 +183,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 +199,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 +252,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/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/shell/shell.c b/shell/shell.c index 5fb125ee..5d346860 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,85 @@ 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)); +            }          } -	    g_hash_table_insert(update_tbl, g_strdup(key), -				gtk_tree_iter_copy(&child)); - -	} - -	g_free(value); +        g_free(value);      }  } | 
