changeset 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 f90b022235fe
children 01be71085964
files src/gaim.h src/gaimrc.c src/plugins.c
diffstat 3 files changed, 74 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/gaim.h	Wed Apr 19 22:36:38 2000 +0000
+++ b/src/gaim.h	Thu Apr 20 00:12:58 2000 +0000
@@ -150,6 +150,7 @@
 	void *data;
 };
 
+extern GList *plugins;
 extern GList *callbacks;
 #endif
 
@@ -295,7 +296,7 @@
 #define TYPE_SIGNOFF   4
 #define TYPE_KEEPALIVE 5
 
-#define REVISION "gaim:$Revision: 149 $"
+#define REVISION "gaim:$Revision: 152 $"
 #define FLAPON "FLAPON\r\n\r\n"
 
 #define ROAST "Tic/Toc"
@@ -569,6 +570,7 @@
 #ifdef GAIM_PLUGINS
 /* Functions in plugins.c */
 extern void show_plugins(GtkWidget *, gpointer);
+extern void load_plugin (char *);
 extern void gaim_signal_connect(void *, enum gaim_event, void *, void *);
 extern void gaim_signal_disconnect(void *, enum gaim_event, void *);
 #endif
--- a/src/gaimrc.c	Wed Apr 19 22:36:38 2000 +0000
+++ b/src/gaimrc.c	Thu Apr 20 00:12:58 2000 +0000
@@ -143,6 +143,8 @@
 		return 1;
 	} else if (!strcmp(tag, "away")) {
 		return 2;
+	} else if (!strcmp(tag, "plugins")) {
+		return 3;
 	}
 
 	return -1;
@@ -232,8 +234,54 @@
 	fprintf(f, "}\n");
 }
 
+#ifdef GAIM_PLUGINS
+static void gaimrc_write_plugins(FILE *f)
+{
+	GList *pl = plugins;
+	struct gaim_plugin *p;
 
+	fprintf(f, "plugins {\n");
 
+	while (pl) {
+		char *path;
+
+		p = (struct gaim_plugin *)pl->data;
+
+		path = escape_text2(p->filename);
+
+		fprintf(f, "\tplugin { %s }\n", path);
+
+		free(path);
+
+		pl = pl->next;
+	}
+
+	fprintf(f, "}\n");
+}
+
+static void gaimrc_read_plugins(FILE *f)
+{
+	struct parse *p;
+	char buf[4096];
+
+	buf[0] = 0;
+	
+	while (buf[0] != '}')
+	{
+		if (!fgets(buf, sizeof(buf), f))
+			return;
+		
+		if (buf[0] == '}')
+			return;
+
+		p = parse_line(buf);
+		if (!strcmp(p->option, "plugin"))
+		{
+			load_plugin(p->value[0]);
+		}
+	}
+}
+#endif /* GAIM_PLUGINS */
 
 static struct aim_user *gaimrc_read_user(FILE *f)
 {
@@ -520,6 +568,11 @@
                                 case 2:
                                         gaimrc_read_away(f);
                                         break;
+#ifdef GAIM_PLUGINS
+				case 3:
+					gaimrc_read_plugins(f);
+					break;
+#endif
 				default:
 					/* NOOP */
 					break;
@@ -543,6 +596,9 @@
 			gaimrc_write_users(f);
                         gaimrc_write_options(f);
                         gaimrc_write_away(f);
+#ifdef GAIM_PLUGINS
+			gaimrc_write_plugins(f);
+#endif
                         fclose(f);
                         chmod(buf, S_IRUSR | S_IWUSR);
                 }
--- a/src/plugins.c	Wed Apr 19 22:36:38 2000 +0000
+++ b/src/plugins.c	Thu Apr 20 00:12:58 2000 +0000
@@ -46,12 +46,12 @@
 
 /* ------------------ Global Variables ----------------------- */
 
+GList *plugins   = NULL;
 GList *callbacks = NULL;
 
 /* ------------------ Local Variables ------------------------ */
 
 static GtkWidget *plugin_dialog = NULL;
-static GList     *plugins = NULL;
 
 static GtkWidget *pluglist;
 static GtkWidget *plugtext;
@@ -62,12 +62,13 @@
 /* --------------- Function Declarations --------------------- */
 
        void show_plugins (GtkWidget *, gpointer);
+       void load_plugin  (char *);
 
        void gaim_signal_connect   (void *, enum gaim_event, void *, void *);
        void gaim_signal_disconnect(void *, enum gaim_event, void *);
 
 static void destroy_plugins  (GtkWidget *, gpointer);
-static void load_plugin  (GtkWidget *, gpointer);
+static void load_file        (GtkWidget *, gpointer);
 static void load_which_plugin(GtkWidget *, gpointer);
 static void unload           (GtkWidget *, gpointer);
 static void list_clicked     (GtkWidget *, struct gaim_plugin *);
@@ -82,7 +83,7 @@
 	plugin_dialog = NULL;
 }
 
-static void load_plugin(GtkWidget *w, gpointer data)
+static void load_file(GtkWidget *w, gpointer data)
 {
 	char *buf = g_malloc(BUF_LEN);
  
@@ -120,14 +121,22 @@
 }
 
 static void load_which_plugin(GtkWidget *w, gpointer data) {
+	load_plugin(gtk_file_selection_get_filename(
+					GTK_FILE_SELECTION(plugin_dialog)));
+
+	if (plugin_dialog)
+		gtk_widget_destroy(plugin_dialog);
+	plugin_dialog = NULL;
+}
+
+void load_plugin(char *filename) {
 	struct gaim_plugin *plug;
 	void (*gaim_plugin_init)();
 	char *(*cfunc)();
 	char *error;
 
 	plug = g_malloc(sizeof *plug);
-	plug->filename = g_strdup(gtk_file_selection_get_filename(
-					GTK_FILE_SELECTION(plugin_dialog)));
+	plug->filename = g_strdup(filename);
 	/* do NOT OR with RTLD_GLOBAL, otherwise plugins may conflict
 	 * (it's really just a way to work around other people's bad
 	 * programming, by not using RTLD_GLOBAL :P ) */
@@ -139,10 +148,6 @@
 		return;
 	}
 
-	if (plugin_dialog)
-		gtk_widget_destroy(plugin_dialog);
-	plugin_dialog = NULL;
-
 	gaim_plugin_init = dlsym(plug->handle, "gaim_plugin_init");
 	if ((error = (char *)dlerror()) != NULL) {
 		do_error_dialog(error, "Plugin Error");
@@ -222,7 +227,7 @@
 
 	add = gtk_button_new_with_label("Load Plugin");
 	gtk_signal_connect(GTK_OBJECT(add), "clicked",
-			   GTK_SIGNAL_FUNC(load_plugin), NULL);
+			   GTK_SIGNAL_FUNC(load_file), NULL);
 	gtk_box_pack_start(GTK_BOX(botbox), add, TRUE, FALSE, 5);
 
 	config = gtk_button_new_with_label("Configure Plugin");