[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: Thu, 1 May 2014 21:04:46 +0000 (UTC)
commit 096a8363bc7e75f50345e4fa21a6b3b11f3525be
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu May 1 15:14:56 2014 +0200
BuildTool and BuildJob classes
And add enum types.
docs/reference/latexila-sections.txt | 7 -
src/liblatexila/Makefile.am | 36 +++-
src/liblatexila/latexila-build-job.c | 106 ++++++++
src/liblatexila/latexila-build-job.h | 68 +++++
src/liblatexila/latexila-build-tool.c | 315 ++++++++++++++++++++++++
src/liblatexila/latexila-build-tool.h | 61 +++++
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 +
13 files changed, 781 insertions(+), 271 deletions(-)
---
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index 544000c..5e35b0c 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>
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..e19412f
--- /dev/null
+++ b/src/liblatexila/latexila-build-job.c
@@ -0,0 +1,106 @@
+/*
+ * 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/>.
+ */
+
+#include "latexila-build-job.h"
+
+struct _LatexilaBuildJobPrivate
+{
+ LatexilaPostProcessorType post_processor_type;
+ gchar *command;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaBuildJob, latexila_build_job, G_TYPE_OBJECT)
+
+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->dispose = latexila_build_job_dispose;
+ object_class->finalize = latexila_build_job_finalize;
+}
+
+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);
+}
+
+const gchar *
+latexila_build_job_get_command (LatexilaBuildJob *build_job)
+{
+ g_return_val_if_fail (LATEXILA_IS_BUILD_JOB (build_job), NULL);
+
+ return build_job->priv->command;
+}
+
+void
+latexila_build_job_set_command (LatexilaBuildJob *build_job,
+ const gchar *command)
+{
+ g_return_if_fail (LATEXILA_IS_BUILD_JOB (build_job));
+
+ g_free (build_job->priv->command);
+ build_job->priv->command = g_strdup (command);
+}
+
+LatexilaPostProcessorType
+latexila_build_job_get_post_processor_type (LatexilaBuildJob *build_job)
+{
+ g_return_val_if_fail (LATEXILA_IS_BUILD_JOB (build_job), LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT);
+
+ return build_job->priv->post_processor_type;
+}
+
+void
+latexila_build_job_set_post_processor_type (LatexilaBuildJob *build_job,
+ LatexilaPostProcessorType post_processor_type)
+{
+ g_return_if_fail (LATEXILA_IS_BUILD_JOB (build_job));
+
+ build_job->priv->post_processor_type = post_processor_type;
+}
diff --git a/src/liblatexila/latexila-build-job.h b/src/liblatexila/latexila-build-job.h
new file mode 100644
index 0000000..41db320
--- /dev/null
+++ b/src/liblatexila/latexila-build-job.h
@@ -0,0 +1,68 @@
+/*
+ * 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);
+
+const gchar * latexila_build_job_get_command (LatexilaBuildJob *build_job);
+
+void latexila_build_job_set_command (LatexilaBuildJob *build_job,
+ const gchar *command);
+
+LatexilaPostProcessorType
+ latexila_build_job_get_post_processor_type (LatexilaBuildJob *build_job);
+
+void latexila_build_job_set_post_processor_type (LatexilaBuildJob *build_job,
+ LatexilaPostProcessorType
post_processor_type);
+
+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..a1c094f
--- /dev/null
+++ b/src/liblatexila/latexila-build-tool.c
@@ -0,0 +1,315 @@
+/*
+ * 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/>.
+ */
+
+#include "latexila-build-tool.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);
+}
diff --git a/src/liblatexila/latexila-build-tool.h b/src/liblatexila/latexila-build-tool.h
new file mode 100644
index 0000000..c2b102c
--- /dev/null
+++ b/src/liblatexila/latexila-build-tool.h
@@ -0,0 +1,61 @@
+/*
+ * 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);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_BUILD_TOOL_H__ */
diff --git a/src/liblatexila/latexila-build-tools.c b/src/liblatexila/latexila-build-tools.c
index 04e634a..0b5bd0b 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;
+ latexila_build_job_set_post_processor_type (cur_job, type);
}
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;
+ latexila_build_job_set_command (build_tools->priv->cur_job, stripped_text);
}
-
- 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]