refactor: Switch to CallsPluginManager

This commit is contained in:
Evangelos Ribeiro Tzaras
2023-05-15 10:08:55 +02:00
parent 37b208f040
commit d3e42c93cd
9 changed files with 371 additions and 589 deletions

View File

@@ -187,72 +187,6 @@ calls_provider_get_origins (CallsProvider *self)
return CALLS_PROVIDER_GET_CLASS (self)->get_origins (self);
}
/**
* calls_provider_load_plugin:
* @name: The name of the provider plugin to load
*
* Get a #CallsProvider plugin by name
*
* Returns: (transfer full): A #CallsProvider
*/
CallsProvider *
calls_provider_load_plugin (const char *name)
{
g_autoptr (GError) error = NULL;
PeasEngine *plugins;
PeasPluginInfo *info;
PeasExtension *extension;
plugins = peas_engine_get_default ();
// Find the plugin
info = peas_engine_get_plugin_info (plugins, name);
if (!info) {
g_debug ("Could not find plugin `%s'", name);
return NULL;
}
// Possibly load the plugin
if (!peas_plugin_info_is_loaded (info)) {
peas_engine_load_plugin (plugins, info);
if (!peas_plugin_info_is_available (info, &error)) {
g_debug ("Error loading plugin `%s': %s", name, error->message);
return NULL;
}
g_debug ("Loaded plugin `%s'", name);
}
// Check the plugin provides CallsProvider
if (!peas_engine_provides_extension (plugins, info, CALLS_TYPE_PROVIDER)) {
g_debug ("Plugin `%s' does not have a provider extension", name);
return NULL;
}
// Get the extension
extension = peas_engine_create_extensionv (plugins, info, CALLS_TYPE_PROVIDER, 0, NULL);
if (!extension) {
g_debug ("Could not create provider from plugin `%s'", name);
return NULL;
}
g_debug ("Created provider from plugin `%s'", name);
return CALLS_PROVIDER (extension);
}
void
calls_provider_unload_plugin (const char *name)
{
PeasEngine *engine = peas_engine_get_default ();
PeasPluginInfo *plugin = peas_engine_get_plugin_info (engine, name);
if (plugin)
peas_engine_unload_plugin (engine, plugin);
else
g_warning ("Can't unload plugin: No plugin with name %s found", name);
}
/**
* calls_provider_get_protocols:
* @self: A #CallsProvider