[devhelp/wip/book-list: 3/3] Implement DhBookListSimple private class



commit 9b27ebb0533ae6619cbf035ad06e37d215c37e19
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Apr 23 11:11:16 2018 +0200

    Implement DhBookListSimple private class

 devhelp/dh-book-list-simple.c |  167 +++++++++++++++++++++++++++++++++++++++++
 devhelp/dh-book-list-simple.h |   61 +++++++++++++++
 devhelp/meson.build           |    1 +
 docs/reference/meson.build    |    1 +
 po/POTFILES.in                |    1 +
 5 files changed, 231 insertions(+), 0 deletions(-)
---
diff --git a/devhelp/dh-book-list-simple.c b/devhelp/dh-book-list-simple.c
new file mode 100644
index 0000000..8771392
--- /dev/null
+++ b/devhelp/dh-book-list-simple.c
@@ -0,0 +1,167 @@
+/* -*- 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-simple.h"
+
+struct _DhBookListSimplePrivate {
+        /* List of DhBookList*. */
+        GList *book_lists;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhBookListSimple, _dh_book_list_simple, DH_TYPE_BOOK_LIST)
+
+static void
+dh_book_list_simple_dispose (GObject *object)
+{
+        DhBookListSimple *list_simple = DH_BOOK_LIST_SIMPLE (object);
+
+        g_list_free_full (list_simple->priv->book_lists, g_object_unref);
+        list_simple->priv->book_lists = NULL;
+
+        G_OBJECT_CLASS (_dh_book_list_simple_parent_class)->dispose (object);
+}
+
+static void
+_dh_book_list_simple_class_init (DhBookListSimpleClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->dispose = dh_book_list_simple_dispose;
+}
+
+static void
+_dh_book_list_simple_init (DhBookListSimple *list_simple)
+{
+        list_simple->priv = _dh_book_list_simple_get_instance_private (list_simple);
+}
+
+/* Returns: (transfer full) (element-type DhBook). */
+static GList *
+generate_list (DhBookListSimple *list_simple)
+{
+        GList *ret = NULL;
+        GList *book_list_node;
+
+        for (book_list_node = list_simple->priv->book_lists;
+             book_list_node != NULL;
+             book_list_node = book_list_node->next) {
+                DhBookList *book_list = DH_BOOK_LIST (book_list_node->data);
+                GList *books;
+                GList *book_node;
+
+                books = dh_book_list_get_books (book_list);
+
+                /* First DhBookList, take all DhBook's. */
+                if (book_list_node == list_simple->priv->book_lists) {
+                        g_assert (ret == NULL);
+                        ret = g_list_copy_deep (books, (GCopyFunc) g_object_ref, NULL);
+                        continue;
+                }
+
+                for (book_node = books; book_node != NULL; book_node = book_node->next) {
+                        DhBook *book = DH_BOOK (book_node->data);
+
+                        /* Ensure to have unique book IDs. */
+                        if (g_list_find_custom (ret, book, (GCompareFunc)dh_book_cmp_by_id) == NULL)
+                                ret = g_list_prepend (ret, g_object_ref (book));
+                }
+        }
+
+        return ret;
+}
+
+static void
+repopulate (DhBookListSimple *list_simple)
+{
+        GList *old_list;
+        GList *new_list;
+
+        old_list = dh_book_list_get_books (DH_BOOK_LIST (list_simple));
+        new_list = generate_list (list_simple);
+
+        /* TODO remove/add books. */
+
+        g_list_free_full (new_list, g_object_unref);
+}
+
+static void
+book_list_add_book_cb (DhBookList       *book_list,
+                       DhBook           *book,
+                       DhBookListSimple *list_simple)
+{
+        repopulate (list_simple);
+}
+
+static void
+book_list_remove_book_cb (DhBookList       *book_list,
+                          DhBook           *book,
+                          DhBookListSimple *list_simple)
+{
+        repopulate (list_simple);
+}
+
+static void
+set_book_lists (DhBookListSimple *list_simple,
+                GList            *book_lists)
+{
+        GList *l;
+
+        g_assert (list_simple->priv->book_lists == NULL);
+
+        for (l = book_lists; l != NULL; l = l->next) {
+                DhBookList *book_list;
+
+                if (!DH_IS_BOOK_LIST (l->data)) {
+                        g_warn_if_reached ();
+                        continue;
+                }
+
+                book_list = l->data;
+                list_simple->priv->book_lists = g_list_prepend (list_simple->priv->book_lists,
+                                                                g_object_ref (book_list));
+
+                g_signal_connect_object (book_list,
+                                         "add-book",
+                                         G_CALLBACK (book_list_add_book_cb),
+                                         list_simple,
+                                         G_CONNECT_AFTER);
+
+                g_signal_connect_object (book_list,
+                                         "remove-book",
+                                         G_CALLBACK (book_list_remove_book_cb),
+                                         list_simple,
+                                         G_CONNECT_AFTER);
+        }
+
+        list_simple->priv->book_lists = g_list_reverse (list_simple->priv->book_lists);
+
+        repopulate (list_simple);
+}
+
+DhBookList *
+_dh_book_list_simple_new (GList *book_lists)
+{
+        DhBookListSimple *list_simple;
+
+        list_simple = g_object_new (DH_TYPE_BOOK_LIST_SIMPLE, NULL);
+        set_book_lists (list_simple, book_lists);
+
+        return DH_BOOK_LIST (list_simple);
+}
diff --git a/devhelp/dh-book-list-simple.h b/devhelp/dh-book-list-simple.h
new file mode 100644
index 0000000..f8211ac
--- /dev/null
+++ b/devhelp/dh-book-list-simple.h
@@ -0,0 +1,61 @@
+/* -*- 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_SIMPLE_H
+#define DH_BOOK_LIST_SIMPLE_H
+
+#include <glib-object.h>
+#include "dh-book-list.h"
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_BOOK_LIST_SIMPLE             (_dh_book_list_simple_get_type ())
+#define DH_BOOK_LIST_SIMPLE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), DH_TYPE_BOOK_LIST_SIMPLE, 
DhBookListSimple))
+#define DH_BOOK_LIST_SIMPLE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), DH_TYPE_BOOK_LIST_SIMPLE, 
DhBookListSimpleClass))
+#define DH_IS_BOOK_LIST_SIMPLE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DH_TYPE_BOOK_LIST_SIMPLE))
+#define DH_IS_BOOK_LIST_SIMPLE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), DH_TYPE_BOOK_LIST_SIMPLE))
+#define DH_BOOK_LIST_SIMPLE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), DH_TYPE_BOOK_LIST_SIMPLE, 
DhBookListSimpleClass))
+
+typedef struct _DhBookListSimple         DhBookListSimple;
+typedef struct _DhBookListSimpleClass    DhBookListSimpleClass;
+typedef struct _DhBookListSimplePrivate  DhBookListSimplePrivate;
+
+struct _DhBookListSimple {
+        DhBookList parent;
+
+        DhBookListSimplePrivate *priv;
+};
+
+struct _DhBookListSimpleClass {
+        DhBookListClass parent_class;
+
+        /* Padding for future expansion */
+        gpointer padding[12];
+};
+
+G_GNUC_INTERNAL
+GType           _dh_book_list_simple_get_type   (void);
+
+G_GNUC_INTERNAL
+DhBookList *    _dh_book_list_simple_new        (GList *book_lists);
+
+G_END_DECLS
+
+#endif /* DH_BOOK_LIST_SIMPLE_H */
diff --git a/devhelp/meson.build b/devhelp/meson.build
index 2d8c3d3..ac89def 100644
--- a/devhelp/meson.build
+++ b/devhelp/meson.build
@@ -34,6 +34,7 @@ libdevhelp_public_c_files = [
 ]
 
 libdevhelp_private_c_files = [
+        'dh-book-list-simple.c',
         'dh-error.c',
         'dh-parser.c',
         'dh-search-context.c',
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index ac9c213..c5511bb 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -11,6 +11,7 @@ GNOME.gtkdoc(
                 'api-breaks.xml'
         ],
         ignore_headers : [
+                'dh-book-list-simple.h',
                 'dh-dconf-migration.h',
                 'dh-error.h',
                 'dh-parser.h',
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1e78344..6c4837f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,6 +7,7 @@ data/org.gnome.libdevhelp-3.gschema.xml
 devhelp/dh-assistant-view.c
 devhelp/dh-book.c
 devhelp/dh-book-list.c
+devhelp/dh-book-list-simple.c
 devhelp/dh-book-manager.c
 devhelp/dh-book-tree.c
 devhelp/dh-completion.c


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