[devhelp/wip/book-manager-singleton] BookTree: remove book-manager property
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/book-manager-singleton] BookTree: remove book-manager property
- Date: Mon, 1 May 2017 15:31:15 +0000 (UTC)
commit fd1457e0f8fc250ed2fc87551a780fc746ee97af
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon May 1 16:54:32 2017 +0200
BookTree: remove book-manager property
src/dh-book-tree.c | 108 ++++++++++++++--------------------------------------
src/dh-book-tree.h | 3 +-
src/dh-sidebar.c | 2 +-
3 files changed, 31 insertions(+), 82 deletions(-)
---
diff --git a/src/dh-book-tree.c b/src/dh-book-tree.c
index 113952c..0149c81 100644
--- a/src/dh-book-tree.c
+++ b/src/dh-book-tree.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "dh-book-tree.h"
+#include "dh-book-manager.h"
#include "dh-book.h"
typedef struct {
@@ -32,9 +33,8 @@ typedef struct {
} FindURIData;
typedef struct {
- GtkTreeStore *store;
- DhBookManager *book_manager;
- DhLink *selected_link;
+ GtkTreeStore *store;
+ DhLink *selected_link;
} DhBookTreePrivate;
enum {
@@ -51,11 +51,6 @@ enum {
N_COLUMNS
};
-enum {
- PROP_0,
- PROP_BOOK_MANAGER
-};
-
G_DEFINE_TYPE_WITH_PRIVATE (DhBookTree, dh_book_tree, GTK_TYPE_TREE_VIEW);
static guint signals[LAST_SIGNAL] = { 0 };
@@ -113,7 +108,8 @@ book_tree_find_language_group (DhBookTree *tree,
gboolean *next_found)
{
DhBookTreePrivate *priv = dh_book_tree_get_instance_private (tree);
- GtkTreeIter loop_iter;
+ DhBookManager *book_manager;
+ GtkTreeIter loop_iter;
g_assert ((exact_iter != NULL && exact_found != NULL) ||
(next_iter != NULL && next_found != NULL));
@@ -125,7 +121,8 @@ book_tree_find_language_group (DhBookTree *tree,
*next_found = FALSE;
/* If we're not doing language grouping, return not found */
- if (!dh_book_manager_get_group_by_language (priv->book_manager))
+ book_manager = dh_book_manager_get_singleton ();
+ if (!dh_book_manager_get_group_by_language (book_manager))
return;
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
@@ -295,10 +292,12 @@ book_tree_add_book_to_store (DhBookTree *tree,
DhBook *book)
{
DhBookTreePrivate *priv = dh_book_tree_get_instance_private (tree);
- GtkTreeIter book_iter;
+ DhBookManager *book_manager;
+ GtkTreeIter book_iter;
/* If grouping by language we need to add the language categories */
- if (dh_book_manager_get_group_by_language (priv->book_manager)) {
+ book_manager = dh_book_manager_get_singleton ();
+ if (dh_book_manager_get_group_by_language (book_manager)) {
GtkTreeIter language_iter;
gboolean language_iter_found;
GtkTreeIter next_language_iter;
@@ -497,6 +496,7 @@ static void
book_tree_init_selection (DhBookTree *tree)
{
DhBookTreePrivate *priv;
+ DhBookManager *book_manager;
GtkTreeSelection *selection;
GtkTreeIter iter;
gboolean iter_found = FALSE;
@@ -516,7 +516,8 @@ book_tree_init_selection (DhBookTree *tree)
tree);
/* If grouping by languages, get first book in the first language */
- if (dh_book_manager_get_group_by_language (priv->book_manager)) {
+ book_manager = dh_book_manager_get_singleton ();
+ if (dh_book_manager_get_group_by_language (book_manager)) {
GtkTreeIter language_iter;
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
@@ -554,6 +555,7 @@ static void
book_tree_populate_tree (DhBookTree *tree)
{
DhBookTreePrivate *priv = dh_book_tree_get_instance_private (tree);
+ DhBookManager *book_manager;
GList *l;
gtk_tree_view_set_model (GTK_TREE_VIEW (tree), NULL);
@@ -562,7 +564,8 @@ book_tree_populate_tree (DhBookTree *tree)
GTK_TREE_MODEL (priv->store));
/* This list comes in order, but we don't really mind */
- for (l = dh_book_manager_get_books (priv->book_manager);
+ book_manager = dh_book_manager_get_singleton ();
+ for (l = dh_book_manager_get_books (book_manager);
l != NULL;
l = l->next) {
DhBook *book = DH_BOOK (l->data);
@@ -583,76 +586,43 @@ book_tree_group_by_language_cb (GObject *object,
book_tree_populate_tree (tree);
}
-static void
-dh_book_tree_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- DhBookTreePrivate *priv = dh_book_tree_get_instance_private (DH_BOOK_TREE (object));
-
- switch (prop_id) {
- case PROP_BOOK_MANAGER:
- g_value_set_object (value, priv->book_manager);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-dh_book_tree_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- DhBookTreePrivate *priv = dh_book_tree_get_instance_private (DH_BOOK_TREE (object));
-
- switch (prop_id) {
- case PROP_BOOK_MANAGER:
- g_return_if_fail (priv->book_manager == NULL);
- priv->book_manager = g_value_dup_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
+/* TODO move the code in this function in init(), we have now access to the
+ * book_manager directly.
+ */
static void
dh_book_tree_constructed (GObject *object)
{
DhBookTree *tree = DH_BOOK_TREE (object);
DhBookTreePrivate *priv = dh_book_tree_get_instance_private (tree);
+ DhBookManager *book_manager;
- g_signal_connect_object (priv->book_manager,
+ book_manager = dh_book_manager_get_singleton ();
+
+ g_signal_connect_object (book_manager,
"book-created",
G_CALLBACK (book_tree_book_created_or_enabled_cb),
tree,
0);
- g_signal_connect_object (priv->book_manager,
+ g_signal_connect_object (book_manager,
"book-enabled",
G_CALLBACK (book_tree_book_created_or_enabled_cb),
tree,
0);
- g_signal_connect_object (priv->book_manager,
+ g_signal_connect_object (book_manager,
"book-deleted",
G_CALLBACK (book_tree_book_deleted_or_disabled_cb),
tree,
0);
- g_signal_connect_object (priv->book_manager,
+ g_signal_connect_object (book_manager,
"book-disabled",
G_CALLBACK (book_tree_book_deleted_or_disabled_cb),
tree,
0);
- g_signal_connect_object (priv->book_manager,
+ g_signal_connect_object (book_manager,
"notify::group-by-language",
G_CALLBACK (book_tree_group_by_language_cb),
tree,
@@ -669,7 +639,6 @@ dh_book_tree_dispose (GObject *object)
DhBookTreePrivate *priv = dh_book_tree_get_instance_private (DH_BOOK_TREE (object));
g_clear_object (&priv->store);
- g_clear_object (&priv->book_manager);
G_OBJECT_CLASS (dh_book_tree_parent_class)->dispose (object);
}
@@ -679,27 +648,10 @@ dh_book_tree_class_init (DhBookTreeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->get_property = dh_book_tree_get_property;
- object_class->set_property = dh_book_tree_set_property;
object_class->constructed = dh_book_tree_constructed;
object_class->dispose = dh_book_tree_dispose;
/**
- * DhBookTree:book-manager:
- *
- * The #DhBookManager.
- */
- g_object_class_install_property (object_class,
- PROP_BOOK_MANAGER,
- g_param_spec_object ("book-manager",
- "Book Manager",
- "",
- DH_TYPE_BOOK_MANAGER,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- /**
* DhBookTree::link-selected:
* @tree: the #DhBookTree.
* @link: the selected #DhLink.
@@ -761,15 +713,13 @@ dh_book_tree_init (DhBookTree *tree)
/**
* dh_book_tree_new:
- * @book_manager: a #DhBookManager.
*
* Returns: (transfer floating): a new #DhBookTree widget.
*/
GtkWidget *
-dh_book_tree_new (DhBookManager *book_manager)
+dh_book_tree_new (void)
{
return GTK_WIDGET (g_object_new (DH_TYPE_BOOK_TREE,
- "book-manager", book_manager,
"enable-search", FALSE,
NULL));
}
diff --git a/src/dh-book-tree.h b/src/dh-book-tree.h
index f3aff40..6369e40 100644
--- a/src/dh-book-tree.h
+++ b/src/dh-book-tree.h
@@ -21,7 +21,6 @@
#include <gtk/gtk.h>
#include "dh-link.h"
-#include "dh-book-manager.h"
G_BEGIN_DECLS
@@ -43,7 +42,7 @@ struct _DhBookTreeClass {
};
GType dh_book_tree_get_type (void) G_GNUC_CONST;
-GtkWidget * dh_book_tree_new (DhBookManager *book_manager);
+GtkWidget * dh_book_tree_new (void);
void dh_book_tree_select_uri (DhBookTree *tree,
const gchar *uri);
DhLink *dh_book_tree_get_selected_book (DhBookTree *tree);
diff --git a/src/dh-sidebar.c b/src/dh-sidebar.c
index 6f9de91..095f7d3 100644
--- a/src/dh-sidebar.c
+++ b/src/dh-sidebar.c
@@ -659,7 +659,7 @@ dh_sidebar_constructed (GObject *object)
sidebar,
0);
- priv->book_tree = DH_BOOK_TREE (dh_book_tree_new (priv->book_manager));
+ priv->book_tree = DH_BOOK_TREE (dh_book_tree_new ());
gtk_widget_show (GTK_WIDGET (priv->book_tree));
g_signal_connect (priv->book_tree,
"link-selected",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]