gedit r6263 - in trunk: . gedit



Author: sfre
Date: Mon May  5 10:52:10 2008
New Revision: 6263
URL: http://svn.gnome.org/viewvc/gedit?rev=6263&view=rev

Log:
Make GeditPythonModule inherit from GeditModule

This has been done to somewhat standardize the loader API.
This way the engine shouldn't need to make explicit checks.
Note that we still need to check manually if python is initialized,
which sort of defeats the purpose.


Modified:
   trunk/ChangeLog
   trunk/gedit/gedit-module.c
   trunk/gedit/gedit-module.h
   trunk/gedit/gedit-plugin-info-priv.h
   trunk/gedit/gedit-plugin-info.c
   trunk/gedit/gedit-plugin-info.h
   trunk/gedit/gedit-plugins-engine.c
   trunk/gedit/gedit-python-module.c
   trunk/gedit/gedit-python-module.h

Modified: trunk/gedit/gedit-module.c
==============================================================================
--- trunk/gedit/gedit-module.c	(original)
+++ trunk/gedit/gedit-module.c	Mon May  5 10:52:10 2008
@@ -41,69 +41,32 @@
 #include "gedit-module.h"
 #include "gedit-debug.h"
 
-#include <gmodule.h>
-
-typedef struct _GeditModuleClass GeditModuleClass;
-
-struct _GeditModuleClass
-{
-	GTypeModuleClass parent_class;
-};
-
-struct _GeditModule
-{
-	GTypeModule parent_instance;
-
-	GModule *library;
-
-	gchar *path;
-	GType type;
-};
-
 typedef GType (*GeditModuleRegisterFunc) (GTypeModule *);
 
-static void gedit_module_init		(GeditModule *action);
-static void gedit_module_class_init	(GeditModuleClass *class);
-
-static GObjectClass *parent_class = NULL;
-
-GType
-gedit_module_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0))
-	{
-		static const GTypeInfo type_info =
-		{
-			sizeof (GeditModuleClass),
-			(GBaseInitFunc) NULL,
-			(GBaseFinalizeFunc) NULL,
-			(GClassInitFunc) gedit_module_class_init,
-			(GClassFinalizeFunc) NULL,
-			NULL,
-			sizeof (GeditModule),
-			0, /* n_preallocs */
-			(GInstanceInitFunc) gedit_module_init,
-		};
-
-		type = g_type_register_static (G_TYPE_TYPE_MODULE,
-					       "GeditModule",
-					       &type_info, 0);
-	}
+enum {
+	PROP_0,
+	PROP_MODULE_NAME,
+	PROP_PATH
+};
 
-	return type;
-}
+G_DEFINE_TYPE (GeditModule, gedit_module, G_TYPE_TYPE_MODULE);
 
 static gboolean
 gedit_module_load (GTypeModule *gmodule)
 {
 	GeditModule *module = GEDIT_MODULE (gmodule);
 	GeditModuleRegisterFunc register_func;
+	gchar *path;
+
+	gedit_debug_message (DEBUG_PLUGINS, "Loading %s module from %s",
+			     module->module_name, module->path);
 
-	gedit_debug_message (DEBUG_PLUGINS, "Loading %s", module->path);
+	path = g_module_build_path (module->path, module->module_name);
+	g_return_val_if_fail (path != NULL, FALSE);
+	gedit_debug_message (DEBUG_PLUGINS, "Module filename: %s", path);
 
-	module->library = g_module_open (module->path, 0);
+	module->library = g_module_open (path, 0);
+	g_free (path);
 
 	if (module->library == NULL)
 	{
@@ -136,7 +99,7 @@
 
 	if (module->type == 0)
 	{
-		g_warning ("Invalid gedit plugin contained by module %s", module->path);
+		g_warning ("Invalid gedit plugin contained by module %s", module->module_name);
 		return FALSE;
 	}
 
@@ -156,25 +119,10 @@
 	module->type = 0;
 }
 
-const gchar *
-gedit_module_get_path (GeditModule *module)
-{
-	g_return_val_if_fail (GEDIT_IS_MODULE (module), NULL);
-
-	return module->path;
-}
-
-GObject *
-gedit_module_new_object (GeditModule *module)
+static void
+gedit_module_class_real_garbage_collect (void)
 {
-	gedit_debug_message (DEBUG_PLUGINS, "Creating object of type %s", g_type_name (module->type));
-
-	if (module->type == 0)
-	{
-		return NULL;
-	}
-
-	return g_object_new (module->type, NULL);
+	/* Do nothing */
 }
 
 static void
@@ -191,38 +139,119 @@
 	gedit_debug_message (DEBUG_PLUGINS, "GeditModule %p finalising", module);
 
 	g_free (module->path);
+	g_free (module->module_name);
 
-	G_OBJECT_CLASS (parent_class)->finalize (object);
+	G_OBJECT_CLASS (gedit_module_parent_class)->finalize (object);
 }
 
 static void
-gedit_module_class_init (GeditModuleClass *class)
+gedit_module_get_property (GObject    *object,
+			   guint       prop_id,
+			   GValue     *value,
+			   GParamSpec *pspec)
 {
-	GObjectClass *object_class = G_OBJECT_CLASS (class);
-	GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
+	GeditModule *module = GEDIT_MODULE (object);
+
+	switch (prop_id)
+	{
+		case PROP_MODULE_NAME:
+			g_value_set_string (value, module->module_name);
+			break;
+		case PROP_PATH:
+			g_value_set_string (value, module->path);
+			break;
+		default:
+			g_return_if_reached ();
+	}
+}
 
-	parent_class = (GObjectClass *) g_type_class_peek_parent (class);
+static void
+gedit_module_set_property (GObject      *object,
+			   guint         prop_id,
+			   const GValue *value,
+			   GParamSpec   *pspec)
+{
+	GeditModule *module = GEDIT_MODULE (object);
 
+	switch (prop_id)
+	{
+		case PROP_MODULE_NAME:
+			module->module_name = g_value_dup_string (value);
+			g_type_module_set_name (G_TYPE_MODULE (object),
+						module->module_name);
+			break;
+		case PROP_PATH:
+			module->path = g_value_dup_string (value);
+			break;
+		default:
+			g_return_if_reached ();
+	}
+}
+
+static void
+gedit_module_class_init (GeditModuleClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
+
+	object_class->set_property = gedit_module_set_property;
+	object_class->get_property = gedit_module_get_property;
 	object_class->finalize = gedit_module_finalize;
 
 	module_class->load = gedit_module_load;
 	module_class->unload = gedit_module_unload;
+
+	klass->garbage_collect = gedit_module_class_real_garbage_collect;
+
+	g_object_class_install_property (object_class,
+					 PROP_MODULE_NAME,
+					 g_param_spec_string ("module-name",
+							      "Module Name",
+							      "The module to load for this plugin",
+							      NULL,
+							      G_PARAM_READWRITE |
+							      G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property (object_class,
+					 PROP_PATH,
+					 g_param_spec_string ("path",
+							      "Path",
+							      "The path to use when loading this module",
+							      NULL,
+							      G_PARAM_READWRITE |
+							      G_PARAM_CONSTRUCT_ONLY));
+}
+
+void
+gedit_module_class_garbage_collect (GeditModuleClass *klass)
+{
+	g_return_if_fail (GEDIT_IS_MODULE_CLASS (klass));
+	return GEDIT_MODULE_CLASS (klass)->garbage_collect ();
 }
 
-GeditModule *
-gedit_module_new (const gchar *path)
+GObject *
+gedit_module_new_object (GeditModule *module)
 {
-	GeditModule *result;
+	g_return_val_if_fail (module->type != 0, NULL);
 
-	if (path == NULL || path[0] == '\0')
-	{
-		return NULL;
-	}
+	gedit_debug_message (DEBUG_PLUGINS, "Creating object of type %s",
+			     g_type_name (module->type));
 
-	result = g_object_new (GEDIT_TYPE_MODULE, NULL);
+	return g_object_new (module->type, NULL);
+}
 
-	g_type_module_set_name (G_TYPE_MODULE (result), path);
-	result->path = g_strdup (path);
+const gchar *
+gedit_module_get_path (GeditModule *module)
+{
+	g_return_val_if_fail (GEDIT_IS_MODULE (module), NULL);
+
+	return module->path;
+}
+
+const gchar *
+gedit_module_get_module_name (GeditModule *module)
+{
+	g_return_val_if_fail (GEDIT_IS_MODULE (module), NULL);
 
-	return result;
+	return module->module_name;
 }

Modified: trunk/gedit/gedit-module.h
==============================================================================
--- trunk/gedit/gedit-module.h	(original)
+++ trunk/gedit/gedit-module.h	Mon May  5 10:52:10 2008
@@ -36,10 +36,11 @@
  * $Id$
  */
  
-#ifndef GEDIT_MODULE_H
-#define GEDIT_MODULE_H
+#ifndef __GEDIT_MODULE_H__
+#define __GEDIT_MODULE_H__
 
 #include <glib-object.h>
+#include <gmodule.h>
 
 G_BEGIN_DECLS
 
@@ -47,19 +48,43 @@
 #define GEDIT_MODULE(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_MODULE, GeditModule))
 #define GEDIT_MODULE_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_MODULE, GeditModuleClass))
 #define GEDIT_IS_MODULE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_MODULE))
-#define GEDIT_IS_MODULE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((obj), GEDIT_TYPE_MODULE))
+#define GEDIT_IS_MODULE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_MODULE))
 #define GEDIT_MODULE_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_MODULE, GeditModuleClass))
 
-typedef struct _GeditModule	GeditModule;
+typedef struct _GeditModule GeditModule;
 
-GType		 gedit_module_get_type		(void) G_GNUC_CONST;
+struct _GeditModule
+{
+	GTypeModule parent;
+
+	GModule *library;
+
+	gchar *path;
+	gchar *module_name;
+	GType type;
+};
+
+typedef struct _GeditModuleClass GeditModuleClass;
+
+struct _GeditModuleClass
+{
+	GTypeModuleClass parent_class;
 
-GeditModule	*gedit_module_new		(const gchar *path);
+	/* Virtual class methods */
+	void		 (* garbage_collect)	();
+};
+
+GType		 gedit_module_get_type		(void) G_GNUC_CONST;
 
 const gchar	*gedit_module_get_path		(GeditModule *module);
 
+const gchar	*gedit_module_get_module_name	(GeditModule *module);
+
 GObject		*gedit_module_new_object	(GeditModule *module);
 
+void		 gedit_module_class_garbage_collect
+						(GeditModuleClass *klass);
+
 G_END_DECLS
 
 #endif

Modified: trunk/gedit/gedit-plugin-info-priv.h
==============================================================================
--- trunk/gedit/gedit-plugin-info-priv.h	(original)
+++ trunk/gedit/gedit-plugin-info-priv.h	Mon May  5 10:52:10 2008
@@ -35,12 +35,6 @@
 #include "gedit-plugin-info.h"
 #include "gedit-plugin.h"
 
-typedef enum
-{
-	GEDIT_PLUGIN_LOADER_C,
-	GEDIT_PLUGIN_LOADER_PY,
-} GeditPluginLoader;
-
 struct _GeditPluginInfo
 {
 	gint               refcount;
@@ -48,8 +42,8 @@
 	gchar             *file;
 
 	gchar             *module_name;
-	GeditPluginLoader  loader;
-	GTypeModule       *module;
+	GType              module_type;
+	GeditModule       *module;
 	gchar            **dependencies;
 
 	gchar             *name;

Modified: trunk/gedit/gedit-plugin-info.c
==============================================================================
--- trunk/gedit/gedit-plugin-info.c	(original)
+++ trunk/gedit/gedit-plugin-info.c	Mon May  5 10:52:10 2008
@@ -42,6 +42,10 @@
 #include "gedit-debug.h"
 #include "gedit-plugin.h"
 
+#ifdef ENABLE_PYTHON
+#include "gedit-python-module.h"
+#endif
+
 void
 _gedit_plugin_info_ref (GeditPluginInfo *info)
 {
@@ -192,16 +196,17 @@
 				     NULL);
 	if (str && strcmp(str, "python") == 0)
 	{
-		info->loader = GEDIT_PLUGIN_LOADER_PY;
 #ifndef ENABLE_PYTHON
 		g_warning ("Cannot load Python plugin '%s' since gedit was not "
 			   "compiled with Python support.", file);
 		goto error;
+#else
+		info->module_type = GEDIT_TYPE_PYTHON_MODULE;
 #endif
 	}
 	else
 	{
-		info->loader = GEDIT_PLUGIN_LOADER_C;
+		info->module_type = GEDIT_TYPE_MODULE;
 	}
 	g_free (str);
 

Modified: trunk/gedit/gedit-plugin-info.h
==============================================================================
--- trunk/gedit/gedit-plugin-info.h	(original)
+++ trunk/gedit/gedit-plugin-info.h	Mon May  5 10:52:10 2008
@@ -33,6 +33,7 @@
 #define __GEDIT_PLUGIN_INFO_H__
 
 #include <glib-object.h>
+#include "gedit-module.h"
 
 G_BEGIN_DECLS
 

Modified: trunk/gedit/gedit-plugins-engine.c
==============================================================================
--- trunk/gedit/gedit-plugins-engine.c	(original)
+++ trunk/gedit/gedit-plugins-engine.c	Mon May  5 10:52:10 2008
@@ -239,9 +239,15 @@
 void
 gedit_plugins_engine_garbage_collect (GeditPluginsEngine *engine)
 {
-#ifdef ENABLE_PYTHON
-	gedit_python_garbage_collect ();
-#endif
+	GType *module_types = g_type_children (GEDIT_TYPE_MODULE, NULL);
+	unsigned i;
+	for (i = 0; module_types[i] != 0; i++)
+	{
+		gpointer klass = g_type_class_peek (module_types[i]);
+		if (klass != NULL)
+			gedit_module_class_garbage_collect (klass);
+	}
+	g_free (module_types);
 }
 
 static void
@@ -338,107 +344,50 @@
 	g_return_val_if_fail (info->module_name != NULL, FALSE);
 	g_return_val_if_fail (info->plugin == NULL, FALSE);
 	g_return_val_if_fail (info->available, FALSE);
-	
-	switch (info->loader)
-	{
-		case GEDIT_PLUGIN_LOADER_C:
-			dirname = g_path_get_dirname (info->file);	
-			g_return_val_if_fail (dirname != NULL, FALSE);
-
-			path = g_module_build_path (dirname, info->module_name);
-			g_free (dirname);
-			g_return_val_if_fail (path != NULL, FALSE);
-	
-			info->module = G_TYPE_MODULE (gedit_module_new (path));
-			g_free (path);
-			
-			break;
+
+	dirname = g_path_get_dirname (info->file);
+	g_return_val_if_fail (dirname != NULL, FALSE);
 
 #ifdef ENABLE_PYTHON
-		case GEDIT_PLUGIN_LOADER_PY:
+	if (info->module_type == GEDIT_TYPE_PYTHON_MODULE)
+	{
+		if (!gedit_python_init ())
 		{
-			gchar *dir;
-			
-			if (!gedit_python_init ())
-			{
-				/* Mark plugin as unavailable and fails */
-				info->available = FALSE;
-				
-				g_warning ("Cannot load Python plugin '%s' since gedit "
-				           "was not able to initialize the Python interpreter.",
-				           info->name);
-
-				return FALSE;
-			}
-
-			dir = g_path_get_dirname (info->file);
-			
-			g_return_val_if_fail ((info->module_name != NULL) &&
-			                      (info->module_name[0] != '\0'),
-			                      FALSE);
-
-			info->module = G_TYPE_MODULE (
-					gedit_python_module_new (dir, info->module_name));
-					
-			g_free (dir);
-			break;
+			/* Mark plugin as unavailable and fail */
+			info->available = FALSE;
+			g_warning ("Cannot load Python plugin '%s' since gedit "
+			           "was not able to initialize the Python interpreter.",
+			           info->name);
 		}
-#endif
-		default:
-			g_return_val_if_reached (FALSE);
 	}
+#endif
+
+	info->module = GEDIT_MODULE (g_object_new (info->module_type,
+						   "path", dirname,
+						   "module-name", info->module_name,
+						   NULL));
 
-	if (!g_type_module_use (info->module))
+	if (!g_type_module_use (G_TYPE_MODULE (info->module)))
 	{
-		switch (info->loader)
-		{
-			case GEDIT_PLUGIN_LOADER_C:
-				g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.",
-					   info->name,			           
-					   gedit_module_get_path (GEDIT_MODULE (info->module)));
-				break;
-
-			case GEDIT_PLUGIN_LOADER_PY:
-				g_warning ("Cannot load Python plugin '%s' since file '%s' cannot be read.",
-					   info->name,			           
-					   info->module_name);
-				break;
+		g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.",
+			   gedit_module_get_module_name (info->module),
+			   gedit_module_get_path (info->module));
 
-			default:
-				g_return_val_if_reached (FALSE);				
-		}
-			   
 		g_object_unref (G_OBJECT (info->module));
 		info->module = NULL;
 
-		/* Mark plugin as unavailable and fails */
+		/* Mark plugin as unavailable and fail. */
 		info->available = FALSE;
 		
 		return FALSE;
 	}
-	
-	switch (info->loader)
-	{
-		case GEDIT_PLUGIN_LOADER_C:
-			info->plugin = 
-				GEDIT_PLUGIN (gedit_module_new_object (GEDIT_MODULE (info->module)));
-			break;
 
-#ifdef ENABLE_PYTHON
-		case GEDIT_PLUGIN_LOADER_PY:
-			info->plugin = 
-				GEDIT_PLUGIN (gedit_python_module_new_object (GEDIT_PYTHON_MODULE (info->module)));
-			break;
-#endif
+	info->plugin = GEDIT_PLUGIN (gedit_module_new_object (info->module));
 
-		default:
-			g_return_val_if_reached (FALSE);
-	}
-	
-	g_type_module_unuse (info->module);
+	g_type_module_unuse (G_TYPE_MODULE (info->module));
 
 	gedit_debug_message (DEBUG_PLUGINS, "End");
-	
+
 	return TRUE;
 }
 

Modified: trunk/gedit/gedit-python-module.c
==============================================================================
--- trunk/gedit/gedit-python-module.c	(original)
+++ trunk/gedit/gedit-python-module.c	Mon May  5 10:52:10 2008
@@ -24,6 +24,7 @@
 #include <config.h>
 #endif
 
+#include <Python.h>
 #include <pygobject.h>
 #include <pygtk/pygtk.h>
 
@@ -41,24 +42,6 @@
 #define PY_SSIZE_T_MIN INT_MIN
 #endif
 
-#define GEDIT_PYTHON_MODULE_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
-						 GEDIT_TYPE_PYTHON_MODULE, \
-						 GeditPythonModulePrivate))
-
-struct _GeditPythonModulePrivate
-{
-	gchar *module;
-	gchar *path;
-	GType type;
-};
-
-enum
-{
-	PROP_0,
-	PROP_PATH,
-	PROP_MODULE
-};
-
 /* Exported by pygedit module */
 void pygedit_register_classes (PyObject *d);
 void pygedit_add_constants (PyObject *module, const gchar *strip_prefix);
@@ -75,14 +58,14 @@
 /* We retreive this to check for correct class hierarchy */
 static PyTypeObject *PyGeditPlugin_Type;
 
-G_DEFINE_TYPE (GeditPythonModule, gedit_python_module, G_TYPE_TYPE_MODULE)
+G_DEFINE_TYPE (GeditPythonModule, gedit_python_module, GEDIT_TYPE_MODULE)
 
 static gboolean
 gedit_python_module_load (GTypeModule *gmodule)
 {
-	GeditPythonModulePrivate *priv = GEDIT_PYTHON_MODULE_GET_PRIVATE (gmodule);
+	GeditModule *module = GEDIT_MODULE (gmodule);
 	PyObject *main_module, *main_locals, *locals, *key, *value;
-	PyObject *module, *fromlist;
+	PyObject *pymodule, *fromlist;
 	Py_ssize_t pos = 0;
 	
 	g_return_val_if_fail (Py_IsInitialized (), FALSE);
@@ -95,10 +78,10 @@
 	}
 
 	/* If we have a special path, we register it */
-	if (priv->path != NULL)
+	if (module->path != NULL)
 	{
 		PyObject *sys_path = PySys_GetObject ("path");
-		PyObject *path = PyString_FromString (priv->path);
+		PyObject *path = PyString_FromString (module->path);
 
 		if (PySequence_Contains(sys_path, path) == 0)
 			PyList_Insert (sys_path, 0, path);
@@ -111,15 +94,15 @@
 	/* we need a fromlist to be able to import modules with a '.' in the
 	   name. */
 	fromlist = PyTuple_New(0);
-	module = PyImport_ImportModuleEx (priv->module, main_locals, main_locals, fromlist); 
+	pymodule = PyImport_ImportModuleEx (module->module_name, main_locals, main_locals, fromlist);
 	Py_DECREF(fromlist);
-	if (!module)
+	if (!pymodule)
 	{
 		PyErr_Print ();
 		return FALSE;
 	}
 
-	locals = PyModule_GetDict (module);
+	locals = PyModule_GetDict (pymodule);
 	while (PyDict_Next (locals, &pos, &key, &value))
 	{
 		if (!PyType_Check(value))
@@ -127,7 +110,7 @@
 
 		if (PyObject_IsSubclass (value, (PyObject*) PyGeditPlugin_Type))
 		{
-			priv->type = gedit_python_object_get_type (gmodule, value);
+			module->type = gedit_python_object_get_type (gmodule, value);
 			return TRUE;
 		}
 	}
@@ -138,22 +121,38 @@
 static void
 gedit_python_module_unload (GTypeModule *module)
 {
-	GeditPythonModulePrivate *priv = GEDIT_PYTHON_MODULE_GET_PRIVATE (module);
 	gedit_debug_message (DEBUG_PLUGINS, "Unloading Python module");
-	
-	priv->type = 0;
+	GEDIT_MODULE (module)->type = 0;
 }
 
-GObject *
-gedit_python_module_new_object (GeditPythonModule *module)
+static gint idle_garbage_collect_id = 0;
+
+static gboolean
+run_gc (gpointer data)
 {
-	GeditPythonModulePrivate *priv = GEDIT_PYTHON_MODULE_GET_PRIVATE (module);
-	gedit_debug_message (DEBUG_PLUGINS, "Creating object of type %s", g_type_name (priv->type));
+	while (PyGC_Collect ())
+		;
+
+	idle_garbage_collect_id = 0;
+	return FALSE;
+}
+
+static void
+gedit_python_module_class_garbage_collect (void)
+{
+	if (Py_IsInitialized())
+	{
+		/*
+		 * We both run the GC right now and we schedule
+		 * a further collection in the main loop.
+		 */
 
-	if (priv->type == 0)
-		return NULL;
+		while (PyGC_Collect ())
+			;
 
-	return g_object_new (priv->type, NULL);
+		if (idle_garbage_collect_id == 0)
+			idle_garbage_collect_id = g_idle_add (run_gc, NULL);
+	}
 }
 
 static void
@@ -165,108 +164,29 @@
 static void
 gedit_python_module_finalize (GObject *object)
 {
-	GeditPythonModulePrivate *priv = GEDIT_PYTHON_MODULE_GET_PRIVATE (object);
-	gedit_debug_message (DEBUG_PLUGINS, "Finalizing Python module %s", g_type_name (priv->type));
-
-	g_free (priv->module);
-	g_free (priv->path);
+	gedit_debug_message (DEBUG_PLUGINS, "Finalizing Python module %s",
+			     g_type_name (GEDIT_MODULE (object)->type));
 
 	G_OBJECT_CLASS (gedit_python_module_parent_class)->finalize (object);
 }
 
 static void
-gedit_python_module_get_property (GObject    *object,
-				  guint       prop_id,
-				  GValue     *value,
-				  GParamSpec *pspec)
+gedit_python_module_class_init (GeditPythonModuleClass *klass)
 {
-	/* no readable properties */
-	g_return_if_reached ();
-}
-
-static void
-gedit_python_module_set_property (GObject      *object,
-				  guint         prop_id,
-				  const GValue *value,
-				  GParamSpec   *pspec)
-{
-	GeditPythonModule *mod = GEDIT_PYTHON_MODULE (object);
-
-	switch (prop_id)
-	{
-		case PROP_MODULE:
-			GEDIT_PYTHON_MODULE_GET_PRIVATE (mod)->module = g_value_dup_string (value);
-			break;
-		case PROP_PATH:
-			GEDIT_PYTHON_MODULE_GET_PRIVATE (mod)->path = g_value_dup_string (value);
-			break;
-		default:
-			g_return_if_reached ();
-	}
-}
-
-static void
-gedit_python_module_class_init (GeditPythonModuleClass *class)
-{
-	GObjectClass *object_class = G_OBJECT_CLASS (class);
-	GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GTypeModuleClass *gmodule_class = G_TYPE_MODULE_CLASS (klass);
+	GeditModuleClass *module_class = GEDIT_MODULE_CLASS (klass);
 
 	object_class->finalize = gedit_python_module_finalize;
-	object_class->get_property = gedit_python_module_get_property;
-	object_class->set_property = gedit_python_module_set_property;
-
-	g_object_class_install_property
-			(object_class,
-			 PROP_MODULE,
-			 g_param_spec_string ("module",
-					      "Module Name",
-					      "The Python module to load for this plugin",
-					      NULL,
-					      G_PARAM_READWRITE |
-					      G_PARAM_CONSTRUCT_ONLY |
-					      G_PARAM_STATIC_STRINGS));
-
-	g_object_class_install_property
-			(object_class,
-			 PROP_PATH,
-			 g_param_spec_string ("path",
-					      "Path",
-					      "The Python path to use when loading this module",
-					      NULL,
-					      G_PARAM_READWRITE |
-					      G_PARAM_CONSTRUCT_ONLY |
-					      G_PARAM_STATIC_STRINGS));
-
-	g_type_class_add_private (object_class, sizeof (GeditPythonModulePrivate));
-	
-	module_class->load = gedit_python_module_load;
-	module_class->unload = gedit_python_module_unload;
-}
-
-GeditPythonModule *
-gedit_python_module_new (const gchar *path,
-			 const gchar *module)
-{
-	GeditPythonModule *result;
-
-	if (module == NULL || module[0] == '\0')
-		return NULL;
-
-	result = g_object_new (GEDIT_TYPE_PYTHON_MODULE,
-			       "module", module,
-			       "path", path,
-			       NULL);
 
-	g_type_module_set_name (G_TYPE_MODULE (result), module);
+	gmodule_class->load = gedit_python_module_load;
+	gmodule_class->unload = gedit_python_module_unload;
 
-	return result;
+	module_class->garbage_collect = gedit_python_module_class_garbage_collect;
 }
 
-
 /* --- these are not module methods, they are here out of convenience --- */
 
-static gint idle_garbage_collect_id = 0;
-
 /* C equivalent of
  *    import pygtk
  *    pygtk.require ("2.0")
@@ -575,32 +495,3 @@
 		Py_Finalize ();
 	}
 }
-
-static gboolean
-run_gc (gpointer data)
-{
-	while (PyGC_Collect ())
-		;
-
-	idle_garbage_collect_id = 0;
-	return FALSE;
-}
-
-void
-gedit_python_garbage_collect (void)
-{
-	if (Py_IsInitialized())
-	{
-		/*
-		 * We both run the GC right now and we schedule
-		 * a further collection in the main loop.
-		 */
-
-		while (PyGC_Collect ())
-			;
-
-		if (idle_garbage_collect_id == 0)
-			idle_garbage_collect_id = g_idle_add (run_gc, NULL);
-	}
-}
-

Modified: trunk/gedit/gedit-python-module.h
==============================================================================
--- trunk/gedit/gedit-python-module.h	(original)
+++ trunk/gedit/gedit-python-module.h	Mon May  5 10:52:10 2008
@@ -20,11 +20,11 @@
  * Boston, MA 02111-1307, USA. 
  */
 
-#ifndef GEDIT_PYTHON_MODULE_H
-#define GEDIT_PYTHON_MODULE_H
+#ifndef __GEDIT_PYTHON_MODULE_H__
+#define __GEDIT_PYTHON_MODULE_H__
 
-#include <Python.h>
 #include <glib-object.h>
+#include "gedit-module.h"
 
 G_BEGIN_DECLS
 
@@ -32,31 +32,14 @@
 #define GEDIT_PYTHON_MODULE(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_PYTHON_MODULE, GeditPythonModule))
 #define GEDIT_PYTHON_MODULE_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_PYTHON_MODULE, GeditPythonModuleClass))
 #define GEDIT_IS_PYTHON_MODULE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_PYTHON_MODULE))
-#define GEDIT_IS_PYTHON_MODULE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((obj), GEDIT_TYPE_PYTHON_MODULE))
+#define GEDIT_IS_PYTHON_MODULE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_PYTHON_MODULE))
 #define GEDIT_PYTHON_MODULE_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_PYTHON_MODULE, GeditPythonModuleClass))
 
-typedef struct _GeditPythonModule		GeditPythonModule;
-typedef struct _GeditPythonModuleClass 		GeditPythonModuleClass;
-typedef struct _GeditPythonModulePrivate	GeditPythonModulePrivate;
-
-struct _GeditPythonModuleClass
-{
-	GTypeModuleClass parent_class;
-};
-
-struct _GeditPythonModule
-{
-	GTypeModule parent_instance;
-};
+typedef GeditModule		GeditPythonModule;
+typedef GeditModuleClass	GeditPythonModuleClass;
 
 GType			 gedit_python_module_get_type		(void);
 
-GeditPythonModule	*gedit_python_module_new		(const gchar* path,
-								 const gchar *module);
-
-GObject			*gedit_python_module_new_object		(GeditPythonModule *module);
-
-
 /* --- Python utils --- */
 
 /* Must be called before loading python modules */
@@ -64,8 +47,6 @@
 
 void			gedit_python_shutdown			(void);
 
-void			gedit_python_garbage_collect		(void);
-
 G_END_DECLS
 
 #endif



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