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
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"
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"
46 /* model for the plugin treeview */
56 static GtkWidget
*plugin_window
= NULL
;
60 plugingui_treeview_new (GtkWidget
*box
)
64 GtkTreeViewColumn
*col
;
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
));
78 gtk_tree_view_column_set_alignment (col
, 0.5);
80 gtk_widget_show (view
);
85 plugingui_close_button (GtkWidget
* wid
, gpointer a
)
87 gtk_widget_destroy (plugin_window
);
91 plugingui_close (GtkWidget
* wid
, gpointer a
)
96 extern GSList
*plugin_list
;
99 fe_pluginlist_update (void)
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
);
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);
131 plugingui_load_cb (session
*sess
, char *file
)
135 char *buf
= malloc (strlen (file
) + 9);
137 if (strchr (file
, ' '))
138 sprintf (buf
, "LOAD \"%s\"", file
);
140 sprintf (buf
, "LOAD %s", file
);
141 handle_command (sess
, buf
, FALSE
);
147 plugingui_load (void)
149 gtkutil_file_req (_("Select a Plugin or Script to load"), plugingui_load_cb
,
150 current_sess
, NULL
, FRF_ADDFOLDER
);
154 plugingui_loadbutton_cb (GtkWidget
* wid
, gpointer unused
)
160 plugingui_unload (GtkWidget
* wid
, gpointer unused
)
163 char *modname
, *file
, *buf
;
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))
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
);
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
);
184 sprintf (buf
, "UNLOAD %s", file
);
185 handle_command (current_sess
, buf
, FALSE
);
194 plugingui_open (void)
197 GtkWidget
*vbox
, *action_area
;
201 gtk_window_present (GTK_WINDOW (plugin_window
));
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
,
228 fe_pluginlist_update ();
230 gtk_widget_show (plugin_window
);