comparison src/plugins.c @ 92:f3c6cf79f651

[gaim-migrate @ 102] Loading/unloading plugins works correctly. I have to add "hooks" to the rest of gaim now to do certain things. Other than that, it's all good. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 07 Apr 2000 22:48:58 +0000
parents f5b305c0d974
children 9f6ce50ffb78
comparison
equal deleted inserted replaced
91:308d0896d979 92:f3c6cf79f651
49 static GtkWidget *plugin_dialog = NULL; 49 static GtkWidget *plugin_dialog = NULL;
50 static GList *plugins = NULL; 50 static GList *plugins = NULL;
51 51
52 static GtkWidget *pluglist; 52 static GtkWidget *pluglist;
53 static GtkWidget *plugtext; 53 static GtkWidget *plugtext;
54 static GtkWidget *plugwindow;
54 55
55 /* --------------- Function Declarations -------------------- */ 56 /* --------------- Function Declarations -------------------- */
56 57
57 void load_plugin (GtkWidget *, gpointer); 58 void load_plugin (GtkWidget *, gpointer);
58 void unload_plugin(GtkWidget *, gpointer); 59 void unload_plugin(GtkWidget *, gpointer);
60 61
61 static void destroy_plugins (GtkWidget *, gpointer); 62 static void destroy_plugins (GtkWidget *, gpointer);
62 static void load_which_plugin(GtkWidget *, gpointer); 63 static void load_which_plugin(GtkWidget *, gpointer);
63 static void unload (GtkWidget *, gpointer); 64 static void unload (GtkWidget *, gpointer);
64 static void list_clicked (GtkWidget *, struct gaim_plugin *); 65 static void list_clicked (GtkWidget *, struct gaim_plugin *);
66 static void update_show_plugins();
67 static void hide_plugins (GtkWidget *, gpointer);
65 68
66 /* ------------------ Code Below ---------------------------- */ 69 /* ------------------ Code Below ---------------------------- */
67 70
68 static void destroy_plugins(GtkWidget *w, gpointer data) { 71 static void destroy_plugins(GtkWidget *w, gpointer data) {
69 if (plugin_dialog) 72 if (plugin_dialog)
106 109
107 void load_which_plugin(GtkWidget *w, gpointer data) { 110 void load_which_plugin(GtkWidget *w, gpointer data) {
108 struct gaim_plugin *plug; 111 struct gaim_plugin *plug;
109 void (*gaim_plugin_init)(); 112 void (*gaim_plugin_init)();
110 char *(*cfunc)(); 113 char *(*cfunc)();
111 int (*nfunc)();
112 char *error; 114 char *error;
113 115
114 plug = g_malloc(sizeof *plug); 116 plug = g_malloc(sizeof *plug);
115 plug->filename = gtk_file_selection_get_filename( 117 plug->filename = g_strdup(gtk_file_selection_get_filename(
116 GTK_FILE_SELECTION(plugin_dialog)); 118 GTK_FILE_SELECTION(plugin_dialog)));
117 /* do NOT OR with RTLD_GLOBAL, otherwise plugins may conflict 119 /* do NOT OR with RTLD_GLOBAL, otherwise plugins may conflict
118 * (it's really just a way to work around other people's bad 120 * (it's really just a way to work around other people's bad
119 * programming, by not using RTLD_GLOBAL :P ) */ 121 * programming, by not using RTLD_GLOBAL :P ) */
120 plug->handle = dlopen(plug->filename, RTLD_LAZY); 122 plug->handle = dlopen(plug->filename, RTLD_LAZY);
121 if (!plug->handle) { 123 if (!plug->handle) {
149 cfunc = dlsym(plug->handle, "description"); 151 cfunc = dlsym(plug->handle, "description");
150 if ((error = dlerror()) == NULL) 152 if ((error = dlerror()) == NULL)
151 plug->description = (*cfunc)(); 153 plug->description = (*cfunc)();
152 else 154 else
153 plug->description = NULL; 155 plug->description = NULL;
156
157 update_show_plugins();
154 } 158 }
155 159
156 void unload_plugin(GtkWidget *w, gpointer data) { 160 void unload_plugin(GtkWidget *w, gpointer data) {
157 /* FIXME */ 161 /* FIXME */
158 } 162 }
159 163
160 void show_plugins(GtkWidget *w, gpointer data) { 164 void show_plugins(GtkWidget *w, gpointer data) {
161 /* most of this code was shamelessly stolen from prefs.c */ 165 /* most of this code was shamelessly stolen from prefs.c */
162 GtkWidget *window;
163 GtkWidget *page; 166 GtkWidget *page;
164 GtkWidget *topbox; 167 GtkWidget *topbox;
165 GtkWidget *botbox; 168 GtkWidget *botbox;
166 GtkWidget *sw; 169 GtkWidget *sw;
167 GtkWidget *label; 170 GtkWidget *label;
171 GtkWidget *remove; 174 GtkWidget *remove;
172 GList *plugs = plugins; 175 GList *plugs = plugins;
173 struct gaim_plugin *p; 176 struct gaim_plugin *p;
174 gchar buffer[1024]; 177 gchar buffer[1024];
175 178
176 window = gtk_window_new(GTK_WINDOW_DIALOG); 179 if (plugwindow) return;
177 gtk_widget_realize(window); 180
178 aol_icon(window->window); 181 plugwindow = gtk_window_new(GTK_WINDOW_DIALOG);
179 gtk_container_border_width(GTK_CONTAINER(window), 10); 182 gtk_widget_realize(plugwindow);
180 gtk_window_set_title(GTK_WINDOW(window), "Gaim - Plugins"); 183 aol_icon(plugwindow->window);
184 gtk_container_border_width(GTK_CONTAINER(plugwindow), 10);
185 gtk_window_set_title(GTK_WINDOW(plugwindow), "Gaim - Plugins");
186 gtk_widget_set_usize(plugwindow, 400, 250);
187 gtk_signal_connect(GTK_OBJECT(plugwindow), "destroy",
188 GTK_SIGNAL_FUNC(hide_plugins), NULL);
181 189
182 page = gtk_vbox_new(FALSE, 0); 190 page = gtk_vbox_new(FALSE, 0);
183 topbox = gtk_hbox_new(FALSE, 0); 191 topbox = gtk_hbox_new(FALSE, 0);
184 botbox = gtk_hbox_new(FALSE, 0); 192 botbox = gtk_hbox_new(FALSE, 0);
185 193
235 gtk_container_add(GTK_CONTAINER(pluglist), list_item); 243 gtk_container_add(GTK_CONTAINER(pluglist), list_item);
236 gtk_widget_show(list_item); 244 gtk_widget_show(list_item);
237 245
238 plugs = plugs->next; 246 plugs = plugs->next;
239 } 247 }
248 if (plugins != NULL)
249 gtk_list_select_item(GTK_LIST(pluglist), 0);
240 250
241 gtk_widget_show(page); 251 gtk_widget_show(page);
242 gtk_widget_show(topbox); 252 gtk_widget_show(topbox);
243 gtk_widget_show(botbox); 253 gtk_widget_show(botbox);
244 gtk_widget_show(sw); 254 gtk_widget_show(sw);
246 gtk_widget_show(pluglist); 256 gtk_widget_show(pluglist);
247 gtk_widget_show(plugtext); 257 gtk_widget_show(plugtext);
248 gtk_widget_show(add); 258 gtk_widget_show(add);
249 gtk_widget_show(remove); 259 gtk_widget_show(remove);
250 260
251 gtk_container_add(GTK_CONTAINER(window), page); 261 gtk_container_add(GTK_CONTAINER(plugwindow), page);
252 gtk_widget_show(window); 262 gtk_widget_show(plugwindow);
263 }
264
265 void update_show_plugins() {
266 GList *plugs = plugins;
267 struct gaim_plugin *p;
268 GtkWidget *label;
269 GtkWidget *list_item;
270
271 if (pluglist == NULL) return;
272
273 gtk_list_clear_items(GTK_LIST(pluglist), 0, -1);
274 while (plugs) {
275 p = (struct gaim_plugin *)plugs->data;
276 label = gtk_label_new(p->filename);
277 list_item = gtk_list_item_new();
278 gtk_container_add(GTK_CONTAINER(list_item), label);
279 gtk_signal_connect(GTK_OBJECT(list_item), "select",
280 GTK_SIGNAL_FUNC(list_clicked), p);
281 gtk_object_set_user_data(GTK_OBJECT(list_item), p);
282
283 gtk_widget_show(label);
284 gtk_container_add(GTK_CONTAINER(pluglist), list_item);
285 gtk_widget_show(list_item);
286 plugs = plugs->next;
287 }
288 if (plugins != NULL)
289 gtk_list_select_item(GTK_LIST(pluglist), 0);
290 else {
291 gtk_text_set_point(GTK_TEXT(plugtext), 0);
292 gtk_text_forward_delete(GTK_TEXT(plugtext),
293 gtk_text_get_length(GTK_TEXT(plugtext)));
294 }
253 } 295 }
254 296
255 void unload(GtkWidget *w, gpointer data) { 297 void unload(GtkWidget *w, gpointer data) {
256 GList *i; 298 GList *i;
257 struct gaim_plugin *p; 299 struct gaim_plugin *p;
258 void (*gaim_plugin_remove)(); 300 void (*gaim_plugin_remove)();
259 char *error; 301 char *error;
260 302
261 i = GTK_LIST(pluglist)->selection; 303 i = GTK_LIST(pluglist)->selection;
262 304
305 if (i == NULL) return;
306
263 p = gtk_object_get_user_data(GTK_OBJECT(i->data)); 307 p = gtk_object_get_user_data(GTK_OBJECT(i->data));
264
265 g_list_remove(plugins, p);
266 308
267 gaim_plugin_remove = dlsym(p->handle, "gaim_plugin_remove"); 309 gaim_plugin_remove = dlsym(p->handle, "gaim_plugin_remove");
268 if ((error = dlerror()) == NULL) 310 if ((error = dlerror()) == NULL)
269 (*gaim_plugin_remove)(); 311 (*gaim_plugin_remove)();
270 dlclose(p->handle); 312 dlclose(p->handle);
313
314 plugins = g_list_remove(plugins, p);
271 g_free(p); 315 g_free(p);
316 update_show_plugins();
272 } 317 }
273 318
274 void list_clicked(GtkWidget *w, struct gaim_plugin *p) { 319 void list_clicked(GtkWidget *w, struct gaim_plugin *p) {
275 gchar buffer[2048]; 320 gchar buffer[2048];
276 guint text_len; 321 guint text_len;
281 326
282 g_snprintf(buffer, sizeof buffer, "%s\n%s", p->name, p->description); 327 g_snprintf(buffer, sizeof buffer, "%s\n%s", p->name, p->description);
283 gtk_text_insert(GTK_TEXT(plugtext), NULL, NULL, NULL, buffer, -1); 328 gtk_text_insert(GTK_TEXT(plugtext), NULL, NULL, NULL, buffer, -1);
284 } 329 }
285 330
331 void hide_plugins(GtkWidget *w, gpointer data) {
332 if (plugwindow)
333 gtk_widget_destroy(plugwindow);
334 plugwindow = NULL;
335 }
336
286 #endif /* GAIM_PLUGINS */ 337 #endif /* GAIM_PLUGINS */