gedit r6610 - in branches/new_plugins: gedit plugin-loaders/c plugin-loaders/python plugin-loaders/python/bindings



Author: jessevdk
Date: Sun Nov 23 19:50:55 2008
New Revision: 6610
URL: http://svn.gnome.org/viewvc/gedit?rev=6610&view=rev

Log:
Removed specification file, now uses get_name interface function
Fixed double references to _PyAPI stuff
Fixed scanning for plugin loaders, now only one lazy scan is performed
when first requested. Loaders itself are then lazy constructed from
the module


Removed:
   branches/new_plugins/plugin-loaders/c/cloader.gedit-plugin-loader.desktop.in
   branches/new_plugins/plugin-loaders/python/pythonloader.gedit-plugin-loader.desktop.in
Modified:
   branches/new_plugins/gedit/gedit-object-module.c
   branches/new_plugins/gedit/gedit-plugin-loader.c
   branches/new_plugins/gedit/gedit-plugin-loader.h
   branches/new_plugins/gedit/gedit-plugins-engine.c
   branches/new_plugins/plugin-loaders/c/Makefile.am
   branches/new_plugins/plugin-loaders/c/gedit-plugin-loader-c.c
   branches/new_plugins/plugin-loaders/python/Makefile.am
   branches/new_plugins/plugin-loaders/python/bindings/gedit.override
   branches/new_plugins/plugin-loaders/python/bindings/geditcommands.override
   branches/new_plugins/plugin-loaders/python/bindings/geditmessage.override
   branches/new_plugins/plugin-loaders/python/bindings/geditutils.override
   branches/new_plugins/plugin-loaders/python/gedit-plugin-loader-python.c
   branches/new_plugins/plugin-loaders/python/gedit-plugin-python.h

Modified: branches/new_plugins/gedit/gedit-object-module.c
==============================================================================
--- branches/new_plugins/gedit/gedit-object-module.c	(original)
+++ branches/new_plugins/gedit/gedit-object-module.c	Sun Nov 23 19:50:55 2008
@@ -77,7 +77,9 @@
 	g_return_val_if_fail (path != NULL, FALSE);
 	gedit_debug_message (DEBUG_PLUGINS, "Module filename: %s", path);
 
-	module->priv->library = g_module_open (path, 0);
+	module->priv->library = g_module_open (path, 
+					       G_MODULE_BIND_LAZY |
+					       G_MODULE_BIND_LOCAL);
 	g_free (path);
 
 	if (module->priv->library == NULL)

Modified: branches/new_plugins/gedit/gedit-plugin-loader.c
==============================================================================
--- branches/new_plugins/gedit/gedit-plugin-loader.c	(original)
+++ branches/new_plugins/gedit/gedit-plugin-loader.c	Sun Nov 23 19:50:55 2008
@@ -60,6 +60,34 @@
 	return type;
 }
 
+const gchar *
+gedit_plugin_loader_type_get_name (GType type)
+{
+	GTypeClass *klass;
+	GeditPluginLoaderInterface *iface;
+	
+	klass = g_type_class_ref (type);
+	
+	if (klass == NULL)
+	{
+		g_warning ("Could not get class info for plugin loader");
+		return NULL;
+	}
+
+	iface = g_type_interface_peek (klass, GEDIT_TYPE_PLUGIN_LOADER);
+	
+	if (iface == NULL)
+	{
+		g_warning ("Could not get plugin loader interface");
+		g_type_class_unref (klass);
+		
+		return NULL;
+	}
+	
+	g_return_val_if_fail (iface->get_name != NULL, NULL);
+	return iface->get_name ();
+}
+
 GeditPlugin *
 gedit_plugin_loader_load (GeditPluginLoader *loader,
 			  GeditPluginInfo   *info,

Modified: branches/new_plugins/gedit/gedit-plugin-loader.h
==============================================================================
--- branches/new_plugins/gedit/gedit-plugin-loader.h	(original)
+++ branches/new_plugins/gedit/gedit-plugin-loader.h	Sun Nov 23 19:50:55 2008
@@ -38,17 +38,21 @@
 struct _GeditPluginLoaderInterface {
 	GTypeInterface parent;
 
-	GeditPlugin *(*load) 	(GeditPluginLoader 	*loader,
-			     	 GeditPluginInfo	*info,
-			      	 const gchar       	*path);
+	const gchar *(*get_name)		(void);
 
-	void (*unload)		(GeditPluginLoader 	*loader,
-				 GeditPluginInfo       	*info);
+	GeditPlugin *(*load) 		(GeditPluginLoader 	*loader,
+			     		 GeditPluginInfo	*info,
+			      		 const gchar       	*path);
 
-	void (*garbage_collect) (GeditPluginLoader	*loader);
+	void 	     (*unload)		(GeditPluginLoader 	*loader,
+					 GeditPluginInfo       	*info);
+
+	void         (*garbage_collect) 	(GeditPluginLoader	*loader);
 };
 
 GType gedit_plugin_loader_get_type (void);
+
+const gchar *gedit_plugin_loader_type_get_name	(GType 			 type);
 GeditPlugin *gedit_plugin_loader_load		(GeditPluginLoader 	*loader,
 						 GeditPluginInfo 	*info,
 						 const gchar		*path);

Modified: branches/new_plugins/gedit/gedit-plugins-engine.c
==============================================================================
--- branches/new_plugins/gedit/gedit-plugins-engine.c	(original)
+++ branches/new_plugins/gedit/gedit-plugins-engine.c	Sun Nov 23 19:50:55 2008
@@ -51,7 +51,7 @@
 #define GEDIT_PLUGINS_ENGINE_KEY GEDIT_PLUGINS_ENGINE_BASE_KEY "/active-plugins"
 
 #define PLUGIN_EXT	".gedit-plugin"
-#define LOADER_EXT	".gedit-plugin-loader"
+#define LOADER_EXT	G_MODULE_SUFFIX
 
 typedef struct
 {
@@ -178,7 +178,7 @@
 	       gpointer            userdata)
 {
 	const gchar *home;
-	const gchar *pdirs_env;
+	const gchar *pdirs_env = NULL;
 	gchar **pdirs;
 	int i;
 
@@ -207,10 +207,10 @@
 		if (!ret)
 			return;
 	}
+	
+	if (envname)
+		pdirs_env = g_getenv (envname);
 
-	pdirs_env = g_getenv (envname);
-
-	/* What if no env var is set? We use the default location(s)! */
 	if (pdirs_env == NULL)
 		pdirs_env = envdefault;
 
@@ -272,13 +272,12 @@
 static void
 add_loader (GeditPluginsEngine *engine,
 	    const gchar        *loader_name,
-	    GeditPluginLoader  *loader,
 	    GeditObjectModule  *module)
 {
 	LoaderInfo *info;
 
 	info = g_new (LoaderInfo, 1);
-	info->loader = loader;
+	info->loader = NULL;
 	info->module = module;
 
 	g_hash_table_insert (engine->priv->loaders, g_strdup (loader_name), info);
@@ -408,93 +407,66 @@
 static gboolean
 load_loader (GeditPluginsEngine *engine,
 	     const gchar        *filename,
-	     const gchar        *loader_name)
+	     gpointer		 data)
 {
-	GKeyFile *loader_file;
 	GeditObjectModule *module;
-	gchar *str;
+	gchar *base;
 	gchar *path;
-	GeditPluginLoader *loader;
-	
-	loader_file = g_key_file_new ();
-	
-	if (!g_key_file_load_from_file (loader_file, filename, G_KEY_FILE_NONE, NULL))
-	{
-		g_warning ("Bad loader file: %s", filename);
-		g_key_file_free (loader_file);
-		return TRUE;
-	}
+	const gchar *name;
+	GType type;
 	
-	/* get loader name */
-	str = g_key_file_get_string (loader_file,
-				     "Gedit Plugin Loader",
-				     "Loader",
-				     NULL);
-	
-	/* check if this is the loader we need */
-	if (str == NULL || g_ascii_strcasecmp (str, loader_name) != 0)
-	{
-		if (str == NULL || *str == '\0')
-			g_warning ("Could not find 'Loader' in %s", filename);
+	/* try to load in the module */
+	path = g_path_get_dirname (filename);
+	base = g_path_get_basename (filename);
 
-		g_key_file_free (loader_file);
-		g_free (str);
-		return TRUE;
-	}
+	module = gedit_object_module_new (base, path, "register_gedit_plugin_loader");
 	
-	/* get module name */
-	str = g_key_file_get_string (loader_file,
-				     "Gedit Plugin Loader",
-				     "Module",
-				     NULL);
+	g_free (base);
+	g_free (path);
 
-	if ((str == NULL) || (*str == '\0'))
+	/* make sure to load the type definition */
+	if (!g_type_module_use (G_TYPE_MODULE (module)))
 	{
-		g_warning ("Could not find 'Module' in %s", filename);
+		g_object_unref (module);
+		g_warning ("Plugin loader module `%s' could not be loaded", filename);
 
-		g_key_file_free (loader_file);
-		g_free (str);
 		return TRUE;
 	}
 	
-	path = g_path_get_dirname (filename);
-	module = gedit_object_module_new (str, path, "register_gedit_plugin_loader");
+	/* get the exported type and check the name as exported by the 
+	 * loader interface */
+	type = gedit_object_module_get_object_type (module);
+	name = gedit_plugin_loader_type_get_name (type);
 	
-	g_free (path);
-	g_free (str);
+	g_message("Name: %s", name);
 	
-	/* make sure to load the type definition */
-	if (!g_type_module_use (G_TYPE_MODULE (module)))
+	add_loader (engine, name, module);	
+	g_type_module_unuse (G_TYPE_MODULE (module));
+
+	return TRUE;
+}
+
+static void
+ensure_loader (LoaderInfo *info)
+{
+	if (info->loader == NULL && info->module != NULL)
 	{
-		g_object_unref (module);
-		g_warning ("Plugin loader module could not be loaded");
-		
-		add_loader (engine, loader_name, NULL, NULL);
-		return FALSE;
-	}
-	
-	/* create a new loader object */
-	loader = (GeditPluginLoader *)gedit_object_module_new_object (module, NULL);
+		/* create a new loader object */
+		GeditPluginLoader *loader;
+		loader = (GeditPluginLoader *)gedit_object_module_new_object (info->module, NULL);
 	
-	if (loader == NULL || !GEDIT_IS_PLUGIN_LOADER (loader))
-	{
-		g_warning ("Loader object is not a valid GeditPluginLoader instance");
-		
-		if (loader != NULL && G_IS_OBJECT (loader))
-			g_object_unref (loader);
-
-		g_type_module_unuse (G_TYPE_MODULE (module));
-		g_object_unref (module);
+		if (loader == NULL || !GEDIT_IS_PLUGIN_LOADER (loader))
+		{
+			g_warning ("Loader object is not a valid GeditPluginLoader instance");
 		
-		add_loader (engine, loader_name, NULL, NULL);
-		return FALSE;
+			if (loader != NULL && G_IS_OBJECT (loader))
+				g_object_unref (loader);
+		}
+		else
+		{
+			info->loader = loader;
+		}
 	}
-	
-	/* add the loader to the hash */
-	add_loader (engine, loader_name, loader, module);
-	g_type_module_unuse (G_TYPE_MODULE (module));
-
-	return FALSE;
 }
 
 static GeditPluginLoader *
@@ -505,22 +477,38 @@
 	
 	loader_name = info->loader;
 
-	loader_info = (LoaderInfo *)g_hash_table_lookup (engine->priv->loaders, loader_name);
+	loader_info = (LoaderInfo *)g_hash_table_lookup (
+			engine->priv->loaders, 
+			loader_name);
 
-	if (loader_info)
-		return loader_info->loader;
-
-	/* loader could not be found in the hash, try to find it */
-	load_all_real (engine, 
-		       "plugin-loaders", 
-		       "GEDIT_LOADERS_PATH", 
-		       GEDIT_LOADERDIR,
-		       LOADER_EXT,
-		       (LoadDirCallback)load_loader,
-		       (gpointer)loader_name);
+	if (loader_info == NULL)
+	{
+		/* loader could not be found in the hash, try to find it by 
+		   scanning */
+		load_all_real (engine, 
+			       "plugin-loaders", 
+			       NULL, 
+			       GEDIT_LOADERDIR,
+			       LOADER_EXT,
+			       (LoadDirCallback)load_loader,
+			       NULL);
+		
+		loader_info = (LoaderInfo *)g_hash_table_lookup (
+				engine->priv->loaders, 
+				loader_name);
+	}
+	
+	
+	
+	if (loader_info == NULL)
+	{
+		/* cache non-existent so we don't scan again */
+		add_loader (engine, loader_name, NULL);
+		return NULL;
+	}
 	
-	loader_info = (LoaderInfo *)g_hash_table_lookup (engine->priv->loaders, loader_name);
-	return loader_info ? loader_info->loader : NULL;
+	ensure_loader (loader_info);
+	return loader_info->loader;
 }
 
 GeditPluginsEngine *

Modified: branches/new_plugins/plugin-loaders/c/Makefile.am
==============================================================================
--- branches/new_plugins/plugin-loaders/c/Makefile.am	(original)
+++ branches/new_plugins/plugin-loaders/c/Makefile.am	Sun Nov 23 19:50:55 2008
@@ -20,18 +20,3 @@
 
 libcloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS)
 libcloader_la_LIBADD = $(GEDIT_LIBS)
-
-loader_in_files = cloader.gedit-plugin-loader.desktop.in
-
-%.gedit-plugin-loader: %.gedit-plugin-loader.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-
-loader_DATA = $(loader_in_files:.gedit-plugin-loader.desktop.in=.gedit-plugin-loader)
-
-EXTRA_DIST = \
-	$(loader_in_files)
-
-CLEANFILES = \
-	$(loader_DATA)
-
-DISTCLEANFILES = \
-	$(loader_DATA)

Modified: branches/new_plugins/plugin-loaders/c/gedit-plugin-loader-c.c
==============================================================================
--- branches/new_plugins/plugin-loaders/c/gedit-plugin-loader-c.c	(original)
+++ branches/new_plugins/plugin-loaders/c/gedit-plugin-loader-c.c	Sun Nov 23 19:50:55 2008
@@ -12,6 +12,12 @@
 
 GEDIT_PLUGIN_LOADER_REGISTER_TYPE (GeditPluginLoaderC, gedit_plugin_loader_c);
 
+static const gchar *
+gedit_plugin_loader_iface_get_name (void)
+{
+	return "C";
+}
+
 static GeditPlugin *
 gedit_plugin_loader_iface_load (GeditPluginLoader *loader,
 				GeditPluginInfo   *info,
@@ -71,6 +77,7 @@
 {
 	GeditPluginLoaderInterface *iface = (GeditPluginLoaderInterface *)g_iface;
 	
+	iface->get_name = gedit_plugin_loader_iface_get_name;
 	iface->load = gedit_plugin_loader_iface_load;
 	iface->unload = gedit_plugin_loader_iface_unload;
 }

Modified: branches/new_plugins/plugin-loaders/python/Makefile.am
==============================================================================
--- branches/new_plugins/plugin-loaders/python/Makefile.am	(original)
+++ branches/new_plugins/plugin-loaders/python/Makefile.am	Sun Nov 23 19:50:55 2008
@@ -31,18 +31,3 @@
 libpythonloader_la_LIBADD = \
 	$(GEDIT_LIBS) 			\
 	$(srcdir)/bindings/gedit.la
-
-loader_in_files = pythonloader.gedit-plugin-loader.desktop.in
-
-%.gedit-plugin-loader: %.gedit-plugin-loader.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-
-loader_DATA = $(loader_in_files:.gedit-plugin-loader.desktop.in=.gedit-plugin-loader)
-
-EXTRA_DIST = \
-	$(loader_in_files)
-
-CLEANFILES = \
-	$(loader_DATA)
-
-DISTCLEANFILES = \
-	$(loader_DATA)

Modified: branches/new_plugins/plugin-loaders/python/bindings/gedit.override
==============================================================================
--- branches/new_plugins/plugin-loaders/python/bindings/gedit.override	(original)
+++ branches/new_plugins/plugin-loaders/python/bindings/gedit.override	Sun Nov 23 19:50:55 2008
@@ -1,7 +1,6 @@
 %%
 headers
-#define NO_IMPORT_PYGOBJECT
-#include "pygobject.h"
+#include <pygobject.h>
 #include <pygtk/pygtk.h>
 
 #include <gedit/gedit-language-manager.h>

Modified: branches/new_plugins/plugin-loaders/python/bindings/geditcommands.override
==============================================================================
--- branches/new_plugins/plugin-loaders/python/bindings/geditcommands.override	(original)
+++ branches/new_plugins/plugin-loaders/python/bindings/geditcommands.override	Sun Nov 23 19:50:55 2008
@@ -1,7 +1,8 @@
 %%
 headers
 #define NO_IMPORT_PYGOBJECT
-#include "pygobject.h"
+#define NO_IMPORT_PYGTK
+#include <pygobject.h>
 #include <pygtk/pygtk.h>
 
 #include "gedit-commands.h"

Modified: branches/new_plugins/plugin-loaders/python/bindings/geditmessage.override
==============================================================================
--- branches/new_plugins/plugin-loaders/python/bindings/geditmessage.override	(original)
+++ branches/new_plugins/plugin-loaders/python/bindings/geditmessage.override	Sun Nov 23 19:50:55 2008
@@ -35,7 +35,8 @@
 static int
 _helper_wrap_message_types(PyObject *args, gchar ***keys, GType **types, gint *num, gboolean direct)
 {
-    guint len, i, pos;
+    guint len, i;
+    Py_ssize_t pos;
     
     len = PyTuple_Size(args);
 
@@ -180,7 +181,8 @@
 static int
 _helper_wrap_message_set_values(GeditMessage *message, PyObject *args)
 {
-    guint len, i;
+    guint len;
+    Py_ssize_t i;
     
     len = PyTuple_Size(args);
 
@@ -218,7 +220,8 @@
 static GeditMessage *
 _helper_wrap_create_message(PyObject *args)
 {
-    guint len, num;
+    guint len;
+    gint num;
     gchar *domain;
     gchar *name;
     GType *types;
@@ -316,7 +319,7 @@
 static PyObject *
 _wrap_gedit_message_set_types(PyGObject *self, PyObject *args)
 {
-    guint num;
+    gint num;
     GType *types;
     gchar **keys;
 

Modified: branches/new_plugins/plugin-loaders/python/bindings/geditutils.override
==============================================================================
--- branches/new_plugins/plugin-loaders/python/bindings/geditutils.override	(original)
+++ branches/new_plugins/plugin-loaders/python/bindings/geditutils.override	Sun Nov 23 19:50:55 2008
@@ -1,7 +1,8 @@
 %%
 headers
 #define NO_IMPORT_PYGOBJECT
-#include "pygobject.h"
+#define NO_IMPORT_PYGTK
+#include <pygobject.h>
 #include <pygtk/pygtk.h>
 
 #include "gedit-utils.h"

Modified: branches/new_plugins/plugin-loaders/python/gedit-plugin-loader-python.c
==============================================================================
--- branches/new_plugins/plugin-loaders/python/gedit-plugin-loader-python.c	(original)
+++ branches/new_plugins/plugin-loaders/python/gedit-plugin-loader-python.c	Sun Nov 23 19:50:55 2008
@@ -2,6 +2,9 @@
 #include "gedit-plugin-python.h"
 #include <gedit/gedit-object-module.h>
 
+#define NO_IMPORT_PYGOBJECT
+#define NO_IMPORT_PYGTK
+
 #include <Python.h>
 #include <pygobject.h>
 #include <pygtk/pygtk.h>
@@ -114,6 +117,12 @@
 	return new_plugin_from_info (loader, info);
 }
 
+static const gchar *
+gedit_plugin_loader_iface_get_name (void)
+{
+	return "Python";
+}
+
 static GeditPlugin *
 gedit_plugin_loader_iface_load (GeditPluginLoader *loader,
 				GeditPluginInfo   *info,
@@ -248,6 +257,7 @@
 {
 	GeditPluginLoaderInterface *iface = (GeditPluginLoaderInterface *)g_iface;
 	
+	iface->get_name = gedit_plugin_loader_iface_get_name;
 	iface->load = gedit_plugin_loader_iface_load;
 	iface->unload = gedit_plugin_loader_iface_unload;
 	iface->garbage_collect = gedit_plugin_loader_iface_garbage_collect;

Modified: branches/new_plugins/plugin-loaders/python/gedit-plugin-python.h
==============================================================================
--- branches/new_plugins/plugin-loaders/python/gedit-plugin-python.h	(original)
+++ branches/new_plugins/plugin-loaders/python/gedit-plugin-python.h	Sun Nov 23 19:50:55 2008
@@ -24,6 +24,8 @@
 #ifndef __GEDIT_PLUGIN_PYTHON_H__
 #define __GEDIT_PLUGIN_PYTHON_H__
 
+#define NO_IMPORT_PYGOBJECT
+
 #include <glib-object.h>
 #include <pygobject.h>
 



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