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