summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/plugin.c')
-rw-r--r--plugins/pychrysalide/plugin.c127
1 files changed, 126 insertions, 1 deletions
diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c
index 495cecf..aa91fb8 100644
--- a/plugins/pychrysalide/plugin.c
+++ b/plugins/pychrysalide/plugin.c
@@ -57,6 +57,9 @@ static void py_plugin_module_init_gclass(GPluginModuleClass *, gpointer);
/* Initialise une instance sur la base du dérivé de GObject. */
static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds);
+/* Encadre une étape de la vie d'un greffon. */
+static bool py_plugin_module_manage_wrapper(GPluginModule *);
+
/* Accompagne la fin du chargement des modules natifs. */
static void py_plugin_module_notify_plugins_loaded_wrapper(GPluginModule *, PluginAction);
@@ -229,6 +232,7 @@ static PyObject *py_plugin_module_new(PyTypeObject *type, PyObject *args, PyObje
static void py_plugin_module_init_gclass(GPluginModuleClass *class, gpointer unused)
{
class->init = NULL;
+ class->manage = py_plugin_module_manage_wrapper;
class->exit = NULL;
class->plugins_loaded = py_plugin_module_notify_plugins_loaded_wrapper;
@@ -293,6 +297,7 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds)
"\n" \
"Depending on the implemented actions, some of the following methods" \
" have to be defined for new classes:\n" \
+ "* pychrysalide.PluginModule._init_config();\n" \
"* pychrysalide.PluginModule._notify_plugins_loaded();\n" \
"* pychrysalide.PluginModule._include_theme();\n" \
"* pychrysalide.PluginModule._on_panel_creation;\n" \
@@ -395,8 +400,71 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds)
/******************************************************************************
* *
* Paramètres : plugin = greffon à manipuler. *
+* *
+* Description : Encadre une étape de la vie d'un greffon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool py_plugin_module_manage_wrapper(GPluginModule *plugin)
+{
+ bool result; /* Bilan à faire remonter */
+ PyGILState_STATE gstate; /* Sauvegarde d'environnement */
+ PyObject *pyobj; /* Objet Python concerné */
+ PyObject *args; /* Arguments pour l'appel */
+ PyObject *pyret; /* Bilan d'exécution */
+
+#define PLUGIN_MODULE_MANAGE_WRAPPER PYTHON_WRAPPER_DEF \
+( \
+ _manage, "$self, action, /", \
+ METH_VARARGS, \
+ "Abstract method called to react to several steps of the plugin" \
+ " life.\n" \
+ "\n" \
+ "The expected action is a pychrysalide.PluginModule.PluginAction" \
+ " value.\n" \
+ "\n" \
+ "This method has to be defined in order to handle actions such as" \
+ " *PLUGIN_LOADED*." \
+)
+
+ result = true;
+
+ gstate = PyGILState_Ensure();
+
+ pyobj = pygobject_new(G_OBJECT(plugin));
+
+ if (has_python_method(pyobj, "_manage"))
+ {
+ args = PyTuple_New(1);
+
+ PyTuple_SetItem(args, 0, PyLong_FromUnsignedLong(PGA_PLUGIN_LOADED));
+
+ pyret = run_python_method(pyobj, "_manage", args);
+
+ result = (pyret == Py_True);
+
+ Py_XDECREF(pyret);
+ Py_DECREF(args);
+
+ }
+
+ Py_DECREF(pyobj);
+
+ PyGILState_Release(gstate);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon à manipuler. *
* action = type d'action attendue. *
-* unused = variable non utilisé pour l'usage de __VA_ARGS__. *
* *
* Description : Accompagne la fin du chargement des modules natifs. *
* *
@@ -1629,6 +1697,61 @@ static PyObject *py_plugin_module_get_filename(PyObject *self, void *closure)
/******************************************************************************
* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit la configuration mise en place pour le greffon. *
+* *
+* Retour : Configuration dédiée à l'extension. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_plugin_module_get_config(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GPluginModule *plugin; /* Version native du greffon */
+ GGenConfig *config; /* Configuration associée */
+
+#define PLUGIN_MODULE_CONFIG_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ config, py_plugin_module, \
+ "Dedicated configuration for the plugin." \
+ "\n" \
+ "The value is a pychrysalide.glibext.GenConfig instance" \
+ " or None if the configuration is not yet created.\n" \
+ "\n" \
+ "As configuration storage path depends on the plugin name," \
+ " all plugin properties have to get fully loaded by the" \
+ " core before the configuration can be setup." \
+ "automatically" \
+)
+
+ plugin = G_PLUGIN_MODULE(pygobject_get(self));
+ config = g_plugin_module_get_config(plugin);
+
+ if (config == NULL)
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ else
+ {
+ result = pygobject_new(G_OBJECT(config));
+
+ g_object_unref(G_OBJECT(config));
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : - *
* *
* Description : Fournit un accès à une définition de type à diffuser. *
@@ -1642,6 +1765,7 @@ static PyObject *py_plugin_module_get_filename(PyObject *self, void *closure)
PyTypeObject *get_python_plugin_module_type(void)
{
static PyMethodDef py_plugin_module_methods[] = {
+ PLUGIN_MODULE_MANAGE_WRAPPER,
PLUGIN_MODULE_NOTIFY_PLUGINS_LOADED_WRAPPER,
PLUGIN_MODULE_INCLUDE_THEME_WRAPPER,
PLUGIN_MODULE_ON_PANEL_CREATION_WRAPPER,
@@ -1661,6 +1785,7 @@ PyTypeObject *get_python_plugin_module_type(void)
static PyGetSetDef py_plugin_module_getseters[] = {
PLUGIN_MODULE_MODNAME_ATTRIB,
PLUGIN_MODULE_FILENAME_ATTRIB,
+ PLUGIN_MODULE_CONFIG_ATTRIB,
{ NULL }
};