[devhelp/wip/devhelp-next] gsettings: split DhSettings between lib and app



commit cfd2c3add8317e2b7f6643654db2f315ed6d49a2
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Mar 9 14:11:52 2018 +0100

    gsettings: split DhSettings between lib and app
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784351

 devhelp/dh-settings.c |  137 +------------------------------
 devhelp/dh-settings.h |   20 +----
 po/POTFILES.in        |    1 +
 src/Makefile.am       |    2 +
 src/dh-app.c          |   14 ++--
 src/dh-assistant.c    |   14 ++--
 src/dh-main.c         |    2 +
 src/dh-preferences.c  |   11 ++-
 src/dh-settings-app.c |  216 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/dh-settings-app.h |   72 ++++++++++++++++
 src/dh-window.c       |   34 ++++----
 11 files changed, 336 insertions(+), 187 deletions(-)
---
diff --git a/devhelp/dh-settings.c b/devhelp/dh-settings.c
index a2b5223..594c7fa 100644
--- a/devhelp/dh-settings.c
+++ b/devhelp/dh-settings.c
@@ -1,7 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
 /*
  * Copyright (C) 2012 Thomas Bechtold <toabctl gnome org>
- * Copyright (C) 2017 Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2017, 2018 Sébastien Wilmet <swilmet gnome org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -17,37 +17,15 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
 #include "dh-settings.h"
 
-/* Devhelp GSettings schema IDs */
+/* libdevhelp GSettings schema IDs */
 #define SETTINGS_SCHEMA_ID_CONTENTS             "org.gnome.libdevhelp-3.contents"
-#define SETTINGS_SCHEMA_ID_WINDOW               "org.gnome.devhelp.state.main.window"
-#define SETTINGS_SCHEMA_ID_PANED                "org.gnome.devhelp.state.main.paned"
-#define SETTINGS_SCHEMA_ID_ASSISTANT            "org.gnome.devhelp.state.assistant.window"
-#define SETTINGS_SCHEMA_ID_FONTS                "org.gnome.devhelp.fonts"
-
-/* Provided by the gsettings-desktop-schemas module. */
-#define SETTINGS_SCHEMA_ID_DESKTOP_INTERFACE    "org.gnome.desktop.interface"
-#define SYSTEM_FIXED_FONT_KEY                   "monospace-font-name"
-#define SYSTEM_VARIABLE_FONT_KEY                "font-name"
 
 struct _DhSettingsPrivate {
-        GSettings *settings_window;
-        GSettings *settings_paned;
         GSettings *settings_contents;
-        GSettings *settings_assistant;
-        GSettings *settings_fonts;
-        GSettings *settings_desktop_interface;
-};
-
-enum {
-        FONTS_CHANGED,
-        N_SIGNALS
 };
 
-static guint signals[N_SIGNALS] = { 0 };
-
 /* DhSettings is a singleton. */
 static DhSettings *singleton = NULL;
 
@@ -58,12 +36,7 @@ dh_settings_dispose (GObject *object)
 {
         DhSettings *self = DH_SETTINGS (object);
 
-        g_clear_object (&self->priv->settings_window);
-        g_clear_object (&self->priv->settings_paned);
         g_clear_object (&self->priv->settings_contents);
-        g_clear_object (&self->priv->settings_assistant);
-        g_clear_object (&self->priv->settings_fonts);
-        g_clear_object (&self->priv->settings_desktop_interface);
 
         G_OBJECT_CLASS (dh_settings_parent_class)->dispose (object);
 }
@@ -84,34 +57,6 @@ dh_settings_class_init (DhSettingsClass *klass)
 
         object_class->dispose = dh_settings_dispose;
         object_class->finalize = dh_settings_finalize;
-
-        signals[FONTS_CHANGED] =
-                g_signal_new ("fonts-changed",
-                              G_TYPE_FROM_CLASS (klass),
-                              G_SIGNAL_RUN_LAST,
-                              G_STRUCT_OFFSET (DhSettingsClass, fonts_changed),
-                              NULL, NULL, NULL,
-                              G_TYPE_NONE,
-                              2,
-                              G_TYPE_STRING,
-                              G_TYPE_STRING);
-}
-
-static void
-fonts_changed_cb (GSettings *gsettings,
-                  gchar     *key,
-                  gpointer   user_data)
-{
-        DhSettings *self = DH_SETTINGS (user_data);
-        gchar *fixed_font = NULL;
-        gchar *variable_font = NULL;
-
-        dh_settings_get_selected_fonts (self, &fixed_font, &variable_font);
-
-        g_signal_emit (self, signals[FONTS_CHANGED], 0, fixed_font, variable_font);
-
-        g_free (fixed_font);
-        g_free (variable_font);
 }
 
 static void
@@ -132,30 +77,6 @@ dh_settings_init (DhSettings *self)
         self->priv->settings_contents = g_settings_new_with_path (SETTINGS_SCHEMA_ID_CONTENTS,
                                                                   /* Must be compatible with Devhelp app 
version 3.28. */
                                                                   "/org/gnome/devhelp/state/main/contents/");
-
-        self->priv->settings_window = g_settings_new (SETTINGS_SCHEMA_ID_WINDOW);
-        self->priv->settings_paned = g_settings_new (SETTINGS_SCHEMA_ID_PANED);
-        self->priv->settings_assistant = g_settings_new (SETTINGS_SCHEMA_ID_ASSISTANT);
-        self->priv->settings_fonts = g_settings_new (SETTINGS_SCHEMA_ID_FONTS);
-        self->priv->settings_desktop_interface = g_settings_new (SETTINGS_SCHEMA_ID_DESKTOP_INTERFACE);
-
-        g_signal_connect_object (self->priv->settings_fonts,
-                                 "changed",
-                                 G_CALLBACK (fonts_changed_cb),
-                                 self,
-                                 0);
-
-        g_signal_connect_object (self->priv->settings_desktop_interface,
-                                 "changed::" SYSTEM_FIXED_FONT_KEY,
-                                 G_CALLBACK (fonts_changed_cb),
-                                 self,
-                                 0);
-
-        g_signal_connect_object (self->priv->settings_desktop_interface,
-                                 "changed::" SYSTEM_VARIABLE_FONT_KEY,
-                                 G_CALLBACK (fonts_changed_cb),
-                                 self,
-                                 0);
 }
 
 DhSettings *
@@ -180,62 +101,8 @@ _dh_settings_unref_singleton (void)
 }
 
 GSettings *
-dh_settings_peek_window_settings (DhSettings *self)
-{
-        g_return_val_if_fail (DH_IS_SETTINGS (self), NULL);
-        return self->priv->settings_window;
-}
-
-GSettings *
-dh_settings_peek_paned_settings (DhSettings *self)
-{
-        g_return_val_if_fail (DH_IS_SETTINGS (self), NULL);
-        return self->priv->settings_paned;
-}
-
-GSettings *
 dh_settings_peek_contents_settings (DhSettings *self)
 {
         g_return_val_if_fail (DH_IS_SETTINGS (self), NULL);
         return self->priv->settings_contents;
 }
-
-GSettings *
-dh_settings_peek_assistant_settings (DhSettings *self)
-{
-        g_return_val_if_fail (DH_IS_SETTINGS (self), NULL);
-        return self->priv->settings_assistant;
-}
-
-GSettings *
-dh_settings_peek_fonts_settings (DhSettings *self)
-{
-        g_return_val_if_fail (DH_IS_SETTINGS (self), NULL);
-        return self->priv->settings_fonts;
-}
-
-void
-dh_settings_get_selected_fonts (DhSettings  *self,
-                                gchar      **font_name_fixed,
-                                gchar      **font_name_variable)
-{
-        gboolean use_system_font;
-
-        g_return_if_fail (DH_IS_SETTINGS (self));
-        g_return_if_fail (font_name_fixed != NULL && *font_name_fixed == NULL);
-        g_return_if_fail (font_name_variable != NULL && *font_name_variable == NULL);
-
-        use_system_font = g_settings_get_boolean (self->priv->settings_fonts, "use-system-fonts");
-
-        if (use_system_font) {
-                *font_name_fixed = g_settings_get_string (self->priv->settings_desktop_interface,
-                                                          SYSTEM_FIXED_FONT_KEY);
-                *font_name_variable = g_settings_get_string (self->priv->settings_desktop_interface,
-                                                             SYSTEM_VARIABLE_FONT_KEY);
-        } else {
-                *font_name_fixed = g_settings_get_string (self->priv->settings_fonts,
-                                                          "fixed-font");
-                *font_name_variable = g_settings_get_string (self->priv->settings_fonts,
-                                                             "variable-font");
-        }
-}
diff --git a/devhelp/dh-settings.h b/devhelp/dh-settings.h
index c977121..af9a8fd 100644
--- a/devhelp/dh-settings.h
+++ b/devhelp/dh-settings.h
@@ -1,7 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
 /*
  * Copyright (C) 2012 Thomas Bechtold <toabctl gnome org>
- * Copyright (C) 2017 Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2017, 2018 Sébastien Wilmet <swilmet gnome org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -43,10 +43,8 @@ struct _DhSettings {
 struct _DhSettingsClass {
         GObjectClass parent;
 
-        /* Signals */
-        void (*fonts_changed) (DhSettings  *settings,
-                               const gchar *font_name_fixed,
-                               const gchar *font_name_variable);
+        /* Padding for future expansion */
+        gpointer padding[12];
 };
 
 GType           dh_settings_get_type                    (void) G_GNUC_CONST;
@@ -56,20 +54,8 @@ DhSettings *    dh_settings_get_singleton               (void);
 G_GNUC_INTERNAL
 void            _dh_settings_unref_singleton            (void);
 
-GSettings *     dh_settings_peek_window_settings        (DhSettings *self);
-
-GSettings *     dh_settings_peek_paned_settings         (DhSettings *self);
-
 GSettings *     dh_settings_peek_contents_settings      (DhSettings *self);
 
-GSettings *     dh_settings_peek_assistant_settings     (DhSettings *self);
-
-GSettings *     dh_settings_peek_fonts_settings         (DhSettings *self);
-
-void            dh_settings_get_selected_fonts          (DhSettings  *self,
-                                                         gchar      **font_name_fixed,
-                                                         gchar      **font_name_variable);
-
 G_END_DECLS
 
 #endif /* DH_SETTINGS_H */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c92128e..bf3dd24 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -26,6 +26,7 @@ src/dh-assistant.ui
 src/dh-main.c
 src/dh-preferences.c
 src/dh-preferences.ui
+src/dh-settings-app.c
 src/dh-tab.c
 src/dh-tab-label.c
 src/dh-util-app.c
diff --git a/src/Makefile.am b/src/Makefile.am
index f031475..99738cc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,7 @@ app_headers =                 \
        dh-app.h                \
        dh-assistant.h          \
        dh-preferences.h        \
+       dh-settings-app.h       \
        dh-tab.h                \
        dh-tab-label.h          \
        dh-util-app.h           \
@@ -23,6 +24,7 @@ app_c_files =                 \
        dh-assistant.c          \
        dh-main.c               \
        dh-preferences.c        \
+       dh-settings-app.c       \
        dh-tab.c                \
        dh-tab-label.c          \
        dh-util-app.c           \
diff --git a/src/dh-app.c b/src/dh-app.c
index 07f555d..08f6883 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -23,9 +23,9 @@
 #include "config.h"
 #include "dh-app.h"
 #include <glib/gi18n.h>
-#include "devhelp/dh-settings.h"
 #include "dh-assistant.h"
 #include "dh-preferences.h"
+#include "dh-settings-app.h"
 #include "dh-util-app.h"
 
 G_DEFINE_TYPE (DhApp, dh_app, GTK_TYPE_APPLICATION);
@@ -52,30 +52,30 @@ static void
 save_active_main_window_gsettings (DhApp *app)
 {
         DhWindow *active_window;
-        DhSettings *settings;
+        DhSettingsApp *settings;
 
         active_window = dh_app_get_active_main_window (app, FALSE);
         if (active_window == NULL)
                 return;
 
-        settings = dh_settings_get_singleton ();
+        settings = dh_settings_app_get_singleton ();
         dh_util_window_settings_save (GTK_WINDOW (active_window),
-                                      dh_settings_peek_window_settings (settings));
+                                      dh_settings_app_peek_window_settings (settings));
 }
 
 static void
 save_active_assistant_window_gsettings (DhApp *app)
 {
         DhAssistant *active_assistant;
-        DhSettings *settings;
+        DhSettingsApp *settings;
 
         active_assistant = get_active_assistant_window (app);
         if (active_assistant == NULL)
                 return;
 
-        settings = dh_settings_get_singleton ();
+        settings = dh_settings_app_get_singleton ();
         dh_util_window_settings_save (GTK_WINDOW (active_assistant),
-                                      dh_settings_peek_assistant_settings (settings));
+                                      dh_settings_app_peek_assistant_settings (settings));
 }
 
 static void
diff --git a/src/dh-assistant.c b/src/dh-assistant.c
index ad48d1b..1232c13 100644
--- a/src/dh-assistant.c
+++ b/src/dh-assistant.c
@@ -19,7 +19,7 @@
 #include "config.h"
 #include "dh-assistant.h"
 #include <devhelp/devhelp.h>
-#include "devhelp/dh-settings.h"
+#include "dh-settings-app.h"
 #include "dh-util-app.h"
 #include "dh-window.h"
 
@@ -61,11 +61,11 @@ static gboolean
 dh_assistant_delete_event (GtkWidget   *widget,
                            GdkEventAny *event)
 {
-        DhSettings *settings;
+        DhSettingsApp *settings;
 
-        settings = dh_settings_get_singleton ();
+        settings = dh_settings_app_get_singleton ();
         dh_util_window_settings_save (GTK_WINDOW (widget),
-                                      dh_settings_peek_assistant_settings (settings));
+                                      dh_settings_app_peek_assistant_settings (settings));
 
         if (GTK_WIDGET_CLASS (dh_assistant_parent_class)->delete_event == NULL)
                 return GDK_EVENT_PROPAGATE;
@@ -103,16 +103,16 @@ DhAssistant *
 dh_assistant_new (DhApp *application)
 {
         DhAssistant *assistant;
-        DhSettings *settings;
+        DhSettingsApp *settings;
 
         assistant = g_object_new (DH_TYPE_ASSISTANT,
                                   "application", application,
                                   NULL);
 
-        settings = dh_settings_get_singleton ();
+        settings = dh_settings_app_get_singleton ();
         gtk_widget_realize (GTK_WIDGET (assistant));
         dh_util_window_settings_restore (GTK_WINDOW (assistant),
-                                         dh_settings_peek_assistant_settings (settings));
+                                         dh_settings_app_peek_assistant_settings (settings));
 
         return assistant;
 }
diff --git a/src/dh-main.c b/src/dh-main.c
index 2ebdddd..19cf209 100644
--- a/src/dh-main.c
+++ b/src/dh-main.c
@@ -22,6 +22,7 @@
 #include <glib/gi18n.h>
 #include <devhelp/devhelp.h>
 #include "dh-app.h"
+#include "dh-settings-app.h"
 
 int
 main (int argc, char **argv)
@@ -39,6 +40,7 @@ main (int argc, char **argv)
         g_object_unref (application);
 
         dh_finalize ();
+        dh_settings_app_unref_singleton ();
 
         return status;
 }
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
index b843e3b..cc5aa63 100644
--- a/src/dh-preferences.c
+++ b/src/dh-preferences.c
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <devhelp/devhelp.h>
 #include "devhelp/dh-settings.h"
+#include "dh-settings-app.h"
 #include "dh-util-app.h"
 
 static GtkWidget *prefs_dialog = NULL;
@@ -588,7 +589,8 @@ dh_preferences_init (DhPreferences *prefs)
 {
         DhPreferencesPrivate *priv;
         DhBookManager *book_manager;
-        DhSettings *settings;
+        DhSettings *settings_lib;
+        DhSettingsApp *settings_app;
         GSettings *settings_fonts;
         GSettings *settings_contents;
 
@@ -617,9 +619,10 @@ dh_preferences_init (DhPreferences *prefs)
                                  0);
 
         /* setup GSettings bindings */
-        settings = dh_settings_get_singleton ();
-        settings_fonts = dh_settings_peek_fonts_settings (settings);
-        settings_contents = dh_settings_peek_contents_settings (settings);
+        settings_app = dh_settings_app_get_singleton ();
+        settings_fonts = dh_settings_app_peek_fonts_settings (settings_app);
+        settings_lib = dh_settings_get_singleton ();
+        settings_contents = dh_settings_peek_contents_settings (settings_lib);
         g_settings_bind (settings_fonts, "use-system-fonts",
                          priv->system_fonts_button, "active",
                          G_SETTINGS_BIND_DEFAULT);
diff --git a/src/dh-settings-app.c b/src/dh-settings-app.c
new file mode 100644
index 0000000..0f0b951
--- /dev/null
+++ b/src/dh-settings-app.c
@@ -0,0 +1,216 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2012 Thomas Bechtold <toabctl gnome org>
+ * Copyright (C) 2017, 2018 Sébastien Wilmet <swilmet gnome org>
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "dh-settings-app.h"
+
+/* Devhelp GSettings schema IDs */
+#define SETTINGS_SCHEMA_ID_WINDOW               "org.gnome.devhelp.state.main.window"
+#define SETTINGS_SCHEMA_ID_PANED                "org.gnome.devhelp.state.main.paned"
+#define SETTINGS_SCHEMA_ID_ASSISTANT            "org.gnome.devhelp.state.assistant.window"
+#define SETTINGS_SCHEMA_ID_FONTS                "org.gnome.devhelp.fonts"
+
+/* Provided by the gsettings-desktop-schemas module. */
+#define SETTINGS_SCHEMA_ID_DESKTOP_INTERFACE    "org.gnome.desktop.interface"
+#define SYSTEM_FIXED_FONT_KEY                   "monospace-font-name"
+#define SYSTEM_VARIABLE_FONT_KEY                "font-name"
+
+struct _DhSettingsAppPrivate {
+        GSettings *settings_window;
+        GSettings *settings_paned;
+        GSettings *settings_assistant;
+        GSettings *settings_fonts;
+        GSettings *settings_desktop_interface;
+};
+
+enum {
+        FONTS_CHANGED,
+        N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
+/* DhSettingsApp is a singleton. */
+static DhSettingsApp *singleton = NULL;
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhSettingsApp, dh_settings_app, G_TYPE_OBJECT);
+
+static void
+dh_settings_app_dispose (GObject *object)
+{
+        DhSettingsApp *self = DH_SETTINGS_APP (object);
+
+        g_clear_object (&self->priv->settings_window);
+        g_clear_object (&self->priv->settings_paned);
+        g_clear_object (&self->priv->settings_assistant);
+        g_clear_object (&self->priv->settings_fonts);
+        g_clear_object (&self->priv->settings_desktop_interface);
+
+        G_OBJECT_CLASS (dh_settings_app_parent_class)->dispose (object);
+}
+
+static void
+dh_settings_app_finalize (GObject *object)
+{
+        if (singleton == DH_SETTINGS_APP (object))
+                singleton = NULL;
+
+        G_OBJECT_CLASS (dh_settings_app_parent_class)->finalize (object);
+}
+
+static void
+dh_settings_app_class_init (DhSettingsAppClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->dispose = dh_settings_app_dispose;
+        object_class->finalize = dh_settings_app_finalize;
+
+        signals[FONTS_CHANGED] =
+                g_signal_new ("fonts-changed",
+                              G_TYPE_FROM_CLASS (klass),
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (DhSettingsAppClass, fonts_changed),
+                              NULL, NULL, NULL,
+                              G_TYPE_NONE,
+                              2,
+                              G_TYPE_STRING,
+                              G_TYPE_STRING);
+}
+
+static void
+fonts_changed_cb (GSettings *gsettings,
+                  gchar     *key,
+                  gpointer   user_data)
+{
+        DhSettingsApp *self = DH_SETTINGS_APP (user_data);
+        gchar *fixed_font = NULL;
+        gchar *variable_font = NULL;
+
+        dh_settings_app_get_selected_fonts (self, &fixed_font, &variable_font);
+
+        g_signal_emit (self, signals[FONTS_CHANGED], 0, fixed_font, variable_font);
+
+        g_free (fixed_font);
+        g_free (variable_font);
+}
+
+static void
+dh_settings_app_init (DhSettingsApp *self)
+{
+        self->priv = dh_settings_app_get_instance_private (self);
+
+        self->priv->settings_window = g_settings_new (SETTINGS_SCHEMA_ID_WINDOW);
+        self->priv->settings_paned = g_settings_new (SETTINGS_SCHEMA_ID_PANED);
+        self->priv->settings_assistant = g_settings_new (SETTINGS_SCHEMA_ID_ASSISTANT);
+        self->priv->settings_fonts = g_settings_new (SETTINGS_SCHEMA_ID_FONTS);
+        self->priv->settings_desktop_interface = g_settings_new (SETTINGS_SCHEMA_ID_DESKTOP_INTERFACE);
+
+        g_signal_connect_object (self->priv->settings_fonts,
+                                 "changed",
+                                 G_CALLBACK (fonts_changed_cb),
+                                 self,
+                                 0);
+
+        g_signal_connect_object (self->priv->settings_desktop_interface,
+                                 "changed::" SYSTEM_FIXED_FONT_KEY,
+                                 G_CALLBACK (fonts_changed_cb),
+                                 self,
+                                 0);
+
+        g_signal_connect_object (self->priv->settings_desktop_interface,
+                                 "changed::" SYSTEM_VARIABLE_FONT_KEY,
+                                 G_CALLBACK (fonts_changed_cb),
+                                 self,
+                                 0);
+}
+
+DhSettingsApp *
+dh_settings_app_get_singleton (void)
+{
+        if (singleton == NULL)
+                singleton = g_object_new (DH_TYPE_SETTINGS_APP, NULL);
+
+        return singleton;
+}
+
+void
+dh_settings_app_unref_singleton (void)
+{
+        if (singleton != NULL)
+                g_object_unref (singleton);
+
+        /* singleton is not set to NULL here, it is set to NULL in
+         * dh_settings_app_finalize() (i.e. when we are sure that the ref count
+         * reaches 0).
+         */
+}
+
+GSettings *
+dh_settings_app_peek_window_settings (DhSettingsApp *self)
+{
+        g_return_val_if_fail (DH_IS_SETTINGS_APP (self), NULL);
+        return self->priv->settings_window;
+}
+
+GSettings *
+dh_settings_app_peek_paned_settings (DhSettingsApp *self)
+{
+        g_return_val_if_fail (DH_IS_SETTINGS_APP (self), NULL);
+        return self->priv->settings_paned;
+}
+
+GSettings *
+dh_settings_app_peek_assistant_settings (DhSettingsApp *self)
+{
+        g_return_val_if_fail (DH_IS_SETTINGS_APP (self), NULL);
+        return self->priv->settings_assistant;
+}
+
+GSettings *
+dh_settings_app_peek_fonts_settings (DhSettingsApp *self)
+{
+        g_return_val_if_fail (DH_IS_SETTINGS_APP (self), NULL);
+        return self->priv->settings_fonts;
+}
+
+void
+dh_settings_app_get_selected_fonts (DhSettingsApp  *self,
+                                    gchar         **font_name_fixed,
+                                    gchar         **font_name_variable)
+{
+        gboolean use_system_font;
+
+        g_return_if_fail (DH_IS_SETTINGS_APP (self));
+        g_return_if_fail (font_name_fixed != NULL && *font_name_fixed == NULL);
+        g_return_if_fail (font_name_variable != NULL && *font_name_variable == NULL);
+
+        use_system_font = g_settings_get_boolean (self->priv->settings_fonts, "use-system-fonts");
+
+        if (use_system_font) {
+                *font_name_fixed = g_settings_get_string (self->priv->settings_desktop_interface,
+                                                          SYSTEM_FIXED_FONT_KEY);
+                *font_name_variable = g_settings_get_string (self->priv->settings_desktop_interface,
+                                                             SYSTEM_VARIABLE_FONT_KEY);
+        } else {
+                *font_name_fixed = g_settings_get_string (self->priv->settings_fonts,
+                                                          "fixed-font");
+                *font_name_variable = g_settings_get_string (self->priv->settings_fonts,
+                                                             "variable-font");
+        }
+}
diff --git a/src/dh-settings-app.h b/src/dh-settings-app.h
new file mode 100644
index 0000000..17ac4cd
--- /dev/null
+++ b/src/dh-settings-app.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2012 Thomas Bechtold <toabctl gnome org>
+ * Copyright (C) 2017, 2018 Sébastien Wilmet <swilmet gnome org>
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DH_SETTINGS_APP_H
+#define DH_SETTINGS_APP_H
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_SETTINGS_APP                (dh_settings_app_get_type ())
+#define DH_SETTINGS_APP(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), DH_TYPE_SETTINGS_APP, 
DhSettingsApp))
+#define DH_IS_SETTINGS_APP(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DH_TYPE_SETTINGS_APP))
+#define DH_SETTINGS_APP_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), DH_TYPE_SETTINGS_APP, 
DhSettingsAppClass))
+#define DH_IS_SETTINGS_APP_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), DH_TYPE_SETTINGS_APP))
+#define DH_SETTINGS_APP_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), DH_TYPE_SETTINGS_APP, 
DhSettingsAppClass))
+
+typedef struct _DhSettingsApp        DhSettingsApp;
+typedef struct _DhSettingsAppClass   DhSettingsAppClass;
+typedef struct _DhSettingsAppPrivate DhSettingsAppPrivate;
+
+struct _DhSettingsApp {
+        GObject parent;
+        DhSettingsAppPrivate *priv;
+};
+
+struct _DhSettingsAppClass {
+        GObjectClass parent;
+
+        /* Signals */
+        void (*fonts_changed) (DhSettingsApp *settings,
+                               const gchar   *font_name_fixed,
+                               const gchar   *font_name_variable);
+};
+
+GType           dh_settings_app_get_type                    (void);
+
+DhSettingsApp * dh_settings_app_get_singleton               (void);
+
+void            dh_settings_app_unref_singleton             (void);
+
+GSettings *     dh_settings_app_peek_window_settings        (DhSettingsApp *self);
+
+GSettings *     dh_settings_app_peek_paned_settings         (DhSettingsApp *self);
+
+GSettings *     dh_settings_app_peek_assistant_settings     (DhSettingsApp *self);
+
+GSettings *     dh_settings_app_peek_fonts_settings         (DhSettingsApp *self);
+
+void            dh_settings_app_get_selected_fonts          (DhSettingsApp  *self,
+                                                             gchar         **font_name_fixed,
+                                                             gchar         **font_name_variable);
+
+G_END_DECLS
+
+#endif /* DH_SETTINGS_APP_H */
diff --git a/src/dh-window.c b/src/dh-window.c
index a857b15..1c63392 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -23,7 +23,7 @@
 #include <glib/gi18n.h>
 #include <webkit2/webkit2.h>
 #include <devhelp/devhelp.h>
-#include "devhelp/dh-settings.h"
+#include "dh-settings-app.h"
 #include "dh-tab.h"
 #include "dh-tab-label.h"
 #include "dh-util-app.h"
@@ -70,11 +70,11 @@ static gboolean
 dh_window_delete_event (GtkWidget   *widget,
                         GdkEventAny *event)
 {
-        DhSettings *settings;
+        DhSettingsApp *settings;
 
-        settings = dh_settings_get_singleton ();
+        settings = dh_settings_app_get_singleton ();
         dh_util_window_settings_save (GTK_WINDOW (widget),
-                                      dh_settings_peek_window_settings (settings));
+                                      dh_settings_app_peek_window_settings (settings));
 
         if (GTK_WIDGET_CLASS (dh_window_parent_class)->delete_event == NULL)
                 return GDK_EVENT_PROPAGATE;
@@ -457,10 +457,10 @@ add_actions (DhWindow *window)
 }
 
 static void
-settings_fonts_changed_cb (DhSettings  *settings,
-                           const gchar *font_name_fixed,
-                           const gchar *font_name_variable,
-                           DhWindow    *window)
+settings_fonts_changed_cb (DhSettingsApp *settings,
+                           const gchar   *font_name_fixed,
+                           const gchar   *font_name_variable,
+                           DhWindow      *window)
 {
         DhWindowPrivate *priv = dh_window_get_instance_private (window);
         gint n_pages;
@@ -680,7 +680,7 @@ dh_window_init (DhWindow *window)
 {
         DhWindowPrivate *priv = dh_window_get_instance_private (window);
         GtkApplication *app;
-        DhSettings *settings;
+        DhSettingsApp *settings;
         GSettings *paned_settings;
 
         gtk_widget_init_template (GTK_WIDGET (window));
@@ -693,14 +693,14 @@ dh_window_init (DhWindow *window)
                                                 priv->window_menu_plus_app_menu);
         }
 
-        settings = dh_settings_get_singleton ();
+        settings = dh_settings_app_get_singleton ();
         g_signal_connect_object (settings,
                                  "fonts-changed",
                                  G_CALLBACK (settings_fonts_changed_cb),
                                  window,
                                  0);
 
-        paned_settings = dh_settings_peek_paned_settings (settings);
+        paned_settings = dh_settings_app_peek_paned_settings (settings);
         g_settings_bind (paned_settings, "position",
                          priv->hpaned, "position",
                          G_SETTINGS_BIND_DEFAULT |
@@ -950,7 +950,7 @@ open_new_tab (DhWindow    *window,
         DhWindowPrivate *priv = dh_window_get_instance_private (window);
         DhTab *tab;
         DhWebView *web_view;
-        DhSettings *settings;
+        DhSettingsApp *settings;
         gchar *font_fixed = NULL;
         gchar *font_variable = NULL;
         GtkWidget *label;
@@ -963,8 +963,8 @@ open_new_tab (DhWindow    *window,
         web_view = dh_tab_get_web_view (tab);
 
         /* Set font */
-        settings = dh_settings_get_singleton ();
-        dh_settings_get_selected_fonts (settings, &font_fixed, &font_variable);
+        settings = dh_settings_app_get_singleton ();
+        dh_settings_app_get_selected_fonts (settings, &font_fixed, &font_variable);
         dh_util_view_set_font (WEBKIT_WEB_VIEW (web_view), font_fixed, font_variable);
         g_free (font_fixed);
         g_free (font_variable);
@@ -1027,7 +1027,7 @@ GtkWidget *
 dh_window_new (GtkApplication *application)
 {
         DhWindow *window;
-        DhSettings *settings;
+        DhSettingsApp *settings;
 
         g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
 
@@ -1035,10 +1035,10 @@ dh_window_new (GtkApplication *application)
                                "application", application,
                                NULL);
 
-        settings = dh_settings_get_singleton ();
+        settings = dh_settings_app_get_singleton ();
         gtk_widget_realize (GTK_WIDGET (window));
         dh_util_window_settings_restore (GTK_WINDOW (window),
-                                         dh_settings_peek_window_settings (settings));
+                                         dh_settings_app_peek_window_settings (settings));
 
         return GTK_WIDGET (window);
 }


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