498bc027bc6e01660efd0967ffe4c63efd77d3a5
[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  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <gtk/gtk.h>
31
32 #include <epan/filesystem.h>
33 #include <epan/plugins.h>
34 #include "about_dlg.h"
35 #include "ui_util.h"
36 #include "dlg_utils.h"
37 #include "compat_macros.h"
38 #include "globals.h"
39 #if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3
40 #include "text_page.h"
41 #endif
42
43 #include "svnversion.h"
44
45 #include "../image/eicon3d64.xpm"
46 #include "gtkglobals.h"
47
48 extern GString *comp_info_str, *runtime_info_str;
49
50 #ifdef HAVE_PLUGINS
51 extern GtkWidget *about_plugins_page_new(void);
52 #endif
53
54 static void about_ethereal_destroy_cb(GtkWidget *, gpointer);
55
56
57 /*
58  * Keep a static pointer to the current "About Ethereal" window, if any, so
59  * that if somebody tries to do "About Ethereal" while there's already an
60  * "About Ethereal" window up, we just pop up the existing one, rather than
61  * creating a new one.
62  */
63 static GtkWidget *about_ethereal_w;
64
65
66 static void
67 about_ethereal(GtkWidget *parent, GtkWidget *main_vb, const char *title)
68 {
69   GtkWidget   *msg_label, *icon;
70 #if GTK_MAJOR_VERSION >= 2
71   gchar       *message;
72 #endif
73
74   icon = xpm_to_widget_from_parent(parent, eicon3d64_xpm);
75   gtk_container_add(GTK_CONTAINER(main_vb), icon);
76
77   msg_label = gtk_label_new(title);
78 #if GTK_MAJOR_VERSION >= 2
79   message = g_strdup_printf("<span size=\"x-large\" weight=\"bold\">%s</span>", title);
80   gtk_label_set_markup(GTK_LABEL(msg_label), message);
81   g_free(message);
82 #endif
83   gtk_container_add(GTK_CONTAINER(main_vb), msg_label);
84 }
85
86
87 GtkWidget *
88 splash_new(char *message)
89 {
90     GtkWidget *win;
91     GtkWidget *main_lb;
92
93     GtkWidget *main_vb;
94
95     win = splash_window_new();
96
97     /* When calling about_ethereal(), we must realize the top-level
98        widget for the window, otherwise GTK will throw a warning
99        because we don't have a colormap associated with that window and
100        can't handle the pixmap. */
101     gtk_widget_realize(win);
102
103     main_vb = gtk_vbox_new(FALSE, 6);
104     gtk_container_border_width(GTK_CONTAINER(main_vb), 24);
105     gtk_container_add(GTK_CONTAINER(win), main_vb);
106
107     about_ethereal(win, main_vb, "Ethereal - Network Protocol Analyzer");
108
109     main_lb = gtk_label_new(message);
110     gtk_container_add(GTK_CONTAINER(main_vb), main_lb);
111     OBJECT_SET_DATA(win, "splash_label", main_lb);
112     
113     gtk_widget_show_all(win);
114
115     splash_update(win, message);
116
117     return win;
118 }
119
120 void
121 splash_update(GtkWidget *win, char *message)
122 {
123     GtkWidget *main_lb;
124
125     if (win == NULL) return;
126
127     main_lb = OBJECT_GET_DATA(win, "splash_label");
128     gtk_label_set_text(GTK_LABEL(main_lb), message);
129
130     /* Process all pending GUI events before continuing, so that
131        the splash screen window gets updated. */
132     while (gtk_events_pending()) gtk_main_iteration();
133 }
134
135 guint
136 splash_destroy(GtkWidget *win)
137 {
138     if (win == NULL) return FALSE;
139
140     gtk_widget_destroy(win);
141     return FALSE;
142 }
143
144
145 static GtkWidget *
146 about_ethereal_page_new(void)
147 {
148   GtkWidget   *main_vb, *msg_label /*, *icon*/;
149   gchar       *message;
150   const char   title[] = "Ethereal - Network Protocol Analyzer";
151
152   main_vb = gtk_vbox_new(FALSE, 6);
153   gtk_container_border_width(GTK_CONTAINER(main_vb), 12);
154
155   about_ethereal(top_level, main_vb, title);
156
157   /* Construct the message string */
158   message = g_strdup_printf(
159        "Version " VERSION
160 #ifdef SVNVERSION
161        " (" SVNVERSION ")"
162 #endif
163        " (C) 1998-2005 Gerald Combs <gerald@ethereal.com>\n\n"
164        "%s\n\n"
165        "%s\n\n"
166
167        "Ethereal is Open Source Software released under the GNU General Public License.\n\n"
168
169        "Check the man page and http://www.ethereal.com for more information.",
170        comp_info_str->str, runtime_info_str->str);
171
172   msg_label = gtk_label_new(message);
173   g_free(message);
174   gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_FILL);
175 #if GTK_MAJOR_VERSION >= 2
176   gtk_label_set_selectable(GTK_LABEL(msg_label), TRUE);
177 #endif
178   gtk_container_add(GTK_CONTAINER(main_vb), msg_label);
179
180   return main_vb;
181 }
182
183 #if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3
184 static GtkWidget *
185 about_authors_page_new(void)
186 {
187   GtkWidget   *page;
188   char *absolute_path;
189
190   absolute_path = get_datafile_path("AUTHORS-SHORT");
191   page = text_page_new(absolute_path);
192
193   return page;
194 }
195 #endif
196
197 static void
198 about_folders_row(GtkWidget *table, const char *label, const char *dir, const char *tip)
199 {
200   simple_list_append(table, 0, label, 1, dir, 2, tip, -1);
201 }
202
203
204 static GtkWidget *
205 about_folders_page_new(void)
206 {
207   GtkWidget   *table;
208   const char *constpath;
209   char *path;
210   const gchar *titles[] = { "Name", "Folder", "Typical Files"};
211   GtkWidget *scrolledwindow;
212
213   scrolledwindow = scrolled_window_new(NULL, NULL);
214 #if GTK_MAJOR_VERSION >= 2
215   gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), 
216                                    GTK_SHADOW_IN);
217 #endif
218
219   /* Container for our data */
220   table = simple_list_new(3, titles);
221
222   /* "file open" */
223   about_folders_row(table, "\"File\" dialogs", get_last_open_dir(),
224       "capture files");
225
226   /* temp */
227   path = get_tempfile_path("");
228   about_folders_row(table, "Temp", path,
229       "untitled capture files");
230   g_free((void *) path);
231
232   /* pers conf */
233   path = get_persconffile_path("", FALSE);
234   about_folders_row(table, "Personal configuration", path, 
235       "\"dfilters\", \"preferences\", \"ethers\", ...");
236   g_free((void *) path);
237
238   /* global conf */
239   constpath = get_datafile_dir();
240   about_folders_row(table, "Global configuration", constpath,
241       "\"dfilters\", \"preferences\", \"manuf\", ...");
242
243   /* system */
244   constpath = get_systemfile_dir();
245   about_folders_row(table, "System", constpath,
246       "\"ethers\", \"ipxnets\"");
247
248   /* program */
249   path = g_strdup(ethereal_path);
250   path = get_dirname(path);
251   about_folders_row(table, "Program", path,
252       "program files");
253   g_free((void *) path);
254
255 #ifdef HAVE_PLUGINS
256   /* pers plugins */
257   path = get_plugins_pers_dir();
258   about_folders_row(table, "Personal Plugins", path,
259       "dissector plugins");
260   g_free((void *) path);
261
262   /* global plugins */
263   path = get_plugins_global_dir(PLUGIN_DIR);
264   about_folders_row(table, "Global Plugins", path,
265       "dissector plugins");
266   g_free((void *) path);
267 #endif
268
269   gtk_container_add(GTK_CONTAINER(scrolledwindow), table);
270
271   return scrolledwindow;
272 }
273
274
275 void
276 about_ethereal_cb( GtkWidget *w _U_, gpointer data _U_ )
277 {
278   GtkWidget   *main_vb, *main_nb, *bbox, *ok_btn;
279
280   GtkWidget   *page_lb, *about_page, *folders_page, *plugins_page;
281 #if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3
282   GtkWidget   *authors_page;
283 #endif
284
285   if (about_ethereal_w != NULL) {
286     /* There's already an "About Ethereal" dialog box; reactivate it. */
287     reactivate_window(about_ethereal_w);
288     return;
289   }
290
291   /*
292    * XXX - use GtkDialog?  The GNOME 2.x GnomeAbout widget does.
293    * Should we use GtkDialog for simple_dialog() as well?  Or
294    * is the GTK+ 2.x GtkDialog appropriate but the 1.2[.x] one
295    * not?  (The GNOME 1.x GnomeAbout widget uses GnomeDialog.)
296    */
297   about_ethereal_w = dlg_window_new("About Ethereal");
298   /* set the initial position (must be done, before show is called!) */
299   /* default position is not appropriate for the about dialog */
300 #if GTK_MAJOR_VERSION >= 2
301   gtk_window_set_position(GTK_WINDOW(about_ethereal_w), GTK_WIN_POS_CENTER_ON_PARENT);
302 #else
303   gtk_window_set_position(GTK_WINDOW(about_ethereal_w), GTK_WIN_POS_CENTER);
304 #endif
305   /* setting the size is dangerous here, as making it too short will 
306    * clip content on GTK1, so simply use the natural size */
307   /*gtk_window_set_default_size(GTK_WINDOW(about_ethereal_w), 600, 400);*/
308   gtk_container_border_width(GTK_CONTAINER(about_ethereal_w), 6);
309
310   main_vb = gtk_vbox_new(FALSE, 12);
311   gtk_container_border_width(GTK_CONTAINER(main_vb), 6);
312   gtk_container_add(GTK_CONTAINER(about_ethereal_w), main_vb);
313
314   main_nb = gtk_notebook_new();
315   gtk_box_pack_start(GTK_BOX(main_vb), main_nb, TRUE, TRUE, 0);
316
317   about_page = about_ethereal_page_new();
318   page_lb = gtk_label_new("Ethereal");
319   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), about_page, page_lb);
320
321 #if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3
322   authors_page = about_authors_page_new();
323   page_lb = gtk_label_new("Authors");
324   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), authors_page, page_lb);
325 #endif
326
327   folders_page = about_folders_page_new();
328   page_lb = gtk_label_new("Folders");
329   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), folders_page, page_lb);
330
331 #ifdef HAVE_PLUGINS
332   plugins_page = about_plugins_page_new();
333   page_lb = gtk_label_new("Plugins");
334   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), plugins_page, page_lb);
335 #endif
336
337   /* Button row */
338   bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
339   gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
340
341   ok_btn = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
342   window_set_cancel_button(about_ethereal_w, ok_btn, window_cancel_button_cb);
343
344   SIGNAL_CONNECT(about_ethereal_w, "delete_event", window_delete_event_cb, NULL);
345   SIGNAL_CONNECT(about_ethereal_w, "destroy", about_ethereal_destroy_cb, NULL);
346
347   gtk_widget_show_all(about_ethereal_w);
348   window_present(about_ethereal_w);
349 }
350
351 static void
352 about_ethereal_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
353 {
354   /* Note that we no longer have an "About Ethereal" dialog box. */
355   about_ethereal_w = NULL;
356 }
357
358