[devhelp/wip/book-list] Implement DhBookList abstract class



commit ca2ad23ce0c5f25f9e5f6e9c90ceee27b69aebea
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Apr 22 15:07:27 2018 +0200

    Implement DhBookList abstract class

 devhelp/dh-book-list.c              |  155 +++++++++++++++++++++++++++++++++++
 devhelp/dh-book-list.h              |   86 +++++++++++++++++++
 devhelp/meson.build                 |    2 +
 docs/reference/devhelp-docs.xml     |    1 +
 docs/reference/devhelp-sections.txt |   18 ++++
 po/POTFILES.in                      |    1 +
 6 files changed, 263 insertions(+), 0 deletions(-)
---
diff --git a/devhelp/dh-book-list.c b/devhelp/dh-book-list.c
new file mode 100644
index 0000000..8270cc6
--- /dev/null
+++ b/devhelp/dh-book-list.c
@@ -0,0 +1,155 @@
+/* -*- 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.h"
+
+/**
+ * SECTION:dh-book-list
+ * @Title: DhBookList
+ * @Short_description: Abstract class for a list of #DhBook's
+ *
+ * #DhBookList is an abstract class for a list of #DhBook's.
+ */
+
+struct _DhBookListPrivate {
+};
+
+enum {
+        SIGNAL_BOOK_ADDED,
+        SIGNAL_BOOK_REMOVED,
+        N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
+G_DEFINE_TYPE (DhBookList, dh_book_list, G_TYPE_OBJECT)
+
+static GList *
+dh_book_list_get_books_default (DhBookList *book_list)
+{
+        return NULL;
+}
+
+static void
+dh_book_list_class_init (DhBookListClass *klass)
+{
+        klass->get_books = dh_book_list_get_books_default;
+
+        /**
+         * DhBookList::book-added:
+         * @book_list: the #DhBookList emitting the signal.
+         * @book: the added #DhBook.
+         *
+         * Since: 3.30
+         */
+        signals[SIGNAL_BOOK_ADDED] =
+                g_signal_new ("book-added",
+                              G_TYPE_FROM_CLASS (klass),
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (DhBookListClass, book_added),
+                              NULL, NULL, NULL,
+                              G_TYPE_NONE,
+                              1, DH_TYPE_BOOK);
+
+        /**
+         * DhBookList::book-removed:
+         * @book_list: the #DhBookList emitting the signal.
+         * @book: the removed #DhBook.
+         *
+         * Since: 3.30
+         */
+        signals[SIGNAL_BOOK_REMOVED] =
+                g_signal_new ("book-removed",
+                              G_TYPE_FROM_CLASS (klass),
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (DhBookListClass, book_removed),
+                              NULL, NULL, NULL,
+                              G_TYPE_NONE,
+                              1, DH_TYPE_BOOK);
+}
+
+static void
+dh_book_list_init (DhBookList *book_list)
+{
+}
+
+/**
+ * dh_book_list_get_books:
+ * @book_list: a #DhBookList.
+ *
+ * Returns: (transfer none) (element-type DhBook): the #GList of #DhBook's part
+ * of @book_list.
+ * Since: 3.30
+ */
+GList *
+dh_book_list_get_books (DhBookList *book_list)
+{
+        g_return_val_if_fail (DH_IS_BOOK_LIST (book_list), NULL);
+
+        return DH_BOOK_LIST_GET_CLASS (book_list)->get_books (book_list);
+}
+
+/**
+ * dh_book_list_book_added:
+ * @book_list: a #DhBookList.
+ * @book: a #DhBook.
+ *
+ * Emits the #DhBookList::book-added signal.
+ *
+ * This function is intended to be used by #DhBookList subclasses.
+ *
+ * Since: 3.30
+ */
+void
+dh_book_list_book_added (DhBookList *book_list,
+                         DhBook     *book)
+{
+        g_return_if_fail (DH_IS_BOOK_LIST (book_list));
+        g_return_if_fail (DH_IS_BOOK (book));
+
+        g_signal_emit (book_list,
+                       signals[SIGNAL_BOOK_ADDED],
+                       0,
+                       book);
+}
+
+/**
+ * dh_book_list_book_removed:
+ * @book_list: a #DhBookList.
+ * @book: a #DhBook.
+ *
+ * Emits the #DhBookList::book-removed signal.
+ *
+ * This function is intended to be used by #DhBookList subclasses.
+ *
+ * Since: 3.30
+ */
+void
+dh_book_list_book_removed (DhBookList *book_list,
+                           DhBook     *book)
+{
+        g_return_if_fail (DH_IS_BOOK_LIST (book_list));
+        g_return_if_fail (DH_IS_BOOK (book));
+
+        g_signal_emit (book_list,
+                       signals[SIGNAL_BOOK_REMOVED],
+                       0,
+                       book);
+}
diff --git a/devhelp/dh-book-list.h b/devhelp/dh-book-list.h
new file mode 100644
index 0000000..f4ac70b
--- /dev/null
+++ b/devhelp/dh-book-list.h
@@ -0,0 +1,86 @@
+/* -*- 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_H
+#define DH_BOOK_LIST_H
+
+#include <glib-object.h>
+#include <devhelp/dh-book.h>
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_BOOK_LIST             (dh_book_list_get_type ())
+#define DH_BOOK_LIST(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), DH_TYPE_BOOK_LIST, DhBookList))
+#define DH_BOOK_LIST_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), DH_TYPE_BOOK_LIST, DhBookListClass))
+#define DH_IS_BOOK_LIST(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DH_TYPE_BOOK_LIST))
+#define DH_IS_BOOK_LIST_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), DH_TYPE_BOOK_LIST))
+#define DH_BOOK_LIST_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), DH_TYPE_BOOK_LIST, DhBookListClass))
+
+typedef struct _DhBookList         DhBookList;
+typedef struct _DhBookListClass    DhBookListClass;
+typedef struct _DhBookListPrivate  DhBookListPrivate;
+
+struct _DhBookList {
+        GObject parent;
+
+        DhBookListPrivate *priv;
+};
+
+/**
+ * DhBookListClass:
+ * @parent_class: The parent class.
+ * @book_added: Virtual function pointer for the #DhBookList::book-added signal.
+ * @book_removed: Virtual function pointer for the #DhBookList::book-removed
+ *   signal.
+ * @get_books: Virtual function pointer for dh_book_list_get_books(). Returns
+ *   %NULL by default.
+ */
+struct _DhBookListClass {
+        GObjectClass parent_class;
+
+        /* Signals */
+        void    (* book_added)          (DhBookList *book_list,
+                                         DhBook     *book);
+
+        void    (* book_removed)        (DhBookList *book_list,
+                                         DhBook     *book);
+
+        /* Vfuncs */
+        GList * (* get_books)           (DhBookList *book_list);
+
+        /*< private >*/
+
+        /* Padding for future expansion */
+        gpointer padding[12];
+};
+
+GType   dh_book_list_get_type           (void);
+
+GList * dh_book_list_get_books          (DhBookList *book_list);
+
+void    dh_book_list_book_added         (DhBookList *book_list,
+                                         DhBook     *book);
+
+void    dh_book_list_book_removed       (DhBookList *book_list,
+                                         DhBook     *book);
+
+G_END_DECLS
+
+#endif /* DH_BOOK_LIST_H */
diff --git a/devhelp/meson.build b/devhelp/meson.build
index 314d0b4..2d8c3d3 100644
--- a/devhelp/meson.build
+++ b/devhelp/meson.build
@@ -2,6 +2,7 @@ libdevhelp_public_headers = [
         'devhelp.h',
         'dh-assistant-view.h',
         'dh-book.h',
+        'dh-book-list.h',
         'dh-book-manager.h',
         'dh-book-tree.h',
         'dh-completion.h',
@@ -18,6 +19,7 @@ libdevhelp_public_headers = [
 libdevhelp_public_c_files = [
         'dh-assistant-view.c',
         'dh-book.c',
+        'dh-book-list.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 a5a0a08..5047d31 100644
--- a/docs/reference/devhelp-docs.xml
+++ b/docs/reference/devhelp-docs.xml
@@ -29,6 +29,7 @@
     <chapter id="data">
       <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.xml"/>
       <xi:include href="xml/dh-link.xml"/>
     </chapter>
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index 8cfd225..edcc4a1 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -51,6 +51,24 @@ dh_book_get_type
 </SECTION>
 
 <SECTION>
+<FILE>dh-book-list</FILE>
+DhBookList
+DhBookListClass
+dh_book_list_get_books
+dh_book_list_book_added
+dh_book_list_book_removed
+<SUBSECTION Standard>
+DH_BOOK_LIST
+DH_BOOK_LIST_CLASS
+DH_BOOK_LIST_GET_CLASS
+DH_IS_BOOK_LIST
+DH_IS_BOOK_LIST_CLASS
+DH_TYPE_BOOK_LIST
+DhBookListPrivate
+dh_book_list_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 c416b6a..1e78344 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.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]