Move the contents of image/expert_*.h to gtk/expert_indicators.h. Add
[obnox/wireshark/wip.git] / gtk / main_statusbar.c
1 /* main_statusbar.c
2  *
3  * $Id$
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32
33 #include <gtk/gtk.h>
34
35 #include <epan/epan.h>
36 #include <epan/filesystem.h>
37 #include <epan/epan_dissect.h>
38 #include <epan/expert.h>
39 #include <epan/prefs.h>
40
41 #include "../cfile.h"
42 #include "../file.h"
43 #include "../capture_opts.h"
44 #include "../capture_ui_utils.h"
45 #ifdef HAVE_LIBPCAP
46 #include "../capture.h"
47 #endif
48
49 #include "gtk/recent.h"
50 #include "gtk/main.h"
51 #include "gtk/main_statusbar.h"
52 #include "gtk/main_statusbar_private.h"
53 #include "gtk/gui_utils.h"
54 #include "gtk/gtkglobals.h"
55 #include "gtk/expert_comp_dlg.h"
56 #include "gtk/profile_dlg.h"
57 #include "gtk/main_welcome.h"
58 #include "gtk/expert_indicators.h"
59
60 /*
61  * The order below defines the priority of info bar contexts.
62  */
63 typedef enum {
64     STATUS_LEVEL_MAIN,
65     STATUS_LEVEL_FILE,
66     STATUS_LEVEL_FILTER,
67     STATUS_LEVEL_HELP,
68     NUM_STATUS_LEVELS
69 } status_level_e;
70
71
72 #ifdef HAVE_LIBPCAP
73 #define DEF_READY_MESSAGE " Ready to load or capture"
74 #else
75 #define DEF_READY_MESSAGE " Ready to load file"
76 #endif
77
78
79 static GtkWidget    *status_pane_left, *status_pane_right;
80 static GtkWidget    *info_bar, *info_bar_event, *packets_bar, *profile_bar, *profile_bar_event;
81 static GtkWidget    *expert_info_error, *expert_info_warn, *expert_info_note;
82 static GtkWidget    *expert_info_chat, *expert_info_none;
83
84 static guint        main_ctx, file_ctx, help_ctx, filter_ctx, packets_ctx, profile_ctx;
85 static guint        status_levels[NUM_STATUS_LEVELS];
86 static gchar        *packets_str = NULL;
87 static gchar        *profile_str = NULL;
88
89
90 static void info_bar_new(void);
91 static void packets_bar_new(void);
92 static void profile_bar_new(void);
93 static void status_expert_new(void);
94
95 /* Temporary message timeouts */
96 #define TEMPORARY_MSG_TIMEOUT (7 * 1000)
97 #define TEMPORARY_FLASH_TIMEOUT (1 * 1000)
98 #define TEMPORARY_FLASH_INTERVAL (TEMPORARY_FLASH_TIMEOUT / 4)
99 static gint flash_time;
100 static gboolean flash_highlight = FALSE;
101
102 /*
103  * Push a message referring to file access onto the statusbar.
104  */
105 static void
106 statusbar_push_file_msg(const gchar *msg)
107 {
108     int i;
109
110     /*g_warning("statusbar_push: %s", msg);*/
111     for (i = STATUS_LEVEL_FILE + 1; i < NUM_STATUS_LEVELS; i++) {
112         if (status_levels[i])
113             return;
114     }
115     status_levels[STATUS_LEVEL_FILE]++;
116
117     gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, msg);
118 }
119
120 /*
121  * Pop a message referring to file access off the statusbar.
122  */
123 static void
124 statusbar_pop_file_msg(void)
125 {
126     /*g_warning("statusbar_pop");*/
127     if (status_levels[STATUS_LEVEL_FILE] > 0) {
128         status_levels[STATUS_LEVEL_FILE]--;
129     }
130     gtk_statusbar_pop(GTK_STATUSBAR(info_bar), file_ctx);
131 }
132
133 /*
134  * Push a message referring to the currently-selected field onto the statusbar.
135  */
136 void
137 statusbar_push_field_msg(const gchar *msg)
138 {
139     int i;
140
141     for (i = STATUS_LEVEL_HELP + 1; i < NUM_STATUS_LEVELS; i++) {
142         if (status_levels[i])
143             return;
144     }
145     status_levels[STATUS_LEVEL_HELP]++;
146
147     gtk_statusbar_push(GTK_STATUSBAR(info_bar), help_ctx, msg);
148 }
149
150 /*
151  * Pop a message referring to the currently-selected field off the statusbar.
152  */
153 void
154 statusbar_pop_field_msg(void)
155 {
156     if (status_levels[STATUS_LEVEL_HELP] > 0) {
157         status_levels[STATUS_LEVEL_HELP]--;
158     }
159     gtk_statusbar_pop(GTK_STATUSBAR(info_bar), help_ctx);
160 }
161
162 /*
163  * Push a message referring to the current filter onto the statusbar.
164  */
165 void
166 statusbar_push_filter_msg(const gchar *msg)
167 {
168     int i;
169
170     for (i = STATUS_LEVEL_FILTER + 1; i < NUM_STATUS_LEVELS; i++) {
171         if (status_levels[i])
172             return;
173     }
174     status_levels[STATUS_LEVEL_FILTER]++;
175
176     gtk_statusbar_push(GTK_STATUSBAR(info_bar), filter_ctx, msg);
177 }
178
179 /*
180  * Pop a message referring to the current filter off the statusbar.
181  */
182 void
183 statusbar_pop_filter_msg(void)
184 {
185     if (status_levels[STATUS_LEVEL_FILTER] > 0) {
186         status_levels[STATUS_LEVEL_FILTER]--;
187     }
188     gtk_statusbar_pop(GTK_STATUSBAR(info_bar), filter_ctx);
189 }
190
191 /*
192  * Timeout callbacks for statusbar_push_temporary_msg
193  */
194 static gboolean
195 statusbar_remove_temporary_msg(gpointer data)
196 {
197     guint msg_id = GPOINTER_TO_UINT(data);
198     
199     gtk_statusbar_remove(GTK_STATUSBAR(info_bar), main_ctx, msg_id);
200
201     return FALSE;
202 }
203
204 static gboolean
205 statusbar_flash_temporary_msg(gpointer data _U_)
206 {
207     gboolean retval = TRUE;
208
209     if (flash_time > 0) {
210         flash_highlight = !flash_highlight;
211     } else {
212         flash_highlight = FALSE;
213         retval = FALSE;
214     }
215
216     /*
217      * As of 2.18.3 gtk_drag_highlight just draws a border around the widget
218      * so we can abuse it here.
219      */
220     if (flash_highlight) {
221         gtk_drag_highlight(info_bar);
222     } else {
223         gtk_drag_unhighlight(info_bar);
224     }
225
226     flash_time -= TEMPORARY_FLASH_INTERVAL;    
227
228     return retval;
229 }
230
231 /*
232  * Push a temporary message onto the statusbar.
233  */
234 void
235 statusbar_push_temporary_msg(const gchar *msg)
236 {
237     guint msg_id;
238     
239     msg_id = gtk_statusbar_push(GTK_STATUSBAR(info_bar), main_ctx, msg);
240     
241     flash_time = TEMPORARY_FLASH_TIMEOUT - 1;
242     g_timeout_add(TEMPORARY_FLASH_INTERVAL, statusbar_flash_temporary_msg, NULL);
243
244     g_timeout_add(TEMPORARY_MSG_TIMEOUT, statusbar_remove_temporary_msg, GUINT_TO_POINTER(msg_id));
245 }
246
247
248 GtkWidget *
249 statusbar_new(void)
250 {
251     GtkWidget *status_hbox;
252
253     /* Sstatus hbox */
254     status_hbox = gtk_hbox_new(FALSE, 1);
255     gtk_container_set_border_width(GTK_CONTAINER(status_hbox), 0);
256
257     /* info (main) statusbar */
258     info_bar_new();
259
260     /* packets statusbar */
261     packets_bar_new();
262
263     /* profile statusbar */
264     profile_bar_new();
265
266     /* expert info indicator */
267     status_expert_new();
268
269     /* Pane for the statusbar */
270     status_pane_left = gtk_hpaned_new();
271     gtk_widget_show(status_pane_left);
272     status_pane_right = gtk_hpaned_new();
273     gtk_widget_show(status_pane_right);
274
275     return status_hbox;
276 }
277
278 void
279 statusbar_load_window_geometry(void)
280 {
281     if (recent.has_gui_geometry_status_pane && recent.gui_geometry_status_pane_left)
282         gtk_paned_set_position(GTK_PANED(status_pane_left), recent.gui_geometry_status_pane_left);
283     if (recent.has_gui_geometry_status_pane && recent.gui_geometry_status_pane_right)
284         gtk_paned_set_position(GTK_PANED(status_pane_right), recent.gui_geometry_status_pane_right);
285 }
286
287 void
288 statusbar_save_window_geometry(void)
289 {
290     recent.gui_geometry_status_pane_left    = gtk_paned_get_position(GTK_PANED(status_pane_left));
291     recent.gui_geometry_status_pane_right   = gtk_paned_get_position(GTK_PANED(status_pane_right));
292 }
293
294
295 /*
296  * Helper for statusbar_widgets_emptying()
297  */
298 static void
299 foreach_remove_a_child(GtkWidget *widget, gpointer data) {
300     gtk_container_remove(GTK_CONTAINER(data), widget);
301 }
302
303 void
304 statusbar_widgets_emptying(GtkWidget *statusbar)
305 {
306     g_object_ref(G_OBJECT(info_bar));
307     g_object_ref(G_OBJECT(info_bar_event));
308     g_object_ref(G_OBJECT(packets_bar));
309     g_object_ref(G_OBJECT(profile_bar));
310     g_object_ref(G_OBJECT(profile_bar_event));
311     g_object_ref(G_OBJECT(status_pane_left));
312     g_object_ref(G_OBJECT(status_pane_right));
313     g_object_ref(G_OBJECT(expert_info_error));
314     g_object_ref(G_OBJECT(expert_info_warn));
315     g_object_ref(G_OBJECT(expert_info_note));
316     g_object_ref(G_OBJECT(expert_info_chat));
317     g_object_ref(G_OBJECT(expert_info_none));
318
319     /* empty all containers participating */
320     gtk_container_foreach(GTK_CONTAINER(statusbar),     foreach_remove_a_child, statusbar);
321     gtk_container_foreach(GTK_CONTAINER(status_pane_left),   foreach_remove_a_child, status_pane_left);
322     gtk_container_foreach(GTK_CONTAINER(status_pane_right),   foreach_remove_a_child, status_pane_right);
323 }
324
325 void
326 statusbar_widgets_pack(GtkWidget *statusbar)
327 {
328     gtk_box_pack_start(GTK_BOX(statusbar), expert_info_error, FALSE, FALSE, 2);
329     gtk_box_pack_start(GTK_BOX(statusbar), expert_info_warn, FALSE, FALSE, 2);
330     gtk_box_pack_start(GTK_BOX(statusbar), expert_info_note, FALSE, FALSE, 2);
331     gtk_box_pack_start(GTK_BOX(statusbar), expert_info_chat, FALSE, FALSE, 2);
332     gtk_box_pack_start(GTK_BOX(statusbar), expert_info_none, FALSE, FALSE, 2);
333     gtk_box_pack_start(GTK_BOX(statusbar), status_pane_left, TRUE, TRUE, 0);
334     gtk_paned_pack1(GTK_PANED(status_pane_left), info_bar_event, FALSE, FALSE);
335     gtk_paned_pack2(GTK_PANED(status_pane_left), status_pane_right, TRUE, FALSE);
336     gtk_paned_pack1(GTK_PANED(status_pane_right), packets_bar, TRUE, FALSE);
337     gtk_paned_pack2(GTK_PANED(status_pane_right), profile_bar_event, FALSE, FALSE);
338 }
339
340 void
341 statusbar_widgets_show_or_hide(GtkWidget *statusbar)
342 {
343     /*
344      * Show the status hbox if either:
345      *
346      *    1) we're showing the filter toolbar and we want it in the status
347      *       line
348      *
349      * or
350      *
351      *    2) we're showing the status bar.
352      */
353     if ((recent.filter_toolbar_show && prefs.filter_toolbar_show_in_statusbar) ||
354          recent.statusbar_show) {
355         gtk_widget_show(statusbar);
356     } else {
357         gtk_widget_hide(statusbar);
358     }
359
360     if (recent.statusbar_show) {
361         gtk_widget_show(status_pane_left);
362     } else {
363         gtk_widget_hide(status_pane_left);
364     }
365 }
366
367
368 static void
369 info_bar_new(void)
370 {
371     int i;
372
373     info_bar_event = gtk_event_box_new();
374     info_bar = gtk_statusbar_new();
375     gtk_container_add(GTK_CONTAINER(info_bar_event), info_bar);
376     main_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "main");
377     file_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "file");
378     help_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "help");
379     filter_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "filter");
380     gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(info_bar), FALSE);
381     gtk_statusbar_push(GTK_STATUSBAR(info_bar), main_ctx, DEF_READY_MESSAGE);
382
383     for (i = 0; i < NUM_STATUS_LEVELS; i++) {
384         status_levels[i] = 0;
385     }
386
387     gtk_widget_show(info_bar);
388     gtk_widget_show(info_bar_event);
389 }
390
391 static void
392 packets_bar_new(void)
393 {
394     /* tip: tooltips don't work on statusbars! */
395     packets_bar = gtk_statusbar_new();
396     packets_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(packets_bar), "packets");
397     packets_bar_update();
398     gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(packets_bar), FALSE);
399
400     gtk_widget_show(packets_bar);
401 }
402
403 static void
404 profile_bar_new(void)
405 {
406     GtkTooltips   *tooltips;
407
408     tooltips = gtk_tooltips_new();
409
410     profile_bar_event = gtk_event_box_new();
411     profile_bar = gtk_statusbar_new();
412     gtk_container_add(GTK_CONTAINER(profile_bar_event), profile_bar);
413     g_signal_connect(profile_bar_event, "button_press_event", G_CALLBACK(profile_show_popup_cb), NULL);
414     profile_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(profile_bar), "profile");
415     gtk_tooltips_set_tip (tooltips, profile_bar_event,
416                           "Click to change configuration profile", NULL);
417     profile_bar_update();
418
419     gtk_widget_show(profile_bar);
420     gtk_widget_show(profile_bar_event);
421 }
422
423
424 /*
425  * update the packets statusbar to the current values
426  */
427 void
428 packets_bar_update(void)
429 {
430     if(packets_bar) {
431         /* remove old status */
432         if(packets_str) {
433             g_free(packets_str);
434             gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx);
435         }
436
437         /* do we have any packets? */
438         if(cfile.count) {
439             if(cfile.drops_known) {
440                 packets_str = g_strdup_printf(" Packets: %u Displayed: %u Marked: %u Dropped: %u",
441                     cfile.count, cfile.displayed_count, cfile.marked_count, cfile.drops);
442             } else {
443                 gulong computed_elapsed = cf_get_computed_elapsed();
444
445                 packets_str = g_strdup_printf(" Packets: %u Displayed: %u Marked: %u  Time: %02lu:%02lu:%02lu.%03lu",
446                     cfile.count, cfile.displayed_count, cfile.marked_count,
447                     computed_elapsed/3600000,
448                     computed_elapsed%3600000/60000,
449                     computed_elapsed%60000/1000,
450                     computed_elapsed%1000);
451             }
452         } else {
453             packets_str = g_strdup(" No Packets");
454         }
455         gtk_statusbar_push(GTK_STATUSBAR(packets_bar), packets_ctx, packets_str);
456     }
457 }
458
459 /*
460  * update the packets statusbar to the current values
461  */
462 void
463 profile_bar_update(void)
464 {
465     if (profile_bar) {
466         /* remove old status */
467         if(profile_str) {
468             g_free(profile_str);
469             gtk_statusbar_pop(GTK_STATUSBAR(profile_bar), profile_ctx);
470         }
471
472         profile_str = g_strdup_printf (" Profile: %s", get_profile_name ());
473
474         gtk_statusbar_push(GTK_STATUSBAR(profile_bar), profile_ctx, profile_str);
475     }
476 }
477
478
479 static void
480 status_expert_new(void)
481 {
482     GtkWidget *expert_image;
483     GtkTooltips   *tooltips;
484
485     tooltips = gtk_tooltips_new();
486
487     expert_image = pixbuf_to_widget(expert_error_pb_data);
488     gtk_tooltips_set_tip(tooltips, expert_image, "ERROR is the highest expert info level", NULL);
489     gtk_widget_show(expert_image);
490     expert_info_error = gtk_event_box_new();
491     gtk_container_add(GTK_CONTAINER(expert_info_error), expert_image);
492     g_signal_connect(expert_info_error, "button_press_event", G_CALLBACK(expert_comp_dlg_cb), NULL);
493
494     expert_image = pixbuf_to_widget(expert_warn_pb_data);
495     gtk_tooltips_set_tip(tooltips, expert_image, "WARNING is the highest expert info level", NULL);
496     gtk_widget_show(expert_image);
497     expert_info_warn = gtk_event_box_new();
498     gtk_container_add(GTK_CONTAINER(expert_info_warn), expert_image);
499     g_signal_connect(expert_info_warn, "button_press_event", G_CALLBACK(expert_comp_dlg_cb), NULL);
500
501     expert_image = pixbuf_to_widget(expert_note_pb_data);
502     gtk_tooltips_set_tip(tooltips, expert_image, "NOTE is the highest expert info level", NULL);
503     gtk_widget_show(expert_image);
504     expert_info_note = gtk_event_box_new();
505     gtk_container_add(GTK_CONTAINER(expert_info_note), expert_image);
506     g_signal_connect(expert_info_note, "button_press_event", G_CALLBACK(expert_comp_dlg_cb), NULL);
507
508     expert_image = pixbuf_to_widget(expert_chat_pb_data);
509     gtk_tooltips_set_tip(tooltips, expert_image, "CHAT is the highest expert info level", NULL);
510     gtk_widget_show(expert_image);
511     expert_info_chat = gtk_event_box_new();
512     gtk_container_add(GTK_CONTAINER(expert_info_chat), expert_image);
513     g_signal_connect(expert_info_chat, "button_press_event", G_CALLBACK(expert_comp_dlg_cb), NULL);
514
515     expert_image = pixbuf_to_widget(expert_none_pb_data);
516     gtk_tooltips_set_tip(tooltips, expert_image, "No expert info", NULL);
517     gtk_widget_show(expert_image);
518     expert_info_none = gtk_event_box_new();
519     gtk_container_add(GTK_CONTAINER(expert_info_none), expert_image);
520     g_signal_connect(expert_info_none, "button_press_event", G_CALLBACK(expert_comp_dlg_cb), NULL);
521     gtk_widget_show(expert_info_none);
522 }
523
524 static void
525 status_expert_hide(void)
526 {
527     /* reset expert info indicator */
528     gtk_widget_hide(expert_info_error);
529     gtk_widget_hide(expert_info_warn);
530     gtk_widget_hide(expert_info_note);
531     gtk_widget_hide(expert_info_chat);
532     gtk_widget_hide(expert_info_none);
533 }
534
535 void
536 status_expert_update(void)
537 {
538     status_expert_hide();
539
540     switch(expert_get_highest_severity()) {
541         case(PI_ERROR):
542         gtk_widget_show(expert_info_error);
543         break;
544         case(PI_WARN):
545         gtk_widget_show(expert_info_warn);
546         break;
547         case(PI_NOTE):
548         gtk_widget_show(expert_info_note);
549         break;
550         case(PI_CHAT):
551         gtk_widget_show(expert_info_chat);
552         break;
553         default:
554         gtk_widget_show(expert_info_none);
555         break;
556     }
557 }
558
559 static void
560 statusbar_set_filename(const char *file_name, gint64 file_length, nstime_t *file_elapsed_time)
561 {
562   gchar       *size_str;
563   gchar       *status_msg;
564
565   /* expert info indicator */
566   status_expert_update();
567
568   /* statusbar */
569   /* convert file size */
570   if (file_length/1024/1024 > 10) {
571     size_str = g_strdup_printf("%" G_GINT64_MODIFIER "d MB", file_length/1024/1024);
572   } else if (file_length/1024 > 10) {
573     size_str = g_strdup_printf("%" G_GINT64_MODIFIER "d KB", file_length/1024);
574   } else {
575     size_str = g_strdup_printf("%" G_GINT64_MODIFIER "d Bytes", file_length);
576   }
577
578   status_msg = g_strdup_printf(" File: \"%s\" %s %02lu:%02lu:%02lu",
579     (file_name) ? file_name : "", size_str,
580     (long)file_elapsed_time->secs/3600,
581     (long)file_elapsed_time->secs%3600/60,
582     (long)file_elapsed_time->secs%60);
583   g_free(size_str);
584   statusbar_push_file_msg(status_msg);
585   g_free(status_msg);
586 }
587
588
589 static void
590 statusbar_cf_file_closing_cb(capture_file *cf _U_)
591 {
592     /* Clear any file-related status bar messages.
593        XXX - should be "clear *ALL* file-related status bar messages;
594        will there ever be more than one on the stack? */
595     statusbar_pop_file_msg();
596
597     /* reset expert info indicator */
598     status_expert_hide();
599     gtk_widget_show(expert_info_none);
600 }
601
602
603 static void
604 statusbar_cf_file_closed_cb(capture_file *cf _U_)
605 {
606   /* go back to "No packets" */
607   packets_bar_update();
608 }
609
610
611 static void
612 statusbar_cf_file_read_start_cb(capture_file *cf)
613 {
614   const gchar *name_ptr;
615   gchar       *load_msg;
616
617   /* Ensure we pop any previous loaded filename */
618   statusbar_pop_file_msg();
619
620   name_ptr = get_basename(cf->filename);
621
622   load_msg = g_strdup_printf(" Loading: %s", name_ptr);
623   statusbar_push_file_msg(load_msg);
624   g_free(load_msg);
625 }
626
627
628 static void
629 statusbar_cf_file_read_finished_cb(capture_file *cf)
630 {
631     statusbar_pop_file_msg();
632     statusbar_set_filename(cf->filename, cf->f_datalen, &(cf->elapsed_time));
633 }
634
635
636 #ifdef HAVE_LIBPCAP
637 static void
638 statusbar_capture_prepared_cb(capture_options *capture_opts _U_)
639 {
640     gchar *msg = " Waiting for capture input data ...";
641     statusbar_push_file_msg(msg);
642     welcome_header_push_msg(msg);
643 }
644
645 static void
646 statusbar_capture_update_started_cb(capture_options *capture_opts)
647 {
648     gchar *capture_msg;
649
650
651     statusbar_pop_file_msg();
652     welcome_header_pop_msg();
653
654     if(capture_opts->iface) {
655         capture_msg = g_strdup_printf(" %s: <live capture in progress> to file: %s",
656                                       get_iface_description(capture_opts),
657                                       (capture_opts->save_file) ? capture_opts->save_file : "");
658     } else {
659         capture_msg = g_strdup_printf(" <live capture in progress> to file: %s",
660             (capture_opts->save_file) ? capture_opts->save_file : "");
661     }
662
663     statusbar_push_file_msg(capture_msg);
664
665     g_free(capture_msg);
666 }
667
668 static void
669 statusbar_capture_update_continue_cb(capture_options *capture_opts)
670 {
671     capture_file *cf = capture_opts->cf;
672     gchar *capture_msg;
673
674
675     status_expert_update();
676
677     statusbar_pop_file_msg();
678
679     if (cf->f_datalen/1024/1024 > 10) {
680         capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d MB",
681                                       get_iface_description(capture_opts),
682                                       capture_opts->save_file,
683                                       cf->f_datalen/1024/1024);
684     } else if (cf->f_datalen/1024 > 10) {
685         capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d KB",
686                                       get_iface_description(capture_opts),
687                                       capture_opts->save_file,
688                                       cf->f_datalen/1024);
689     } else {
690         capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d Bytes",
691                                       get_iface_description(capture_opts),
692                                       capture_opts->save_file,
693                                       cf->f_datalen);
694     }
695
696     statusbar_push_file_msg(capture_msg);
697 }
698
699 static void
700 statusbar_capture_update_finished_cb(capture_options *capture_opts)
701 {
702     capture_file *cf = capture_opts->cf;
703
704     /* Pop the "<live capture in progress>" message off the status bar. */
705     statusbar_pop_file_msg();
706     statusbar_set_filename(cf->filename, cf->f_datalen, &(cf->elapsed_time));
707 }
708
709 static void
710 statusbar_capture_fixed_started_cb(capture_options *capture_opts)
711 {
712     gchar *capture_msg;
713
714
715     statusbar_pop_file_msg();
716
717     capture_msg = g_strdup_printf(" %s: <live capture in progress> to file: %s",
718                                   get_iface_description(capture_opts),
719                                   (capture_opts->save_file) ? capture_opts->save_file : "");
720
721     statusbar_push_file_msg(capture_msg);
722     gtk_statusbar_push(GTK_STATUSBAR(packets_bar), packets_ctx, " Packets: 0");
723
724     g_free(capture_msg);
725 }
726
727 static void
728 statusbar_capture_fixed_continue_cb(capture_options *capture_opts)
729 {
730     capture_file *cf = capture_opts->cf;
731     gchar *capture_msg;
732
733
734     gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx);
735     capture_msg = g_strdup_printf(" Packets: %u", cf_get_packet_count(cf));
736     gtk_statusbar_push(GTK_STATUSBAR(packets_bar), packets_ctx, capture_msg);
737     g_free(capture_msg);
738 }
739
740
741 static void
742 statusbar_capture_fixed_finished_cb(capture_options *capture_opts _U_)
743 {
744 #if 0
745     capture_file *cf = capture_opts->cf;
746 #endif
747
748     /* Pop the "<live capture in progress>" message off the status bar. */
749     statusbar_pop_file_msg();
750     welcome_header_pop_msg();
751
752     /* Pop the "<capturing>" message off the status bar */
753     gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx);
754 }
755
756 #endif /* HAVE_LIBPCAP */
757
758
759 static void
760 statusbar_cf_field_unselected_cb(capture_file *cf _U_)
761 {
762     statusbar_pop_field_msg();
763 }
764
765 static void
766 statusbar_cf_file_safe_started_cb(gchar * filename)
767 {
768     gchar        *save_msg;
769
770     save_msg = g_strdup_printf(" Saving: %s...", get_basename(filename));
771     statusbar_push_file_msg(save_msg);
772     g_free(save_msg);
773 }
774
775 static void
776 statusbar_cf_file_safe_finished_cb(gpointer data _U_)
777 {
778     /* Pop the "Saving:" message off the status bar. */
779     statusbar_pop_file_msg();
780 }
781
782 static void
783 statusbar_cf_file_safe_failed_cb(gpointer data _U_)
784 {
785     /* Pop the "Saving:" message off the status bar. */
786     statusbar_pop_file_msg();
787 }
788
789
790
791 void
792 statusbar_cf_callback(gint event, gpointer data, gpointer user_data _U_)
793 {
794     switch(event) {
795     case(cf_cb_file_closing):
796         statusbar_cf_file_closing_cb(data);
797         break;
798     case(cf_cb_file_closed):
799         statusbar_cf_file_closed_cb(data);
800         break;
801     case(cf_cb_file_read_start):
802         statusbar_cf_file_read_start_cb(data);
803         break;
804     case(cf_cb_file_read_finished):
805         statusbar_cf_file_read_finished_cb(data);
806         break;
807     case(cf_cb_packet_selected):
808         break;
809     case(cf_cb_packet_unselected):
810         break;
811     case(cf_cb_field_unselected):
812         statusbar_cf_field_unselected_cb(data);
813         break;
814     case(cf_cb_file_safe_started):
815         statusbar_cf_file_safe_started_cb(data);
816         break;
817     case(cf_cb_file_safe_finished):
818         statusbar_cf_file_safe_finished_cb(data);
819         break;
820     case(cf_cb_file_safe_reload_finished):
821         break;
822     case(cf_cb_file_safe_failed):
823         statusbar_cf_file_safe_failed_cb(data);
824         break;
825     default:
826         g_warning("statusbar_cf_callback: event %u unknown", event);
827         g_assert_not_reached();
828     }
829 }
830
831 #ifdef HAVE_LIBPCAP
832 void
833 statusbar_capture_callback(gint event, capture_options *capture_opts,
834                            gpointer user_data _U_)
835 {
836     switch(event) {
837     case(capture_cb_capture_prepared):
838         statusbar_capture_prepared_cb(capture_opts);
839         break;
840     case(capture_cb_capture_update_started):
841         statusbar_capture_update_started_cb(capture_opts);
842         break;
843     case(capture_cb_capture_update_continue):
844         statusbar_capture_update_continue_cb(capture_opts);
845         break;
846     case(capture_cb_capture_update_finished):
847         statusbar_capture_update_finished_cb(capture_opts);
848         break;
849     case(capture_cb_capture_fixed_started):
850         statusbar_capture_fixed_started_cb(capture_opts);
851         break;
852     case(capture_cb_capture_fixed_continue):
853         statusbar_capture_fixed_continue_cb(capture_opts);
854         break;
855     case(capture_cb_capture_fixed_finished):
856         statusbar_capture_fixed_finished_cb(capture_opts);
857         break;
858     case(capture_cb_capture_stopping):
859         /* Beware: this state won't be called, if the capture child
860          * closes the capturing on it's own! */
861         break;
862     default:
863         g_warning("statusbar_capture_callback: event %u unknown", event);
864         g_assert_not_reached();
865     }
866 }
867 #endif