[devhelp] Implement DhBookListBuilder public class



commit c5ad3445fbd7a76989a60a0cc4bd59c489d55d19
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Apr 25 16:37:19 2018 +0200

    Implement DhBookListBuilder public class

 devhelp/devhelp.h                   |    1 +
 devhelp/dh-book-list-builder.c      |  126 +++++++++++++++++++++++++++++++++++
 devhelp/dh-book-list-builder.h      |   64 ++++++++++++++++++
 devhelp/meson.build                 |    2 +
 docs/reference/devhelp-docs.xml     |    1 +
 docs/reference/devhelp-sections.txt |   18 +++++
 po/POTFILES.in                      |    1 +
 7 files changed, 213 insertions(+), 0 deletions(-)
---
diff --git a/devhelp/devhelp.h b/devhelp/devhelp.h
index 1278a7d..a90a9f1 100644
--- a/devhelp/devhelp.h
+++ b/devhelp/devhelp.h
@@ -28,6 +28,7 @@
 #include <devhelp/dh-assistant-view.h>
 #include <devhelp/dh-book.h>
 #include <devhelp/dh-book-list.h>
+#include <devhelp/dh-book-list-builder.h>
 #include <devhelp/dh-book-manager.h>
 #include <devhelp/dh-book-tree.h>
 #include <devhelp/dh-completion.h>
diff --git a/devhelp/dh-book-list-builder.c b/devhelp/dh-book-list-builder.c
new file mode 100644
index 0000000..080edd2
--- /dev/null
+++ b/devhelp/dh-book-list-builder.c
@@ -0,0 +1,126 @@
+/* -*- 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-book-list-builder.h"
+#include "dh-book-list-simple.h"
+
+/**
+ * SECTION:dh-book-list-builder
+ * @Title: DhBookListBuilder
+ * @Short_description: Builds #DhBookList objects
+ *
+ * #DhBookListBuilder permits to build #DhBookList objects.
+ */
+
+/* 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 _DhBookListBuilderPrivate {
+        /* List of DhBookList*. */
+        GList *sub_book_lists;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhBookListBuilder, dh_book_list_builder, G_TYPE_OBJECT)
+
+static void
+dh_book_list_builder_dispose (GObject *object)
+{
+        DhBookListBuilder *builder = DH_BOOK_LIST_BUILDER (object);
+
+        g_list_free_full (builder->priv->sub_book_lists, g_object_unref);
+        builder->priv->sub_book_lists = NULL;
+
+        G_OBJECT_CLASS (dh_book_list_builder_parent_class)->dispose (object);
+}
+
+static void
+dh_book_list_builder_class_init (DhBookListBuilderClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->dispose = dh_book_list_builder_dispose;
+}
+
+static void
+dh_book_list_builder_init (DhBookListBuilder *builder)
+{
+        builder->priv = dh_book_list_builder_get_instance_private (builder);
+}
+
+/**
+ * dh_book_list_builder_new:
+ *
+ * Returns: (transfer full): a new #DhBookListBuilder.
+ * Since: 3.30
+ */
+DhBookListBuilder *
+dh_book_list_builder_new (void)
+{
+        return g_object_new (DH_TYPE_BOOK_LIST_BUILDER, NULL);
+}
+
+/**
+ * dh_book_list_builder_add_sub_book_list:
+ * @builder: a #DhBookListBuilder.
+ * @sub_book_list: a #DhBookList.
+ *
+ * Adds @sub_book_list.
+ *
+ * The #DhBookList object that will be created with
+ * dh_book_list_builder_create_object() will contain all the sub-#DhBookList's
+ * added with this function (and it will listen to their signals). The
+ * sub-#DhBookList's must be added in order of decreasing priority (the first
+ * sub-#DhBookList added has the highest priority). The priority is used in case
+ * of book ID conflicts (see dh_book_get_id()).
+ *
+ * Since: 3.30
+ */
+void
+dh_book_list_builder_add_sub_book_list (DhBookListBuilder *builder,
+                                        DhBookList        *sub_book_list)
+{
+        g_return_if_fail (DH_IS_BOOK_LIST_BUILDER (builder));
+        g_return_if_fail (DH_IS_BOOK_LIST (sub_book_list));
+
+        builder->priv->sub_book_lists = g_list_append (builder->priv->sub_book_lists,
+                                                       g_object_ref (sub_book_list));
+}
+
+/**
+ * dh_book_list_builder_create_object:
+ * @builder: a #DhBookListBuilder.
+ *
+ * Creates the #DhBookList. It actually creates a subclass of #DhBookList, but
+ * the subclass is not exposed to the public API.
+ *
+ * Returns: (transfer full): the newly created #DhBookList object.
+ * Since: 3.30
+ */
+DhBookList *
+dh_book_list_builder_create_object (DhBookListBuilder *builder)
+{
+        g_return_val_if_fail (DH_IS_BOOK_LIST_BUILDER (builder), NULL);
+
+        return _dh_book_list_simple_new (builder->priv->sub_book_lists);
+}
diff --git a/devhelp/dh-book-list-builder.h b/devhelp/dh-book-list-builder.h
new file mode 100644
index 0000000..9cb0cc0
--- /dev/null
+++ b/devhelp/dh-book-list-builder.h
@@ -0,0 +1,64 @@
+/* -*- 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_BOOK_LIST_BUILDER_H
+#define DH_BOOK_LIST_BUILDER_H
+
+#include <glib-object.h>
+#include <devhelp/dh-book-list.h>
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_BOOK_LIST_BUILDER             (dh_book_list_builder_get_type ())
+#define DH_BOOK_LIST_BUILDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), DH_TYPE_BOOK_LIST_BUILDER, 
DhBookListBuilder))
+#define DH_BOOK_LIST_BUILDER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), DH_TYPE_BOOK_LIST_BUILDER, 
DhBookListBuilderClass))
+#define DH_IS_BOOK_LIST_BUILDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DH_TYPE_BOOK_LIST_BUILDER))
+#define DH_IS_BOOK_LIST_BUILDER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), DH_TYPE_BOOK_LIST_BUILDER))
+#define DH_BOOK_LIST_BUILDER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), DH_TYPE_BOOK_LIST_BUILDER, 
DhBookListBuilderClass))
+
+typedef struct _DhBookListBuilder         DhBookListBuilder;
+typedef struct _DhBookListBuilderClass    DhBookListBuilderClass;
+typedef struct _DhBookListBuilderPrivate  DhBookListBuilderPrivate;
+
+struct _DhBookListBuilder {
+        GObject parent;
+
+        DhBookListBuilderPrivate *priv;
+};
+
+struct _DhBookListBuilderClass {
+        GObjectClass parent_class;
+
+        /* Padding for future expansion */
+        gpointer padding[12];
+};
+
+GType                   dh_book_list_builder_get_type           (void);
+
+DhBookListBuilder *     dh_book_list_builder_new                (void);
+
+void                    dh_book_list_builder_add_sub_book_list  (DhBookListBuilder *builder,
+                                                                 DhBookList        *sub_book_list);
+
+DhBookList *            dh_book_list_builder_create_object      (DhBookListBuilder *builder);
+
+G_END_DECLS
+
+#endif /* DH_BOOK_LIST_BUILDER_H */
diff --git a/devhelp/meson.build b/devhelp/meson.build
index ac89def..d3093e2 100644
--- a/devhelp/meson.build
+++ b/devhelp/meson.build
@@ -3,6 +3,7 @@ libdevhelp_public_headers = [
         'dh-assistant-view.h',
         'dh-book.h',
         'dh-book-list.h',
+        'dh-book-list-builder.h',
         'dh-book-manager.h',
         'dh-book-tree.h',
         'dh-completion.h',
@@ -20,6 +21,7 @@ libdevhelp_public_c_files = [
         'dh-assistant-view.c',
         'dh-book.c',
         'dh-book-list.c',
+        'dh-book-list-builder.c',
         'dh-book-manager.c',
         'dh-book-tree.c',
         'dh-completion.c',
diff --git a/docs/reference/devhelp-docs.xml b/docs/reference/devhelp-docs.xml
index 5047d31..3e3f4ec 100644
--- a/docs/reference/devhelp-docs.xml
+++ b/docs/reference/devhelp-docs.xml
@@ -30,6 +30,7 @@
       <title>The Data</title>
       <xi:include href="xml/dh-book-manager.xml"/>
       <xi:include href="xml/dh-book-list.xml"/>
+      <xi:include href="xml/dh-book-list-builder.xml"/>
       <xi:include href="xml/dh-book.xml"/>
       <xi:include href="xml/dh-link.xml"/>
     </chapter>
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index fa3bd7b..5e1c47a 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -69,6 +69,24 @@ dh_book_list_get_type
 </SECTION>
 
 <SECTION>
+<FILE>dh-book-list-builder</FILE>
+DhBookListBuilder
+dh_book_list_builder_new
+dh_book_list_builder_add_sub_book_list
+dh_book_list_builder_create_object
+<SUBSECTION Standard>
+DH_BOOK_LIST_BUILDER
+DH_BOOK_LIST_BUILDER_CLASS
+DH_BOOK_LIST_BUILDER_GET_CLASS
+DH_IS_BOOK_LIST_BUILDER
+DH_IS_BOOK_LIST_BUILDER_CLASS
+DH_TYPE_BOOK_LIST_BUILDER
+DhBookListBuilderClass
+DhBookListBuilderPrivate
+dh_book_list_builder_get_type
+</SECTION>
+
+<SECTION>
 <FILE>dh-book-manager</FILE>
 DhBookManager
 dh_book_manager_new
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6c4837f..5649132 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ data/org.gnome.devhelp.gschema.xml
 data/org.gnome.libdevhelp-3.gschema.xml
 devhelp/dh-assistant-view.c
 devhelp/dh-book.c
+devhelp/dh-book-list-builder.c
 devhelp/dh-book-list.c
 devhelp/dh-book-list-simple.c
 devhelp/dh-book-manager.c


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