gedit r6655 - in trunk: . gedit plugin-loaders/c plugin-loaders/python plugin-loaders/python/bindings



Author: jessevdk
Date: Sat Dec  6 13:42:50 2008
New Revision: 6655
URL: http://svn.gnome.org/viewvc/gedit?rev=6655&view=rev

Log:
    * gedit/gedit-plugin.h:
    * gedit/gedit-plugin.c:
    * plugin-loaders/python/gedit-plugin-loader-python.c:
    * plugin-loaders/python/bindings/gedit.defs:
    * plugin-loaders/python/bindings/geditplugin.override:
    * plugin-loaders/c/gedit-plugin-loader-c.c:

    Added 'install-path' construct only property set by plugin
    loaders so that plugins (especially C plugins) can find
    out where they are installed (thus making relocation of
    plugins + data possible without recompiling the plugin)


Modified:
   trunk/ChangeLog
   trunk/gedit/gedit-plugin.c
   trunk/gedit/gedit-plugin.h
   trunk/plugin-loaders/c/gedit-plugin-loader-c.c
   trunk/plugin-loaders/python/bindings/gedit.defs
   trunk/plugin-loaders/python/bindings/geditplugin.override
   trunk/plugin-loaders/python/gedit-plugin-loader-python.c

Modified: trunk/gedit/gedit-plugin.c
==============================================================================
--- trunk/gedit/gedit-plugin.c	(original)
+++ trunk/gedit/gedit-plugin.c	Sat Dec  6 13:42:50 2008
@@ -34,6 +34,21 @@
 
 #include "gedit-plugin.h"
 
+/* properties */
+enum {
+	PROP_0,
+	PROP_INSTALL_PATH
+};
+
+typedef struct _GeditPluginPrivate GeditPluginPrivate;
+
+struct _GeditPluginPrivate
+{
+	gchar *install_path;
+};
+
+#define GEDIT_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_PLUGIN, GeditPluginPrivate))
+
 G_DEFINE_TYPE(GeditPlugin, gedit_plugin, G_TYPE_OBJECT)
 
 static void
@@ -55,15 +70,76 @@
 		create_configure_dialog);
 }
 
+static void
+gedit_plugin_get_property (GObject    *object,
+			   guint       prop_id,
+			   GValue     *value,
+			   GParamSpec *pspec)
+{
+	GeditPluginPrivate *priv = GEDIT_PLUGIN_GET_PRIVATE (object);
+
+	switch (prop_id)
+	{
+		case PROP_INSTALL_PATH:
+			g_value_set_string (value, priv->install_path);
+			break;
+		default:
+			g_return_if_reached ();
+	}
+}
+
+static void
+gedit_plugin_set_property (GObject      *object,
+			   guint         prop_id,
+			   const GValue *value,
+			   GParamSpec   *pspec)
+{
+	GeditPluginPrivate *priv = GEDIT_PLUGIN_GET_PRIVATE (object);
+
+	switch (prop_id)
+	{
+		case PROP_INSTALL_PATH:
+			priv->install_path = g_value_dup_string (value);
+			break;
+		default:
+			g_return_if_reached ();
+	}
+}
+
+static void
+gedit_plugin_finalize (GObject *object)
+{
+	GeditPluginPrivate *priv = GEDIT_PLUGIN_GET_PRIVATE (object);
+	
+	g_free (priv->install_path);
+}
+
 static void 
 gedit_plugin_class_init (GeditPluginClass *klass)
 {
+    	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
 	klass->activate = dummy;
 	klass->deactivate = dummy;
 	klass->update_ui = dummy;
 	
 	klass->create_configure_dialog = create_configure_dialog;
 	klass->is_configurable = is_configurable;
+
+	object_class->get_property = gedit_plugin_get_property;
+	object_class->set_property = gedit_plugin_set_property;
+	object_class->finalize = gedit_plugin_finalize;
+
+	g_object_class_install_property (object_class,
+					 PROP_INSTALL_PATH,
+					 g_param_spec_string ("install-path",
+							      "Install Path",
+							      "The path where the plugin is installed",
+							      NULL,
+							      G_PARAM_READWRITE | 
+								  G_PARAM_CONSTRUCT_ONLY));
+	
+	g_type_class_add_private (klass, sizeof (GeditPluginPrivate));
 }
 
 static void
@@ -73,6 +149,20 @@
 }
 
 /**
+ * gedit_plugin_get_install_path:
+ * @plugin: a #GeditPlugin
+ *
+ * Returns the path where the plugin is installed
+ */
+const gchar *
+gedit_plugin_get_install_path (GeditPlugin *plugin)
+{
+	g_return_val_if_fail (GEDIT_IS_PLUGIN (plugin), NULL);
+	
+	return GEDIT_PLUGIN_GET_PRIVATE (plugin)->install_path;
+}
+
+/**
  * gedit_plugin_activate:
  * @plugin: a #GeditPlugin
  * @window: a #GeditWindow

Modified: trunk/gedit/gedit-plugin.h
==============================================================================
--- trunk/gedit/gedit-plugin.h	(original)
+++ trunk/gedit/gedit-plugin.h	Sat Dec  6 13:42:50 2008
@@ -99,6 +99,7 @@
  * Public methods
  */
 GType 		 gedit_plugin_get_type 		(void) G_GNUC_CONST;
+gchar const	*gedit_plugin_get_install_path	(GeditPlugin *plugin);
 
 void 		 gedit_plugin_activate		(GeditPlugin *plugin,
 						 GeditWindow *window);

Modified: trunk/plugin-loaders/c/gedit-plugin-loader-c.c
==============================================================================
--- trunk/plugin-loaders/c/gedit-plugin-loader-c.c	(original)
+++ trunk/plugin-loaders/c/gedit-plugin-loader-c.c	Sat Dec  6 13:42:50 2008
@@ -72,7 +72,7 @@
 	}
 	
 	/* create new plugin object */
-	result = (GeditPlugin *)gedit_object_module_new_object (module, NULL);
+	result = (GeditPlugin *)gedit_object_module_new_object (module, "install-path", path, NULL);
 	
 	if (!result)
 	{
@@ -81,7 +81,7 @@
 		
 		return NULL;
 	}
-	
+
 	g_type_module_unuse (G_TYPE_MODULE (module));
 	
 	return result;

Modified: trunk/plugin-loaders/python/bindings/gedit.defs
==============================================================================
--- trunk/plugin-loaders/python/bindings/gedit.defs	(original)
+++ trunk/plugin-loaders/python/bindings/gedit.defs	Sat Dec  6 13:42:50 2008
@@ -662,6 +662,12 @@
   (return-type "GtkWidget*")
 )
 
+(define-method get_install_path
+  (of-object "GeditPlugin")
+  (c-name "gedit_plugin_get_install_path")
+  (return-type "const-gchar*")
+)
+
 ;; From ../gedit/gedit-plugin-python.h
 
 (define-function gedit_plugin_python_get_type
@@ -672,7 +678,7 @@
 (define-function gedit_plugin_python_new
   (c-name "gedit_plugin_python_new")
   (is-constructor-of "GeditPluginPython")
-  (return-type "GObject*")
+  (return-type "GeditPluginPython*")
 )
 
 ;; From ../../gedit/gedit-status-bar.h

Modified: trunk/plugin-loaders/python/bindings/geditplugin.override
==============================================================================
--- trunk/plugin-loaders/python/bindings/geditplugin.override	(original)
+++ trunk/plugin-loaders/python/bindings/geditplugin.override	Sat Dec  6 13:42:50 2008
@@ -196,14 +196,9 @@
 static int
 _wrap_gedit_plugin_python_new(PyGObject *self)
 {
-        pygobject_construct (self, NULL);
-
-        if (!self->obj) {
-                PyErr_SetString (PyExc_RuntimeError, "could not create gedit.Plugin object");
-                return -1;
-        }
-        
-        _gedit_plugin_python_set_instance (GEDIT_PLUGIN_PYTHON (self->obj), (PyObject *)self);
+        /* explicitly don't create the gobject, because we do that
+		   in the loader so we can set the install path property
+		   at construction time */
         return 0;
 }
 %%

Modified: trunk/plugin-loaders/python/gedit-plugin-loader-python.c
==============================================================================
--- trunk/plugin-loaders/python/gedit-plugin-loader-python.c	(original)
+++ trunk/plugin-loaders/python/gedit-plugin-loader-python.c	Sat Dec  6 13:42:50 2008
@@ -53,6 +53,7 @@
 	PyObject *type;
 	PyObject *instance;
 	gchar    *path;
+	GType     class_type;
 } PythonInfo;
 
 static void gedit_plugin_loader_iface_init (gpointer g_iface, gpointer iface_data);
@@ -104,19 +105,57 @@
 		      GeditPluginInfo         *info)
 {
 	PythonInfo *pyinfo;
-	GObject *object;
-	
+	PyGObject *pygobject;
+	GeditPlugin *instance;
+
 	pyinfo = (PythonInfo *)g_hash_table_lookup (loader->priv->loaded_plugins, info);
 	
 	if (pyinfo == NULL)
 		return NULL;
 
-	pyinfo->instance = PyObject_CallObject (pyinfo->type, NULL);
+	/* To be able to set the install-path at construction time, we need two 
+	   different strategies. If the py object has a registered gtype, the normal
+	   construction of the underlying gobject will happen before we can set the
+	   install-path. Therefore, the following two cases defined:
+	   1) The python class has a gtype derived from GeditPluginPython
+	      The strategy here is to construct the gobject first (with the correct
+		  gtype, and setting the install-path), and then wrap it
+	   2) The python class has the GeditPluginPython gtype (but it is still
+	      a derived class from the python point of view)
+		  In this case, we create the python object first, and construct the gobject
+		  afterwards. The initialize function of the GeditPluginPython bindings
+		  prevent the early construction of the gobject
+	*/
+	if (pyinfo->class_type != GEDIT_TYPE_PLUGIN_PYTHON)
+	{
+		GObject *obj = g_object_new (pyinfo->class_type, "install-path", pyinfo->path, NULL);
+		pygobject = (PyGObject *)pygobject_new (obj);
+	}
+	else
+	{
+		pygobject = (PyGObject *)PyObject_CallObject (pyinfo->type, NULL);
+		
+		if (pygobject->obj != NULL)
+			g_error("GObject for plugin is already initialized!");
+		
+		pygobject_construct(pygobject, "install-path", pyinfo->path, NULL);
+	}
+
+	if (pygobject == NULL || pygobject->obj == NULL)
+	{
+		g_warning ("Could not create instance for %s.", gedit_plugin_info_get_name (info));
+		return NULL;
+	}
 
-        object = pygobject_get (pyinfo->instance);
+	instance = GEDIT_PLUGIN (pygobject->obj);
+	pyinfo->instance = (PyObject *)pygobject;
 
+	/* make sure to register the python instance for the GeditPluginPython
+	   object to it can wrap the virtual gedit plugin funcs back to python */
+	_gedit_plugin_python_set_instance (GEDIT_PLUGIN_PYTHON (instance), (PyObject *)pygobject);
+	
 	/* we return a reference here because the other is owned by python */
-	return GEDIT_PLUGIN (g_object_ref (object));
+	return GEDIT_PLUGIN (g_object_ref (instance));
 }
 
 static GeditPlugin *
@@ -131,7 +170,8 @@
 	pyinfo = g_new (PythonInfo, 1);
 	pyinfo->path = g_strdup (path);
 	pyinfo->type = type;
-	
+	pyinfo->class_type = pyg_type_from_object(type);
+
 	Py_INCREF (pyinfo->type);
 	
 	g_hash_table_insert (loader->priv->loaded_plugins, info, pyinfo);



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