Inspector: Show directory sizes in the resource tab

This is makes it easy to answer the question: how much do resources
cost. It turns out that all the resources in GTK+ currently weigh
around 1MB.
This commit is contained in:
Matthias Clasen
2014-07-19 01:20:28 -04:00
parent a9201b8379
commit ea9026e3a0
2 changed files with 86 additions and 7 deletions

View File

@ -29,7 +29,9 @@
enum enum
{ {
COLUMN_NAME, COLUMN_NAME,
COLUMN_PATH COLUMN_PATH,
COLUMN_COUNT,
COLUMN_SIZE
}; };
struct _GtkInspectorResourceListPrivate struct _GtkInspectorResourceListPrivate
@ -38,7 +40,10 @@ struct _GtkInspectorResourceListPrivate
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
GtkWidget *image; GtkWidget *image;
GtkWidget *content; GtkWidget *content;
GtkWidget *type;
GtkWidget *type_label; GtkWidget *type_label;
GtkWidget *count;
GtkWidget *count_label;
GtkWidget *size_label; GtkWidget *size_label;
GtkWidget *info_grid; GtkWidget *info_grid;
}; };
@ -48,7 +53,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorResourceList, gtk_inspector_resource_lis
static void static void
load_resources_recurse (GtkInspectorResourceList *sl, load_resources_recurse (GtkInspectorResourceList *sl,
GtkTreeIter *parent, GtkTreeIter *parent,
const gchar *path) const gchar *path,
gint *count_out,
gsize *size_out)
{ {
gchar **names; gchar **names;
gint i; gint i;
@ -60,6 +67,8 @@ load_resources_recurse (GtkInspectorResourceList *sl,
gint len; gint len;
gchar *p; gchar *p;
gboolean has_slash; gboolean has_slash;
gint count;
gsize size;
p = g_strconcat (path, names[i], NULL); p = g_strconcat (path, names[i], NULL);
@ -75,8 +84,25 @@ load_resources_recurse (GtkInspectorResourceList *sl,
COLUMN_PATH, p, COLUMN_PATH, p,
-1); -1);
count = 0;
size = 0;
if (has_slash) if (has_slash)
load_resources_recurse (sl, &iter, p); {
load_resources_recurse (sl, &iter, p, &count, &size);
}
else
{
count = 1;
g_resources_get_info (p, 0, &size, NULL, NULL);
}
gtk_tree_store_set (sl->priv->model, &iter,
COLUMN_COUNT, count,
COLUMN_SIZE, size,
-1);
*count_out += count;
*size_out += size;
g_free (p); g_free (p);
} }
@ -97,6 +123,7 @@ selection_changed (GtkTreeSelection *selection,
GBytes *bytes; GBytes *bytes;
gchar *type; gchar *type;
gconstpointer data; gconstpointer data;
gint count;
gsize size; gsize size;
GError *error = NULL; GError *error = NULL;
@ -105,10 +132,28 @@ selection_changed (GtkTreeSelection *selection,
gtk_tree_model_get (GTK_TREE_MODEL (rl->priv->model), &iter, gtk_tree_model_get (GTK_TREE_MODEL (rl->priv->model), &iter,
COLUMN_PATH, &path, COLUMN_PATH, &path,
COLUMN_NAME, &name, COLUMN_NAME, &name,
COLUMN_COUNT, &count,
COLUMN_SIZE, &size,
-1); -1);
if (g_str_has_suffix (path, "/")) if (g_str_has_suffix (path, "/"))
{ {
gchar *text;
text = g_strdup_printf ("%d", count);
gtk_label_set_text (GTK_LABEL (rl->priv->count_label), text);
g_free (text);
text = g_format_size (size);
gtk_label_set_text (GTK_LABEL (rl->priv->size_label), text);
g_free (text);
gtk_widget_hide (rl->priv->type);
gtk_widget_hide (rl->priv->type_label);
gtk_widget_show (rl->priv->count);
gtk_widget_show (rl->priv->count_label);
gtk_widget_show (rl->priv->info_grid);
gtk_text_buffer_set_text (rl->priv->buffer, "", -1); gtk_text_buffer_set_text (rl->priv->buffer, "", -1);
gtk_stack_set_visible_child_name (GTK_STACK (rl->priv->content), "text"); gtk_stack_set_visible_child_name (GTK_STACK (rl->priv->content), "text");
goto out; goto out;
@ -135,6 +180,10 @@ selection_changed (GtkTreeSelection *selection,
gtk_label_set_text (GTK_LABEL (rl->priv->size_label), text); gtk_label_set_text (GTK_LABEL (rl->priv->size_label), text);
g_free (text); g_free (text);
gtk_widget_show (rl->priv->type);
gtk_widget_show (rl->priv->type_label);
gtk_widget_hide (rl->priv->count);
gtk_widget_hide (rl->priv->count_label);
gtk_widget_show (rl->priv->info_grid); gtk_widget_show (rl->priv->info_grid);
if (g_content_type_is_a (type, "text/*")) if (g_content_type_is_a (type, "text/*"))
@ -170,8 +219,10 @@ out:
static void static void
load_resources (GtkInspectorResourceList *sl) load_resources (GtkInspectorResourceList *sl)
{ {
gint count = 0;
gsize size = 0;
load_resources_recurse (sl, NULL, "/"); load_resources_recurse (sl, NULL, "/", &count, &size);
} }
static void static void
@ -193,6 +244,9 @@ gtk_inspector_resource_list_class_init (GtkInspectorResourceListClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, content); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, content);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, image); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, image);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, type_label); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, type_label);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, type);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, count_label);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, count);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, size_label); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, size_label);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, info_grid); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, info_grid);

View File

@ -4,6 +4,8 @@
<columns> <columns>
<column type="gchararray"/> <column type="gchararray"/>
<column type="gchararray"/> <column type="gchararray"/>
<column type="gint"/>
<column type="guint64"/>
</columns> </columns>
</object> </object>
<object class="GtkTextBuffer" id="buffer"> <object class="GtkTextBuffer" id="buffer">
@ -55,7 +57,7 @@
<property name="column-spacing">10</property> <property name="column-spacing">10</property>
<property name="margin">20</property> <property name="margin">20</property>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel" id="type">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Type:</property> <property name="label" translatable="yes">Type:</property>
<property name="halign">end</property> <property name="halign">end</property>
@ -77,6 +79,29 @@
<property name="top-attach">0</property> <property name="top-attach">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="count">
<property name="visible">True</property>
<property name="label" translatable="yes">Count:</property>
<property name="halign">end</property>
<property name="valign">baseline</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="count_label">
<property name="visible">True</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">True</property> <property name="visible">True</property>
@ -86,7 +111,7 @@
</object> </object>
<packing> <packing>
<property name="left-attach">0</property> <property name="left-attach">0</property>
<property name="top-attach">1</property> <property name="top-attach">2</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -97,7 +122,7 @@
</object> </object>
<packing> <packing>
<property name="left-attach">1</property> <property name="left-attach">1</property>
<property name="top-attach">1</property> <property name="top-attach">2</property>
</packing> </packing>
</child> </child>
</object> </object>