diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2005-01-29 02:14:25 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2005-01-29 02:14:25 +0000 |
commit | 3d9c7d48ae267513aaf2f70069e8e676ad4aaab1 (patch) | |
tree | b84878f881134faa23a9f8b468af0c511fc2a7b4 | |
parent | b3b3f5cbccad71bf2c567c865107f5a63c713059 (diff) |
Add a new menu item "View/Resize Columns" to, well, resize columns. As this might take a long time, I've provided a progress bar with the option to cancel the operation.
I might later add something like "View/Auto Resize Columns" with a checkbox menu item, so this is done everytime a capture file finished loading. However, I don't know how well this will work together with "Update list of packets in real time" while doing a capture.
svn path=/trunk/; revision=13192
-rw-r--r-- | gtk/menu.c | 2 | ||||
-rw-r--r-- | gtk/packet_list.c | 76 | ||||
-rw-r--r-- | gtk/packet_list.h | 7 |
3 files changed, 83 insertions, 2 deletions
diff --git a/gtk/menu.c b/gtk/menu.c index 4b53801508..45f201787c 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -259,6 +259,8 @@ static GtkItemFactoryEntry menu_items[] = ITEM_FACTORY_STOCK_ENTRY("/View/_Normal Size", "<control>equal", view_zoom_100_cb, 0, GTK_STOCK_ZOOM_100), ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL), + ITEM_FACTORY_ENTRY("/View/Resize Columns", NULL, packet_list_resize_columns_cb, + 0, NULL, NULL), ITEM_FACTORY_ENTRY("/View/Collapse _All", NULL, collapse_all_cb, 0, NULL, NULL), ITEM_FACTORY_ENTRY("/View/_Expand All", NULL, expand_all_cb, diff --git a/gtk/packet_list.c b/gtk/packet_list.c index 3e20f1d794..597ccc9fa9 100644 --- a/gtk/packet_list.c +++ b/gtk/packet_list.c @@ -54,6 +54,11 @@ #include "image/clist_ascend.xpm" #include "image/clist_descend.xpm" +#include "progress_dlg.h" + +#define N_PROGBAR_UPDATES 100 + + /* * XXX - gross hack. * This lets us use GtkCList in GTK+ 1.3[.x] and later, and EthCList on @@ -509,8 +514,8 @@ packet_list_new(e_prefs *prefs) SIGNAL_CONNECT(packet_list, "select-row", packet_list_select_cb, NULL); SIGNAL_CONNECT(packet_list, "unselect-row", packet_list_unselect_cb, NULL); for (i = 0; i < cfile.cinfo.num_cols; i++) { - /* Columns do not automatically resize, but are resizeable by - the user. */ + /* For performance reasons, columns do not automatically resize, + but are resizeable by the user. */ eth_clist_set_column_auto_resize(ETH_CLIST(packet_list), i, FALSE); eth_clist_set_column_resizeable(ETH_CLIST(packet_list), i, TRUE); @@ -591,10 +596,77 @@ packet_list_freeze(void) } void +packet_list_resize_columns(void) { + int i; + int progbar_nextstep; + int progbar_quantum; + gboolean stop_flag; + GTimeVal start_time; + float prog_val; + progdlg_t *progbar = NULL; + gchar status_str[100]; + + + progbar_nextstep = 0; + /* When we reach the value that triggers a progress bar update, + bump that value by this amount. */ + progbar_quantum = cfile.cinfo.num_cols/N_PROGBAR_UPDATES; + + stop_flag = FALSE; + g_get_current_time(&start_time); + + + main_window_update(); + + for (i = 0; i < cfile.cinfo.num_cols; i++) { + if (i >= progbar_nextstep) { + /* let's not divide by zero. I should never be started + * with count == 0, so let's assert that + */ + g_assert(cfile.cinfo.num_cols > 0); + + prog_val = (gfloat) i / cfile.cinfo.num_cols; + + /* Create the progress bar if necessary */ + if (progbar == NULL) + progbar = delayed_create_progress_dlg("Resizing", "Resize Columns", + &stop_flag, &start_time, prog_val); + + if (progbar != NULL) { + g_snprintf(status_str, sizeof(status_str), + "%u of %u columns (%s)", i+1, cfile.cinfo.num_cols, cfile.cinfo.col_title[i]); + update_progress_dlg(progbar, prog_val, status_str); + } + + progbar_nextstep += progbar_quantum; + } + + if (stop_flag) { + /* Well, the user decided to abort the resizing... */ + break; + } + + eth_clist_set_column_auto_resize(ETH_CLIST(packet_list), i, TRUE); + eth_clist_set_column_auto_resize(ETH_CLIST(packet_list), i, FALSE); + } + + /* We're done resizing the columns; destroy the progress bar if it + was created. */ + if (progbar != NULL) + destroy_progress_dlg(progbar); +} + +void packet_list_resize_columns_cb(GtkWidget *widget, gpointer data) +{ + packet_list_resize_columns(); +} + +void packet_list_thaw(void) { eth_clist_thaw(ETH_CLIST(packet_list)); packets_bar_update(); + /*packet_list_resize_columns();*/ } void diff --git a/gtk/packet_list.h b/gtk/packet_list.h index a3f10bd385..fbbbae06d7 100644 --- a/gtk/packet_list.h +++ b/gtk/packet_list.h @@ -44,6 +44,13 @@ extern GtkWidget *packet_list_new(e_prefs *prefs); */ extern void packet_list_set_column_titles(void); +/** Resize columns + * + * @param widget parent widget (unused) + * @param data unused + */ +extern void packet_list_resize_columns_cb(GtkWidget *widget, gpointer data); + /** Mark the currently selected packet. * * @param widget parent widget (unused) |