Auto size COL_NUMBER, COL_PACKET_LENGTH and COL_CUMULATIVE_BYTES
authorkrj <krj@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 7 Sep 2009 18:53:17 +0000 (18:53 +0000)
committerkrj <krj@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 7 Sep 2009 18:53:17 +0000 (18:53 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@29778 f5534014-38df-0310-8fa8-9805f1628bb7

epan/nstime.c
epan/nstime.h
gtk/packet_list_store.c

index 99dc43d748522f9fdd9ee6988aa73b15ccfd545c..da7fc35e05696f61a2b9b378ee5c52f63e65feaa 100644 (file)
@@ -138,7 +138,7 @@ void nstime_sum(nstime_t *sum, const nstime_t *a, const nstime_t *b)
  * a < b : < 0
  */
 
-int nstime_cmp (nstime_t *a, const nstime_t *b )
+int nstime_cmp (const nstime_t *a, const nstime_t *b )
 {
     if (a->secs == b->secs) {
         return a->nsecs - b->nsecs;
index af807973730be0eff063ca9ab8b64381ef9b33b8..f7cf0957f1ca4cce24f6d23435990332cdeeb133 100644 (file)
@@ -78,7 +78,7 @@ extern void nstime_sum(nstime_t *sum, const nstime_t *b, const nstime_t *a );
  * a = b : 0
  * a < b : < 0
  */
-extern int nstime_cmp(nstime_t *a, const nstime_t *b );
+extern int nstime_cmp (const nstime_t *a, const nstime_t *b );
 
 /* converts nstime to double, time base is milli seconds */
 extern double nstime_to_msec(const nstime_t *nstime);
index 2fb2da843d7b01067e4ac0eed035c7dd867e14a5..b12646a5db040290248d73911e49e1a75b9a2d0e 100644 (file)
@@ -41,8 +41,9 @@
 #include "ui_util.h"
 
 #include <epan/epan_dissect.h>
-#include "epan/column_info.h"
-#include "epan/column.h"
+#include <epan/column_info.h>
+#include <epan/column.h>
+#include <epan/nstime.h>
 
 #include "color.h"
 #include "color_filters.h"
@@ -678,7 +679,7 @@ packet_list_change_record(PacketList *packet_list, guint row, gint col, column_i
 
        if (!record->fdata->col_text) {
                record->fdata->col_text_len = se_alloc0(sizeof(record->fdata->col_text) *
-                                            (packet_list->n_columns-1));
+                                                                                       (packet_list->n_columns-1));
                record->fdata->col_text = se_alloc0(sizeof(record->fdata->col_text) *
                                                                                        (packet_list->n_columns-1));
        }
@@ -732,7 +733,7 @@ packet_list_change_record(PacketList *packet_list, guint row, gint col, column_i
                default:
                        record->fdata->col_text_len[col] = (guint) strlen(cinfo->col_data[col]);
                        record->fdata->col_text[col] = se_memdup(cinfo->col_data[col],
-                                                     record->fdata->col_text_len[col] + 1);
+                                                                                                        record->fdata->col_text_len[col] + 1);
                        break;
        }
 }
@@ -772,73 +773,73 @@ packet_list_dissect_and_cache_all(PacketList *packet_list)
 {
        PacketListRecord *record;
 
-    int         progbar_nextstep;
-    int         progbar_quantum;
-    gboolean    progbar_stop_flag;
-    GTimeVal    progbar_start_time;
-    float       progbar_val;
-    progdlg_t  *progbar = NULL;
-    gchar       progbar_status_str[100];
-    gint        progbar_loop_max;
-    gint        progbar_loop_var;
-    gint        progbar_updates = 100 /* 100% */;
+       int             progbar_nextstep;
+       int             progbar_quantum;
+       gboolean        progbar_stop_flag;
+       GTimeVal        progbar_start_time;
+       float           progbar_val;
+       progdlg_t  *progbar = NULL;
+       gchar           progbar_status_str[100];
+       gint            progbar_loop_max;
+       gint            progbar_loop_var;
+       gint            progbar_updates = 100 /* 100% */;
 
        g_assert(packet_list->columnized == FALSE);
 
-    progbar_loop_max = PACKET_LIST_RECORD_COUNT(packet_list->physical_rows);
-    /* Update the progress bar when it gets to this value. */
-    progbar_nextstep = 0;
-    /* When we reach the value that triggers a progress bar update,
-       bump that value by this amount. */
-    progbar_quantum = progbar_loop_max/progbar_updates;
-    /* Progress so far. */
-    progbar_val = 0.0f;
-
-    progbar_stop_flag = FALSE;
-    g_get_current_time(&progbar_start_time);
-
-    main_window_update();
-
-    for (progbar_loop_var = 0; progbar_loop_var < progbar_loop_max; ++progbar_loop_var) {
-      record = PACKET_LIST_RECORD_GET(packet_list->physical_rows, progbar_loop_var);
-      packet_list_dissect_and_cache_record(packet_list, record, TRUE, FALSE);
-
-      /* Create the progress bar if necessary.
-         We check on every iteration of the loop, so that it takes no
-         longer than the standard time to create it (otherwise, for a
-         large file, we might take considerably longer than that standard
-         time in order to get to the next progress bar step). */
-      if (progbar == NULL)
-         progbar = delayed_create_progress_dlg("Construct", "Columns",
-                        TRUE, &progbar_stop_flag,
-                        &progbar_start_time, progbar_val);
-
-      if (progbar_loop_var >= progbar_nextstep) {
-        /* let's not divide by zero. We should never be started
-         * with count == 0, so let's assert that */
-        g_assert(progbar_loop_max > 0);
-
-        progbar_val = (gfloat) progbar_loop_var / progbar_loop_max;
-
-        if (progbar != NULL) {
-          g_snprintf(progbar_status_str, sizeof(progbar_status_str),
-                     "%u of %u frames", progbar_loop_var+1, progbar_loop_max);
-          update_progress_dlg(progbar, progbar_val, progbar_status_str);
-        }
-
-        progbar_nextstep += progbar_quantum;
-      }
-
-      if (progbar_stop_flag) {
-        /* Well, the user decided to abort the resizing... */
-        break;
-      }
-    }
-
-    /* We're done resizing the columns; destroy the progress bar if it
-       was created. */
-    if (progbar != NULL)
-      destroy_progress_dlg(progbar);
+       progbar_loop_max = PACKET_LIST_RECORD_COUNT(packet_list->physical_rows);
+       /* Update the progress bar when it gets to this value. */
+       progbar_nextstep = 0;
+       /* When we reach the value that triggers a progress bar update,
+          bump that value by this amount. */
+       progbar_quantum = progbar_loop_max/progbar_updates;
+       /* Progress so far. */
+       progbar_val = 0.0f;
+
+       progbar_stop_flag = FALSE;
+       g_get_current_time(&progbar_start_time);
+
+       main_window_update();
+
+       for (progbar_loop_var = 0; progbar_loop_var < progbar_loop_max; ++progbar_loop_var) {
+         record = PACKET_LIST_RECORD_GET(packet_list->physical_rows, progbar_loop_var);
+         packet_list_dissect_and_cache_record(packet_list, record, TRUE, FALSE);
+
+         /* Create the progress bar if necessary.
+                We check on every iteration of the loop, so that it takes no
+                longer than the standard time to create it (otherwise, for a
+                large file, we might take considerably longer than that standard
+                time in order to get to the next progress bar step). */
+         if (progbar == NULL)
+                progbar = delayed_create_progress_dlg("Construct", "Columns",
+                                               TRUE, &progbar_stop_flag,
+                                               &progbar_start_time, progbar_val);
+
+         if (progbar_loop_var >= progbar_nextstep) {
+               /* let's not divide by zero. We should never be started
+                * with count == 0, so let's assert that */
+               g_assert(progbar_loop_max > 0);
+
+               progbar_val = (gfloat) progbar_loop_var / progbar_loop_max;
+
+               if (progbar != NULL) {
+                 g_snprintf(progbar_status_str, sizeof(progbar_status_str),
+                                        "%u of %u frames", progbar_loop_var+1, progbar_loop_max);
+                 update_progress_dlg(progbar, progbar_val, progbar_status_str);
+               }
+
+               progbar_nextstep += progbar_quantum;
+         }
+
+         if (progbar_stop_flag) {
+               /* Well, the user decided to abort the resizing... */
+               break;
+         }
+       }
+
+       /* We're done resizing the columns; destroy the progress bar if it
+          was created. */
+       if (progbar != NULL)
+         destroy_progress_dlg(progbar);
 
        packet_list->columnized = TRUE;
 }
@@ -1125,29 +1126,100 @@ packet_list_get_widest_column_string(PacketList *packet_list, gint col)
                return "";
 
        if (col_based_on_frame_data(&cfile.cinfo, col)) {
-        /* TODO: Calculate according to column */
-               return get_column_width_string(get_column_format(col), col);
+               PacketListRecord *record;
+               guint vis_idx;
+
+        guint32 widest_column_val = 0;
+               nstime_t widest_column_time;
+
+               nstime_set_zero(&widest_column_time);
+
+               for(vis_idx = 0; vis_idx < PACKET_LIST_RECORD_COUNT(packet_list->visible_rows); ++vis_idx) {
+                       record = PACKET_LIST_RECORD_GET(packet_list->visible_rows, vis_idx);
+                       switch (cfile.cinfo.col_fmt[col]) {
+
+                       case COL_NUMBER:
+                               if (record->fdata->num > widest_column_val)
+                                       widest_column_val = record->fdata->num;
+                               break;
+                       case COL_PACKET_LENGTH:
+                               if (record->fdata->pkt_len > widest_column_val)
+                                       widest_column_val = record->fdata->pkt_len;
+                               break;
+                       case COL_CUMULATIVE_BYTES:
+                               if (record->fdata->cum_bytes > widest_column_val)
+                                       widest_column_val = record->fdata->cum_bytes;
+                               break;
+                       case COL_ABS_TIME:
+                               if (nstime_cmp(&record->fdata->abs_ts, &widest_column_time))
+                                       widest_column_time = record->fdata->abs_ts;
+                               break;
+                       case COL_REL_TIME:
+                               if (nstime_cmp(&record->fdata->rel_ts, &widest_column_time))
+                                       widest_column_time = record->fdata->rel_ts;
+                               break;
+                       case COL_DELTA_TIME:
+                               if (nstime_cmp(&record->fdata->del_cap_ts, &widest_column_time))
+                                       widest_column_time = record->fdata->del_cap_ts;
+                               break;
+                       case COL_DELTA_TIME_DIS:
+                               if (nstime_cmp(&record->fdata->del_dis_ts, &widest_column_time))
+                                       widest_column_time = record->fdata->del_dis_ts;
+                               break;
+
+                       case COL_CLS_TIME:
+                       case COL_ABS_DATE_TIME:
+                               /* TODO: Implement */
+                               break;
+
+                       default:
+                               g_assert_not_reached();
+                       }
+               }
+
+               switch (cfile.cinfo.col_fmt[col]) {
+
+               case COL_NUMBER:
+               case COL_PACKET_LENGTH:
+               case COL_CUMULATIVE_BYTES:
+            return ep_strdup_printf("%u", widest_column_val);
+
+               case COL_ABS_TIME:
+               case COL_REL_TIME:
+               case COL_DELTA_TIME:
+               case COL_DELTA_TIME_DIS:
+                       /* TODO: Implement */
+                       return get_column_width_string(get_column_format(col), col);
+
+               case COL_CLS_TIME:
+               case COL_ABS_DATE_TIME:
+                       /* TODO: Implement */
+                       return get_column_width_string(get_column_format(col), col);
+
+               default:
+                       g_assert_not_reached();
+                       return NULL;
+               }
        }
        else {
                PacketListRecord *record;
                guint vis_idx;
-               guint widest_column_idx = 0;
+
+               gchar *widest_column_str = NULL;
                guint widest_column_len = 0;
 
-        if (!packet_list->columnized)
-            packet_list_dissect_and_cache_all(packet_list);
+               if (!packet_list->columnized)
+                       packet_list_dissect_and_cache_all(packet_list);
 
                for(vis_idx = 0; vis_idx < PACKET_LIST_RECORD_COUNT(packet_list->visible_rows); ++vis_idx) {
                        record = PACKET_LIST_RECORD_GET(packet_list->visible_rows, vis_idx);
                        if (record->fdata->col_text_len[col] > widest_column_len) {
-                               widest_column_idx = vis_idx;
+                               widest_column_str = record->fdata->col_text[col];
                                widest_column_len = record->fdata->col_text_len[col];
                        }
                }
 
-               g_assert(widest_column_idx < PACKET_LIST_RECORD_COUNT(packet_list->visible_rows));
-               record = PACKET_LIST_RECORD_GET(packet_list->visible_rows, widest_column_idx);
-               return record->fdata->col_text[col];
+               return widest_column_str;
        }
 }