[devhelp/wip/book-list] BookList: add get_default()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/book-list] BookList: add get_default()
- Date: Sat, 28 Apr 2018 10:09:37 +0000 (UTC)
commit a1129a628c00a0e055b32a6bc73105ae6070ac2d
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 28 12:06:58 2018 +0200
BookList: add get_default()
devhelp/dh-book-list.c | 55 +++++++++++++++++++++++++++++++++++
devhelp/dh-book-list.h | 5 +++
devhelp/dh-init.c | 2 +
docs/reference/devhelp-sections.txt | 1 +
4 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/devhelp/dh-book-list.c b/devhelp/dh-book-list.c
index e154541..791e8fc 100644
--- a/devhelp/dh-book-list.c
+++ b/devhelp/dh-book-list.c
@@ -19,6 +19,8 @@
*/
#include "dh-book-list.h"
+#include "dh-book-list-builder.h"
+#include "dh-settings.h"
/**
* SECTION:dh-book-list
@@ -46,6 +48,7 @@ enum {
N_SIGNALS
};
+static DhBookList *default_instance = NULL;
static guint signals[N_SIGNALS] = { 0 };
G_DEFINE_TYPE_WITH_PRIVATE (DhBookList, dh_book_list, G_TYPE_OBJECT)
@@ -71,6 +74,15 @@ dh_book_list_dispose (GObject *object)
}
static void
+dh_book_list_finalize (GObject *object)
+{
+ if (default_instance == DH_BOOK_LIST (object))
+ default_instance = NULL;
+
+ G_OBJECT_CLASS (dh_book_list_parent_class)->finalize (object);
+}
+
+static void
dh_book_list_add_book_default (DhBookList *book_list,
DhBook *book)
{
@@ -109,6 +121,7 @@ dh_book_list_class_init (DhBookListClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = dh_book_list_dispose;
+ object_class->finalize = dh_book_list_finalize;
klass->add_book = dh_book_list_add_book_default;
klass->remove_book = dh_book_list_remove_book_default;
@@ -180,6 +193,48 @@ dh_book_list_new (void)
}
/**
+ * dh_book_list_get_default:
+ *
+ * Gets the default #DhBookList object. It is created with #DhBookListBuilder,
+ * dh_book_list_builder_add_default_sub_book_lists() is called, and
+ * dh_book_list_builder_read_books_disabled_setting() is called with the default
+ * #DhSettings object as returned by dh_settings_get_default().
+ *
+ * Returns: (transfer none): the default #DhBookList object.
+ * Since: 3.30
+ */
+DhBookList *
+dh_book_list_get_default (void)
+{
+ if (default_instance == NULL) {
+ DhSettings *default_settings;
+ DhBookListBuilder *builder;
+
+ default_settings = dh_settings_get_default ();
+
+ builder = dh_book_list_builder_new ();
+ dh_book_list_builder_add_default_sub_book_lists (builder);
+ dh_book_list_builder_read_books_disabled_setting (builder, default_settings);
+ default_instance = dh_book_list_builder_create_object (builder);
+ g_object_unref (builder);
+ }
+
+ return default_instance;
+}
+
+void
+_dh_book_list_unref_default (void)
+{
+ if (default_instance != NULL)
+ g_object_unref (default_instance);
+
+ /* default_instance is not set to NULL here, it is set to NULL in
+ * dh_book_list_finalize() (i.e. when we are sure that the ref count
+ * reaches 0).
+ */
+}
+
+/**
* dh_book_list_get_books:
* @book_list: a #DhBookList.
*
diff --git a/devhelp/dh-book-list.h b/devhelp/dh-book-list.h
index 0fcfe3e..9660715 100644
--- a/devhelp/dh-book-list.h
+++ b/devhelp/dh-book-list.h
@@ -76,6 +76,11 @@ GType dh_book_list_get_type (void);
DhBookList * dh_book_list_new (void);
+DhBookList * dh_book_list_get_default (void);
+
+G_GNUC_INTERNAL
+void _dh_book_list_unref_default (void);
+
GList * dh_book_list_get_books (DhBookList *book_list);
void dh_book_list_add_book (DhBookList *book_list,
diff --git a/devhelp/dh-init.c b/devhelp/dh-init.c
index 4e946d6..f70f9a4 100644
--- a/devhelp/dh-init.c
+++ b/devhelp/dh-init.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "dh-init.h"
#include <glib/gi18n-lib.h>
+#include "dh-book-list.h"
#include "dh-book-manager.h"
#include "dh-profile.h"
#include "dh-settings.h"
@@ -82,6 +83,7 @@ dh_finalize (void)
* accordingly, at the right place.
*/
if (!done) {
+ _dh_book_list_unref_default ();
_dh_book_manager_unref_singleton ();
_dh_profile_unref_default ();
_dh_settings_unref_default ();
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index 898c0d9..fd1b360 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -55,6 +55,7 @@ dh_book_get_type
DhBookList
DhBookListClass
dh_book_list_new
+dh_book_list_get_default
dh_book_list_get_books
dh_book_list_add_book
dh_book_list_remove_book
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]