[devhelp/wip/book-list] BookListSimple: read optionally the "books-disabled" GSettings key
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/book-list] BookListSimple: read optionally the "books-disabled" GSettings key
- Date: Thu, 26 Apr 2018 16:20:35 +0000 (UTC)
commit f355bbdf5f45ade0d34381960f6823d09e0cc0ce
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Apr 26 17:31:08 2018 +0200
BookListSimple: read optionally the "books-disabled" GSettings key
devhelp/dh-book-list-builder.c | 2 +-
devhelp/dh-book-list-simple.c | 52 ++++++++++++++++++++++++++++++++++++++-
devhelp/dh-book-list-simple.h | 4 ++-
3 files changed, 54 insertions(+), 4 deletions(-)
---
diff --git a/devhelp/dh-book-list-builder.c b/devhelp/dh-book-list-builder.c
index 080edd2..fdceccf 100644
--- a/devhelp/dh-book-list-builder.c
+++ b/devhelp/dh-book-list-builder.c
@@ -122,5 +122,5 @@ 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);
+ return _dh_book_list_simple_new (builder->priv->sub_book_lists, NULL);
}
diff --git a/devhelp/dh-book-list-simple.c b/devhelp/dh-book-list-simple.c
index b50dc5b..43706ae 100644
--- a/devhelp/dh-book-list-simple.c
+++ b/devhelp/dh-book-list-simple.c
@@ -23,6 +23,9 @@
struct _DhBookListSimplePrivate {
/* List of DhBookList*. */
GList *sub_book_lists;
+
+ /* For reading the "books-disabled" GSettings key. */
+ DhSettings *settings;
};
G_DEFINE_TYPE_WITH_PRIVATE (DhBookListSimple, _dh_book_list_simple, DH_TYPE_BOOK_LIST)
@@ -35,6 +38,8 @@ dh_book_list_simple_dispose (GObject *object)
g_list_free_full (list_simple->priv->sub_book_lists, g_object_unref);
list_simple->priv->sub_book_lists = NULL;
+ g_clear_object (&list_simple->priv->settings);
+
G_OBJECT_CLASS (_dh_book_list_simple_parent_class)->dispose (object);
}
@@ -52,6 +57,28 @@ _dh_book_list_simple_init (DhBookListSimple *list_simple)
list_simple->priv = _dh_book_list_simple_get_instance_private (list_simple);
}
+/* Returns: the new start of the list. */
+static GList *
+filter_by_books_disabled (DhBookListSimple *list_simple,
+ GList *list)
+{
+ GList *new_list = NULL;
+ GList *l;
+
+ if (list_simple->priv->settings == NULL)
+ return list;
+
+ for (l = list; l != NULL; l = l->next) {
+ DhBook *book = DH_BOOK (l->data);
+
+ if (dh_settings_is_book_enabled (list_simple->priv->settings, book))
+ new_list = g_list_prepend (new_list, g_object_ref (book));
+ }
+
+ g_list_free_full (list, g_object_unref);
+ return new_list;
+}
+
/* Returns: (transfer full) (element-type DhBook). */
static GList *
generate_list (DhBookListSimple *list_simple)
@@ -84,7 +111,7 @@ generate_list (DhBookListSimple *list_simple)
}
}
- return ret;
+ return filter_by_books_disabled (list_simple, ret);
}
static void
@@ -169,17 +196,38 @@ set_sub_book_lists (DhBookListSimple *list_simple,
}
list_simple->priv->sub_book_lists = g_list_reverse (list_simple->priv->sub_book_lists);
+}
+static void
+books_disabled_changed_cb (DhSettings *settings,
+ DhBookListSimple *list_simple)
+{
repopulate (list_simple);
}
+/* @settings is for reading the "books-disabled" GSettings key. */
DhBookList *
-_dh_book_list_simple_new (GList *sub_book_lists)
+_dh_book_list_simple_new (GList *sub_book_lists,
+ DhSettings *settings)
{
DhBookListSimple *list_simple;
+ g_return_val_if_fail (settings == NULL || DH_IS_SETTINGS (settings), NULL);
+
list_simple = g_object_new (DH_TYPE_BOOK_LIST_SIMPLE, NULL);
set_sub_book_lists (list_simple, sub_book_lists);
+ if (settings != NULL) {
+ list_simple->priv->settings = g_object_ref (settings);
+
+ g_signal_connect_object (settings,
+ "books-disabled-changed",
+ G_CALLBACK (books_disabled_changed_cb),
+ list_simple,
+ G_CONNECT_AFTER);
+ }
+
+ repopulate (list_simple);
+
return DH_BOOK_LIST (list_simple);
}
diff --git a/devhelp/dh-book-list-simple.h b/devhelp/dh-book-list-simple.h
index da418c7..414d518 100644
--- a/devhelp/dh-book-list-simple.h
+++ b/devhelp/dh-book-list-simple.h
@@ -23,6 +23,7 @@
#include <glib-object.h>
#include "dh-book-list.h"
+#include "dh-settings.h"
G_BEGIN_DECLS
@@ -54,7 +55,8 @@ G_GNUC_INTERNAL
GType _dh_book_list_simple_get_type (void);
G_GNUC_INTERNAL
-DhBookList * _dh_book_list_simple_new (GList *sub_book_lists);
+DhBookList * _dh_book_list_simple_new (GList *sub_book_lists,
+ DhSettings *settings);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]