/*
- * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
return type;
}
-void gis_plugin_expose(GisPlugin *self)
+const gchar *gis_plugin_get_name(GisPlugin *self)
{
- g_return_if_fail(GIS_IS_PLUGIN(self));
- GIS_PLUGIN_GET_INTERFACE(self)->expose(self);
+ if (!GIS_IS_PLUGIN(self))
+ return NULL;
+ return GIS_PLUGIN_GET_INTERFACE(self)->name;
+}
+
+const gchar *gis_plugin_get_description(GisPlugin *self)
+{
+ if (!GIS_IS_PLUGIN(self))
+ return NULL;
+ return GIS_PLUGIN_GET_INTERFACE(self)->description;
}
GtkWidget *gis_plugin_get_config(GisPlugin *self)
{
- g_return_val_if_fail(GIS_IS_PLUGIN(self), NULL);
+ if (!GIS_IS_PLUGIN(self))
+ return NULL;
GisPluginInterface *iface = GIS_PLUGIN_GET_INTERFACE(self);
- return iface->get_config ? iface->get_config (self) : NULL;
+ return iface->get_config ? iface->get_config(self) : NULL;
}
GisPlugin *plugin;
} GisPluginStore;
-GisPlugins *gis_plugins_new(gchar *dir)
+GisPlugins *gis_plugins_new(const gchar *dir, GisPrefs *prefs)
{
g_debug("GisPlugins: new - dir=%s", dir);
- GisPlugins *plugins = g_new0(GisPlugins, 1);
+ GisPlugins *self = g_new0(GisPlugins, 1);
+ self->prefs = prefs;
if (dir)
- plugins->dir = g_strdup(dir);
- plugins->plugins = g_ptr_array_new();
- return plugins;
+ self->dir = g_strdup(dir);
+ return self;
}
void gis_plugins_free(GisPlugins *self)
{
g_debug("GisPlugins: free");
- for (int i = 0; i < self->plugins->len; i++) {
- GisPluginStore *store = g_ptr_array_index(self->plugins, i);
+ for (GList *cur = self->plugins; cur; cur = cur->next) {
+ GisPluginStore *store = cur->data;
+ g_debug("GisPlugin: freeing %s refs=%d->%d", store->name,
+ G_OBJECT(store->plugin)->ref_count,
+ G_OBJECT(store->plugin)->ref_count-1);
g_object_unref(store->plugin);
g_free(store->name);
g_free(store);
- g_ptr_array_remove_index(self->plugins, i);
}
- g_ptr_array_free(self->plugins, TRUE);
+ g_list_free(self->plugins);
if (self->dir)
g_free(self->dir);
g_free(self);
gchar *dirs[] = {self->dir, PLUGINSDIR};
g_debug("pluginsdir=%s", PLUGINSDIR);
for (int i = 0; i<2; i++) {
+ if (dirs[i] == NULL)
+ continue;
GDir *dir = g_dir_open(dirs[i], 0, NULL);
if (dir == NULL)
continue;
GisPluginStore *store = g_new0(GisPluginStore, 1);
store->name = g_strdup(name);
store->plugin = constructor(viewer, prefs);
- g_ptr_array_add(self->plugins, store);
+ self->plugins = g_list_prepend(self->plugins, store);
return store->plugin;
}
+GisPlugin *gis_plugins_enable(GisPlugins *self, const char *name,
+ GisViewer *viewer, GisPrefs *prefs)
+{
+ GisPlugin *plugin = gis_plugins_load(self, name, viewer, prefs);
+ gis_prefs_set_boolean_v(self->prefs, "plugins", name, TRUE);
+ return plugin;
+}
+
+GList *gis_plugins_load_enabled(GisPlugins *self,
+ GisViewer *viewer, GisPrefs *prefs)
+{
+ GList *loaded = NULL;
+ for (GList *cur = gis_plugins_available(self); cur; cur = cur->next) {
+ gchar *name = cur->data;
+ if (gis_prefs_get_boolean_v(self->prefs, "plugins", name, NULL)) {
+ GisPlugin *plugin = gis_plugins_load(self, name, viewer, prefs);
+ loaded = g_list_prepend(loaded, plugin);
+ }
+ }
+ return loaded;
+}
+
gboolean gis_plugins_unload(GisPlugins *self, const char *name)
{
g_debug("GisPlugins: unload %s", name);
- for (int i = 0; i < self->plugins->len; i++) {
- GisPluginStore *store = g_ptr_array_index(self->plugins, i);
+ for (GList *cur = self->plugins; cur; cur = cur->next) {
+ GisPluginStore *store = cur->data;
if (g_str_equal(store->name, name)) {
g_object_unref(store->plugin);
g_free(store->name);
g_free(store);
- g_ptr_array_remove_index(self->plugins, i);
+ self->plugins = g_list_delete_link(self->plugins, cur);
}
}
return FALSE;
}
+
+gboolean gis_plugins_disable(GisPlugins *self, const char *name)
+{
+ gis_prefs_set_boolean_v(self->prefs, "plugins", name, FALSE);
+ gis_plugins_unload(self, name);
+ return FALSE;
+}
+
void gis_plugins_foreach(GisPlugins *self, GCallback _callback, gpointer user_data)
{
g_debug("GisPlugins: foreach");
return;
typedef void (*CBFunc)(GisPlugin *, const gchar *, gpointer);
CBFunc callback = (CBFunc)_callback;
- for (int i = 0; i < self->plugins->len; i++) {
- GisPluginStore *store = g_ptr_array_index(self->plugins, i);
+ for (GList *cur = self->plugins; cur; cur = cur->next) {
+ GisPluginStore *store = cur->data;
callback(store->plugin, store->name, user_data);
}
}