[devhelp/wip/book-manager-singleton] Sidebar: remove book-manager property



commit 09fc82a7c2a46d0808164861b9ecfc51e935e9a3
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon May 1 17:15:40 2017 +0200

    Sidebar: remove book-manager property
    
    dh_sidebar_new() is also used by gnome-builder and Anjuta, so do not
    break the API of that function.

 src/dh-sidebar.c |   85 +++++++++--------------------------------------------
 src/dh-window.c  |    8 +----
 2 files changed, 17 insertions(+), 76 deletions(-)
---
diff --git a/src/dh-sidebar.c b/src/dh-sidebar.c
index 2c279df..b4ffdbd 100644
--- a/src/dh-sidebar.c
+++ b/src/dh-sidebar.c
@@ -31,8 +31,6 @@
 #include "dh-book-tree.h"
 
 typedef struct {
-        DhBookManager           *book_manager;
-
         DhBookTree              *book_tree;
         GtkScrolledWindow       *sw_book_tree;
 
@@ -47,11 +45,6 @@ typedef struct {
 } DhSidebarPrivate;
 
 enum {
-        PROP_0,
-        PROP_BOOK_MANAGER
-};
-
-enum {
         LINK_SELECTED,
         LAST_SIGNAL
 };
@@ -167,11 +160,12 @@ sidebar_book_deleted_or_disabled_cb (DhBookManager *book_manager,
 static void
 sidebar_completion_populate (DhSidebar *sidebar)
 {
-        DhSidebarPrivate *priv = dh_sidebar_get_instance_private (sidebar);
+        DhBookManager *book_manager;
         GList *books;
         GList *l;
 
-        books = dh_book_manager_get_books (priv->book_manager);
+        book_manager = dh_book_manager_get_singleton ();
+        books = dh_book_manager_get_books (book_manager);
 
         for (l = books; l != NULL; l = l->next)
                 sidebar_completion_add_book (sidebar, DH_BOOK (l->data));
@@ -471,7 +465,8 @@ dh_sidebar_select_uri (DhSidebar   *sidebar,
 
 /**
  * dh_sidebar_new:
- * @book_manager: a #DhBookManager.
+ * @book_manager: a #DhBookManager. This parameter is deprecated, you can just
+ * pass %NULL.
  *
  * Returns: (transfer floating): a new #DhSidebar widget.
  */
@@ -480,7 +475,6 @@ dh_sidebar_new (DhBookManager *book_manager)
 {
         return GTK_WIDGET (g_object_new (DH_TYPE_SIDEBAR,
                                          "orientation", GTK_ORIENTATION_VERTICAL,
-                                         "book-manager", book_manager,
                                          NULL));
 }
 
@@ -489,7 +483,6 @@ dh_sidebar_dispose (GObject *object)
 {
         DhSidebarPrivate *priv = dh_sidebar_get_instance_private (DH_SIDEBAR (object));
 
-        g_clear_object (&priv->book_manager);
         g_clear_object (&priv->hitlist_model);
 
         if (priv->idle_complete_id != 0) {
@@ -591,69 +584,38 @@ dh_sidebar_init (DhSidebar *sidebar)
         gtk_widget_show_all (GTK_WIDGET (sidebar));
 }
 
-static void
-dh_sidebar_get_property (GObject    *object,
-                         guint       prop_id,
-                         GValue     *value,
-                         GParamSpec *pspec)
-{
-        DhSidebarPrivate *priv = dh_sidebar_get_instance_private (DH_SIDEBAR (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_sidebar_set_property (GObject      *object,
-                         guint         prop_id,
-                         const GValue *value,
-                         GParamSpec   *pspec)
-{
-        DhSidebarPrivate *priv = dh_sidebar_get_instance_private (DH_SIDEBAR (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 the code of this function can be moved to init(), we now have the
+ * book_manager directly.
+ */
 static void
 dh_sidebar_constructed (GObject *object)
 {
         DhSidebar *sidebar = DH_SIDEBAR (object);
         DhSidebarPrivate *priv = dh_sidebar_get_instance_private (sidebar);
+        DhBookManager *book_manager;
 
         /* Setup 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 (sidebar_book_created_or_enabled_cb),
                                  sidebar,
                                  0);
 
-        g_signal_connect_object (priv->book_manager,
+        g_signal_connect_object (book_manager,
                                  "book-enabled",
                                  G_CALLBACK (sidebar_book_created_or_enabled_cb),
                                  sidebar,
                                  0);
 
-        g_signal_connect_object (priv->book_manager,
+        g_signal_connect_object (book_manager,
                                  "book-deleted",
                                  G_CALLBACK (sidebar_book_deleted_or_disabled_cb),
                                  sidebar,
                                  0);
 
-        g_signal_connect_object (priv->book_manager,
+        g_signal_connect_object (book_manager,
                                  "book-disabled",
                                  G_CALLBACK (sidebar_book_deleted_or_disabled_cb),
                                  sidebar,
@@ -680,26 +642,9 @@ dh_sidebar_class_init (DhSidebarClass *klass)
 
         object_class->dispose = dh_sidebar_dispose;
         object_class->finalize = dh_sidebar_finalize;
-        object_class->get_property = dh_sidebar_get_property;
-        object_class->set_property = dh_sidebar_set_property;
         object_class->constructed = dh_sidebar_constructed;
 
         /**
-         * DhSidebar: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));
-
-        /**
          * DhSidebar::link-selected:
          * @sidebar: a #DhSidebar.
          * @link: the selected #DhLink.
diff --git a/src/dh-window.c b/src/dh-window.c
index 7e102d4..1197205 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -813,14 +813,10 @@ window_web_view_switch_page_after_cb (GtkNotebook *notebook,
 static void
 window_populate (DhWindow *window)
 {
-        DhWindowPrivate *priv;
-        DhBookManager *book_manager;
-
-        priv = dh_window_get_instance_private (window);
-        book_manager = dh_app_peek_book_manager (DH_APP (gtk_window_get_application (GTK_WINDOW (window))));
+        DhWindowPrivate *priv = dh_window_get_instance_private (window);
 
         /* Sidebar */
-        priv->sidebar = DH_SIDEBAR (dh_sidebar_new (book_manager));
+        priv->sidebar = DH_SIDEBAR (dh_sidebar_new (NULL));
         gtk_widget_set_vexpand (GTK_WIDGET (priv->sidebar), TRUE);
         gtk_widget_set_hexpand (GTK_WIDGET (priv->sidebar), TRUE);
         gtk_widget_show (GTK_WIDGET (priv->sidebar));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]