a888f6847a8f033b79ebf6d1def15e9549b4231e
[metze/wireshark/wip.git] / ui / gtk / main_welcome.c
1 /* main_welcome.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 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
30 #endif
31 #include <time.h>
32
33 #include <gtk/gtk.h>
34
35 #include <epan/prefs.h>
36
37 #include "../color.h"
38 #ifdef HAVE_LIBPCAP
39 #include "capture.h"
40 #include "capture-pcap-util.h"
41 #include "capture_opts.h"
42 #include "capture_ui_utils.h"
43 #endif
44
45 #include <wsutil/file_util.h>
46
47 #include "ui/recent.h"
48 #include "ui/simple_dialog.h"
49
50 #include "ui/gtk/gui_utils.h"
51 #include "ui/gtk/color_utils.h"
52 #include "ui/gtk/gtkglobals.h"
53 #include "ui/gtk/main.h"
54 #include "ui/gtk/menus.h"
55 #include "ui/gtk/main_welcome.h"
56 #include "ui/gtk/help_dlg.h"
57 #include "ui/gtk/capture_file_dlg.h"
58 #include "ui/gtk/stock_icons.h"
59 #include "ui/gtk/utf8_entities.h"
60 #ifdef HAVE_LIBPCAP
61 #include "ui/gtk/capture_dlg.h"
62 #include "ui/gtk/capture_if_dlg.h"
63 #include "ui/gtk/capture_globals.h"
64 #if GTK_CHECK_VERSION(2,18,0)
65 #include "ui/gtk/webbrowser.h"
66 #endif
67 #endif /* HAVE_LIBPCAP */
68 #include "../../image/wssplash-dev.xpm"
69 #include "../version_info.h"
70
71 #ifdef _WIN32
72 #include <tchar.h>
73 #include <windows.h>
74 #endif
75
76 #ifdef HAVE_AIRPCAP
77 #include "airpcap.h"
78 #include "airpcap_loader.h"
79 #include "airpcap_gui_utils.h"
80 #endif
81 #if defined(HAVE_AIRPCAP)
82 #include "../../image/toolbar/capture_airpcap_16.xpm"
83 #endif
84 #if defined(HAVE_PCAP_REMOTE)
85 #include "ui/gtk/remote_icons.h"
86 #endif
87
88 /* XXX */
89 static GtkWidget *welcome_hb = NULL;
90 static GtkWidget *header_lb = NULL;
91 /* Foreground colors are set using Pango markup */
92 #if GTK_CHECK_VERSION(3,0,0)
93 static GdkRGBA rgba_welcome_bg = {0.901, 0.901, 0.901, 1.0 };
94 static GdkRGBA rgba_header_bar_bg = { 0.094, 0.360, 0.792, 1.0 };
95 static GdkRGBA rgba_topic_header_bg = {  0.004, 0.224, 0.745, 1.0 };
96 static GdkRGBA rgba_topic_content_bg = { 1, 1, 1, 1.0 };
97 static GdkRGBA rgba_topic_item_idle_bg;
98 static GdkRGBA rgba_topic_item_entered_bg =  { 0.827, 0.847, 0.854, 1.0 };
99 #else
100 static GdkColor welcome_bg = { 0, 0xe6e6, 0xe6e6, 0xe6e6 };
101 static GdkColor header_bar_bg = { 0, 0x1818, 0x5c5c, 0xcaca };
102 static GdkColor topic_header_bg = { 0, 0x0101, 0x3939, 0xbebe };
103 static GdkColor topic_content_bg = { 0, 0xffff, 0xffff, 0xffff };
104 static GdkColor topic_item_idle_bg;
105 static GdkColor topic_item_entered_bg = { 0, 0xd3d3, 0xd8d8, 0xdada };
106 #endif
107 static GtkWidget *welcome_file_panel_vb = NULL;
108 #ifdef HAVE_LIBPCAP
109 static GtkWidget *if_view = NULL;
110 static GtkWidget *swindow;
111 #endif
112
113 static GSList *status_messages = NULL;
114
115 static GMutex *recent_mtx;
116
117 #ifdef HAVE_LIBPCAP
118 static void capture_if_start(GtkWidget *w _U_, gpointer data _U_);
119 static gboolean activate_link_cb(GtkLabel *label _U_, gchar *uri, gpointer user_data _U_);
120 static void welcome_if_tree_load(void);
121 #endif
122
123 /* The "scroll box dynamic" is a (complicated) pseudo widget to */
124 /* place a vertically list of widgets in (currently the interfaces and recent files). */
125 /* Once this list get's higher than a specified amount, */
126 /* it is moved into a scrolled_window. */
127 /* This is all complicated, the scrolled window is a bit ugly, */
128 /* the sizes might not be the same on all systems, ... */
129 /* ... but that's the best what we currently have */
130 #define SCROLL_BOX_CHILD_BOX          "ScrollBoxDynamic_ChildBox"
131 #define SCROLL_BOX_MAX_CHILDS         "ScrollBoxDynamic_MaxChilds"
132 #define SCROLL_BOX_SCROLLW_Y_SIZE     "ScrollBoxDynamic_Scrollw_Y_Size"
133 #define SCROLL_BOX_SCROLLW            "ScrollBoxDynamic_Scrollw"
134 #define TREE_VIEW_INTERFACES          "TreeViewInterfaces"
135 #define CAPTURE_VIEW                  "CaptureView"
136 #define CAPTURE_LABEL                 "CaptureLabel"
137 #define CAPTURE_HB_BOX_INTERFACE_LIST "CaptureHorizontalBoxInterfaceList"
138 #define CAPTURE_HB_BOX_START          "CaptureHorizontalBoxStart"
139 #define CAPTURE_HB_BOX_CAPTURE        "CaptureHorizontalBoxCapture"
140
141
142 static GtkWidget *
143 scroll_box_dynamic_new(GtkWidget *child_box, guint max_childs, guint scrollw_y_size) {
144     GtkWidget * parent_box;
145
146
147     parent_box = gtk_vbox_new(FALSE, 0);
148     gtk_box_pack_start(GTK_BOX(parent_box), GTK_WIDGET(child_box), TRUE, TRUE, 0);
149     g_object_set_data(G_OBJECT(parent_box), SCROLL_BOX_CHILD_BOX, child_box);
150     g_object_set_data(G_OBJECT(parent_box), SCROLL_BOX_MAX_CHILDS, GINT_TO_POINTER(max_childs));
151     g_object_set_data(G_OBJECT(parent_box), SCROLL_BOX_SCROLLW_Y_SIZE, GINT_TO_POINTER(scrollw_y_size));
152     gtk_widget_show_all(parent_box);
153
154     return parent_box;
155 }
156
157
158 static GtkWidget *
159 scroll_box_dynamic_add(GtkWidget *parent_box)
160 {
161     GtkWidget *child_box;
162     GtkWidget *scrollw;
163     guint max_cnt;
164     guint curr_cnt;
165     guint scrollw_y_size;
166     GList *childs;
167
168     child_box = g_object_get_data(G_OBJECT(parent_box), SCROLL_BOX_CHILD_BOX);
169     max_cnt = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(parent_box), SCROLL_BOX_MAX_CHILDS));
170
171     /* get the current number of children */
172     childs = gtk_container_get_children(GTK_CONTAINER(child_box));
173     curr_cnt = g_list_length(childs);
174     g_list_free(childs);
175
176     /* have we just reached the max? */
177     if(curr_cnt == max_cnt) {
178         /* create the scrolled window */
179         /* XXX - there's no way to get rid of the shadow frame - except for creating an own widget :-( */
180         scrollw = scrolled_window_new(NULL, NULL);
181         scrollw_y_size = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(parent_box), SCROLL_BOX_SCROLLW_Y_SIZE));
182         gtk_widget_set_size_request(scrollw, -1, scrollw_y_size);
183
184         g_object_set_data(G_OBJECT(parent_box), SCROLL_BOX_SCROLLW, scrollw);
185         gtk_box_pack_start(GTK_BOX(parent_box), scrollw, TRUE, TRUE, 0);
186
187         /* move child_box from parent_box into scrolled window */
188         g_object_ref(child_box);
189         gtk_container_remove(GTK_CONTAINER(parent_box), child_box);
190         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollw),
191                                               child_box);
192         gtk_widget_show_all(scrollw);
193     }
194
195     return child_box;
196 }
197
198
199 static GtkWidget *
200 scroll_box_dynamic_reset(GtkWidget *parent_box)
201 {
202     GtkWidget *child_box, *scrollw;
203
204
205     child_box = g_object_get_data(G_OBJECT(parent_box), SCROLL_BOX_CHILD_BOX);
206     scrollw = g_object_get_data(G_OBJECT(parent_box), SCROLL_BOX_SCROLLW);
207
208     if(scrollw != NULL) {
209         /* move the child_box back from scrolled window into the parent_box */
210         g_object_ref(child_box);
211         gtk_container_remove(GTK_CONTAINER(parent_box), scrollw);
212         g_object_set_data(G_OBJECT(parent_box), SCROLL_BOX_SCROLLW, NULL);
213         gtk_box_pack_start(GTK_BOX(parent_box), child_box, TRUE, TRUE, 0);
214     }
215
216     return child_box;
217 }
218
219
220 /* mouse entered this widget - change background color */
221 static gboolean
222 welcome_item_enter_cb(GtkWidget *eb, GdkEventCrossing *event _U_, gpointer user_data _U_)
223 {
224 #if GTK_CHECK_VERSION(3,0,0)
225     gtk_widget_override_background_color(eb, GTK_STATE_NORMAL, &rgba_topic_item_entered_bg);
226 #else
227     gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &topic_item_entered_bg);
228 #endif
229     return FALSE;
230 }
231
232
233 /* mouse has left this widget - change background color  */
234 static gboolean
235 welcome_item_leave_cb(GtkWidget *eb, GdkEventCrossing *event _U_, gpointer user_data _U_)
236 {
237 #if GTK_CHECK_VERSION(3,0,0)
238     gtk_widget_override_background_color(eb, GTK_STATE_NORMAL, &rgba_topic_item_idle_bg);
239 #else
240     gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &topic_item_idle_bg);
241 #endif
242     return FALSE;
243 }
244
245
246 typedef gboolean (*welcome_button_callback_t)  (GtkWidget      *widget,
247                                                 GdkEventButton *event,
248                                                 gpointer        user_data);
249
250 /* create a "button widget" */
251 static GtkWidget *
252 welcome_button(const gchar *stock_item,
253                const gchar *title, const gchar *subtitle, const gchar *tooltip,
254                welcome_button_callback_t welcome_button_callback, gpointer welcome_button_callback_data)
255 {
256     GtkWidget *eb, *w, *item_hb, *text_vb;
257     gchar *formatted_text;
258
259     item_hb = gtk_hbox_new(FALSE, 1);
260
261     /* event box (for background color and events) */
262     eb = gtk_event_box_new();
263     gtk_container_add(GTK_CONTAINER(eb), item_hb);
264 #if GTK_CHECK_VERSION(3,0,0)
265     gtk_widget_override_background_color(eb, GTK_STATE_NORMAL, &rgba_topic_item_idle_bg);
266 #else
267     gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &topic_item_idle_bg);
268 #endif
269     if(tooltip != NULL) {
270         gtk_widget_set_tooltip_text(eb, tooltip);
271     }
272
273     g_signal_connect(eb, "enter-notify-event", G_CALLBACK(welcome_item_enter_cb), NULL);
274     g_signal_connect(eb, "leave-notify-event", G_CALLBACK(welcome_item_leave_cb), NULL);
275     g_signal_connect(eb, "button-release-event", G_CALLBACK(welcome_button_callback), welcome_button_callback_data);
276
277     /* icon */
278     w = gtk_image_new_from_stock(stock_item, GTK_ICON_SIZE_LARGE_TOOLBAR);
279     gtk_box_pack_start(GTK_BOX(item_hb), w, FALSE, FALSE, 5);
280
281     text_vb = gtk_vbox_new(FALSE, 3);
282
283     /* title */
284     w = gtk_label_new(title);
285     gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.5f);
286     formatted_text = g_strdup_printf("<span weight=\"bold\" size=\"x-large\" foreground=\"black\">%s</span>", title);
287     gtk_label_set_markup(GTK_LABEL(w), formatted_text);
288     g_free(formatted_text);
289     gtk_box_pack_start(GTK_BOX(text_vb), w, FALSE, FALSE, 1);
290
291     /* subtitle */
292     w = gtk_label_new(subtitle);
293     gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.5f);
294     formatted_text = g_strdup_printf("<span size=\"small\" foreground=\"black\">%s</span>", subtitle);
295     gtk_label_set_markup(GTK_LABEL(w), formatted_text);
296     g_free(formatted_text);
297     gtk_box_pack_start(GTK_BOX(text_vb), w, FALSE, FALSE, 1);
298
299     gtk_box_pack_start(GTK_BOX(item_hb), text_vb, TRUE, TRUE, 5);
300
301     return eb;
302 }
303
304
305 /* Hack to handle welcome-button "button-release-event" callback   */
306 /*  1. Dispatch to desired actual callback                         */
307 /*  2. Return TRUE for the event callback.                         */
308 /* user_data: actual (no arg) callback fcn to be invoked.          */
309 static gboolean
310 welcome_button_callback_helper(GtkWidget *w, GdkEventButton *event _U_, gpointer user_data)
311 {
312     void (*funct)(GtkWidget *, gpointer) = user_data;
313     (*funct)(w, NULL);
314     return TRUE;
315 }
316
317
318 void
319 welcome_header_set_message(gchar *msg) {
320     GString *message;
321     time_t secs = time(NULL);
322     struct tm *now = localtime(&secs);
323
324     message = g_string_new("<span weight=\"bold\" size=\"x-large\" foreground=\"white\">");
325
326     if (msg) {
327         g_string_append(message, msg);
328     } else { /* Use our default header */
329         if ((now->tm_mon == 3 && now->tm_mday == 1) || (now->tm_mon == 6 && now->tm_mday == 14)) {
330             g_string_append(message, "Sniffing the glue that holds the Internet together");
331         } else {
332             g_string_append(message, prefs.gui_start_title);
333         }
334
335         if (prefs.gui_version_in_start_page) {
336             g_string_append_printf(message, "</span>\n<span size=\"large\" foreground=\"white\">Version " VERSION "%s",
337                                    wireshark_svnversion);
338         }
339     }
340
341     g_string_append(message, "</span>");
342
343     gtk_label_set_markup(GTK_LABEL(header_lb), message->str);
344     g_string_free(message, TRUE);
345 }
346
347
348 /* create the banner "above our heads" */
349 static GtkWidget *
350 welcome_header_new(void)
351 {
352     GtkWidget *item_vb;
353     GtkWidget *item_hb;
354     GtkWidget *eb;
355     GtkWidget *icon;
356
357     item_vb = gtk_vbox_new(FALSE, 0);
358
359     /* colorize vbox */
360     eb = gtk_event_box_new();
361     gtk_container_add(GTK_CONTAINER(eb), item_vb);
362 #if GTK_CHECK_VERSION(3,0,0)
363     gtk_widget_override_background_color(eb, GTK_STATE_NORMAL, &rgba_header_bar_bg);
364 #else
365     gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &header_bar_bg);
366 #endif
367     item_hb = gtk_hbox_new(FALSE, 0);
368     gtk_box_pack_start(GTK_BOX(item_vb), item_hb, FALSE, FALSE, 10);
369
370     /*icon = xpm_to_widget_from_parent(top_level, wssplash_xpm);*/
371     icon = xpm_to_widget(wssplash_xpm);
372     gtk_box_pack_start(GTK_BOX(item_hb), icon, FALSE, FALSE, 10);
373
374     header_lb = gtk_label_new(NULL);
375     welcome_header_set_message(NULL);
376     gtk_label_set_selectable(GTK_LABEL(header_lb), TRUE);
377     gtk_misc_set_alignment(GTK_MISC(header_lb), 0.0f, 0.5f);
378     gtk_box_pack_start(GTK_BOX(item_hb), header_lb, TRUE, TRUE, 5);
379
380     gtk_widget_show_all(eb);
381
382     return eb;
383 }
384
385
386 void
387 welcome_header_push_msg(const gchar *msg) {
388     gchar *msg_copy = g_strdup(msg);
389
390     status_messages = g_slist_append(status_messages, msg_copy);
391
392     welcome_header_set_message(msg_copy);
393
394     gtk_widget_hide(welcome_hb);
395 }
396
397
398 void
399 welcome_header_pop_msg(void) {
400     gchar *msg = NULL;
401
402     if (status_messages) {
403         g_free(status_messages->data);
404         status_messages = g_slist_delete_link(status_messages, status_messages);
405     }
406
407     if (status_messages) {
408         msg = status_messages->data;
409     }
410
411     welcome_header_set_message(msg);
412
413     if (!status_messages) {
414         gtk_widget_show(welcome_hb);
415     }
416 }
417
418
419 /* create a "topic header widget" */
420 static GtkWidget *
421 welcome_topic_header_new(const char *header)
422 {
423     GtkWidget *w;
424     GtkWidget *eb;
425     gchar *formatted_message;
426
427
428     w = gtk_label_new(header);
429     formatted_message = g_strdup_printf("<span weight=\"bold\" size=\"x-large\" foreground=\"white\">%s</span>", header);
430     gtk_label_set_markup(GTK_LABEL(w), formatted_message);
431     g_free(formatted_message);
432
433     /* colorize vbox */
434     eb = gtk_event_box_new();
435     gtk_container_add(GTK_CONTAINER(eb), w);
436 #if GTK_CHECK_VERSION(3,0,0)
437     gtk_widget_override_background_color(eb, GTK_STATE_NORMAL, &rgba_topic_header_bg);
438 #else
439     gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &topic_header_bg);
440 #endif
441     return eb;
442 }
443
444
445 /* create a "topic widget" */
446 static GtkWidget *
447 welcome_topic_new(const char *header, GtkWidget **to_fill)
448 {
449     GtkWidget *topic_vb;
450     GtkWidget *layout_vb;
451     GtkWidget *topic_eb;
452     GtkWidget *topic_header;
453
454
455     topic_vb = gtk_vbox_new(FALSE, 0);
456
457     topic_header = welcome_topic_header_new(header);
458     gtk_box_pack_start(GTK_BOX(topic_vb), topic_header, FALSE, FALSE, 0);
459
460     layout_vb = gtk_vbox_new(FALSE, 5);
461     gtk_container_set_border_width(GTK_CONTAINER(layout_vb), 10);
462     gtk_box_pack_start(GTK_BOX(topic_vb), layout_vb, FALSE, FALSE, 0);
463
464     /* colorize vbox (we need an event box for this!) */
465     topic_eb = gtk_event_box_new();
466     gtk_container_add(GTK_CONTAINER(topic_eb), topic_vb);
467 #if GTK_CHECK_VERSION(3,0,0)
468     gtk_widget_override_background_color(topic_eb, GTK_STATE_NORMAL, &rgba_topic_content_bg);
469 #else
470     gtk_widget_modify_bg(topic_eb, GTK_STATE_NORMAL, &topic_content_bg);
471 #endif
472     *to_fill = layout_vb;
473
474     return topic_eb;
475 }
476
477
478 /* a file link was pressed */
479 static gboolean
480 welcome_filename_link_press_cb(GtkWidget *widget _U_, GdkEventButton *event _U_, gpointer data)
481 {
482     menu_open_filename(data);
483
484     return FALSE;
485 }
486
487 typedef struct _recent_item_status {
488     gchar     *filename;
489     GtkWidget *label;
490     GObject   *menu_item;
491     GString   *str;
492     gboolean   stat_done;
493     int        err;
494     guint      timer;
495 } recent_item_status;
496
497 /*
498  * Fetch the status of a file.
499  * This function might be called as a thread. We can't use any drawing
500  * routines here: http://developer.gnome.org/gdk/2.24/gdk-Threads.html
501  */
502 static void *get_recent_item_status(void *data)
503 {
504     recent_item_status *ri_stat = (recent_item_status *) data;
505     ws_statb64 stat_buf;
506     int err;
507
508     if (!ri_stat) {
509         return NULL;
510     }
511
512     /*
513      * Add file size. We use binary prefixes instead of IEC because that's what
514      * most OSes use.
515      */
516     err = ws_stat64(ri_stat->filename, &stat_buf);
517     g_mutex_lock(recent_mtx);
518     ri_stat->err = err;
519     if(err == 0) {
520         if (stat_buf.st_size/1024/1024/1024 > 10) {
521             g_string_append_printf(ri_stat->str, " (%" G_GINT64_MODIFIER "d GB)", (gint64) (stat_buf.st_size/1024/1024/1024));
522         } else if (stat_buf.st_size/1024/1024 > 10) {
523             g_string_append_printf(ri_stat->str, " (%" G_GINT64_MODIFIER "d MB)", (gint64) (stat_buf.st_size/1024/1024));
524         } else if (stat_buf.st_size/1024 > 10) {
525             g_string_append_printf(ri_stat->str, " (%" G_GINT64_MODIFIER "d KB)", (gint64) (stat_buf.st_size/1024));
526         } else {
527             g_string_append_printf(ri_stat->str, " (%" G_GINT64_MODIFIER "d Bytes)", (gint64) (stat_buf.st_size));
528         }
529         /* pango format string */
530         g_string_prepend(ri_stat->str, "<span foreground='blue'>");
531         g_string_append(ri_stat->str, "</span>");
532     } else {
533         g_string_append(ri_stat->str, " [not found]");
534     }
535
536     if (!ri_stat->label) { /* The widget went away while we were busy. */
537         g_free(ri_stat->filename);
538         g_string_free(ri_stat->str, TRUE);
539         g_free(ri_stat);
540     } else {
541         ri_stat->stat_done = TRUE;
542     }
543     g_mutex_unlock(recent_mtx);
544
545     return NULL;
546 }
547
548 /* Timeout callback for recent items */
549 static gboolean
550 update_recent_items(gpointer data)
551 {
552     recent_item_status *ri_stat = (recent_item_status *) data;
553     gboolean again = TRUE;
554
555     if (!ri_stat) {
556         return FALSE;
557     }
558
559     g_mutex_lock(recent_mtx);
560     if (ri_stat->stat_done) {
561         again = FALSE;
562         gtk_label_set_markup(GTK_LABEL(ri_stat->label), ri_stat->str->str);
563         if (ri_stat->err == 0) {
564             gtk_widget_set_sensitive(ri_stat->label, TRUE);
565             gtk_action_set_sensitive((GtkAction *) ri_stat->menu_item, TRUE);
566         }
567         ri_stat->timer = 0;
568     }
569     /* Else append some sort of Unicode or ASCII animation to the label? */
570     g_mutex_unlock(recent_mtx);
571     return again;
572 }
573
574 static void welcome_filename_destroy_cb(GtkWidget *w _U_, gpointer data) {
575     recent_item_status *ri_stat = (recent_item_status *) data;
576
577     if (!ri_stat) {
578         return;
579     }
580
581     g_mutex_lock(recent_mtx);
582     if (ri_stat->timer) {
583         g_source_remove(ri_stat->timer);
584         ri_stat->timer = 0;
585     }
586
587     g_object_unref(ri_stat->menu_item);
588
589     if (ri_stat->stat_done) {
590         g_free(ri_stat->filename);
591         g_string_free(ri_stat->str, TRUE);
592         g_free(ri_stat);
593     } else {
594         ri_stat->label = NULL;
595     }
596     g_mutex_unlock(recent_mtx);
597 }
598
599 /* create a "file link widget" */
600 static GtkWidget *
601 welcome_filename_link_new(const gchar *filename, GtkWidget **label, GObject *menu_item)
602 {
603     GtkWidget   *w;
604     GtkWidget   *eb;
605     GString     *str;
606     gchar       *str_escaped;
607     glong        uni_len;
608     gsize        uni_start, uni_end;
609     const glong  max = 60;
610     recent_item_status *ri_stat;
611
612     /* filename */
613     str = g_string_new(filename);
614     uni_len = g_utf8_strlen(str->str, str->len);
615
616     /* cut max filename length */
617     if (uni_len > max) {
618         uni_start = g_utf8_offset_to_pointer(str->str, 20) - str->str;
619         uni_end = g_utf8_offset_to_pointer(str->str, uni_len - max) - str->str;
620         g_string_erase(str, uni_start, uni_end);
621         g_string_insert(str, uni_start, " " UTF8_HORIZONTAL_ELLIPSIS " ");
622     }
623
624     /* escape the possibly shortened filename before adding pango language */
625     str_escaped=g_markup_escape_text(str->str, -1);
626     g_string_free(str, TRUE);
627
628     /* label */
629     w = gtk_label_new(str_escaped);
630     *label = w;
631     gtk_misc_set_padding(GTK_MISC(w), 5, 2);
632     gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.0f);
633     gtk_widget_set_sensitive(w, FALSE);
634
635     ri_stat = g_malloc(sizeof(recent_item_status));
636     ri_stat->filename = g_strdup(filename);
637     ri_stat->label = w;
638     ri_stat->menu_item = menu_item;
639     ri_stat->str = g_string_new(str_escaped);
640     ri_stat->stat_done = FALSE;
641     ri_stat->timer = 0;
642     g_object_ref(G_OBJECT(menu_item));
643     g_signal_connect(w, "destroy", G_CALLBACK(welcome_filename_destroy_cb), ri_stat);
644     g_free(str_escaped);
645
646 #if GLIB_CHECK_VERSION(2,31,0)
647     /* XXX - Add the filename here? */
648     g_thread_new("Recent item status", get_recent_item_status, ri_stat);
649 #else
650     g_thread_create(get_recent_item_status, ri_stat, FALSE, NULL);
651 #endif
652     ri_stat->timer = g_timeout_add(200, update_recent_items, ri_stat);
653
654     /* event box */
655     eb = gtk_event_box_new();
656 #if GTK_CHECK_VERSION(3,0,0)
657     gtk_widget_override_background_color(eb, GTK_STATE_NORMAL, &rgba_topic_item_idle_bg);
658 #else
659     gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &topic_item_idle_bg);
660 #endif
661     gtk_container_add(GTK_CONTAINER(eb), w);
662     gtk_widget_set_tooltip_text(eb, filename);
663
664     g_signal_connect(eb, "enter-notify-event", G_CALLBACK(welcome_item_enter_cb), w);
665     g_signal_connect(eb, "leave-notify-event", G_CALLBACK(welcome_item_leave_cb), w);
666     g_signal_connect(eb, "button-press-event", G_CALLBACK(welcome_filename_link_press_cb), (gchar *) filename);
667
668     return eb;
669 }
670
671
672 /* reset the list of recent files */
673 void
674 main_welcome_reset_recent_capture_files(void)
675 {
676     GtkWidget *child_box;
677     GList* child_list;
678     GList* child_list_item;
679
680
681     if(welcome_file_panel_vb) {
682         child_box = scroll_box_dynamic_reset(welcome_file_panel_vb);
683         child_list = gtk_container_get_children(GTK_CONTAINER(child_box));
684         child_list_item = child_list;
685
686         while(child_list_item) {
687             gtk_container_remove(GTK_CONTAINER(child_box), child_list_item->data);
688             child_list_item = g_list_next(child_list_item);
689         }
690
691         g_list_free(child_list);
692     }
693 }
694
695
696 /* add a new file to the list of recent files */
697 void
698 main_welcome_add_recent_capture_file(const char *widget_cf_name, GObject *menu_item)
699 {
700     GtkWidget *w;
701     GtkWidget *child_box;
702     GtkWidget *label;
703
704
705     w = welcome_filename_link_new(widget_cf_name, &label, menu_item);
706     child_box = scroll_box_dynamic_add(welcome_file_panel_vb);
707     gtk_box_pack_start(GTK_BOX(child_box), w, FALSE, FALSE, 0);
708     gtk_widget_show_all(w);
709     gtk_widget_show_all(child_box);
710 }
711
712 #ifdef HAVE_LIBPCAP
713 static gboolean select_current_ifaces(GtkTreeModel  *model,
714                                   GtkTreePath   *path,
715                                   GtkTreeIter   *iter,
716                                   gpointer       userdata)
717 {
718     guint i;
719     gchar *if_name;
720     interface_t device;
721
722     GtkTreeSelection *selection = (GtkTreeSelection *)userdata;
723     device.name = NULL;
724     gtk_tree_model_get (model, iter, IFACE_NAME, &if_name, -1);
725     for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
726         device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
727         if (strcmp(device.name, if_name) == 0) {
728             if (device.selected && !gtk_tree_selection_path_is_selected(selection, path)) {
729                 gtk_tree_selection_select_iter(selection, iter);
730             } else {
731                 gtk_tree_selection_unselect_iter(selection, iter);
732             }
733             break;
734         }
735     }
736     return FALSE;
737 }
738
739 gboolean on_selection_changed(GtkTreeSelection *selection _U_,
740                               GtkTreeModel *model,
741                               GtkTreePath *path,
742                               gboolean path_currently_selected,
743                               gpointer data _U_)
744 {
745     GtkTreeIter  iter;
746     gchar *if_name;
747     guint i;
748     interface_t device;
749
750     gtk_tree_model_get_iter (model, &iter, path);
751     gtk_tree_model_get (model, &iter, IFACE_NAME, &if_name, -1);
752     for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
753         device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
754         if (strcmp(device.name, if_name) == 0) {
755             if (!device.locked) {
756                 if (path_currently_selected) {
757                     if (device.selected) {
758                         device.selected = FALSE;
759                         device.locked = TRUE;
760                         global_capture_opts.num_selected--;
761                     }
762                 } else {
763                     if (!device.selected) {
764                         device.selected = TRUE;
765                         device.locked = TRUE;
766                         global_capture_opts.num_selected++;
767                     }
768                 }
769                 global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
770                 g_array_insert_val(global_capture_opts.all_ifaces, i, device);
771
772                 if (dlg_window_present()) {
773                     enable_selected_interface(g_strdup(if_name), device.selected);
774                 }
775                 if (interfaces_dialog_window_present()) {
776                     update_selected_interface(g_strdup(if_name));
777                 }
778                 device.locked = FALSE;
779                 global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
780                 g_array_insert_val(global_capture_opts.all_ifaces, i, device);
781             }
782             break;
783         }
784     }
785     return TRUE;
786 }
787
788 static gboolean activate_ifaces(GtkTreeModel  *model,
789                                 GtkTreePath   *path _U_,
790                                 GtkTreeIter   *iter,
791                                 gpointer       userdata)
792 {
793     gchar *if_name;
794     GtkWidget *view;
795     GtkTreeSelection *selection;
796     selected_name_t  *entry = (selected_name_t *)userdata;
797
798     view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
799     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
800     gtk_tree_model_get (model, iter, IFACE_NAME, &if_name, -1);
801     if (strcmp(if_name, entry->name) == 0) {
802         if (entry->activate) {
803             gtk_tree_selection_select_iter(selection, iter);
804         } else {
805             gtk_tree_selection_unselect_iter(selection, iter);
806         }
807         return TRUE;
808     }
809     return FALSE;
810 }
811
812 void change_interface_selection(gchar* name, gboolean activate)
813 {
814     GtkWidget        *view;
815     GtkTreeModel     *model;
816     selected_name_t  entry;
817
818     view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
819     model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
820     entry.name = g_strdup(name);
821     entry.activate = activate;
822     gtk_tree_model_foreach(GTK_TREE_MODEL(model), (GtkTreeModelForeachFunc)(activate_ifaces), (gpointer) &entry);
823 }
824
825 void change_selection_for_all(gboolean enable)
826 {
827     guint i;
828
829     for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
830         change_interface_selection(g_array_index(global_capture_opts.all_ifaces, interface_t, i).name, enable);
831     }
832 }
833 #endif
834
835 void
836 select_ifaces(void)
837 {
838 #ifdef HAVE_LIBPCAP
839     GtkWidget        *view;
840     GtkTreeModel     *model;
841     GtkTreeSelection *entry;
842
843     if (global_capture_opts.num_selected > 0 && swindow) {
844         view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
845         model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
846         entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
847         gtk_tree_model_foreach(GTK_TREE_MODEL(model), select_current_ifaces, (gpointer) entry);
848         gtk_widget_grab_focus(view);
849     }
850 #endif
851 }
852
853 #ifdef HAVE_LIBPCAP
854 void
855 change_interface_name(gchar *oldname, guint index)
856 {
857     GtkWidget        *view;
858     GtkTreeModel     *model;
859     GtkTreeIter      iter;
860     interface_t      device;
861     GtkTreeSelection *entry;
862     gchar            *optname;
863
864     view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
865     entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
866     model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
867
868     device = g_array_index(global_capture_opts.all_ifaces, interface_t, index);
869     if (gtk_tree_model_get_iter_first (model, &iter)) {
870         do {
871             gtk_tree_model_get(model, &iter, IFACE_NAME, &optname, -1);
872             if (strcmp(optname, oldname) == 0) {
873                 gtk_list_store_set(GTK_LIST_STORE(model), &iter, ICON, gtk_image_get_pixbuf(GTK_IMAGE(capture_get_if_icon(&device))), IFACE_DESCR, device.display_name, IFACE_NAME, device.name, -1);
874                 if (device.selected) {
875                     gtk_tree_selection_select_iter(entry, &iter);
876                 }
877                 break;
878             }
879         } while (gtk_tree_model_iter_next(model, &iter));
880         g_free(optname);
881     }
882 }
883 #endif
884
885 #ifdef HAVE_PCAP_REMOTE
886 void
887 add_interface_to_list(guint index)
888 {
889     GtkWidget *view, *icon;
890     GtkTreeModel *model;
891     GtkTreeIter iter;
892     gint size;
893     gchar *lines;
894     interface_t device;
895
896     device = g_array_index(global_capture_opts.all_ifaces, interface_t, index);
897     icon = pixbuf_to_widget(remote_sat_pb_data);
898     view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
899     model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
900     size = gtk_tree_model_iter_n_children(model, NULL);
901     lines = g_strdup_printf("%d", size-1);
902     if (gtk_tree_model_get_iter_from_string(model, &iter, lines)) {
903         gtk_list_store_append (GTK_LIST_STORE(model), &iter);
904         gtk_list_store_set(GTK_LIST_STORE(model), &iter, ICON, gtk_image_get_pixbuf(GTK_IMAGE(icon)), IFACE_DESCR, device.display_name, IFACE_NAME, device.name, -1);
905     }
906 }
907 #endif
908
909 #ifdef HAVE_LIBPCAP
910 static void
911 clear_capture_box(void)
912 {
913     GtkWidget         *item_hb;
914     
915     item_hb = g_object_get_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_INTERFACE_LIST);
916     if (item_hb) {
917         gtk_widget_destroy(item_hb);
918     }
919     item_hb = g_object_get_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_START);
920     if (item_hb) {
921         gtk_widget_destroy(item_hb);
922     }
923     item_hb = g_object_get_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_CAPTURE);
924     if (item_hb) {
925         gtk_widget_destroy(item_hb);
926     }
927     if (swindow) {
928         gtk_widget_destroy(swindow);
929         swindow = NULL;
930         if_view = NULL;
931     }
932 }
933
934 static void fill_capture_box(void)
935 {
936     GtkWidget         *box_to_fill;
937     GtkWidget         *item_hb_interface_list, *item_hb_capture, *item_hb_start, *label, *w;
938 #ifdef _WIN32
939     GtkWidget         *item_hb;
940 #endif
941     GtkTreeSelection  *selection;
942     GtkCellRenderer   *renderer;
943     GtkTreeViewColumn *column;
944     int               error = 0;
945     gchar             *label_text;
946 #ifdef _WIN32
947     DWORD reg_ret;
948     DWORD chimney_enabled = 0;
949     DWORD ce_size = sizeof(chimney_enabled);
950 #endif
951   
952     label = g_object_get_data(G_OBJECT(welcome_hb), CAPTURE_LABEL);
953     if (label) {
954         gtk_widget_destroy(label);
955     }
956     box_to_fill = g_object_get_data(G_OBJECT(welcome_hb), CAPTURE_VIEW);
957     if (global_capture_opts.all_ifaces->len > 0) {
958         item_hb_interface_list = welcome_button(WIRESHARK_STOCK_CAPTURE_INTERFACES,
959                                                 "Interface List",
960                                                 "Live list of the capture interfaces\n(counts incoming packets)",
961                                                 "Same as Capture/Interfaces menu or toolbar item",
962                                                 welcome_button_callback_helper, capture_if_cb);
963         gtk_box_pack_start(GTK_BOX(box_to_fill), item_hb_interface_list, FALSE, FALSE, 5);
964         swindow = gtk_scrolled_window_new (NULL, NULL);
965         gtk_widget_set_size_request(swindow, FALSE, 100);
966         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swindow), GTK_SHADOW_IN);
967         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
968         g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_INTERFACE_LIST, item_hb_interface_list);
969
970         if_view = gtk_tree_view_new ();
971         g_object_set(G_OBJECT(if_view), "headers-visible", FALSE, NULL);
972         g_signal_connect(if_view, "row-activated", G_CALLBACK(options_interface_cb), (gpointer)welcome_hb);
973         g_object_set_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES, if_view);
974         column = gtk_tree_view_column_new();
975         renderer = gtk_cell_renderer_pixbuf_new();
976         gtk_tree_view_column_pack_start(column, renderer, FALSE);
977         gtk_tree_view_column_set_attributes(column, renderer, "pixbuf", ICON, NULL);
978         renderer = gtk_cell_renderer_text_new();
979         gtk_tree_view_column_pack_start(column, renderer, TRUE);
980         gtk_tree_view_column_set_attributes(column, renderer, "text", IFACE_DESCR, NULL);
981         gtk_tree_view_append_column(GTK_TREE_VIEW(if_view), column);
982         gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(if_view), 0), TRUE);
983         renderer = gtk_cell_renderer_text_new();
984         column = gtk_tree_view_column_new_with_attributes ("",
985                                                            GTK_CELL_RENDERER(renderer),
986                                                            "text", IFACE_NAME,
987                                                            NULL);
988         gtk_tree_view_append_column(GTK_TREE_VIEW(if_view), column);
989         gtk_tree_view_column_set_visible(column, FALSE);
990         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(if_view));
991         gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
992         item_hb_start = welcome_button(WIRESHARK_STOCK_CAPTURE_START,
993                                        "Start",
994                                        "Choose one or more interfaces to capture from, then <b>Start</b>",
995                                        "Same as Capture/Interfaces with default options",
996                                        (welcome_button_callback_t)capture_if_start, (gpointer)if_view);
997         gtk_box_pack_start(GTK_BOX(box_to_fill), item_hb_start, FALSE, FALSE, 5);
998         welcome_if_tree_load();
999         gtk_container_add (GTK_CONTAINER (swindow), if_view);
1000         gtk_container_add(GTK_CONTAINER(box_to_fill), swindow);
1001         g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_START, item_hb_start);
1002
1003         item_hb_capture = welcome_button(WIRESHARK_STOCK_CAPTURE_OPTIONS,
1004                                          "Capture Options",
1005                                          "Start a capture with detailed options",
1006                                          "Same as Capture/Options menu or toolbar item",
1007                                          welcome_button_callback_helper, capture_prep_cb);
1008         gtk_box_pack_start(GTK_BOX(box_to_fill), item_hb_capture, FALSE, FALSE, 5);
1009         g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_CAPTURE, item_hb_capture);
1010 #ifdef _WIN32
1011         /* Check for chimney offloading */
1012         reg_ret = RegQueryValueEx(HKEY_LOCAL_MACHINE,
1013                                   _T("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\EnableTCPChimney"),
1014                                   NULL, NULL, (LPBYTE) &chimney_enabled, &ce_size);
1015         if (reg_ret == ERROR_SUCCESS && chimney_enabled) {
1016             item_hb = welcome_button(WIRESHARK_STOCK_WIKI,
1017                                      "Offloading Detected",
1018                                      "TCP Chimney offloading is enabled. You \nmight not capture much data.",
1019                                      topic_online_url(ONLINEPAGE_CHIMNEY),
1020                                      topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_CHIMNEY));
1021             gtk_box_pack_start(GTK_BOX(box_to_fill), item_hb_capture, FALSE, FALSE, 5);
1022         }
1023 #endif /* _WIN32 */
1024     } else {
1025        if (if_view) {
1026            clear_capture_box();
1027        }
1028        if (error != NO_INTERFACES_FOUND) {
1029             if (error == CANT_GET_INTERFACE_LIST) {
1030                 label_text = g_strdup("No interface can be used for capturing in "
1031                                       "this system with the current configuration.\n"
1032                                       "\n"
1033                                       "See Capture Help below for details.");
1034             } else {
1035                 label_text = g_strdup("WinPcap doesn't appear to be installed.  "
1036                                       "In order to capture packets, WinPcap "
1037                                       "must be installed; see\n"
1038                                       "\n"
1039 #if GTK_CHECK_VERSION(2,18,0)
1040                                       "        <a href=\"http://www.winpcap.org/\">http://www.winpcap.org/</a>\n"
1041 #else
1042                                       "        http://www.winpcap.org/\n"
1043 #endif
1044                                       "\n"
1045                                       "or the mirror at\n"
1046                                       "\n"
1047 #if GTK_CHECK_VERSION(2,18,0)
1048                                       "        <a href=\"http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\">http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/</a>\n"
1049 #else
1050                                       "        http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\n"
1051 #endif
1052                                       "\n"
1053                                       "or the mirror at\n"
1054                                       "\n"
1055 #if GTK_CHECK_VERSION(2,18,0)
1056                                       "        <a href=\"http://winpcap.cs.pu.edu.tw/\">http://winpcap.cs.pu.edu.tw/</a>\n"
1057 #else
1058                                       "        http://winpcap.cs.pu.edu.tw/\n"
1059 #endif
1060                                       "\n"
1061                                       "for a downloadable version of WinPcap "
1062                                       "and for instructions on how to install "
1063                                       "WinPcap.");
1064             }
1065         } else {
1066             label_text = g_strdup("No interface can be used for capturing in "
1067                                   "this system with the current configuration.\n"
1068                                   "\n"
1069                                   "See Capture Help below for details.");
1070         }
1071         w = gtk_label_new(label_text);
1072         gtk_label_set_markup(GTK_LABEL(w), label_text);
1073         gtk_label_set_line_wrap(GTK_LABEL(w), TRUE);
1074         g_free (label_text);
1075         gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.0f);
1076         gtk_box_pack_start(GTK_BOX(box_to_fill), w, FALSE, FALSE, 5);
1077 #if GTK_CHECK_VERSION(2,18,0)
1078         g_signal_connect(w, "activate-link", G_CALLBACK(activate_link_cb), NULL);
1079 #endif
1080         g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_LABEL, w);
1081     }
1082 }
1083 #endif
1084
1085 /* list the interfaces */
1086 static void
1087 welcome_if_tree_load(void)
1088 {
1089 #ifdef HAVE_LIBPCAP
1090     guint               i;
1091     GtkListStore        *store = NULL;
1092     GtkTreeIter         iter;
1093     GtkTreeSelection    *entry;
1094     interface_t         device;
1095     gboolean            changed = FALSE;
1096     int                 error;
1097
1098     if (if_view && swindow) {
1099         entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(if_view));
1100         gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(entry));
1101         store = gtk_list_store_new(NUMCOLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
1102
1103         gtk_list_store_clear(store);
1104         gtk_tree_view_set_model(GTK_TREE_VIEW(if_view), GTK_TREE_MODEL (store));
1105         /* LOAD THE INTERFACES */
1106         if (global_capture_opts.all_ifaces->len == 0) {
1107             scan_local_interfaces(&global_capture_opts, &error);
1108             if (global_capture_opts.all_ifaces->len == 0) {
1109                 fill_capture_box();
1110             }
1111         } else {
1112             for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
1113                 device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
1114                 if (!device.hidden) {
1115                     gtk_list_store_append (store, &iter);
1116                     gtk_list_store_set (store, &iter, ICON, gtk_image_get_pixbuf(GTK_IMAGE(capture_get_if_icon(&device))), IFACE_DESCR, device.display_name, IFACE_NAME, device.name, -1);
1117                     if (device.selected) {
1118                         gtk_tree_selection_select_iter(entry, &iter);
1119                     }
1120                 }
1121             }
1122             changed = TRUE;
1123             gtk_tree_selection_set_select_function(GTK_TREE_SELECTION(entry), on_selection_changed, (gpointer)&changed, NULL);
1124             if (gtk_widget_is_focus(GTK_WIDGET(if_view)) && dlg_window_present()) {
1125                 update_all_rows();
1126             }
1127         }
1128     } else {
1129         fill_capture_box();    
1130     }
1131 #endif  /* HAVE_LIBPCAP */
1132 }
1133
1134
1135 /* reload the list of interfaces */
1136 void
1137 welcome_if_panel_reload(void)
1138 {
1139 #ifdef HAVE_LIBPCAP
1140     if (welcome_hb) {
1141         welcome_if_tree_load();
1142         gtk_widget_show_all(welcome_hb);
1143     }
1144 #endif  /* HAVE_LIBPCAP */
1145 }
1146
1147 #ifdef HAVE_LIBPCAP
1148 static void capture_if_start(GtkWidget *w _U_, gpointer data _U_)
1149 {
1150 #ifdef HAVE_AIRPCAP
1151     interface_t device;
1152     guint i;
1153 #endif
1154     if (global_capture_opts.num_selected == 0) {
1155         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1156             "You didn't specify an interface on which to capture packets.");
1157         return;
1158     }
1159
1160     /* XXX - remove this? */
1161     if (global_capture_opts.save_file) {
1162         g_free(global_capture_opts.save_file);
1163         global_capture_opts.save_file = NULL;
1164     }
1165 #ifdef HAVE_AIRPCAP  /* TODO: don't let it depend on interface_opts */
1166     for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
1167         device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
1168         airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, device.name);
1169         airpcap_if_selected = airpcap_if_active;
1170         if (airpcap_if_selected) {
1171             break;
1172         }
1173     }
1174     airpcap_set_toolbar_start_capture(airpcap_if_active);
1175 #endif
1176     capture_start_cb(NULL, NULL);
1177 }
1178 #endif
1179
1180 #ifdef HAVE_LIBPCAP
1181 #if GTK_CHECK_VERSION(2,18,0)
1182 static gboolean
1183 activate_link_cb(GtkLabel *label _U_, gchar *uri, gpointer user_data _U_)
1184 {
1185     return browser_open_url(uri);
1186 }
1187 #endif
1188 #endif
1189
1190 /* create the welcome page */
1191 GtkWidget *
1192 welcome_new(void)
1193 {
1194     GtkWidget *welcome_scrollw;
1195     GtkWidget *welcome_eb;
1196     GtkWidget *welcome_vb;
1197     GtkWidget *column_vb;
1198     GtkWidget *item_hb;
1199     GtkWidget *w;
1200     GtkWidget *header;
1201     GtkWidget *topic_vb;
1202     GtkWidget *topic_to_fill;
1203     GtkWidget *topic_capture_to_fill;
1204     gchar     *label_text;
1205     GtkWidget *file_child_box;
1206 #ifdef HAVE_LIBPCAP
1207     int       error;
1208 #endif
1209 #ifdef _WIN32
1210     DWORD chimney_enabled = 0;
1211     DWORD ce_size = sizeof(chimney_enabled);
1212 #endif
1213     /* prepare colors */
1214 #if 0
1215     /* Allocating color isn't necessary? */
1216
1217     /* "page" background */
1218     get_color(&welcome_bg);
1219
1220     /* header bar background color */
1221     get_color(&header_bar_bg);
1222
1223     /* topic header background color */
1224     get_color(&topic_header_bg);
1225
1226     /* topic content background color */
1227     get_color(&topic_content_bg);
1228 #endif
1229 #if GTK_CHECK_VERSION(3,0,0)
1230     rgba_topic_item_idle_bg = rgba_topic_content_bg;
1231 #else
1232     topic_item_idle_bg = topic_content_bg;
1233 #endif
1234 #if 0
1235     /* Allocating collor isn't necessary? */
1236     /* topic item entered color */
1237     get_color(&topic_item_entered_bg);
1238 #endif
1239     welcome_scrollw = scrolled_window_new(NULL, NULL);
1240
1241     welcome_vb = gtk_vbox_new(FALSE, 0);
1242
1243     welcome_eb = gtk_event_box_new();
1244     gtk_container_add(GTK_CONTAINER(welcome_eb), welcome_vb);
1245 #if GTK_CHECK_VERSION(3,0,0)
1246     gtk_widget_override_background_color(welcome_eb, GTK_STATE_NORMAL, &rgba_welcome_bg);
1247 #else
1248     gtk_widget_modify_bg(welcome_eb, GTK_STATE_NORMAL, &welcome_bg);
1249 #endif
1250     /* header */
1251     header = welcome_header_new();
1252     gtk_box_pack_start(GTK_BOX(welcome_vb), header, FALSE, FALSE, 0);
1253
1254     /* content */
1255     welcome_hb = gtk_hbox_new(FALSE, 10);
1256     gtk_container_set_border_width(GTK_CONTAINER(welcome_hb), 10);
1257     gtk_box_pack_start(GTK_BOX(welcome_vb), welcome_hb, TRUE, TRUE, 0);
1258
1259
1260     /* column capture */
1261     column_vb = gtk_vbox_new(FALSE, 10);
1262 #if GTK_CHECK_VERSION(3,0,0)
1263     gtk_widget_override_background_color(column_vb, GTK_STATE_NORMAL, &rgba_welcome_bg);
1264 #else
1265     gtk_widget_modify_bg(column_vb, GTK_STATE_NORMAL, &welcome_bg);
1266 #endif
1267     gtk_box_pack_start(GTK_BOX(welcome_hb), column_vb, TRUE, TRUE, 0);
1268
1269     /* capture topic */
1270     topic_vb = welcome_topic_new("Capture", &topic_capture_to_fill);
1271     gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);
1272     g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_VIEW, topic_capture_to_fill);
1273
1274 #ifdef HAVE_LIBPCAP
1275     if (global_capture_opts.all_ifaces->len == 0) {
1276         scan_local_interfaces(&global_capture_opts, &error);
1277     }
1278
1279     fill_capture_box();
1280
1281     /* capture help topic */
1282     topic_vb = welcome_topic_new("Capture Help", &topic_to_fill);
1283     gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);
1284
1285     item_hb = welcome_button(WIRESHARK_STOCK_WIKI,
1286         "How to Capture",
1287         "Step by step to a successful capture setup",
1288         topic_online_url(ONLINEPAGE_CAPTURE_SETUP),
1289         topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_CAPTURE_SETUP));
1290     gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
1291
1292     item_hb = welcome_button(WIRESHARK_STOCK_WIKI,
1293         "Network Media",
1294         "Specific information for capturing on:\nEthernet, WLAN, ...",
1295         topic_online_url(ONLINEPAGE_NETWORK_MEDIA),
1296         topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_NETWORK_MEDIA));
1297     gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
1298 #else
1299     label_text =  g_strdup("<span foreground=\"black\">Capturing is not compiled into\nthis version of Wireshark!</span>");
1300     w = gtk_label_new(label_text);
1301     gtk_label_set_markup(GTK_LABEL(w), label_text);
1302     g_free (label_text);
1303     gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.0f);
1304     gtk_box_pack_start(GTK_BOX(topic_capture_to_fill), w, FALSE, FALSE, 5);
1305 #endif  /* HAVE_LIBPCAP */
1306
1307     /* fill bottom space */
1308     w = gtk_label_new("");
1309     gtk_box_pack_start(GTK_BOX(topic_capture_to_fill), w, TRUE, TRUE, 0);
1310
1311
1312     /* column files */
1313     topic_vb = welcome_topic_new("Files", &topic_to_fill);
1314     gtk_box_pack_start(GTK_BOX(welcome_hb), topic_vb, TRUE, TRUE, 0);
1315
1316     item_hb = welcome_button(GTK_STOCK_OPEN,
1317         "Open",
1318         "Open a previously captured file",
1319         "Same as File/Open menu or toolbar item",
1320         welcome_button_callback_helper, file_open_cmd_cb);
1321     gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
1322
1323     /* prepare list of recent files (will be filled in later) */
1324     label_text =  g_strdup("<span foreground=\"black\">Open Recent:</span>");
1325     w = gtk_label_new(label_text);
1326     gtk_label_set_markup(GTK_LABEL(w), label_text);
1327     g_free (label_text);
1328     gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.0f);
1329     gtk_box_pack_start(GTK_BOX(topic_to_fill), w, FALSE, FALSE, 5);
1330
1331     file_child_box = gtk_vbox_new(FALSE, 1);
1332     /* 17 file items or 300 pixels height is about the size */
1333     /* that still fits on a screen of about 1000*700 */
1334     welcome_file_panel_vb = scroll_box_dynamic_new(GTK_WIDGET(file_child_box), 17, 300);
1335     gtk_box_pack_start(GTK_BOX(topic_to_fill), welcome_file_panel_vb, FALSE, FALSE, 0);
1336
1337     item_hb = welcome_button(WIRESHARK_STOCK_WIKI,
1338         "Sample Captures",
1339         "A rich assortment of example capture files on the wiki",
1340         topic_online_url(ONLINEPAGE_SAMPLE_CAPTURES),
1341         topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_SAMPLE_CAPTURES));
1342     gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
1343
1344     /* fill bottom space */
1345     w = gtk_label_new("");
1346     gtk_box_pack_start(GTK_BOX(topic_to_fill), w, TRUE, TRUE, 0);
1347
1348
1349     /* column online */
1350     column_vb = gtk_vbox_new(FALSE, 10);
1351     gtk_box_pack_start(GTK_BOX(welcome_hb), column_vb, TRUE, TRUE, 0);
1352
1353     /* topic online */
1354     topic_vb = welcome_topic_new("Online", &topic_to_fill);
1355     gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);
1356
1357     item_hb = welcome_button(GTK_STOCK_HOME,
1358         "Website",
1359         "Visit the project's website",
1360         topic_online_url(ONLINEPAGE_HOME),
1361         topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_HOME));
1362     gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
1363
1364 #ifdef HHC_DIR
1365     item_hb = welcome_button(GTK_STOCK_HELP,
1366         "User's Guide",
1367         "The User's Guide "
1368         "(local version, if installed)",
1369         "Locally installed (if installed) otherwise online version",
1370         topic_menu_cb, GINT_TO_POINTER(HELP_CONTENT));
1371 #else
1372     item_hb = welcome_button(GTK_STOCK_HELP,
1373         "User's Guide",
1374         "The User's Guide "
1375         "(online version)",
1376         topic_online_url(ONLINEPAGE_USERGUIDE),
1377         topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_USERGUIDE));
1378 #endif
1379     gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
1380
1381     item_hb = welcome_button(WIRESHARK_STOCK_WIKI,
1382         "Security",
1383         "Work with Wireshark as securely as possible",
1384         topic_online_url(ONLINEPAGE_SECURITY),
1385         topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_SECURITY));
1386     gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
1387
1388 #if 0
1389     /* XXX - add this, once the Windows update functionality is implemented */
1390     /* topic updates */
1391     topic_vb = welcome_topic_new("Updates", &topic_to_fill);
1392     gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);
1393
1394     label_text =  g_strdup("<span foreground=\"black\">No updates available!</span>");
1395     w = gtk_label_new(label_text);
1396     gtk_label_set_markup(GTK_LABEL(w), label_text);
1397     g_free (label_text);
1398     gtk_box_pack_start(GTK_BOX(topic_to_fill), w, TRUE, TRUE, 0);
1399 #endif
1400
1401
1402     /* the end */
1403     gtk_widget_show_all(welcome_eb);
1404
1405     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(welcome_scrollw),
1406                                           welcome_eb);
1407     gtk_widget_show_all(welcome_scrollw);
1408
1409 #if GLIB_CHECK_VERSION(2,31,0)
1410     recent_mtx = g_malloc(sizeof(GMutex));
1411     g_mutex_init(recent_mtx);
1412 #else
1413     recent_mtx = g_mutex_new();
1414 #endif
1415
1416     return welcome_scrollw;
1417 }
1418
1419 GtkWidget* get_welcome_window(void)
1420 {
1421     return welcome_hb;
1422 }
1423
1424