65212ee578f4b60dc8dac3a84e9565ae355729ea
[obnox/wireshark/wip.git] / gtk / about_dlg.c
1 /* about_dlg.c
2  *
3  * $Id$
4  *
5  * Ulf Lamping <ulf.lamping@web.de>
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 2000 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <gtk/gtk.h>
31 #include <string.h>
32
33 #include <epan/filesystem.h>
34 #include <epan/plugins.h>
35 #ifdef HAVE_LIBSMI
36 #include <epan/oids.h>
37 #endif
38 #ifdef HAVE_GEOIP
39 #include <epan/geoip_db.h>
40 #endif
41
42 #include "../globals.h"
43 #include "../log.h"
44 #include "../version_info.h"
45
46 #include "gtk/about_dlg.h"
47 #include "gtk/gui_utils.h"
48 #include "gtk/dlg_utils.h"
49 #include "gtk/file_dlg.h"
50 #include "gtk/text_page_utils.h"
51 #include "gtk/gtkglobals.h"
52 #include "gtk/main.h"
53 #include "gtk/plugins_dlg.h"
54
55 #include "../image/wssplash-dev.xpm"
56 #include "webbrowser.h"
57
58 static void about_wireshark_destroy_cb(GtkWidget *, gpointer);
59
60
61 /*
62  * Keep a static pointer to the current "About Wireshark" window, if any, so
63  * that if somebody tries to do "About Wireshark" while there's already an
64  * "About Wireshark" window up, we just pop up the existing one, rather than
65  * creating a new one.
66  */
67 static GtkWidget *about_wireshark_w;
68
69
70 static void
71 about_wireshark(GtkWidget *parent, GtkWidget *main_vb)
72 {
73   GtkWidget   *msg_label, *icon;
74   gchar       *message;
75   const char  *title = "Network Protocol Analyzer";
76
77   icon = xpm_to_widget_from_parent(parent, wssplash_xpm);
78   gtk_container_add(GTK_CONTAINER(main_vb), icon);
79
80   msg_label = gtk_label_new(title);
81   message = g_strdup_printf("<span size=\"x-large\" weight=\"bold\">%s</span>", title);
82   gtk_label_set_markup(GTK_LABEL(msg_label), message);
83   g_free(message);
84   gtk_container_add(GTK_CONTAINER(main_vb), msg_label);
85 }
86
87 static void
88 splash_update_label(GtkWidget *win, const char *message)
89 {
90     GtkWidget *main_lb;
91
92     if (win == NULL) return;
93
94     main_lb = g_object_get_data(G_OBJECT(win), "splash_label");
95     gtk_label_set_text(GTK_LABEL(main_lb), message);
96
97     /* Process all pending GUI events before continuing, so that
98        the splash screen window gets updated. */
99     while (gtk_events_pending()) gtk_main_iteration();
100 }
101
102 GtkWidget*
103 splash_new(const char *message)
104 {
105     GtkWidget *win;
106     GtkWidget *main_lb;
107
108     GtkWidget *main_vb;
109     GtkWidget *percentage_hb;
110     GtkWidget *prog_bar;
111     GtkWidget *percentage_lb;
112
113     win = splash_window_new();
114
115     /* When calling about_wireshark(), we must realize the top-level
116        widget for the window, otherwise GTK will throw a warning
117        because we don't have a colormap associated with that window and
118        can't handle the pixmap. */
119     gtk_widget_realize(win);
120
121     main_vb = gtk_vbox_new(FALSE, 6);
122     gtk_container_set_border_width(GTK_CONTAINER(main_vb), 24);
123     gtk_container_add(GTK_CONTAINER(win), main_vb);
124
125     about_wireshark(win, main_vb);
126
127     main_lb = gtk_label_new(message);
128     gtk_container_add(GTK_CONTAINER(main_vb), main_lb);
129     g_object_set_data(G_OBJECT(win), "splash_label", main_lb);
130
131     main_lb = gtk_label_new("");
132     gtk_container_add(GTK_CONTAINER(main_vb), main_lb);
133     g_object_set_data(G_OBJECT(win), "protocol_label", main_lb);
134
135     percentage_hb = gtk_hbox_new(FALSE, 1);
136     gtk_box_pack_start(GTK_BOX(main_vb), percentage_hb, TRUE, TRUE, 3);
137
138     prog_bar = gtk_progress_bar_new();
139     gtk_box_pack_start(GTK_BOX(percentage_hb), prog_bar, TRUE, TRUE, 3);
140     g_object_set_data(G_OBJECT(win), "progress_bar", prog_bar);
141
142     percentage_lb = gtk_label_new("  0%");
143     gtk_misc_set_alignment(GTK_MISC(percentage_lb), 0.0, 0.0);
144     gtk_box_pack_start(GTK_BOX(percentage_hb), percentage_lb, FALSE, TRUE, 3);
145     g_object_set_data(G_OBJECT(win), "percentage_label", percentage_lb);
146
147     gtk_widget_show_all(win);
148
149     splash_update_label(win, message);
150
151     return win;
152 }
153
154 #define REGISTER_FREQ 100 /* Milliseconds */
155
156 void
157 splash_update(register_action_e action, const char *message, gpointer client_data)
158 {
159     GtkWidget  *win;
160     GtkWidget  *main_lb;
161     GtkWidget  *prog_bar;
162     GtkWidget  *percentage_lb;
163     gfloat     percentage;
164     gulong     ul_percentage;
165     gchar      tmp[100];
166     const char *action_msg;
167
168     static gulong ul_sofar = 0;
169     static gulong ul_count = 0;
170
171     static register_action_e last_action = RA_NONE;
172
173     static GTimeVal cur_tv;
174     static GTimeVal next_tv = {0, 0};
175
176     win = (GtkWidget *)client_data;
177
178     if (win == NULL) return;
179
180     g_get_current_time(&cur_tv);
181     if (cur_tv.tv_sec <= next_tv.tv_sec && cur_tv.tv_usec <= next_tv.tv_usec && ul_sofar < ul_count - 1) {
182       /* Only update every REGISTER_FREQ milliseconds */
183       ul_sofar++;
184       return;
185     }
186     memcpy(&next_tv, &cur_tv, sizeof(next_tv));
187     next_tv.tv_usec += REGISTER_FREQ * 1000;
188     if (next_tv.tv_usec >= 1000000) {
189         next_tv.tv_sec++;
190         next_tv.tv_usec -= 1000000;
191     }
192
193     if(last_action != action) {
194       /* the action has changed */
195       switch(action) {
196       case RA_DISSECTORS:
197         action_msg = "Initializing dissectors ...";
198         break;
199       case RA_LISTENERS:
200         action_msg = "Initializing tap listeners ...";
201         break;
202       case RA_REGISTER:
203         action_msg = "Registering dissector ...";
204         break;
205       case RA_PLUGIN_REGISTER:
206         action_msg = "Registering plugins ...";
207         break;
208       case RA_HANDOFF:
209         action_msg = "Handing off dissector ...";
210         break;
211       case RA_PLUGIN_HANDOFF:
212         action_msg = "Handing off plugins ...";
213         break;
214       case RA_PREFERENCES:
215         action_msg = "Loading module preferences ...";
216         break;
217       case RA_CONFIGURATION:
218         action_msg = "Loading configuration files ...";
219         break;
220       default:
221         action_msg = "(Unknown action)";;
222         break;
223       }
224       splash_update_label(win, action_msg);
225       last_action = action;
226     }
227
228     if(ul_count == 0) /* get the count of dissectors */
229       ul_count = register_count() + 6; /* additional 6 for:
230                                           dissectors, listeners,
231                                           registering plugins, handingoff plugins,
232                                           preferences and configuration */
233
234     main_lb = g_object_get_data(G_OBJECT(win), "protocol_label");
235     /* make_dissector_reg.py changed -
236        so we need to strip off the leading elements to get back to the protocol */
237     if(message) {
238       if(!strncmp(message, "proto_register_", 15))
239         message += 15;
240       else if(!strncmp(message, "proto_reg_handoff_", 18))
241         message += 18;
242     }
243     gtk_label_set_text(GTK_LABEL(main_lb), message ? message : "");
244
245     ul_sofar++;
246
247     g_assert (ul_sofar <= ul_count);
248
249     percentage = (gfloat)ul_sofar/(gfloat)ul_count;
250     ul_percentage = (gulong)(percentage * 100);
251
252     /* update progress bar */
253     prog_bar = g_object_get_data(G_OBJECT(win), "progress_bar");
254     gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(prog_bar), percentage);
255
256     percentage_lb = g_object_get_data(G_OBJECT(win), "percentage_label");
257     g_snprintf(tmp, sizeof(tmp), "%lu%%", ul_percentage);
258     gtk_label_set_text((GtkLabel*)percentage_lb, tmp);
259
260     /* Process all pending GUI events before continuing, so that
261        the splash screen window gets updated. */
262     while (gtk_events_pending()) gtk_main_iteration();
263
264 }
265
266 guint
267 splash_destroy(GtkWidget *win)
268 {
269     if (win == NULL) return FALSE;
270
271     gtk_widget_destroy(win);
272     return FALSE;
273 }
274
275
276 static GtkWidget *
277 about_wireshark_page_new(void)
278 {
279   GtkWidget   *main_vb, *msg_label /*, *icon*/;
280   gchar       *message;
281
282   main_vb = gtk_vbox_new(FALSE, 6);
283   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 12);
284
285 #if GTK_CHECK_VERSION(2,9,0)
286   g_object_set(gtk_widget_get_settings(main_vb),
287     "gtk-label-select-on-focus", FALSE, NULL);
288 #endif
289
290   about_wireshark(top_level, main_vb);
291
292   /* Construct the message string */
293   message = g_strdup_printf(
294        "Version " VERSION "%s\n"
295        "\n"
296        "%s"
297        "\n"
298        "%s"
299        "\n"
300        "%s"
301        "\n"
302        "Wireshark is Open Source Software released under the GNU General Public License.\n"
303        "\n"
304        "Check the man page and http://www.wireshark.org for more information.",
305        wireshark_svnversion, get_copyright_info(), comp_info_str->str,
306        runtime_info_str->str);
307
308   msg_label = gtk_label_new(message);
309   g_free(message);
310   gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_FILL);
311   gtk_label_set_selectable(GTK_LABEL(msg_label), TRUE);
312   gtk_container_add(GTK_CONTAINER(main_vb), msg_label);
313
314   return main_vb;
315 }
316
317 static GtkWidget *
318 about_authors_page_new(void)
319 {
320   GtkWidget   *page;
321   char *absolute_path;
322
323   absolute_path = get_datafile_path("AUTHORS-SHORT");
324   page = text_page_new(absolute_path);
325
326   return page;
327 }
328
329 static gint about_folders_callback(GtkWidget *widget, GdkEventButton *event, gint id _U_)
330 {
331   GtkTreeSelection *tree_selection;
332   GtkTreeModel *model;
333   GtkTreeIter  iter;
334   gchar        *path;
335
336   tree_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
337
338   if(gtk_tree_selection_count_selected_rows(tree_selection) == 0)
339     return FALSE;
340
341   if(event->type != GDK_2BUTTON_PRESS)
342     /* not a double click */
343     return FALSE;
344
345   if(gtk_tree_selection_get_selected (tree_selection, &model, &iter)) {
346     gtk_tree_model_get(model, &iter, 1, &path, -1);
347     filemanager_open_directory(path);
348   }
349
350   return TRUE;
351 }
352
353 static void
354 about_folders_row(GtkWidget *table, const char *label, const char *dir, const char *tip)
355 {
356   simple_list_append(table, 0, label, 1, dir, 2, tip, -1);
357 }
358
359
360 static GtkWidget *
361 about_folders_page_new(void)
362 {
363   GtkWidget   *table;
364   const char *constpath;
365   char *path;
366   const gchar *titles[] = { "Name", "Folder", "Typical Files"};
367   GtkWidget *scrolledwindow;
368 #if defined (HAVE_LIBSMI) || defined (HAVE_GEOIP)
369   gint i;
370   gchar **resultArray;
371 #endif
372
373   scrolledwindow = scrolled_window_new(NULL, NULL);
374   gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow),
375                                    GTK_SHADOW_IN);
376
377   /* Container for our data */
378   table = simple_list_new(3, titles);
379
380   /* connect a callback so we can spot a double-click */
381   g_signal_connect(table, "button_press_event",
382                      G_CALLBACK(about_folders_callback), NULL);
383
384   simple_list_url_col(table, 1);
385
386   /* "file open" */
387   about_folders_row(table, "\"File\" dialogs", get_last_open_dir(),
388       "capture files");
389
390   /* temp */
391   path = get_tempfile_path("");
392   about_folders_row(table, "Temp", path,
393       "untitled capture files");
394   g_free((void *) path);
395
396   /* pers conf */
397   path = get_persconffile_path("", FALSE, FALSE);
398   about_folders_row(table, "Personal configuration", path,
399       "\"dfilters\", \"preferences\", \"ethers\", ...");
400   g_free((void *) path);
401
402   /* global conf */
403   constpath = get_datafile_dir();
404   if (constpath != NULL) {
405     about_folders_row(table, "Global configuration", constpath,
406         "\"dfilters\", \"preferences\", \"manuf\", ...");
407   }
408
409   /* system */
410   constpath = get_systemfile_dir();
411   about_folders_row(table, "System", constpath,
412       "\"ethers\", \"ipxnets\"");
413
414   /* program */
415   constpath = get_progfile_dir();
416   about_folders_row(table, "Program", constpath,
417       "program files");
418
419 #ifdef HAVE_PLUGINS
420   /* pers plugins */
421   path = get_plugins_pers_dir();
422   about_folders_row(table, "Personal Plugins", path,
423       "dissector plugins");
424   g_free((void *) path);
425
426   /* global plugins */
427   about_folders_row(table, "Global Plugins", get_plugin_dir(),
428       "dissector plugins");
429 #endif
430
431 #ifdef HAVE_GEOIP
432   /* GeoIP */
433   path = geoip_db_get_paths();
434
435 #ifdef _WIN32
436   resultArray = g_strsplit(path, ";", 10);
437 #else
438   resultArray = g_strsplit(path, ":", 10);
439 #endif
440
441   for(i = 0; resultArray[i]; i++)
442     about_folders_row(table, "GeoIP path", g_strstrip(resultArray[i]),
443                       "GeoIP database search path");
444   g_strfreev(resultArray);
445   g_free((void *) path);
446 #endif
447
448 #ifdef HAVE_LIBSMI
449   /* SMI MIBs/PIBs */
450   path = oid_get_default_mib_path();
451
452 #ifdef _WIN32
453   resultArray = g_strsplit(path, ";", 10);
454 #else
455   resultArray = g_strsplit(path, ":", 10);
456 #endif
457
458   for(i = 0; resultArray[i]; i++)
459     about_folders_row(table, "MIB/PIB path", g_strstrip(resultArray[i]),
460                       "SMI MIB/PIB search path");
461   g_strfreev(resultArray);
462   g_free((void *) path);
463 #endif
464
465   gtk_container_add(GTK_CONTAINER(scrolledwindow), table);
466
467   return scrolledwindow;
468 }
469
470 static GtkWidget *
471 about_license_page_new(void)
472 {
473   GtkWidget   *page;
474   char *absolute_path;
475
476   absolute_path = get_datafile_path("COPYING");
477   page = text_page_new(absolute_path);
478
479   return page;
480 }
481
482 void
483 about_wireshark_cb( GtkWidget *w _U_, gpointer data _U_ )
484 {
485   GtkWidget   *main_vb, *main_nb, *bbox, *ok_btn;
486   GtkWidget   *page_lb, *about_page, *folders_page;
487
488 #ifdef HAVE_PLUGINS
489   GtkWidget   *plugins_page;
490 #endif
491
492   GtkWidget   *authors_page, *license_page;
493
494   if (about_wireshark_w != NULL) {
495     /* There's already an "About Wireshark" dialog box; reactivate it. */
496     reactivate_window(about_wireshark_w);
497     return;
498   }
499
500   /*
501    * XXX - use GtkDialog?  The GNOME 2.x GnomeAbout widget does.
502    * Should we use GtkDialog for simple_dialog() as well?  Or
503    * is the GTK+ 2.x GtkDialog appropriate but the 1.2[.x] one
504    * not?  (The GNOME 1.x GnomeAbout widget uses GnomeDialog.)
505    */
506   about_wireshark_w = dlg_window_new("About Wireshark");
507   /* set the initial position (must be done, before show is called!) */
508   /* default position is not appropriate for the about dialog */
509   gtk_window_set_position(GTK_WINDOW(about_wireshark_w), GTK_WIN_POS_CENTER_ON_PARENT);
510   gtk_window_set_default_size(GTK_WINDOW(about_wireshark_w), 600, 400);
511   gtk_container_set_border_width(GTK_CONTAINER(about_wireshark_w), 6);
512
513   main_vb = gtk_vbox_new(FALSE, 12);
514   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 6);
515   gtk_container_add(GTK_CONTAINER(about_wireshark_w), main_vb);
516
517   main_nb = gtk_notebook_new();
518   gtk_box_pack_start(GTK_BOX(main_vb), main_nb, TRUE, TRUE, 0);
519
520   about_page = about_wireshark_page_new();
521   page_lb = gtk_label_new("Wireshark");
522   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), about_page, page_lb);
523
524   authors_page = about_authors_page_new();
525   page_lb = gtk_label_new("Authors");
526   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), authors_page, page_lb);
527
528   folders_page = about_folders_page_new();
529   page_lb = gtk_label_new("Folders");
530   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), folders_page, page_lb);
531
532 #ifdef HAVE_PLUGINS
533   plugins_page = about_plugins_page_new();
534   page_lb = gtk_label_new("Plugins");
535   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), plugins_page, page_lb);
536 #endif
537
538   license_page = about_license_page_new();
539   page_lb = gtk_label_new("License");
540   /* set a minmum width to avoid a lot of line breaks at the wrong places */
541   gtk_widget_set_size_request(license_page, 600, -1);
542   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), license_page, page_lb);
543
544   /* Button row */
545   bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
546   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
547
548   ok_btn = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
549   gtk_widget_grab_focus(ok_btn);
550   gtk_widget_grab_default(ok_btn);
551   window_set_cancel_button(about_wireshark_w, ok_btn, window_cancel_button_cb);
552
553   g_signal_connect(about_wireshark_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
554   g_signal_connect(about_wireshark_w, "destroy", G_CALLBACK(about_wireshark_destroy_cb), NULL);
555
556   gtk_widget_show_all(about_wireshark_w);
557   window_present(about_wireshark_w);
558 }
559
560 static void
561 about_wireshark_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
562 {
563   /* Note that we no longer have an "About Wireshark" dialog box. */
564   about_wireshark_w = NULL;
565 }
566
567