Update the ServiceResponseTime helper routines so that the columns

can be sorted.

"borrowed" lots of code for this from gtkclist.c

Columns 0,1  sort in ascending order by default
Columns 2-5 sort in ascending order by default

svn path=/trunk/; revision=7905
This commit is contained in:
Ronnie Sahlberg 2003-06-21 05:39:45 +00:00
parent 76a6027bf6
commit f97314ba3d
1 changed files with 141 additions and 4 deletions

View File

@ -3,7 +3,7 @@
* Helper routines common to all service response time statistics
* tap.
*
* $Id: service_response_time_table.c,v 1.1 2003/06/21 01:42:45 sahlberg Exp $
* $Id: service_response_time_table.c,v 1.2 2003/06/21 05:39:45 sahlberg Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -28,24 +28,154 @@
# include "config.h"
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gtk/gtk.h>
#include "compat_macros.h"
#include "epan/packet_info.h"
#include "service_response_time_table.h"
#include "image/clist_ascend.xpm"
#include "image/clist_descend.xpm"
typedef struct column_arrows {
GtkWidget *table;
GtkWidget *ascend_pm;
GtkWidget *descend_pm;
} column_arrows;
static void
srt_click_column_cb(GtkCList *clist, gint column, gpointer data)
{
column_arrows *col_arrows = (column_arrows *) data;
int i;
gtk_clist_freeze(clist);
for (i = 0; i < 6; i++) {
gtk_widget_hide(col_arrows[i].ascend_pm);
gtk_widget_hide(col_arrows[i].descend_pm);
}
if (column == clist->sort_column) {
if (clist->sort_type == GTK_SORT_ASCENDING) {
clist->sort_type = GTK_SORT_DESCENDING;
gtk_widget_show(col_arrows[column].descend_pm);
} else {
clist->sort_type = GTK_SORT_ASCENDING;
gtk_widget_show(col_arrows[column].ascend_pm);
}
} else {
/* Columns 2-5 Count, Min, Max, Avg are sorted in descending
order by default.
Columns 0 and 1 sort by ascending order by default
*/
if(column>=2){
clist->sort_type = GTK_SORT_DESCENDING;
gtk_widget_show(col_arrows[column].descend_pm);
} else {
clist->sort_type = GTK_SORT_ASCENDING;
gtk_widget_show(col_arrows[column].ascend_pm);
}
gtk_clist_set_sort_column(clist, column);
}
gtk_clist_thaw(clist);
gtk_clist_sort(clist);
}
static gint
srt_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
{
char *text1 = NULL;
char *text2 = NULL;
int i1, i2;
float f1,f2;
GtkCListRow *row1 = (GtkCListRow *) ptr1;
GtkCListRow *row2 = (GtkCListRow *) ptr2;
text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
switch(clist->sort_column){
case 1:
return strcmp (text1, text2);
case 0:
case 2:
i1=atoi(text1);
i2=atoi(text2);
return i1-i2;
case 3:
case 4:
case 5:
sscanf(text1,"%f",&f1);
sscanf(text2,"%f",&f2);
if(fabs(f1-f2)<0.000005)
return 0;
if(f1>f2)
return 1;
return -1;
}
g_assert_not_reached();
return 0;
}
void
init_srt_table(srt_stat_table *rst, int num_procs, GtkWidget *vbox)
{
int i, j;
char *title[] = { "Index", "Procedure", "Calls", "Min SRT", "Max SRT", "Avg SRT" };
column_arrows *col_arrows;
GdkBitmap *ascend_bm, *descend_bm;
GdkPixmap *ascend_pm, *descend_pm;
GtkStyle *win_style;
GtkWidget *column_lb;
char *default_titles[] = { "Index", "Procedure", "Calls", "Min SRT", "Max SRT", "Avg SRT" };
rst->scrolled_window=gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(rst->scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_box_pack_start(GTK_BOX(vbox), rst->scrolled_window, TRUE, TRUE, 0);
gtk_widget_show(rst->scrolled_window);
rst->table=(GtkCList *)gtk_clist_new_with_titles(6, title);
rst->table=(GtkCList *)gtk_clist_new(6);
col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * 6);
win_style = gtk_widget_get_style(rst->scrolled_window);
ascend_pm = gdk_pixmap_create_from_xpm_d(rst->scrolled_window->window,
&ascend_bm,
&win_style->bg[GTK_STATE_NORMAL],
(gchar **)clist_ascend_xpm);
descend_pm = gdk_pixmap_create_from_xpm_d(rst->scrolled_window->window,
&descend_bm,
&win_style->bg[GTK_STATE_NORMAL],
(gchar **)clist_descend_xpm);
for (i = 0; i < 6; i++) {
col_arrows[i].table = gtk_table_new(2, 2, FALSE);
gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
column_lb = gtk_label_new(default_titles[i]);
gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show(column_lb);
col_arrows[i].ascend_pm = gtk_pixmap_new(ascend_pm, ascend_bm);
gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
if (i == 0) {
gtk_widget_show(col_arrows[i].ascend_pm);
}
col_arrows[i].descend_pm = gtk_pixmap_new(descend_pm, descend_bm);
gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_clist_set_column_widget(GTK_CLIST(rst->table), i, col_arrows[i].table);
gtk_widget_show(col_arrows[i].table);
}
gtk_clist_column_titles_show(GTK_CLIST(rst->table));
gtk_clist_set_compare_func(rst->table, srt_sort_column);
gtk_clist_set_sort_column(rst->table, 0);
gtk_clist_set_sort_type(rst->table, GTK_SORT_ASCENDING);
/*XXX instead of this we should probably have some code to
dynamically adjust the width of the columns */
@ -59,7 +189,12 @@ init_srt_table(srt_stat_table *rst, int num_procs, GtkWidget *vbox)
gtk_clist_set_shadow_type(rst->table, GTK_SHADOW_IN);
gtk_clist_column_titles_show(rst->table);
gtk_container_add(GTK_CONTAINER(rst->scrolled_window), (GtkWidget *)rst->table);
SIGNAL_CONNECT(rst->table, "click-column", srt_click_column_cb, col_arrows);
gtk_widget_show((GtkWidget *)rst->table);
gtk_widget_show(rst->scrolled_window);
rst->num_procs=num_procs;
rst->procedures=g_malloc(sizeof(srt_procedure_t)*num_procs);
@ -195,6 +330,8 @@ draw_srt_table_data(srt_stat_table *rst)
g_free(rst->procedures[i].entries[5]);
rst->procedures[i].entries[5]=strp;
}
gtk_clist_sort(rst->table);
}