[devhelp: 20/36] book-manager: Make 'group by language' a property
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp: 20/36] book-manager: Make 'group by language' a property
- Date: Mon, 20 Dec 2010 14:33:06 +0000 (UTC)
commit 4c5ab7375846b09ce5556529eb485de53aea5765
Author: Aleksander Morgado <aleksander lanedo com>
Date: Thu Dec 9 16:59:30 2010 +0100
book-manager: Make 'group by language' a property
src/dh-book-manager.c | 119 +++++++++++++++++++++++++++++++++++++++++++------
src/dh-book-manager.h | 20 +++++---
src/dh-preferences.c | 5 +-
3 files changed, 120 insertions(+), 24 deletions(-)
---
diff --git a/src/dh-book-manager.c b/src/dh-book-manager.c
index 59b0574..135de64 100644
--- a/src/dh-book-manager.c
+++ b/src/dh-book-manager.c
@@ -44,6 +44,8 @@ typedef struct {
GHashTable *monitors;
/* List of book names currently disabled */
GSList *books_disabled;
+ /* Whether books should be grouped by language */
+ gboolean group_by_language;
} DhBookManagerPriv;
enum {
@@ -51,9 +53,15 @@ enum {
BOOK_DELETED,
BOOK_ENABLED,
BOOK_DISABLED,
+ BOOKLIST_GROUP_BY_LANGUAGE,
LAST_SIGNAL
};
+enum {
+ PROP_0,
+ PROP_GROUP_BY_LANGUAGE
+};
+
static gint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (DhBookManager, dh_book_manager, G_TYPE_OBJECT);
@@ -61,13 +69,21 @@ G_DEFINE_TYPE (DhBookManager, dh_book_manager, G_TYPE_OBJECT);
#define GET_PRIVATE(instance) G_TYPE_INSTANCE_GET_PRIVATE \
(instance, DH_TYPE_BOOK_MANAGER, DhBookManagerPriv)
-static void dh_book_manager_init (DhBookManager *book_manager);
-static void dh_book_manager_class_init (DhBookManagerClass *klass);
-
-static void book_manager_add_from_filepath (DhBookManager *book_manager,
- const gchar *book_path);
-static void book_manager_add_from_dir (DhBookManager *book_manager,
- const gchar *dir_path);
+static void dh_book_manager_init (DhBookManager *book_manager);
+static void dh_book_manager_class_init (DhBookManagerClass *klass);
+
+static void book_manager_add_from_filepath (DhBookManager *book_manager,
+ const gchar *book_path);
+static void book_manager_add_from_dir (DhBookManager *book_manager,
+ const gchar *dir_path);
+static void book_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void book_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
#ifdef GDK_WINDOWING_QUARTZ
static void book_manager_add_from_xcode_docset (DhBookManager *book_manager,
@@ -109,6 +125,8 @@ dh_book_manager_class_init (DhBookManagerClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = book_manager_finalize;
+ object_class->set_property = book_manager_set_property;
+ object_class->get_property = book_manager_get_property;
signals[BOOK_CREATED] =
g_signal_new ("book-created",
@@ -151,6 +169,17 @@ dh_book_manager_class_init (DhBookManagerClass *klass)
1,
G_TYPE_OBJECT);
+ g_object_class_install_property (object_class,
+ PROP_GROUP_BY_LANGUAGE,
+ g_param_spec_boolean ("group-by-language",
+ ("Group by language"),
+ ("TRUE if books should be grouped by language"),
+ FALSE,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB)));
+
g_type_class_add_private (klass, sizeof (DhBookManagerPriv));
}
@@ -165,6 +194,47 @@ dh_book_manager_init (DhBookManager *book_manager)
priv->books_disabled = dh_util_state_load_books_disabled ();
}
+static void
+book_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ DhBookManager *book_manager = DH_BOOK_MANAGER (object);
+
+ switch (prop_id)
+ {
+ case PROP_GROUP_BY_LANGUAGE:
+ dh_book_manager_set_group_by_language (book_manager,
+ g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+book_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ DhBookManager *book_manager = DH_BOOK_MANAGER (object);
+
+ switch (prop_id)
+ {
+ case PROP_GROUP_BY_LANGUAGE:
+ g_value_set_boolean (value,
+ dh_book_manager_get_group_by_language (book_manager));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
static gboolean
book_manager_is_book_disabled_in_conf (DhBookManager *book_manager,
DhBook *book)
@@ -480,9 +550,6 @@ book_manager_book_deleted_cb (DhBook *book,
/* Look for the item we want to remove */
li = g_list_find (priv->books, book);
if (li) {
- g_debug ("Deleting book '%s' from the book manager list",
- dh_book_get_title (book));
-
/* Emit signal to notify others */
g_signal_emit (book_manager,
signals[BOOK_DELETED],
@@ -607,9 +674,6 @@ book_manager_add_from_filepath (DhBookManager *book_manager,
book,
(GCompareFunc)dh_book_cmp_by_title);
- g_debug ("Adding book '%s' to the book manager list",
- dh_book_get_title (book));
-
/* Set the proper enabled/disabled state, depending on conf */
dh_book_set_enabled (book,
!book_manager_is_book_disabled_in_conf (book_manager,
@@ -678,9 +742,36 @@ dh_book_manager_get_book_by_path (DhBookManager *book_manager,
return l ? l->data : NULL;
}
+gboolean
+dh_book_manager_get_group_by_language (DhBookManager *book_manager)
+{
+ g_return_val_if_fail (book_manager, FALSE);
+
+ return GET_PRIVATE (book_manager)->group_by_language;
+}
+
+void
+dh_book_manager_set_group_by_language (DhBookManager *book_manager,
+ gboolean group_by_language)
+{
+ DhBookManagerPriv *priv;
+
+ g_return_if_fail (book_manager);
+
+ priv = GET_PRIVATE (book_manager);
+
+ /* Store in conf */
+ dh_util_state_store_group_books_by_language (group_by_language);
+
+ priv->group_by_language = group_by_language;
+ g_object_notify (G_OBJECT (book_manager), "group-by-language");
+}
+
DhBookManager *
dh_book_manager_new (void)
{
- return g_object_new (DH_TYPE_BOOK_MANAGER, NULL);
+ return g_object_new (DH_TYPE_BOOK_MANAGER,
+ "group-by-language", dh_util_state_load_group_books_by_language (),
+ NULL);
}
diff --git a/src/dh-book-manager.h b/src/dh-book-manager.h
index 525bace..1caa2e9 100644
--- a/src/dh-book-manager.h
+++ b/src/dh-book-manager.h
@@ -45,14 +45,18 @@ struct _DhBookManagerClass {
GObjectClass parent_class;
};
-GType dh_book_manager_get_type (void) G_GNUC_CONST;
-DhBookManager *dh_book_manager_new (void);
-void dh_book_manager_populate (DhBookManager *book_manager);
-GList *dh_book_manager_get_books (DhBookManager *book_manager);
-DhBook *dh_book_manager_get_book_by_name (DhBookManager *book_manager,
- const gchar *name);
-DhBook *dh_book_manager_get_book_by_path (DhBookManager *book_manager,
- const gchar *path);
+GType dh_book_manager_get_type (void) G_GNUC_CONST;
+DhBookManager *dh_book_manager_new (void);
+void dh_book_manager_populate (DhBookManager *book_manager);
+GList *dh_book_manager_get_books (DhBookManager *book_manager);
+DhBook *dh_book_manager_get_book_by_name (DhBookManager *book_manager,
+ const gchar *name);
+DhBook *dh_book_manager_get_book_by_path (DhBookManager *book_manager,
+ const gchar *path);
+
+gboolean dh_book_manager_get_group_by_language (DhBookManager *book_manager);
+void dh_book_manager_set_group_by_language (DhBookManager *book_manager,
+ gboolean group_by_language);
G_END_DECLS
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
index eea5196..d32a8a4 100644
--- a/src/dh-preferences.c
+++ b/src/dh-preferences.c
@@ -464,7 +464,8 @@ preferences_bookshelf_group_by_language_toggled_cb (GtkToggleButton *button,
active = gtk_toggle_button_get_active (button);
- dh_util_state_store_group_books_by_language (active);
+ dh_book_manager_set_group_by_language (prefs->book_manager,
+ active);
}
void
@@ -532,7 +533,7 @@ dh_preferences_show_dialog (GtkWindow *parent)
}
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->group_by_language_button),
- dh_util_state_load_group_books_by_language ());
+ dh_book_manager_get_group_by_language (prefs->book_manager));
preferences_bookshelf_populate_store ();
g_object_unref (builder);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]