[devhelp] Implement DhProfileBuilder
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Implement DhProfileBuilder
- Date: Wed, 4 Apr 2018 14:49:26 +0000 (UTC)
commit 08482765d36992fd31e449da39023f07fe422f2e
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Apr 4 16:35:29 2018 +0200
Implement DhProfileBuilder
devhelp/devhelp.h | 1 +
devhelp/dh-profile-builder.c | 123 +++++++++++++++++++++++++++++++++++
devhelp/dh-profile-builder.h | 65 ++++++++++++++++++
devhelp/dh-profile.c | 7 ++-
devhelp/meson.build | 2 +
docs/reference/devhelp-docs.xml | 1 +
docs/reference/devhelp-sections.txt | 18 +++++
po/POTFILES.in | 1 +
8 files changed, 217 insertions(+), 1 deletions(-)
---
diff --git a/devhelp/devhelp.h b/devhelp/devhelp.h
index 114e8bb..59aaedd 100644
--- a/devhelp/devhelp.h
+++ b/devhelp/devhelp.h
@@ -34,6 +34,7 @@
#include <devhelp/dh-keyword-model.h>
#include <devhelp/dh-link.h>
#include <devhelp/dh-profile.h>
+#include <devhelp/dh-profile-builder.h>
#include <devhelp/dh-settings.h>
#include <devhelp/dh-settings-builder.h>
#include <devhelp/dh-sidebar.h>
diff --git a/devhelp/dh-profile-builder.c b/devhelp/dh-profile-builder.c
new file mode 100644
index 0000000..33655bb
--- /dev/null
+++ b/devhelp/dh-profile-builder.c
@@ -0,0 +1,123 @@
+/* -*- 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-builder.h"
+
+/**
+ * SECTION:dh-profile-builder
+ * @Title: DhProfileBuilder
+ * @Short_description: Builds #DhProfile objects
+ *
+ * #DhProfileBuilder permits to build #DhProfile objects. Once a #DhProfile
+ * object is created, it is immutable.
+ */
+
+/* API design:
+ *
+ * It follows the builder pattern, see:
+ * https://blogs.gnome.org/otte/2018/02/03/builders/
+ * but it is implemented in a simpler way, to have less boilerplate.
+ */
+
+struct _DhProfileBuilderPrivate {
+ DhSettings *settings;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhProfileBuilder, dh_profile_builder, G_TYPE_OBJECT)
+
+static void
+dh_profile_builder_dispose (GObject *object)
+{
+ DhProfileBuilder *builder = DH_PROFILE_BUILDER (object);
+
+ g_clear_object (&builder->priv->settings);
+
+ G_OBJECT_CLASS (dh_profile_builder_parent_class)->dispose (object);
+}
+
+static void
+dh_profile_builder_class_init (DhProfileBuilderClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = dh_profile_builder_dispose;
+}
+
+static void
+dh_profile_builder_init (DhProfileBuilder *builder)
+{
+ builder->priv = dh_profile_builder_get_instance_private (builder);
+}
+
+/**
+ * dh_profile_builder_new:
+ *
+ * Returns: (transfer full): a new #DhProfileBuilder.
+ * Since: 3.30
+ */
+DhProfileBuilder *
+dh_profile_builder_new (void)
+{
+ return g_object_new (DH_TYPE_PROFILE_BUILDER, NULL);
+}
+
+/**
+ * dh_profile_builder_set_settings:
+ * @builder: a #DhProfileBuilder.
+ * @settings: a #DhSettings.
+ *
+ * Sets the #DhSettings object.
+ *
+ * If you don't call this function, the default #DhSettings object as returned
+ * by dh_settings_get_default() will be used.
+ *
+ * Since: 3.30
+ */
+void
+dh_profile_builder_set_settings (DhProfileBuilder *builder,
+ DhSettings *settings)
+{
+ g_return_if_fail (DH_IS_PROFILE_BUILDER (builder));
+ g_return_if_fail (DH_IS_SETTINGS (settings));
+
+ g_set_object (&builder->priv->settings, settings);
+}
+
+/**
+ * dh_profile_builder_create_object:
+ * @builder: a #DhProfileBuilder.
+ *
+ * Returns: (transfer full): the newly created #DhProfile object.
+ * Since: 3.30
+ */
+DhProfile *
+dh_profile_builder_create_object (DhProfileBuilder *builder)
+{
+ g_return_val_if_fail (DH_IS_PROFILE_BUILDER (builder), NULL);
+
+ /* Set default values if needed.
+ * Use all the set functions to test them, to have the same code paths
+ * as if the set functions were already called.
+ */
+ if (builder->priv->settings == NULL)
+ dh_profile_builder_set_settings (builder, dh_settings_get_default ());
+
+ return _dh_profile_new (builder->priv->settings);
+}
diff --git a/devhelp/dh-profile-builder.h b/devhelp/dh-profile-builder.h
new file mode 100644
index 0000000..6623275
--- /dev/null
+++ b/devhelp/dh-profile-builder.h
@@ -0,0 +1,65 @@
+/* -*- 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_BUILDER_H
+#define DH_PROFILE_BUILDER_H
+
+#include <glib-object.h>
+#include <devhelp/dh-profile.h>
+#include <devhelp/dh-settings.h>
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_PROFILE_BUILDER (dh_profile_builder_get_type ())
+#define DH_PROFILE_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DH_TYPE_PROFILE_BUILDER,
DhProfileBuilder))
+#define DH_PROFILE_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DH_TYPE_PROFILE_BUILDER,
DhProfileBuilderClass))
+#define DH_IS_PROFILE_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DH_TYPE_PROFILE_BUILDER))
+#define DH_IS_PROFILE_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DH_TYPE_PROFILE_BUILDER))
+#define DH_PROFILE_BUILDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DH_TYPE_PROFILE_BUILDER,
DhProfileBuilderClass))
+
+typedef struct _DhProfileBuilder DhProfileBuilder;
+typedef struct _DhProfileBuilderClass DhProfileBuilderClass;
+typedef struct _DhProfileBuilderPrivate DhProfileBuilderPrivate;
+
+struct _DhProfileBuilder {
+ GObject parent;
+
+ DhProfileBuilderPrivate *priv;
+};
+
+struct _DhProfileBuilderClass {
+ GObjectClass parent_class;
+
+ /* Padding for future expansion */
+ gpointer padding[12];
+};
+
+GType dh_profile_builder_get_type (void);
+
+DhProfileBuilder * dh_profile_builder_new (void);
+
+void dh_profile_builder_set_settings (DhProfileBuilder *builder,
+ DhSettings *settings);
+
+DhProfile * dh_profile_builder_create_object (DhProfileBuilder *builder);
+
+G_END_DECLS
+
+#endif /* DH_PROFILE_BUILDER_H */
diff --git a/devhelp/dh-profile.c b/devhelp/dh-profile.c
index b13518c..d5d6e26 100644
--- a/devhelp/dh-profile.c
+++ b/devhelp/dh-profile.c
@@ -19,6 +19,7 @@
*/
#include "dh-profile.h"
+#include "dh-profile-builder.h"
/**
* SECTION:dh-profile
@@ -94,7 +95,11 @@ DhProfile *
dh_profile_get_default (void)
{
if (default_instance == NULL) {
- default_instance = _dh_profile_new (dh_settings_get_default ());
+ DhProfileBuilder *builder;
+
+ builder = dh_profile_builder_new ();
+ default_instance = dh_profile_builder_create_object (builder);
+ g_object_unref (builder);
}
return default_instance;
diff --git a/devhelp/meson.build b/devhelp/meson.build
index 2e71563..314d0b4 100644
--- a/devhelp/meson.build
+++ b/devhelp/meson.build
@@ -9,6 +9,7 @@ libdevhelp_public_headers = [
'dh-keyword-model.h',
'dh-link.h',
'dh-profile.h',
+ 'dh-profile-builder.h',
'dh-settings.h',
'dh-settings-builder.h',
'dh-sidebar.h'
@@ -24,6 +25,7 @@ libdevhelp_public_c_files = [
'dh-keyword-model.c',
'dh-link.c',
'dh-profile.c',
+ 'dh-profile-builder.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 5950927..a5a0a08 100644
--- a/docs/reference/devhelp-docs.xml
+++ b/docs/reference/devhelp-docs.xml
@@ -21,6 +21,7 @@
<title>General</title>
<xi:include href="xml/init.xml"/>
<xi:include href="xml/dh-profile.xml"/>
+ <xi:include href="xml/dh-profile-builder.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 41b9780..48ddfb1 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -167,6 +167,24 @@ dh_profile_get_type
</SECTION>
<SECTION>
+<FILE>dh-profile-builder</FILE>
+DhProfileBuilder
+dh_profile_builder_new
+dh_profile_builder_set_settings
+dh_profile_builder_create_object
+<SUBSECTION Standard>
+DH_IS_PROFILE_BUILDER
+DH_IS_PROFILE_BUILDER_CLASS
+DH_PROFILE_BUILDER
+DH_PROFILE_BUILDER_CLASS
+DH_PROFILE_BUILDER_GET_CLASS
+DH_TYPE_PROFILE_BUILDER
+DhProfileBuilderClass
+DhProfileBuilderPrivate
+dh_profile_builder_get_type
+</SECTION>
+
+<SECTION>
<FILE>dh-settings</FILE>
DhSettings
dh_settings_get_default
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c322423..233d865 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-builder.c
devhelp/dh-profile.c
devhelp/dh-search-context.c
devhelp/dh-settings-builder.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]