gedit r6715 - in branches/win32: . gedit



Author: pborelli
Date: Wed Dec 24 14:11:21 2008
New Revision: 6715
URL: http://svn.gnome.org/viewvc/gedit?rev=6715&view=rev

Log:
2008-12-24  Paolo Borelli  <pborelli katamail com>

	* gedit/gedit-plugins-engine.[ch]:
	* gedit/gedit-prefs-manager.[ch]:
	* gedit/gedit-prefs-manager.[ch]:
	Centralize all gconf related code in the prefs manager.



Modified:
   branches/win32/ChangeLog
   branches/win32/gedit/gedit-plugins-engine.c
   branches/win32/gedit/gedit-plugins-engine.h
   branches/win32/gedit/gedit-prefs-manager-app.c
   branches/win32/gedit/gedit-prefs-manager.c
   branches/win32/gedit/gedit-prefs-manager.h

Modified: branches/win32/gedit/gedit-plugins-engine.c
==============================================================================
--- branches/win32/gedit/gedit-plugins-engine.c	(original)
+++ branches/win32/gedit/gedit-plugins-engine.c	Wed Dec 24 14:11:21 2008
@@ -35,13 +35,13 @@
 #include <string.h>
 
 #include <glib/gi18n.h>
-#include <gconf/gconf-client.h>
 
 #include "gedit-plugins-engine.h"
 #include "gedit-plugin-info-priv.h"
 #include "gedit-plugin.h"
 #include "gedit-debug.h"
 #include "gedit-app.h"
+#include "gedit-prefs-manager.h"
 #include "gedit-plugin-loader.h"
 #include "gedit-object-module.h"
 #include "gedit-dirs.h"
@@ -75,16 +75,11 @@
 	GList *plugin_list;
 	GHashTable *loaders;
 
-	GConfClient *gconf_client;
-	gboolean activate_from_gconf;
+	gboolean activate_from_prefs;
 };
 
 GeditPluginsEngine *default_engine = NULL;
 
-static void	gedit_plugins_engine_active_plugins_changed (GConfClient *client,
-							     guint cnxn_id, 
-							     GConfEntry *entry, 
-							     gpointer user_data);
 static void	gedit_plugins_engine_activate_plugin_real (GeditPluginsEngine *engine,
 							   GeditPluginInfo    *info);
 static void	gedit_plugins_engine_deactivate_plugin_real (GeditPluginsEngine *engine,
@@ -299,24 +294,11 @@
 						    GEDIT_TYPE_PLUGINS_ENGINE,
 						    GeditPluginsEnginePrivate);
 
-	engine->priv->gconf_client = gconf_client_get_default ();
-	g_return_if_fail (engine->priv->gconf_client != NULL);
-
-	gconf_client_add_dir (engine->priv->gconf_client,
-			      GEDIT_PLUGINS_ENGINE_BASE_KEY,
-			      GCONF_CLIENT_PRELOAD_ONELEVEL,
-			      NULL);
-
-	gconf_client_notify_add (engine->priv->gconf_client,
-				 GEDIT_PLUGINS_ENGINE_KEY,
-				 gedit_plugins_engine_active_plugins_changed,
-				 engine, NULL, NULL);
-
 	load_all_plugins (engine);
-	
-	/* make sure that the first reactivation will read active plugins from
-	   gconf */
-	engine->priv->activate_from_gconf = TRUE;
+
+	/* make sure that the first reactivation will read active plugins
+	   from the prefs */
+	engine->priv->activate_from_prefs = TRUE;
 
 	/* mapping from loadername -> loader object */
 	engine->priv->loaders = g_hash_table_new_full (hash_lowercase,
@@ -348,8 +330,6 @@
 	
 	gedit_debug (DEBUG_PLUGINS);
 
-	g_return_if_fail (engine->priv->gconf_client != NULL);
-
 	/* Firs deactivate all plugins */
 	for (item = engine->priv->plugin_list; item; item = item->next)
 	{
@@ -371,7 +351,6 @@
 	}
 
 	g_list_free (engine->priv->plugin_list);
-	g_object_unref (engine->priv->gconf_client);
 }
 
 static void
@@ -551,6 +530,7 @@
 	GList *l = g_list_find_custom (engine->priv->plugin_list,
 				       name,
 				       (GCompareFunc) compare_plugin_info_and_name);
+
 	return l == NULL ? NULL : (GeditPluginInfo *) l->data;
 }
 
@@ -559,7 +539,6 @@
 {
 	GSList *active_plugins = NULL;
 	GList *l;
-	gboolean res;
 
 	for (l = engine->priv->plugin_list; l != NULL; l = l->next)
 	{
@@ -572,14 +551,7 @@
 		}
 	}
 
-	res = gconf_client_set_list (engine->priv->gconf_client,
-				     GEDIT_PLUGINS_ENGINE_KEY,
-				     GCONF_VALUE_STRING,
-				     active_plugins,
-				     NULL);
-
-	if (!res)
-		g_warning ("Error saving the list of active plugins.");
+	gedit_prefs_manager_set_active_plugins (active_plugins);
 
 	g_slist_free (active_plugins);
 }
@@ -707,35 +679,32 @@
 gedit_plugins_engine_activate_plugins (GeditPluginsEngine *engine,
 					GeditWindow        *window)
 {
-	GList *pl;
 	GSList *active_plugins = NULL;
+	GList *pl;
 
 	gedit_debug (DEBUG_PLUGINS);
 
 	g_return_if_fail (GEDIT_IS_PLUGINS_ENGINE (engine));
 	g_return_if_fail (GEDIT_IS_WINDOW (window));
-	
+
 	/* the first time, we get the 'active' plugins from gconf */
-	if (engine->priv->activate_from_gconf)
+	if (engine->priv->activate_from_prefs)
 	{
-		active_plugins = gconf_client_get_list (engine->priv->gconf_client,
-							GEDIT_PLUGINS_ENGINE_KEY,
-							GCONF_VALUE_STRING,
-							NULL);
+		active_plugins = gedit_prefs_manager_get_active_plugins ();
 	}
 
 	for (pl = engine->priv->plugin_list; pl; pl = pl->next)
 	{
 		GeditPluginInfo *info = (GeditPluginInfo*)pl->data;
 		
-		if (engine->priv->activate_from_gconf && 
+		if (engine->priv->activate_from_prefs && 
 		    g_slist_find_custom (active_plugins,
 					 gedit_plugin_info_get_module_name (info),
 					 (GCompareFunc)strcmp) == NULL)
 			continue;
 		
 		/* If plugin is not active, don't try to activate/load it */
-		if (!engine->priv->activate_from_gconf && 
+		if (!engine->priv->activate_from_prefs && 
 		    !gedit_plugin_info_is_active (info))
 			continue;
 
@@ -744,11 +713,11 @@
 					       window);
 	}
 	
-	if (engine->priv->activate_from_gconf)
+	if (engine->priv->activate_from_prefs)
 	{
 		g_slist_foreach (active_plugins, (GFunc) g_free, NULL);
 		g_slist_free (active_plugins);
-		engine->priv->activate_from_gconf = FALSE;
+		engine->priv->activate_from_prefs = FALSE;
 	}
 	
 	gedit_debug_message (DEBUG_PLUGINS, "End");
@@ -839,35 +808,16 @@
 	gtk_widget_show (conf_dlg);
 }
 
-static void 
-gedit_plugins_engine_active_plugins_changed (GConfClient *client,
-					     guint cnxn_id,
-					     GConfEntry *entry,
-					     gpointer user_data)
+void 
+gedit_plugins_engine_active_plugins_changed (GeditPluginsEngine *engine)
 {
-	GeditPluginsEngine *engine;
-	GList *pl;
 	gboolean to_activate;
 	GSList *active_plugins;
+	GList *pl;
 
 	gedit_debug (DEBUG_PLUGINS);
 
-	g_return_if_fail (entry->key != NULL);
-	g_return_if_fail (entry->value != NULL);
-
-	engine = GEDIT_PLUGINS_ENGINE (user_data);
-	
-	if (!((entry->value->type == GCONF_VALUE_LIST) && 
-	      (gconf_value_get_list_type (entry->value) == GCONF_VALUE_STRING)))
-	{
-		g_warning ("The gconf key '%s' may be corrupted.", GEDIT_PLUGINS_ENGINE_KEY);
-		return;
-	}
-	
-	active_plugins = gconf_client_get_list (engine->priv->gconf_client,
-						GEDIT_PLUGINS_ENGINE_KEY,
-						GCONF_VALUE_STRING,
-						NULL);
+	active_plugins = gedit_prefs_manager_get_active_plugins ();
 
 	for (pl = engine->priv->plugin_list; pl; pl = pl->next)
 	{
@@ -890,4 +840,3 @@
 	g_slist_free (active_plugins);
 }
 
-

Modified: branches/win32/gedit/gedit-plugins-engine.h
==============================================================================
--- branches/win32/gedit/gedit-plugins-engine.h	(original)
+++ branches/win32/gedit/gedit-plugins-engine.h	Wed Dec 24 14:11:21 2008
@@ -78,7 +78,6 @@
 GeditPluginInfo	*gedit_plugins_engine_get_plugin_info	(GeditPluginsEngine *engine,
 							 const gchar        *name);
 
-
 /* plugin load and unloading (overall, for all windows) */
 gboolean 	 gedit_plugins_engine_activate_plugin 	(GeditPluginsEngine *engine,
 							 GeditPluginInfo    *info);
@@ -97,6 +96,10 @@
 void		 gedit_plugins_engine_update_plugins_ui  (GeditPluginsEngine *engine,
 							  GeditWindow        *window);
 
+/* private for gconf notification */
+void		 gedit_plugins_engine_active_plugins_changed
+							(GeditPluginsEngine *engine);
+
 G_END_DECLS
 
 #endif  /* __GEDIT_PLUGINS_ENGINE_H__ */

Modified: branches/win32/gedit/gedit-prefs-manager-app.c
==============================================================================
--- branches/win32/gedit/gedit-prefs-manager-app.c	(original)
+++ branches/win32/gedit/gedit-prefs-manager-app.c	Wed Dec 24 14:11:21 2008
@@ -43,6 +43,7 @@
 #include "gedit-view.h"
 #include "gedit-window.h"
 #include "gedit-window-private.h"
+#include "gedit-plugins-engine.h"
 #include "gedit-style-scheme-manager.h"
 #include "gedit-dirs.h"
 
@@ -127,6 +128,11 @@
 							 GConfEntry  *entry,
 							 gpointer     user_data);
 
+static void gedit_prefs_manager_active_plugins_changed	(GConfClient *client,
+							 guint        cnxn_id, 
+							 GConfEntry  *entry, 
+							 gpointer     user_data);
+
 static void gedit_prefs_manager_lockdown_changed	(GConfClient *client,
 							 guint        cnxn_id,
 							 GConfEntry  *entry,
@@ -627,6 +633,11 @@
 				GPM_PREFS_DIR,
 				GCONF_CLIENT_PRELOAD_RECURSIVE,
 				NULL);
+
+		gconf_client_add_dir (gedit_prefs_manager->gconf_client,
+				GPM_PLUGINS_DIR,
+				GCONF_CLIENT_PRELOAD_RECURSIVE,
+				NULL);
 		
 		gconf_client_add_dir (gedit_prefs_manager->gconf_client,
 				GPM_LOCKDOWN_DIR,
@@ -712,7 +723,12 @@
 				GPM_SAVE_DIR,
 				gedit_prefs_manager_auto_save_changed,
 				NULL, NULL, NULL);
-		
+
+		gconf_client_notify_add (gedit_prefs_manager->gconf_client,
+				GPM_ACTIVE_PLUGINS,
+				gedit_prefs_manager_active_plugins_changed,
+				NULL, NULL, NULL);
+
 		gconf_client_notify_add (gedit_prefs_manager->gconf_client,
 				GPM_LOCKDOWN_DIR,
 				gedit_prefs_manager_lockdown_changed,
@@ -1538,6 +1554,31 @@
 	}
 }
 
+static void 
+gedit_prefs_manager_active_plugins_changed (GConfClient *client,
+					    guint        cnxn_id,
+					    GConfEntry  *entry,
+					    gpointer     user_data)
+{
+	gedit_debug (DEBUG_PREFS);
+
+	g_return_if_fail (entry->key != NULL);
+	g_return_if_fail (entry->value != NULL);
+
+	if (strcmp (entry->key, GPM_ACTIVE_PLUGINS) == 0)
+	{
+		if ((entry->value->type == GCONF_VALUE_LIST) && 
+		    (gconf_value_get_list_type (entry->value) == GCONF_VALUE_STRING))
+		{
+			GeditPluginsEngine *engine;
+
+			engine = gedit_plugins_engine_get_default ();
+
+			gedit_plugins_engine_active_plugins_changed (engine);
+		}
+	}
+}
+
 static void
 gedit_prefs_manager_lockdown_changed (GConfClient *client,
 				      guint        cnxn_id,

Modified: branches/win32/gedit/gedit-prefs-manager.c
==============================================================================
--- branches/win32/gedit/gedit-prefs-manager.c	(original)
+++ branches/win32/gedit/gedit-prefs-manager.c	Wed Dec 24 14:11:21 2008
@@ -669,6 +669,7 @@
 {
 	GSList *strings;
 	GSList *res = NULL;
+
 	gedit_debug (DEBUG_PREFS);
 
 	g_return_val_if_fail (gedit_prefs_manager != NULL, NULL);
@@ -738,6 +739,7 @@
 {
 	GSList *strings;
 	GSList *res = NULL;
+
 	gedit_debug (DEBUG_PREFS);
 
 	g_return_val_if_fail (gedit_prefs_manager != NULL, NULL);
@@ -813,8 +815,8 @@
 			GPM_SHOWN_IN_MENU_ENCODINGS,
 			GCONF_VALUE_STRING,
 		       	list,
-			NULL);	
-	
+			NULL);
+
 	g_slist_free (list);
 }
 
@@ -982,7 +984,51 @@
 					     GPM_DEFAULT_RESTORE_CURSOR_POSITION);
 }
 
+/* Plugins: we just store/return a list of strings, all the magic has to
+ * happen in the plugin engine */
+
+GSList *
+gedit_prefs_manager_get_active_plugins (void)
+{
+	GSList *plugins;
+
+	gedit_debug (DEBUG_PREFS);
+
+	g_return_val_if_fail (gedit_prefs_manager != NULL, NULL);
+	g_return_val_if_fail (gedit_prefs_manager->gconf_client != NULL, NULL);
+
+	plugins = gconf_client_get_list (gedit_prefs_manager->gconf_client,
+					 GPM_ACTIVE_PLUGINS,
+					 GCONF_VALUE_STRING, 
+					 NULL);
+
+	return plugins;
+}
+
+void
+gedit_prefs_manager_set_active_plugins (const GSList *plugins)
+{	
+	g_return_if_fail (gedit_prefs_manager != NULL);
+	g_return_if_fail (gedit_prefs_manager->gconf_client != NULL);
+	g_return_if_fail (gedit_prefs_manager_active_plugins_can_set ());
+
+	gconf_client_set_list (gedit_prefs_manager->gconf_client,
+			       GPM_ACTIVE_PLUGINS,
+			       GCONF_VALUE_STRING,
+		       	       (GSList *) plugins,
+			       NULL);
+}
+
+gboolean
+gedit_prefs_manager_active_plugins_can_set (void)
+{
+	gedit_debug (DEBUG_PREFS);
+
+	return gedit_prefs_manager_key_is_writable (GPM_ACTIVE_PLUGINS);
+}
+
 /* Global Lockdown */
+
 GeditLockdownMask
 gedit_prefs_manager_get_lockdown (void)
 {

Modified: branches/win32/gedit/gedit-prefs-manager.h
==============================================================================
--- branches/win32/gedit/gedit-prefs-manager.h	(original)
+++ branches/win32/gedit/gedit-prefs-manager.h	Wed Dec 24 14:11:21 2008
@@ -131,6 +131,10 @@
 /* White list of writable gnome-vfs methods */
 #define GPM_WRITABLE_VFS_SCHEMES 	GPM_SAVE_DIR "/writable_vfs_schemes"
 
+/* Plugins */
+#define GPM_PLUGINS_DIR			GEDIT_BASE_KEY "/plugins"
+#define GPM_ACTIVE_PLUGINS		GPM_PLUGINS_DIR "/active-plugins"
+
 /* Global Lockdown keys */
 #define GPM_LOCKDOWN_DIR		"/desktop/gnome/lockdown"
 #define GPM_LOCKDOWN_COMMAND_LINE	GPM_LOCKDOWN_DIR "/disable_command_line"
@@ -269,7 +273,6 @@
 void			 gedit_prefs_manager_set_insert_spaces	 	(gboolean ai);
 gboolean		 gedit_prefs_manager_insert_spaces_can_set 	(void);
 
-
 /* Auto indent */
 gboolean		 gedit_prefs_manager_get_auto_indent	 	(void);
 void			 gedit_prefs_manager_set_auto_indent	 	(gboolean ai);
@@ -401,6 +404,11 @@
 void			 gedit_prefs_manager_set_source_style_scheme	(const gchar *scheme);
 gboolean		 gedit_prefs_manager_source_style_scheme_can_set(void);
 
+/* Plugins */
+GSList			*gedit_prefs_manager_get_active_plugins		(void);
+void			 gedit_prefs_manager_set_active_plugins		(const GSList *plugins);
+gboolean 		 gedit_prefs_manager_active_plugins_can_set	(void);
+
 /* Global lockdown */
 GeditLockdownMask	 gedit_prefs_manager_get_lockdown			(void);
 



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