[goffice] Fixed go_plugins_init() issues related to components intialization.



commit b1641edc50191ddb45c210a86d1cdfee70628174
Author: Jean Brefort <jean brefort normalesup org>
Date:   Fri Apr 9 08:40:17 2010 +0200

    Fixed go_plugins_init() issues related to components intialization.

 ChangeLog                                |   12 +++++
 goffice/app/go-plugin.c                  |   69 ++++++++++++++---------------
 goffice/component/go-component-factory.c |   48 ++++++++++++++++++---
 goffice/component/goffice-component.h    |    2 +
 4 files changed, 88 insertions(+), 43 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index af21f04..a62f1f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-04-09  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/app/go-plugin.c (go_plugins_init), (go_plugins_add): fixed issues
+	related to components intialization.
+	* goffice/component/go-component-factory.c
+	(go_component_type_service_read_xml),
+	(go_component_type_service_activate),
+	(go_component_type_service_deactivate),
+	(go_component_type_service_class_init): implement components plugins 
+	activation/deactivation.
+	* goffice/component/goffice-component.h: add missing headers.
+
 2010-04-08  Morten Welinder  <terra gnome org>
 
 	* goffice/app/go-conf-win32.c (go_conf_win32_clone_full): Handle
diff --git a/goffice/app/go-plugin.c b/goffice/app/go-plugin.c
index e8c0142..5a72f2e 100644
--- a/goffice/app/go-plugin.c
+++ b/goffice/app/go-plugin.c
@@ -1751,11 +1751,19 @@ go_plugins_init (GOCmdContext *context,
 
 	go_default_loader_type = default_loader_type;
 	go_plugins_set_dirs (plugin_dirs);
+	if (loader_services == NULL) {
+		loader_services = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
-	loader_services = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+		/* initialize hash table with information about known plugin.xml files */
+		plugin_file_state_dir_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, plugin_file_state_free);
+	} else {
+		go_plugins_rescan (&error, NULL);
+		if (error != NULL) {
+			GO_SLIST_PREPEND (error_list, go_error_info_new_str_with_details (
+				_("Errors while reading info about new plugins."), error));
+		}
+	}
 
-	/* initialize hash table with information about known plugin.xml files */
-	plugin_file_state_dir_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, plugin_file_state_free);
 	GO_SLIST_FOREACH (known_states, char, state_str,
 		PluginFileState *state;
 
@@ -1765,24 +1773,26 @@ go_plugins_init (GOCmdContext *context,
 	);
 	plugin_file_state_hash_changed = FALSE;
 
-	/* collect information about the available plugins */
-	available_plugins = go_plugin_list_read_for_all_dirs (&error);
-	available_plugins_id_hash = g_hash_table_new (g_str_hash, g_str_equal);
-	GO_SLIST_FOREACH (available_plugins, GOPlugin, plugin,
-		g_hash_table_insert (
-			available_plugins_id_hash,
-			(gpointer) go_plugin_get_id (plugin), plugin);
-	);
-	if (error != NULL) {
-		GO_SLIST_PREPEND (error_list, go_error_info_new_str_with_details (
-			_("Errors while reading info about available plugins."), error));
+	if (available_plugins_id_hash == NULL) {
+		/* collect information about the available plugins */
+		available_plugins = go_plugin_list_read_for_all_dirs (&error);
+		available_plugins_id_hash = g_hash_table_new (g_str_hash, g_str_equal);
+		GO_SLIST_FOREACH (available_plugins, GOPlugin, plugin,
+			g_hash_table_insert (
+				available_plugins_id_hash,
+				(gpointer) go_plugin_get_id (plugin), plugin);
+		);
+		if (error != NULL) {
+			GO_SLIST_PREPEND (error_list, go_error_info_new_str_with_details (
+				_("Errors while reading info about available plugins."), error));
+		}
 	}
 
 	/* get descriptors for all previously active plugins */
 	plugin_list = NULL;
 	GO_SLIST_FOREACH (active_plugins, char, plugin_id,
 		GOPlugin *plugin = go_plugins_get_plugin_by_id (plugin_id);
-		if (plugin != NULL)
+		if (plugin != NULL && !go_plugin_is_active (plugin))
 			GO_SLIST_PREPEND (plugin_list, plugin);
 	);
 
@@ -1822,6 +1832,8 @@ go_plugins_init (GOCmdContext *context,
  * @default_loader_type : importer to use by default.
  *
  * Adds new plugins to currently used plugins.
+ * Deprecated: this function is deprecated and should not be used at all. It will be removed
+ * during next development cycle. Use go_plugins_init() instead.
  **/
 void
 go_plugins_add (GOCmdContext *context,
@@ -1836,6 +1848,11 @@ go_plugins_add (GOCmdContext *context,
 
 	go_default_loader_type = default_loader_type;
 	go_plugins_set_dirs (plugin_dirs);
+	go_plugins_rescan (&error, NULL);
+	if (error != NULL) {
+		GO_SLIST_PREPEND (error_list, go_error_info_new_str_with_details (
+			_("Errors while reading info about new plugins."), error));
+	}
 
 	GO_SLIST_FOREACH (known_states, char, state_str,
 		PluginFileState *state;
@@ -1846,33 +1863,13 @@ go_plugins_add (GOCmdContext *context,
 	);
 	plugin_file_state_hash_changed = FALSE;
 
-	/* collect information about the available plugins */
-	g_slist_free (available_plugins);
-	available_plugins = go_plugin_list_read_for_all_dirs (&error);
-	GO_SLIST_FOREACH (available_plugins, GOPlugin, plugin,
-		g_hash_table_insert (
-			available_plugins_id_hash,
-			(gpointer) go_plugin_get_id (plugin), plugin);
-	);
-	if (error != NULL) {
-		GO_SLIST_PREPEND (error_list, go_error_info_new_str_with_details (
-			_("Errors while reading info about available plugins."), error));
-	}
-
-	/* get descriptors for all previously active plugins */
 	plugin_list = NULL;
 	GO_SLIST_FOREACH (active_plugins, char, plugin_id,
 		GOPlugin *plugin = go_plugins_get_plugin_by_id (plugin_id);
-		if (plugin != NULL)
+		if (plugin != NULL && !go_plugin_is_active (plugin))
 			GO_SLIST_PREPEND (plugin_list, plugin);
 	);
 
-	/* get descriptors for new plugins */
-	g_hash_table_foreach (
-		plugin_file_state_dir_hash,
-		(GHFunc) ghf_collect_new_plugins,
-		&plugin_list);
-
 	plugin_list = g_slist_reverse (plugin_list);
 	go_plugin_db_activate_plugin_list (plugin_list, &error);
 	g_slist_free (plugin_list);
diff --git a/goffice/component/go-component-factory.c b/goffice/component/go-component-factory.c
index 3fde349..02d8af9 100644
--- a/goffice/component/go-component-factory.c
+++ b/goffice/component/go-component-factory.c
@@ -110,6 +110,7 @@ static void
 go_component_type_service_read_xml (GOPluginService * service, xmlNode * tree,
 				    GOErrorInfo ** ret_error)
 {
+	GOComponentTypeService *comp_service = GO_COMPONENT_TYPE_SERVICE (service);
 	xmlNode *ptr;
 
 	g_return_if_fail (service->id != NULL);
@@ -142,23 +143,54 @@ go_component_type_service_read_xml (GOPluginService * service, xmlNode * tree,
 					g_strdup (service->id);
 				mime_type->support_clipboard = (support_clipboard &&
 					!strcmp (support_clipboard, "yes"))? TRUE: FALSE;
-				mime_types_names =
-					g_slist_append (mime_types_names,
-							name);
 				g_hash_table_replace (mime_types, name,
 						      mime_type);
+				comp_service->mime_types = g_slist_append (comp_service->mime_types, g_strdup (name));
 			} else if (i > mime_type->priority) {
-				xmlFree (name);
+				/* removing the mime type from the previous service */
+				GOComponentTypeService *old_service = g_hash_table_lookup (pending_engines,
+										mime_type->component_type_name);
+				GSList *old_mime = g_slist_find_custom (old_service->mime_types, name, (GCompareFunc) strcmp);
+				g_free (old_mime->data);
+				old_service->mime_types = g_slist_remove_link (old_service->mime_types, old_mime);
 				g_free (mime_type->component_type_name);
-				mime_type->component_type_name =
-					g_strdup (service->id);
+				mime_type->component_type_name = g_strdup (service->id);
 				mime_type->priority = i;
-			}
+				comp_service->mime_types = g_slist_append (comp_service->mime_types, g_strdup (name));
+				xmlFree (name);
+			} else
+				xmlFree (name);
 			if (support_clipboard)
 				xmlFree (support_clipboard);
 		}
 }
 
+static void
+go_component_type_service_activate (GOPluginService *service, GOErrorInfo **ret_error)
+{
+	GOComponentTypeService *comp_service = GO_COMPONENT_TYPE_SERVICE (service);
+	GSList *l = comp_service->mime_types;
+	while (l) {
+		mime_types_names = g_slist_append (mime_types_names, g_strdup (l->data));
+		l = l->next;
+	}
+	service->is_active = TRUE;
+}
+
+static void
+go_component_type_service_deactivate (GOPluginService *service, GOErrorInfo **ret_error)
+{
+	GOComponentTypeService *comp_service = GO_COMPONENT_TYPE_SERVICE (service);
+	GSList *l = comp_service->mime_types;
+	while (l) {
+		GSList *mime_type = g_slist_find_custom (mime_types_names, l->data, (GCompareFunc) strcmp);
+		g_free (mime_type->data);
+		mime_types_names = g_slist_remove_link (mime_types_names, mime_type);
+		l = l->next;
+	}
+	service->is_active = FALSE;
+}
+
 static char *
 go_component_type_service_get_description (GOPluginService * service)
 {
@@ -199,6 +231,8 @@ go_component_type_service_class_init (GObjectClass * gobject_klass)
 	gobject_klass->finalize = go_component_type_service_finalize;
 	ps_class->read_xml = go_component_type_service_read_xml;
 	ps_class->get_description = go_component_type_service_get_description;
+	ps_class->activate = go_component_type_service_activate;
+	ps_class->deactivate = go_component_type_service_deactivate;
 }
 
 GSF_CLASS (GOComponentTypeService, go_component_type_service,
diff --git a/goffice/component/goffice-component.h b/goffice/component/goffice-component.h
index 912b44e..a97e83a 100644
--- a/goffice/component/goffice-component.h
+++ b/goffice/component/goffice-component.h
@@ -29,6 +29,8 @@ G_BEGIN_DECLS
 typedef struct _GOComponent GOComponent;
 typedef struct _GOComponentType GOComponentType;
 
+#include <goffice/component/go-component.h>
+#include <goffice/component/go-component-factory.h>
 G_END_DECLS
 
 #endif	/* GOFFICE_COMPONENT_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]