[devhelp] Implement DhSettingsBuilder
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Implement DhSettingsBuilder
- Date: Mon, 2 Apr 2018 08:31:54 +0000 (UTC)
commit a73b89db459ab0904dfcbafcccffa3329bd35477
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Apr 2 10:05:40 2018 +0200
Implement DhSettingsBuilder
The API design is documented in the code.
The gtk-doc comments will be added later, currently DhSettingsBuilder is
not yet very useful, since the other classes in the library call
dh_settings_get_default(). It is planned to add a DhProfile class and
add "profile" properties to relevant classes.
devhelp/devhelp.h | 1 +
devhelp/dh-settings-builder.c | 83 +++++++++++++++++++++++++++++++++++++++++
devhelp/dh-settings-builder.h | 65 ++++++++++++++++++++++++++++++++
devhelp/dh-settings.c | 14 +++++-
devhelp/dh-settings.h | 3 +
devhelp/meson.build | 2 +
docs/reference/meson.build | 1 +
po/POTFILES.in | 1 +
8 files changed, 167 insertions(+), 3 deletions(-)
---
diff --git a/devhelp/devhelp.h b/devhelp/devhelp.h
index dd6027b..ad03dcb 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-settings.h>
+#include <devhelp/dh-settings-builder.h>
#include <devhelp/dh-sidebar.h>
#endif /* DEVHELP_H */
diff --git a/devhelp/dh-settings-builder.c b/devhelp/dh-settings-builder.c
new file mode 100644
index 0000000..af3b8a4
--- /dev/null
+++ b/devhelp/dh-settings-builder.c
@@ -0,0 +1,83 @@
+/* -*- 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-settings-builder.h"
+
+/* API design:
+ *
+ * Follow the builder pattern, see:
+ * https://blogs.gnome.org/otte/2018/02/03/builders/
+ * but implement it in a simpler way, to have less boilerplate.
+ */
+
+struct _DhSettingsBuilderPrivate {
+ gchar *contents_path;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhSettingsBuilder, dh_settings_builder, G_TYPE_OBJECT)
+
+static void
+dh_settings_builder_finalize (GObject *object)
+{
+ DhSettingsBuilder *builder = DH_SETTINGS_BUILDER (object);
+
+ g_free (builder->priv->contents_path);
+
+ G_OBJECT_CLASS (dh_settings_builder_parent_class)->finalize (object);
+}
+
+static void
+dh_settings_builder_class_init (DhSettingsBuilderClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = dh_settings_builder_finalize;
+}
+
+static void
+dh_settings_builder_init (DhSettingsBuilder *builder)
+{
+ builder->priv = dh_settings_builder_get_instance_private (builder);
+}
+
+DhSettingsBuilder *
+dh_settings_builder_new (void)
+{
+ return g_object_new (DH_TYPE_SETTINGS_BUILDER, NULL);
+}
+
+void
+dh_settings_builder_set_contents_path (DhSettingsBuilder *builder,
+ const gchar *contents_path)
+{
+ g_return_if_fail (DH_IS_SETTINGS_BUILDER (builder));
+ g_return_if_fail (contents_path != NULL);
+
+ g_free (builder->priv->contents_path);
+ builder->priv->contents_path = g_strdup (contents_path);
+}
+
+DhSettings *
+dh_settings_builder_create_object (DhSettingsBuilder *builder)
+{
+ g_return_val_if_fail (DH_IS_SETTINGS_BUILDER (builder), NULL);
+
+ return _dh_settings_new (builder->priv->contents_path);
+}
diff --git a/devhelp/dh-settings-builder.h b/devhelp/dh-settings-builder.h
new file mode 100644
index 0000000..30cb34b
--- /dev/null
+++ b/devhelp/dh-settings-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_SETTINGS_BUILDER_H
+#define DH_SETTINGS_BUILDER_H
+
+#include <glib-object.h>
+#include <devhelp/dh-settings.h>
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_SETTINGS_BUILDER (dh_settings_builder_get_type ())
+#define DH_SETTINGS_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DH_TYPE_SETTINGS_BUILDER,
DhSettingsBuilder))
+#define DH_SETTINGS_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DH_TYPE_SETTINGS_BUILDER,
DhSettingsBuilderClass))
+#define DH_IS_SETTINGS_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DH_TYPE_SETTINGS_BUILDER))
+#define DH_IS_SETTINGS_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DH_TYPE_SETTINGS_BUILDER))
+#define DH_SETTINGS_BUILDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DH_TYPE_SETTINGS_BUILDER,
DhSettingsBuilderClass))
+
+typedef struct _DhSettingsBuilder DhSettingsBuilder;
+typedef struct _DhSettingsBuilderClass DhSettingsBuilderClass;
+typedef struct _DhSettingsBuilderPrivate DhSettingsBuilderPrivate;
+
+struct _DhSettingsBuilder {
+ GObject parent;
+
+ DhSettingsBuilderPrivate *priv;
+};
+
+struct _DhSettingsBuilderClass {
+ GObjectClass parent_class;
+
+ /* Padding for future expansion */
+ gpointer padding[12];
+};
+
+GType dh_settings_builder_get_type (void);
+
+DhSettingsBuilder *
+ dh_settings_builder_new (void);
+
+void dh_settings_builder_set_contents_path (DhSettingsBuilder *builder,
+ const gchar *contents_path);
+
+DhSettings * dh_settings_builder_create_object (DhSettingsBuilder *builder);
+
+G_END_DECLS
+
+#endif /* DH_SETTINGS_BUILDER_H */
diff --git a/devhelp/dh-settings.c b/devhelp/dh-settings.c
index fbe75b1..49a9f8a 100644
--- a/devhelp/dh-settings.c
+++ b/devhelp/dh-settings.c
@@ -20,6 +20,7 @@
*/
#include "dh-settings.h"
+#include "dh-settings-builder.h"
/**
* SECTION:dh-settings
@@ -76,7 +77,7 @@ dh_settings_init (DhSettings *self)
self->priv = dh_settings_get_instance_private (self);
}
-static DhSettings *
+DhSettings *
_dh_settings_new (const gchar *contents_path)
{
DhSettings *object;
@@ -109,8 +110,15 @@ DhSettings *
dh_settings_get_default (void)
{
if (default_instance == NULL) {
- default_instance = _dh_settings_new (/* Must be compatible with Devhelp app version 3.28: */
- "/org/gnome/devhelp/state/main/contents/");
+ DhSettingsBuilder *builder;
+
+ builder = dh_settings_builder_new ();
+
+ /* Must be compatible with Devhelp app version 3.28: */
+ dh_settings_builder_set_contents_path (builder, "/org/gnome/devhelp/state/main/contents/");
+
+ default_instance = dh_settings_builder_create_object (builder);
+ g_object_unref (builder);
}
return default_instance;
diff --git a/devhelp/dh-settings.h b/devhelp/dh-settings.h
index 009dd3d..b8729b7 100644
--- a/devhelp/dh-settings.h
+++ b/devhelp/dh-settings.h
@@ -51,6 +51,9 @@ struct _DhSettingsClass {
GType dh_settings_get_type (void) G_GNUC_CONST;
+G_GNUC_INTERNAL
+DhSettings * _dh_settings_new (const gchar *contents_path);
+
DhSettings * dh_settings_get_default (void);
G_GNUC_INTERNAL
diff --git a/devhelp/meson.build b/devhelp/meson.build
index d9945ca..aadf497 100644
--- a/devhelp/meson.build
+++ b/devhelp/meson.build
@@ -9,6 +9,7 @@ libdevhelp_public_headers = [
'dh-keyword-model.h',
'dh-link.h',
'dh-settings.h',
+ 'dh-settings-builder.h',
'dh-sidebar.h'
]
@@ -22,6 +23,7 @@ libdevhelp_public_c_files = [
'dh-keyword-model.c',
'dh-link.c',
'dh-settings.c',
+ 'dh-settings-builder.c',
'dh-sidebar.c'
]
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index ac9c213..d80af06 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -15,6 +15,7 @@ GNOME.gtkdoc(
'dh-error.h',
'dh-parser.h',
'dh-search-context.h',
+ 'dh-settings-builder.h',
'dh-util-lib.h'
],
install : true
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0c888fe..a2c8dd5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,6 +15,7 @@ devhelp/dh-keyword-model.c
devhelp/dh-link.c
devhelp/dh-parser.c
devhelp/dh-search-context.c
+devhelp/dh-settings-builder.c
devhelp/dh-settings.c
devhelp/dh-sidebar.c
devhelp/dh-util-lib.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]