[latexila/wip/build-tools-revamp] LatexilaBuildTools classes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/wip/build-tools-revamp] LatexilaBuildTools classes
- Date: Fri, 25 Apr 2014 17:09:48 +0000 (UTC)
commit 08fb4989726ed920327fe20603083fc1846736b6
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 19 15:44:23 2014 +0200
LatexilaBuildTools classes
And add a latexila-types.h for convenience.
src/liblatexila/Makefile.am | 11 +-
src/liblatexila/latexila-build-tools-default.c | 224 ++++++++
src/liblatexila/latexila-build-tools-default.h | 58 ++
src/liblatexila/latexila-build-tools-personal.c | 409 ++++++++++++++
src/liblatexila/latexila-build-tools-personal.h | 80 +++
src/liblatexila/latexila-build-tools.c | 571 ++++++++++++++++++++
src/liblatexila/latexila-build-tools.h | 108 ++++
.../latexila-post-processor-all-output.h | 3 +-
src/liblatexila/latexila-post-processor.h | 2 +-
src/liblatexila/latexila-types.h | 35 ++
10 files changed, 1498 insertions(+), 3 deletions(-)
---
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 78f7716..35372b0 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -1,9 +1,18 @@
+AM_CPPFLAGS = $(WARN_CFLAGS)
+
noinst_LTLIBRARIES = liblatexila.la
liblatexila_la_SOURCES = \
+ latexila-build-tools.c \
+ latexila-build-tools.h \
+ latexila-build-tools-default.c \
+ latexila-build-tools-default.h \
+ latexila-build-tools-personal.c \
+ latexila-build-tools-personal.h \
latexila-post-processor.c \
latexila-post-processor.h \
latexila-post-processor-all-output.c \
- latexila-post-processor-all-output.h
+ latexila-post-processor-all-output.h \
+ latexila-types.h
-include $(top_srcdir)/git.mk
diff --git a/src/liblatexila/latexila-build-tools-default.c b/src/liblatexila/latexila-build-tools-default.c
new file mode 100644
index 0000000..68a6ee2
--- /dev/null
+++ b/src/liblatexila/latexila-build-tools-default.c
@@ -0,0 +1,224 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * SECTION:build-tools-default
+ * @title: LatexilaBuildToolsDefault
+ * @short_description: Default build tools
+ *
+ * The #LatexilaBuildToolsDefault singleton class represents the default build
+ * tools of LaTeXila. The only possible modification is to enable or disable a
+ * build tool. Each default build tool has an ID. These IDs are used to load and
+ * save the lists of enabled and disabled build tools. The XML file is never
+ * modified by LaTeXila. But the XML file (located in data/build_tools/) can be
+ * modified by a developer to change a command, add a new build tool (with a new
+ * ID), etc. The changes will automatically be available to all the users when
+ * upgrading to the new LaTeXila version. That's why the default build tools can
+ * not be modified and are not saved to another XML file.
+ */
+
+#include "config.h"
+#include "latexila-build-tools-default.h"
+#include <gio/gio.h>
+
+static LatexilaBuildToolsDefault *instance = NULL;
+
+struct _LatexilaBuildToolsDefaultPrivate
+{
+ gint something; /* not used, but the struct can not be empty */
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildToolsDefault, latexila_build_tools_default,
LATEXILA_TYPE_BUILD_TOOLS)
+
+static void
+set_enabled_by_id (LatexilaBuildToolsDefault *build_tools,
+ gint build_tool_id,
+ gboolean enabled)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *l;
+
+ for (l = build_tools_parent->build_tools; l != NULL; l = l->next)
+ {
+ LatexilaBuildTool *build_tool = l->data;
+
+ if (build_tool->id == build_tool_id)
+ {
+ build_tool->enabled = enabled;
+ return;
+ }
+ }
+}
+
+/* Enable or disable the build tools.
+ * There are two lists: the enabled build tools IDs, and the disabled build tools IDs.
+ * By default, the two lists are empty. If an ID is in a list, it will override the
+ * default value found in the XML file. So when a new default build tool is added,
+ * it is not present in the lists, and it automatically gets the default value from
+ * the XML file.
+ */
+static void
+load_settings (LatexilaBuildToolsDefault *build_tools)
+{
+ GSettings *settings;
+ GVariant *tools;
+ GVariantIter *iter;
+ gint tool_id;
+
+ settings = g_settings_new ("org.gnome.latexila.preferences.latex");
+
+ tools = g_settings_get_value (settings, "enabled-default-build-tools");
+ g_variant_get (tools, "ai", &iter);
+
+ while (g_variant_iter_loop (iter, "i", &tool_id))
+ {
+ set_enabled_by_id (build_tools, tool_id, TRUE);
+ }
+
+ g_variant_iter_free (iter);
+ g_variant_unref (tools);
+
+ tools = g_settings_get_value (settings, "disabled-default-build-tools");
+ g_variant_get (tools, "ai", &iter);
+
+ while (g_variant_iter_loop (iter, "i", &tool_id))
+ {
+ set_enabled_by_id (build_tools, tool_id, FALSE);
+ }
+
+ g_variant_iter_free (iter);
+ g_variant_unref (tools);
+ g_object_unref (settings);
+}
+
+static void
+save_settings (LatexilaBuildToolsDefault *build_tools)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GVariantBuilder builder_enabled;
+ GVariantBuilder builder_disabled;
+ GVariant *enabled_tools;
+ GVariant *disabled_tools;
+ GSettings *settings;
+ GList *l;
+
+ g_variant_builder_init (&builder_enabled, G_VARIANT_TYPE_ARRAY);
+ g_variant_builder_init (&builder_disabled, G_VARIANT_TYPE_ARRAY);
+
+ for (l = build_tools_parent->build_tools; l != NULL; l = l->next)
+ {
+ LatexilaBuildTool *build_tool = l->data;
+
+ if (build_tool->enabled)
+ {
+ g_variant_builder_add (&builder_enabled, "i", build_tool->id);
+ }
+ else
+ {
+ g_variant_builder_add (&builder_disabled, "i", build_tool->id);
+ }
+ }
+
+ enabled_tools = g_variant_builder_end (&builder_enabled);
+ disabled_tools = g_variant_builder_end (&builder_disabled);
+
+ settings = g_settings_new ("org.gnome.latexila.preferences.latex");
+ g_settings_set_value (settings, "enabled-default-build-tools", enabled_tools);
+ g_settings_set_value (settings, "disabled-default-build-tools", disabled_tools);
+
+ g_variant_unref (enabled_tools);
+ g_variant_unref (disabled_tools);
+ g_object_unref (settings);
+}
+
+#if 0
+static void
+latexila_build_tools_default_finalize (GObject *object)
+{
+
+ G_OBJECT_CLASS (latexila_build_tools_default_parent_class)->finalize (object);
+}
+#endif
+
+static void
+latexila_build_tools_default_class_init (LatexilaBuildToolsDefaultClass *klass)
+{
+#if 0
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = latexila_build_tools_default_finalize;
+#endif
+}
+
+static GFile *
+get_xml_file (void)
+{
+ gchar *path;
+ GFile *file;
+
+ path = g_build_filename (DATA_DIR, "build_tools.xml", NULL);
+ file = g_file_new_for_path (path);
+ g_free (path);
+
+ return file;
+}
+
+static void
+latexila_build_tools_default_init (LatexilaBuildToolsDefault *build_tools)
+{
+ GFile *xml_file;
+
+ build_tools->priv = latexila_build_tools_default_get_instance_private (build_tools);
+
+ /* load_settings() will be called directly after the file is loaded. So if
+ * external code connects to the "loaded" signal too, normally the settings
+ * will be loaded too.
+ */
+ g_signal_connect (build_tools,
+ "loaded",
+ G_CALLBACK (load_settings),
+ NULL);
+
+ g_signal_connect (build_tools,
+ "modified",
+ G_CALLBACK (save_settings),
+ NULL);
+
+ xml_file = get_xml_file ();
+ latexila_build_tools_load (LATEXILA_BUILD_TOOLS (instance), xml_file);
+ g_object_unref (xml_file);
+}
+
+/**
+ * latexila_build_tools_default_get_instance:
+ *
+ * Gets the instance of the #LatexilaBuildToolsDefault singleton.
+ *
+ * Returns: the instance of #LatexilaBuildToolsDefault.
+ */
+LatexilaBuildToolsDefault *
+latexila_build_tools_default_get_instance (void)
+{
+ if (instance == NULL)
+ {
+ instance = g_object_new (LATEXILA_TYPE_BUILD_TOOLS_DEFAULT, NULL);
+ }
+
+ return instance;
+}
diff --git a/src/liblatexila/latexila-build-tools-default.h b/src/liblatexila/latexila-build-tools-default.h
new file mode 100644
index 0000000..c010aaa
--- /dev/null
+++ b/src/liblatexila/latexila-build-tools-default.h
@@ -0,0 +1,58 @@
+/*
+ * 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_DEFAULT_H__
+#define __LATEXILA_BUILD_TOOLS_DEFAULT_H__
+
+#include <glib-object.h>
+#include "latexila-build-tools.h"
+#include "latexila-types.h"
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_BUILD_TOOLS_DEFAULT (latexila_build_tools_default_get_type ())
+#define LATEXILA_BUILD_TOOLS_DEFAULT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
LATEXILA_TYPE_BUILD_TOOLS_DEFAULT, LatexilaBuildToolsDefault))
+#define LATEXILA_BUILD_TOOLS_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
LATEXILA_TYPE_BUILD_TOOLS_DEFAULT, LatexilaBuildToolsDefaultClass))
+#define LATEXILA_IS_BUILD_TOOLS_DEFAULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
LATEXILA_TYPE_BUILD_TOOLS_DEFAULT))
+#define LATEXILA_IS_BUILD_TOOLS_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
LATEXILA_TYPE_BUILD_TOOLS_DEFAULT))
+#define LATEXILA_BUILD_TOOLS_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
LATEXILA_TYPE_BUILD_TOOLS_DEFAULT, LatexilaBuildToolsDefaultClass))
+
+typedef struct _LatexilaBuildToolsDefaultClass LatexilaBuildToolsDefaultClass;
+typedef struct _LatexilaBuildToolsDefaultPrivate LatexilaBuildToolsDefaultPrivate;
+
+struct _LatexilaBuildToolsDefault
+{
+ LatexilaBuildTools parent;
+
+ LatexilaBuildToolsDefaultPrivate *priv;
+};
+
+struct _LatexilaBuildToolsDefaultClass
+{
+ LatexilaBuildToolsClass parent_class;
+};
+
+GType latexila_build_tools_default_get_type (void) G_GNUC_CONST;
+
+LatexilaBuildToolsDefault *
+ latexila_build_tools_default_get_instance (void);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_BUILD_TOOLS_DEFAULT_H__ */
diff --git a/src/liblatexila/latexila-build-tools-personal.c b/src/liblatexila/latexila-build-tools-personal.c
new file mode 100644
index 0000000..86ea295
--- /dev/null
+++ b/src/liblatexila/latexila-build-tools-personal.c
@@ -0,0 +1,409 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * SECTION:build-tools-personal
+ * @title: LatexilaBuildToolsPersonal
+ * @short_description: Personal build tools
+ *
+ * The #LatexilaBuildToolsPersonal singleton class represents the personal build
+ * tools. The personal build tools can be entirely modified. The XML file can be
+ * saved with latexila_build_tools_personal_save().
+ */
+
+#include "latexila-build-tools-personal.h"
+#include <gio/gio.h>
+
+static LatexilaBuildToolsPersonal *instance = NULL;
+
+struct _LatexilaBuildToolsPersonalPrivate
+{
+ /* Used for saving */
+ GString *xml_file_contents;
+
+ guint modified : 1;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildToolsPersonal, latexila_build_tools_personal,
LATEXILA_TYPE_BUILD_TOOLS)
+
+static void
+latexila_build_tools_personal_finalize (GObject *object)
+{
+ LatexilaBuildToolsPersonal *build_tools = LATEXILA_BUILD_TOOLS_PERSONAL (object);
+
+ if (build_tools->priv->xml_file_contents != NULL)
+ {
+ g_string_free (build_tools->priv->xml_file_contents, TRUE);
+ build_tools->priv->xml_file_contents = NULL;
+ }
+
+ G_OBJECT_CLASS (latexila_build_tools_personal_parent_class)->finalize (object);
+}
+
+static void
+latexila_build_tools_personal_class_init (LatexilaBuildToolsPersonalClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = latexila_build_tools_personal_finalize;
+}
+
+static GFile *
+get_xml_file (void)
+{
+ gchar *path;
+ GFile *file;
+
+ path = g_build_filename (g_get_user_config_dir (),
+ "latexila",
+ "build_tools.xml",
+ NULL);
+
+ file = g_file_new_for_path (path);
+ g_free (path);
+
+ return file;
+}
+
+static void
+modified_cb (LatexilaBuildToolsPersonal *build_tools)
+{
+ build_tools->priv->modified = TRUE;
+}
+
+static void
+latexila_build_tools_personal_init (LatexilaBuildToolsPersonal *build_tools)
+{
+ GFile *xml_file;
+
+ build_tools->priv = latexila_build_tools_personal_get_instance_private (build_tools);
+
+ g_signal_connect (build_tools,
+ "modified",
+ G_CALLBACK (modified_cb),
+ NULL);
+
+ xml_file = get_xml_file ();
+ latexila_build_tools_load (LATEXILA_BUILD_TOOLS (build_tools), xml_file);
+ g_object_unref (xml_file);
+}
+
+/**
+ * latexila_build_tools_personal_get_instance:
+ *
+ * Gets the instance of the #LatexilaBuildToolsPersonal singleton.
+ *
+ * Returns: the instance of #LatexilaBuildToolsPersonal.
+ */
+LatexilaBuildToolsPersonal *
+latexila_build_tools_personal_get_instance (void)
+{
+ if (instance == NULL)
+ {
+ instance = g_object_new (LATEXILA_TYPE_BUILD_TOOLS_PERSONAL, NULL);
+ }
+
+ return instance;
+}
+
+static void
+save_cb (GFile *xml_file,
+ GAsyncResult *result,
+ LatexilaBuildToolsPersonal *build_tools)
+{
+ GError *error = NULL;
+
+ g_file_replace_contents_finish (xml_file, result, NULL, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error while saving the personal build tools: %s",
+ error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ build_tools->priv->modified = FALSE;
+ }
+
+ g_string_free (build_tools->priv->xml_file_contents, TRUE);
+ build_tools->priv->xml_file_contents = NULL;
+
+ g_object_unref (build_tools);
+}
+
+/**
+ * latexila_build_tools_personal_save:
+ * @build_tools: a #LatexilaBuildToolsPersonal object.
+ *
+ * Saves the personal build tools into the XML file.
+ */
+void
+latexila_build_tools_personal_save (LatexilaBuildToolsPersonal *build_tools)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GString *contents;
+ GList *cur_build_tool;
+ GFile *xml_file;
+
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+
+ if (!build_tools->priv->modified)
+ {
+ return;
+ }
+
+ if (build_tools->priv->xml_file_contents != NULL)
+ {
+ g_string_free (build_tools->priv->xml_file_contents, TRUE);
+ }
+
+ contents = g_string_new ("<tools>");
+ build_tools->priv->xml_file_contents = contents;
+
+ for (cur_build_tool = build_tools_parent->build_tools;
+ cur_build_tool != NULL;
+ cur_build_tool = cur_build_tool->next)
+ {
+ LatexilaBuildTool *build_tool = cur_build_tool->data;
+ gchar *escaped_text;
+ GSList *cur_build_job;
+
+ g_string_append_printf (contents,
+ "\n <tool enabled=\"%s\" extensions=\"%s\" icon=\"%s\">\n",
+ build_tool->enabled ? "true" : "false",
+ build_tool->extensions != NULL ? build_tool->extensions : "",
+ build_tool->icon != NULL ? build_tool->icon : "");
+
+ escaped_text = g_markup_printf_escaped (" <label>%s</label>\n"
+ " <description>%s</description>\n",
+ build_tool->label != NULL ? build_tool->label : "",
+ build_tool->description != NULL ? build_tool->description :
"");
+
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
+
+ for (cur_build_job = build_tool->jobs;
+ cur_build_job != NULL;
+ cur_build_job = cur_build_job->next)
+ {
+ LatexilaBuildJob *build_job = cur_build_job->data;
+
+ escaped_text = g_markup_printf_escaped (" <job postProcessor=\"%s\">%s</job>\n",
+ latexila_get_post_processor_name_from_type
(build_job->post_processor_type),
+ build_job->command != NULL ? build_job->command : "");
+
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
+ }
+
+ escaped_text = g_markup_printf_escaped (" <open>%s</open>\n",
+ build_tool->files_to_open != NULL ? build_tool->files_to_open
: "");
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
+
+ g_string_append (contents, " </tool>\n");
+ }
+
+ g_string_append (contents, "</tools>\n");
+
+ /* Avoid finalization of build_tools during the async operation. */
+ g_object_ref (build_tools);
+
+ xml_file = get_xml_file ();
+
+ g_file_replace_contents_async (xml_file,
+ contents->str,
+ contents->len,
+ NULL,
+ TRUE, /* make a backup */
+ G_FILE_CREATE_NONE,
+ NULL,
+ (GAsyncReadyCallback) save_cb,
+ build_tools);
+
+ g_object_unref (xml_file);
+}
+
+/**
+ * latexila_build_tools_personal_move_up:
+ * @build_tools:
+ * @tool_num:
+ *
+ * Move a build tool up. The first build tool is at the top.
+ */
+void
+latexila_build_tools_personal_move_up (LatexilaBuildToolsPersonal *build_tools,
+ guint tool_num)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *node;
+ GList *prev_node;
+
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+
+ node = g_list_nth (build_tools_parent->build_tools, tool_num);
+ g_return_if_fail (node != NULL);
+
+ prev_node = node->prev;
+ g_return_if_fail (prev_node != NULL);
+
+ build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
+
+ build_tools_parent->build_tools = g_list_insert_before (build_tools_parent->build_tools,
+ prev_node,
+ node->data);
+
+ g_list_free (node);
+
+ g_signal_emit_by_name (build_tools, "modified");
+}
+
+/**
+ * latexila_build_tools_personal_move_down:
+ * @build_tools:
+ * @tool_num:
+ *
+ * Move a build tool down. The first build tool is at the top.
+ */
+void
+latexila_build_tools_personal_move_down (LatexilaBuildToolsPersonal *build_tools,
+ guint tool_num)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *node;
+ GList *next_node;
+
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+
+ node = g_list_nth (build_tools_parent->build_tools, tool_num);
+ g_return_if_fail (node != NULL);
+
+ next_node = node->next;
+ g_return_if_fail (next_node != NULL);
+
+ build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
+
+ build_tools_parent->build_tools = g_list_insert_before (build_tools_parent->build_tools,
+ next_node->next,
+ node->data);
+
+ g_list_free (node);
+
+ g_signal_emit_by_name (build_tools, "modified");
+}
+
+/**
+ * latexila_build_tools_personal_delete:
+ * @build_tools:
+ * @tool_num:
+ */
+void
+latexila_build_tools_personal_delete (LatexilaBuildToolsPersonal *build_tools,
+ guint tool_num)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *node;
+
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+
+ node = g_list_nth (build_tools_parent->build_tools, tool_num);
+ g_return_if_fail (node != NULL);
+
+ build_tools_parent->build_tools = g_list_remove_link (build_tools_parent->build_tools, node);
+
+ g_list_free_full (node, (GDestroyNotify) latexila_build_tool_free);
+
+ g_signal_emit_by_name (build_tools, "modified");
+}
+
+/**
+ * latexila_build_tools_personal_add:
+ * @build_tools:
+ * @new_build_tool:
+ *
+ * Append the new build tool at the end.
+ */
+void
+latexila_build_tools_personal_add (LatexilaBuildToolsPersonal *build_tools,
+ LatexilaBuildTool *new_build_tool)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+
+ build_tools_parent->build_tools = g_list_append (build_tools_parent->build_tools,
+ new_build_tool);
+
+ g_signal_emit_by_name (build_tools, "modified");
+}
+
+/**
+ * latexila_build_tools_personal_insert:
+ * @build_tools:
+ * @new_build_tool:
+ * @position:
+ *
+ * Inserts a new build tool at a given position.
+ */
+void
+latexila_build_tools_personal_insert (LatexilaBuildToolsPersonal *build_tools,
+ LatexilaBuildTool *new_build_tool,
+ guint position)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+
+ build_tools_parent->build_tools = g_list_insert (build_tools_parent->build_tools,
+ new_build_tool,
+ position);
+
+ g_signal_emit_by_name (build_tools, "modified");
+}
+
+/**
+ * latexila_build_tools_personal_replace:
+ * @build_tools:
+ * @new_build_tool:
+ * @position:
+ *
+ * Replaces a build tool.
+ */
+void
+latexila_build_tools_personal_replace (LatexilaBuildToolsPersonal *build_tools,
+ LatexilaBuildTool *new_build_tool,
+ guint position)
+{
+ LatexilaBuildTools *build_tools_parent = LATEXILA_BUILD_TOOLS (build_tools);
+ GList *node;
+
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS_PERSONAL (build_tools));
+
+ node = g_list_nth (build_tools_parent->build_tools, position);
+ g_return_if_fail (node != NULL);
+
+ if (node->data != new_build_tool)
+ {
+ latexila_build_tool_free (node->data);
+ node->data = new_build_tool;
+
+ g_signal_emit_by_name (build_tools, "modified");
+ }
+}
diff --git a/src/liblatexila/latexila-build-tools-personal.h b/src/liblatexila/latexila-build-tools-personal.h
new file mode 100644
index 0000000..1a1edb1
--- /dev/null
+++ b/src/liblatexila/latexila-build-tools-personal.h
@@ -0,0 +1,80 @@
+/*
+ * 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_PERSONAL_H__
+#define __LATEXILA_BUILD_TOOLS_PERSONAL_H__
+
+#include <glib-object.h>
+#include "latexila-build-tools.h"
+#include "latexila-types.h"
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_BUILD_TOOLS_PERSONAL (latexila_build_tools_personal_get_type ())
+#define LATEXILA_BUILD_TOOLS_PERSONAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
LATEXILA_TYPE_BUILD_TOOLS_PERSONAL, LatexilaBuildToolsPersonal))
+#define LATEXILA_BUILD_TOOLS_PERSONAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
LATEXILA_TYPE_BUILD_TOOLS_PERSONAL, LatexilaBuildToolsPersonalClass))
+#define LATEXILA_IS_BUILD_TOOLS_PERSONAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
LATEXILA_TYPE_BUILD_TOOLS_PERSONAL))
+#define LATEXILA_IS_BUILD_TOOLS_PERSONAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
LATEXILA_TYPE_BUILD_TOOLS_PERSONAL))
+#define LATEXILA_BUILD_TOOLS_PERSONAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
LATEXILA_TYPE_BUILD_TOOLS_PERSONAL, LatexilaBuildToolsPersonalClass))
+
+typedef struct _LatexilaBuildToolsPersonalClass LatexilaBuildToolsPersonalClass;
+typedef struct _LatexilaBuildToolsPersonalPrivate LatexilaBuildToolsPersonalPrivate;
+
+struct _LatexilaBuildToolsPersonal
+{
+ LatexilaBuildTools parent;
+
+ LatexilaBuildToolsPersonalPrivate *priv;
+};
+
+struct _LatexilaBuildToolsPersonalClass
+{
+ LatexilaBuildToolsClass parent_class;
+};
+
+GType latexila_build_tools_personal_get_type (void) G_GNUC_CONST;
+
+LatexilaBuildToolsPersonal *
+ latexila_build_tools_personal_get_instance (void);
+
+void latexila_build_tools_personal_save (LatexilaBuildToolsPersonal
*build_tools);
+
+void latexila_build_tools_personal_move_up (LatexilaBuildToolsPersonal
*build_tools,
+ guint tool_num);
+
+void latexila_build_tools_personal_move_down (LatexilaBuildToolsPersonal
*build_tools,
+ guint tool_num);
+
+void latexila_build_tools_personal_delete (LatexilaBuildToolsPersonal
*build_tools,
+ guint tool_num);
+
+void latexila_build_tools_personal_add (LatexilaBuildToolsPersonal
*build_tools,
+ LatexilaBuildTool
*new_build_tool);
+
+void latexila_build_tools_personal_insert (LatexilaBuildToolsPersonal
*build_tools,
+ LatexilaBuildTool
*new_build_tool,
+ guint position);
+
+void latexila_build_tools_personal_replace (LatexilaBuildToolsPersonal
*build_tools,
+ LatexilaBuildTool
*new_build_tool,
+ guint position);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_BUILD_TOOLS_PERSONAL_H__ */
diff --git a/src/liblatexila/latexila-build-tools.c b/src/liblatexila/latexila-build-tools.c
new file mode 100644
index 0000000..06a9336
--- /dev/null
+++ b/src/liblatexila/latexila-build-tools.c
@@ -0,0 +1,571 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * SECTION:build-tools
+ * @title: LatexilaBuildTools
+ * @short_description: Build tools base class
+ *
+ * Base class for the build tools. The build tools are stored in an XML file.
+ * The XML file is loaded into data structures in memory.
+ */
+
+#include "config.h"
+#include "latexila-build-tools.h"
+#include <glib/gi18n.h>
+#include "latexila-build-tools-default.h"
+
+struct _LatexilaBuildToolsPrivate
+{
+ /* Used during the XML file parsing to load the build tools. */
+ LatexilaBuildTool *cur_tool;
+ LatexilaBuildJob *cur_job;
+};
+
+enum
+{
+ SIGNAL_LOADED,
+ SIGNAL_MODIFIED,
+ LAST_SIGNAL
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildTools, latexila_build_tools, G_TYPE_OBJECT)
+
+static guint signals[LAST_SIGNAL];
+
+static LatexilaBuildJob *
+build_job_new (void)
+{
+ return g_slice_new0 (LatexilaBuildJob);
+}
+
+static void
+build_job_free (LatexilaBuildJob *build_job)
+{
+ if (build_job != NULL)
+ {
+ g_free (build_job->command);
+ g_slice_free (LatexilaBuildJob, build_job);
+ }
+}
+
+static LatexilaBuildTool *
+build_tool_new (void)
+{
+ return g_slice_new0 (LatexilaBuildTool);
+}
+
+/**
+ * latexila_build_tool_free:
+ * @build_tool: the build tool to free.
+ */
+void
+latexila_build_tool_free (LatexilaBuildTool *build_tool)
+{
+ if (build_tool != NULL)
+ {
+ 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);
+ }
+}
+
+/**
+ * latexila_build_tool_get_description:
+ * @build_tool: a #LatexilaBuildTool.
+ *
+ * Gets the description. The label is returned if the description is empty.
+ *
+ * Returns: the description.
+ */
+const gchar *
+latexila_build_tool_get_description (LatexilaBuildTool *build_tool)
+{
+ if (build_tool->description == NULL ||
+ build_tool->description[0] == '\0')
+ {
+ return build_tool->label;
+ }
+
+ return build_tool->description;
+}
+
+/**
+ * latexila_get_post_processor_type_from_name:
+ * @name: the name of the post-processor.
+ * @type: the output post-processor type.
+ *
+ * Returns: %TRUE on success, %FALSE otherwise.
+ */
+gboolean
+latexila_get_post_processor_type_from_name (const gchar *name,
+ LatexilaPostProcessorType *type)
+{
+ g_assert (type != NULL);
+
+ if (g_str_equal (name, "latexmk"))
+ {
+ *type = LATEXILA_POST_PROCESSOR_TYPE_LATEXMK;
+ return TRUE;
+ }
+
+ if (g_str_equal (name, "latex"))
+ {
+ *type = LATEXILA_POST_PROCESSOR_TYPE_LATEX;
+ return TRUE;
+ }
+
+ if (g_str_equal (name, "all-output"))
+ {
+ *type = LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT;
+ return TRUE;
+ }
+
+ if (g_str_equal (name, "no-output"))
+ {
+ *type = LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/**
+ * latexila_get_post_processor_name_from_type:
+ * @type: the post-processor type.
+ *
+ * Returns: the post-processor name.
+ */
+const gchar *
+latexila_get_post_processor_name_from_type (LatexilaPostProcessorType type)
+{
+ switch (type)
+ {
+ case LATEXILA_POST_PROCESSOR_TYPE_LATEXMK:
+ return "latexmk";
+
+ case LATEXILA_POST_PROCESSOR_TYPE_LATEX:
+ return "latex";
+
+ case LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT:
+ return "all-output";
+
+ case LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT:
+ return "no-output";
+
+ default:
+ g_return_val_if_reached (NULL);
+ }
+}
+
+static void
+latexila_build_tools_finalize (GObject *object)
+{
+ LatexilaBuildTools *build_tools = LATEXILA_BUILD_TOOLS (object);
+
+ g_list_free_full (build_tools->build_tools, (GDestroyNotify) latexila_build_tool_free);
+ latexila_build_tool_free (build_tools->priv->cur_tool);
+ build_job_free (build_tools->priv->cur_job);
+
+ 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->finalize = latexila_build_tools_finalize;
+
+ /**
+ * LatexilaBuildTools::loaded:
+ * @build_tools: a #LatexilaBuildTools object.
+ *
+ * The ::loaded signal is emitted when the build tools are fully loaded.
+ */
+ signals[SIGNAL_LOADED] = g_signal_new ("loaded",
+ LATEXILA_TYPE_BUILD_TOOLS,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+ /**
+ * LatexilaBuildTools::modified:
+ * @build_tools: a #LatexilaBuildTools object.
+ *
+ * The ::modified signal is emitted when a build tool is modified.
+ */
+ signals[SIGNAL_MODIFIED] = g_signal_new ("modified",
+ LATEXILA_TYPE_BUILD_TOOLS,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+}
+
+static void
+latexila_build_tools_init (LatexilaBuildTools *build_tools)
+{
+ build_tools->priv = latexila_build_tools_get_instance_private (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;
+
+ latexila_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;
+
+ 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"))
+ {
+ LatexilaPostProcessorType type;
+
+ if (latexila_get_post_processor_type_from_name (attribute_values[i], &type))
+ {
+ cur_job->post_processor_type = type;
+ }
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ "unknown post processor \"%s\"",
+ attribute_values[i]);
+ }
+ }
+
+ /* 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)
+{
+ 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 = build_tools->priv->cur_tool;
+
+ cur_tool->jobs = g_slist_reverse (cur_tool->jobs);
+
+ build_tools->build_tools = g_list_prepend (build_tools->build_tools, cur_tool);
+
+ build_tools->priv->cur_tool = NULL;
+ }
+
+ else if (g_str_equal (element_name, "job"))
+ {
+ LatexilaBuildTool *cur_tool = build_tools->priv->cur_tool;
+
+ cur_tool->jobs = g_slist_prepend (cur_tool->jobs,
+ build_tools->priv->cur_job);
+
+ build_tools->priv->cur_job = NULL;
+ }
+
+ else if (error != NULL)
+ {
+ *error = g_error_new (G_MARKUP_ERROR,
+ G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ "unknown element \"%s\"",
+ element_name);
+ }
+}
+
+static void
+parser_text (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error)
+{
+ LatexilaBuildTools *build_tools = user_data;
+ const gchar *element_name = g_markup_parse_context_get_element (context);
+ gchar *stripped_text = g_strdup (text);
+ stripped_text = g_strstrip (stripped_text);
+
+ if (g_str_equal (element_name, "job") &&
+ build_tools->priv->cur_job != NULL)
+ {
+ g_free (build_tools->priv->cur_job->command);
+ build_tools->priv->cur_job->command = stripped_text;
+ }
+
+ else if (g_str_equal (element_name, "label") &&
+ build_tools->priv->cur_tool != NULL)
+ {
+ g_free (build_tools->priv->cur_tool->label);
+ build_tools->priv->cur_tool->label = g_strdup (_(stripped_text));
+
+ g_free (stripped_text);
+ }
+
+ else if (g_str_equal (element_name, "description") &&
+ build_tools->priv->cur_tool != NULL)
+ {
+ g_free (build_tools->priv->cur_tool->description);
+ build_tools->priv->cur_tool->description = g_strdup (_(stripped_text));
+
+ g_free (stripped_text);
+ }
+
+ else if (g_str_equal (element_name, "open") &&
+ build_tools->priv->cur_tool != NULL)
+ {
+ g_free (build_tools->priv->cur_tool->files_to_open);
+ build_tools->priv->cur_tool->files_to_open = stripped_text;
+ }
+
+ else
+ {
+ g_free (stripped_text);
+ }
+}
+
+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:
+ build_tools->build_tools = g_list_reverse (build_tools->build_tools);
+
+ g_markup_parse_context_free (context);
+ g_free (contents);
+
+ g_signal_emit (build_tools, signals[SIGNAL_LOADED], 0);
+}
+
+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)
+ {
+ if (LATEXILA_IS_BUILD_TOOLS_DEFAULT (build_tools))
+ {
+ gchar *path = g_file_get_parse_name (xml_file);
+ g_warning ("XML file not found for the default build tools: %s", path);
+ g_free (path);
+ }
+
+ /* For the personal build tools it means that there is simply no
+ * personal build tools, it is not an error.
+ */
+ }
+ else
+ {
+ g_warning ("Error while loading the contents of the build tools XML file: %s",
+ error->message);
+ }
+
+ g_error_free (error);
+ }
+
+ if (contents != NULL)
+ {
+ parse_contents (build_tools, contents);
+ }
+
+ g_object_unref (build_tools);
+}
+
+/**
+ * latexila_build_tools_load:
+ * @build_tools:
+ * @xml_file:
+ *
+ * Loads asynchronously the XML file contents and parses it.
+ * This function is used by subclasses of #LatexilaBuildTools.
+ * When the file is fully loaded, the #LatexilaBuildTools::loaded signal is
+ * emitted.
+ */
+void
+latexila_build_tools_load (LatexilaBuildTools *build_tools,
+ GFile *xml_file)
+{
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOLS (build_tools));
+ g_return_if_fail (G_IS_FILE (xml_file));
+
+ /* Avoid finalization of build_tools during the async operation. */
+ g_object_ref (build_tools);
+
+ g_file_load_contents_async (xml_file,
+ NULL,
+ (GAsyncReadyCallback) load_contents_cb,
+ build_tools);
+}
+
+/**
+ * latexila_build_tools_set_enabled:
+ * @build_tools:
+ * @tool_num:
+ * @enabled:
+ */
+void
+latexila_build_tools_set_enabled (LatexilaBuildTools *build_tools,
+ guint tool_num,
+ gboolean enabled)
+{
+ LatexilaBuildTool *build_tool = g_list_nth_data (build_tools->build_tools, tool_num);
+
+ g_return_if_fail (build_tool != NULL);
+
+ if (build_tool->enabled != enabled)
+ {
+ build_tool->enabled = enabled;
+ g_signal_emit (build_tools, signals[SIGNAL_MODIFIED], 0);
+ }
+}
diff --git a/src/liblatexila/latexila-build-tools.h b/src/liblatexila/latexila-build-tools.h
new file mode 100644
index 0000000..1677694
--- /dev/null
+++ b/src/liblatexila/latexila-build-tools.h
@@ -0,0 +1,108 @@
+/*
+ * 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 <gio/gio.h>
+#include "latexila-types.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 _LatexilaBuildToolsClass LatexilaBuildToolsClass;
+typedef struct _LatexilaBuildToolsPrivate LatexilaBuildToolsPrivate;
+
+struct _LatexilaBuildTools
+{
+ GObject parent;
+
+ /* A list of LatexilaBuildTool's.
+ * External code should just read the list, not modify it.
+ */
+ GList *build_tools;
+
+ 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;
+
+GType latexila_build_tools_get_type (void) G_GNUC_CONST;
+
+void latexila_build_tool_free (LatexilaBuildTool *build_tool);
+
+const gchar * latexila_build_tool_get_description (LatexilaBuildTool *build_tool);
+
+gboolean latexila_get_post_processor_type_from_name (const gchar *name,
+ LatexilaPostProcessorType *type);
+
+const gchar * latexila_get_post_processor_name_from_type (LatexilaPostProcessorType type);
+
+void latexila_build_tools_load (LatexilaBuildTools *build_tools,
+ GFile *xml_file);
+
+void latexila_build_tools_set_enabled (LatexilaBuildTools *build_tools,
+ guint tool_num,
+ gboolean enabled);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_BUILD_TOOLS_H__ */
diff --git a/src/liblatexila/latexila-post-processor-all-output.h
b/src/liblatexila/latexila-post-processor-all-output.h
index 44c4926..6ae5d67 100644
--- a/src/liblatexila/latexila-post-processor-all-output.h
+++ b/src/liblatexila/latexila-post-processor-all-output.h
@@ -20,7 +20,9 @@
#ifndef __LATEXILA_POST_PROCESSOR_ALL_OUTPUT_H__
#define __LATEXILA_POST_PROCESSOR_ALL_OUTPUT_H__
+#include <glib-object.h>
#include "latexila-post-processor.h"
+#include "latexila-types.h"
G_BEGIN_DECLS
@@ -31,7 +33,6 @@ G_BEGIN_DECLS
#define LATEXILA_IS_POST_PROCESSOR_ALL_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
LATEXILA_TYPE_POST_PROCESSOR_ALL_OUTPUT))
#define LATEXILA_POST_PROCESSOR_ALL_OUTPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
LATEXILA_TYPE_POST_PROCESSOR_ALL_OUTPUT, LatexilaPostProcessorAllOutputClass))
-typedef struct _LatexilaPostProcessorAllOutput LatexilaPostProcessorAllOutput;
typedef struct _LatexilaPostProcessorAllOutputClass LatexilaPostProcessorAllOutputClass;
typedef struct _LatexilaPostProcessorAllOutputPrivate LatexilaPostProcessorAllOutputPrivate;
diff --git a/src/liblatexila/latexila-post-processor.h b/src/liblatexila/latexila-post-processor.h
index f8096bc..b889d38 100644
--- a/src/liblatexila/latexila-post-processor.h
+++ b/src/liblatexila/latexila-post-processor.h
@@ -22,6 +22,7 @@
#include <glib.h>
#include <glib-object.h>
+#include "latexila-types.h"
G_BEGIN_DECLS
@@ -32,7 +33,6 @@ G_BEGIN_DECLS
#define LATEXILA_IS_POST_PROCESSOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
LATEXILA_TYPE_POST_PROCESSOR))
#define LATEXILA_POST_PROCESSOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
LATEXILA_TYPE_POST_PROCESSOR, LatexilaPostProcessorClass))
-typedef struct _LatexilaPostProcessor LatexilaPostProcessor;
typedef struct _LatexilaPostProcessorClass LatexilaPostProcessorClass;
typedef struct _LatexilaPostProcessorPrivate LatexilaPostProcessorPrivate;
diff --git a/src/liblatexila/latexila-types.h b/src/liblatexila/latexila-types.h
new file mode 100644
index 0000000..64f5523
--- /dev/null
+++ b/src/liblatexila/latexila-types.h
@@ -0,0 +1,35 @@
+/*
+ * 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_TYPES_H__
+#define __LATEXILA_TYPES_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _LatexilaBuildTools LatexilaBuildTools;
+typedef struct _LatexilaBuildToolsDefault LatexilaBuildToolsDefault;
+typedef struct _LatexilaBuildToolsPersonal LatexilaBuildToolsPersonal;
+typedef struct _LatexilaPostProcessor LatexilaPostProcessor;
+typedef struct _LatexilaPostProcessorAllOutput LatexilaPostProcessorAllOutput;
+
+G_END_DECLS
+
+#endif /* __LATEXILA_TYPES_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]