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