31 #include "gnc-hooks.h" 33 static QofLogModule log_module = GNC_MOD_GUI;
35 static void gnc_plugin_manager_dispose (GObject *
object);
36 static void gnc_plugin_manager_finalize (GObject *
object);
37 static void gnc_plugin_manager_shutdown (gpointer dummy, gpointer dummy2);
45 GHashTable *plugins_table;
46 } GncPluginManagerPrivate;
48 G_DEFINE_TYPE(GncPluginManager, gnc_plugin_manager, G_TYPE_OBJECT)
57 static guint signals[LAST_SIGNAL] = { 0 };
58 static GncPluginManager *singleton = NULL;
63 if (singleton == NULL)
65 singleton = g_object_new (GNC_TYPE_PLUGIN_MANAGER,
67 gnc_hook_add_dangler (HOOK_SHUTDOWN,
68 gnc_plugin_manager_shutdown, NULL, NULL);
81 g_return_if_fail (GNC_IS_PLUGIN_MANAGER (manager));
82 g_return_if_fail (GNC_IS_PLUGIN (plugin));
84 index = g_list_index (manager->plugins, plugin);
89 manager->plugins = g_list_append (manager->plugins, plugin);
90 g_hash_table_insert (manager->plugins_table,
91 g_strdup( GNC_PLUGIN_GET_CLASS(plugin)->plugin_name ),
94 g_signal_emit (G_OBJECT (manager), signals[PLUGIN_ADDED], 0, plugin);
105 g_return_if_fail (GNC_IS_PLUGIN_MANAGER (manager));
106 g_return_if_fail (GNC_IS_PLUGIN (plugin));
108 index = g_list_index (manager->plugins, plugin);
113 manager->plugins = g_list_remove (manager->plugins, plugin);
114 g_hash_table_remove (manager->plugins_table,
115 GNC_PLUGIN_GET_CLASS(plugin)->plugin_name);
117 g_signal_emit (G_OBJECT (manager), signals[PLUGIN_REMOVED], 0, plugin);
119 LEAVE (
"removed %s from GncPluginManager",
121 g_object_unref (plugin);
127 g_return_val_if_fail (GNC_IS_PLUGIN_MANAGER (manager), NULL);
129 return g_list_copy (manager->plugins);
136 g_return_val_if_fail (GNC_IS_PLUGIN_MANAGER (manager), NULL);
137 g_return_val_if_fail (name != NULL, NULL);
139 return GNC_PLUGIN (g_hash_table_lookup (manager->plugins_table, name));
143 gnc_plugin_manager_class_init (GncPluginManagerClass *klass)
145 GObjectClass *object_class = G_OBJECT_CLASS (klass);
147 object_class->dispose = gnc_plugin_manager_dispose;
148 object_class->finalize = gnc_plugin_manager_finalize;
150 signals[PLUGIN_ADDED] = g_signal_new (
"plugin-added",
151 G_OBJECT_CLASS_TYPE (klass),
155 g_cclosure_marshal_VOID__OBJECT,
159 signals[PLUGIN_REMOVED] = g_signal_new (
"plugin-removed",
160 G_OBJECT_CLASS_TYPE (klass),
164 g_cclosure_marshal_VOID__OBJECT,
171 gnc_plugin_manager_init (GncPluginManager *manager)
173 manager->plugins_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
177 gnc_plugin_manager_dispose (GObject *
object)
179 GncPluginManager *manager = GNC_PLUGIN_MANAGER (
object);
181 g_return_if_fail (GNC_IS_PLUGIN_MANAGER (manager));
183 if (manager->plugins_table)
185 g_hash_table_destroy (manager->plugins_table);
186 manager->plugins_table = NULL;
188 g_list_foreach (manager->plugins, (GFunc)g_object_unref, NULL);
189 g_list_free (manager->plugins);
190 manager->plugins = NULL;
193 G_OBJECT_CLASS (gnc_plugin_manager_parent_class)->dispose (
object);
197 gnc_plugin_manager_finalize (GObject *
object)
199 g_return_if_fail (GNC_IS_PLUGIN_MANAGER (
object));
201 G_OBJECT_CLASS (gnc_plugin_manager_parent_class)->finalize (
object);
205 gnc_plugin_manager_shutdown (gpointer dummy, gpointer dummy2)
207 if (singleton != NULL)
209 g_object_unref(singleton);
Plugin management functions for the GnuCash UI.
void gnc_plugin_manager_add_plugin(GncPluginManager *manager, GncPlugin *plugin)
Add a plugin to the list maintained by the plugin manager.
#define ENTER(format, args...)
Print a function entry debugging message.
void gnc_plugin_manager_remove_plugin(GncPluginManager *manager, GncPlugin *plugin)
Remove a plugin from the list maintained by the plugin manager.
GncPluginManager * gnc_plugin_manager_get(void)
Retrieve a pointer to the plugin manager.
All type declarations for the whole Gnucash engine.
#define LEAVE(format, args...)
Print a function exit debugging message.
GList * gnc_plugin_manager_get_plugins(GncPluginManager *manager)
Get a list of all plugins being held by the plugin manager.
GncPlugin * gnc_plugin_manager_get_plugin(GncPluginManager *manager, const gchar *name)
Find a plugin by name from the list of plugins being held by the plugin manager.