Delete extra_split if we're not using it. This keeps its handle from
[metze/wireshark/wip.git] / ui / gtk / plugins_dlg.c
1 /* plugins_dlg.c
2  * Dialog boxes for plugins
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <gtk/gtk.h>
28
29 #include "epan/plugins.h"
30
31 #include "ui/gtk/dlg_utils.h"
32 #include "ui/gtk/gui_utils.h"
33 #include "ui/gtk/plugins_dlg.h"
34
35 #include "webbrowser.h"
36
37 #if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
38
39 static gboolean
40 about_plugins_callback(GtkWidget *widget, GdkEventButton *event, gint id _U_)
41 {
42   GtkTreeSelection *tree_selection;
43   GtkTreeModel *model;
44   GtkTreeIter  iter;
45   gchar        *type;
46   gchar        *file;
47
48   tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(widget));
49
50   if (gtk_tree_selection_count_selected_rows (tree_selection) == 0)
51     return FALSE;
52
53   if (event->type != GDK_2BUTTON_PRESS)
54     /* not a double click */
55     return FALSE;
56
57   if (gtk_tree_selection_get_selected (tree_selection, &model, &iter)) {
58      gtk_tree_model_get (model, &iter, 2, &type, -1);
59      if (strcmp (type, "lua script") == 0) {
60         gtk_tree_model_get (model, &iter, 3, &file, -1);
61         browser_open_data_file (file);
62         g_free (file);
63      }
64      g_free (type);
65   }
66
67   return TRUE;
68 }
69
70 /*
71  * Fill the list widget with a list of the plugin modules.
72  * XXX - We might want to combine this with plugins_dump_all().
73  */
74 static void
75 plugins_scan(GtkWidget *list)
76 {
77 #ifdef HAVE_PLUGINS
78     plugin     *pt_plug;
79     const char *sep;
80 #endif
81 #ifdef HAVE_LUA
82     wslua_plugin  *lua_plug;
83 #endif
84     GString    *type;
85
86 #ifdef HAVE_PLUGINS
87     for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
88     {
89         type = g_string_new("");
90         sep = "";
91         if (pt_plug->register_protoinfo)
92         {
93             type = g_string_append(type, "dissector");
94             sep = ", ";
95         }
96         if (pt_plug->register_tap_listener)
97         {
98             type = g_string_append(type, sep);
99             type = g_string_append(type, "tap");
100             sep = ", ";
101         }
102         if (pt_plug->register_wtap_module)
103         {
104             type = g_string_append(type, sep);
105             type = g_string_append(type, "file format");
106             sep = ", ";
107         }
108         if (pt_plug->register_codec_module)
109         {
110             type = g_string_append(type, sep);
111             type = g_string_append(type, "codec");
112         }
113         simple_list_append(list, 0, pt_plug->name, 1, pt_plug->version,
114                            2, type->str, 3, g_module_name(pt_plug->handle), -1);
115         g_string_free(type, TRUE);
116     }
117 #endif
118
119 #ifdef HAVE_LUA
120     for (lua_plug = wslua_plugin_list; lua_plug != NULL; lua_plug = lua_plug->next)
121     {
122         type = g_string_new("");
123         type = g_string_append(type, "lua script");
124
125         simple_list_append(list, 0, lua_plug->name, 1, lua_plug->version, 2, type->str, 3, lua_plug->filename, -1);
126         g_string_free(type, TRUE);
127     }
128 #endif
129 }
130
131
132 GtkWidget *
133 about_plugins_page_new(void)
134 {
135     GtkWidget *scrolledwindow;
136     GtkWidget *plugins_list;
137     static const gchar *titles[] = {"Name", "Version", "Type", "Path"};
138
139
140     scrolledwindow = scrolled_window_new(NULL, NULL);
141     gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow),
142                                    GTK_SHADOW_IN);
143
144     plugins_list = simple_list_new(4, titles);
145     plugins_scan(plugins_list);
146
147     /* connect a callback so we can spot a double-click */
148     g_signal_connect(plugins_list, "button_press_event",
149                      G_CALLBACK(about_plugins_callback), NULL);
150     
151     gtk_container_add(GTK_CONTAINER(scrolledwindow), plugins_list);
152
153     return scrolledwindow;
154 }
155
156 #endif /* HAVE_PLUGINS || HAVE_LUA */