[devhelp] Settings: add group-books-by-language property and bind() function
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Settings: add group-books-by-language property and bind() function
- Date: Tue, 3 Apr 2018 11:52:02 +0000 (UTC)
commit 1a442f3e99e2b16c818f922635115f425b6c6547
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Apr 3 11:44:26 2018 +0200
Settings: add group-books-by-language property and bind() function
The idea will be to remove dh_settings_peek_contents_settings(), to not
expose publicly the GSettings objects.
Binding the property to the GSettings key is optional, to be able to
force a certain value for a certain profile.
devhelp/dh-settings.c | 125 +++++++++++++++++++++++++++++++++++
devhelp/dh-settings.h | 17 ++++--
docs/reference/devhelp-sections.txt | 3 +
3 files changed, 140 insertions(+), 5 deletions(-)
---
diff --git a/devhelp/dh-settings.c b/devhelp/dh-settings.c
index 64c159e..9ff4e24 100644
--- a/devhelp/dh-settings.c
+++ b/devhelp/dh-settings.c
@@ -49,13 +49,60 @@
struct _DhSettingsPrivate {
GSettings *settings_contents;
+
+ guint group_books_by_language : 1;
+};
+
+enum {
+ PROP_0,
+ PROP_GROUP_BOOKS_BY_LANGUAGE,
+ N_PROPERTIES
};
+static GParamSpec *properties[N_PROPERTIES];
static DhSettings *default_instance = NULL;
G_DEFINE_TYPE_WITH_PRIVATE (DhSettings, dh_settings, G_TYPE_OBJECT);
static void
+dh_settings_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ DhSettings *self = DH_SETTINGS (object);
+
+ switch (prop_id) {
+ case PROP_GROUP_BOOKS_BY_LANGUAGE:
+ g_value_set_boolean (value, dh_settings_get_group_books_by_language (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+dh_settings_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ DhSettings *self = DH_SETTINGS (object);
+
+ switch (prop_id) {
+ case PROP_GROUP_BOOKS_BY_LANGUAGE:
+ dh_settings_set_group_books_by_language (self, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
dh_settings_dispose (GObject *object)
{
DhSettings *self = DH_SETTINGS (object);
@@ -79,8 +126,28 @@ dh_settings_class_init (DhSettingsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->get_property = dh_settings_get_property;
+ object_class->set_property = dh_settings_set_property;
object_class->dispose = dh_settings_dispose;
object_class->finalize = dh_settings_finalize;
+
+ /**
+ * DhSettings:group-books-by-language:
+ *
+ * Whether books should be grouped by programming language in the UI.
+ *
+ * Since: 3.30
+ */
+ properties[PROP_GROUP_BOOKS_BY_LANGUAGE] =
+ g_param_spec_boolean ("group-books-by-language",
+ "Group books by language",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
static void
@@ -148,3 +215,61 @@ dh_settings_peek_contents_settings (DhSettings *self)
g_return_val_if_fail (DH_IS_SETTINGS (self), NULL);
return self->priv->settings_contents;
}
+
+/**
+ * dh_settings_get_group_books_by_language:
+ * @self: a #DhSettings.
+ *
+ * Returns: the value of the #DhSettings:group-books-by-language property.
+ * Since: 3.30
+ */
+gboolean
+dh_settings_get_group_books_by_language (DhSettings *self)
+{
+ g_return_val_if_fail (DH_IS_SETTINGS (self), FALSE);
+
+ return self->priv->group_books_by_language;
+}
+
+/**
+ * dh_settings_set_group_books_by_language:
+ * @self: a #DhSettings.
+ * @group_books_by_language: the new value.
+ *
+ * Sets the #DhSettings:group-books-by-language property.
+ *
+ * Since: 3.30
+ */
+void
+dh_settings_set_group_books_by_language (DhSettings *self,
+ gboolean group_books_by_language)
+{
+ g_return_if_fail (DH_IS_SETTINGS (self));
+
+ group_books_by_language = group_books_by_language != FALSE;
+
+ if (self->priv->group_books_by_language != group_books_by_language) {
+ self->priv->group_books_by_language = group_books_by_language;
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_GROUP_BOOKS_BY_LANGUAGE]);
+ }
+}
+
+/**
+ * dh_settings_bind_group_books_by_language:
+ * @self: a #DhSettings.
+ *
+ * Binds the #DhSettings:group-books-by-language property to the corresponding
+ * #GSettings key.
+ *
+ * Since: 3.30
+ */
+void
+dh_settings_bind_group_books_by_language (DhSettings *self)
+{
+ g_return_if_fail (DH_IS_SETTINGS (self));
+
+ g_settings_bind (self->priv->settings_contents, "group-books-by-language",
+ self, "group-books-by-language",
+ G_SETTINGS_BIND_DEFAULT |
+ G_SETTINGS_BIND_NO_SENSITIVITY);
+}
diff --git a/devhelp/dh-settings.h b/devhelp/dh-settings.h
index b8729b7..d1186b8 100644
--- a/devhelp/dh-settings.h
+++ b/devhelp/dh-settings.h
@@ -49,17 +49,24 @@ struct _DhSettingsClass {
gpointer padding[12];
};
-GType dh_settings_get_type (void) G_GNUC_CONST;
+GType dh_settings_get_type (void) G_GNUC_CONST;
G_GNUC_INTERNAL
-DhSettings * _dh_settings_new (const gchar *contents_path);
+DhSettings * _dh_settings_new (const gchar *contents_path);
-DhSettings * dh_settings_get_default (void);
+DhSettings * dh_settings_get_default (void);
G_GNUC_INTERNAL
-void _dh_settings_unref_default (void);
+void _dh_settings_unref_default (void);
-GSettings * dh_settings_peek_contents_settings (DhSettings *self);
+GSettings * dh_settings_peek_contents_settings (DhSettings *self);
+
+gboolean dh_settings_get_group_books_by_language (DhSettings *self);
+
+void dh_settings_set_group_books_by_language (DhSettings *self,
+ gboolean group_books_by_language);
+
+void dh_settings_bind_group_books_by_language (DhSettings *self);
G_END_DECLS
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index ce06fa3..a5d13bc 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -156,6 +156,9 @@ dh_link_type_get_type
DhSettings
dh_settings_get_default
dh_settings_peek_contents_settings
+dh_settings_get_group_books_by_language
+dh_settings_set_group_books_by_language
+dh_settings_bind_group_books_by_language
<SUBSECTION Standard>
DH_IS_SETTINGS
DH_IS_SETTINGS_CLASS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]