|
1
|
1 /*
|
|
|
2 * gaim
|
|
|
3 *
|
|
|
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
|
|
|
5 *
|
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
|
9 * (at your option) any later version.
|
|
|
10 *
|
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
14 * GNU General Public License for more details.
|
|
|
15 *
|
|
|
16 * You should have received a copy of the GNU General Public License
|
|
|
17 * along with this program; if not, write to the Free Software
|
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
19 *
|
|
|
20 * ----------------
|
|
|
21 * The Plug-in plug
|
|
|
22 *
|
|
|
23 * Plugin support is currently being maintained by Mike Saraf
|
|
|
24 * msaraf@dwc.edu
|
|
|
25 *
|
|
90
|
26 * Well, I didn't see any work done on it for a while, so I'm going to try
|
|
|
27 * my hand at it. - Eric warmenhoven@yahoo.com
|
|
|
28 *
|
|
1
|
29 */
|
|
|
30
|
|
90
|
31 #ifdef GAIM_PLUGINS
|
|
|
32
|
|
1
|
33 #include <string.h>
|
|
|
34 #include <sys/time.h>
|
|
|
35
|
|
|
36 #include <sys/types.h>
|
|
|
37 #include <sys/stat.h>
|
|
|
38
|
|
|
39 #include <unistd.h>
|
|
|
40 #include <stdio.h>
|
|
|
41 #include <stdlib.h>
|
|
|
42 #include <gtk/gtk.h>
|
|
|
43 #include "gaim.h"
|
|
|
44
|
|
90
|
45 #include <dlfcn.h>
|
|
|
46
|
|
1
|
47 /* ------------------ Local Variables -------------------------*/
|
|
|
48
|
|
90
|
49 static GtkWidget *plugin_dialog = NULL;
|
|
|
50 static GList *plugins = NULL;
|
|
|
51
|
|
|
52 static GtkWidget *pluglist;
|
|
|
53 static GtkWidget *plugtext;
|
|
1
|
54
|
|
|
55 /* --------------- Function Declarations -------------------- */
|
|
|
56
|
|
90
|
57 void load_plugin (GtkWidget *, gpointer);
|
|
|
58 void unload_plugin(GtkWidget *, gpointer);
|
|
|
59 void show_plugins (GtkWidget *, gpointer);
|
|
|
60
|
|
|
61 static void destroy_plugins (GtkWidget *, gpointer);
|
|
|
62 static void load_which_plugin(GtkWidget *, gpointer);
|
|
|
63 static void unload (GtkWidget *, gpointer);
|
|
|
64 static void list_clicked (GtkWidget *, struct gaim_plugin *);
|
|
|
65
|
|
1
|
66 /* ------------------ Code Below ---------------------------- */
|
|
|
67
|
|
90
|
68 static void destroy_plugins(GtkWidget *w, gpointer data) {
|
|
|
69 if (plugin_dialog)
|
|
|
70 gtk_widget_destroy(plugin_dialog);
|
|
|
71 plugin_dialog = NULL;
|
|
|
72 }
|
|
|
73
|
|
|
74 void load_plugin(GtkWidget *w, gpointer data)
|
|
1
|
75 {
|
|
90
|
76 char *buf = g_malloc(BUF_LEN);
|
|
1
|
77
|
|
90
|
78 if (!plugin_dialog) {
|
|
|
79 plugin_dialog = gtk_file_selection_new("Gaim - Plugin List");
|
|
|
80
|
|
|
81 gtk_file_selection_hide_fileop_buttons(
|
|
|
82 GTK_FILE_SELECTION(plugin_dialog));
|
|
|
83
|
|
|
84 if(getenv("PLUGIN_DIR") == NULL) {
|
|
|
85 g_snprintf(buf, BUF_LEN - 1, "%s/%s", getenv("HOME"), PLUGIN_DIR);
|
|
|
86 } else {
|
|
|
87 g_snprintf(buf, BUF_LEN - 1, "%s/", getenv("PLUGIN_DIR"));
|
|
|
88 }
|
|
1
|
89
|
|
90
|
90 gtk_file_selection_set_filename(GTK_FILE_SELECTION(plugin_dialog), buf);
|
|
|
91 gtk_signal_connect(GTK_OBJECT(plugin_dialog), "destroy",
|
|
|
92 GTK_SIGNAL_FUNC(destroy_plugins), plugin_dialog);
|
|
|
93
|
|
|
94 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(plugin_dialog)->ok_button),
|
|
|
95 "clicked", GTK_SIGNAL_FUNC(load_which_plugin), NULL);
|
|
|
96
|
|
|
97 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(plugin_dialog)->cancel_button),
|
|
|
98 "clicked", GTK_SIGNAL_FUNC(destroy_plugins), NULL);
|
|
|
99
|
|
|
100 }
|
|
|
101
|
|
|
102 g_free(buf);
|
|
|
103 gtk_widget_show(plugin_dialog);
|
|
|
104 gdk_window_raise(plugin_dialog->window);
|
|
|
105 }
|
|
1
|
106
|
|
90
|
107 void load_which_plugin(GtkWidget *w, gpointer data) {
|
|
|
108 struct gaim_plugin *plug;
|
|
|
109 void (*gaim_plugin_init)();
|
|
|
110 char *(*cfunc)();
|
|
|
111 int (*nfunc)();
|
|
|
112 char *error;
|
|
|
113
|
|
|
114 plug = g_malloc(sizeof *plug);
|
|
|
115 plug->filename = gtk_file_selection_get_filename(
|
|
|
116 GTK_FILE_SELECTION(plugin_dialog));
|
|
|
117 /* do NOT OR with RTLD_GLOBAL, otherwise plugins may conflict
|
|
|
118 * (it's really just a way to work around other people's bad
|
|
|
119 * programming, by not using RTLD_GLOBAL :P ) */
|
|
|
120 plug->handle = dlopen(plug->filename, RTLD_LAZY);
|
|
|
121 if (!plug->handle) {
|
|
|
122 error = dlerror();
|
|
|
123 do_error_dialog(error, "Plugin Error");
|
|
|
124 g_free(plug);
|
|
|
125 return;
|
|
|
126 }
|
|
|
127
|
|
|
128 if (plugin_dialog)
|
|
|
129 gtk_widget_destroy(plugin_dialog);
|
|
|
130 plugin_dialog = NULL;
|
|
1
|
131
|
|
90
|
132 gaim_plugin_init = dlsym(plug->handle, "gaim_plugin_init");
|
|
|
133 if ((error = dlerror()) != NULL) {
|
|
|
134 do_error_dialog(error, "Plugin Error");
|
|
|
135 dlclose(plug->handle);
|
|
|
136 g_free(plug);
|
|
|
137 return;
|
|
|
138 }
|
|
|
139
|
|
|
140 plugins = g_list_append(plugins, plug);
|
|
|
141 (*gaim_plugin_init)();
|
|
1
|
142
|
|
90
|
143 cfunc = dlsym(plug->handle, "name");
|
|
|
144 if ((error = dlerror()) == NULL)
|
|
|
145 plug->name = (*cfunc)();
|
|
|
146 else
|
|
|
147 plug->name = NULL;
|
|
1
|
148
|
|
90
|
149 cfunc = dlsym(plug->handle, "description");
|
|
|
150 if ((error = dlerror()) == NULL)
|
|
|
151 plug->description = (*cfunc)();
|
|
|
152 else
|
|
|
153 plug->description = NULL;
|
|
|
154 }
|
|
1
|
155
|
|
90
|
156 void unload_plugin(GtkWidget *w, gpointer data) {
|
|
|
157 /* FIXME */
|
|
1
|
158 }
|
|
|
159
|
|
90
|
160 void show_plugins(GtkWidget *w, gpointer data) {
|
|
|
161 /* most of this code was shamelessly stolen from prefs.c */
|
|
|
162 GtkWidget *window;
|
|
|
163 GtkWidget *page;
|
|
|
164 GtkWidget *topbox;
|
|
|
165 GtkWidget *botbox;
|
|
|
166 GtkWidget *sw;
|
|
|
167 GtkWidget *label;
|
|
|
168 GtkWidget *list_item;
|
|
|
169 GtkWidget *sw2;
|
|
|
170 GtkWidget *add;
|
|
|
171 GtkWidget *remove;
|
|
|
172 GList *plugs = plugins;
|
|
|
173 struct gaim_plugin *p;
|
|
|
174 gchar buffer[1024];
|
|
|
175
|
|
|
176 window = gtk_window_new(GTK_WINDOW_DIALOG);
|
|
|
177 gtk_widget_realize(window);
|
|
|
178 aol_icon(window->window);
|
|
|
179 gtk_container_border_width(GTK_CONTAINER(window), 10);
|
|
|
180 gtk_window_set_title(GTK_WINDOW(window), "Gaim - Plugins");
|
|
|
181
|
|
|
182 page = gtk_vbox_new(FALSE, 0);
|
|
|
183 topbox = gtk_hbox_new(FALSE, 0);
|
|
|
184 botbox = gtk_hbox_new(FALSE, 0);
|
|
|
185
|
|
|
186 sw2 = gtk_scrolled_window_new(NULL, NULL);
|
|
|
187 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw2),
|
|
|
188 GTK_POLICY_AUTOMATIC,
|
|
|
189 GTK_POLICY_AUTOMATIC);
|
|
|
190
|
|
|
191 pluglist = gtk_list_new();
|
|
|
192 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), pluglist);
|
|
|
193 gtk_box_pack_start(GTK_BOX(topbox), sw2, TRUE, TRUE, 0);
|
|
|
194
|
|
|
195 sw = gtk_scrolled_window_new(NULL, NULL);
|
|
|
196 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
|
|
|
197 GTK_POLICY_AUTOMATIC,
|
|
|
198 GTK_POLICY_AUTOMATIC);
|
|
|
199
|
|
|
200 plugtext = gtk_text_new(NULL, NULL);
|
|
|
201 gtk_container_add(GTK_CONTAINER(sw), plugtext);
|
|
|
202 gtk_box_pack_start(GTK_BOX(topbox), sw, TRUE, TRUE, 0);
|
|
|
203 gtk_text_set_word_wrap(GTK_TEXT(plugtext), TRUE);
|
|
|
204 gtk_text_set_editable(GTK_TEXT(plugtext), FALSE);
|
|
|
205
|
|
|
206 add = gtk_button_new_with_label("Load Plugin");
|
|
|
207 gtk_signal_connect(GTK_OBJECT(add), "clicked",
|
|
|
208 GTK_SIGNAL_FUNC(load_plugin), NULL);
|
|
|
209 gtk_box_pack_start(GTK_BOX(botbox), add, TRUE, FALSE, 5);
|
|
|
210
|
|
|
211 remove = gtk_button_new_with_label("Unload Plugin");
|
|
|
212 gtk_signal_connect(GTK_OBJECT(remove), "clicked",
|
|
|
213 GTK_SIGNAL_FUNC(unload), pluglist);
|
|
|
214 gtk_box_pack_start(GTK_BOX(botbox), remove, TRUE, FALSE, 5);
|
|
|
215
|
|
|
216 gtk_box_pack_start(GTK_BOX(page), topbox, TRUE, TRUE, 0);
|
|
|
217 gtk_box_pack_start(GTK_BOX(page), botbox, FALSE, FALSE, 0);
|
|
|
218
|
|
|
219 if (plugs != NULL) {
|
|
|
220 p = (struct gaim_plugin *)plugs->data;
|
|
|
221 g_snprintf(buffer, sizeof(buffer), "%s", p->filename);
|
|
|
222 gtk_text_insert(GTK_TEXT(plugtext), NULL, NULL, NULL, buffer, -1);
|
|
|
223 }
|
|
|
224
|
|
|
225 while (plugs) {
|
|
|
226 p = (struct gaim_plugin *)plugs->data;
|
|
|
227 label = gtk_label_new(p->filename);
|
|
|
228 list_item = gtk_list_item_new();
|
|
|
229 gtk_container_add(GTK_CONTAINER(list_item), label);
|
|
|
230 gtk_signal_connect(GTK_OBJECT(list_item), "select",
|
|
|
231 GTK_SIGNAL_FUNC(list_clicked), p);
|
|
|
232 gtk_object_set_user_data(GTK_OBJECT(list_item), p);
|
|
|
233
|
|
|
234 gtk_widget_show(label);
|
|
|
235 gtk_container_add(GTK_CONTAINER(pluglist), list_item);
|
|
|
236 gtk_widget_show(list_item);
|
|
|
237
|
|
|
238 plugs = plugs->next;
|
|
|
239 }
|
|
|
240
|
|
|
241 gtk_widget_show(page);
|
|
|
242 gtk_widget_show(topbox);
|
|
|
243 gtk_widget_show(botbox);
|
|
|
244 gtk_widget_show(sw);
|
|
|
245 gtk_widget_show(sw2);
|
|
|
246 gtk_widget_show(pluglist);
|
|
|
247 gtk_widget_show(plugtext);
|
|
|
248 gtk_widget_show(add);
|
|
|
249 gtk_widget_show(remove);
|
|
|
250
|
|
|
251 gtk_container_add(GTK_CONTAINER(window), page);
|
|
|
252 gtk_widget_show(window);
|
|
1
|
253 }
|
|
|
254
|
|
90
|
255 void unload(GtkWidget *w, gpointer data) {
|
|
|
256 GList *i;
|
|
|
257 struct gaim_plugin *p;
|
|
|
258 void (*gaim_plugin_remove)();
|
|
|
259 char *error;
|
|
|
260
|
|
|
261 i = GTK_LIST(pluglist)->selection;
|
|
|
262
|
|
|
263 p = gtk_object_get_user_data(GTK_OBJECT(i->data));
|
|
|
264
|
|
|
265 g_list_remove(plugins, p);
|
|
1
|
266
|
|
90
|
267 gaim_plugin_remove = dlsym(p->handle, "gaim_plugin_remove");
|
|
|
268 if ((error = dlerror()) == NULL)
|
|
|
269 (*gaim_plugin_remove)();
|
|
|
270 dlclose(p->handle);
|
|
|
271 g_free(p);
|
|
|
272 }
|
|
|
273
|
|
|
274 void list_clicked(GtkWidget *w, struct gaim_plugin *p) {
|
|
|
275 gchar buffer[2048];
|
|
|
276 guint text_len;
|
|
|
277
|
|
|
278 text_len = gtk_text_get_length(GTK_TEXT(plugtext));
|
|
|
279 gtk_text_set_point(GTK_TEXT(plugtext), 0);
|
|
|
280 gtk_text_forward_delete(GTK_TEXT(plugtext), text_len);
|
|
|
281
|
|
|
282 g_snprintf(buffer, sizeof buffer, "%s\n%s", p->name, p->description);
|
|
|
283 gtk_text_insert(GTK_TEXT(plugtext), NULL, NULL, NULL, buffer, -1);
|
|
|
284 }
|
|
|
285
|
|
|
286 #endif /* GAIM_PLUGINS */
|