Get rid of another Clist.

svn path=/trunk/; revision=27647
This commit is contained in:
Anders Broman 2009-03-08 01:01:58 +00:00
parent 646aafff35
commit a9103bb14f
1 changed files with 196 additions and 279 deletions

View File

@ -55,21 +55,18 @@
#include "gtk/filter_dlg.h"
#include "gtk/gui_utils.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;
enum
{
IEI_COLUMN,
MSG_NAME_COLUMN,
COUNT_COLUMN,
N_COLUMN /* The number of columns */
};
typedef struct _gsm_a_stat_dlg_t {
GtkWidget *win;
GtkWidget *scrolled_win;
GtkWidget *table;
char *entries[3];
} gsm_a_stat_dlg_t;
typedef struct _gsm_a_stat_t {
@ -98,7 +95,99 @@ static gsm_a_stat_dlg_t dlg_dtap_tp;
static gsm_a_stat_dlg_t dlg_sacch_rr;
static gsm_a_stat_t gsm_a_stat;
/* Create list */
static
GtkWidget* create_list()
{
GtkListStore *list_store;
GtkWidget *list;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
GtkTreeSortable *sortable;
GtkTreeView *list_view;
GtkTreeSelection *selection;
/* Create the store */
list_store = gtk_list_store_new(N_COLUMN, /* Total number of columns XXX*/
G_TYPE_UINT, /* IEI */
G_TYPE_STRING, /* Message Name */
G_TYPE_UINT); /* Count */
/* Create a view */
list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
list_view = GTK_TREE_VIEW(list);
sortable = GTK_TREE_SORTABLE(list_store);
#if GTK_CHECK_VERSION(2,6,0)
/* Speed up the list display */
gtk_tree_view_set_fixed_height_mode(list_view, TRUE);
#endif
/* Setup the sortable columns */
gtk_tree_sortable_set_sort_column_id(sortable, IEI_COLUMN, GTK_SORT_ASCENDING);
gtk_tree_view_set_headers_clickable(list_view, FALSE);
/* The view now holds a reference. We can get rid of our own reference */
g_object_unref (G_OBJECT (list_store));
/*
* Create the first column packet, associating the "text" attribute of the
* cell_renderer to the first column of the model
*/
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("IEI", renderer,
"text", IEI_COLUMN,
NULL);
/* gtk_tree_view_column_set_cell_data_func(column, renderer, present_as_hex_func,
GINT_TO_POINTER(IEI_COLUMN), NULL);
*/
gtk_tree_view_column_set_sort_column_id(column, IEI_COLUMN);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_min_width(column, 50);
/* Add the column to the view. */
gtk_tree_view_append_column (list_view, column);
/* Second column.. Message Name. */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Message Name", renderer,
"text", MSG_NAME_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id(column, MSG_NAME_COLUMN);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_min_width(column, 280);
gtk_tree_view_append_column (list_view, column);
/* Third column.. Count. */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Count", renderer,
"text", COUNT_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id(column, COUNT_COLUMN);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_min_width(column, 50);
gtk_tree_view_append_column (list_view, column);
/* Now enable the sorting of each column */
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view), TRUE);
gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(list_view), TRUE);
/* Setup the selection handler */
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
return list;
}
static void
gsm_a_stat_reset(
void *tapdata)
@ -122,54 +211,54 @@ gsm_a_stat_packet(
switch (data_p->pdu_type)
{
case BSSAP_PDU_TYPE_BSSMAP:
stat_p->bssmap_message_type[data_p->message_type]++;
break;
stat_p->bssmap_message_type[data_p->message_type]++;
break;
case BSSAP_PDU_TYPE_DTAP:
switch (data_p->protocol_disc)
{
case PD_CC:
stat_p->dtap_cc_message_type[data_p->message_type]++;
break;
case PD_MM:
stat_p->dtap_mm_message_type[data_p->message_type]++;
break;
case PD_RR:
stat_p->dtap_rr_message_type[data_p->message_type]++;
break;
case PD_GMM:
stat_p->dtap_gmm_message_type[data_p->message_type]++;
break;
case PD_SMS:
stat_p->dtap_sms_message_type[data_p->message_type]++;
break;
case PD_SM:
stat_p->dtap_sm_message_type[data_p->message_type]++;
break;
case PD_SS:
stat_p->dtap_ss_message_type[data_p->message_type]++;
break;
case PD_TP:
stat_p->dtap_tp_message_type[data_p->message_type]++;
break;
default:
/*
* unsupported PD
*/
return(0);
case PD_CC:
stat_p->dtap_cc_message_type[data_p->message_type]++;
break;
case PD_MM:
stat_p->dtap_mm_message_type[data_p->message_type]++;
break;
case PD_RR:
stat_p->dtap_rr_message_type[data_p->message_type]++;
break;
case PD_GMM:
stat_p->dtap_gmm_message_type[data_p->message_type]++;
break;
case PD_SMS:
stat_p->dtap_sms_message_type[data_p->message_type]++;
break;
case PD_SM:
stat_p->dtap_sm_message_type[data_p->message_type]++;
break;
case PD_SS:
stat_p->dtap_ss_message_type[data_p->message_type]++;
break;
case PD_TP:
stat_p->dtap_tp_message_type[data_p->message_type]++;
break;
default:
/*
* unsupported PD
*/
return(0);
}
break;
case GSM_A_PDU_TYPE_SACCH:
switch (data_p->protocol_disc)
{
case 0:
stat_p->sacch_rr_message_type[data_p->message_type]++;
break;
default:
/* unknown Short PD */
break;
}
switch (data_p->protocol_disc)
{
case 0:
stat_p->sacch_rr_message_type[data_p->message_type]++;
break;
default:
/* unknown Short PD */
break;
}
break;
default:
@ -189,26 +278,34 @@ gsm_a_stat_draw_aux(
int *message_count,
const value_string *msg_strings)
{
int i, j;
char *strp;
GtkListStore *list_store;
GtkTreeIter iter;
int i;
if (dlg_p->win != NULL)
{
i = 0;
if (dlg_p->win != NULL){
i = 0;
list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW (dlg_p->table))); /* Get store */
while (msg_strings[i].strptr)
{
j = gtk_clist_find_row_from_data(GTK_CLIST(dlg_p->table), (gpointer)(long) i);
strp = g_strdup_printf("%d", message_count[msg_strings[i].value]);
gtk_clist_set_text(GTK_CLIST(dlg_p->table), j, 2, strp);
g_free(strp);
i++;
}
gtk_clist_sort(GTK_CLIST(dlg_p->table));
while (msg_strings[i].strptr){
/* Creates a new row at position. iter will be changed to point to this new row.
* If position is larger than the number of rows on the list, then the new row will be appended to the list.
* The row will be filled with the values given to this function.
* :
* should generally be preferred when inserting rows in a sorted list store.
*/
#if GTK_CHECK_VERSION(2,6,0)
gtk_list_store_insert_with_values( list_store , &iter, G_MAXINT,
#else
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
#endif
IEI_COLUMN, msg_strings[i].value,
MSG_NAME_COLUMN, (char *)msg_strings[i].strptr,
COUNT_COLUMN, message_count[msg_strings[i].value],
-1);
i++;
}
}
}
@ -222,166 +319,76 @@ gsm_a_stat_draw(
if (dlg_bssmap.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_bssmap,
stat_p->bssmap_message_type,
gsm_a_bssmap_msg_strings);
gsm_a_stat_draw_aux(&dlg_bssmap,
stat_p->bssmap_message_type,
gsm_a_bssmap_msg_strings);
}
if (dlg_dtap_mm.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_dtap_mm,
stat_p->dtap_mm_message_type,
gsm_a_dtap_msg_mm_strings);
gsm_a_stat_draw_aux(&dlg_dtap_mm,
stat_p->dtap_mm_message_type,
gsm_a_dtap_msg_mm_strings);
}
if (dlg_dtap_rr.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_dtap_rr,
stat_p->dtap_rr_message_type,
gsm_a_dtap_msg_rr_strings);
gsm_a_stat_draw_aux(&dlg_dtap_rr,
stat_p->dtap_rr_message_type,
gsm_a_dtap_msg_rr_strings);
}
if (dlg_dtap_cc.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_dtap_cc,
stat_p->dtap_cc_message_type,
gsm_a_dtap_msg_cc_strings);
gsm_a_stat_draw_aux(&dlg_dtap_cc,
stat_p->dtap_cc_message_type,
gsm_a_dtap_msg_cc_strings);
}
if (dlg_dtap_gmm.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_dtap_gmm,
stat_p->dtap_gmm_message_type,
gsm_a_dtap_msg_gmm_strings);
gsm_a_stat_draw_aux(&dlg_dtap_gmm,
stat_p->dtap_gmm_message_type,
gsm_a_dtap_msg_gmm_strings);
}
if (dlg_dtap_sms.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_dtap_sms,
stat_p->dtap_sms_message_type,
gsm_a_dtap_msg_sms_strings);
gsm_a_stat_draw_aux(&dlg_dtap_sms,
stat_p->dtap_sms_message_type,
gsm_a_dtap_msg_sms_strings);
}
if (dlg_dtap_sm.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_dtap_sm,
stat_p->dtap_sm_message_type,
gsm_a_dtap_msg_sm_strings);
gsm_a_stat_draw_aux(&dlg_dtap_sm,
stat_p->dtap_sm_message_type,
gsm_a_dtap_msg_sm_strings);
}
if (dlg_dtap_ss.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_dtap_ss,
stat_p->dtap_ss_message_type,
gsm_a_dtap_msg_ss_strings);
gsm_a_stat_draw_aux(&dlg_dtap_ss,
stat_p->dtap_ss_message_type,
gsm_a_dtap_msg_ss_strings);
}
if (dlg_dtap_tp.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_dtap_tp,
stat_p->dtap_tp_message_type,
gsm_a_dtap_msg_tp_strings);
gsm_a_stat_draw_aux(&dlg_dtap_tp,
stat_p->dtap_tp_message_type,
gsm_a_dtap_msg_tp_strings);
}
if (dlg_sacch_rr.win != NULL)
{
gsm_a_stat_draw_aux(&dlg_sacch_rr,
stat_p->sacch_rr_message_type,
gsm_a_sacch_msg_rr_strings);
gsm_a_stat_draw_aux(&dlg_sacch_rr,
stat_p->sacch_rr_message_type,
gsm_a_sacch_msg_rr_strings);
}
}
static void
gsm_a_stat_gtk_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 < 3; 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 0-1 sorted in descending order by default
* Columns 2 sorted in ascending order by default
*/
if (column <= 1)
{
clist->sort_type = GTK_SORT_ASCENDING;
gtk_widget_show(col_arrows[column].ascend_pm);
}
else
{
clist->sort_type = GTK_SORT_DESCENDING;
gtk_widget_show(col_arrows[column].descend_pm);
}
gtk_clist_set_sort_column(clist, column);
}
gtk_clist_thaw(clist);
gtk_clist_sort(clist);
}
static gint
gsm_a_stat_gtk_sort_column(
GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2)
{
const GtkCListRow *row1 = ptr1;
const GtkCListRow *row2 = ptr2;
char *text1 = NULL;
char *text2 = NULL;
int i1, i2;
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 0:
/* FALLTHRU */
case 2:
i1 = strtol(text1, NULL, 0);
i2 = strtol(text2, NULL, 0);
return(i1 - i2);
case 1:
return(strcmp(text1, text2));
}
g_assert_not_reached();
return(0);
}
static void
gsm_a_stat_gtk_win_destroy_cb(
@ -397,11 +404,6 @@ gsm_a_stat_gtk_win_create(
gsm_a_stat_dlg_t *dlg_p,
const char *title)
{
#define INIT_TABLE_NUM_COLUMNS 3
const char *default_titles[] = { "IEI", "Message Name", "Count" };
int i;
column_arrows *col_arrows;
GtkWidget *column_lb;
GtkWidget *vbox;
GtkWidget *bt_close;
GtkWidget *bbox;
@ -417,59 +419,9 @@ gsm_a_stat_gtk_win_create(
dlg_p->scrolled_win = scrolled_window_new(NULL, NULL);
gtk_box_pack_start(GTK_BOX(vbox), dlg_p->scrolled_win, TRUE, TRUE, 0);
dlg_p->table = gtk_clist_new(INIT_TABLE_NUM_COLUMNS);
col_arrows =
(column_arrows *) g_malloc(sizeof(column_arrows) * INIT_TABLE_NUM_COLUMNS);
for (i = 0; i < INIT_TABLE_NUM_COLUMNS; 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 = xpm_to_widget(clist_ascend_xpm);
gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm,
1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
col_arrows[i].descend_pm = xpm_to_widget(clist_descend_xpm);
gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm,
1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
if (i == 0)
{
/* default column sorting */
gtk_widget_show(col_arrows[i].ascend_pm);
}
gtk_clist_set_column_widget(GTK_CLIST(dlg_p->table), i, col_arrows[i].table);
gtk_widget_show(col_arrows[i].table);
}
gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
gtk_clist_set_compare_func(GTK_CLIST(dlg_p->table), gsm_a_stat_gtk_sort_column);
gtk_clist_set_sort_column(GTK_CLIST(dlg_p->table), 0);
gtk_clist_set_sort_type(GTK_CLIST(dlg_p->table), GTK_SORT_ASCENDING);
gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 0, 50);
gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 1, 330);
gtk_clist_set_column_width(GTK_CLIST(dlg_p->table), 2, 50);
gtk_clist_set_shadow_type(GTK_CLIST(dlg_p->table), GTK_SHADOW_IN);
gtk_clist_column_titles_show(GTK_CLIST(dlg_p->table));
dlg_p->table = create_list();
gtk_container_add(GTK_CONTAINER(dlg_p->scrolled_win), dlg_p->table);
g_signal_connect(dlg_p->table, "click-column", G_CALLBACK(gsm_a_stat_gtk_click_column_cb), col_arrows);
/* Button row. */
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
@ -490,7 +442,7 @@ gsm_a_stat_gtk_bssmap_cb(
GtkWidget *w _U_,
gpointer d _U_)
{
int i;
/* int i;*/
/*
@ -503,23 +455,6 @@ gsm_a_stat_gtk_bssmap_cb(
}
gsm_a_stat_gtk_win_create(&dlg_bssmap, "GSM A-I/F BSSMAP Statistics");
i = 0;
while (gsm_a_bssmap_msg_strings[i].strptr)
{
dlg_bssmap.entries[0] = g_strdup_printf("0x%02x",
gsm_a_bssmap_msg_strings[i].value);
dlg_bssmap.entries[1] = g_strdup(gsm_a_bssmap_msg_strings[i].strptr);
dlg_bssmap.entries[2] = g_strdup("0");
gtk_clist_insert(GTK_CLIST(dlg_bssmap.table), i, dlg_bssmap.entries);
gtk_clist_set_row_data(GTK_CLIST(dlg_bssmap.table), i, (gpointer)(long) i);
i++;
}
gsm_a_stat_draw(&gsm_a_stat);
}
@ -541,8 +476,6 @@ gsm_a_stat_gtk_dtap_cb(
const char *title,
const value_string *dtap_msg_strings)
{
int i;
/*
* if the window is already open, bring it to front
@ -555,22 +488,6 @@ gsm_a_stat_gtk_dtap_cb(
gsm_a_stat_gtk_win_create(dlg_dtap_p, title);
i = 0;
while (dtap_msg_strings[i].strptr)
{
dlg_dtap_p->entries[0] = g_strdup_printf("0x%02x",
dtap_msg_strings[i].value);
dlg_dtap_p->entries[1] = g_strdup(dtap_msg_strings[i].strptr);
dlg_dtap_p->entries[2] = g_strdup("0");
gtk_clist_insert(GTK_CLIST(dlg_dtap_p->table), i, dlg_dtap_p->entries);
gtk_clist_set_row_data(GTK_CLIST(dlg_dtap_p->table), i, (gpointer)(long) i);
i++;
}
gsm_a_stat_draw(&gsm_a_stat);
}