- Declare some functions static
[obnox/wireshark/wip.git] / gtk / plugins_dlg.c
1 /* plugins_dlg.c
2  * Dialog boxes for plugins
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1999 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <gtk/gtk.h>
30
31 #include "globals.h"
32 #include <epan/plugins.h>
33 #include "dlg_utils.h"
34 #include "gui_utils.h"
35 #include "compat_macros.h"
36 #include "plugins_dlg.h"
37
38 #ifdef HAVE_PLUGINS
39
40 static void plugins_destroy_cb(GtkWidget *, gpointer);
41
42 /*
43  * Keep a static pointer to the current "Plugins" window, if any, so that
44  * if somebody tries to do "Help->About Plugins" while there's already a
45  * "Plugins" window up, we just pop up the existing one, rather than
46  * creating a new one.
47 */
48 static GtkWidget *plugins_window = NULL;
49
50
51
52 /*
53  * Fill the list widget with a list of the plugin modules.
54  */
55 static void
56 plugins_scan(GtkWidget *list)
57 {
58     plugin     *pt_plug;
59     GString    *type;
60     const char       *sep;
61
62     pt_plug = plugin_list;
63     while (pt_plug)
64     {
65         type = g_string_new("");
66         sep = "";
67         if (pt_plug->register_protoinfo)
68         {
69             type = g_string_append(type, sep);
70             type = g_string_append(type, "dissector");
71             sep = ",";
72         }
73         if (pt_plug->register_tap_listener)
74         {
75             type = g_string_append(type, sep);
76             type = g_string_append(type, "tap");
77             sep = ",";
78         }
79         simple_list_append(list, 0, pt_plug->name, 1, pt_plug->version,
80                            2, type->str, -1);
81         g_string_free(type, TRUE);
82         pt_plug = pt_plug->next;
83     }
84 }
85
86
87 GtkWidget *
88 about_plugins_page_new(void)
89 {
90     GtkWidget *scrolledwindow;
91     GtkWidget *plugins_list;
92     const gchar     *titles[] = {"Name", "Version", "Type"};
93
94     
95     scrolledwindow = scrolled_window_new(NULL, NULL);
96 #if GTK_MAJOR_VERSION >= 2
97     gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), 
98                                    GTK_SHADOW_IN);
99 #endif
100
101     plugins_list = simple_list_new(3 , titles);
102     plugins_scan(plugins_list);
103
104     gtk_container_add(GTK_CONTAINER(scrolledwindow), plugins_list);
105
106     return scrolledwindow;
107 }
108
109 static void
110 tools_plugins_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
111 {
112     GtkWidget *main_vbox;
113     GtkWidget *main_frame;
114     GtkWidget *frame_hbox;
115     GtkWidget *page;
116     GtkWidget *bbox;
117     GtkWidget *ok_bt;
118
119     if (plugins_window != NULL) {
120         /* There's already a "Plugins" dialog box; reactivate it. */
121         reactivate_window(plugins_window);
122         return;
123     }
124
125     plugins_window = dlg_window_new("Ethereal: Plugins");
126     gtk_window_set_default_size(GTK_WINDOW(plugins_window), 250, 200);
127
128     main_vbox = gtk_vbox_new(FALSE, 0);
129     gtk_container_add(GTK_CONTAINER(plugins_window), main_vbox);
130
131     main_frame = gtk_frame_new("Plugins List");
132     gtk_box_pack_start(GTK_BOX(main_vbox), main_frame, TRUE, TRUE, 0);
133     gtk_container_set_border_width(GTK_CONTAINER(main_frame), 5);
134
135     frame_hbox = gtk_hbox_new(FALSE,0);
136     gtk_container_add(GTK_CONTAINER(main_frame), frame_hbox);
137     gtk_container_set_border_width(GTK_CONTAINER(frame_hbox), 5);
138
139     page = about_plugins_page_new();
140     gtk_box_pack_start(GTK_BOX(frame_hbox), page, TRUE, TRUE, 0);
141
142     /* button row */
143     bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
144     gtk_box_pack_end(GTK_BOX(main_vbox), bbox, FALSE, FALSE, 3);
145
146     ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
147     window_set_cancel_button(plugins_window, ok_bt, window_cancel_button_cb);
148
149     SIGNAL_CONNECT(plugins_window, "delete_event", window_delete_event_cb, NULL);
150     SIGNAL_CONNECT(plugins_window, "destroy", plugins_destroy_cb, NULL);
151
152     gtk_widget_show_all(plugins_window);
153     window_present(plugins_window);
154 }
155
156 static void
157 plugins_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
158 {
159     /* Note that we no longer have a Plugins window. */
160     plugins_window = NULL;
161 }
162
163
164 #endif /* HAVE_PLUGINS */