[latexila/wip/build-tools-revamp] LatexilaBuildTools class (not finished)
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/wip/build-tools-revamp] LatexilaBuildTools class (not finished)
- Date: Sat, 19 Apr 2014 15:21:35 +0000 (UTC)
commit b8aaa0588a7d726545374f98b0bdcc2e471252cb
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 19 15:44:23 2014 +0200
LatexilaBuildTools class (not finished)
src/liblatexila/Makefile.am | 2 +
src/liblatexila/latexila-build-tools.c | 344 ++++++++++++++++++++++++++++++++
src/liblatexila/latexila-build-tools.h | 94 +++++++++
3 files changed, 440 insertions(+), 0 deletions(-)
---
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 78f7716..bb98eb6 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -1,6 +1,8 @@
noinst_LTLIBRARIES = liblatexila.la
liblatexila_la_SOURCES = \
+ latexila-build-tools.c \
+ latexila-build-tools.h \
latexila-post-processor.c \
latexila-post-processor.h \
latexila-post-processor-all-output.c \
diff --git a/src/liblatexila/latexila-build-tools.c b/src/liblatexila/latexila-build-tools.c
new file mode 100644
index 0000000..b8c0575
--- /dev/null
+++ b/src/liblatexila/latexila-build-tools.c
@@ -0,0 +1,344 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Load build tools from an XML file into data structures in memory. The build
+ * tools can be modified in memory, and then saved into the XML file.
+ */
+
+#include "latexila-build-tools.h"
+#include <gio/gio.h>
+
+struct _LatexilaBuildToolsPrivate
+{
+ /* A list of LatexilaBuildTool's */
+ GList *build_tools;
+
+ GFile *xml_file;
+
+ LatexilaBuildToolsType build_tools_type;
+
+ /* Used during the XML file parsing to load the build tools. */
+ LatexilaBuildTool *cur_tool;
+ LatexilaBuildJob *cur_job;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildTools, latexila_build_tools, G_TYPE_OBJECT)
+
+static LatexilaBuildJob *
+build_job_new (void)
+{
+ return g_slice_new0 (LatexilaBuildJob);
+}
+
+static void
+build_job_free (LatexilaBuildJob *build_job)
+{
+ g_free (build_job->command);
+ g_slice_free (LatexilaBuildJob, build_job);
+}
+
+static LatexilaBuildTool *
+build_tool_new (void)
+{
+ return g_slice_new0 (LatexilaBuildTool);
+}
+
+static void
+build_tool_free (LatexilaBuildTool *build_tool)
+{
+ g_free (build_tool->label);
+ g_free (build_tool->description);
+ g_free (build_tool->extensions);
+ g_free (build_tool->icon);
+ g_free (build_tool->files_to_open);
+
+ g_slist_free_full (build_tool->jobs, (GDestroyNotify) build_job_free);
+
+ g_slice_free (LatexilaBuildTool, build_tool);
+}
+
+static void
+latexila_build_tools_dispose (GObject *object)
+{
+ LatexilaBuildTools *build_tools = LATEXILA_BUILD_TOOLS (object);
+
+ g_clear_object (&build_tools->priv->xml_file);
+
+ G_OBJECT_CLASS (latexila_build_tools_parent_class)->dispose (object);
+}
+
+static void
+latexila_build_tools_finalize (GObject *object)
+{
+ /* TODO free list of build tools */
+
+ G_OBJECT_CLASS (latexila_build_tools_parent_class)->finalize (object);
+}
+
+static void
+latexila_build_tools_class_init (LatexilaBuildToolsClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = latexila_build_tools_dispose;
+ object_class->finalize = latexila_build_tools_finalize;
+}
+
+static void
+latexila_build_tools_init (LatexilaBuildTools *self)
+{
+ self->priv = latexila_build_tools_get_instance_private (self);
+}
+
+LatexilaBuildTools *
+latexila_build_tools_new (GFile *xml_file,
+ LatexilaBuildToolsType build_tools_type)
+{
+ LatexilaBuildTools *build_tools;
+
+ g_return_val_if_fail (G_IS_FILE (xml_file), NULL);
+
+ build_tools = g_object_new (LATEXILA_TYPE_BUILD_TOOLS, NULL);
+ build_tools->priv->xml_file = g_object_ref (xml_file);
+ build_tools->priv->build_tools_type = build_tools_type;
+
+ return build_tools;
+}
+
+static void
+parser_start_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error)
+{
+ LatexilaBuildTools *build_tools = user_data;
+
+ if (g_str_equal (element_name, "tools") ||
+ g_str_equal (element_name, "label") ||
+ g_str_equal (element_name, "description") ||
+ g_str_equal (element_name, "open"))
+ {
+ /* do nothing */
+ }
+
+ else if (g_str_equal (element_name, "tool"))
+ {
+ LatexilaBuildTool *cur_tool;
+ gint i;
+
+ if (build_tools->priv->cur_tool != NULL)
+ {
+ build_tool_free (build_tools->priv->cur_tool);
+ }
+
+ cur_tool = build_tool_new ();
+ build_tools->priv->cur_tool = cur_tool;
+
+ for (i = 0; attribute_names[i] != NULL; i++)
+ {
+ if (g_str_equal (attribute_names[i], "id"))
+ {
+ cur_tool->id = g_strtod (attribute_values[i], NULL);
+ }
+ /* "show" was the previous name of "enabled" */
+ else if (g_str_equal (attribute_names[i], "show") ||
+ g_str_equal (attribute_names[i], "enabled"))
+ {
+ cur_tool->enabled = g_str_equal (attribute_values[i], "true");
+ }
+ else if (g_str_equal (attribute_names[i], "extensions"))
+ {
+ cur_tool->extensions = g_strdup (attribute_values[i]);
+ }
+ else if (g_str_equal (attribute_names[i], "icon"))
+ {
+ cur_tool->icon = g_strdup (attribute_values[i]);
+ }
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
+ "unknown attribute \"%s\"",
+ attribute_names[i]);
+ }
+ }
+ }
+
+ else if (g_str_equal (element_name, "job"))
+ {
+ LatexilaBuildJob *cur_job;
+ gint i;
+
+ if (build_tools->priv->cur_job != NULL)
+ {
+ build_job_free (build_tools->priv->cur_job);
+ }
+
+ cur_job = build_job_new ();
+ build_tools->priv->cur_job = cur_job;
+
+ for (i = 0; attribute_names[i] != NULL; i++)
+ {
+ if (g_str_equal (attribute_names[i], "postProcessor"))
+ {
+ /* TODO */
+ }
+
+ /* For compatibility (no longer used) */
+ else if (g_str_equal (attribute_names[i], "mustSucceed"))
+ {
+ }
+
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
+ "unknown attribute \"%s\"",
+ attribute_names[i]);
+ }
+ }
+ }
+
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ "unknown element \"%s\"",
+ element_name);
+ }
+}
+
+static void
+parser_end_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ gpointer user_data,
+ GError **error)
+{
+}
+
+static void
+parser_text (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error)
+{
+}
+
+static void
+parse_contents (LatexilaBuildTools *build_tools,
+ gchar *contents)
+{
+ GMarkupParser parser;
+ GMarkupParseContext *context;
+ GError *error = NULL;
+
+ parser.start_element = parser_start_element;
+ parser.end_element = parser_end_element;
+ parser.text = parser_text;
+ parser.passthrough = NULL;
+ parser.error = NULL;
+
+ context = g_markup_parse_context_new (&parser, 0, build_tools, NULL);
+
+ g_markup_parse_context_parse (context, contents, -1, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error while parsing build tools: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ goto out;
+ }
+
+ g_markup_parse_context_end_parse (context, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error while ending build tools parser: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ goto out;
+ }
+
+out:
+ g_markup_parse_context_free (context);
+ g_free (contents);
+}
+
+static void
+load_contents_cb (GFile *xml_file,
+ GAsyncResult *result,
+ LatexilaBuildTools *build_tools)
+{
+ gchar *contents = NULL;
+ GError *error = NULL;
+
+ g_file_load_contents_finish (xml_file, result, &contents, NULL, NULL, &error);
+
+ if (error != NULL)
+ {
+ if (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_NOT_FOUND)
+ {
+ switch (build_tools->priv->build_tools_type)
+ {
+ case LATEXILA_BUILD_TOOLS_TYPE_DEFAULT:
+ g_warning ("XML file not found for the default build tools: %s",
+ g_file_get_parse_name (xml_file));
+ break;
+
+ case LATEXILA_BUILD_TOOLS_TYPE_PERSONAL:
+ /* No personal build tools. */
+ break;
+
+ default:
+ g_return_if_reached ();
+ break;
+ }
+ }
+ else
+ {
+ g_warning ("Error while loading the contents of the build tools XML file: %s",
+ error->message);
+ }
+
+ g_error_free (error);
+ return;
+ }
+
+ if (contents != NULL)
+ {
+ parse_contents (build_tools, contents);
+ }
+}
+
+void
+latexila_build_tools_load (LatexilaBuildTools *build_tools)
+{
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS (build_tools));
+ g_return_if_fail (build_tools->priv->xml_file != NULL);
+
+ g_file_load_contents_async (build_tools->priv->xml_file,
+ NULL,
+ load_contents_cb,
+ build_tools);
+}
diff --git a/src/liblatexila/latexila-build-tools.h b/src/liblatexila/latexila-build-tools.h
new file mode 100644
index 0000000..c75449a
--- /dev/null
+++ b/src/liblatexila/latexila-build-tools.h
@@ -0,0 +1,94 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LATEXILA_BUILD_TOOLS_H__
+#define __LATEXILA_BUILD_TOOLS_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_BUILD_TOOLS (latexila_build_tools_get_type ())
+#define LATEXILA_BUILD_TOOLS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LATEXILA_TYPE_BUILD_TOOLS,
LatexilaBuildTools))
+#define LATEXILA_BUILD_TOOLS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LATEXILA_TYPE_BUILD_TOOLS,
LatexilaBuildToolsClass))
+#define LATEXILA_IS_BUILD_TOOLS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LATEXILA_TYPE_BUILD_TOOLS))
+#define LATEXILA_IS_BUILD_TOOLS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LATEXILA_TYPE_BUILD_TOOLS))
+#define LATEXILA_BUILD_TOOLS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LATEXILA_TYPE_BUILD_TOOLS,
LatexilaBuildToolsClass))
+
+typedef struct _LatexilaBuildTools LatexilaBuildTools;
+typedef struct _LatexilaBuildToolsClass LatexilaBuildToolsClass;
+typedef struct _LatexilaBuildToolsPrivate LatexilaBuildToolsPrivate;
+
+struct _LatexilaBuildTools
+{
+ GObject parent;
+
+ LatexilaBuildToolsPrivate *priv;
+};
+
+struct _LatexilaBuildToolsClass
+{
+ GObjectClass parent_class;
+};
+
+typedef enum
+{
+ LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT,
+ LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT,
+ LATEXILA_POST_PROCESSOR_TYPE_LATEX,
+ LATEXILA_POST_PROCESSOR_TYPE_LATEXMK
+} LatexilaPostProcessorType;
+
+typedef struct
+{
+ LatexilaPostProcessorType post_processor_type;
+ gchar *command;
+} LatexilaBuildJob;
+
+typedef struct
+{
+ gchar *label;
+ gchar *description;
+ gchar *extensions;
+ gchar *icon;
+ gchar *files_to_open;
+
+ /* A list of LatexilaBuildJob's */
+ GSList *jobs;
+
+ /* The id is used only by the default build tools.
+ * It is used to save those are enabled or disabled.
+ */
+ gint id;
+
+ guint enabled : 1;
+} LatexilaBuildTool;
+
+typedef enum
+{
+ LATEXILA_BUILD_TOOLS_TYPE_DEFAULT, /* default build tools */
+ LATEXILA_BUILD_TOOLS_TYPE_PERSONAL /* personal build tools */
+} LatexilaBuildToolsType;
+
+GType latexila_build_tools_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __LATEXILA_BUILD_TOOLS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]