restructure configure so pkg-config derived SSL flags get used
[rofl0r-ixchat.git] / src / fe-gtk / plugingui.c
blob8fb6ee362291cc32634d1943e86c897019d44ea0
1 /* X-Chat
2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #include <string.h>
20 #include <stdio.h>
21 #include <stdlib.h>
23 #include "fe-gtk.h"
25 #include <gtk/gtkdialog.h>
26 #include <gtk/gtkstock.h>
27 #include <gtk/gtkbox.h>
28 #include <gtk/gtkscrolledwindow.h>
30 #include <gtk/gtkliststore.h>
31 #include <gtk/gtktreeview.h>
32 #include <gtk/gtktreeselection.h>
33 #include <gtk/gtkcellrenderertext.h>
35 #include "../common/xchat.h"
36 #define PLUGIN_C
37 typedef struct session xchat_context;
38 #include "../common/xchat-plugin.h"
39 #include "../common/plugin.h"
40 #include "../common/util.h"
41 #include "../common/outbound.h"
42 #include "../common/fe.h"
43 #include "../common/xchatc.h"
44 #include "gtkutil.h"
46 /* model for the plugin treeview */
47 enum
49 NAME_COLUMN,
50 VERSION_COLUMN,
51 FILE_COLUMN,
52 DESC_COLUMN,
53 N_COLUMNS
56 static GtkWidget *plugin_window = NULL;
59 static GtkWidget *
60 plugingui_treeview_new (GtkWidget *box)
62 GtkListStore *store;
63 GtkWidget *view;
64 GtkTreeViewColumn *col;
65 int col_id;
67 store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
68 G_TYPE_STRING, G_TYPE_STRING);
69 g_return_val_if_fail (store != NULL, NULL);
70 view = gtkutil_treeview_new (box, GTK_TREE_MODEL (store), NULL,
71 NAME_COLUMN, _("Name"),
72 VERSION_COLUMN, _("Version"),
73 FILE_COLUMN, _("File"),
74 DESC_COLUMN, _("Description"), -1);
75 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
76 for (col_id=0; (col = gtk_tree_view_get_column (GTK_TREE_VIEW (view), col_id));
77 col_id++)
78 gtk_tree_view_column_set_alignment (col, 0.5);
80 gtk_widget_show (view);
81 return view;
84 static void
85 plugingui_close_button (GtkWidget * wid, gpointer a)
87 gtk_widget_destroy (plugin_window);
90 static void
91 plugingui_close (GtkWidget * wid, gpointer a)
93 plugin_window = NULL;
96 extern GSList *plugin_list;
98 void
99 fe_pluginlist_update (void)
101 xchat_plugin *pl;
102 GSList *list;
103 GtkTreeView *view;
104 GtkListStore *store;
105 GtkTreeIter iter;
107 if (!plugin_window)
108 return;
110 view = g_object_get_data (G_OBJECT (plugin_window), "view");
111 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
112 gtk_list_store_clear (store);
114 list = plugin_list;
115 while (list)
117 pl = list->data;
118 if (pl->version[0] != 0)
120 gtk_list_store_append (store, &iter);
121 gtk_list_store_set (store, &iter, NAME_COLUMN, pl->name,
122 VERSION_COLUMN, pl->version,
123 FILE_COLUMN, file_part (pl->filename),
124 DESC_COLUMN, pl->desc, -1);
126 list = list->next;
130 static void
131 plugingui_load_cb (session *sess, char *file)
133 if (file)
135 char *buf = malloc (strlen (file) + 9);
137 if (strchr (file, ' '))
138 sprintf (buf, "LOAD \"%s\"", file);
139 else
140 sprintf (buf, "LOAD %s", file);
141 handle_command (sess, buf, FALSE);
142 free (buf);
146 void
147 plugingui_load (void)
149 gtkutil_file_req (_("Select a Plugin or Script to load"), plugingui_load_cb,
150 current_sess, NULL, FRF_ADDFOLDER);
153 static void
154 plugingui_loadbutton_cb (GtkWidget * wid, gpointer unused)
156 plugingui_load ();
159 static void
160 plugingui_unload (GtkWidget * wid, gpointer unused)
162 int len;
163 char *modname, *file, *buf;
164 GtkTreeView *view;
165 GtkTreeIter iter;
167 view = g_object_get_data (G_OBJECT (plugin_window), "view");
168 if (!gtkutil_treeview_get_selected (view, &iter, NAME_COLUMN, &modname,
169 FILE_COLUMN, &file, -1))
170 return;
172 len = strlen (file);
173 if (len > 3 && strcasecmp (file + len - 3, ".so") == 0)
175 if (plugin_kill (modname, FALSE) == 2)
176 fe_message (_("That plugin is refusing to unload.\n"), FE_MSG_ERROR);
177 } else
179 /* let python.so or perl.so handle it */
180 buf = malloc (strlen (file) + 10);
181 if (strchr (file, ' '))
182 sprintf (buf, "UNLOAD \"%s\"", file);
183 else
184 sprintf (buf, "UNLOAD %s", file);
185 handle_command (current_sess, buf, FALSE);
186 free (buf);
189 g_free (modname);
190 g_free (file);
193 void
194 plugingui_open (void)
196 GtkWidget *view;
197 GtkWidget *vbox, *action_area;
199 if (plugin_window)
201 gtk_window_present (GTK_WINDOW (plugin_window));
202 return;
205 plugin_window = gtk_dialog_new ();
206 g_signal_connect (G_OBJECT (plugin_window), "destroy",
207 G_CALLBACK (plugingui_close), 0);
208 gtk_window_set_default_size (GTK_WINDOW (plugin_window), 500, 250);
209 vbox = GTK_DIALOG (plugin_window)->vbox;
210 action_area = GTK_DIALOG (plugin_window)->action_area;
211 gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
212 gtk_window_set_position (GTK_WINDOW (plugin_window), GTK_WIN_POS_CENTER);
213 gtk_window_set_title (GTK_WINDOW (plugin_window), _("XChat: Plugins and Scripts"));
215 view = plugingui_treeview_new (vbox);
216 g_object_set_data (G_OBJECT (plugin_window), "view", view);
218 gtkutil_button (action_area, GTK_STOCK_REVERT_TO_SAVED, NULL,
219 plugingui_loadbutton_cb, NULL, _("_Load..."));
221 gtkutil_button (action_area, GTK_STOCK_DELETE, NULL,
222 plugingui_unload, NULL, _("_UnLoad"));
224 gtkutil_button (action_area,
225 GTK_STOCK_CLOSE, NULL, plugingui_close_button,
226 NULL, _("_Close"));
228 fe_pluginlist_update ();
230 gtk_widget_show (plugin_window);