FIRST_PROTO_PREFS_PAGE needs to be incremented by 2 in order for
[obnox/wireshark/wip.git] / gtk / plugins_dlg.c
1 /* plugins_dlg.c
2  * Dialog boxes for plugins
3  *
4  * $Id: plugins_dlg.c,v 1.23 2002/01/21 07:37:42 guy Exp $
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 <errno.h>
30
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
33 #endif
34
35 #include <stdlib.h>
36 #include <string.h>
37 #include <gtk/gtk.h>
38
39 #include "globals.h"
40 #include <epan/plugins.h>
41 #include "dlg_utils.h"
42
43 #ifdef HAVE_PLUGINS
44
45 static void plugins_close_cb(GtkWidget *, gpointer);
46 static void plugins_scan(GtkWidget *);
47
48 void
49 tools_plugins_cmd_cb(GtkWidget *widget, gpointer data)
50 {
51     GtkWidget *plugins_window;
52     GtkWidget *main_vbox;
53     GtkWidget *main_frame;
54     GtkWidget *frame_hbox;
55     GtkWidget *scrolledwindow;
56     GtkWidget *plugins_clist;
57     GtkWidget *frame_vbnbox;
58     GtkWidget *main_hbnbox;
59     GtkWidget *close_bn;
60     gchar     *titles[] = {"Name", "Version"};
61
62     plugins_window = dlg_window_new("Ethereal: Plugins");
63
64     main_vbox = gtk_vbox_new(FALSE, 0);
65     gtk_container_add(GTK_CONTAINER(plugins_window), main_vbox);
66     gtk_widget_show(main_vbox);
67
68     main_frame = gtk_frame_new("Plugins List");
69     gtk_box_pack_start(GTK_BOX(main_vbox), main_frame, TRUE, TRUE, 0);
70     gtk_container_set_border_width(GTK_CONTAINER(main_frame), 10);
71     gtk_widget_show(main_frame);
72
73     frame_hbox = gtk_hbox_new(FALSE,0);
74     gtk_container_add(GTK_CONTAINER(main_frame), frame_hbox);
75     gtk_container_set_border_width(GTK_CONTAINER(frame_hbox), 5);
76     gtk_widget_show(frame_hbox);
77
78     scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
79     gtk_box_pack_start(GTK_BOX(frame_hbox), scrolledwindow, TRUE, TRUE, 0);
80     gtk_widget_set_usize(scrolledwindow, 400, 150);
81     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),
82             GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
83     gtk_widget_show(scrolledwindow);
84
85     plugins_clist = gtk_clist_new_with_titles(2, titles);
86     gtk_container_add(GTK_CONTAINER(scrolledwindow), plugins_clist);
87     gtk_clist_set_selection_mode(GTK_CLIST(plugins_clist), GTK_SELECTION_SINGLE);
88     gtk_clist_column_titles_passive(GTK_CLIST(plugins_clist));
89     gtk_clist_column_titles_show(GTK_CLIST(plugins_clist));
90     gtk_clist_set_column_auto_resize(GTK_CLIST(plugins_clist), 0, TRUE);
91     gtk_clist_set_column_auto_resize(GTK_CLIST(plugins_clist), 1, TRUE);
92     plugins_scan(plugins_clist);
93     gtk_widget_show(plugins_clist);
94
95     frame_vbnbox = gtk_vbutton_box_new();
96     gtk_box_pack_start(GTK_BOX(frame_hbox), frame_vbnbox, FALSE, TRUE, 0);
97     gtk_container_set_border_width(GTK_CONTAINER(frame_vbnbox), 20);
98     gtk_button_box_set_layout(GTK_BUTTON_BOX(frame_vbnbox), GTK_BUTTONBOX_SPREAD);
99     gtk_widget_show(frame_vbnbox);
100
101     main_hbnbox = gtk_hbutton_box_new();
102     gtk_box_pack_start(GTK_BOX(main_vbox), main_hbnbox, FALSE, TRUE, 0);
103     gtk_container_set_border_width(GTK_CONTAINER(main_hbnbox), 10);
104     gtk_button_box_set_layout(GTK_BUTTON_BOX(main_hbnbox), GTK_BUTTONBOX_SPREAD);
105     gtk_widget_show(main_hbnbox);
106
107     close_bn = gtk_button_new_with_label("Close");
108     gtk_container_add(GTK_CONTAINER(main_hbnbox), close_bn);
109     gtk_widget_show(close_bn);
110     gtk_signal_connect(GTK_OBJECT(close_bn), "clicked",
111             GTK_SIGNAL_FUNC(plugins_close_cb), GTK_OBJECT(plugins_window));
112
113     gtk_widget_show(plugins_window);
114
115 }
116
117 /*
118  * Fill the clist widget with a list of the plugin modules.
119  */
120 static void
121 plugins_scan(GtkWidget *clist)
122 {
123     plugin   *pt_plug;
124     gchar    *plugent[2];               /* new entry added in clist */
125
126     pt_plug = plugin_list;
127     while (pt_plug)
128     {
129         plugent[0] = pt_plug->name;
130         plugent[1] = pt_plug->version;
131         gtk_clist_append(GTK_CLIST(clist), plugent);
132         pt_plug = pt_plug->next;
133     }
134 }
135
136 static void
137 plugins_close_cb(GtkWidget *close_bt, gpointer parent_w)
138 {
139     gtk_grab_remove(GTK_WIDGET(parent_w));
140     gtk_widget_destroy(GTK_WIDGET(parent_w));
141 }
142 #endif