[latexila/wip/build-tools-revamp] BuildTool and BuildJob classes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/wip/build-tools-revamp] BuildTool and BuildJob classes
- Date: Sun, 4 May 2014 17:54:50 +0000 (UTC)
commit f821b8363cabb9c8c2907a05713a49265913c524
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu May 1 15:14:56 2014 +0200
BuildTool and BuildJob classes
And add enum types.
configure.ac | 1 +
docs/reference/latexila-docs.xml | 2 +
docs/reference/latexila-sections.txt | 45 +++-
src/liblatexila/Makefile.am | 36 ++-
src/liblatexila/latexila-build-job.c | 175 +++++++++++
src/liblatexila/latexila-build-job.h | 59 ++++
src/liblatexila/latexila-build-tool.c | 377 +++++++++++++++++++++++
src/liblatexila/latexila-build-tool.h | 63 ++++
src/liblatexila/latexila-build-tools-default.c | 20 +-
src/liblatexila/latexila-build-tools-personal.c | 66 ++---
src/liblatexila/latexila-build-tools.c | 228 +++------------
src/liblatexila/latexila-build-tools.h | 63 ----
src/liblatexila/latexila-enum-types.c.template | 41 +++
src/liblatexila/latexila-enum-types.h.template | 26 ++
src/liblatexila/latexila-post-processor.c | 68 ++++
src/liblatexila/latexila-post-processor.h | 31 ++-
src/liblatexila/latexila-types.h | 2 +
17 files changed, 981 insertions(+), 322 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c1d8ca0..860cb70 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,6 +74,7 @@ AC_PROG_CC
AC_PROG_INSTALL
AM_PROG_CC_C_O
AC_PATH_PROG([GLIB_COMPILE_RESOURCES], [glib-compile-resources])
+AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums])
AM_PROG_VALAC([${VALA_REQUIRED_VERSION}],
[found_vala=true]
[found_vala=false])
diff --git a/docs/reference/latexila-docs.xml b/docs/reference/latexila-docs.xml
index f12c1c6..018642e 100644
--- a/docs/reference/latexila-docs.xml
+++ b/docs/reference/latexila-docs.xml
@@ -14,6 +14,8 @@
<xi:include href="xml/build-tools.xml"/>
<xi:include href="xml/build-tools-default.xml"/>
<xi:include href="xml/build-tools-personal.xml"/>
+ <xi:include href="xml/build-tool.xml"/>
+ <xi:include href="xml/build-job.xml"/>
</chapter>
<chapter id="object-tree">
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index 544000c..cd7bf83 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -4,13 +4,6 @@
<FILE>build-tools</FILE>
<TITLE>LatexilaBuildTools</TITLE>
LatexilaBuildTools
-LatexilaBuildTool
-LatexilaBuildJob
-LatexilaPostProcessorType
-latexila_build_tool_get_description
-latexila_build_tool_free
-latexila_get_post_processor_type_from_name
-latexila_get_post_processor_name_from_type
latexila_build_tools_load
latexila_build_tools_set_enabled
<SUBSECTION Standard>
@@ -62,3 +55,41 @@ LATEXILA_TYPE_BUILD_TOOLS_PERSONAL
latexila_build_tools_personal_get_type
LatexilaBuildToolsPersonalPrivate
</SECTION>
+
+<SECTION>
+<FILE>build-tool</FILE>
+<TITLE>LatexilaBuildTool</TITLE>
+LatexilaBuildTool
+latexila_build_tool_new
+latexila_build_tool_add_job
+latexila_build_tool_get_description
+latexila_build_tool_to_xml
+<SUBSECTION Standard>
+LATEXILA_BUILD_TOOL
+LATEXILA_BUILD_TOOL_CLASS
+LATEXILA_BUILD_TOOL_GET_CLASS
+LATEXILA_IS_BUILD_TOOL
+LATEXILA_IS_BUILD_TOOL_CLASS
+LATEXILA_TYPE_BUILD_TOOL
+LatexilaBuildToolClass
+LatexilaBuildToolPrivate
+latexila_build_tool_get_type
+</SECTION>
+
+<SECTION>
+<FILE>build-job</FILE>
+<TITLE>LatexilaBuildJob</TITLE>
+LatexilaBuildJob
+latexila_build_job_new
+latexila_build_job_to_xml
+<SUBSECTION Standard>
+LATEXILA_BUILD_JOB
+LATEXILA_BUILD_JOB_CLASS
+LATEXILA_BUILD_JOB_GET_CLASS
+LATEXILA_IS_BUILD_JOB
+LATEXILA_IS_BUILD_JOB_CLASS
+LATEXILA_TYPE_BUILD_JOB
+LatexilaBuildJobClass
+LatexilaBuildJobPrivate
+latexila_build_job_get_type
+</SECTION>
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 27a7ff2..d377ce1 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -2,19 +2,43 @@ AM_CPPFLAGS = $(WARN_CFLAGS)
noinst_LTLIBRARIES = liblatexila.la
-liblatexila_la_SOURCES = \
- latexila-build-tools.c \
+liblatexila_headers = \
+ latexila-build-job.h \
+ latexila-build-tool.h \
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-types.h
+BUILT_SOURCES = \
+ latexila-enum-types.c \
+ latexila-enum-types.h
+
+liblatexila_la_SOURCES = \
+ latexila-build-job.c \
+ latexila-build-tool.c \
+ latexila-build-tools.c \
+ latexila-build-tools-default.c \
+ latexila-build-tools-personal.c \
+ latexila-post-processor.c \
+ latexila-post-processor-all-output.c \
+ $(liblatexila_headers) \
+ $(BUILT_SOURCES)
+
+ENUM_TYPES = $(liblatexila_headers)
+
+latexila-enum-types.h: latexila-enum-types.h.template $(ENUM_TYPES) $(GLIB_MKENUMS)
+ $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template latexila-enum-types.h.template $(ENUM_TYPES))
$@
+
+latexila-enum-types.c: latexila-enum-types.c.template $(ENUM_TYPES) $(GLIB_MKENUMS)
+ $(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template latexila-enum-types.c.template $(ENUM_TYPES))
$@
+
+EXTRA_DIST = \
+ latexila-enum-types.c.template \
+ latexila-enum-types.h.template
+
noinst_DATA =
CLEANFILES =
diff --git a/src/liblatexila/latexila-build-job.c b/src/liblatexila/latexila-build-job.c
new file mode 100644
index 0000000..bacf1f4
--- /dev/null
+++ b/src/liblatexila/latexila-build-job.c
@@ -0,0 +1,175 @@
+/*
+ * 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-job
+ * @title: LatexilaBuildJob
+ * @short_description: Build job
+ *
+ * A build job. It contains a command (as a string) and a post-processor type.
+ */
+
+#include "latexila-build-job.h"
+#include "latexila-enum-types.h"
+
+struct _LatexilaBuildJobPrivate
+{
+ gchar *command;
+ LatexilaPostProcessorType post_processor_type;
+};
+
+enum
+{
+ PROP_0,
+ PROP_COMMAND,
+ PROP_POST_PROCESSOR_TYPE
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildJob, latexila_build_job, G_TYPE_OBJECT)
+
+static void
+latexila_build_job_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
+
+ switch (prop_id)
+ {
+ case PROP_COMMAND:
+ g_value_set_string (value, build_job->priv->command);
+ break;
+
+ case PROP_POST_PROCESSOR_TYPE:
+ g_value_set_enum (value, build_job->priv->post_processor_type);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+latexila_build_job_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
+
+ switch (prop_id)
+ {
+ case PROP_COMMAND:
+ g_free (build_job->priv->command);
+ build_job->priv->command = g_value_dup_string (value);
+ break;
+
+ case PROP_POST_PROCESSOR_TYPE:
+ build_job->priv->post_processor_type = g_value_get_enum (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+latexila_build_job_dispose (GObject *object)
+{
+
+ G_OBJECT_CLASS (latexila_build_job_parent_class)->dispose (object);
+}
+
+static void
+latexila_build_job_finalize (GObject *object)
+{
+ LatexilaBuildJob *build_job = LATEXILA_BUILD_JOB (object);
+
+ g_free (build_job->priv->command);
+
+ G_OBJECT_CLASS (latexila_build_job_parent_class)->finalize (object);
+}
+
+static void
+latexila_build_job_class_init (LatexilaBuildJobClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = latexila_build_job_get_property;
+ object_class->set_property = latexila_build_job_set_property;
+ object_class->dispose = latexila_build_job_dispose;
+ object_class->finalize = latexila_build_job_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_COMMAND,
+ g_param_spec_string ("command",
+ "Command",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_POST_PROCESSOR_TYPE,
+ g_param_spec_enum ("post-processor-type",
+ "Post-processor type",
+ "",
+ LATEXILA_TYPE_POST_PROCESSOR_TYPE,
+ LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+latexila_build_job_init (LatexilaBuildJob *self)
+{
+ self->priv = latexila_build_job_get_instance_private (self);
+}
+
+/**
+ * latexila_build_job_new:
+ *
+ * Returns: a new #LatexilaBuildJob object.
+ */
+LatexilaBuildJob *
+latexila_build_job_new (void)
+{
+ return g_object_new (LATEXILA_TYPE_BUILD_JOB, NULL);
+}
+
+/**
+ * latexila_build_job_to_xml:
+ * @build_job: a #LatexilaBuildJob object.
+ *
+ * Returns: the XML contents of the @build_job. Free with g_free().
+ */
+gchar *
+latexila_build_job_to_xml (LatexilaBuildJob *build_job)
+{
+ g_return_val_if_fail (LATEXILA_IS_BUILD_JOB (build_job), NULL);
+
+ return g_markup_printf_escaped (" <job postProcessor=\"%s\">%s</job>\n",
+ latexila_post_processor_get_name_from_type
(build_job->priv->post_processor_type),
+ build_job->priv->command != NULL ? build_job->priv->command : "");
+}
diff --git a/src/liblatexila/latexila-build-job.h b/src/liblatexila/latexila-build-job.h
new file mode 100644
index 0000000..d636bc7
--- /dev/null
+++ b/src/liblatexila/latexila-build-job.h
@@ -0,0 +1,59 @@
+/*
+ * 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_JOB_H__
+#define __LATEXILA_BUILD_JOB_H__
+
+#include <glib-object.h>
+#include "latexila-types.h"
+#include "latexila-post-processor.h"
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_BUILD_JOB (latexila_build_job_get_type ())
+#define LATEXILA_BUILD_JOB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LATEXILA_TYPE_BUILD_JOB,
LatexilaBuildJob))
+#define LATEXILA_BUILD_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LATEXILA_TYPE_BUILD_JOB,
LatexilaBuildJobClass))
+#define LATEXILA_IS_BUILD_JOB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LATEXILA_TYPE_BUILD_JOB))
+#define LATEXILA_IS_BUILD_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LATEXILA_TYPE_BUILD_JOB))
+#define LATEXILA_BUILD_JOB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LATEXILA_TYPE_BUILD_JOB,
LatexilaBuildJobClass))
+
+typedef struct _LatexilaBuildJobClass LatexilaBuildJobClass;
+typedef struct _LatexilaBuildJobPrivate LatexilaBuildJobPrivate;
+
+struct _LatexilaBuildJob
+{
+ GObject parent;
+
+ LatexilaBuildJobPrivate *priv;
+};
+
+struct _LatexilaBuildJobClass
+{
+ GObjectClass parent_class;
+};
+
+GType latexila_build_job_get_type (void) G_GNUC_CONST;
+
+LatexilaBuildJob * latexila_build_job_new (void);
+
+gchar * latexila_build_job_to_xml (LatexilaBuildJob *build_job);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_BUILD_JOB_H__ */
diff --git a/src/liblatexila/latexila-build-tool.c b/src/liblatexila/latexila-build-tool.c
new file mode 100644
index 0000000..2e26860
--- /dev/null
+++ b/src/liblatexila/latexila-build-tool.c
@@ -0,0 +1,377 @@
+/*
+ * 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-tool
+ * @title: LatexilaBuildTool
+ * @short_description: Build tool
+ *
+ * A build tool. It contains some basic properties: a label, a description, an
+ * icon, etc. It contains a list of file extensions for which the build tool can
+ * run on. More interestingly, it contains the list of #LatexilaBuildJob's to
+ * run. And a list of files to open when the build jobs are successfully run.
+ */
+
+#include "latexila-build-tool.h"
+#include "latexila-build-job.h"
+
+struct _LatexilaBuildToolPrivate
+{
+ gchar *label;
+ gchar *description;
+ gchar *extensions;
+ gchar *icon;
+ gchar *files_to_open;
+ gint id;
+
+ /* A list of LatexilaBuildJob's. */
+ GQueue *jobs;
+
+ guint enabled : 1;
+};
+
+enum
+{
+ PROP_0,
+ PROP_LABEL,
+ PROP_DESCRIPTION,
+ PROP_EXTENSIONS,
+ PROP_ICON,
+ PROP_FILES_TO_OPEN,
+ PROP_ID,
+ PROP_ENABLED
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildTool, latexila_build_tool, G_TYPE_OBJECT)
+
+static void
+latexila_build_tool_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
+
+ switch (prop_id)
+ {
+ case PROP_LABEL:
+ g_value_set_string (value, build_tool->priv->label);
+ break;
+
+ case PROP_DESCRIPTION:
+ g_value_set_string (value, build_tool->priv->description);
+ break;
+
+ case PROP_EXTENSIONS:
+ g_value_set_string (value, build_tool->priv->extensions);
+ break;
+
+ case PROP_ICON:
+ g_value_set_string (value, build_tool->priv->icon);
+ break;
+
+ case PROP_FILES_TO_OPEN:
+ g_value_set_string (value, build_tool->priv->files_to_open);
+ break;
+
+ case PROP_ID:
+ g_value_set_int (value, build_tool->priv->id);
+ break;
+
+ case PROP_ENABLED:
+ g_value_set_boolean (value, build_tool->priv->enabled);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+latexila_build_tool_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
+
+ switch (prop_id)
+ {
+ case PROP_LABEL:
+ g_free (build_tool->priv->label);
+ build_tool->priv->label = g_value_dup_string (value);
+ break;
+
+ case PROP_DESCRIPTION:
+ g_free (build_tool->priv->description);
+ build_tool->priv->description = g_value_dup_string (value);
+ break;
+
+ case PROP_EXTENSIONS:
+ g_free (build_tool->priv->extensions);
+ build_tool->priv->extensions = g_value_dup_string (value);
+ break;
+
+ case PROP_ICON:
+ g_free (build_tool->priv->icon);
+ build_tool->priv->icon = g_value_dup_string (value);
+ break;
+
+ case PROP_FILES_TO_OPEN:
+ g_free (build_tool->priv->files_to_open);
+ build_tool->priv->files_to_open = g_value_dup_string (value);
+ break;
+
+ case PROP_ID:
+ build_tool->priv->id = g_value_get_int (value);
+ break;
+
+ case PROP_ENABLED:
+ build_tool->priv->enabled = g_value_get_boolean (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+latexila_build_tool_dispose (GObject *object)
+{
+ LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
+
+ if (build_tool->priv->jobs != NULL)
+ {
+ g_queue_free_full (build_tool->priv->jobs, g_object_unref);
+ build_tool->priv->jobs = NULL;
+ }
+
+ G_OBJECT_CLASS (latexila_build_tool_parent_class)->dispose (object);
+}
+
+static void
+latexila_build_tool_finalize (GObject *object)
+{
+ LatexilaBuildTool *build_tool = LATEXILA_BUILD_TOOL (object);
+
+ g_free (build_tool->priv->label);
+ g_free (build_tool->priv->description);
+ g_free (build_tool->priv->extensions);
+ g_free (build_tool->priv->icon);
+ g_free (build_tool->priv->files_to_open);
+
+ G_OBJECT_CLASS (latexila_build_tool_parent_class)->finalize (object);
+}
+
+static void
+latexila_build_tool_class_init (LatexilaBuildToolClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = latexila_build_tool_get_property;
+ object_class->set_property = latexila_build_tool_set_property;
+ object_class->dispose = latexila_build_tool_dispose;
+ object_class->finalize = latexila_build_tool_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_LABEL,
+ g_param_spec_string ("label",
+ "Label",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_DESCRIPTION,
+ g_param_spec_string ("description",
+ "Description",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_EXTENSIONS,
+ g_param_spec_string ("extensions",
+ "Extensions",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_ICON,
+ g_param_spec_string ("icon",
+ "Icon",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_FILES_TO_OPEN,
+ g_param_spec_string ("files-to-open",
+ "Files to open",
+ "",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * LatexilaBuildTool:id:
+ *
+ * The build tool ID. It is used only by the default build tools, for saving
+ * in #GSettings the lists of enabled/disabled build tools.
+ */
+ g_object_class_install_property (object_class,
+ PROP_ID,
+ g_param_spec_int ("id",
+ "ID",
+ "",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_ENABLED,
+ g_param_spec_boolean ("enabled",
+ "Enabled",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+latexila_build_tool_init (LatexilaBuildTool *self)
+{
+ self->priv = latexila_build_tool_get_instance_private (self);
+
+ self->priv->jobs = g_queue_new ();
+}
+
+/**
+ * latexila_build_tool_new:
+ *
+ * Returns: a new #LatexilaBuildTool object.
+ */
+LatexilaBuildTool *
+latexila_build_tool_new (void)
+{
+ return g_object_new (LATEXILA_TYPE_BUILD_TOOL, NULL);
+}
+
+/**
+ * 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->priv->description == NULL ||
+ build_tool->priv->description[0] == '\0')
+ {
+ return build_tool->priv->label;
+ }
+
+ return build_tool->priv->description;
+}
+
+/**
+ * latexila_build_tool_add_job:
+ * @build_tool: a #LatexilaBuildTool.
+ * @build_job: a #LatexilaBuildJob.
+ *
+ * Adds a build job at the end of the list (in O(1)).
+ */
+void
+latexila_build_tool_add_job (LatexilaBuildTool *build_tool,
+ LatexilaBuildJob *build_job)
+{
+ g_return_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool));
+ g_return_if_fail (LATEXILA_IS_BUILD_JOB (build_job));
+
+ g_queue_push_tail (build_tool->priv->jobs, build_job);
+}
+
+/**
+ * latexila_build_tool_to_xml:
+ * @tool: a #LatexilaBuildTool object.
+ *
+ * Returns: the XML contents of the build tool. Free with g_free().
+ */
+gchar *
+latexila_build_tool_to_xml (LatexilaBuildTool *tool)
+{
+ GString *contents;
+ gchar *escaped_text;
+ GList *l;
+
+ g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (tool), NULL);
+
+ contents = g_string_new (NULL);
+
+ g_string_append_printf (contents,
+ "\n <tool enabled=\"%s\" extensions=\"%s\" icon=\"%s\">\n",
+ tool->priv->enabled ? "true" : "false",
+ tool->priv->extensions != NULL ? tool->priv->extensions : "",
+ tool->priv->icon != NULL ? tool->priv->icon : "");
+
+ escaped_text = g_markup_printf_escaped (" <label>%s</label>\n"
+ " <description>%s</description>\n",
+ tool->priv->label != NULL ? tool->priv->label : "",
+ tool->priv->description != NULL ? tool->priv->description : "");
+
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
+
+ for (l = tool->priv->jobs->head; l != NULL; l = l->next)
+ {
+ LatexilaBuildJob *job = l->data;
+
+ escaped_text = latexila_build_job_to_xml (job);
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
+ }
+
+ escaped_text = g_markup_printf_escaped (" <open>%s</open>\n",
+ tool->priv->files_to_open != NULL ? tool->priv->files_to_open :
"");
+ g_string_append (contents, escaped_text);
+ g_free (escaped_text);
+
+ g_string_append (contents, " </tool>\n");
+
+ return g_string_free (contents, FALSE);
+}
diff --git a/src/liblatexila/latexila-build-tool.h b/src/liblatexila/latexila-build-tool.h
new file mode 100644
index 0000000..8e4b0f5
--- /dev/null
+++ b/src/liblatexila/latexila-build-tool.h
@@ -0,0 +1,63 @@
+/*
+ * 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_TOOL_H__
+#define __LATEXILA_BUILD_TOOL_H__
+
+#include "latexila-types.h"
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_BUILD_TOOL (latexila_build_tool_get_type ())
+#define LATEXILA_BUILD_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LATEXILA_TYPE_BUILD_TOOL,
LatexilaBuildTool))
+#define LATEXILA_BUILD_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LATEXILA_TYPE_BUILD_TOOL,
LatexilaBuildToolClass))
+#define LATEXILA_IS_BUILD_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LATEXILA_TYPE_BUILD_TOOL))
+#define LATEXILA_IS_BUILD_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LATEXILA_TYPE_BUILD_TOOL))
+#define LATEXILA_BUILD_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LATEXILA_TYPE_BUILD_TOOL,
LatexilaBuildToolClass))
+
+typedef struct _LatexilaBuildToolClass LatexilaBuildToolClass;
+typedef struct _LatexilaBuildToolPrivate LatexilaBuildToolPrivate;
+
+struct _LatexilaBuildTool
+{
+ GObject parent;
+
+ LatexilaBuildToolPrivate *priv;
+};
+
+struct _LatexilaBuildToolClass
+{
+ GObjectClass parent_class;
+};
+
+GType latexila_build_tool_get_type (void) G_GNUC_CONST;
+
+LatexilaBuildTool * latexila_build_tool_new (void);
+
+const gchar * latexila_build_tool_get_description (LatexilaBuildTool *build_tool);
+
+void latexila_build_tool_add_job (LatexilaBuildTool *build_tool,
+ LatexilaBuildJob *build_job);
+
+gchar * latexila_build_tool_to_xml (LatexilaBuildTool *tool);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_BUILD_TOOL_H__ */
diff --git a/src/liblatexila/latexila-build-tools-default.c b/src/liblatexila/latexila-build-tools-default.c
index 5cafb72..f57ff8a 100644
--- a/src/liblatexila/latexila-build-tools-default.c
+++ b/src/liblatexila/latexila-build-tools-default.c
@@ -57,10 +57,13 @@ set_enabled_by_id (LatexilaBuildToolsDefault *build_tools,
for (l = build_tools_parent->build_tools; l != NULL; l = l->next)
{
LatexilaBuildTool *build_tool = l->data;
+ gint id;
- if (build_tool->id == build_tool_id)
+ g_object_get (build_tool, "id", &id, NULL);
+
+ if (id == build_tool_id)
{
- build_tool->enabled = enabled;
+ g_object_set (build_tool, "enabled", enabled, NULL);
return;
}
}
@@ -124,14 +127,21 @@ save_settings (LatexilaBuildToolsDefault *build_tools)
for (l = build_tools_parent->build_tools; l != NULL; l = l->next)
{
LatexilaBuildTool *build_tool = l->data;
+ gboolean enabled;
+ gint id;
+
+ g_object_get (build_tool,
+ "enabled", &enabled,
+ "id", &id,
+ NULL);
- if (build_tool->enabled)
+ if (enabled)
{
- g_variant_builder_add (&builder_enabled, "i", build_tool->id);
+ g_variant_builder_add (&builder_enabled, "i", id);
}
else
{
- g_variant_builder_add (&builder_disabled, "i", build_tool->id);
+ g_variant_builder_add (&builder_disabled, "i", id);
}
}
diff --git a/src/liblatexila/latexila-build-tools-personal.c b/src/liblatexila/latexila-build-tools-personal.c
index 1325600..e0bedfd 100644
--- a/src/liblatexila/latexila-build-tools-personal.c
+++ b/src/liblatexila/latexila-build-tools-personal.c
@@ -29,6 +29,7 @@
#include "latexila-build-tools-personal.h"
#include <gio/gio.h>
+#include "latexila-build-tool.h"
static LatexilaBuildToolsPersonal *instance = NULL;
@@ -182,43 +183,10 @@ latexila_build_tools_personal_save (LatexilaBuildToolsPersonal *build_tools)
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");
+ gchar *build_tool_xml = latexila_build_tool_to_xml (build_tool);
+
+ g_string_append (contents, build_tool_xml);
+ g_free (build_tool_xml);
}
g_string_append (contents, "</tools>\n");
@@ -311,8 +279,10 @@ latexila_build_tools_personal_move_down (LatexilaBuildToolsPersonal *build_tools
/**
* latexila_build_tools_personal_delete:
- * @build_tools:
- * @tool_num:
+ * @build_tools: the #LatexilaBuildToolsPersonal instance.
+ * @tool_num: the build tool position in the list.
+ *
+ * Deletes a build tool.
*/
void
latexila_build_tools_personal_delete (LatexilaBuildToolsPersonal *build_tools,
@@ -328,7 +298,7 @@ latexila_build_tools_personal_delete (LatexilaBuildToolsPersonal *build_tools,
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_list_free_full (node, g_object_unref);
g_signal_emit_by_name (build_tools, "modified");
}
@@ -336,7 +306,7 @@ latexila_build_tools_personal_delete (LatexilaBuildToolsPersonal *build_tools,
/**
* latexila_build_tools_personal_add:
* @build_tools: the #LatexilaBuildToolsPersonal instance.
- * @new_build_tool: the new build tool structure.
+ * @new_build_tool: the new build tool object.
*
* Append the new build tool at the end of the list.
*/
@@ -351,13 +321,15 @@ latexila_build_tools_personal_add (LatexilaBuildToolsPersonal *build_tools,
build_tools_parent->build_tools = g_list_append (build_tools_parent->build_tools,
new_build_tool);
+ g_object_ref (new_build_tool);
+
g_signal_emit_by_name (build_tools, "modified");
}
/**
* latexila_build_tools_personal_insert:
* @build_tools: the #LatexilaBuildToolsPersonal instance.
- * @new_build_tool: the new build tool structure.
+ * @new_build_tool: the new build tool object.
* @position: the position in the list where to insert the new build tool.
*
* Inserts a new build tool at a given position.
@@ -375,15 +347,17 @@ latexila_build_tools_personal_insert (LatexilaBuildToolsPersonal *build_tools,
new_build_tool,
position);
+ g_object_ref (new_build_tool);
+
g_signal_emit_by_name (build_tools, "modified");
}
/**
* latexila_build_tools_personal_replace:
* @build_tools: the #LatexilaBuildToolsPersonal instance.
- * @new_build_tool: the new build tool structure.
+ * @new_build_tool: the new build tool object.
* @position: the position in the list where to replace the build tool. The old
- * build tool structure located at @position will be freed.
+ * build tool located at @position will be unreffed.
*
* Replaces a build tool.
*/
@@ -402,8 +376,8 @@ latexila_build_tools_personal_replace (LatexilaBuildToolsPersonal *build_tools,
if (node->data != new_build_tool)
{
- latexila_build_tool_free (node->data);
- node->data = new_build_tool;
+ g_object_unref (node->data);
+ node->data = g_object_ref (new_build_tool);
g_signal_emit_by_name (build_tools, "modified");
}
diff --git a/src/liblatexila/latexila-build-tools.c b/src/liblatexila/latexila-build-tools.c
index 04e634a..3e02f20 100644
--- a/src/liblatexila/latexila-build-tools.c
+++ b/src/liblatexila/latexila-build-tools.c
@@ -35,6 +35,9 @@
#include "latexila-build-tools.h"
#include <glib/gi18n.h>
#include "latexila-build-tools-default.h"
+#include "latexila-build-tool.h"
+#include "latexila-build-job.h"
+#include "latexila-post-processor.h"
struct _LatexilaBuildToolsPrivate
{
@@ -54,147 +57,18 @@ G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildTools, latexila_build_tools, G_TYPE_OBJ
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)
+latexila_build_tools_dispose (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_list_free_full (build_tools->build_tools, g_object_unref);
+ build_tools->build_tools = NULL;
+
+ g_clear_object (&build_tools->priv->cur_tool);
+ g_clear_object (&build_tools->priv->cur_job);
- G_OBJECT_CLASS (latexila_build_tools_parent_class)->finalize (object);
+ G_OBJECT_CLASS (latexila_build_tools_parent_class)->dispose (object);
}
static void
@@ -202,7 +76,7 @@ latexila_build_tools_class_init (LatexilaBuildToolsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = latexila_build_tools_finalize;
+ object_class->dispose = latexila_build_tools_dispose;
/**
* LatexilaBuildTools::loaded:
@@ -257,29 +131,31 @@ parser_start_element (GMarkupParseContext *context,
LatexilaBuildTool *cur_tool;
gint i;
- latexila_build_tool_free (build_tools->priv->cur_tool);
- cur_tool = build_tool_new ();
+ g_clear_object (&build_tools->priv->cur_tool);
+ cur_tool = latexila_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);
+ gint id = g_strtod (attribute_values[i], NULL);
+ g_object_set (cur_tool, "id", id, 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");
+ gboolean enabled = g_str_equal (attribute_values[i], "true");
+ g_object_set (cur_tool, "enabled", enabled, NULL);
}
else if (g_str_equal (attribute_names[i], "extensions"))
{
- cur_tool->extensions = g_strdup (attribute_values[i]);
+ g_object_set (cur_tool, "extensions", attribute_values[i], NULL);
}
else if (g_str_equal (attribute_names[i], "icon"))
{
- cur_tool->icon = g_strdup (attribute_values[i]);
+ g_object_set (cur_tool, "icon", attribute_values[i], NULL);
}
else if (error != NULL)
{
@@ -296,8 +172,8 @@ parser_start_element (GMarkupParseContext *context,
LatexilaBuildJob *cur_job;
gint i;
- build_job_free (build_tools->priv->cur_job);
- cur_job = build_job_new ();
+ g_clear_object (&build_tools->priv->cur_job);
+ cur_job = latexila_build_job_new ();
build_tools->priv->cur_job = cur_job;
for (i = 0; attribute_names[i] != NULL; i++)
@@ -306,9 +182,9 @@ parser_start_element (GMarkupParseContext *context,
{
LatexilaPostProcessorType type;
- if (latexila_get_post_processor_type_from_name (attribute_values[i], &type))
+ if (latexila_post_processor_get_type_from_name (attribute_values[i], &type))
{
- cur_job->post_processor_type = type;
+ g_object_set (cur_job, "post-processor-type", type, NULL);
}
else if (error != NULL)
{
@@ -361,22 +237,15 @@ parser_end_element (GMarkupParseContext *context,
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->build_tools = g_list_prepend (build_tools->build_tools,
+ build_tools->priv->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);
-
+ latexila_build_tool_add_job (build_tools->priv->cur_tool,
+ build_tools->priv->cur_job);
build_tools->priv->cur_job = NULL;
}
@@ -401,42 +270,24 @@ parser_text (GMarkupParseContext *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)
+ if (g_str_equal (element_name, "job"))
{
- g_free (build_tools->priv->cur_job->command);
- build_tools->priv->cur_job->command = stripped_text;
+ g_object_set (build_tools->priv->cur_job, "command", stripped_text, NULL);
}
-
- else if (g_str_equal (element_name, "label") &&
- build_tools->priv->cur_tool != NULL)
+ else if (g_str_equal (element_name, "label"))
{
- g_free (build_tools->priv->cur_tool->label);
- build_tools->priv->cur_tool->label = g_strdup (_(stripped_text));
-
- g_free (stripped_text);
+ g_object_set (build_tools->priv->cur_tool, "label", _(stripped_text), NULL);
}
-
- else if (g_str_equal (element_name, "description") &&
- build_tools->priv->cur_tool != NULL)
+ else if (g_str_equal (element_name, "description"))
{
- g_free (build_tools->priv->cur_tool->description);
- build_tools->priv->cur_tool->description = g_strdup (_(stripped_text));
-
- g_free (stripped_text);
+ g_object_set (build_tools->priv->cur_tool, "description", _(stripped_text), NULL);
}
-
- else if (g_str_equal (element_name, "open") &&
- build_tools->priv->cur_tool != NULL)
+ else if (g_str_equal (element_name, "open"))
{
- g_free (build_tools->priv->cur_tool->files_to_open);
- build_tools->priv->cur_tool->files_to_open = stripped_text;
+ g_object_set (build_tools->priv->cur_tool, "files-to-open", stripped_text, NULL);
}
- else
- {
- g_free (stripped_text);
- }
+ g_free (stripped_text);
}
static void
@@ -568,9 +419,6 @@ latexila_build_tools_set_enabled (LatexilaBuildTools *build_tools,
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);
- }
+ g_object_set (build_tool, "enabled", enabled, NULL);
+ 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
index e097e20..0a9c7be 100644
--- a/src/liblatexila/latexila-build-tools.h
+++ b/src/liblatexila/latexila-build-tools.h
@@ -34,8 +34,6 @@ G_BEGIN_DECLS
typedef struct _LatexilaBuildToolsClass LatexilaBuildToolsClass;
typedef struct _LatexilaBuildToolsPrivate LatexilaBuildToolsPrivate;
-typedef struct _LatexilaBuildJob LatexilaBuildJob;
-typedef struct _LatexilaBuildTool LatexilaBuildTool;
/**
* LatexilaBuildTools:
@@ -59,69 +57,8 @@ struct _LatexilaBuildToolsClass
GObjectClass parent_class;
};
-/**
- * LatexilaPostProcessorType:
- * @LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT: no output.
- * @LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT: all output.
- * @LATEXILA_POST_PROCESSOR_TYPE_LATEX: for a LaTeX command.
- * @LATEXILA_POST_PROCESSOR_TYPE_LATEXMK: for the latexmk command.
- *
- * Types of post-processors.
- */
-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;
-
-/**
- * LatexilaBuildJob:
- * @post_processor_type: the post-processor type.
- * @command: the command to run.
- */
-struct _LatexilaBuildJob
-{
- LatexilaPostProcessorType post_processor_type;
- gchar *command;
-};
-
-/**
- * LatexilaBuildTool:
- * @label: the label.
- * @description: the description.
- * @extensions: the extensions.
- * @icon: the icon.
- * @files_to_open: the files to open.
- * @jobs: a list of #LatexilaBuildJob's.
- * @id: ID of the build tool. It is used only by the default build tools, for
- * saving in #GSettings the lists of enabled/disabled build tools.
- * @enabled: whether the build tool is enabled (for showing it in the UI).
- */
-struct _LatexilaBuildTool
-{
- gchar *label;
- gchar *description;
- gchar *extensions;
- gchar *icon;
- gchar *files_to_open;
- GSList *jobs;
- gint id;
- guint enabled : 1;
-};
-
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);
diff --git a/src/liblatexila/latexila-enum-types.c.template b/src/liblatexila/latexila-enum-types.c.template
new file mode 100644
index 0000000..59f8797
--- /dev/null
+++ b/src/liblatexila/latexila-enum-types.c.template
@@ -0,0 +1,41 @@
+/*** BEGIN file-header ***/
+#include "latexila-enum-types.h"
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+#include "@filename@"
+
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+ enum_name@_get_type (void)
+{
+ static GType the_type = 0;
+
+ if (the_type == 0)
+ {
+ static const G Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+ { @VALUENAME@,
+ "@VALUENAME@",
+ "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+ { 0, NULL, NULL }
+ };
+
+ the_type = g_ type@_register_static (
+ g_intern_static_string ("@EnumName@"),
+ values);
+ }
+
+ return the_type;
+}
+
+/*** END value-tail ***/
diff --git a/src/liblatexila/latexila-enum-types.h.template b/src/liblatexila/latexila-enum-types.h.template
new file mode 100644
index 0000000..daa7d7a
--- /dev/null
+++ b/src/liblatexila/latexila-enum-types.h.template
@@ -0,0 +1,26 @@
+/*** BEGIN file-header ***/
+#ifndef __LATEXILA_ENUM_TYPES_H__
+#define __LATEXILA_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* Enumerations from "@filename@" */
+
+/*** END file-production ***/
+
+/*** BEGIN enumeration-production ***/
+#define LATEXILA_TYPE_ ENUMSHORT@ (@enum_name _get_type())
+GType @enum_name _get_type (void) G_GNUC_CONST;
+
+/*** END enumeration-production ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* __LATEXILA_ENUM_TYPES_H__ */
+/*** END file-tail ***/
diff --git a/src/liblatexila/latexila-post-processor.c b/src/liblatexila/latexila-post-processor.c
index f5861db..19e2b40 100644
--- a/src/liblatexila/latexila-post-processor.c
+++ b/src/liblatexila/latexila-post-processor.c
@@ -34,6 +34,74 @@ enum
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaPostProcessor, latexila_post_processor, G_TYPE_OBJECT)
+/**
+ * latexila_post_processor_get_type_from_name:
+ * @name: the name of the post-processor.
+ * @type: (out): the output post-processor type.
+ *
+ * Returns: %TRUE on success, %FALSE otherwise.
+ */
+gboolean
+latexila_post_processor_get_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_post_processor_get_name_from_type:
+ * @type: the post-processor type.
+ *
+ * Returns: the post-processor name.
+ */
+const gchar *
+latexila_post_processor_get_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_post_processor_get_property (GObject *object,
guint prop_id,
diff --git a/src/liblatexila/latexila-post-processor.h b/src/liblatexila/latexila-post-processor.h
index b889d38..61049a1 100644
--- a/src/liblatexila/latexila-post-processor.h
+++ b/src/liblatexila/latexila-post-processor.h
@@ -36,6 +36,22 @@ G_BEGIN_DECLS
typedef struct _LatexilaPostProcessorClass LatexilaPostProcessorClass;
typedef struct _LatexilaPostProcessorPrivate LatexilaPostProcessorPrivate;
+/**
+ * LatexilaPostProcessorType:
+ * @LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT: no output.
+ * @LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT: all output.
+ * @LATEXILA_POST_PROCESSOR_TYPE_LATEX: for a LaTeX command.
+ * @LATEXILA_POST_PROCESSOR_TYPE_LATEXMK: for the latexmk command.
+ *
+ * Types of post-processors.
+ */
+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;
struct _LatexilaPostProcessor
{
@@ -54,14 +70,19 @@ struct _LatexilaPostProcessorClass
GSList * (* get_messages) (LatexilaPostProcessor *post_processor);
};
-GType latexila_post_processor_get_type (void) G_GNUC_CONST;
+GType latexila_post_processor_get_type (void) G_GNUC_CONST;
+
+gboolean latexila_post_processor_get_type_from_name (const gchar *name,
+ LatexilaPostProcessorType *type);
+
+const gchar * latexila_post_processor_get_name_from_type (LatexilaPostProcessorType type);
-LatexilaPostProcessor * latexila_post_processor_new (void);
+LatexilaPostProcessor * latexila_post_processor_new (void);
-void latexila_post_processor_process (LatexilaPostProcessor *post_processor,
- const gchar *output);
+void latexila_post_processor_process (LatexilaPostProcessor *post_processor,
+ const gchar *output);
-GSList * latexila_post_processor_get_messages (LatexilaPostProcessor *post_processor);
+GSList * latexila_post_processor_get_messages (LatexilaPostProcessor
*post_processor);
G_END_DECLS
diff --git a/src/liblatexila/latexila-types.h b/src/liblatexila/latexila-types.h
index 64f5523..dce5031 100644
--- a/src/liblatexila/latexila-types.h
+++ b/src/liblatexila/latexila-types.h
@@ -24,6 +24,8 @@
G_BEGIN_DECLS
+typedef struct _LatexilaBuildJob LatexilaBuildJob;
+typedef struct _LatexilaBuildTool LatexilaBuildTool;
typedef struct _LatexilaBuildTools LatexilaBuildTools;
typedef struct _LatexilaBuildToolsDefault LatexilaBuildToolsDefault;
typedef struct _LatexilaBuildToolsPersonal LatexilaBuildToolsPersonal;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]