[devhelp] Implement DhProfile



commit e313194005f583fa33eb0ebefccacc2f4a427fc7
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Apr 4 15:29:59 2018 +0200

    Implement DhProfile

 devhelp/devhelp.h                   |    1 +
 devhelp/dh-init.c                   |    2 +
 devhelp/dh-profile.c                |  128 +++++++++++++++++++++++++++++++++++
 devhelp/dh-profile.h                |   67 ++++++++++++++++++
 devhelp/meson.build                 |    2 +
 docs/reference/devhelp-docs.xml     |    1 +
 docs/reference/devhelp-sections.txt |   17 +++++
 po/POTFILES.in                      |    1 +
 8 files changed, 219 insertions(+), 0 deletions(-)
---
diff --git a/devhelp/devhelp.h b/devhelp/devhelp.h
index ad03dcb..114e8bb 100644
--- a/devhelp/devhelp.h
+++ b/devhelp/devhelp.h
@@ -33,6 +33,7 @@
 #include <devhelp/dh-init.h>
 #include <devhelp/dh-keyword-model.h>
 #include <devhelp/dh-link.h>
+#include <devhelp/dh-profile.h>
 #include <devhelp/dh-settings.h>
 #include <devhelp/dh-settings-builder.h>
 #include <devhelp/dh-sidebar.h>
diff --git a/devhelp/dh-init.c b/devhelp/dh-init.c
index bdc8b11..4e946d6 100644
--- a/devhelp/dh-init.c
+++ b/devhelp/dh-init.c
@@ -23,6 +23,7 @@
 #include "dh-init.h"
 #include <glib/gi18n-lib.h>
 #include "dh-book-manager.h"
+#include "dh-profile.h"
 #include "dh-settings.h"
 
 /**
@@ -82,6 +83,7 @@ dh_finalize (void)
          */
         if (!done) {
                 _dh_book_manager_unref_singleton ();
+                _dh_profile_unref_default ();
                 _dh_settings_unref_default ();
                 done = TRUE;
         }
diff --git a/devhelp/dh-profile.c b/devhelp/dh-profile.c
new file mode 100644
index 0000000..b13518c
--- /dev/null
+++ b/devhelp/dh-profile.c
@@ -0,0 +1,128 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * This file is part of Devhelp.
+ *
+ * Copyright (C) 2018 Sébastien Wilmet <swilmet gnome org>
+ *
+ * Devhelp 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.
+ *
+ * Devhelp 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 Devhelp.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "dh-profile.h"
+
+/**
+ * SECTION:dh-profile
+ * @Title: DhProfile
+ * @Short_description: libdevhelp profile
+ */
+
+struct _DhProfilePrivate {
+        DhSettings *settings;
+};
+
+static DhProfile *default_instance = NULL;
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhProfile, dh_profile, G_TYPE_OBJECT)
+
+static void
+dh_profile_dispose (GObject *object)
+{
+        DhProfile *profile = DH_PROFILE (object);
+
+        g_clear_object (&profile->priv->settings);
+
+        G_OBJECT_CLASS (dh_profile_parent_class)->dispose (object);
+}
+
+static void
+dh_profile_finalize (GObject *object)
+{
+        if (default_instance == DH_PROFILE (object))
+                default_instance = NULL;
+
+        G_OBJECT_CLASS (dh_profile_parent_class)->finalize (object);
+}
+
+static void
+dh_profile_class_init (DhProfileClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->dispose = dh_profile_dispose;
+        object_class->finalize = dh_profile_finalize;
+}
+
+static void
+dh_profile_init (DhProfile *profile)
+{
+        profile->priv = dh_profile_get_instance_private (profile);
+}
+
+DhProfile *
+_dh_profile_new (DhSettings *settings)
+{
+        DhProfile *profile;
+
+        g_return_val_if_fail (DH_IS_SETTINGS (settings), NULL);
+
+        profile = g_object_new (DH_TYPE_PROFILE, NULL);
+        profile->priv->settings = g_object_ref (settings);
+
+        return profile;
+}
+
+/**
+ * dh_profile_get_default:
+ *
+ * Gets the default #DhProfile object. It has the default #DhSettings object as
+ * returned by dh_settings_get_default().
+ *
+ * Returns: (transfer none): the default #DhProfile object.
+ * Since: 3.30
+ */
+DhProfile *
+dh_profile_get_default (void)
+{
+        if (default_instance == NULL) {
+                default_instance = _dh_profile_new (dh_settings_get_default ());
+        }
+
+        return default_instance;
+}
+
+void
+_dh_profile_unref_default (void)
+{
+        if (default_instance != NULL)
+                g_object_unref (default_instance);
+
+        /* default_instance is not set to NULL here, it is set to NULL in
+         * dh_profile_finalize() (i.e. when we are sure that the ref count
+         * reaches 0).
+         */
+}
+
+/**
+ * dh_profile_get_settings:
+ * @profile: a #DhProfile.
+ *
+ * Returns: (transfer none): the #DhSettings of @profile.
+ * Since: 3.30
+ */
+DhSettings *
+dh_profile_get_settings (DhProfile *profile)
+{
+        g_return_val_if_fail (DH_IS_PROFILE (profile), NULL);
+
+        return profile->priv->settings;
+}
diff --git a/devhelp/dh-profile.h b/devhelp/dh-profile.h
new file mode 100644
index 0000000..26bf308
--- /dev/null
+++ b/devhelp/dh-profile.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * This file is part of Devhelp.
+ *
+ * Copyright (C) 2018 Sébastien Wilmet <swilmet gnome org>
+ *
+ * Devhelp 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.
+ *
+ * Devhelp 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 Devhelp.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DH_PROFILE_H
+#define DH_PROFILE_H
+
+#include <glib-object.h>
+#include <devhelp/dh-settings.h>
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_PROFILE             (dh_profile_get_type ())
+#define DH_PROFILE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), DH_TYPE_PROFILE, DhProfile))
+#define DH_PROFILE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), DH_TYPE_PROFILE, DhProfileClass))
+#define DH_IS_PROFILE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DH_TYPE_PROFILE))
+#define DH_IS_PROFILE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), DH_TYPE_PROFILE))
+#define DH_PROFILE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), DH_TYPE_PROFILE, DhProfileClass))
+
+typedef struct _DhProfile         DhProfile;
+typedef struct _DhProfileClass    DhProfileClass;
+typedef struct _DhProfilePrivate  DhProfilePrivate;
+
+struct _DhProfile {
+        GObject parent;
+
+        DhProfilePrivate *priv;
+};
+
+struct _DhProfileClass {
+        GObjectClass parent_class;
+
+        /* Padding for future expansion */
+        gpointer padding[12];
+};
+
+GType           dh_profile_get_type             (void);
+
+G_GNUC_INTERNAL
+DhProfile *     _dh_profile_new                 (DhSettings *settings);
+
+DhProfile *     dh_profile_get_default          (void);
+
+G_GNUC_INTERNAL
+void            _dh_profile_unref_default       (void);
+
+DhSettings *    dh_profile_get_settings         (DhProfile *profile);
+
+G_END_DECLS
+
+#endif /* DH_PROFILE_H */
diff --git a/devhelp/meson.build b/devhelp/meson.build
index aadf497..2e71563 100644
--- a/devhelp/meson.build
+++ b/devhelp/meson.build
@@ -8,6 +8,7 @@ libdevhelp_public_headers = [
         'dh-init.h',
         'dh-keyword-model.h',
         'dh-link.h',
+        'dh-profile.h',
         'dh-settings.h',
         'dh-settings-builder.h',
         'dh-sidebar.h'
@@ -22,6 +23,7 @@ libdevhelp_public_c_files = [
         'dh-init.c',
         'dh-keyword-model.c',
         'dh-link.c',
+        'dh-profile.c',
         'dh-settings.c',
         'dh-settings-builder.c',
         'dh-sidebar.c'
diff --git a/docs/reference/devhelp-docs.xml b/docs/reference/devhelp-docs.xml
index ed3e626..5950927 100644
--- a/docs/reference/devhelp-docs.xml
+++ b/docs/reference/devhelp-docs.xml
@@ -20,6 +20,7 @@
     <chapter id="general">
       <title>General</title>
       <xi:include href="xml/init.xml"/>
+      <xi:include href="xml/dh-profile.xml"/>
       <xi:include href="xml/dh-settings.xml"/>
       <xi:include href="xml/dh-settings-builder.xml"/>
     </chapter>
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index 2c9ed72..41b9780 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -150,6 +150,23 @@ dh_link_type_get_type
 </SECTION>
 
 <SECTION>
+<FILE>dh-profile</FILE>
+DhProfile
+dh_profile_get_default
+dh_profile_get_settings
+<SUBSECTION Standard>
+DH_IS_PROFILE
+DH_IS_PROFILE_CLASS
+DH_PROFILE
+DH_PROFILE_CLASS
+DH_PROFILE_GET_CLASS
+DH_TYPE_PROFILE
+DhProfileClass
+DhProfilePrivate
+dh_profile_get_type
+</SECTION>
+
+<SECTION>
 <FILE>dh-settings</FILE>
 DhSettings
 dh_settings_get_default
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a2c8dd5..c322423 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,6 +14,7 @@ devhelp/dh-init.c
 devhelp/dh-keyword-model.c
 devhelp/dh-link.c
 devhelp/dh-parser.c
+devhelp/dh-profile.c
 devhelp/dh-search-context.c
 devhelp/dh-settings-builder.c
 devhelp/dh-settings.c


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