void StatsTreeDialog::fillTree()
{
    GString *error_string;
    if (!st_cfg_ || file_closed_) return;

    gchar* display_name_temp = stats_tree_get_displayname(st_cfg_->name);
    QString display_name(display_name_temp);
    g_free(display_name_temp);

    // The GTK+ UI appends "Stats Tree" to the window title. If we do the same
    // here we should expand the name completely, e.g. to "Statistics Tree".
    setWindowSubtitle(display_name);

    st_cfg_->pr = &cfg_pr_;
    cfg_pr_.st_dlg = this;

    if (st_) {
        stats_tree_free(st_);
    }
    st_ = stats_tree_new(st_cfg_, NULL, ui->displayFilterLineEdit->text().toUtf8().constData());

    // Add number of columns for this stats_tree
    QStringList headerLabels;
    for (int count = 0; count<st_->num_columns; count++) {
        headerLabels.push_back(stats_tree_get_column_name(count));
    }
    ui->statsTreeWidget->setColumnCount(headerLabels.count());
    ui->statsTreeWidget->setHeaderLabels(headerLabels);
    resize(st_->num_columns*80+80, height());
    for (int count = 0; count<st_->num_columns; count++) {
        headerLabels.push_back(stats_tree_get_column_name(count));
    }
    ui->statsTreeWidget->setSortingEnabled(false);

    error_string = register_tap_listener(st_cfg_->tapname,
                          st_,
                          st_->filter,
                          st_cfg_->flags,
                          resetTap,
                          stats_tree_packet,
                          drawTreeItems);
    if (error_string) {
        QMessageBox::critical(this, tr("%1 failed to attach to tap").arg(display_name),
                             error_string->str);
        g_string_free(error_string, TRUE);
        reject();
    }

    cf_retap_packets(cap_file_.capFile());
    drawTreeItems(st_);

    ui->statsTreeWidget->setSortingEnabled(true);
    remove_tap_listener(st_);

    st_cfg_->pr = NULL;
}
void StatsTreeDialog::fillTree()
{
    if (!st_cfg_ || file_closed_) return;

    QString display_name = gchar_free_to_qstring(stats_tree_get_displayname(st_cfg_->name));

    // The GTK+ UI appends "Stats Tree" to the window title. If we do the same
    // here we should expand the name completely, e.g. to "Statistics Tree".
    setWindowSubtitle(display_name);

    st_cfg_->pr = &cfg_pr_;
    cfg_pr_.st_dlg = this;

    if (st_) {
        stats_tree_free(st_);
    }
    QString display_filter = displayFilter();
    st_ = stats_tree_new(st_cfg_, NULL, display_filter.toUtf8().constData());

    // Add number of columns for this stats_tree
    QStringList header_labels;
    for (int count = 0; count<st_->num_columns; count++) {
        header_labels.push_back(stats_tree_get_column_name(count));
    }
    statsTreeWidget()->setColumnCount(header_labels.count());
    statsTreeWidget()->setHeaderLabels(header_labels);
    statsTreeWidget()->setSortingEnabled(false);

    if (!registerTapListener(st_cfg_->tapname,
                             st_,
                             st_->filter,
                             st_cfg_->flags,
                             resetTap,
                             stats_tree_packet,
                             drawTreeItems)) {
        reject(); // XXX Stay open instead?
        return;
    }

    cap_file_.retapPackets();
    drawTreeItems(st_);

    statsTreeWidget()->setSortingEnabled(true);
    removeTapListeners();

    st_cfg_->pr = NULL;
}
示例#3
0
static void
draw_gtk_tree(void *psp)
{
	stats_tree  *st		 = (stats_tree *)psp;
	stat_node   *child;
	int	     count;
	gint	     sort_column = GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID;
	GtkSortType  order	 = GTK_SORT_DESCENDING;

	for (count = 0; count<st->num_columns; count++) {
		gtk_tree_view_column_set_title(gtk_tree_view_get_column(GTK_TREE_VIEW(st->pr->tree),count),
										stats_tree_get_column_name(count));
	}

	gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (st->pr->store), &sort_column, &order);
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (st->pr->store),
				GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_DESCENDING);

	for (child = st->root.children; child; child = child->next ) {
		draw_gtk_node(child);

		if ( (!(child->st_flags&ST_FLG_DEF_NOEXPAND)) && child->pr->iter && st->pr->store ) {
			gtk_tree_view_expand_row(GTK_TREE_VIEW(st->pr->tree),
				 gtk_tree_model_get_path(GTK_TREE_MODEL(st->pr->store),child->pr->iter),
						 FALSE);
		}
	}

	if	((sort_column==GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID)||
		 (sort_column==GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)) {
		sort_column= stats_tree_get_default_sort_col(st)+N_RESERVED_COL;
		order= stats_tree_is_default_sort_DESC(st)?GTK_SORT_DESCENDING:GTK_SORT_ASCENDING;
	}

	/* Only call this once the entire list is drawn - else Gtk seems */
	/* to get sorting order wrong (sorting broken when new nodes are */
	/* added after setting sort column.) Also for performance.	   */
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (st->pr->store), sort_column, order);
}
示例#4
0
/** helper funcation to add note to formatted stats_tree */
WS_DLL_PUBLIC void stats_tree_format_node_as_str(const stat_node *node,
						 GString *s,
						 st_format_type format_type,
						 guint indent,
						 const gchar *path,
						 gint maxnamelen,
						 gint sort_column,
						 gboolean sort_descending)
{
	int count;
	int num_columns= node->st->num_columns;
	gchar **values= stats_tree_get_values_from_node(node);
	stat_node *child;
	sortinfo si;
	gchar *full_path;
	char fmt[16];

	switch(format_type)
	{
	case ST_FORMAT_YAML:
		if (indent) {
			g_sprintf(fmt, "%%%ds%%s%%s", indent*4-2);
		}
		else {
			strcpy(fmt, "%s%s%s");
		}
		g_string_append_printf(s, fmt, "", indent?"- ":"", "Description");
		g_string_append_printf(s, ": \"%s\"\n", values[0]);

		for (count = 1; count<num_columns; count++) {
			if (*values[count]) {
				g_string_append_printf(s, fmt, "", indent?"  ":"",
										stats_tree_get_column_name(count));
				g_string_append_printf(s, ": %s\n", values[count]);
			}
		}
		if (node->children) {
			g_string_append_printf(s, fmt, "", indent?"  ":"", "Items:\n");
		}
		break;
	case ST_FORMAT_XML:
		{
		char *itemname = xml_escape(values[0]);
		g_string_append_printf(s,"<stat-node name=\"%s\"%s>\n",itemname,
				node->rng?" isrange=\"true\"":"");
		g_free(itemname);
		for (count = 1; count<num_columns; count++) {
			gchar *colname= g_strdup(stats_tree_get_column_name(count));
			g_string_append_printf(s,"<%s>",clean_for_xml_tag(colname));
			g_string_append_printf(s,"%s</%s>\n",values[count],colname);
			g_free(colname);
		}
		}
		break;
	case ST_FORMAT_CSV:
		g_string_append_printf(s,"%d,\"%s\",\"%s\"",indent,path,values[0]);
		for (count = 1; count<num_columns; count++) {
			g_string_append_printf(s,",%s",values[count]);
		}
		g_string_append (s,"\n");
		break;
	case ST_FORMAT_PLAIN:
		g_sprintf (fmt,"%%%ds%%-%us",indent,maxnamelen-indent);
		g_string_append_printf(s,fmt,"",values[0]);
		for (count = 1; count<num_columns; count++) {
			g_sprintf (fmt," %%-%us",stats_tree_get_column_size(count)+1);
			g_string_append_printf(s,fmt,values[count]);
		}
		g_string_append (s,"\n");
		break;
	}

	indent++;
	indent = indent > INDENT_MAX ? INDENT_MAX : indent;
	full_path= g_strdup_printf ("%s/%s",path,values[0]);

	for (count = 0; count<num_columns; count++) {
		g_free(values[count]);
	}
	g_free(values);

	if (node->children) {
		GArray *Children= g_array_new(FALSE,FALSE,sizeof(child));
		for (child = node->children; child; child = child->next ) {
			g_array_append_val(Children,child);
		}
		si.sort_column = sort_column;
		si.sort_descending = sort_descending;
		g_array_sort_with_data(Children,stat_node_array_sortcmp,&si);
		for (count = 0; count<((int)Children->len); count++) {
			stats_tree_format_node_as_str(g_array_index(Children,stat_node*,count), s, format_type,
					indent, full_path, maxnamelen, sort_column, sort_descending);
		}
		g_array_free(Children,FALSE);
	}
	g_free(full_path);

	if (format_type==ST_FORMAT_XML) {
		g_string_append(s,"</stat-node>\n");
	}
}
示例#5
0
extern GString*
stats_tree_format_as_str(const stats_tree* st, st_format_type format_type,
					gint sort_column, gboolean sort_descending)
{
	int maxnamelen= stats_tree_branch_max_namelen(&st->root,0);
	stat_node *child;
	GString *s;
	int count;
	gchar *separator = NULL;

	switch(format_type)
	{
	case ST_FORMAT_YAML:
		s = g_string_new("---\n");
		break;
	case ST_FORMAT_XML:
		s = g_string_new("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
		break;
	case ST_FORMAT_CSV:
		s = g_string_new("\"level\",\"parent\",");
		for (count = 0; count<st->num_columns; count++) {
			g_string_append_printf(s,"\"%s\",",stats_tree_get_column_name(count));
		}
		g_string_append (s,"\n");
		break;
	case ST_FORMAT_PLAIN:
		{
		char fmt[16];
		int sep_length;

		sep_length= maxnamelen;
		for (count = 1; count<st->num_columns; count++) {
			sep_length += stats_tree_get_column_size(count)+2;
		}
		separator = (gchar *)g_malloc(sep_length+1);
		memset (separator, '=', sep_length);
		separator[sep_length] = 0;

		s = g_string_new("\n");
		g_string_append(s,separator);
		g_string_append_printf(s,"\n%s:\n",st->cfg->name);
		g_sprintf (fmt,"%%-%us",maxnamelen);
		g_string_append_printf(s,fmt,stats_tree_get_column_name(0));
		for (count = 1; count<st->num_columns; count++) {
			g_sprintf (fmt," %%-%us",stats_tree_get_column_size(count)+1);
			g_string_append_printf(s,fmt,stats_tree_get_column_name(count));
		}
		memset (separator, '-', sep_length);
		g_string_append_printf(s,"\n%s\n",separator);
		}
		break;
	default:
		return g_string_new("unknown format for stats_tree\n");
	}

	for (child = st->root.children; child; child = child->next ) {
		stats_tree_format_node_as_str(child,s,format_type,0,"",maxnamelen,sort_column,sort_descending);

	}

	if (format_type==ST_FORMAT_PLAIN) {
		g_string_append_printf(s,"\n%s\n",separator);
		g_free(separator);
	}

	return s;
}
示例#6
0
void StatsTreeDialog::fillTree()
{
    GString *error_string;
    if (!st_cfg_) return;

    gchar* display_name_temp = stats_tree_get_displayname(st_cfg_->name);
    QString display_name(display_name_temp);
    g_free(display_name_temp);

    setWindowTitle(display_name + tr(" Stats Tree"));

    if (!cap_file_) return;

    if (st_cfg_->in_use) {
        QMessageBox::warning(this, tr("%1 already open").arg(display_name),
                             tr("Each type of tree can only be generated one at at time."));
        reject();
    }

    st_cfg_->in_use = TRUE;
    st_cfg_->pr = &cfg_pr_;
    cfg_pr_.st_dlg = this;

    if (st_) {
        stats_tree_free(st_);
    }
    st_ = stats_tree_new(st_cfg_, NULL, ui->displayFilterLineEdit->text().toUtf8().constData());

    // Add number of columns for this stats_tree
    QStringList headerLabels;
    for (int count = 0; count<st_->num_columns; count++) {
        headerLabels.push_back(stats_tree_get_column_name(count));
    }
    ui->statsTreeWidget->setColumnCount(headerLabels.count());
    ui->statsTreeWidget->setHeaderLabels(headerLabels);
    resize(st_->num_columns*80+80, height());
    for (int count = 0; count<st_->num_columns; count++) {
        headerLabels.push_back(stats_tree_get_column_name(count));
    }
    ui->statsTreeWidget->setSortingEnabled(false);

    error_string = register_tap_listener(st_cfg_->tapname,
                          st_,
                          st_->filter,
                          st_cfg_->flags,
                          resetTap,
                          stats_tree_packet,
                          drawTreeItems);
    if (error_string) {
        QMessageBox::critical(this, tr("%1 failed to attach to tap").arg(display_name),
                             error_string->str);
        g_string_free(error_string, TRUE);
        reject();
    }

    cf_retap_packets(cap_file_);
    drawTreeItems(st_);

    ui->statsTreeWidget->setSortingEnabled(true);
    remove_tap_listener(st_);

    st_cfg_->in_use = FALSE;
    st_cfg_->pr = NULL;
}