#include <glib.h>
#include <epan/stats_tree_priv.h>
+#include <string.h>
+
+/*
+TODO:
+ - sort out the sorting issue
+
+ */
/* used to contain the registered stat trees */
static GHashTable* registry = NULL;
}
}
+extern guint stats_branch_max_name_len(const stat_node* node, guint indent) {
+ stat_node* child;
+ guint maxlen = 0;
+ guint len;
+
+ indent = indent > INDENT_MAX ? INDENT_MAX : indent;
+
+ if (node->children) {
+ for (child = node->children; child; child = child->next ) {
+ len = stats_branch_max_name_len(child,indent+1);
+ maxlen = len > maxlen ? len : maxlen;
+ }
+ }
+
+ len = strlen(node->name) + indent;
+ maxlen = len > maxlen ? len : maxlen;
+
+ return maxlen;
+}
+
+static gchar* format;
+
/* populates the given GString with a tree representation of a branch given by node,
using indent spaces as initial indentation */
extern void stat_branch_to_str(const stat_node* node, GString* s, guint indent) {
stat_node* child;
- static gchar indentation[INDENT_MAX];
+ static gchar indentation[INDENT_MAX+1];
static gchar value[NUM_BUF_SIZE];
static gchar rate[NUM_BUF_SIZE];
static gchar percent[NUM_BUF_SIZE];
- guint i;
+
+ guint i = 0;
+
+ if (indent == 0) {
+ format = g_strdup_printf(" %%s%%-%us%%12s\t%%12s\t%%12s\n",stats_branch_max_name_len(node,0));
+ }
get_strings_from_node(node, value, rate, percent);
indent = indent > INDENT_MAX ? INDENT_MAX : indent;
/* fill indentation with indent spaces */
- for ( i = 0 ; i<(indent-1); i++) indentation[i] = ' ';
- indentation[i] = '\0';
+ if (indent > 0) {
+ while(i<indent)
+ indentation[i++] = ' ';
+ }
- g_string_sprintfa(s,"%s%s\t%s\t%s\t%s\n",
- indentation,node->name,value,rate,percent);
+ indentation[i++] = '\0';
+ g_string_sprintfa(s,format,
+ indentation,node->name,value,rate,percent);
+
if (node->children) {
for (child = node->children; child; child = child->next ) {
stat_branch_to_str(child,s,indent+1);
}
}
+
+ if (indent == 0) {
+ g_free(format);
+ }
}
+
/* frees the resources allocated by a stat_tree node */
static void free_stat_node( stat_node* node ) {
stat_node* child;
st->filter = NULL;
st->root.counter = 0;
- st->root.name = STAT_TREE_ROOT;
+ st->root.name = g_strdup(name);
st->root.st = st;
st->root.parent = NULL;
st->root.children = NULL;
GtkTreeStore* store;
GtkWidget* tree;
#else
- GtkText* textbox;
+ struct GtkText* textbox;
#endif
};
draw_gtk_node(child);
}
}
+#else
+static void draw_gtk_node(stat_node* node _U_) {}
#endif
static void draw_gtk_tree( void *psp ) {
gtk_tree_view_set_model(GTK_TREE_VIEW(st->pr->tree),GTK_TREE_MODEL(st->pr->store));
#else
GString* text = g_string_new("");
+ gchar* fmt;
+
+ fmt = g_strdup_printf(" %%s%%-%us%%12s\t%%12s\t%%12s\n",stats_branch_max_name_len(&st->root,0));
+ g_string_sprintfa(text,fmt,"",st->name,"value","rate","percent");
+ g_free(fmt);
+ g_string_sprintfa(text,"-------------------------------------------------------------------\n");
+
for (child = st->root.children; child; child = child->next ) {
- stat_node_to_str(child,text,0);
+ stat_branch_to_str(child,text,0);
}
- gtk_text_freeze(st->textbox);
- gtk_text_set_point(st->textbox,0);
- gtk_text_forward_delete(st->textbox,gtk_text_get_length(st->textbox));
- gtk_text_insert(st->textbox,NULL,st->textbox->style->black,NULL,text->str,-1);
- gtk_text_thaw(st->textbox);
+ gtk_text_freeze(st->pr->textbox);
+ gtk_text_set_point(st->pr->textbox,0);
+ gtk_text_forward_delete(st->pr->textbox,gtk_text_get_length(st->pr->textbox));
+ gtk_text_insert(st->pr->textbox,NULL,
+ NULL,NULL,text->str,-1);
+ gtk_text_thaw(st->pr->textbox);
g_string_free(text,TRUE);
#endif
remove_tap_listener(st);
unprotect_thread_critical_region();
+#if GTK_MAJOR_VERSION >= 2
if (st->root.pr)
st->root.pr->iter = NULL;
+#endif
}
guint8* title = NULL;
guint8* window_name = NULL;
GString* error_string;
+ GtkWidget *scr_win;
#if GTK_MAJOR_VERSION >= 2
GtkTreeViewColumn* column;
GtkCellRenderer* renderer;
- GtkWidget *scr_win;
#endif
if (abbr) {
gtk_window_set_title(GTK_WINDOW(st->pr->win), title);
g_free(title);
-
-#if GTK_MAJOR_VERSION >= 2
+
scr_win = scrolled_window_new(NULL, NULL);
+
+#if GTK_MAJOR_VERSION >= 2
st->pr->store = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_append_column (GTK_TREE_VIEW (st->pr->tree), column);
#else
- pr->textbox = gtk_text_new(NULL,NULL);
+ st->pr->textbox = gtk_text_new(NULL,NULL);
+ gtk_text_set_editable(st->pr->textbox,TRUE);
gtk_container_add( GTK_CONTAINER(scr_win), st->pr->textbox);
gtk_container_add( GTK_CONTAINER(st->pr->win), scr_win);
#endif