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