Commit 99ad3568 authored by Chyla Zbigniew's avatar Chyla Zbigniew

Added support for plugin dependencies + some fixes.


Added support for plugin dependencies + some fixes.

* src/gutils.h (g_list_to_vector, g_vector_free_custom):
New macros. (used macros instead of functions to avoid casting and
pointer size problems - ANSI C doesn't guarantee that
sizeof (void *) == sizeof (something_else *).

* src/plugin-loader.c
(gnumeric_plugin_loader_load): Load required plugin dependencies
before the plugin itself, increment n_deps for every loaded
dependency (by calling plugin_dependencies_inc_dependants).
(gnumeric_plugin_loader_unload): New function.
(gnumeric_plugin_loader_load_service): Increment number of loaded
services if loaded succesfully.
(gnumeric_plugin_loader_unload_service): Decrement number of loaded
services if unloaded succesfully, unload plugin if it reaches zero.

* src/plugin-loader.h
(struct _GnumericPluginLoader): Added n_loaded_services.
(gnumeric_plugin_loader_unload): New function.

* src/plugin-service.c:
(plugin_service_file_opener_open_func,
plugin_service_file_saver_save_func):
Used gnumeric_io_error_occurred (and gnumeric_io_clear_error) when
checking for error.

* src/plugin.c:
(plugins_active_by_default): Array containing ids of "standard"
plugins. These will be active by default.
(struct _PluginDependency): New struct.
(struct _PluginInfo): Added dependencies_v, d_deps. Replaced
service_list with services_v (vector in place of list).
(plugin_info_get_config_prefix, plugin_dependency_get_plugin_info,
plugin_info_read_dependency_list, plugin_dependency_free,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_load_dependencies):
New functions.
(plugin_info_provides_loader_by_type_str, plugin_info_free):
Adjusted to service_list -> services_v change.
(plugin_info_read): Read (optional) dependencies, adjusted to
service_list -> services_v change.
(activate_plugin):
Activate required dependencies before the plugin itself.
Increment n_deps for every activated dependency (by calling
plugin_dependencies_inc_dependants).
Adjusted to service_list -> services_v change.
(deactivate_plugin):
Decrement n_deps for every activated dependency (by calling
plugin_dependencies_dec_dependants).
Adjusted to service_list -> services_v change.
(plugin_can_deactivate):
Return FALSE if any of n_deps > 0.
Adjusted to service_list -> services_v change.
(plugin_list_sort_by_dependency): Removed.
(plugin_db_activate_plugin_list): Removed sorting.
(plugin_db_init): Always activate new plugin if it's defined in
plugins_active_by_default array.

* src/plugin.h:
(PluginDependencyType): New enum.
(plugin_load_dependencies,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_info_get_config_prefix): New functions.
parent b0421f0d
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
Added support for plugin dependencies + some fixes.
* src/gutils.h (g_list_to_vector, g_vector_free_custom):
New macros. (used macros instead of functions to avoid casting and
pointer size problems - ANSI C doesn't guarantee that
sizeof (void *) == sizeof (something_else *).
* src/plugin-loader.c
(gnumeric_plugin_loader_load): Load required plugin dependencies
before the plugin itself, increment n_deps for every loaded
dependency (by calling plugin_dependencies_inc_dependants).
(gnumeric_plugin_loader_unload): New function.
(gnumeric_plugin_loader_load_service): Increment number of loaded
services if loaded succesfully.
(gnumeric_plugin_loader_unload_service): Decrement number of loaded
services if unloaded succesfully, unload plugin if it reaches zero.
* src/plugin-loader.h
(struct _GnumericPluginLoader): Added n_loaded_services.
(gnumeric_plugin_loader_unload): New function.
* src/plugin-service.c:
(plugin_service_file_opener_open_func,
plugin_service_file_saver_save_func):
Used gnumeric_io_error_occurred (and gnumeric_io_clear_error) when
checking for error.
* src/plugin.c:
(plugins_active_by_default): Array containing ids of "standard"
plugins. These will be active by default.
(struct _PluginDependency): New struct.
(struct _PluginInfo): Added dependencies_v, d_deps. Replaced
service_list with services_v (vector in place of list).
(plugin_info_get_config_prefix, plugin_dependency_get_plugin_info,
plugin_info_read_dependency_list, plugin_dependency_free,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_load_dependencies):
New functions.
(plugin_info_provides_loader_by_type_str, plugin_info_free):
Adjusted to service_list -> services_v change.
(plugin_info_read): Read (optional) dependencies, adjusted to
service_list -> services_v change.
(activate_plugin):
Activate required dependencies before the plugin itself.
Increment n_deps for every activated dependency (by calling
plugin_dependencies_inc_dependants).
Adjusted to service_list -> services_v change.
(deactivate_plugin):
Decrement n_deps for every activated dependency (by calling
plugin_dependencies_dec_dependants).
Adjusted to service_list -> services_v change.
(plugin_can_deactivate):
Return FALSE if any of n_deps > 0.
Adjusted to service_list -> services_v change.
(plugin_list_sort_by_dependency): Removed.
(plugin_db_activate_plugin_list): Removed sorting.
(plugin_db_init): Always activate new plugin if it's defined in
plugins_active_by_default array.
* src/plugin.h:
(PluginDependencyType): New enum.
(plugin_load_dependencies,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_info_get_config_prefix): New functions.
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
* src/io-context-priv.h:
......
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
Added support for plugin dependencies + some fixes.
* src/gutils.h (g_list_to_vector, g_vector_free_custom):
New macros. (used macros instead of functions to avoid casting and
pointer size problems - ANSI C doesn't guarantee that
sizeof (void *) == sizeof (something_else *).
* src/plugin-loader.c
(gnumeric_plugin_loader_load): Load required plugin dependencies
before the plugin itself, increment n_deps for every loaded
dependency (by calling plugin_dependencies_inc_dependants).
(gnumeric_plugin_loader_unload): New function.
(gnumeric_plugin_loader_load_service): Increment number of loaded
services if loaded succesfully.
(gnumeric_plugin_loader_unload_service): Decrement number of loaded
services if unloaded succesfully, unload plugin if it reaches zero.
* src/plugin-loader.h
(struct _GnumericPluginLoader): Added n_loaded_services.
(gnumeric_plugin_loader_unload): New function.
* src/plugin-service.c:
(plugin_service_file_opener_open_func,
plugin_service_file_saver_save_func):
Used gnumeric_io_error_occurred (and gnumeric_io_clear_error) when
checking for error.
* src/plugin.c:
(plugins_active_by_default): Array containing ids of "standard"
plugins. These will be active by default.
(struct _PluginDependency): New struct.
(struct _PluginInfo): Added dependencies_v, d_deps. Replaced
service_list with services_v (vector in place of list).
(plugin_info_get_config_prefix, plugin_dependency_get_plugin_info,
plugin_info_read_dependency_list, plugin_dependency_free,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_load_dependencies):
New functions.
(plugin_info_provides_loader_by_type_str, plugin_info_free):
Adjusted to service_list -> services_v change.
(plugin_info_read): Read (optional) dependencies, adjusted to
service_list -> services_v change.
(activate_plugin):
Activate required dependencies before the plugin itself.
Increment n_deps for every activated dependency (by calling
plugin_dependencies_inc_dependants).
Adjusted to service_list -> services_v change.
(deactivate_plugin):
Decrement n_deps for every activated dependency (by calling
plugin_dependencies_dec_dependants).
Adjusted to service_list -> services_v change.
(plugin_can_deactivate):
Return FALSE if any of n_deps > 0.
Adjusted to service_list -> services_v change.
(plugin_list_sort_by_dependency): Removed.
(plugin_db_activate_plugin_list): Removed sorting.
(plugin_db_init): Always activate new plugin if it's defined in
plugins_active_by_default array.
* src/plugin.h:
(PluginDependencyType): New enum.
(plugin_load_dependencies,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_info_get_config_prefix): New functions.
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
* src/io-context-priv.h:
......
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
Added support for plugin dependencies + some fixes.
* src/gutils.h (g_list_to_vector, g_vector_free_custom):
New macros. (used macros instead of functions to avoid casting and
pointer size problems - ANSI C doesn't guarantee that
sizeof (void *) == sizeof (something_else *).
* src/plugin-loader.c
(gnumeric_plugin_loader_load): Load required plugin dependencies
before the plugin itself, increment n_deps for every loaded
dependency (by calling plugin_dependencies_inc_dependants).
(gnumeric_plugin_loader_unload): New function.
(gnumeric_plugin_loader_load_service): Increment number of loaded
services if loaded succesfully.
(gnumeric_plugin_loader_unload_service): Decrement number of loaded
services if unloaded succesfully, unload plugin if it reaches zero.
* src/plugin-loader.h
(struct _GnumericPluginLoader): Added n_loaded_services.
(gnumeric_plugin_loader_unload): New function.
* src/plugin-service.c:
(plugin_service_file_opener_open_func,
plugin_service_file_saver_save_func):
Used gnumeric_io_error_occurred (and gnumeric_io_clear_error) when
checking for error.
* src/plugin.c:
(plugins_active_by_default): Array containing ids of "standard"
plugins. These will be active by default.
(struct _PluginDependency): New struct.
(struct _PluginInfo): Added dependencies_v, d_deps. Replaced
service_list with services_v (vector in place of list).
(plugin_info_get_config_prefix, plugin_dependency_get_plugin_info,
plugin_info_read_dependency_list, plugin_dependency_free,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_load_dependencies):
New functions.
(plugin_info_provides_loader_by_type_str, plugin_info_free):
Adjusted to service_list -> services_v change.
(plugin_info_read): Read (optional) dependencies, adjusted to
service_list -> services_v change.
(activate_plugin):
Activate required dependencies before the plugin itself.
Increment n_deps for every activated dependency (by calling
plugin_dependencies_inc_dependants).
Adjusted to service_list -> services_v change.
(deactivate_plugin):
Decrement n_deps for every activated dependency (by calling
plugin_dependencies_dec_dependants).
Adjusted to service_list -> services_v change.
(plugin_can_deactivate):
Return FALSE if any of n_deps > 0.
Adjusted to service_list -> services_v change.
(plugin_list_sort_by_dependency): Removed.
(plugin_db_activate_plugin_list): Removed sorting.
(plugin_db_init): Always activate new plugin if it's defined in
plugins_active_by_default array.
* src/plugin.h:
(PluginDependencyType): New enum.
(plugin_load_dependencies,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_info_get_config_prefix): New functions.
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
* src/io-context-priv.h:
......
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
Added support for plugin dependencies + some fixes.
* src/gutils.h (g_list_to_vector, g_vector_free_custom):
New macros. (used macros instead of functions to avoid casting and
pointer size problems - ANSI C doesn't guarantee that
sizeof (void *) == sizeof (something_else *).
* src/plugin-loader.c
(gnumeric_plugin_loader_load): Load required plugin dependencies
before the plugin itself, increment n_deps for every loaded
dependency (by calling plugin_dependencies_inc_dependants).
(gnumeric_plugin_loader_unload): New function.
(gnumeric_plugin_loader_load_service): Increment number of loaded
services if loaded succesfully.
(gnumeric_plugin_loader_unload_service): Decrement number of loaded
services if unloaded succesfully, unload plugin if it reaches zero.
* src/plugin-loader.h
(struct _GnumericPluginLoader): Added n_loaded_services.
(gnumeric_plugin_loader_unload): New function.
* src/plugin-service.c:
(plugin_service_file_opener_open_func,
plugin_service_file_saver_save_func):
Used gnumeric_io_error_occurred (and gnumeric_io_clear_error) when
checking for error.
* src/plugin.c:
(plugins_active_by_default): Array containing ids of "standard"
plugins. These will be active by default.
(struct _PluginDependency): New struct.
(struct _PluginInfo): Added dependencies_v, d_deps. Replaced
service_list with services_v (vector in place of list).
(plugin_info_get_config_prefix, plugin_dependency_get_plugin_info,
plugin_info_read_dependency_list, plugin_dependency_free,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_load_dependencies):
New functions.
(plugin_info_provides_loader_by_type_str, plugin_info_free):
Adjusted to service_list -> services_v change.
(plugin_info_read): Read (optional) dependencies, adjusted to
service_list -> services_v change.
(activate_plugin):
Activate required dependencies before the plugin itself.
Increment n_deps for every activated dependency (by calling
plugin_dependencies_inc_dependants).
Adjusted to service_list -> services_v change.
(deactivate_plugin):
Decrement n_deps for every activated dependency (by calling
plugin_dependencies_dec_dependants).
Adjusted to service_list -> services_v change.
(plugin_can_deactivate):
Return FALSE if any of n_deps > 0.
Adjusted to service_list -> services_v change.
(plugin_list_sort_by_dependency): Removed.
(plugin_db_activate_plugin_list): Removed sorting.
(plugin_db_init): Always activate new plugin if it's defined in
plugins_active_by_default array.
* src/plugin.h:
(PluginDependencyType): New enum.
(plugin_load_dependencies,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_info_get_config_prefix): New functions.
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
* src/io-context-priv.h:
......
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
Added support for plugin dependencies + some fixes.
* src/gutils.h (g_list_to_vector, g_vector_free_custom):
New macros. (used macros instead of functions to avoid casting and
pointer size problems - ANSI C doesn't guarantee that
sizeof (void *) == sizeof (something_else *).
* src/plugin-loader.c
(gnumeric_plugin_loader_load): Load required plugin dependencies
before the plugin itself, increment n_deps for every loaded
dependency (by calling plugin_dependencies_inc_dependants).
(gnumeric_plugin_loader_unload): New function.
(gnumeric_plugin_loader_load_service): Increment number of loaded
services if loaded succesfully.
(gnumeric_plugin_loader_unload_service): Decrement number of loaded
services if unloaded succesfully, unload plugin if it reaches zero.
* src/plugin-loader.h
(struct _GnumericPluginLoader): Added n_loaded_services.
(gnumeric_plugin_loader_unload): New function.
* src/plugin-service.c:
(plugin_service_file_opener_open_func,
plugin_service_file_saver_save_func):
Used gnumeric_io_error_occurred (and gnumeric_io_clear_error) when
checking for error.
* src/plugin.c:
(plugins_active_by_default): Array containing ids of "standard"
plugins. These will be active by default.
(struct _PluginDependency): New struct.
(struct _PluginInfo): Added dependencies_v, d_deps. Replaced
service_list with services_v (vector in place of list).
(plugin_info_get_config_prefix, plugin_dependency_get_plugin_info,
plugin_info_read_dependency_list, plugin_dependency_free,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_load_dependencies):
New functions.
(plugin_info_provides_loader_by_type_str, plugin_info_free):
Adjusted to service_list -> services_v change.
(plugin_info_read): Read (optional) dependencies, adjusted to
service_list -> services_v change.
(activate_plugin):
Activate required dependencies before the plugin itself.
Increment n_deps for every activated dependency (by calling
plugin_dependencies_inc_dependants).
Adjusted to service_list -> services_v change.
(deactivate_plugin):
Decrement n_deps for every activated dependency (by calling
plugin_dependencies_dec_dependants).
Adjusted to service_list -> services_v change.
(plugin_can_deactivate):
Return FALSE if any of n_deps > 0.
Adjusted to service_list -> services_v change.
(plugin_list_sort_by_dependency): Removed.
(plugin_db_activate_plugin_list): Removed sorting.
(plugin_db_init): Always activate new plugin if it's defined in
plugins_active_by_default array.
* src/plugin.h:
(PluginDependencyType): New enum.
(plugin_load_dependencies,
plugin_inc_dependants, plugin_dec_dependants,
plugin_dependencies_inc_dependants,
plugin_dependencies_dec_dependants,
plugin_info_get_config_prefix): New functions.
2001-03-20 Zbigniew Chyla <cyba@gnome.pl>
* src/io-context-priv.h:
......
......@@ -17,6 +17,26 @@ GList *g_create_list (gpointer item1, ...);
void g_list_free_custom (GList *list, GFreeFunc free_func);
GList *g_string_list_copy (GList *list);
GList *g_strsplit_to_list (const gchar *string, const gchar *delimiter);
#define g_list_to_vector(vector,elem_type,list_expr) \
G_STMT_START { \
GList *list, *l; \
gint size, i; \
list = (list_expr); \
size = g_list_length (list); \
(vector) = g_new (elem_type *, size + 1); \
for (l = list, i = 0; l != NULL; l = l->next, i++) \
(vector)[i] = (elem_type *) l->data; \
(vector)[size] = NULL; \
} G_STMT_END
#define g_vector_free_custom(vector_expr,elem_type,free_func_expr) \
G_STMT_START { \
elem_type **vector; \
GFreeFunc free_func; \
free_func = free_func_expr; \
for (vector = (vector_expr); *vector != NULL; vector++) \
free_func (*vector); \
g_free (vector); \
} G_STMT_END
void g_slist_free_custom (GSList *list, GFreeFunc free_func);
......
......@@ -40,6 +40,7 @@ gnumeric_plugin_loader_init (GnumericPluginLoader *loader)
loader->plugin = NULL;
loader->is_loaded = FALSE;
loader->n_loaded_services = 0;
}
static void
......@@ -196,14 +197,48 @@ gnumeric_plugin_loader_load (GnumericPluginLoader *loader, ErrorInfo **ret_error
if (loader->is_loaded) {
return;
}
gnumeric_plugin_loader_class = GNUMERIC_PLUGIN_LOADER_CLASS (GTK_OBJECT (loader)->klass);
g_return_if_fail (gnumeric_plugin_loader_class->load != NULL);
gnumeric_plugin_loader_class->load (loader, &error);
plugin_load_dependencies (loader->plugin, &error);
if (error == NULL) {
loader->is_loaded = TRUE;
PLUGIN_MESSAGE ("Loaded plugin \"%s\".\n", plugin_info_peek_id (loader->plugin));
gnumeric_plugin_loader_class = GNUMERIC_PLUGIN_LOADER_CLASS (GTK_OBJECT (loader)->klass);
g_return_if_fail (gnumeric_plugin_loader_class->load != NULL);
gnumeric_plugin_loader_class->load (loader, &error);
if (error == NULL) {
loader->is_loaded = TRUE;
plugin_dependencies_inc_dependants (loader->plugin, DEPENDENCY_LOAD);
PLUGIN_MESSAGE ("Loaded plugin \"%s\".\n", plugin_info_peek_id (loader->plugin));
} else {
*ret_error = error;
}
} else {
*ret_error = error;
*ret_error = error_info_new_str_with_details (
_("Error while loading plugin dependencies."),
error);
}
}
void
gnumeric_plugin_loader_unload (GnumericPluginLoader *loader, ErrorInfo **ret_error)
{
GnumericPluginLoaderClass *gnumeric_plugin_loader_class;
ErrorInfo *error;
g_return_if_fail (IS_GNUMERIC_PLUGIN_LOADER (loader));
g_return_if_fail (ret_error != NULL);
*ret_error = NULL;
if (!loader->is_loaded) {
return;
}
gnumeric_plugin_loader_class = GNUMERIC_PLUGIN_LOADER_CLASS (GTK_OBJECT (loader)->klass);
if (gnumeric_plugin_loader_class->unload != NULL) {
gnumeric_plugin_loader_class->unload (loader, &error);
if (error == NULL) {
loader->is_loaded = FALSE;
plugin_dependencies_dec_dependants (loader->plugin, DEPENDENCY_LOAD);
PLUGIN_MESSAGE ("Unloaded plugin \"%s\".\n", plugin_info_peek_id (loader->plugin));
} else {
*ret_error = error;
}
}
}
......@@ -254,6 +289,10 @@ gnumeric_plugin_loader_load_service (GnumericPluginLoader *loader, PluginService
_("Error while loading plugin."),
error);
}
if (*ret_error == NULL) {
loader->n_loaded_services++;
}
}
void
......@@ -296,7 +335,17 @@ gnumeric_plugin_loader_unload_service (GnumericPluginLoader *loader, PluginServi
*ret_error = error_info_new_str (
_("Service not supported by loader."));
}
*ret_error = error;
if (error == NULL) {
g_return_if_fail (loader->n_loaded_services > 0);
loader->n_loaded_services--;
if (loader->n_loaded_services == 0) {
gnumeric_plugin_loader_unload (loader, &error);
error_info_free (error);
}
} else {
*ret_error = error;
}
}
gint
......
......@@ -22,6 +22,7 @@ struct _GnumericPluginLoader {
PluginInfo *plugin;
gboolean is_loaded;
gint n_loaded_services;
};
struct _GnumericPluginLoaderClass {
......@@ -50,6 +51,7 @@ void gnumeric_plugin_loader_set_attributes (GnumericPluginLoader *loader,
ErrorInfo **ret_error);
void gnumeric_plugin_loader_set_plugin (GnumericPluginLoader *loader, PluginInfo *plugin);
void gnumeric_plugin_loader_load (GnumericPluginLoader *loader, ErrorInfo **ret_error);
void gnumeric_plugin_loader_unload (GnumericPluginLoader *loader, ErrorInfo **ret_error);
void gnumeric_plugin_loader_load_service (GnumericPluginLoader *loader, PluginService *service, ErrorInfo **ret_error);
void gnumeric_plugin_loader_unload_service (GnumericPluginLoader *loader, PluginService *service, ErrorInfo **ret_error);
gint gnumeric_plugin_loader_get_extra_info_list (GnumericPluginLoader *loader, GList **ret_keys_list, GList **ret_values_list);
......
......@@ -379,11 +379,13 @@ plugin_service_file_opener_open_func (FileOpener const *fo, IOContext *io_contex
if (error == NULL) {
g_return_val_if_fail (service_file_opener->plugin_func_file_open != NULL, FALSE);
service_file_opener->plugin_func_file_open (fo, service, io_context, wb_view, file_name);
if (gnumeric_io_has_error_info (io_context)) {
gnumeric_io_error_info_push (io_context, error_info_new_str (
_("Error while reading file.")));
gnumeric_io_error_info_display (io_context);
gnumeric_io_error_info_clear (io_context);
if (gnumeric_io_error_occurred (io_context)) {
if (gnumeric_io_has_error_info (io_context)) {
gnumeric_io_error_info_push (io_context, error_info_new_str (
_("Error while reading file.")));
gnumeric_io_error_info_display (io_context);
}
gnumeric_io_clear_error (io_context);
return FALSE;
} else {
if (service_file_opener->save_info != NULL) {
......@@ -551,11 +553,13 @@ plugin_service_file_saver_save_func (FileSaver const *fs, IOContext *io_context,
if (error == NULL) {
g_return_val_if_fail (service_file_saver->plugin_func_file_save != NULL, FALSE);
service_file_saver->plugin_func_file_save (fs, service, io_context, wb_view, file_name);
if (gnumeric_io_has_error_info (io_context)) {
gnumeric_io_error_info_push (io_context, error_info_new_str (
_("Error while saving file.")));
gnumeric_io_error_info_display (io_context);
gnumeric_io_error_info_clear (io_context);
if (gnumeric_io_error_occurred (io_context)) {
if (gnumeric_io_has_error_info (io_context)) {
gnumeric_io_error_info_push (io_context, error_info_new_str (
_("Error while saving file.")));
gnumeric_io_error_info_display (io_context);
}
gnumeric_io_clear_error (io_context);
return FALSE;
} else {
return TRUE;
......
......@@ -42,12 +42,21 @@
#define PLUGIN_INFO_FILE_NAME "plugin.xml"
static gchar *plugins_active_by_default[] = {"Gnumeric_Excel", NULL};
typedef struct _PluginLoaderStaticInfo PluginLoaderStaticInfo;
struct _PluginLoaderStaticInfo {
gchar *loader_type_str;
GList *attr_names, *attr_values;
};
typedef struct _PluginDependency PluginDependency;
struct _PluginDependency {
gchar *plugin_id;
PluginInfo *pinfo; /* don't use directly */
PluginDependencyType dep_type;
};
struct _PluginInfo {
gchar *dir_name;
gchar *id;
......@@ -55,9 +64,11 @@ struct _PluginInfo {
gchar *description;
gboolean is_active;
gint n_deps[DEPENDENCY_LAST];
PluginDependency **dependencies_v;
PluginLoaderStaticInfo *loader_static_info;
GnumericPluginLoader *loader;
GList *service_list;
PluginService **services_v;
PluginServicesData *services_data;
};
......@@ -121,6 +132,14 @@ plugin_info_get_description (PluginInfo *pinfo)
return g_strdup (pinfo->description);
}
gchar *
plugin_info_get_config_prefix (PluginInfo *pinfo)
{
g_return_val_if_fail (pinfo != NULL, NULL);
return g_strdup_printf ("Gnumeric/Plugins-%s", pinfo->id);
}
gboolean
plugin_info_is_active (PluginInfo *pinfo)
{
......@@ -192,17 +211,14 @@ plugin_info_peek_loader_type_str (PluginInfo *pinfo)
gboolean
plugin_info_provides_loader_by_type_str (PluginInfo *pinfo, const gchar *loader_type_str)
{
GList *l;
PluginService **service_ptr;
g_return_val_if_fail (pinfo != NULL, FALSE);
for (l = pinfo->service_list; l != NULL; l = l->next) {
PluginService *service;
service = (PluginService *) l->data;
if (service->service_type == PLUGIN_SERVICE_PLUGIN_LOADER &&
for (service_ptr = pinfo->services_v; *service_ptr != NULL; service_ptr++) {
if ((*service_ptr)->service_type == PLUGIN_SERVICE_PLUGIN_LOADER &&
(loader_type_str == NULL ||
strcmp (service->t.plugin_loader.loader_id, loader_type_str) == 0)) {
strcmp ((*service_ptr)->t.plugin_loader.loader_id, loader_type_str) == 0)) {
return TRUE;
}
}
......@@ -335,6 +351,53 @@ plugin_loader_is_available_by_id (const gchar *id_str)
return FALSE;
}
static PluginInfo *
plugin_dependency_get_plugin_info (PluginDependency *dep)
{
g_return_val_if_fail (dep != NULL, NULL);
if (dep->pinfo == NULL) {
dep->pinfo = plugin_db_get_plugin_info_by_plugin_id (dep->plugin_id);
}
return dep->pinfo;
}
static GList *
plugin_info_read_dependency_list (xmlNode *tree)
{
GList *dependency_list = NULL;
xmlNode *node;
g_return_val_if_fail (tree != NULL, NULL);
g_return_val_if_fail (strcmp (tree->name, "dependencies") == 0, NULL);
for (node = tree->xmlChildrenNode; node != NULL; node = node->next) {
if (strcmp (node->name, "dep_plugin") == 0) {
gchar *plugin_id;
plugin_id = e_xml_get_string_prop_by_name (node, "id");
if (plugin_id != NULL) {
PluginDependency *dep;
dep = g_new (PluginDependency, 1);
dep->plugin_id = plugin_id;
dep->pinfo = NULL;
dep->dep_type = 0;
if (e_xml_get_bool_prop_by_name_with_default (node, "activate", TRUE)) {
dep->dep_type |= (2 ^ DEPENDENCY_ACTIVATE);
}
if (e_xml_get_bool_prop_by_name_with_default (node, "load", TRUE)) {
dep->dep_type |= (2 ^ DEPENDENCY_LOAD);
}
dependency_list = g_list_prepend (dependency_list, dep);
}
}
}
return g_list_reverse (dependency_list);
}
static GList *
plugin_info_read_service_list (xmlNode *tree, ErrorInfo **ret_error)
{
......@@ -431,14 +494,24 @@ loader_static_info_free (PluginLoaderStaticInfo *loader_info)
g_free (loader_info);
}
static void
plugin_dependency_free (PluginDependency *dep)
{
g_return_if_fail (dep != NULL);
g_free (dep->plugin_id);
g_free (dep);
}
PluginInfo *
plugin_info_read (const gchar *dir_name, xmlNode *tree, ErrorInfo **ret_error)
{
PluginInfo *pinfo = NULL;
gchar *id, *name, *description;
xmlNode *information_node, *loader_node, *services_node;
xmlNode *information_node, *dependencies_node, *loader_node, *services_node;
ErrorInfo *services_error, *loader_error;
GList *service_list;
GList *dependency_list;
PluginLoaderStaticInfo *loader_static_info;
*ret_error = NULL;
......@@ -457,6 +530,12 @@ plugin_info_read (const gchar *dir_name, xmlNode *tree, ErrorInfo **ret_error)
name = NULL;
description = NULL;
}
dependencies_node = e_xml_get_child_by_name (tree, "dependencies");
if (dependencies_node != NULL) {
dependency_list = plugin_info_read_dependency_list (dependencies_node);
} else {
dependency_list = NULL;
}
loader_node = e_xml_get_child_by_name (tree, "loader");
if (loader_node != NULL) {
loader_static_info = plugin_info_read_loader_static_info (loader_node, &loader_error);
......@@ -472,7 +551,8 @@ plugin_info_read (const gchar *dir_name, xmlNode *tree, ErrorInfo **ret_error)
services_error = NULL;
}
if (id != NULL && name != NULL && loader_static_info != NULL && service_list != NULL) {
GList *l;
PluginService **service_ptr;
gint i;
g_assert (loader_error == NULL);
g_assert (services_error == NULL);
......@@ -482,15 +562,18 @@ plugin_info_read (const gchar *dir_name, xmlNode *tree, ErrorInfo **ret_error)
pinfo->id = id;
pinfo->name = name;
pinfo->description = description;
for (i = 0; i < DEPENDENCY_LAST; i++) {
pinfo->n_deps[i] = 0;
}
pinfo->is_active = FALSE;
g_list_to_vector (pinfo->dependencies_v, PluginDependency, dependency_list);
g_list_free (dependency_list);
pinfo->loader_static_info = loader_static_info;
pinfo->loader = NULL;
pinfo->service_list = service_list;
for (l = pinfo->service_list; l != NULL; l = l->next) {
PluginService *service;
service = (PluginService *) l->data;
plugin_service_set_plugin (service, pinfo);
g_list_to_vector (pinfo->services_v, PluginService, service_list);
g_list_free (service_list);
for (service_ptr = pinfo->services_v; *service_ptr != NULL; service_ptr++) {
plugin_service_set_plugin (*service_ptr, pinfo);
}
pinfo->services_data = plugin_services_data_new ();
} else {
......@@ -537,6 +620,7 @@ plugin_info_read (const gchar *dir_name, xmlNode *tree, ErrorInfo **ret_error)
*ret_error = error_info_new_from_error_list (error_list);
}
g_list_free_custom (dependency_list, (GFreeFunc) plugin_dependency_free);
if (loader_static_info != NULL) {
loader_static_info_free (loader_static_info);
}
......@@ -549,6 +633,56 @@ plugin_info_read (const gchar *dir_name, xmlNode *tree, ErrorInfo **ret_error)
return pinfo;
}
void
plugin_inc_dependants (PluginInfo *pinfo, PluginDependencyType dep_type)
{
g_return_if_fail (pinfo != NULL);
g_return_if_fail (dep_type < DEPENDENCY_LAST);
pinfo->n_deps[dep_typ