[gnome-latex] init: move some code to the liblatexila



commit 9e60c56b9d29ee0cf0beb202c2be24c89157e1a6
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Apr 28 14:43:49 2020 +0200

    init: move some code to the liblatexila

 docs/reference/gnome-latex-docs.xml     |  1 +
 docs/reference/gnome-latex-sections.txt |  6 +++
 po/POTFILES.in                          |  1 +
 src/liblatexila/Makefile.am             |  2 +
 src/liblatexila/latexila-init.c         | 89 +++++++++++++++++++++++++++++++++
 src/liblatexila/latexila-init.h         | 33 ++++++++++++
 src/liblatexila/latexila.h              |  1 +
 src/main.vala                           | 19 ++-----
 vapi/config.vapi                        |  1 -
 9 files changed, 136 insertions(+), 17 deletions(-)
---
diff --git a/docs/reference/gnome-latex-docs.xml b/docs/reference/gnome-latex-docs.xml
index 35edfac..9719591 100644
--- a/docs/reference/gnome-latex-docs.xml
+++ b/docs/reference/gnome-latex-docs.xml
@@ -14,6 +14,7 @@
 
     <chapter>
       <title>Main Classes</title>
+      <xi:include href="xml/init.xml"/>
       <xi:include href="xml/factory.xml"/>
       <xi:include href="xml/settings.xml"/>
       <xi:include href="xml/buffer.xml"/>
diff --git a/docs/reference/gnome-latex-sections.txt b/docs/reference/gnome-latex-sections.txt
index 9467f04..e07e87b 100644
--- a/docs/reference/gnome-latex-sections.txt
+++ b/docs/reference/gnome-latex-sections.txt
@@ -150,6 +150,12 @@ LatexilaFactoryClass
 latexila_factory_get_type
 </SECTION>
 
+<SECTION>
+<FILE>init</FILE>
+latexila_init
+latexila_finalize
+</SECTION>
+
 <SECTION>
 <FILE>latex-commands</FILE>
 latexila_latex_commands_add_action_infos
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3926dbe..bb8bf25 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -31,6 +31,7 @@ src/liblatexila/latexila-build-tools-default.c
 src/liblatexila/latexila-build-tools-personal.c
 src/liblatexila/latexila-build-view.c
 src/liblatexila/latexila-factory.c
+src/liblatexila/latexila-init.c
 src/liblatexila/latexila-latex-commands.c
 src/liblatexila/latexila-post-processor-all-output.c
 src/liblatexila/latexila-post-processor.c
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index e8c445d..751ce43 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -33,6 +33,7 @@ liblatexila_public_headers =                  \
        latexila-build-tools-personal.h         \
        latexila-build-view.h                   \
        latexila-factory.h                      \
+       latexila-init.h                         \
        latexila-latex-commands.h               \
        latexila-post-processor.h               \
        latexila-post-processor-all-output.h    \
@@ -58,6 +59,7 @@ liblatexila_public_c_files =                  \
        latexila-build-tools-personal.c         \
        latexila-build-view.c                   \
        latexila-factory.c                      \
+       latexila-init.c                         \
        latexila-latex-commands.c               \
        latexila-post-processor.c               \
        latexila-post-processor-all-output.c    \
diff --git a/src/liblatexila/latexila-init.c b/src/liblatexila/latexila-init.c
new file mode 100644
index 0000000..27bed37
--- /dev/null
+++ b/src/liblatexila/latexila-init.c
@@ -0,0 +1,89 @@
+/*
+ * This file is part of GNOME LaTeX.
+ *
+ * Copyright (C) 2020 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GNOME LaTeX 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.
+ *
+ * GNOME LaTeX 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 GNOME LaTeX.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "latexila-init.h"
+#include <locale.h>
+#include <libintl.h>
+#include <tepl/tepl.h>
+#include "latexila-settings.h"
+
+/**
+ * SECTION:init
+ * @title: Latexila Initialization and Finalization
+ */
+
+static void
+init_i18n (void)
+{
+       setlocale (LC_ALL, "");
+       bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
+       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+       textdomain (GETTEXT_PACKAGE);
+}
+
+/**
+ * latexila_init:
+ *
+ * Initializes GNOME LaTeX (e.g. for the internationalization).
+ *
+ * This function can be called several times, but is meant to be called at the
+ * beginning of main(), before any other Tepl function call.
+ *
+ * This function also calls tepl_init().
+ */
+void
+latexila_init (void)
+{
+       static gboolean done = FALSE;
+
+       if (!done)
+       {
+               init_i18n ();
+               tepl_init ();
+
+               done = TRUE;
+       }
+}
+
+/**
+ * latexila_finalize:
+ *
+ * Free the resources allocated by GNOME LaTeX. For example it unrefs the
+ * singleton objects.
+ *
+ * This function also calls tepl_finalize().
+ *
+ * It is not mandatory to call this function, it's just to be friendlier to
+ * memory debugging tools. This function is meant to be called at the end of
+ * main(). It can be called several times.
+ */
+void
+latexila_finalize (void)
+{
+       static gboolean done = FALSE;
+
+       if (!done)
+       {
+               latexila_settings_unref_singleton ();
+               tepl_finalize ();
+
+               done = TRUE;
+       }
+}
diff --git a/src/liblatexila/latexila-init.h b/src/liblatexila/latexila-init.h
new file mode 100644
index 0000000..bf87439
--- /dev/null
+++ b/src/liblatexila/latexila-init.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of GNOME LaTeX.
+ *
+ * Copyright (C) 2020 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GNOME LaTeX 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.
+ *
+ * GNOME LaTeX 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 GNOME LaTeX.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LATEXILA_INIT_H
+#define LATEXILA_INIT_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void   latexila_init           (void);
+
+void   latexila_finalize       (void);
+
+G_END_DECLS
+
+#endif /* LATEXILA_INIT_H */
diff --git a/src/liblatexila/latexila.h b/src/liblatexila/latexila.h
index 0c531d2..2511e2c 100644
--- a/src/liblatexila/latexila.h
+++ b/src/liblatexila/latexila.h
@@ -35,6 +35,7 @@
 #include "latexila-build-tools-personal.h"
 #include "latexila-build-view.h"
 #include "latexila-factory.h"
+#include "latexila-init.h"
 #include "latexila-latex-commands.h"
 #include "latexila-post-processor.h"
 #include "latexila-post-processor-all-output.h"
diff --git a/src/main.vala b/src/main.vala
index dac1bd5..81b3012 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -1,7 +1,7 @@
 /*
  * This file is part of GNOME LaTeX.
  *
- * Copyright © 2010-2015, 2017 Sébastien Wilmet
+ * Copyright © 2010-2020 Sébastien Wilmet
  *
  * GNOME LaTeX is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,28 +19,15 @@
  * Author: Sébastien Wilmet
  */
 
-using Gtk;
-
-private void init_i18n ()
-{
-    Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALE_DIR);
-    Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
-    Intl.textdomain (Config.GETTEXT_PACKAGE);
-}
-
 int main (string[] argv)
 {
-    init_i18n ();
-
-    Tepl.init ();
+    Latexila.init ();
     Factory factory = new Factory ();
     factory.set_singleton ();
 
     GlatexApp app = new GlatexApp ();
     int status = app.run (argv);
 
-    Tepl.finalize ();
-    Latexila.Settings.unref_singleton ();
-
+    Latexila.finalize ();
     return status;
 }
diff --git a/vapi/config.vapi b/vapi/config.vapi
index 4fdb600..e6cf0a1 100644
--- a/vapi/config.vapi
+++ b/vapi/config.vapi
@@ -4,7 +4,6 @@ namespace Config
     public const string PACKAGE_NAME;
     public const string PACKAGE_VERSION;
     public const string DATA_DIR;
-    public const string LOCALE_DIR;
     public const string GETTEXT_PACKAGE;
     public const string ICONS_DIR;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]