summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/project.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-04-21 22:00:00 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-04-21 22:00:00 (GMT)
commit8eb95d316f7b6fbad0ff798abfe7f70f89e812d2 (patch)
tree4f310c7ffdb94d48fff236e63c7e6f0ed9f1dee1 /plugins/pychrysalide/analysis/project.c
parent315146a49b5570294ca20beca720c4e3f74a86bd (diff)
Improved the way file formats are detected and loaded.
Diffstat (limited to 'plugins/pychrysalide/analysis/project.c')
-rw-r--r--plugins/pychrysalide/analysis/project.c93
1 files changed, 91 insertions, 2 deletions
diff --git a/plugins/pychrysalide/analysis/project.c b/plugins/pychrysalide/analysis/project.c
index cd7578d..fa7de72 100644
--- a/plugins/pychrysalide/analysis/project.c
+++ b/plugins/pychrysalide/analysis/project.c
@@ -32,18 +32,66 @@
#include <analysis/project.h>
+#include "loaded.h"
#include "../helpers.h"
+/* Crée un nouvel objet Python de type 'StudyProject'. */
+static PyObject *py_study_project_new(PyTypeObject *, PyObject *, PyObject *);
+
/* Procède à l'enregistrement d'un projet donné. */
static PyObject *py_study_project_save(PyObject *, PyObject *);
+/* Attache un contenu donné à un projet donné. */
+static PyObject *py_study_project_attach_content(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de l'objet à instancier. *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Crée un nouvel objet Python de type 'StudyProject'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_study_project_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Instance à retourner */
+ const char *filename; /* Destination de la sauvegarde*/
+ int ret; /* Bilan de lecture des args. */
+ GStudyProject *project; /* Version GLib du projet */
+
+ filename = NULL;
+
+ ret = PyArg_ParseTuple(args, "|s", &filename);
+ if (!ret) return NULL;
+
+ if (filename != NULL)
+ project = g_study_project_open(filename);
+ else
+ project = g_study_project_new();
+
+ result = pygobject_new(G_OBJECT(project));
+
+ if (project != NULL)
+ g_object_unref(project);
+
+ return result;
+
+}
/******************************************************************************
* *
-* Paramètres : self = contenu binaire à manipuler. *
+* Paramètres : self = projet d'étude à manipuler. *
* args = arguments accompagnant l'appel. *
* *
* Description : Procède à l'enregistrement d'un projet donné. *
@@ -80,6 +128,41 @@ static PyObject *py_study_project_save(PyObject *self, PyObject *args)
/******************************************************************************
* *
+* Paramètres : self = projet d'étude à manipuler. *
+* args = arguments accompagnant l'appel. *
+* *
+* Description : Attache un contenu donné à un projet donné. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_study_project_attach_content(PyObject *self, PyObject *args)
+{
+ GStudyProject *project; /* Version GLib du format */
+ PyObject *content_obj; /* Objet pour le contenu */
+ int ret; /* Bilan de lecture des args. */
+ GLoadedContent *content; /* Instance GLib correspondante*/
+
+ project = G_STUDY_PROJECT(pygobject_get(self));
+ assert(project != NULL);
+
+ ret = PyArg_ParseTuple(args, "O!", get_python_loaded_content_type(), &content_obj);
+ if (!ret) return NULL;
+
+ content = G_LOADED_CONTENT(pygobject_get(content_obj));
+
+ g_study_project_attach_content(project, content);
+
+ Py_RETURN_NONE;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : - *
* *
* Description : Fournit un accès à une définition de type à diffuser. *
@@ -98,6 +181,11 @@ PyTypeObject *get_python_study_project_type(void)
METH_VARARGS,
"save($self, filename, /)\n--\n\nSave the project into a given file."
},
+ {
+ "attach", py_study_project_attach_content,
+ METH_VARARGS,
+ "attach($self, loaded, /)\n--\n\nAdd a loaded content to the project."
+ },
{ NULL }
};
@@ -116,7 +204,8 @@ PyTypeObject *get_python_study_project_type(void)
.tp_doc = "PyChrysalide study project",
.tp_methods = py_study_project_methods,
- .tp_getset = py_study_project_getseters
+ .tp_getset = py_study_project_getseters,
+ .tp_new = py_study_project_new
};