some more work for
- beautify the text output - make gtk1 textbox implementation usable (I hope) svn path=/trunk/; revision=13506
This commit is contained in:
parent
3d0fbb8c63
commit
ca67abe524
|
@ -29,6 +29,13 @@
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <epan/stats_tree_priv.h>
|
#include <epan/stats_tree_priv.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO:
|
||||||
|
- sort out the sorting issue
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/* used to contain the registered stat trees */
|
/* used to contain the registered stat trees */
|
||||||
static GHashTable* registry = NULL;
|
static GHashTable* registry = NULL;
|
||||||
|
@ -70,34 +77,70 @@ extern guint8* stat_node_to_str(const stat_node* node,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
/* populates the given GString with a tree representation of a branch given by node,
|
||||||
using indent spaces as initial indentation */
|
using indent spaces as initial indentation */
|
||||||
extern void stat_branch_to_str(const stat_node* node, GString* s, guint indent) {
|
extern void stat_branch_to_str(const stat_node* node, GString* s, guint indent) {
|
||||||
stat_node* child;
|
stat_node* child;
|
||||||
static gchar indentation[INDENT_MAX];
|
static gchar indentation[INDENT_MAX+1];
|
||||||
static gchar value[NUM_BUF_SIZE];
|
static gchar value[NUM_BUF_SIZE];
|
||||||
static gchar rate[NUM_BUF_SIZE];
|
static gchar rate[NUM_BUF_SIZE];
|
||||||
static gchar percent[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);
|
get_strings_from_node(node, value, rate, percent);
|
||||||
|
|
||||||
indent = indent > INDENT_MAX ? INDENT_MAX : indent;
|
indent = indent > INDENT_MAX ? INDENT_MAX : indent;
|
||||||
|
|
||||||
/* fill indentation with indent spaces */
|
/* fill indentation with indent spaces */
|
||||||
for ( i = 0 ; i<(indent-1); i++) indentation[i] = ' ';
|
if (indent > 0) {
|
||||||
indentation[i] = '\0';
|
while(i<indent)
|
||||||
|
indentation[i++] = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
g_string_sprintfa(s,"%s%s\t%s\t%s\t%s\n",
|
indentation[i++] = '\0';
|
||||||
|
|
||||||
|
g_string_sprintfa(s,format,
|
||||||
indentation,node->name,value,rate,percent);
|
indentation,node->name,value,rate,percent);
|
||||||
|
|
||||||
if (node->children) {
|
if (node->children) {
|
||||||
for (child = node->children; child; child = child->next ) {
|
for (child = node->children; child; child = child->next ) {
|
||||||
stat_branch_to_str(child,s,indent+1);
|
stat_branch_to_str(child,s,indent+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (indent == 0) {
|
||||||
|
g_free(format);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* frees the resources allocated by a stat_tree node */
|
/* frees the resources allocated by a stat_tree node */
|
||||||
static void free_stat_node( stat_node* node ) {
|
static void free_stat_node( stat_node* node ) {
|
||||||
stat_node* child;
|
stat_node* child;
|
||||||
|
@ -193,7 +236,7 @@ extern void register_stats_tree(guint8* tapname,
|
||||||
st->filter = NULL;
|
st->filter = NULL;
|
||||||
|
|
||||||
st->root.counter = 0;
|
st->root.counter = 0;
|
||||||
st->root.name = STAT_TREE_ROOT;
|
st->root.name = g_strdup(name);
|
||||||
st->root.st = st;
|
st->root.st = st;
|
||||||
st->root.parent = NULL;
|
st->root.parent = NULL;
|
||||||
st->root.children = NULL;
|
st->root.children = NULL;
|
||||||
|
|
|
@ -172,6 +172,9 @@ extern void stat_branch_to_str(const stat_node* node,
|
||||||
GString* s,
|
GString* s,
|
||||||
guint indent);
|
guint indent);
|
||||||
|
|
||||||
|
/* used to calcuate the size of the indentation and the longest string */
|
||||||
|
extern guint stats_branch_max_name_len(const stat_node* node, guint indent);
|
||||||
|
|
||||||
/* a text representation of a node,
|
/* a text representation of a node,
|
||||||
if buffer is NULL returns a newly allocated string */
|
if buffer is NULL returns a newly allocated string */
|
||||||
extern guint8* stat_node_to_str(const stat_node* node,
|
extern guint8* stat_node_to_str(const stat_node* node,
|
||||||
|
|
|
@ -69,7 +69,7 @@ struct _tree_pres {
|
||||||
GtkTreeStore* store;
|
GtkTreeStore* store;
|
||||||
GtkWidget* tree;
|
GtkWidget* tree;
|
||||||
#else
|
#else
|
||||||
GtkText* textbox;
|
struct GtkText* textbox;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -134,6 +134,8 @@ static void draw_gtk_node(stat_node* node) {
|
||||||
draw_gtk_node(child);
|
draw_gtk_node(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static void draw_gtk_node(stat_node* node _U_) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void draw_gtk_tree( void *psp ) {
|
static void draw_gtk_tree( void *psp ) {
|
||||||
|
@ -147,16 +149,24 @@ static void draw_gtk_tree( void *psp ) {
|
||||||
gtk_tree_view_set_model(GTK_TREE_VIEW(st->pr->tree),GTK_TREE_MODEL(st->pr->store));
|
gtk_tree_view_set_model(GTK_TREE_VIEW(st->pr->tree),GTK_TREE_MODEL(st->pr->store));
|
||||||
#else
|
#else
|
||||||
GString* text = g_string_new("");
|
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 ) {
|
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_freeze(st->pr->textbox);
|
||||||
gtk_text_set_point(st->textbox,0);
|
gtk_text_set_point(st->pr->textbox,0);
|
||||||
gtk_text_forward_delete(st->textbox,gtk_text_get_length(st->textbox));
|
gtk_text_forward_delete(st->pr->textbox,gtk_text_get_length(st->pr->textbox));
|
||||||
gtk_text_insert(st->textbox,NULL,st->textbox->style->black,NULL,text->str,-1);
|
gtk_text_insert(st->pr->textbox,NULL,
|
||||||
gtk_text_thaw(st->textbox);
|
NULL,NULL,text->str,-1);
|
||||||
|
gtk_text_thaw(st->pr->textbox);
|
||||||
|
|
||||||
g_string_free(text,TRUE);
|
g_string_free(text,TRUE);
|
||||||
#endif
|
#endif
|
||||||
|
@ -172,8 +182,10 @@ static void free_gtk_tree(GtkWindow *win _U_, stats_tree *st)
|
||||||
remove_tap_listener(st);
|
remove_tap_listener(st);
|
||||||
unprotect_thread_critical_region();
|
unprotect_thread_critical_region();
|
||||||
|
|
||||||
|
#if GTK_MAJOR_VERSION >= 2
|
||||||
if (st->root.pr)
|
if (st->root.pr)
|
||||||
st->root.pr->iter = NULL;
|
st->root.pr->iter = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,10 +196,10 @@ static void init_gtk_tree(char* optarg) {
|
||||||
guint8* title = NULL;
|
guint8* title = NULL;
|
||||||
guint8* window_name = NULL;
|
guint8* window_name = NULL;
|
||||||
GString* error_string;
|
GString* error_string;
|
||||||
|
GtkWidget *scr_win;
|
||||||
#if GTK_MAJOR_VERSION >= 2
|
#if GTK_MAJOR_VERSION >= 2
|
||||||
GtkTreeViewColumn* column;
|
GtkTreeViewColumn* column;
|
||||||
GtkCellRenderer* renderer;
|
GtkCellRenderer* renderer;
|
||||||
GtkWidget *scr_win;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (abbr) {
|
if (abbr) {
|
||||||
|
@ -222,9 +234,10 @@ static void init_gtk_tree(char* optarg) {
|
||||||
|
|
||||||
gtk_window_set_title(GTK_WINDOW(st->pr->win), title);
|
gtk_window_set_title(GTK_WINDOW(st->pr->win), title);
|
||||||
g_free(title);
|
g_free(title);
|
||||||
|
|
||||||
#if GTK_MAJOR_VERSION >= 2
|
|
||||||
scr_win = scrolled_window_new(NULL, NULL);
|
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,
|
st->pr->store = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
|
||||||
G_TYPE_STRING, G_TYPE_STRING);
|
G_TYPE_STRING, G_TYPE_STRING);
|
||||||
|
@ -268,7 +281,8 @@ static void init_gtk_tree(char* optarg) {
|
||||||
gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (st->pr->tree), column);
|
gtk_tree_view_append_column (GTK_TREE_VIEW (st->pr->tree), column);
|
||||||
#else
|
#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(scr_win), st->pr->textbox);
|
||||||
gtk_container_add( GTK_CONTAINER(st->pr->win), scr_win);
|
gtk_container_add( GTK_CONTAINER(st->pr->win), scr_win);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue