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