comparison src/plugins.c @ 142:fbabd28795d2

[gaim-migrate @ 152] Added auto-load for plugins. Rob pointed out this might be a bad idea: what if plugins modify the buddy list; the plugins are loaded before signon, thus before the buddy list appears. That would cause errors; then when the list does appear, the plugin doesn't work right because it didn't start off well. My response: EWarmenhoven: there are ways around that EWarmenhoven: in gaim_plugin_init you could have: EWarmenhoven: if (blist) { do_the_normal_thing(); } else { gaim_signal_connect(handle, event_signon, now_the_buddy_list_is_here, NULL); } EWarmenhoven: and actually, that's the way it should be for all plugins that modify the buddy list, because there will be at least one point during execution that it could be loaded when the person is signed off (and i'm not talking about when they first start it up, i'm talking about when they choose 'sign off' instead of 'close' in the buddy list menu) committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 20 Apr 2000 00:12:58 +0000
parents c009c4f4ad02
children 8ed64c704fb0
comparison
equal deleted inserted replaced
141:f90b022235fe 142:fbabd28795d2
44 44
45 #include <dlfcn.h> 45 #include <dlfcn.h>
46 46
47 /* ------------------ Global Variables ----------------------- */ 47 /* ------------------ Global Variables ----------------------- */
48 48
49 GList *plugins = NULL;
49 GList *callbacks = NULL; 50 GList *callbacks = NULL;
50 51
51 /* ------------------ Local Variables ------------------------ */ 52 /* ------------------ Local Variables ------------------------ */
52 53
53 static GtkWidget *plugin_dialog = NULL; 54 static GtkWidget *plugin_dialog = NULL;
54 static GList *plugins = NULL;
55 55
56 static GtkWidget *pluglist; 56 static GtkWidget *pluglist;
57 static GtkWidget *plugtext; 57 static GtkWidget *plugtext;
58 static GtkWidget *plugwindow; 58 static GtkWidget *plugwindow;
59 59
60 static GtkWidget *config; 60 static GtkWidget *config;
61 61
62 /* --------------- Function Declarations --------------------- */ 62 /* --------------- Function Declarations --------------------- */
63 63
64 void show_plugins (GtkWidget *, gpointer); 64 void show_plugins (GtkWidget *, gpointer);
65 void load_plugin (char *);
65 66
66 void gaim_signal_connect (void *, enum gaim_event, void *, void *); 67 void gaim_signal_connect (void *, enum gaim_event, void *, void *);
67 void gaim_signal_disconnect(void *, enum gaim_event, void *); 68 void gaim_signal_disconnect(void *, enum gaim_event, void *);
68 69
69 static void destroy_plugins (GtkWidget *, gpointer); 70 static void destroy_plugins (GtkWidget *, gpointer);
70 static void load_plugin (GtkWidget *, gpointer); 71 static void load_file (GtkWidget *, gpointer);
71 static void load_which_plugin(GtkWidget *, gpointer); 72 static void load_which_plugin(GtkWidget *, gpointer);
72 static void unload (GtkWidget *, gpointer); 73 static void unload (GtkWidget *, gpointer);
73 static void list_clicked (GtkWidget *, struct gaim_plugin *); 74 static void list_clicked (GtkWidget *, struct gaim_plugin *);
74 static void update_show_plugins(); 75 static void update_show_plugins();
75 static void hide_plugins (GtkWidget *, gpointer); 76 static void hide_plugins (GtkWidget *, gpointer);
80 if (plugin_dialog) 81 if (plugin_dialog)
81 gtk_widget_destroy(plugin_dialog); 82 gtk_widget_destroy(plugin_dialog);
82 plugin_dialog = NULL; 83 plugin_dialog = NULL;
83 } 84 }
84 85
85 static void load_plugin(GtkWidget *w, gpointer data) 86 static void load_file(GtkWidget *w, gpointer data)
86 { 87 {
87 char *buf = g_malloc(BUF_LEN); 88 char *buf = g_malloc(BUF_LEN);
88 89
89 if (plugin_dialog) { 90 if (plugin_dialog) {
90 g_free(buf); 91 g_free(buf);
118 gtk_widget_show(plugin_dialog); 119 gtk_widget_show(plugin_dialog);
119 gdk_window_raise(plugin_dialog->window); 120 gdk_window_raise(plugin_dialog->window);
120 } 121 }
121 122
122 static void load_which_plugin(GtkWidget *w, gpointer data) { 123 static void load_which_plugin(GtkWidget *w, gpointer data) {
124 load_plugin(gtk_file_selection_get_filename(
125 GTK_FILE_SELECTION(plugin_dialog)));
126
127 if (plugin_dialog)
128 gtk_widget_destroy(plugin_dialog);
129 plugin_dialog = NULL;
130 }
131
132 void load_plugin(char *filename) {
123 struct gaim_plugin *plug; 133 struct gaim_plugin *plug;
124 void (*gaim_plugin_init)(); 134 void (*gaim_plugin_init)();
125 char *(*cfunc)(); 135 char *(*cfunc)();
126 char *error; 136 char *error;
127 137
128 plug = g_malloc(sizeof *plug); 138 plug = g_malloc(sizeof *plug);
129 plug->filename = g_strdup(gtk_file_selection_get_filename( 139 plug->filename = g_strdup(filename);
130 GTK_FILE_SELECTION(plugin_dialog)));
131 /* do NOT OR with RTLD_GLOBAL, otherwise plugins may conflict 140 /* do NOT OR with RTLD_GLOBAL, otherwise plugins may conflict
132 * (it's really just a way to work around other people's bad 141 * (it's really just a way to work around other people's bad
133 * programming, by not using RTLD_GLOBAL :P ) */ 142 * programming, by not using RTLD_GLOBAL :P ) */
134 plug->handle = dlopen(plug->filename, RTLD_LAZY); 143 plug->handle = dlopen(plug->filename, RTLD_LAZY);
135 if (!plug->handle) { 144 if (!plug->handle) {
136 error = (char *)dlerror(); 145 error = (char *)dlerror();
137 do_error_dialog(error, "Plugin Error"); 146 do_error_dialog(error, "Plugin Error");
138 g_free(plug); 147 g_free(plug);
139 return; 148 return;
140 } 149 }
141
142 if (plugin_dialog)
143 gtk_widget_destroy(plugin_dialog);
144 plugin_dialog = NULL;
145 150
146 gaim_plugin_init = dlsym(plug->handle, "gaim_plugin_init"); 151 gaim_plugin_init = dlsym(plug->handle, "gaim_plugin_init");
147 if ((error = (char *)dlerror()) != NULL) { 152 if ((error = (char *)dlerror()) != NULL) {
148 do_error_dialog(error, "Plugin Error"); 153 do_error_dialog(error, "Plugin Error");
149 dlclose(plug->handle); 154 dlclose(plug->handle);
220 gtk_text_set_word_wrap(GTK_TEXT(plugtext), TRUE); 225 gtk_text_set_word_wrap(GTK_TEXT(plugtext), TRUE);
221 gtk_text_set_editable(GTK_TEXT(plugtext), FALSE); 226 gtk_text_set_editable(GTK_TEXT(plugtext), FALSE);
222 227
223 add = gtk_button_new_with_label("Load Plugin"); 228 add = gtk_button_new_with_label("Load Plugin");
224 gtk_signal_connect(GTK_OBJECT(add), "clicked", 229 gtk_signal_connect(GTK_OBJECT(add), "clicked",
225 GTK_SIGNAL_FUNC(load_plugin), NULL); 230 GTK_SIGNAL_FUNC(load_file), NULL);
226 gtk_box_pack_start(GTK_BOX(botbox), add, TRUE, FALSE, 5); 231 gtk_box_pack_start(GTK_BOX(botbox), add, TRUE, FALSE, 5);
227 232
228 config = gtk_button_new_with_label("Configure Plugin"); 233 config = gtk_button_new_with_label("Configure Plugin");
229 gtk_widget_set_sensitive(config, 0); 234 gtk_widget_set_sensitive(config, 0);
230 gtk_box_pack_start(GTK_BOX(botbox), config, TRUE, FALSE, 5); 235 gtk_box_pack_start(GTK_BOX(botbox), config, TRUE, FALSE, 5);