comparison src/plugins.c @ 943:446d7d2cc909

[gaim-migrate @ 953] cleanups from kylev committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 03 Oct 2000 19:12:54 +0000
parents 2876c40108cd
children 2f64424bf319
comparison
equal deleted inserted replaced
942:e77eb4277d7c 943:446d7d2cc909
89 plugin_dialog = NULL; 89 plugin_dialog = NULL;
90 } 90 }
91 91
92 static void load_file(GtkWidget *w, gpointer data) 92 static void load_file(GtkWidget *w, gpointer data)
93 { 93 {
94 char *buf = g_malloc(BUF_LEN); 94 gchar *buf;
95 FILE *fd; 95 FILE *fd;
96 96
97 if (plugin_dialog) { 97 if (plugin_dialog) {
98 g_free(buf);
99 gtk_widget_show(plugin_dialog); 98 gtk_widget_show(plugin_dialog);
100 gdk_window_raise(plugin_dialog->window); 99 gdk_window_raise(plugin_dialog->window);
101 return; 100 return;
102 } 101 }
103 102
104 plugin_dialog = gtk_file_selection_new(_("Gaim - Plugin List")); 103 plugin_dialog = gtk_file_selection_new(_("Gaim - Plugin List"));
105 104
106 gtk_file_selection_hide_fileop_buttons( 105 gtk_file_selection_hide_fileop_buttons(
107 GTK_FILE_SELECTION(plugin_dialog)); 106 GTK_FILE_SELECTION(plugin_dialog));
108 107
109 g_snprintf(buf, BUF_LEN - 1, "%s/%s", getenv("HOME"), PLUGIN_DIR); 108 buf = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, PLUGIN_DIR, NULL);
110 fd = fopen(buf, "r"); 109 fd = fopen(buf, "r");
111 if (!fd) 110 if (!fd)
112 mkdir(buf, S_IRUSR | S_IWUSR | S_IXUSR); 111 mkdir(buf, S_IRUSR | S_IWUSR | S_IXUSR);
113 else 112 else
114 fclose(fd); 113 fclose(fd);
156 sprintf(debug_buff, _("Already loaded %s, " 155 sprintf(debug_buff, _("Already loaded %s, "
157 "not reloading.\n"), filename); 156 "not reloading.\n"), filename);
158 debug_print(debug_buff); 157 debug_print(debug_buff);
159 return; 158 return;
160 } 159 }
161 c = c->next; 160 c = g_list_next(c);
162 } 161 }
163 plug = g_malloc(sizeof *plug); 162 plug = g_malloc(sizeof *plug);
164 if (filename[0] != '/') { 163 if (filename[0] != '/')
165 char *buf = g_malloc(BUF_LEN); 164 plug->filename = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S,
166 g_snprintf(buf, BUF_LEN - 1, "%s/%s", getenv("HOME"), PLUGIN_DIR); 165 PLUGIN_DIR, filename, NULL);
167 plug->filename = g_malloc(strlen(buf) + strlen(filename) + 1); 166 else
168 sprintf(plug->filename, "%s%s", buf, filename);
169 g_free(buf);
170 } else
171 plug->filename = g_strdup(filename); 167 plug->filename = g_strdup(filename);
168
172 sprintf(debug_buff, "Loading %s\n", filename); 169 sprintf(debug_buff, "Loading %s\n", filename);
173 debug_print(debug_buff); 170 debug_print(debug_buff);
174 /* do NOT `OR' with RTLD_GLOBAL, otherwise plugins may conflict 171 /* do NOT `OR' with RTLD_GLOBAL, otherwise plugins may conflict
175 * (it's really just a way to work around other people's bad 172 * (it's really just a way to work around other people's bad
176 * programming, by not using RTLD_GLOBAL :P ) */ 173 * programming, by not using RTLD_GLOBAL :P ) */
208 c = callbacks; 205 c = callbacks;
209 if (c == NULL) { 206 if (c == NULL) {
210 break; 207 break;
211 } 208 }
212 } else { 209 } else {
213 c = c->next; 210 c = g_list_next(c);
214 } 211 }
215 } 212 }
216 gaim_plugin_error = dlsym(plug->handle, "gaim_plugin_error"); 213 gaim_plugin_error = dlsym(plug->handle, "gaim_plugin_error");
217 if ((error = (char *)dlerror()) == NULL) { 214 if ((error = (char *)dlerror()) == NULL) {
218 plugin_error = (*gaim_plugin_error)(retval); 215 plugin_error = (*gaim_plugin_error)(retval);
255 GtkWidget *add; 252 GtkWidget *add;
256 GtkWidget *remove; 253 GtkWidget *remove;
257 GtkWidget *close; 254 GtkWidget *close;
258 GList *plugs = plugins; 255 GList *plugs = plugins;
259 struct gaim_plugin *p; 256 struct gaim_plugin *p;
260 gchar buffer[1024];
261 257
262 if (plugwindow) return; 258 if (plugwindow) return;
263 259
264 plugwindow = gtk_window_new(GTK_WINDOW_DIALOG); 260 plugwindow = gtk_window_new(GTK_WINDOW_DIALOG);
265 gtk_window_set_wmclass(GTK_WINDOW(plugwindow), "plugins", "Gaim"); 261 gtk_window_set_wmclass(GTK_WINDOW(plugwindow), "plugins", "Gaim");
273 269
274 page = gtk_vbox_new(FALSE, 0); 270 page = gtk_vbox_new(FALSE, 0);
275 topbox = gtk_hbox_new(FALSE, 0); 271 topbox = gtk_hbox_new(FALSE, 0);
276 botbox = gtk_hbox_new(FALSE, 0); 272 botbox = gtk_hbox_new(FALSE, 0);
277 273
274 /* Left side: list of plugin file names */
278 sw2 = gtk_scrolled_window_new(NULL, NULL); 275 sw2 = gtk_scrolled_window_new(NULL, NULL);
279 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw2), 276 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw2),
280 GTK_POLICY_AUTOMATIC, 277 GTK_POLICY_AUTOMATIC,
281 GTK_POLICY_AUTOMATIC); 278 GTK_POLICY_AUTOMATIC);
282 279
283 pluglist = gtk_list_new(); 280 pluglist = gtk_list_new();
284 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), pluglist); 281 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw2), pluglist);
285 gtk_box_pack_start(GTK_BOX(topbox), sw2, TRUE, TRUE, 0); 282 gtk_box_pack_start(GTK_BOX(topbox), sw2, TRUE, TRUE, 0);
286 283
284 /* Right side: the text description of the plugin */
287 sw = gtk_scrolled_window_new(NULL, NULL); 285 sw = gtk_scrolled_window_new(NULL, NULL);
288 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), 286 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
289 GTK_POLICY_AUTOMATIC, 287 GTK_POLICY_AUTOMATIC,
290 GTK_POLICY_AUTOMATIC); 288 GTK_POLICY_AUTOMATIC);
291 289
293 gtk_container_add(GTK_CONTAINER(sw), plugtext); 291 gtk_container_add(GTK_CONTAINER(sw), plugtext);
294 gtk_box_pack_start(GTK_BOX(topbox), sw, TRUE, TRUE, 0); 292 gtk_box_pack_start(GTK_BOX(topbox), sw, TRUE, TRUE, 0);
295 gtk_text_set_word_wrap(GTK_TEXT(plugtext), TRUE); 293 gtk_text_set_word_wrap(GTK_TEXT(plugtext), TRUE);
296 gtk_text_set_editable(GTK_TEXT(plugtext), FALSE); 294 gtk_text_set_editable(GTK_TEXT(plugtext), FALSE);
297 295
296 /* Build the bottom button bar */
298 add = gtk_button_new_with_label(_("Load Plugin")); 297 add = gtk_button_new_with_label(_("Load Plugin"));
299 gtk_signal_connect(GTK_OBJECT(add), "clicked", 298 gtk_signal_connect(GTK_OBJECT(add), "clicked",
300 GTK_SIGNAL_FUNC(load_file), NULL); 299 GTK_SIGNAL_FUNC(load_file), NULL);
301 gtk_box_pack_start(GTK_BOX(botbox), add, TRUE, FALSE, 5); 300 gtk_box_pack_start(GTK_BOX(botbox), add, TRUE, FALSE, 5);
302 if (display_options & OPT_DISP_COOL_LOOK) 301 if (display_options & OPT_DISP_COOL_LOOK)
322 if (display_options & OPT_DISP_COOL_LOOK) 321 if (display_options & OPT_DISP_COOL_LOOK)
323 gtk_button_set_relief(GTK_BUTTON(close), GTK_RELIEF_NONE); 322 gtk_button_set_relief(GTK_BUTTON(close), GTK_RELIEF_NONE);
324 323
325 gtk_box_pack_start(GTK_BOX(page), topbox, TRUE, TRUE, 0); 324 gtk_box_pack_start(GTK_BOX(page), topbox, TRUE, TRUE, 0);
326 gtk_box_pack_start(GTK_BOX(page), botbox, FALSE, FALSE, 0); 325 gtk_box_pack_start(GTK_BOX(page), botbox, FALSE, FALSE, 0);
327
328 if (plugs != NULL) {
329 p = (struct gaim_plugin *)plugs->data;
330 g_snprintf(buffer, sizeof(buffer), "%s", p->filename);
331 gtk_text_insert(GTK_TEXT(plugtext), NULL, NULL, NULL, buffer, -1);
332 }
333 326
334 while (plugs) { 327 while (plugs) {
335 p = (struct gaim_plugin *)plugs->data; 328 p = (struct gaim_plugin *)plugs->data;
336 label = gtk_label_new(p->filename); 329 label = gtk_label_new(p->filename);
337 list_item = gtk_list_item_new(); 330 list_item = gtk_list_item_new();
342 335
343 gtk_widget_show(label); 336 gtk_widget_show(label);
344 gtk_container_add(GTK_CONTAINER(pluglist), list_item); 337 gtk_container_add(GTK_CONTAINER(pluglist), list_item);
345 gtk_widget_show(list_item); 338 gtk_widget_show(list_item);
346 339
347 plugs = plugs->next; 340 plugs = g_list_next(plugs);
348 } 341 }
342
343 /* Make the first item selected */
349 if (plugins != NULL) 344 if (plugins != NULL)
350 gtk_list_select_item(GTK_LIST(pluglist), 0); 345 gtk_list_select_item(GTK_LIST(pluglist), 0);
351 346
352 gtk_widget_show(page); 347 gtk_widget_show(page);
353 gtk_widget_show(topbox); 348 gtk_widget_show(topbox);
384 gtk_object_set_user_data(GTK_OBJECT(list_item), p); 379 gtk_object_set_user_data(GTK_OBJECT(list_item), p);
385 380
386 gtk_widget_show(label); 381 gtk_widget_show(label);
387 gtk_container_add(GTK_CONTAINER(pluglist), list_item); 382 gtk_container_add(GTK_CONTAINER(pluglist), list_item);
388 gtk_widget_show(list_item); 383 gtk_widget_show(list_item);
389 plugs = plugs->next; 384 plugs = g_list_next(plugs);
390 } 385 }
391 if (plugins != NULL) 386 if (plugins != NULL)
392 gtk_list_select_item(GTK_LIST(pluglist), 0); 387 gtk_list_select_item(GTK_LIST(pluglist), 0);
393 else { 388 else {
394 gtk_text_set_point(GTK_TEXT(plugtext), 0); 389 gtk_text_set_point(GTK_TEXT(plugtext), 0);
407 402
408 if (i == NULL) return; 403 if (i == NULL) return;
409 404
410 p = gtk_object_get_user_data(GTK_OBJECT(i->data)); 405 p = gtk_object_get_user_data(GTK_OBJECT(i->data));
411 406
407 /* Attempt to call the plugin's remove function (if there) */
412 gaim_plugin_remove = dlsym(p->handle, "gaim_plugin_remove"); 408 gaim_plugin_remove = dlsym(p->handle, "gaim_plugin_remove");
413 if ((error = (char *)dlerror()) == NULL) 409 if ((error = (char *)dlerror()) == NULL)
414 (*gaim_plugin_remove)(); 410 (*gaim_plugin_remove)();
415 411
416 gaim_plugin_unload(p->handle); 412 gaim_plugin_unload(p->handle);
434 while (i) { 430 while (i) {
435 p = (struct gaim_plugin *)i->data; 431 p = (struct gaim_plugin *)i->data;
436 if (handle == p->handle) 432 if (handle == p->handle)
437 break; 433 break;
438 p = NULL; 434 p = NULL;
439 i = i->next; 435 i = g_list_next(i);
440 } 436 }
441 437
442 if (!p) 438 if (!p)
443 return; 439 return;
444 440
445 sprintf(debug_buff, "Unloading %s\n", p->filename); 441 sprintf(debug_buff, "Unloading %s\n", p->filename);
446 debug_print(debug_buff); 442 debug_print(debug_buff);
447 443
448 sprintf(debug_buff, "%d callbacks to search\n", g_list_length(callbacks)); 444 sprintf(debug_buff, "%d callbacks to search\n", g_list_length(callbacks));
449 debug_print(debug_buff); 445 debug_print(debug_buff);
446
450 while (c) { 447 while (c) {
451 g = (struct gaim_callback *)c->data; 448 g = (struct gaim_callback *)c->data;
452 if (g->handle == p->handle) { 449 if (g->handle == p->handle) {
453 callbacks = g_list_remove(callbacks, c->data); 450 callbacks = g_list_remove(callbacks, c->data);
454 g_free(g); 451 g_free(g);
458 c = callbacks; 455 c = callbacks;
459 if (c == NULL) { 456 if (c == NULL) {
460 break; 457 break;
461 } 458 }
462 } else { 459 } else {
463 c = c->next; 460 c = g_list_next(c);
464 } 461 }
465 } 462 }
463 /* remove callbacks later (this will g_free p) */
466 p->remove = gtk_timeout_add(5000, (GtkFunction)remove_callback, p); 464 p->remove = gtk_timeout_add(5000, (GtkFunction)remove_callback, p);
467 465
468 plugins = g_list_remove(plugins, p); 466 plugins = g_list_remove(plugins, p);
469 g_free(p->filename); 467 g_free(p->filename);
470 if (config) gtk_widget_set_sensitive(config, 0); 468 if (config) gtk_widget_set_sensitive(config, 0);
471 update_show_plugins(); 469 update_show_plugins();
472 save_prefs(); 470 save_prefs();
473 } 471 }
474 472
475 void list_clicked(GtkWidget *w, struct gaim_plugin *p) { 473 void list_clicked(GtkWidget *w, struct gaim_plugin *p) {
476 gchar buffer[2048]; 474 gchar *temp;
477 guint text_len; 475 guint text_len;
478 void (*gaim_plugin_config)(); 476 void (*gaim_plugin_config)();
479 char *error; 477 char *error;
480 478
481 if (confighandle != 0) 479 if (confighandle != 0)
482 gtk_signal_disconnect(GTK_OBJECT(config), confighandle); 480 gtk_signal_disconnect(GTK_OBJECT(config), confighandle);
483 text_len = gtk_text_get_length(GTK_TEXT(plugtext)); 481 text_len = gtk_text_get_length(GTK_TEXT(plugtext));
484 gtk_text_set_point(GTK_TEXT(plugtext), 0); 482 gtk_text_set_point(GTK_TEXT(plugtext), 0);
485 gtk_text_forward_delete(GTK_TEXT(plugtext), text_len); 483 gtk_text_forward_delete(GTK_TEXT(plugtext), text_len);
486 484
487 g_snprintf(buffer, sizeof buffer, "%s\n%s", p->name, p->description); 485 temp = g_strdup_printf("%s\n%s", p->name, p->description);
488 gtk_text_insert(GTK_TEXT(plugtext), NULL, NULL, NULL, buffer, -1); 486 gtk_text_insert(GTK_TEXT(plugtext), NULL, NULL, NULL, temp, -1);
489 487 g_free(temp);
488
489 /* Find out if this plug-in has a configuration function */
490 gaim_plugin_config = dlsym(p->handle, "gaim_plugin_config"); 490 gaim_plugin_config = dlsym(p->handle, "gaim_plugin_config");
491 if ((error = (char *)dlerror()) == NULL) { 491 if ((error = (char *)dlerror()) == NULL) {
492 confighandle = gtk_signal_connect(GTK_OBJECT(config), "clicked", 492 confighandle = gtk_signal_connect(GTK_OBJECT(config), "clicked",
493 GTK_SIGNAL_FUNC(gaim_plugin_config), NULL); 493 GTK_SIGNAL_FUNC(gaim_plugin_config), NULL);
494 gtk_widget_set_sensitive(config, 1); 494 gtk_widget_set_sensitive(config, 1);
520 } 520 }
521 521
522 void gaim_signal_disconnect(void *handle, enum gaim_event which, void *func) { 522 void gaim_signal_disconnect(void *handle, enum gaim_event which, void *func) {
523 GList *c = callbacks; 523 GList *c = callbacks;
524 struct gaim_callback *g = NULL; 524 struct gaim_callback *g = NULL;
525
525 while (c) { 526 while (c) {
526 g = (struct gaim_callback *)c->data; 527 g = (struct gaim_callback *)c->data;
527 if (handle == g->handle && func == g->function) { 528 if (handle == g->handle && func == g->function) {
528 callbacks = g_list_remove(callbacks, c->data); 529 callbacks = g_list_remove(callbacks, c->data);
529 g_free(g); 530 g_free(g);
530 c = callbacks; 531 c = callbacks;
531 if (c == NULL) break; 532 if (c == NULL) break;
532 } 533 }
533 c = c->next; 534 c = g_list_next(c);
534 } 535 }
535 } 536 }
536 537
537 #endif /* GAIM_PLUGINS */ 538 #endif /* GAIM_PLUGINS */
538 539