comparison src/plugin.c @ 6486:fab81e4b885c

[gaim-migrate @ 7000] Added support for plugin dependencis. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 18 Aug 2003 01:37:17 +0000
parents 70d5122bc3ff
children 96c5630f8d1d
comparison
equal deleted inserted replaced
6485:70d5122bc3ff 6486:fab81e4b885c
232 232
233 gboolean 233 gboolean
234 gaim_plugin_load(GaimPlugin *plugin) 234 gaim_plugin_load(GaimPlugin *plugin)
235 { 235 {
236 #ifdef GAIM_PLUGINS 236 #ifdef GAIM_PLUGINS
237 GList *dep_list = NULL;
238 GList *l;
239
237 g_return_val_if_fail(plugin != NULL, FALSE); 240 g_return_val_if_fail(plugin != NULL, FALSE);
238 g_return_val_if_fail(plugin->error == NULL, FALSE); 241 g_return_val_if_fail(plugin->error == NULL, FALSE);
239 242
240 if (gaim_plugin_is_loaded(plugin)) 243 if (gaim_plugin_is_loaded(plugin))
241 return TRUE; 244 return TRUE;
245
246 /*
247 * Go through the list of the plugin's dependencies.
248 *
249 * First pass: Make sure all the plugins needed are probed.
250 */
251 for (l = plugin->info->dependencies; l != NULL; l = l->next)
252 {
253 const char *dep_name = (const char *)l->data;
254 GaimPlugin *dep_plugin;
255
256 dep_plugin = gaim_plugins_find_with_id(dep_name);
257
258 if (dep_plugin == NULL)
259 {
260 char buf[BUFSIZ];
261
262 g_snprintf(buf, sizeof(buf),
263 _("The required plugin %s was not found. "
264 "Please install this plugin and try again."),
265 dep_name);
266
267 gaim_notify_error(NULL, NULL,
268 _("Gaim was unable to load your plugin."),
269 buf);
270
271 if (dep_list != NULL)
272 g_list_free(dep_list);
273
274 return FALSE;
275 }
276
277 dep_list = g_list_append(dep_list, dep_plugin);
278 }
279
280 /* Second pass: load all the required plugins. */
281 for (l = dep_list; l != NULL; l = l->next)
282 {
283 GaimPlugin *dep_plugin = (GaimPlugin *)l->data;
284
285 if (!gaim_plugin_is_loaded(dep_plugin))
286 {
287 if (!gaim_plugin_load(dep_plugin))
288 {
289 char buf[BUFSIZ];
290
291 g_snprintf(buf, sizeof(buf),
292 _("The required plugin %s was unable to load."),
293 plugin->info->name);
294
295 gaim_notify_error(NULL, NULL,
296 _("Gaim was unable to load your plugin."),
297 buf);
298
299 if (dep_list != NULL)
300 g_list_free(dep_list);
301
302 return FALSE;
303 }
304 }
305 }
306
307 if (dep_list != NULL)
308 g_list_free(dep_list);
242 309
243 if (plugin->native_plugin) { 310 if (plugin->native_plugin) {
244 if (plugin->info != NULL) { 311 if (plugin->info != NULL) {
245 if (plugin->info->load != NULL) 312 if (plugin->info->load != NULL)
246 plugin->info->load(plugin); 313 plugin->info->load(plugin);
701 GaimPlugin *plugin; 768 GaimPlugin *plugin;
702 GList *l; 769 GList *l;
703 770
704 g_return_val_if_fail(id != NULL, NULL); 771 g_return_val_if_fail(id != NULL, NULL);
705 772
706 for (l = plugins; l != NULL; l = l->next) { 773 for (l = plugins; l != NULL; l = l->next)
774 {
707 plugin = l->data; 775 plugin = l->data;
708 776
709 if (!strcmp(plugin->info->id, id)) 777 if (plugin->info->id != NULL && !strcmp(plugin->info->id, id))
710 return plugin; 778 return plugin;
711 } 779 }
712 780
713 return NULL; 781 return NULL;
714 } 782 }