[gnome-latex] LatexilaSettings: create class



commit f01969f718bf0d3ccd7e085d2ae934f265e6b218
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Apr 23 02:12:05 2020 +0200

    LatexilaSettings: create class

 docs/reference/gnome-latex-docs.xml     |   1 +
 docs/reference/gnome-latex-sections.txt |  18 +++++
 po/POTFILES.in                          |   1 +
 src/liblatexila/Makefile.am             |   2 +
 src/liblatexila/latexila-settings.c     | 128 ++++++++++++++++++++++++++++++++
 src/liblatexila/latexila-settings.h     |  61 +++++++++++++++
 src/liblatexila/latexila.h              |   3 +-
 7 files changed, 213 insertions(+), 1 deletion(-)
---
diff --git a/docs/reference/gnome-latex-docs.xml b/docs/reference/gnome-latex-docs.xml
index 3b78d2f..efd4303 100644
--- a/docs/reference/gnome-latex-docs.xml
+++ b/docs/reference/gnome-latex-docs.xml
@@ -15,6 +15,7 @@
     <chapter>
       <title>Main Classes</title>
       <xi:include href="xml/factory.xml"/>
+      <xi:include href="xml/settings.xml"/>
       <xi:include href="xml/view.xml"/>
     </chapter>
 
diff --git a/docs/reference/gnome-latex-sections.txt b/docs/reference/gnome-latex-sections.txt
index 9db4d71..6fe2bcf 100644
--- a/docs/reference/gnome-latex-sections.txt
+++ b/docs/reference/gnome-latex-sections.txt
@@ -225,6 +225,24 @@ LatexilaPostProcessorLatexmkPrivate
 latexila_post_processor_latexmk_get_type
 </SECTION>
 
+<SECTION>
+<FILE>settings</FILE>
+LatexilaSettings
+latexila_settings_get_singleton
+latexila_settings_unref_singleton
+latexila_settings_peek_editor_settings
+<SUBSECTION Standard>
+LATEXILA_IS_SETTINGS
+LATEXILA_IS_SETTINGS_CLASS
+LATEXILA_SETTINGS
+LATEXILA_SETTINGS_CLASS
+LATEXILA_SETTINGS_GET_CLASS
+LATEXILA_TYPE_SETTINGS
+LatexilaSettingsClass
+LatexilaSettingsPrivate
+latexila_settings_get_type
+</SECTION>
+
 <SECTION>
 <FILE>synctex</FILE>
 LatexilaSynctex
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0d808a9..ce21355 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -35,6 +35,7 @@ src/liblatexila/latexila-post-processor-all-output.c
 src/liblatexila/latexila-post-processor.c
 src/liblatexila/latexila-post-processor-latex.c
 src/liblatexila/latexila-post-processor-latexmk.c
+src/liblatexila/latexila-settings.c
 src/liblatexila/latexila-synctex.c
 src/liblatexila/latexila-templates-common.c
 src/liblatexila/latexila-templates-default.c
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 2198f71..9d737ee 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -37,6 +37,7 @@ liblatexila_public_headers =                  \
        latexila-post-processor-all-output.h    \
        latexila-post-processor-latex.h         \
        latexila-post-processor-latexmk.h       \
+       latexila-settings.h                     \
        latexila-synctex.h                      \
        latexila-templates-default.h            \
        latexila-templates-dialogs.h            \
@@ -60,6 +61,7 @@ liblatexila_public_c_files =                  \
        latexila-post-processor-all-output.c    \
        latexila-post-processor-latex.c         \
        latexila-post-processor-latexmk.c       \
+       latexila-settings.c                     \
        latexila-synctex.c                      \
        latexila-templates-default.c            \
        latexila-templates-dialogs.c            \
diff --git a/src/liblatexila/latexila-settings.c b/src/liblatexila/latexila-settings.c
new file mode 100644
index 0000000..89d51c6
--- /dev/null
+++ b/src/liblatexila/latexila-settings.c
@@ -0,0 +1,128 @@
+/*
+ * 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 "latexila-settings.h"
+
+/**
+ * SECTION:settings
+ * @title: LatexilaSettings
+ * @short_description: Central access to #GSettings objects
+ *
+ * #LatexilaSettings is a singleton class to have a central access to #GSettings
+ * objects. The central access permits to share the same #GSettings objects
+ * between different parts of the application, which normally increases the
+ * performances when synchronizing the values (but this hasn't been verified).
+ */
+
+struct _LatexilaSettingsPrivate
+{
+       GSettings *settings_editor;
+};
+
+/* LatexilaSettings is a singleton. */
+static LatexilaSettings *singleton = NULL;
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaSettings, latexila_settings, G_TYPE_OBJECT)
+
+static void
+latexila_settings_dispose (GObject *object)
+{
+       LatexilaSettings *self = LATEXILA_SETTINGS (object);
+
+       g_clear_object (&self->priv->settings_editor);
+
+       G_OBJECT_CLASS (latexila_settings_parent_class)->dispose (object);
+}
+
+static void
+latexila_settings_finalize (GObject *object)
+{
+       if (singleton == LATEXILA_SETTINGS (object))
+       {
+               singleton = NULL;
+       }
+
+       G_OBJECT_CLASS (latexila_settings_parent_class)->finalize (object);
+}
+
+static void
+latexila_settings_class_init (LatexilaSettingsClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->dispose = latexila_settings_dispose;
+       object_class->finalize = latexila_settings_finalize;
+}
+
+static void
+latexila_settings_init (LatexilaSettings *self)
+{
+       self->priv = latexila_settings_get_instance_private (self);
+
+       self->priv->settings_editor = g_settings_new ("org.gnome.gnome-latex.preferences.editor");
+}
+
+/**
+ * latexila_settings_get_singleton:
+ *
+ * Returns: (transfer none): the #LatexilaSettings singleton instance.
+ */
+LatexilaSettings *
+latexila_settings_get_singleton (void)
+{
+       if (singleton == NULL)
+       {
+               singleton = g_object_new (LATEXILA_TYPE_SETTINGS, NULL);
+       }
+
+       return singleton;
+}
+
+/**
+ * latexila_settings_unref_singleton:
+ *
+ * Unrefs the #LatexilaSettings singleton instance.
+ */
+void
+latexila_settings_unref_singleton (void)
+{
+       if (singleton != NULL)
+       {
+               g_object_unref (singleton);
+       }
+
+       /* singleton is not set to NULL here, it is set to NULL in
+        * latexila_settings_finalize() (i.e. when we are sure that the ref
+        * count reaches 0).
+        */
+}
+
+/**
+ * latexila_settings_peek_editor_settings:
+ * @self: the #LatexilaSettings instance.
+ *
+ * Returns: (transfer none): the #GSettings for
+ * `"org.gnome.gnome-latex.preferences.editor"`.
+ */
+GSettings *
+latexila_settings_peek_editor_settings (LatexilaSettings *self)
+{
+       g_return_val_if_fail (LATEXILA_IS_SETTINGS (self), NULL);
+       return self->priv->settings_editor;
+}
diff --git a/src/liblatexila/latexila-settings.h b/src/liblatexila/latexila-settings.h
new file mode 100644
index 0000000..ed62d8d
--- /dev/null
+++ b/src/liblatexila/latexila-settings.h
@@ -0,0 +1,61 @@
+/*
+ * 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_SETTINGS_H
+#define LATEXILA_SETTINGS_H
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_SETTINGS             (latexila_settings_get_type ())
+#define LATEXILA_SETTINGS(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), LATEXILA_TYPE_SETTINGS, 
LatexilaSettings))
+#define LATEXILA_SETTINGS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), LATEXILA_TYPE_SETTINGS, 
LatexilaSettingsClass))
+#define LATEXILA_IS_SETTINGS(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LATEXILA_TYPE_SETTINGS))
+#define LATEXILA_IS_SETTINGS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), LATEXILA_TYPE_SETTINGS))
+#define LATEXILA_SETTINGS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), LATEXILA_TYPE_SETTINGS, 
LatexilaSettingsClass))
+
+typedef struct _LatexilaSettings         LatexilaSettings;
+typedef struct _LatexilaSettingsClass    LatexilaSettingsClass;
+typedef struct _LatexilaSettingsPrivate  LatexilaSettingsPrivate;
+
+struct _LatexilaSettings
+{
+       GObject parent;
+
+       LatexilaSettingsPrivate *priv;
+};
+
+struct _LatexilaSettingsClass
+{
+       GObjectClass parent_class;
+};
+
+GType          latexila_settings_get_type                      (void);
+
+LatexilaSettings *
+               latexila_settings_get_singleton                 (void);
+
+void           latexila_settings_unref_singleton               (void);
+
+GSettings *    latexila_settings_peek_editor_settings          (LatexilaSettings *self);
+
+G_END_DECLS
+
+#endif /* LATEXILA_SETTINGS_H */
diff --git a/src/liblatexila/latexila.h b/src/liblatexila/latexila.h
index 89c7134..b89f1ba 100644
--- a/src/liblatexila/latexila.h
+++ b/src/liblatexila/latexila.h
@@ -1,7 +1,7 @@
 /*
  * This file is part of GNOME LaTeX.
  *
- * Copyright (C) 2014-2015 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014-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
@@ -38,6 +38,7 @@
 #include "latexila-post-processor.h"
 #include "latexila-post-processor-all-output.h"
 #include "latexila-post-processor-latex.h"
+#include "latexila-settings.h"
 #include "latexila-synctex.h"
 #include "latexila-templates-default.h"
 #include "latexila-templates-personal.h"


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