31 #include "gnc-hooks.h"
37 static void gnc_plugin_manager_dispose (GObject *
object);
38 static void gnc_plugin_manager_finalize (GObject *
object);
39 static void gnc_plugin_manager_shutdown (gpointer dummy, gpointer dummy2);
44 GHashTable *plugins_table;
47 #define GNC_PLUGIN_MANAGER_GET_PRIVATE(o) \
48 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_MANAGER, GncPluginManagerPrivate))
57 static guint signals[LAST_SIGNAL] = { 0 };
60 static GObjectClass *parent_class = NULL;
65 static GType gnc_plugin_manager_type = 0;
67 if (gnc_plugin_manager_type == 0)
69 static const GTypeInfo our_info =
74 (GClassInitFunc) gnc_plugin_manager_class_init,
79 (GInstanceInitFunc) gnc_plugin_manager_init
82 gnc_plugin_manager_type = g_type_register_static (G_TYPE_OBJECT,
87 return gnc_plugin_manager_type;
93 if (singleton == NULL)
95 singleton = g_object_new (GNC_TYPE_PLUGIN_MANAGER,
97 gnc_hook_add_dangler (HOOK_UI_SHUTDOWN,
98 gnc_plugin_manager_shutdown, NULL);
112 g_return_if_fail (GNC_IS_PLUGIN_MANAGER (manager));
113 g_return_if_fail (GNC_IS_PLUGIN (plugin));
115 priv = GNC_PLUGIN_MANAGER_GET_PRIVATE(manager);
116 index = g_list_index (priv->plugins, plugin);
121 priv->plugins = g_list_append (priv->plugins, plugin);
122 g_hash_table_insert (priv->plugins_table,
123 g_strdup( GNC_PLUGIN_GET_CLASS(plugin)->plugin_name ),
126 g_signal_emit (G_OBJECT (manager), signals[PLUGIN_ADDED], 0, plugin);
138 g_return_if_fail (GNC_IS_PLUGIN_MANAGER (manager));
139 g_return_if_fail (GNC_IS_PLUGIN (plugin));
141 priv = GNC_PLUGIN_MANAGER_GET_PRIVATE(manager);
142 index = g_list_index (priv->plugins, plugin);
147 priv->plugins = g_list_remove (priv->plugins, plugin);
148 g_hash_table_remove (priv->plugins_table,
149 GNC_PLUGIN_GET_CLASS(plugin)->plugin_name);
151 g_signal_emit (G_OBJECT (manager), signals[PLUGIN_REMOVED], 0, plugin);
153 LEAVE (
"removed %s from GncPluginManager",
155 g_object_unref (plugin);
163 g_return_val_if_fail (GNC_IS_PLUGIN_MANAGER (manager), NULL);
165 priv = GNC_PLUGIN_MANAGER_GET_PRIVATE(manager);
166 return g_list_copy (priv->plugins);
175 g_return_val_if_fail (GNC_IS_PLUGIN_MANAGER (manager), NULL);
176 g_return_val_if_fail (name != NULL, NULL);
178 priv = GNC_PLUGIN_MANAGER_GET_PRIVATE(manager);
179 return GNC_PLUGIN (g_hash_table_lookup (priv->plugins_table, name));
186 GObjectClass *object_class = G_OBJECT_CLASS (klass);
188 parent_class = g_type_class_peek_parent (klass);
190 object_class->dispose = gnc_plugin_manager_dispose;
191 object_class->finalize = gnc_plugin_manager_finalize;
195 signals[PLUGIN_ADDED] = g_signal_new (
"plugin-added",
196 G_OBJECT_CLASS_TYPE (klass),
200 g_cclosure_marshal_VOID__OBJECT,
204 signals[PLUGIN_REMOVED] = g_signal_new (
"plugin-removed",
205 G_OBJECT_CLASS_TYPE (klass),
209 g_cclosure_marshal_VOID__OBJECT,
220 priv = GNC_PLUGIN_MANAGER_GET_PRIVATE(manager);
221 priv->plugins_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
225 gnc_plugin_manager_dispose (GObject *
object)
230 g_return_if_fail (GNC_IS_PLUGIN_MANAGER (manager));
232 priv = GNC_PLUGIN_MANAGER_GET_PRIVATE(manager);
233 if (priv->plugins_table)
235 g_hash_table_destroy (priv->plugins_table);
236 priv->plugins_table = NULL;
238 g_list_foreach (priv->plugins, (GFunc)g_object_unref, NULL);
239 g_list_free (priv->plugins);
240 priv->plugins = NULL;
243 G_OBJECT_CLASS (parent_class)->dispose (
object);
247 gnc_plugin_manager_finalize (GObject *
object)
249 g_return_if_fail (GNC_IS_PLUGIN_MANAGER (
object));
251 G_OBJECT_CLASS (parent_class)->finalize (
object);
255 gnc_plugin_manager_shutdown (gpointer dummy, gpointer dummy2)
257 if (singleton != NULL)
259 g_object_unref(singleton);
Plugin management functions for the GnuCash UI.
void gnc_plugin_manager_add_plugin(GncPluginManager *manager, GncPlugin *plugin)
#define ENTER(format, args...)
void gnc_plugin_manager_remove_plugin(GncPluginManager *manager, GncPlugin *plugin)
GType gnc_plugin_manager_get_type(void)
GncPluginManager * gnc_plugin_manager_get(void)
All type declarations for the whole Gnucash engine.
#define LEAVE(format, args...)
GList * gnc_plugin_manager_get_plugins(GncPluginManager *manager)
GncPlugin * gnc_plugin_manager_get_plugin(GncPluginManager *manager, const gchar *name)
const gchar * QofLogModule