separate dir functions from the plugin init,
[obnox/wireshark/wip.git] / gtk / about_dlg.c
1 /* about_dlg.c
2  *
3  * $Id: about_dlg.c,v 1.2 2004/05/20 13:48:25 ulfl Exp $
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 "ui_util.h"
35 #include "dlg_utils.h"
36 #include "compat_macros.h"
37 #include "globals.h"
38
39 extern GString *comp_info_str, *runtime_info_str;
40
41 static void about_ethereal_destroy_cb(GtkWidget *, gpointer);
42
43
44 /*
45  * Keep a static pointer to the current "About Ethereal" window, if any, so
46  * that if somebody tries to do "About Ethereal" while there's already an
47  * "About Ethereal" window up, we just pop up the existing one, rather than
48  * creating a new one.
49  */
50 static GtkWidget *about_ethereal_w;
51
52
53 static GtkWidget *
54 about_ethereal_new(void)
55 {
56   GtkWidget   *main_vb, *top_hb, *msg_label;
57   gchar       *message;
58
59   /* Container for our rows */
60   main_vb = gtk_vbox_new(FALSE, 5);
61   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
62
63   /* Top row: Message text */
64   top_hb = gtk_hbox_new(FALSE, 10);
65   gtk_container_add(GTK_CONTAINER(main_vb), top_hb);
66
67   /* Construct the message string */
68   message = g_strdup_printf(
69            "Ethereal - Network Protocol Analyzer\n\n"
70            
71            "Version " VERSION
72 #ifdef CVSVERSION
73            " (" CVSVERSION ")"
74 #endif
75            " (C) 1998-2004 Gerald Combs <gerald@ethereal.com>\n\n"
76
77        "%s\n"
78        "%s\n\n"
79
80        "Ethereal is Open Source software released under the GNU General Public License.\n\n"
81
82            "Check the man page for complete documentation and\n"
83            "for the list of contributors.\n\n"
84
85            "See http://www.ethereal.com for more information.",
86             comp_info_str->str, runtime_info_str->str);
87
88   msg_label = gtk_label_new(message);
89   g_free(message);
90   gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_FILL);
91   gtk_container_add(GTK_CONTAINER(top_hb), msg_label);
92
93   return main_vb;
94 }
95
96
97 static void
98 about_dirs_row(GtkWidget *table, guint row, const char *label, const char *dir, const char *tip)
99 {
100   GtkWidget   *prefs_lb;
101
102   prefs_lb = gtk_label_new(label);
103   gtk_table_attach_defaults(GTK_TABLE(table), prefs_lb, 0, 1, row, row+1);
104   gtk_misc_set_alignment(GTK_MISC(prefs_lb), 1.0, 0.5);
105
106   prefs_lb = gtk_label_new(dir);
107   gtk_table_attach_defaults(GTK_TABLE(table), prefs_lb, 1, 2, row, row+1);
108   gtk_misc_set_alignment(GTK_MISC(prefs_lb), 0.0, 0.5);
109
110   prefs_lb = gtk_label_new(tip);
111   gtk_table_attach_defaults(GTK_TABLE(table), prefs_lb, 2, 3, row, row+1);
112   gtk_misc_set_alignment(GTK_MISC(prefs_lb), 0.0, 0.5);
113 }
114
115
116 static GtkWidget *
117 about_dirs_new(void)
118 {
119   GtkWidget   *table;
120   guint row;
121   const char *path;
122
123   /* Container for our rows */
124   table = gtk_table_new(4, 3, FALSE);
125   gtk_table_set_col_spacings(GTK_TABLE(table), 6);
126   row = 0;
127
128
129   /* "file open" */
130   about_dirs_row(table, row, "\"File\" dialogs:", last_open_dir,
131       "capture files");
132   row++;
133
134   /* temp */
135   path = get_tempfile_path("");
136   about_dirs_row(table, row, "Temp:", path,
137       "untitled capture files");
138   g_free((void *) path);
139   row++;
140
141   /* pers conf */
142   path = get_persconffile_path("", FALSE);
143   about_dirs_row(table, row, "Personal configuration:", path, 
144       "\"dfilters\", \"preferences\", \"ethers\", ...");
145   g_free((void *) path);
146   row++;
147
148   /* global conf */
149   path = get_datafile_dir();
150   about_dirs_row(table, row, "Global configuration:", path,
151       "\"dfilters\", \"preferences\", \"manuf\", ...");
152   /*g_free(path);*/
153   row++;
154
155   /* system */
156   path = get_systemfile_dir();
157   about_dirs_row(table, row, "System:", path,
158       "\"ethers\", \"ipxnets\"");
159   /*g_free(path);*/
160   row++;
161
162   /* program */
163   path = strdup(ethereal_path);
164   path = get_dirname((char *) path);
165   about_dirs_row(table, row, "Program:", path,
166       "program files");
167   g_free((void *) path);
168   row++;
169
170   /* pers plugins */
171   path = get_plugins_pers_dir();
172   about_dirs_row(table, row, "Personal Plugins:", path,
173       "dissector plugins");
174   g_free((void *) path);
175   row++;
176
177   /* global plugins */
178   path = get_plugins_global_dir(PLUGIN_DIR);
179   about_dirs_row(table, row, "Global Plugins:", path,
180       "dissector plugins");
181   g_free((void *) path);
182   row++;
183
184   return table;
185 }
186
187
188 void
189 about_ethereal_cb( GtkWidget *w _U_, gpointer data _U_ )
190 {
191   GtkWidget   *main_vb, *main_nb, *bbox, *ok_btn;
192
193   GtkWidget   *about, *about_lb, *dirs, *dirs_lb;
194
195   if (about_ethereal_w != NULL) {
196     /* There's already an "About Ethereal" dialog box; reactivate it. */
197     reactivate_window(about_ethereal_w);
198     return;
199   }
200
201   /*
202    * XXX - use GtkDialog?  The GNOME 2.x GnomeAbout widget does.
203    * Should we use GtkDialog for simple_dialog() as well?  Or
204    * is the GTK+ 2.x GtkDialog appropriate but the 1.2[.x] one
205    * not?  (The GNOME 1.x GnomeAbout widget uses GnomeDialog.)
206    */
207   about_ethereal_w = dlg_window_new("About Ethereal");
208   SIGNAL_CONNECT(about_ethereal_w, "destroy", about_ethereal_destroy_cb, NULL);
209   gtk_container_border_width(GTK_CONTAINER(about_ethereal_w), 7);
210
211   main_vb = gtk_vbox_new(FALSE, 5);
212   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
213   gtk_container_add(GTK_CONTAINER(about_ethereal_w), main_vb);
214
215   main_nb = gtk_notebook_new();
216   gtk_container_add(GTK_CONTAINER(main_vb), main_nb);
217
218   about = about_ethereal_new();
219   about_lb = gtk_label_new("Ethereal");
220   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), about, about_lb);
221
222   dirs = about_dirs_new();
223   dirs_lb = gtk_label_new("Directories");
224   gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), dirs, dirs_lb);
225
226   /* Button row */
227   bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
228   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
229
230   ok_btn = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
231   SIGNAL_CONNECT_OBJECT(ok_btn, "clicked", gtk_widget_destroy,
232                         about_ethereal_w);
233   gtk_widget_grab_default(ok_btn);
234
235   /* Catch the "key_press_event" signal in the window, so that we can catch
236      the ESC key being pressed and act as if the "Cancel" button had
237      been selected. */
238   dlg_set_cancel(about_ethereal_w, ok_btn);
239
240   gtk_widget_show_all(about_ethereal_w);
241 }
242
243 static void
244 about_ethereal_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
245 {
246   /* Note that we no longer have an "About Ethereal" dialog box. */
247   about_ethereal_w = NULL;
248 }
249